summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/frame.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/frame.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/frame.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/multimedia/opieplayer/libmad/frame.c b/core/multimedia/opieplayer/libmad/frame.c
index 4ebb80c..bf15e7f 100644
--- a/core/multimedia/opieplayer/libmad/frame.c
+++ b/core/multimedia/opieplayer/libmad/frame.c
@@ -1,50 +1,50 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or 7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * 18 *
19 * $Id$ 19 * $Id$
20 */ 20 */
21 21
22# ifdef HAVE_CONFIG_H 22# ifdef HAVE_CONFIG_H
23# include "libmad_config.h" 23# include "libmad_config.h"
24# endif 24# endif
25 25
26# include "libmad_global.h" 26# include "libmad_global.h"
27 27
28# include <stdlib.h> 28# include <stdlib.h>
29 29
30# include "bit.h" 30# include "bit.h"
31# include "stream.h" 31# include "stream.h"
32# include "frame.h" 32# include "frame.h"
33# include "timer.h" 33# include "timer.h"
34# include "layer12.h" 34# include "layer12.h"
35# include "layer3.h" 35# include "layer3.h"
36 36
37static 37static
38unsigned long const bitrate_table[5][15] = { 38unsigned long const bitrate_table[5][15] = {
39 /* MPEG-1 */ 39 /* MPEG-1 */
40 { 0, 32000, 64000, 96000, 128000, 160000, 192000, 224000, /* Layer I */ 40 { 0, 32000, 64000, 96000, 128000, 160000, 192000, 224000, /* Layer I */
41 256000, 288000, 320000, 352000, 384000, 416000, 448000 }, 41 256000, 288000, 320000, 352000, 384000, 416000, 448000 },
42 { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer II */ 42 { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer II */
43 128000, 160000, 192000, 224000, 256000, 320000, 384000 }, 43 128000, 160000, 192000, 224000, 256000, 320000, 384000 },
44 { 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, /* Layer III */ 44 { 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, /* Layer III */
45 112000, 128000, 160000, 192000, 224000, 256000, 320000 }, 45 112000, 128000, 160000, 192000, 224000, 256000, 320000 },
46 46
47 /* MPEG-2 LSF */ 47 /* MPEG-2 LSF */
48 { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer I */ 48 { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer I */
49 128000, 144000, 160000, 176000, 192000, 224000, 256000 }, 49 128000, 144000, 160000, 176000, 192000, 224000, 256000 },
50 { 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, /* Layers */ 50 { 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, /* Layers */
@@ -328,97 +328,97 @@ int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
328 328
329 sync: 329 sync:
330 /* synchronize */ 330 /* synchronize */
331 if (stream->sync) { 331 if (stream->sync) {
332 if (end - ptr < MAD_BUFFER_GUARD) { 332 if (end - ptr < MAD_BUFFER_GUARD) {
333 stream->next_frame = ptr; 333 stream->next_frame = ptr;
334 334
335 stream->error = MAD_ERROR_BUFLEN; 335 stream->error = MAD_ERROR_BUFLEN;
336 goto fail; 336 goto fail;
337 } 337 }
338 else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) { 338 else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
339 /* mark point where frame sync word was expected */ 339 /* mark point where frame sync word was expected */
340 stream->this_frame = ptr; 340 stream->this_frame = ptr;
341 stream->next_frame = ptr + 1; 341 stream->next_frame = ptr + 1;
342 342
343 stream->error = MAD_ERROR_LOSTSYNC; 343 stream->error = MAD_ERROR_LOSTSYNC;
344 goto fail; 344 goto fail;
345 } 345 }
346 } 346 }
347 else { 347 else {
348 mad_bit_init(&stream->ptr, ptr); 348 mad_bit_init(&stream->ptr, ptr);
349 349
350 if (mad_stream_sync(stream) == -1) { 350 if (mad_stream_sync(stream) == -1) {
351 if (end - stream->next_frame >= MAD_BUFFER_GUARD) 351 if (end - stream->next_frame >= MAD_BUFFER_GUARD)
352 stream->next_frame = end - MAD_BUFFER_GUARD; 352 stream->next_frame = end - MAD_BUFFER_GUARD;
353 353
354 stream->error = MAD_ERROR_BUFLEN; 354 stream->error = MAD_ERROR_BUFLEN;
355 goto fail; 355 goto fail;
356 } 356 }
357 357
358 ptr = mad_bit_nextbyte(&stream->ptr); 358 ptr = mad_bit_nextbyte(&stream->ptr);
359 } 359 }
360 360
361 /* begin processing */ 361 /* begin processing */
362 stream->this_frame = ptr; 362 stream->this_frame = ptr;
363 stream->next_frame = ptr + 1; /* possibly bogus sync word */ 363 stream->next_frame = ptr + 1; /* possibly bogus sync word */
364 364
365 mad_bit_init(&stream->ptr, stream->this_frame); 365 mad_bit_init(&stream->ptr, stream->this_frame);
366 366
367 if (decode_header(header, stream) == -1) 367 if (decode_header(header, stream) == -1)
368 goto fail; 368 goto fail;
369 369
370 /* calculate frame duration */ 370 /* calculate frame duration */
371 mad_timer_set(&header->duration, 0, 371 mad_timer_set(&header->duration, 0,
372 32 * MAD_NSBSAMPLES(header), header->samplerate); 372 32 * MAD_NSBSAMPLES(header), header->samplerate);
373 373
374 /* calculate free bit rate */ 374 /* calculate free bit rate */
375 if (header->bitrate == 0) { 375 if (header->bitrate == 0) {
376 if ((!stream->sync || !stream->freerate) && 376 if ((stream->freerate == 0 || !stream->sync) &&
377 free_bitrate(stream, header) == -1) 377 free_bitrate(stream, header) == -1)
378 goto fail; 378 goto fail;
379 379
380 header->bitrate = stream->freerate; 380 header->bitrate = stream->freerate;
381 header->flags |= MAD_FLAG_FREEFORMAT; 381 header->flags |= MAD_FLAG_FREEFORMAT;
382 } 382 }
383 383
384 /* calculate beginning of next frame */ 384 /* calculate beginning of next frame */
385 pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0; 385 pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
386 386
387 if (header->layer == MAD_LAYER_I) 387 if (header->layer == MAD_LAYER_I)
388 N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4; 388 N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4;
389 else { 389 else {
390 unsigned int slots_per_frame; 390 unsigned int slots_per_frame;
391 391
392 slots_per_frame = (header->layer == MAD_LAYER_III && 392 slots_per_frame = (header->layer == MAD_LAYER_III &&
393 (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144; 393 (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144;
394 394
395 N = (slots_per_frame * header->bitrate / header->samplerate) + pad_slot; 395 N = (slots_per_frame * header->bitrate / header->samplerate) + pad_slot;
396 } 396 }
397 397
398 /* verify there is enough data left in buffer to decode this frame */ 398 /* verify there is enough data left in buffer to decode this frame */
399 if (N + MAD_BUFFER_GUARD > end - stream->this_frame) { 399 if (N + MAD_BUFFER_GUARD > end - stream->this_frame) {
400 stream->next_frame = stream->this_frame; 400 stream->next_frame = stream->this_frame;
401 401
402 stream->error = MAD_ERROR_BUFLEN; 402 stream->error = MAD_ERROR_BUFLEN;
403 goto fail; 403 goto fail;
404 } 404 }
405 405
406 stream->next_frame = stream->this_frame + N; 406 stream->next_frame = stream->this_frame + N;
407 407
408 if (!stream->sync) { 408 if (!stream->sync) {
409 /* check that a valid frame header follows this frame */ 409 /* check that a valid frame header follows this frame */
410 410
411 ptr = stream->next_frame; 411 ptr = stream->next_frame;
412 if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) { 412 if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
413 ptr = stream->next_frame = stream->this_frame + 1; 413 ptr = stream->next_frame = stream->this_frame + 1;
414 goto sync; 414 goto sync;
415 } 415 }
416 416
417 stream->sync = 1; 417 stream->sync = 1;
418 } 418 }
419 419
420 header->flags |= MAD_FLAG_INCOMPLETE; 420 header->flags |= MAD_FLAG_INCOMPLETE;
421 421
422 return 0; 422 return 0;
423 423
424 fail: 424 fail: