Debian Codegraph @

Xmp3/common.c

raw symbols SCIP
1 #include "asterisk.h"
2 #include "asterisk/logger.h"
3
4 #include <ctype.h>
5 #include <stdlib.h>
6 #include <signal.h>
7
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11
12 #include "mpg123.h"
13 #include "mpglib.h"
14
15 struct parameter param = { 1 , 1 , 0 , 0 };
16
17 int tabsel_123[2][3][16] = {
18 { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
19 {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
20 {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} },
21
22 { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
23 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
24 {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} }
25 };
26
27 long freqs[9] = { 44100, 48000, 32000,
28 22050, 24000, 16000 ,
29 11025 , 12000 , 8000 };
30
31
32 #if 0
33 static void get_II_stuff(struct frame *fr)
34 {
35 static int translate[3][2][16] =
36 { { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } ,
37 { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } ,
38 { { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } ,
39 { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } ,
40 { { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } ,
41 { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } };
42
43 int table,sblim;
44 static struct al_table *tables[5] =
45 { alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 };
46 static int sblims[5] = { 27 , 30 , 8, 12 , 30 };
47
48 if(fr->lsf)
49 table = 4;
50 else
51 table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index];
52 sblim = sblims[table];
53
54 fr->alloc = tables[table];
55 fr->II_sblimit = sblim;
56 }
57 #endif
58
59 #define HDRCMPMASK 0xfffffd00
60
61 #if 0
62 int head_check(unsigned long head)
63 {
64 if( (head & 0xffe00000) != 0xffe00000)
65 return FALSE;
66 if(!((head>>17)&3))
67 return FALSE;
68 if( ((head>>12)&0xf) == 0xf)
69 return FALSE;
70 if( ((head>>10)&0x3) == 0x3 )
71 return FALSE;
72 return TRUE;
73 }
74 #endif
75
76
77 /*
78 * the code a header and write the information
79 * into the frame structure
80 */
81 int decode_header(struct frame *fr,unsigned long newhead)
82 {
83 if( newhead & (1<<20) ) {
84 fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
85 fr->mpeg25 = 0;
86 }
87 else {
88 fr->lsf = 1;
89 fr->mpeg25 = 1;
90 }
91
92 fr->lay = 4-((newhead>>17)&3);
93 if( ((newhead>>10)&0x3) == 0x3) {
94 ast_log(LOG_WARNING,"Stream error\n");
95 return (0);
96 }
97 if(fr->mpeg25) {
98 fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
99 }
100 else
101 fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
102 fr->error_protection = ((newhead>>16)&0x1)^0x1;
103
104 if(fr->mpeg25) /* allow Bitrate change for 2.5 ... */
105 fr->bitrate_index = ((newhead>>12)&0xf);
106
107 fr->bitrate_index = ((newhead>>12)&0xf);
108 fr->padding = ((newhead>>9)&0x1);
109 fr->extension = ((newhead>>8)&0x1);
110 fr->mode = ((newhead>>6)&0x3);
111 fr->mode_ext = ((newhead>>4)&0x3);
112 fr->copyright = ((newhead>>3)&0x1);
113 fr->original = ((newhead>>2)&0x1);
114 fr->emphasis = newhead & 0x3;
115
116 fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
117
118 if(!fr->bitrate_index)
119 {
120 ast_log(LOG_WARNING,"Free format not supported.\n");
121 return (0);
122 }
123
124 switch(fr->lay)
125 {
126 case 1:
127 #if 0
128 fr->do_layer = do_layer1;
129 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
130 (fr->mode_ext<<2)+4 : 32;
131 fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
132 fr->framesize /= freqs[fr->sampling_frequency];
133 fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
134 #else
135 ast_log(LOG_WARNING,"Layer 1 not supported!\n");
136 #endif
137 break;
138 case 2:
139 #if 0
140 fr->do_layer = do_layer2;
141 get_II_stuff(fr);
142 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
143 (fr->mode_ext<<2)+4 : fr->II_sblimit;
144 fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
145 fr->framesize /= freqs[fr->sampling_frequency];
146 fr->framesize += fr->padding - 4;
147 #else
148 ast_log(LOG_WARNING,"Layer 2 not supported!\n");
149 #endif
150 break;
151 case 3:
152 #if 0
153 fr->do_layer = do_layer3;
154 if(fr->lsf)
155 ssize = (fr->stereo == 1) ? 9 : 17;
156 else
157 ssize = (fr->stereo == 1) ? 17 : 32;
158 #endif
159
160 #if 0
161 if(fr->error_protection)
162 ssize += 2;
163 #endif
164 fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
165 fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
166 fr->framesize = fr->framesize + fr->padding - 4;
167 break;
168 default:
169 ast_log(LOG_WARNING,"Sorry, unknown layer type.\n");
170 return (0);
171 }
172 return 1;
173 }
174
175 #if 0
176 void print_header(struct frame *fr)
177 {
178 static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
179 static char *layers[4] = { "Unknown" , "I", "II", "III" };
180
181 ast_log(LOG_WARNING,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n",
182 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
183 layers[fr->lay],freqs[fr->sampling_frequency],
184 modes[fr->mode],fr->mode_ext,fr->framesize+4);
185 ast_log(LOG_WARNING,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
186 fr->stereo,fr->copyright?"Yes":"No",
187 fr->original?"Yes":"No",fr->error_protection?"Yes":"No",
188 fr->emphasis);
189 ast_log(LOG_WARNING,"Bitrate: %d Kbits/s, Extension value: %d\n",
190 tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension);
191 }
192
193 void print_header_compact(struct frame *fr)
194 {
195 static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
196 static char *layers[4] = { "Unknown" , "I", "II", "III" };
197
198 ast_log(LOG_WARNING,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
199 fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
200 layers[fr->lay],
201 tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
202 freqs[fr->sampling_frequency], modes[fr->mode]);
203 }
204
205 #endif
206
207 unsigned int getbits(struct mpstr *mp, int number_of_bits)
208 {
209 unsigned long rval;
210
211 if(!number_of_bits)
212 return 0;
213
214 {
215 rval = (mp->worksample).wordpointer[0];
216 rval <<= 8;
217 rval |= (mp->worksample).wordpointer[1];
218 rval <<= 8;
219 rval |= (mp->worksample).wordpointer[2];
220 rval <<= (mp->worksample).bitindex;
221 rval &= 0xffffff;
222
223 (mp->worksample).bitindex += number_of_bits;
224
225 rval >>= (24-number_of_bits);
226
227 (mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
228 (mp->worksample).bitindex &= 7;
229 }
230 return rval;
231 }
232
233 unsigned int getbits_fast(struct mpstr *mp, int number_of_bits)
234 {
235 unsigned long rval;
236
237 {
238 rval = (mp->worksample).wordpointer[0];
239 rval <<= 8;
240 rval |= (mp->worksample).wordpointer[1];
241 rval <<= (mp->worksample).bitindex;
242 rval &= 0xffff;
243 (mp->worksample).bitindex += number_of_bits;
244
245 rval >>= (16-number_of_bits);
246
247 (mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
248 (mp->worksample).bitindex &= 7;
249 }
250 return rval;
251 }
252
253 unsigned int get1bit(struct mpstr *mp)
254 {
255 unsigned char rval;
256
257 rval = *((mp->worksample).wordpointer) << (mp->worksample).bitindex;
258
259 (mp->worksample).bitindex++;
260 (mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
261 (mp->worksample).bitindex &= 7;
262
263 return rval>>7;
264 }
265
266
267