annotate Plugins/Input/mpg123/common.c @ 498:1618a9404868 trunk

[svn] removed X11 dependencies and cflags from audacious/makefile.am
author giacomo
date Wed, 25 Jan 2006 17:27:09 -0800
parents 40a60fe13ed6
children d539e5c5f730
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 #include "xmms-id3.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 #include "id3_header.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 const int tabsel_123[2][3][16] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 448,},
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 {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
18 {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
19 {{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
20 {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
21 {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
22 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 const int mpg123_freqs[9] =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 { 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 struct bitstream_info bsi;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 extern gint mpg123_bitrate, mpg123_frequency, mpg123_length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 extern gchar *mpg123_title, *mpg123_filename;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 extern gboolean mpg123_stereo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 static int fsizeold = 0, ssize;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 static unsigned char bsspace[2][MAXFRAMESIZE + 512]; /* MAXFRAMESIZE */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 static unsigned char *bsbuf = bsspace[1], *bsbufold;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 static int bsnum = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 unsigned char *mpg123_pcm_sample;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 int mpg123_pcm_point = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 static VFSFile *filept;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 static int filept_opened;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 static int get_fileinfo(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 fullread(VFSFile * fd, unsigned char *buf, int count)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 int ret, cnt = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 while (cnt < count) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 if (fd)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 ret = vfs_fread(buf + cnt, 1, count - cnt, fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 ret = mpg123_http_read(buf + cnt, count - cnt);
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 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 if (ret == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 cnt += ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 return cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 stream_init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 if (get_fileinfo() < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 mpg123_stream_close(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 if (filept)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 vfs_fclose(filept);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 else if (mpg123_info->network_stream)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 mpg123_http_close();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 /****************************************
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 * HACK,HACK,HACK: step back <num> frames
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 * can only work if the 'stream' isn't a real stream but a file
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 static int stream_back_bytes(int bytes)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 if (vfs_fseek(filept, -bytes, SEEK_CUR) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 stream_head_read(unsigned long *newhead)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 unsigned char hbuf[4];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 if (fullread(filept, hbuf, 4) != 4)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 *newhead = ((unsigned long) hbuf[0] << 24) |
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 ((unsigned long) hbuf[1] << 16) |
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 stream_head_shift(unsigned long *head)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 unsigned char hbuf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 if (fullread(filept, &hbuf, 1) != 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 *head <<= 8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 *head |= hbuf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 *head &= 0xffffffff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 stream_mpg123_read_frame_body(unsigned char *buf, int size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 long l;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 if ((l = fullread(filept, buf, size)) != size) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 if (l <= 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 memset(buf + l, 0, size - l);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 static long
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 stream_tell(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 return vfs_ftell(filept);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 static void stream_rewind(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 vfs_fseek(filept, 0, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 mpg123_stream_jump_to_frame(struct frame *fr, int frame)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150 if (!filept)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 mpg123_read_frame_init();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 vfs_fseek(filept, frame * (fr->framesize + 4), SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 mpg123_read_frame(fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 mpg123_stream_jump_to_byte(struct frame *fr, int byte)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 if (!filept)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 vfs_fseek(filept, byte, SEEK_SET);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 mpg123_read_frame(fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 mpg123_stream_check_for_xing_header(struct frame *fr, xing_header_t * xhead)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 unsigned char *head_data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 int ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 vfs_fseek(filept, -(fr->framesize + 4), SEEK_CUR);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 head_data = g_malloc(fr->framesize + 4);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 vfs_fread(head_data, 1, fr->framesize + 4, filept);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 ret = mpg123_get_xing_header(xhead, head_data);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 g_free(head_data);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 get_fileinfo(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 guchar buf[3];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 if (filept == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 if (vfs_fseek(filept, 0, SEEK_END) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 mpg123_info->filesize = vfs_ftell(filept);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 if (vfs_fseek(filept, -128, SEEK_END) < 0)
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 (fullread(filept, buf, 3) != 3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 if (!strncmp((char *) buf, "TAG", 3))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 mpg123_info->filesize -= 128;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 if (vfs_fseek(filept, 0, SEEK_SET) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 if (mpg123_info->filesize <= 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 return mpg123_info->filesize;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 mpg123_read_frame_init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 memset(bsspace[0], 0, MAXFRAMESIZE + 512);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212 memset(bsspace[1], 0, MAXFRAMESIZE + 512);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 mpg123_info->output_audio = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 * Function read_id3v2_tag (head)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 * Read ID3v2 tag from stream. Return TRUE upon success, or FALSE if
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 * an error occurred.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 read_id3v2_tag(unsigned long head)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 guchar *id3buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 int hdrsize;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 struct id3_tag *id3d;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 struct id3tag_t tag;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 guchar buf[7];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 buf[0] = head & 0xff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 * Read ID3tag header.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 if (fullread(filept, buf + 1, 6) != 6)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 hdrsize = ID3_GET_SIZE28(buf[3], buf[4], buf[5], buf[6]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 * A invalid header could fool us into requesting insane
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 * amounts of memory. Make sure the header size is
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 * reasonable.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 if ((mpg123_info->filesize && hdrsize > mpg123_info->filesize) ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 (!mpg123_info->filesize && hdrsize > 1000000))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 if (mpg123_cfg.disable_id3v2) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 guint8 *tmp = g_malloc(hdrsize);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 gboolean ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 ret = (fullread(filept, tmp, hdrsize) == hdrsize);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 g_free(tmp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 id3buf = g_malloc(hdrsize + ID3_TAGHDR_SIZE + 3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 memcpy(id3buf, "ID3", 3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 memcpy(id3buf + 3, buf, ID3_TAGHDR_SIZE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 * Read ID3tag body.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 if (fullread(filept, id3buf + ID3_TAGHDR_SIZE + 3, hdrsize) != hdrsize) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 g_free(id3buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 * Get info from tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 if ((id3d = id3_open_mem(id3buf, 0)) != NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274 mpg123_get_id3v2(id3d, &tag);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
275 if (!mpg123_info->first_frame) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276 char *songname = mpg123_title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277 mpg123_title = mpg123_format_song_title(&tag, mpg123_filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278 mpg123_ip.set_info(mpg123_title, mpg123_length,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 mpg123_bitrate * 1000,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280 mpg123_frequency, mpg123_stereo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281 if (songname)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 g_free(songname);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 mpg123_title = mpg123_format_song_title(&tag, mpg123_filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287 id3_close(id3d);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 g_free(id3buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 mpg123_head_check(unsigned long head)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 if ((head & 0xffe00000) != 0xffe00000)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 if (!((head >> 17) & 3))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 if (((head >> 12) & 0xf) == 0xf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303 if (!((head >> 12) & 0xf))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
305 if (((head >> 10) & 0x3) == 0x3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
306 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307 if (((head >> 19) & 1) == 1 &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308 ((head >> 17) & 3) == 3 && ((head >> 16) & 1) == 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310 if ((head & 0xffff0000) == 0xfffe0000)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316 /*****************************************************************
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 * read next frame
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 mpg123_read_frame(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 unsigned long newhead;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 fsizeold = fr->framesize; /* for Layer3 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 if (!stream_head_read(&newhead))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 if (!mpg123_head_check(newhead) || !mpg123_decode_header(fr, newhead)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330 int try = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 do {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 try++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 if ((newhead & 0xffffff00) ==
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 ('I' << 24) + ('D' << 16) + ('3' << 8)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 read_id3v2_tag(newhead);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 if (!stream_head_read(&newhead))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 else if (!stream_head_shift(&newhead))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344 while ((!mpg123_head_check(newhead) ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 !mpg123_decode_header(fr, newhead)) && try < (256 * 1024));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 if (try >= (256 * 1024))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 mpg123_info->filesize -= try;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351 /* flip/init buffer for Layer 3 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 bsbufold = bsbuf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 bsbuf = bsspace[bsnum] + 512;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 bsnum = (bsnum + 1) & 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 if (!stream_mpg123_read_frame_body(bsbuf, fr->framesize))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 bsi.bitindex = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 bsi.wordpointer = (unsigned char *) bsbuf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368 * the code a header and write the information
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369 * into the frame structure
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372 mpg123_decode_header(struct frame *fr, unsigned long newhead)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 if (newhead & (1 << 20)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 fr->lsf = (newhead & (1 << 19)) ? 0x0 : 0x1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376 fr->mpeg25 = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 fr->lsf = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380 fr->mpeg25 = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382 fr->lay = 4 - ((newhead >> 17) & 3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 if (fr->mpeg25) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384 fr->sampling_frequency = 6 + ((newhead >> 10) & 0x3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387 fr->sampling_frequency = ((newhead >> 10) & 0x3) + (fr->lsf * 3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 fr->error_protection = ((newhead >> 16) & 0x1) ^ 0x1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 fr->bitrate_index = ((newhead >> 12) & 0xf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 fr->padding = ((newhead >> 9) & 0x1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 fr->extension = ((newhead >> 8) & 0x1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393 fr->mode = ((newhead >> 6) & 0x3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 fr->mode_ext = ((newhead >> 4) & 0x3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 fr->copyright = ((newhead >> 3) & 0x1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 fr->original = ((newhead >> 2) & 0x1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 fr->emphasis = newhead & 0x3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 ssize = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 if (!fr->bitrate_index)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 return (0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 switch (fr->lay) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407 case 1:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 fr->do_layer = mpg123_do_layer1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409 /* inits also shared tables with layer1 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 mpg123_init_layer2(fr->synth_type == SYNTH_MMX);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 fr->framesize =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 fr->framesize /= mpg123_freqs[fr->sampling_frequency];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414 fr->framesize = ((fr->framesize + fr->padding) << 2) - 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416 case 2:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 fr->do_layer = mpg123_do_layer2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 /* inits also shared tables with layer1 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
419 mpg123_init_layer2(fr->synth_type == SYNTH_MMX);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420 fr->framesize =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
421 (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 fr->framesize /= mpg123_freqs[fr->sampling_frequency];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
423 fr->framesize += fr->padding - 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
425 case 3:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 fr->do_layer = mpg123_do_layer3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427 if (fr->lsf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 ssize = (fr->stereo == 1) ? 9 : 17;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
429 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430 ssize = (fr->stereo == 1) ? 17 : 32;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 if (fr->error_protection)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
432 ssize += 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 fr->framesize =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 fr->framesize /= mpg123_freqs[fr->sampling_frequency] << (fr->lsf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436 fr->framesize = fr->framesize + fr->padding - 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
438 default:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439 return (0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441 if (fr->framesize > MAXFRAMESIZE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 mpg123_open_stream(char *bs_filenam, int fd)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449 filept_opened = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450 if (!strncasecmp(bs_filenam, "http://", 7)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 filept = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 mpg123_http_open(bs_filenam);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 mpg123_info->filesize = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 mpg123_info->network_stream = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 if ((filept = vfs_fopen(bs_filenam, "rb")) == NULL ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
458 stream_init() == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 mpg123_info->eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 mpg123_set_pointer(long backstep)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
467 bsi.wordpointer = bsbuf + ssize - backstep;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 if (backstep)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 memcpy(bsi.wordpointer, bsbufold + fsizeold - backstep, backstep);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 bsi.bitindex = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473 double
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 mpg123_compute_bpf(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 double bpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478 switch (fr->lay) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479 case 1:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 bpf = tabsel_123[fr->lsf][0][fr->bitrate_index];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481 bpf *= 12000.0 * 4.0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 bpf /= mpg123_freqs[fr->sampling_frequency] << (fr->lsf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
484 case 2:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
485 case 3:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 bpf = tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
487 bpf *= 144000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
488 bpf /= mpg123_freqs[fr->sampling_frequency] << (fr->lsf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490 default:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
491 bpf = 1.0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
493
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
494 return bpf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
497 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498 mpg123_calc_numframes(struct frame *fr)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
500 return (int) (mpg123_info->filesize / mpg123_compute_bpf(fr));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
501 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
502
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
503 double
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
504 mpg123_relative_pos(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
505 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 if (!filept || !mpg123_info->filesize)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508 return ((double) stream_tell()) / mpg123_info->filesize;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
509 }