summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/frame.c
Side-by-side diff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/frame.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/frame.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/core/multimedia/opieplayer/libmad/frame.c b/core/multimedia/opieplayer/libmad/frame.c
index bf15e7f..3aacb56 100644
--- a/core/multimedia/opieplayer/libmad/frame.c
+++ b/core/multimedia/opieplayer/libmad/frame.c
@@ -1,27 +1,27 @@
/*
* libmad - MPEG audio decoder library
- * Copyright (C) 2000-2001 Robert Leslie
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
# ifdef HAVE_CONFIG_H
# include "libmad_config.h"
# endif
# include "libmad_global.h"
@@ -189,52 +189,59 @@ int decode_header(struct mad_header *header, struct mad_stream *stream)
if (mad_bit_read(&stream->ptr, 1))
header->flags |= MAD_FLAG_PADDING;
/* private_bit */
if (mad_bit_read(&stream->ptr, 1))
header->private_bits |= MAD_PRIVATE_HEADER;
/* mode */
header->mode = 3 - mad_bit_read(&stream->ptr, 2);
/* mode_extension */
header->mode_extension = mad_bit_read(&stream->ptr, 2);
/* copyright */
if (mad_bit_read(&stream->ptr, 1))
header->flags |= MAD_FLAG_COPYRIGHT;
/* original/copy */
if (mad_bit_read(&stream->ptr, 1))
header->flags |= MAD_FLAG_ORIGINAL;
/* emphasis */
header->emphasis = mad_bit_read(&stream->ptr, 2);
- if (header->emphasis == 2) {
+# if defined(OPT_STRICT)
+ /*
+ * ISO/IEC 11172-3 says this is a reserved emphasis value, but
+ * streams exist which use it anyway. Since the value is not important
+ * to the decoder proper, we allow it unless OPT_STRICT is defined.
+ */
+ if (header->emphasis == MAD_EMPHASIS_RESERVED) {
stream->error = MAD_ERROR_BADEMPHASIS;
return -1;
}
+# endif
/* error_check() */
/* crc_check */
if (header->flags & MAD_FLAG_PROTECTION)
header->crc_target = mad_bit_read(&stream->ptr, 16);
return 0;
}
/*
* NAME: free_bitrate()
* DESCRIPTION: attempt to discover the bitstream's free bitrate
*/
static
int free_bitrate(struct mad_stream *stream, struct mad_header const *header)
{
struct mad_bitptr keep_ptr;
unsigned long rate = 0;
unsigned int pad_slot, slots_per_frame;
unsigned char const *ptr = 0;
keep_ptr = stream->ptr;
@@ -262,52 +269,48 @@ int free_bitrate(struct mad_stream *stream, struct mad_header const *header)
rate = (unsigned long) header->samplerate *
(N - 4 * pad_slot + 4) / 48 / 1000;
}
else {
rate = (unsigned long) header->samplerate *
(N - pad_slot + 1) / slots_per_frame / 1000;
}
if (rate >= 8)
break;
}
mad_bit_skip(&stream->ptr, 8);
}
stream->ptr = keep_ptr;
if (rate < 8 || (header->layer == MAD_LAYER_III && rate > 640)) {
stream->error = MAD_ERROR_LOSTSYNC;
return -1;
}
stream->freerate = rate * 1000;
-# if 0 && defined(DEBUG)
- fprintf(stderr, "free bitrate == %lu\n", stream->freerate);
-# endif
-
return 0;
}
/*
* NAME: header->decode()
* DESCRIPTION: read the next frame header from the stream
*/
int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
{
register unsigned char const *ptr, *end;
unsigned int pad_slot, N;
ptr = stream->next_frame;
end = stream->bufend;
if (ptr == 0) {
stream->error = MAD_ERROR_BUFPTR;
goto fail;
}
/* stream skip */
if (stream->skiplen) {
if (!stream->sync)
ptr = stream->this_frame;
@@ -352,49 +355,50 @@ int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
stream->next_frame = end - MAD_BUFFER_GUARD;
stream->error = MAD_ERROR_BUFLEN;
goto fail;
}
ptr = mad_bit_nextbyte(&stream->ptr);
}
/* begin processing */
stream->this_frame = ptr;
stream->next_frame = ptr + 1; /* possibly bogus sync word */
mad_bit_init(&stream->ptr, stream->this_frame);
if (decode_header(header, stream) == -1)
goto fail;
/* calculate frame duration */
mad_timer_set(&header->duration, 0,
32 * MAD_NSBSAMPLES(header), header->samplerate);
/* calculate free bit rate */
if (header->bitrate == 0) {
- if ((stream->freerate == 0 || !stream->sync) &&
+ if ((stream->freerate == 0 || !stream->sync ||
+ (header->layer == MAD_LAYER_III && stream->freerate > 640000)) &&
free_bitrate(stream, header) == -1)
goto fail;
header->bitrate = stream->freerate;
header->flags |= MAD_FLAG_FREEFORMAT;
}
/* calculate beginning of next frame */
pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
if (header->layer == MAD_LAYER_I)
N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4;
else {
unsigned int slots_per_frame;
slots_per_frame = (header->layer == MAD_LAYER_III &&
(header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144;
N = (slots_per_frame * header->bitrate / header->samplerate) + pad_slot;
}
/* verify there is enough data left in buffer to decode this frame */
if (N + MAD_BUFFER_GUARD > end - stream->this_frame) {
stream->next_frame = stream->this_frame;