annotate Plugins/Input/mpg123/common.c @ 61:fa848bd484d8 trunk

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