Mercurial > libavcodec.hg
comparison mlpdec.c @ 9262:3c9a424163ee libavcodec
mlpdec: Split read_matrix_params() into its own function.
author | ramiro |
---|---|
date | Fri, 27 Mar 2009 23:32:32 +0000 |
parents | 5074e89eb15f |
children | 62774b28cde0 |
comparison
equal
deleted
inserted
replaced
9261:931bb51f060e | 9262:3c9a424163ee |
---|---|
496 } | 496 } |
497 | 497 |
498 return 0; | 498 return 0; |
499 } | 499 } |
500 | 500 |
501 /** Read parameters for primitive matrices. */ | |
502 | |
503 static int read_matrix_params(MLPDecodeContext *m, SubStream *s, GetBitContext *gbp) | |
504 { | |
505 unsigned int mat, ch; | |
506 | |
507 s->num_primitive_matrices = get_bits(gbp, 4); | |
508 | |
509 for (mat = 0; mat < s->num_primitive_matrices; mat++) { | |
510 int frac_bits, max_chan; | |
511 s->matrix_out_ch[mat] = get_bits(gbp, 4); | |
512 frac_bits = get_bits(gbp, 4); | |
513 s->lsb_bypass [mat] = get_bits1(gbp); | |
514 | |
515 if (s->matrix_out_ch[mat] > s->max_channel) { | |
516 av_log(m->avctx, AV_LOG_ERROR, | |
517 "Invalid channel %d specified as output from matrix.\n", | |
518 s->matrix_out_ch[mat]); | |
519 return -1; | |
520 } | |
521 if (frac_bits > 14) { | |
522 av_log(m->avctx, AV_LOG_ERROR, | |
523 "Too many fractional bits specified.\n"); | |
524 return -1; | |
525 } | |
526 | |
527 max_chan = s->max_matrix_channel; | |
528 if (!s->noise_type) | |
529 max_chan+=2; | |
530 | |
531 for (ch = 0; ch <= max_chan; ch++) { | |
532 int coeff_val = 0; | |
533 if (get_bits1(gbp)) | |
534 coeff_val = get_sbits(gbp, frac_bits + 2); | |
535 | |
536 s->matrix_coeff[mat][ch] = coeff_val << (14 - frac_bits); | |
537 } | |
538 | |
539 if (s->noise_type) | |
540 s->matrix_noise_shift[mat] = get_bits(gbp, 4); | |
541 else | |
542 s->matrix_noise_shift[mat] = 0; | |
543 } | |
544 | |
545 return 0; | |
546 } | |
547 | |
501 /** Read decoding parameters that change more often than those in the restart | 548 /** Read decoding parameters that change more often than those in the restart |
502 * header. */ | 549 * header. */ |
503 | 550 |
504 static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, | 551 static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, |
505 unsigned int substr) | 552 unsigned int substr) |
506 { | 553 { |
507 SubStream *s = &m->substream[substr]; | 554 SubStream *s = &m->substream[substr]; |
508 unsigned int mat, ch; | 555 unsigned int ch; |
509 | 556 |
510 if (s->param_presence_flags & PARAM_PRESENCE) | 557 if (s->param_presence_flags & PARAM_PRESENCE) |
511 if (get_bits1(gbp)) | 558 if (get_bits1(gbp)) |
512 s->param_presence_flags = get_bits(gbp, 8); | 559 s->param_presence_flags = get_bits(gbp, 8); |
513 | 560 |
521 } | 568 } |
522 } | 569 } |
523 | 570 |
524 if (s->param_presence_flags & PARAM_MATRIX) | 571 if (s->param_presence_flags & PARAM_MATRIX) |
525 if (get_bits1(gbp)) { | 572 if (get_bits1(gbp)) { |
526 s->num_primitive_matrices = get_bits(gbp, 4); | 573 if (read_matrix_params(m, s, gbp) < 0) |
527 | 574 return -1; |
528 for (mat = 0; mat < s->num_primitive_matrices; mat++) { | |
529 int frac_bits, max_chan; | |
530 s->matrix_out_ch[mat] = get_bits(gbp, 4); | |
531 frac_bits = get_bits(gbp, 4); | |
532 s->lsb_bypass [mat] = get_bits1(gbp); | |
533 | |
534 if (s->matrix_out_ch[mat] > s->max_channel) { | |
535 av_log(m->avctx, AV_LOG_ERROR, | |
536 "Invalid channel %d specified as output from matrix.\n", | |
537 s->matrix_out_ch[mat]); | |
538 return -1; | |
539 } | |
540 if (frac_bits > 14) { | |
541 av_log(m->avctx, AV_LOG_ERROR, | |
542 "Too many fractional bits specified.\n"); | |
543 return -1; | |
544 } | |
545 | |
546 max_chan = s->max_matrix_channel; | |
547 if (!s->noise_type) | |
548 max_chan+=2; | |
549 | |
550 for (ch = 0; ch <= max_chan; ch++) { | |
551 int coeff_val = 0; | |
552 if (get_bits1(gbp)) | |
553 coeff_val = get_sbits(gbp, frac_bits + 2); | |
554 | |
555 s->matrix_coeff[mat][ch] = coeff_val << (14 - frac_bits); | |
556 } | |
557 | |
558 if (s->noise_type) | |
559 s->matrix_noise_shift[mat] = get_bits(gbp, 4); | |
560 else | |
561 s->matrix_noise_shift[mat] = 0; | |
562 } | |
563 } | 575 } |
564 | 576 |
565 if (s->param_presence_flags & PARAM_OUTSHIFT) | 577 if (s->param_presence_flags & PARAM_OUTSHIFT) |
566 if (get_bits1(gbp)) | 578 if (get_bits1(gbp)) |
567 for (ch = 0; ch <= s->max_matrix_channel; ch++) { | 579 for (ch = 0; ch <= s->max_matrix_channel; ch++) { |