annotate Plugins/Input/mpg123/common.c @ 1238:dc6f7048a9fa trunk

[svn] - remove metatag entirely
author nenolod
date Wed, 14 Jun 2006 22:41:05 -0700
parents e3d1c45120e1
children d872c88f8c6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 #include <ctype.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 #include <signal.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 #include <sys/types.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 #include <sys/stat.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 #include <fcntl.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 #include "mpg123.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 const int tabsel_123[2][3][16] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 448,},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 {{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}}
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
22 const int mpgdec_freqs[9] =
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 { 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 struct bitstream_info bsi;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
27 extern gint mpgdec_bitrate, mpgdec_frequency, mpgdec_length;
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
28 extern gchar *mpgdec_title, *mpgdec_filename;
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
29 extern gboolean mpgdec_stereo;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 static int fsizeold = 0, ssize;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 static unsigned char bsspace[2][MAXFRAMESIZE + 512]; /* MAXFRAMESIZE */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 static unsigned char *bsbuf = bsspace[1], *bsbufold;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 static int bsnum = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
36 unsigned char *mpgdec_pcm_sample;
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
37 int mpgdec_pcm_point = 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 static VFSFile *filept;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 static int filept_opened;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 static int get_fileinfo(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 fullread(VFSFile * fd, unsigned char *buf, int count)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 int ret, cnt = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 while (cnt < count) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 if (fd)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 ret = vfs_fread(buf + cnt, 1, count - cnt, fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 else
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
53 ret = mpgdec_http_read(buf + cnt, count - cnt);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 if (ret < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 if (ret == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 cnt += ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 return cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 stream_init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 if (get_fileinfo() < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 void
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
72 mpgdec_stream_close(void)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 if (filept)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 vfs_fclose(filept);
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
76 else if (mpgdec_info->network_stream)
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
77 mpgdec_http_close();
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 /****************************************
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 * HACK,HACK,HACK: step back <num> frames
970
0f294f2b0a9b [svn] - integer-mode decoding accuracy improvements
nenolod
parents: 957
diff changeset
82 * can only work if the 'stream' isn't a mpgdec_real stream but a file
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 static int stream_back_bytes(int bytes)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 if (vfs_fseek(filept, -bytes, SEEK_CUR) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 stream_head_read(unsigned long *newhead)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 unsigned char hbuf[4];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 if (fullread(filept, hbuf, 4) != 4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 *newhead = ((unsigned long) hbuf[0] << 24) |
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 ((unsigned long) hbuf[1] << 16) |
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 stream_head_shift(unsigned long *head)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 unsigned char hbuf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 if (fullread(filept, &hbuf, 1) != 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 *head <<= 8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 *head |= hbuf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 *head &= 0xffffffff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 static int
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
120 stream_mpgdec_read_frame_body(unsigned char *buf, int size)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 long l;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 if ((l = fullread(filept, buf, size)) != size) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 if (l <= 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 memset(buf + l, 0, size - l);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 static long
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 stream_tell(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 return vfs_ftell(filept);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 static void stream_rewind(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 vfs_fseek(filept, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 int
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
146 mpgdec_stream_jump_to_frame(struct frame *fr, int frame)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 if (!filept)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 return -1;
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
150 mpgdec_read_frame_init();
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 vfs_fseek(filept, frame * (fr->framesize + 4), SEEK_SET);
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
152 mpgdec_read_frame(fr);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 int
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
157 mpgdec_stream_jump_to_byte(struct frame *fr, int byte)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 if (!filept)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 vfs_fseek(filept, byte, SEEK_SET);
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
162 mpgdec_read_frame(fr);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 int
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
167 mpgdec_stream_check_for_xing_header(struct frame *fr, xing_header_t * xhead)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 unsigned char *head_data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 int ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 vfs_fseek(filept, -(fr->framesize + 4), SEEK_CUR);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 head_data = g_malloc(fr->framesize + 4);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 vfs_fread(head_data, 1, fr->framesize + 4, filept);
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
175 ret = mpgdec_get_xing_header(xhead, head_data);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 g_free(head_data);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 get_fileinfo(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 guchar buf[3];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 if (filept == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 if (vfs_fseek(filept, 0, SEEK_END) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
190 mpgdec_info->filesize = vfs_ftell(filept);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 if (vfs_fseek(filept, -128, SEEK_END) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 if (fullread(filept, buf, 3) != 3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 if (!strncmp((char *) buf, "TAG", 3))
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
196 mpgdec_info->filesize -= 128;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 if (vfs_fseek(filept, 0, SEEK_SET) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
200 if (mpgdec_info->filesize <= 0)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
203 return mpgdec_info->filesize;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 void
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
207 mpgdec_read_frame_init(void)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 memset(bsspace[0], 0, MAXFRAMESIZE + 512);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 memset(bsspace[1], 0, MAXFRAMESIZE + 512);
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
211 mpgdec_info->output_audio = FALSE;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 int
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
215 mpgdec_head_check(unsigned long head)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 if ((head & 0xffe00000) != 0xffe00000)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 if (!((head >> 17) & 3))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 if (((head >> 12) & 0xf) == 0xf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 if (!((head >> 12) & 0xf))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 if (((head >> 10) & 0x3) == 0x3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 if (((head >> 19) & 1) == 1 &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 ((head >> 17) & 3) == 3 && ((head >> 16) & 1) == 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 if ((head & 0xffff0000) == 0xfffe0000)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 /*****************************************************************
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 * read next frame
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 int
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
240 mpgdec_read_frame(struct frame *fr)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 unsigned long newhead;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 fsizeold = fr->framesize; /* for Layer3 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 if (!stream_head_read(&newhead))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
249 if (!mpgdec_head_check(newhead) || !mpgdec_decode_header(fr, newhead)) {
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 int try = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 do {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 try++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 if ((newhead & 0xffffff00) ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 ('I' << 24) + ('D' << 16) + ('3' << 8)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 if (!stream_head_read(&newhead))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 else if (!stream_head_shift(&newhead))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 }
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
263 while ((!mpgdec_head_check(newhead) ||
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
264 !mpgdec_decode_header(fr, newhead)) && try < (256 * 1024));
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 if (try >= (256 * 1024))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
268 mpgdec_info->filesize -= try;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270 /* flip/init buffer for Layer 3 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 bsbufold = bsbuf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 bsbuf = bsspace[bsnum] + 512;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 bsnum = (bsnum + 1) & 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
275 if (!stream_mpgdec_read_frame_body(bsbuf, fr->framesize))
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278 bsi.bitindex = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 bsi.wordpointer = (unsigned char *) bsbuf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287 * the code a header and write the information
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 * into the frame structure
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290 int
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
291 mpgdec_decode_header(struct frame *fr, unsigned long newhead)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293 if (newhead & (1 << 20)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294 fr->lsf = (newhead & (1 << 19)) ? 0x0 : 0x1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 fr->mpeg25 = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298 fr->lsf = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 fr->mpeg25 = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 fr->lay = 4 - ((newhead >> 17) & 3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 if (fr->mpeg25) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303 fr->sampling_frequency = 6 + ((newhead >> 10) & 0x3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
305 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
306 fr->sampling_frequency = ((newhead >> 10) & 0x3) + (fr->lsf * 3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307 fr->error_protection = ((newhead >> 16) & 0x1) ^ 0x1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309 fr->bitrate_index = ((newhead >> 12) & 0xf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310 fr->padding = ((newhead >> 9) & 0x1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311 fr->extension = ((newhead >> 8) & 0x1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312 fr->mode = ((newhead >> 6) & 0x3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 fr->mode_ext = ((newhead >> 4) & 0x3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314 fr->copyright = ((newhead >> 3) & 0x1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315 fr->original = ((newhead >> 2) & 0x1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316 fr->emphasis = newhead & 0x3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318 fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 ssize = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 if (!fr->bitrate_index)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 return (0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 switch (fr->lay) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 case 1:
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
327 fr->do_layer = mpgdec_do_layer1;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 /* inits also shared tables with layer1 */
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
329 mpgdec_init_layer2(fr->synth_type == SYNTH_MMX);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330 fr->framesize =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
332 fr->framesize /= mpgdec_freqs[fr->sampling_frequency];
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 fr->framesize = ((fr->framesize + fr->padding) << 2) - 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 case 2:
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
336 fr->do_layer = mpgdec_do_layer2;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 /* inits also shared tables with layer1 */
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
338 mpgdec_init_layer2(fr->synth_type == SYNTH_MMX);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 fr->framesize =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
341 fr->framesize /= mpgdec_freqs[fr->sampling_frequency];
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 fr->framesize += fr->padding - 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344 case 3:
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
345 fr->do_layer = mpgdec_do_layer3;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 if (fr->lsf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 ssize = (fr->stereo == 1) ? 9 : 17;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 ssize = (fr->stereo == 1) ? 17 : 32;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 if (fr->error_protection)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351 ssize += 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 fr->framesize =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
354 fr->framesize /= mpgdec_freqs[fr->sampling_frequency] << (fr->lsf);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 fr->framesize = fr->framesize + fr->padding - 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357 default:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 return (0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 if (fr->framesize > MAXFRAMESIZE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 void
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
366 mpgdec_open_stream(char *bs_filenam, int fd)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368 filept_opened = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369 if (!strncasecmp(bs_filenam, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 filept = NULL;
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
371 mpgdec_http_open(bs_filenam);
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
372 mpgdec_info->filesize = 0;
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
373 mpgdec_info->network_stream = TRUE;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376 if ((filept = vfs_fopen(bs_filenam, "rb")) == NULL ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 stream_init() == -1)
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
378 mpgdec_info->eof = TRUE;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 void
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
384 mpgdec_set_pointer(long backstep)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386 bsi.wordpointer = bsbuf + ssize - backstep;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387 if (backstep)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 memcpy(bsi.wordpointer, bsbufold + fsizeold - backstep, backstep);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 bsi.bitindex = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 double
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
393 mpgdec_compute_bpf(struct frame *fr)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 double bpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 switch (fr->lay) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 case 1:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 bpf = tabsel_123[fr->lsf][0][fr->bitrate_index];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 bpf *= 12000.0 * 4.0;
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
401 bpf /= mpgdec_freqs[fr->sampling_frequency] << (fr->lsf);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 case 2:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 case 3:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 bpf = tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 bpf *= 144000;
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
407 bpf /= mpgdec_freqs[fr->sampling_frequency] << (fr->lsf);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409 default:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 bpf = 1.0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 return bpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416 int
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
417 mpgdec_calc_numframes(struct frame *fr)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 {
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
419 return (int) (mpgdec_info->filesize / mpgdec_compute_bpf(fr));
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
421
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 double
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
423 mpgdec_relative_pos(void)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 {
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
425 if (!filept || !mpgdec_info->filesize)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 return 0;
1098
b5ae09a6c2f1 [svn] - prepare to split audacious code away from the actual decoder and use a highlevel API
nenolod
parents: 970
diff changeset
427 return ((double) stream_tell()) / mpgdec_info->filesize;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 }