summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/layer12.c
Side-by-side diff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/layer12.c') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/layer12.c64
1 files changed, 51 insertions, 13 deletions
diff --git a/core/multimedia/opieplayer/libmad/layer12.c b/core/multimedia/opieplayer/libmad/layer12.c
index d291174..512b6a5 100644
--- a/core/multimedia/opieplayer/libmad/layer12.c
+++ b/core/multimedia/opieplayer/libmad/layer12.c
@@ -1,9 +1,9 @@
/*
* 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.
*
@@ -39,13 +39,13 @@
/*
* scalefactor table
* used in both Layer I and Layer II decoding
*/
static
-mad_fixed_t const sf_table[63] = {
+mad_fixed_t const sf_table[64] = {
# include "sf_table.dat"
};
/* --- Layer I ------------------------------------------------------------- */
/* linear scaling table */
@@ -160,16 +160,23 @@ int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame)
for (sb = 0; sb < 32; ++sb) {
for (ch = 0; ch < nch; ++ch) {
if (allocation[ch][sb]) {
scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6);
+# if defined(OPT_STRICT)
+ /*
+ * Scalefactor index 63 does not appear in Table B.1 of
+ * ISO/IEC 11172-3. Nonetheless, other implementations accept it,
+ * so we only reject it if OPT_STRICT is defined.
+ */
if (scalefactor[ch][sb] == 63) {
stream->error = MAD_ERROR_BADSCALEFACTOR;
return -1;
}
+# endif
}
}
}
/* decode samples */
@@ -331,26 +338,50 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
mad_fixed_t samples[3];
nch = MAD_NCHANNELS(header);
if (header->flags & MAD_FLAG_LSF_EXT)
index = 4;
+ else if (header->flags & MAD_FLAG_FREEFORMAT)
+ goto freeformat;
else {
- switch (nch == 2 ? header->bitrate / 2 : header->bitrate) {
- case 32000:
- case 48000:
- index = (header->samplerate == 32000) ? 3 : 2;
- break;
+ unsigned long bitrate_per_channel;
- case 56000:
- case 64000:
- case 80000:
- index = 0;
- break;
+ bitrate_per_channel = header->bitrate;
+ if (nch == 2) {
+ bitrate_per_channel /= 2;
- default:
+# if defined(OPT_STRICT)
+ /*
+ * ISO/IEC 11172-3 allows only single channel mode for 32, 48, 56, and
+ * 80 kbps bitrates in Layer II, but some encoders ignore this
+ * restriction. We enforce it if OPT_STRICT is defined.
+ */
+ if (bitrate_per_channel <= 28000 || bitrate_per_channel == 40000) {
+ stream->error = MAD_ERROR_BADMODE;
+ return -1;
+ }
+# endif
+ }
+ else { /* nch == 1 */
+ if (bitrate_per_channel > 192000) {
+ /*
+ * ISO/IEC 11172-3 does not allow single channel mode for 224, 256,
+ * 320, or 384 kbps bitrates in Layer II.
+ */
+ stream->error = MAD_ERROR_BADMODE;
+ return -1;
+ }
+ }
+
+ if (bitrate_per_channel <= 48000)
+ index = (header->samplerate == 32000) ? 3 : 2;
+ else if (bitrate_per_channel <= 80000)
+ index = 0;
+ else {
+ freeformat:
index = (header->samplerate == 48000) ? 0 : 1;
}
}
sblimit = sbquant_table[index].sblimit;
offsets = sbquant_table[index].offsets;
@@ -428,18 +459,25 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
scalefactor[ch][sb][2] = mad_bit_read(&stream->ptr, 6);
}
if (scfsi[ch][sb] & 1)
scalefactor[ch][sb][1] = scalefactor[ch][sb][scfsi[ch][sb] - 1];
+# if defined(OPT_STRICT)
+ /*
+ * Scalefactor index 63 does not appear in Table B.1 of
+ * ISO/IEC 11172-3. Nonetheless, other implementations accept it,
+ * so we only reject it if OPT_STRICT is defined.
+ */
if (scalefactor[ch][sb][0] == 63 ||
scalefactor[ch][sb][1] == 63 ||
scalefactor[ch][sb][2] == 63) {
stream->error = MAD_ERROR_BADSCALEFACTOR;
return -1;
}
+# endif
}
}
}
/* decode samples */