comparison flacdec.c @ 9235:df759d70d6f9 libavcodec

flacdec: give a more accurate error message when validating channel layout. differentiates between invalid values and unsupported values.
author jbr
date Sun, 22 Mar 2009 21:07:43 +0000
parents 8aa63f696237
children 7ec90057127a
comparison
equal deleted inserted replaced
9234:49340eb6f96f 9235:df759d70d6f9
481 } 481 }
482 482
483 static int decode_frame(FLACContext *s) 483 static int decode_frame(FLACContext *s)
484 { 484 {
485 int bs_code, sr_code, bps_code, i; 485 int bs_code, sr_code, bps_code, i;
486 int ch_mode, bps, blocksize, samplerate; 486 int ch_mode, bps, blocksize, samplerate, channels;
487 GetBitContext *gb = &s->gb; 487 GetBitContext *gb = &s->gb;
488 488
489 /* frame sync code */ 489 /* frame sync code */
490 skip_bits(&s->gb, 16); 490 skip_bits(&s->gb, 16);
491 491
494 sr_code = get_bits(gb, 4); 494 sr_code = get_bits(gb, 4);
495 495
496 /* channels and decorrelation */ 496 /* channels and decorrelation */
497 ch_mode = get_bits(gb, 4); 497 ch_mode = get_bits(gb, 4);
498 if (ch_mode < FLAC_MAX_CHANNELS && s->channels == ch_mode+1) { 498 if (ch_mode < FLAC_MAX_CHANNELS && s->channels == ch_mode+1) {
499 channels = ch_mode + 1;
499 ch_mode = FLAC_CHMODE_INDEPENDENT; 500 ch_mode = FLAC_CHMODE_INDEPENDENT;
500 } else if (ch_mode > FLAC_CHMODE_MID_SIDE || s->channels != 2) { 501 } else if (ch_mode <= FLAC_CHMODE_MID_SIDE) {
501 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", 502 channels = 2;
502 ch_mode, s->channels); 503 } else {
504 av_log(s->avctx, AV_LOG_ERROR, "invalid channel mode: %d\n", ch_mode);
505 return -1;
506 }
507 if (channels != s->channels) {
508 av_log(s->avctx, AV_LOG_ERROR, "switching channel layout mid-stream "
509 "is not supported\n");
503 return -1; 510 return -1;
504 } 511 }
505 512
506 /* bits per sample */ 513 /* bits per sample */
507 bps_code = get_bits(gb, 3); 514 bps_code = get_bits(gb, 3);