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.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,15 +1,15 @@
1/* 1/*
2 * libmad - MPEG audio decoder library 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
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
@@ -201,28 +201,35 @@ int decode_header(struct mad_header *header, struct mad_stream *stream)
201 201
202 /* copyright */ 202 /* copyright */
203 if (mad_bit_read(&stream->ptr, 1)) 203 if (mad_bit_read(&stream->ptr, 1))
204 header->flags |= MAD_FLAG_COPYRIGHT; 204 header->flags |= MAD_FLAG_COPYRIGHT;
205 205
206 /* original/copy */ 206 /* original/copy */
207 if (mad_bit_read(&stream->ptr, 1)) 207 if (mad_bit_read(&stream->ptr, 1))
208 header->flags |= MAD_FLAG_ORIGINAL; 208 header->flags |= MAD_FLAG_ORIGINAL;
209 209
210 /* emphasis */ 210 /* emphasis */
211 header->emphasis = mad_bit_read(&stream->ptr, 2); 211 header->emphasis = mad_bit_read(&stream->ptr, 2);
212 212
213 if (header->emphasis == 2) { 213# if defined(OPT_STRICT)
214 /*
215 * ISO/IEC 11172-3 says this is a reserved emphasis value, but
216 * streams exist which use it anyway. Since the value is not important
217 * to the decoder proper, we allow it unless OPT_STRICT is defined.
218 */
219 if (header->emphasis == MAD_EMPHASIS_RESERVED) {
214 stream->error = MAD_ERROR_BADEMPHASIS; 220 stream->error = MAD_ERROR_BADEMPHASIS;
215 return -1; 221 return -1;
216 } 222 }
223# endif
217 224
218 /* error_check() */ 225 /* error_check() */
219 226
220 /* crc_check */ 227 /* crc_check */
221 if (header->flags & MAD_FLAG_PROTECTION) 228 if (header->flags & MAD_FLAG_PROTECTION)
222 header->crc_target = mad_bit_read(&stream->ptr, 16); 229 header->crc_target = mad_bit_read(&stream->ptr, 16);
223 230
224 return 0; 231 return 0;
225} 232}
226 233
227/* 234/*
228 * NAME:free_bitrate() 235 * NAME:free_bitrate()
@@ -274,28 +281,24 @@ int free_bitrate(struct mad_stream *stream, struct mad_header const *header)
274 mad_bit_skip(&stream->ptr, 8); 281 mad_bit_skip(&stream->ptr, 8);
275 } 282 }
276 283
277 stream->ptr = keep_ptr; 284 stream->ptr = keep_ptr;
278 285
279 if (rate < 8 || (header->layer == MAD_LAYER_III && rate > 640)) { 286 if (rate < 8 || (header->layer == MAD_LAYER_III && rate > 640)) {
280 stream->error = MAD_ERROR_LOSTSYNC; 287 stream->error = MAD_ERROR_LOSTSYNC;
281 return -1; 288 return -1;
282 } 289 }
283 290
284 stream->freerate = rate * 1000; 291 stream->freerate = rate * 1000;
285 292
286# if 0 && defined(DEBUG)
287 fprintf(stderr, "free bitrate == %lu\n", stream->freerate);
288# endif
289
290 return 0; 293 return 0;
291} 294}
292 295
293/* 296/*
294 * NAME:header->decode() 297 * NAME:header->decode()
295 * DESCRIPTION:read the next frame header from the stream 298 * DESCRIPTION:read the next frame header from the stream
296 */ 299 */
297int mad_header_decode(struct mad_header *header, struct mad_stream *stream) 300int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
298{ 301{
299 register unsigned char const *ptr, *end; 302 register unsigned char const *ptr, *end;
300 unsigned int pad_slot, N; 303 unsigned int pad_slot, N;
301 304
@@ -364,25 +367,26 @@ int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
364 367
365 mad_bit_init(&stream->ptr, stream->this_frame); 368 mad_bit_init(&stream->ptr, stream->this_frame);
366 369
367 if (decode_header(header, stream) == -1) 370 if (decode_header(header, stream) == -1)
368 goto fail; 371 goto fail;
369 372
370 /* calculate frame duration */ 373 /* calculate frame duration */
371 mad_timer_set(&header->duration, 0, 374 mad_timer_set(&header->duration, 0,
372 32 * MAD_NSBSAMPLES(header), header->samplerate); 375 32 * MAD_NSBSAMPLES(header), header->samplerate);
373 376
374 /* calculate free bit rate */ 377 /* calculate free bit rate */
375 if (header->bitrate == 0) { 378 if (header->bitrate == 0) {
376 if ((stream->freerate == 0 || !stream->sync) && 379 if ((stream->freerate == 0 || !stream->sync ||
380 (header->layer == MAD_LAYER_III && stream->freerate > 640000)) &&
377 free_bitrate(stream, header) == -1) 381 free_bitrate(stream, header) == -1)
378 goto fail; 382 goto fail;
379 383
380 header->bitrate = stream->freerate; 384 header->bitrate = stream->freerate;
381 header->flags |= MAD_FLAG_FREEFORMAT; 385 header->flags |= MAD_FLAG_FREEFORMAT;
382 } 386 }
383 387
384 /* calculate beginning of next frame */ 388 /* calculate beginning of next frame */
385 pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0; 389 pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
386 390
387 if (header->layer == MAD_LAYER_I) 391 if (header->layer == MAD_LAYER_I)
388 N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4; 392 N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4;