Mercurial > mplayer.hg
annotate libmpdemux/demux_realaud.c @ 18940:530bca1ca585
Remove unused prototype
author | rtogni |
---|---|
date | Sat, 08 Jul 2006 12:01:38 +0000 |
parents | 01b9f29c2fb5 |
children | a8e681ad7c90 |
rev | line source |
---|---|
10034 | 1 /* |
2 Realaudio demuxer for MPlayer | |
14908 | 3 (c) 2003, 2005 Roberto Togni |
10034 | 4 */ |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <unistd.h> | |
9 | |
10 #include "config.h" | |
11 #include "mp_msg.h" | |
12 #include "help_mp.h" | |
13 | |
14 #include "stream.h" | |
15 #include "demuxer.h" | |
16 #include "stheader.h" | |
17 #include "bswap.h" | |
18 | |
19 | |
20 #define FOURCC_DOTRA mmioFOURCC('.','r','a', 0xfd) | |
21 #define FOURCC_144 mmioFOURCC('1','4','_','4') | |
22 #define FOURCC_288 mmioFOURCC('2','8','_','8') | |
23 #define FOURCC_DNET mmioFOURCC('d','n','e','t') | |
24 #define FOURCC_LPCJ mmioFOURCC('l','p','c','J') | |
17400 | 25 #define FOURCC_SIPR mmioFOURCC('s','i','p','r') |
26 | |
27 | |
28 static unsigned char sipr_swaps[38][2]={ | |
29 {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68}, | |
30 {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46}, | |
31 {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56}, | |
32 {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83}, | |
33 {77,80} }; | |
34 | |
35 // Map flavour to bytes per second | |
36 static int sipr_fl2bps[4] = {813, 1062, 625, 2000}; // 6.5, 8.5, 5, 16 kbit per second | |
10034 | 37 |
38 | |
39 typedef struct { | |
40 unsigned short version; | |
41 unsigned int dotranum; | |
42 unsigned int data_size; | |
43 unsigned short version2; | |
44 unsigned int hdr_size; | |
45 unsigned short codec_flavor; | |
46 unsigned int coded_framesize; | |
47 unsigned short sub_packet_h; | |
48 unsigned short frame_size; | |
49 unsigned short sub_packet_size; | |
50 char genr[4]; | |
17400 | 51 unsigned char *audio_buf; |
10034 | 52 } ra_priv_t; |
53 | |
54 | |
55 | |
16175 | 56 static int ra_check_file(demuxer_t* demuxer) |
10034 | 57 { |
58 unsigned int chunk_id; | |
59 | |
60 chunk_id = stream_read_dword_le(demuxer->stream); | |
61 if (chunk_id == FOURCC_DOTRA) | |
16175 | 62 return DEMUXER_TYPE_REALAUDIO; |
10034 | 63 else |
64 return 0; | |
65 } | |
66 | |
67 | |
68 | |
69 // return value: | |
70 // 0 = EOF or no stream found | |
71 // 1 = successfully read a packet | |
16175 | 72 static int demux_ra_fill_buffer(demuxer_t *demuxer, demux_stream_t *dsds) |
10034 | 73 { |
74 ra_priv_t *ra_priv = demuxer->priv; | |
75 int len; | |
76 int timestamp; | |
77 int flags; | |
78 demux_stream_t *ds = demuxer->audio; | |
79 sh_audio_t *sh = ds->sh; | |
80 WAVEFORMATEX *wf = sh->wf; | |
81 demux_packet_t *dp; | |
17149
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
82 int x, y; |
10034 | 83 |
84 if (demuxer->stream->eof) | |
85 return 0; | |
86 | |
87 len = wf->nBlockAlign; | |
88 demuxer->filepos = stream_tell(demuxer->stream); | |
89 | |
17400 | 90 if ((sh->format == FOURCC_288) || (sh->format == FOURCC_SIPR)) { |
91 if (sh->format == FOURCC_SIPR) { | |
92 int n; | |
93 int bs = ra_priv->sub_packet_h * ra_priv->frame_size * 2 / 96; // nibbles per subpacket | |
94 stream_read(demuxer->stream, ra_priv->audio_buf, ra_priv->sub_packet_h * ra_priv->frame_size); | |
95 // Perform reordering | |
96 for(n = 0; n < 38; n++) { | |
97 int j; | |
98 int i = bs * sipr_swaps[n][0]; | |
99 int o = bs * sipr_swaps[n][1]; | |
100 // swap nibbles of block 'i' with 'o' TODO: optimize | |
101 for(j = 0; j < bs; j++) { | |
102 int x = (i & 1) ? (ra_priv->audio_buf[i >> 1] >> 4) : (ra_priv->audio_buf[i >> 1] & 0x0F); | |
103 int y = (o & 1) ? (ra_priv->audio_buf[o >> 1] >> 4) : (ra_priv->audio_buf[o >> 1] & 0x0F); | |
104 if(o & 1) | |
105 ra_priv->audio_buf[o >> 1] = (ra_priv->audio_buf[o >> 1] & 0x0F) | (x << 4); | |
106 else | |
107 ra_priv->audio_buf[o >> 1] = (ra_priv->audio_buf[o >> 1] & 0xF0) | x; | |
108 if(i & 1) | |
109 ra_priv->audio_buf[i >> 1] = (ra_priv->audio_buf[i >> 1] & 0x0F) | (y << 4); | |
110 else | |
111 ra_priv->audio_buf[i >> 1] = (ra_priv->audio_buf[i >> 1] & 0xF0) | y; | |
112 ++i; ++o; | |
113 } | |
114 } | |
115 } else { | |
17149
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
116 for (y = 0; y < ra_priv->sub_packet_h; y++) |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
117 for (x = 0; x < ra_priv->sub_packet_h / 2; x++) |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
118 stream_read(demuxer->stream, ra_priv->audio_buf + x * 2 *ra_priv->frame_size + |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
119 y * ra_priv->coded_framesize, ra_priv->coded_framesize); |
17400 | 120 } |
17149
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
121 // Release all the audio packets |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
122 for (x = 0; x < ra_priv->sub_packet_h * ra_priv->frame_size / len; x++) { |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
123 dp = new_demux_packet(len); |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
124 memcpy(dp->buffer, ra_priv->audio_buf + x * len, len); |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
125 dp->pts = x ? 0 : demuxer->filepos / ra_priv->data_size; |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
126 dp->pos = demuxer->filepos; // all equal |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
127 dp->flags = x ? 0 : 0x10; // Mark first packet as keyframe |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
128 ds_add_packet(ds, dp); |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
129 } |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
130 } else { |
10034 | 131 dp = new_demux_packet(len); |
132 stream_read(demuxer->stream, dp->buffer, len); | |
133 | |
10035 | 134 dp->pts = demuxer->filepos / ra_priv->data_size; |
10034 | 135 dp->pos = demuxer->filepos; |
136 dp->flags = 0; | |
137 ds_add_packet(ds, dp); | |
17149
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
138 } |
10034 | 139 |
140 return 1; | |
141 } | |
142 | |
143 | |
144 | |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
17636
diff
changeset
|
145 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level); |
10034 | 146 |
147 | |
148 | |
16175 | 149 static demuxer_t* demux_open_ra(demuxer_t* demuxer) |
10034 | 150 { |
151 ra_priv_t* ra_priv = demuxer->priv; | |
152 sh_audio_t *sh; | |
153 int i; | |
154 char *buf; | |
155 | |
156 if ((ra_priv = (ra_priv_t *)malloc(sizeof(ra_priv_t))) == NULL) { | |
157 mp_msg(MSGT_DEMUX, MSGL_ERR, "[RealAudio] Can't allocate memory for private data.\n"); | |
10232 | 158 return 0; |
10034 | 159 } |
160 memset(ra_priv, 0, sizeof(ra_priv_t)); | |
161 | |
162 demuxer->priv = ra_priv; | |
163 sh = new_sh_audio(demuxer, 0); | |
164 demuxer->audio->id = 0; | |
165 sh->ds=demuxer->audio; | |
166 demuxer->audio->sh = sh; | |
167 | |
168 ra_priv->version = stream_read_word(demuxer->stream); | |
169 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] File version: %d\n", ra_priv->version); | |
170 if ((ra_priv->version < 3) || (ra_priv->version > 4)) { | |
171 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] ra version %d is not supported yet, please " | |
172 "contact MPlayer developers\n", ra_priv->version); | |
10232 | 173 return 0; |
10034 | 174 } |
175 if (ra_priv->version == 3) { | |
176 ra_priv->hdr_size = stream_read_word(demuxer->stream); | |
177 stream_skip(demuxer->stream, 10); | |
178 ra_priv->data_size = stream_read_dword(demuxer->stream); | |
179 } else { | |
180 stream_skip(demuxer->stream, 2); | |
181 ra_priv->dotranum = stream_read_dword(demuxer->stream); | |
182 ra_priv->data_size = stream_read_dword(demuxer->stream); | |
183 ra_priv->version2 = stream_read_word(demuxer->stream); | |
184 ra_priv->hdr_size = stream_read_dword(demuxer->stream); | |
185 ra_priv->codec_flavor = stream_read_word(demuxer->stream); | |
17400 | 186 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] Flavor: %d\n", ra_priv->codec_flavor); |
10034 | 187 ra_priv->coded_framesize = stream_read_dword(demuxer->stream); |
17400 | 188 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] Coded frame size: %d\n", ra_priv->coded_framesize); |
10034 | 189 stream_skip(demuxer->stream, 4); // data size? |
190 stream_skip(demuxer->stream, 8); | |
191 ra_priv->sub_packet_h = stream_read_word(demuxer->stream); | |
17400 | 192 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] Sub packet h: %d\n", ra_priv->sub_packet_h); |
10034 | 193 ra_priv->frame_size = stream_read_word(demuxer->stream); |
194 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] Frame size: %d\n", ra_priv->frame_size); | |
195 ra_priv->sub_packet_size = stream_read_word(demuxer->stream); | |
196 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] Sub packet size: %d\n", ra_priv->sub_packet_size); | |
197 stream_skip(demuxer->stream, 2); | |
198 sh->samplerate = stream_read_word(demuxer->stream); | |
199 stream_skip(demuxer->stream, 2); | |
200 sh->samplesize = stream_read_word(demuxer->stream); | |
201 sh->channels = stream_read_word(demuxer->stream); | |
202 mp_msg(MSGT_DEMUX,MSGL_V,"[RealAudio] %d channel, %d bit, %dHz\n", sh->channels, | |
203 sh->samplesize, sh->samplerate); | |
204 i = stream_read_char(demuxer->stream); | |
16322
9cb2b9b6a9b7
Sparcs do not like wild pointer typecasting (unaligned access).
reimar
parents:
16175
diff
changeset
|
205 ra_priv->genr[0] = stream_read_char(demuxer->stream); |
9cb2b9b6a9b7
Sparcs do not like wild pointer typecasting (unaligned access).
reimar
parents:
16175
diff
changeset
|
206 ra_priv->genr[1] = stream_read_char(demuxer->stream); |
9cb2b9b6a9b7
Sparcs do not like wild pointer typecasting (unaligned access).
reimar
parents:
16175
diff
changeset
|
207 ra_priv->genr[2] = stream_read_char(demuxer->stream); |
9cb2b9b6a9b7
Sparcs do not like wild pointer typecasting (unaligned access).
reimar
parents:
16175
diff
changeset
|
208 ra_priv->genr[3] = stream_read_char(demuxer->stream); |
10034 | 209 if (i != 4) { |
210 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] Genr size is not 4 (%d), please report to " | |
211 "MPlayer developers\n", i); | |
212 stream_skip(demuxer->stream, i - 4); | |
213 } | |
214 i = stream_read_char(demuxer->stream); | |
215 sh->format = stream_read_dword_le(demuxer->stream); | |
216 if (i != 4) { | |
217 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] FourCC size is not 4 (%d), please report to " | |
218 "MPlayer developers\n", i); | |
219 stream_skip(demuxer->stream, i - 4); | |
220 } | |
221 stream_skip(demuxer->stream, 3); | |
222 } | |
223 | |
224 if ((i = stream_read_char(demuxer->stream)) != 0) { | |
225 buf = malloc(i+1); | |
226 stream_read(demuxer->stream, buf, i); | |
227 buf[i] = 0; | |
228 demux_info_add(demuxer, "Title", buf); | |
229 free(buf); | |
230 } | |
231 if ((i = stream_read_char(demuxer->stream)) != 0) { | |
232 buf = malloc(i+1); | |
233 stream_read(demuxer->stream, buf, i); | |
234 buf[i] = 0; | |
235 demux_info_add(demuxer, "Author", buf); | |
236 free(buf); | |
237 } | |
238 if ((i = stream_read_char(demuxer->stream)) != 0) { | |
239 buf = malloc(i+1); | |
240 stream_read(demuxer->stream, buf, i); | |
241 buf[i] = 0; | |
242 demux_info_add(demuxer, "Copyright", buf); | |
243 free(buf); | |
244 } | |
245 | |
14908 | 246 if ((i = stream_read_char(demuxer->stream)) != 0) { |
247 buf = malloc(i+1); | |
248 stream_read(demuxer->stream, buf, i); | |
249 buf[i] = 0; | |
250 demux_info_add(demuxer, "Comment", buf); | |
251 free(buf); | |
252 } | |
10034 | 253 |
254 if (ra_priv->version == 3) { | |
14909 | 255 if(ra_priv->hdr_size + 8 > stream_tell(demuxer->stream)) { |
10034 | 256 stream_skip(demuxer->stream, 1); |
257 i = stream_read_char(demuxer->stream); | |
258 sh->format = stream_read_dword_le(demuxer->stream); | |
259 if (i != 4) { | |
260 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] FourCC size is not 4 (%d), please report to " | |
261 "MPlayer developers\n", i); | |
262 stream_skip(demuxer->stream, i - 4); | |
263 } | |
264 | |
265 if (sh->format != FOURCC_LPCJ) { | |
266 mp_msg(MSGT_DEMUX,MSGL_WARN,"[RealAudio] Version 3 with FourCC %8x, please report to " | |
267 "MPlayer developers\n", sh->format); | |
268 } | |
14909 | 269 } else |
270 // If a stream does not have fourcc, let's assume it's 14.4 | |
271 sh->format = FOURCC_LPCJ; | |
10034 | 272 |
273 sh->channels = 1; | |
274 sh->samplesize = 16; | |
275 sh->samplerate = 8000; | |
276 ra_priv->frame_size = 240; | |
277 sh->format = FOURCC_144; | |
278 } | |
279 | |
280 /* Fill WAVEFORMATEX */ | |
281 sh->wf = malloc(sizeof(WAVEFORMATEX)); | |
282 memset(sh->wf, 0, sizeof(WAVEFORMATEX)); | |
283 sh->wf->nChannels = sh->channels; | |
284 sh->wf->wBitsPerSample = sh->samplesize; | |
285 sh->wf->nSamplesPerSec = sh->samplerate; | |
286 sh->wf->nAvgBytesPerSec = sh->samplerate*sh->samplesize/8; | |
287 sh->wf->nBlockAlign = ra_priv->frame_size; | |
288 sh->wf->cbSize = 0; | |
289 sh->wf->wFormatTag = sh->format; | |
290 | |
291 switch (sh->format) { | |
292 case FOURCC_144: | |
293 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: 14_4\n"); | |
17149
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
294 sh->wf->nBlockAlign = 0x14; |
10034 | 295 break; |
296 case FOURCC_288: | |
297 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: 28_8\n"); | |
17149
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
298 sh->wf->nBlockAlign = ra_priv->coded_framesize; |
18505
01b9f29c2fb5
Fix some potential integer overflow in memory allocation (mot of these
rtognimp
parents:
17977
diff
changeset
|
299 ra_priv->audio_buf = calloc(ra_priv->sub_packet_h, ra_priv->frame_size); |
10034 | 300 break; |
301 case FOURCC_DNET: | |
302 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: DNET -> AC3\n"); | |
303 break; | |
17400 | 304 case FOURCC_SIPR: |
305 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: SIPR\n"); | |
306 sh->wf->nBlockAlign = ra_priv->coded_framesize; | |
307 sh->wf->nAvgBytesPerSec = sipr_fl2bps[ra_priv->codec_flavor]; | |
18505
01b9f29c2fb5
Fix some potential integer overflow in memory allocation (mot of these
rtognimp
parents:
17977
diff
changeset
|
308 ra_priv->audio_buf = calloc(ra_priv->sub_packet_h, ra_priv->frame_size); |
17400 | 309 break; |
10034 | 310 default: |
311 mp_msg(MSGT_DEMUX,MSGL_V,"Audio: Unknown (%d)\n", sh->format); | |
312 } | |
313 | |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
17636
diff
changeset
|
314 print_wave_header(sh->wf, MSGL_V); |
10034 | 315 |
316 /* disable seeking */ | |
317 demuxer->seekable = 0; | |
318 | |
319 if(!ds_fill_buffer(demuxer->audio)) | |
320 mp_msg(MSGT_DEMUXER,MSGL_INFO,"[RealAudio] No data.\n"); | |
10232 | 321 |
16175 | 322 return demuxer; |
10034 | 323 } |
324 | |
325 | |
326 | |
16175 | 327 static void demux_close_ra(demuxer_t *demuxer) |
10034 | 328 { |
329 ra_priv_t* ra_priv = demuxer->priv; | |
330 | |
17149
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
331 if (ra_priv) { |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
332 if (ra_priv->audio_buf) |
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
333 free (ra_priv->audio_buf); |
10034 | 334 free(ra_priv); |
17149
9a0a376a54b1
Move audio packets reordering from codec interface to demuxers for real
rtognimp
parents:
16322
diff
changeset
|
335 } |
10034 | 336 return; |
337 } | |
338 | |
339 | |
340 #if 0 | |
341 /* please upload RV10 samples WITH INDEX CHUNK */ | |
17636 | 342 int demux_seek_ra(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) |
10034 | 343 { |
344 real_priv_t *priv = demuxer->priv; | |
345 demux_stream_t *d_audio = demuxer->audio; | |
346 sh_audio_t *sh_audio = d_audio->sh; | |
347 int aid = d_audio->id; | |
348 int next_offset = 0; | |
349 int rel_seek_frames = 0; | |
350 int streams = 0; | |
351 | |
352 return stream_seek(demuxer->stream, next_offset); | |
353 } | |
354 #endif | |
16175 | 355 |
356 | |
357 demuxer_desc_t demuxer_desc_realaudio = { | |
358 "Realaudio demuxer", | |
359 "realaudio", | |
360 "REALAUDIO", | |
361 "Roberto Togni", | |
362 "handles old audio only .ra files", | |
363 DEMUXER_TYPE_REALAUDIO, | |
364 1, // safe autodetect | |
365 ra_check_file, | |
366 demux_ra_fill_buffer, | |
367 demux_open_ra, | |
368 demux_close_ra, | |
369 NULL, | |
370 NULL | |
371 }; |