Mercurial > libavcodec.hg
comparison vc9.c @ 2671:5619d89d243a libavcodec
few bistream fixes and verbosity tweaks
author | iive |
---|---|
date | Thu, 12 May 2005 15:13:19 +0000 |
parents | ef44d24680d1 |
children | bdd509b4b554 |
comparison
equal
deleted
inserted
replaced
2670:8e9afac9896b | 2671:5619d89d243a |
---|---|
457 */ | 457 */ |
458 static int decode_hrd(VC9Context *v, GetBitContext *gb) | 458 static int decode_hrd(VC9Context *v, GetBitContext *gb) |
459 { | 459 { |
460 int i, num; | 460 int i, num; |
461 | 461 |
462 num = get_bits(gb, 5); | 462 num = 1 + get_bits(gb, 5); |
463 | 463 |
464 if (v->hrd_rate || num != v->hrd_num_leaky_buckets) | 464 if (v->hrd_rate || num != v->hrd_num_leaky_buckets) |
465 { | 465 { |
466 av_freep(&v->hrd_rate); | 466 av_freep(&v->hrd_rate); |
467 } | 467 } |
476 if (!v->hrd_buffer) return -1; | 476 if (!v->hrd_buffer) return -1; |
477 | 477 |
478 v->hrd_num_leaky_buckets = num; | 478 v->hrd_num_leaky_buckets = num; |
479 | 479 |
480 //exponent in base-2 for rate | 480 //exponent in base-2 for rate |
481 v->bit_rate_exponent = get_bits(gb, 4); | 481 v->bit_rate_exponent = 6 + get_bits(gb, 4); |
482 //exponent in base-2 for buffer_size | 482 //exponent in base-2 for buffer_size |
483 v->buffer_size_exponent = get_bits(gb, 4); | 483 v->buffer_size_exponent = 4 + get_bits(gb, 4); |
484 | 484 |
485 for (i=0; i<num; i++) | 485 for (i=0; i<num; i++) |
486 { | 486 { |
487 //mantissae, ordered (if not, use a function ? | 487 //mantissae, ordered (if not, use a function ? |
488 v->hrd_rate[i] = get_bits(gb, 16); | 488 v->hrd_rate[i] = 1 + get_bits(gb, 16); |
489 if (i && v->hrd_rate[i-1]>=v->hrd_rate[i]) | 489 if (i && v->hrd_rate[i-1]>=v->hrd_rate[i]) |
490 { | 490 { |
491 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:" | 491 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:" |
492 "%i vs %i\n", v->hrd_rate[i-1], v->hrd_rate[i]); | 492 "%i vs %i\n", v->hrd_rate[i-1], v->hrd_rate[i]); |
493 return -1; | 493 return -1; |
494 } | 494 } |
495 v->hrd_buffer[i] = get_bits(gb, 16); | 495 v->hrd_buffer[i] = 1 + get_bits(gb, 16); |
496 if (i && v->hrd_buffer[i-1]<v->hrd_buffer[i]) | 496 if (i && v->hrd_buffer[i-1]<v->hrd_buffer[i]) |
497 { | 497 { |
498 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Buffers aren't decreasing:" | 498 av_log(v->s.avctx, AV_LOG_ERROR, "HDR Buffers aren't decreasing:" |
499 "%i vs %i\n", v->hrd_buffer[i-1], v->hrd_buffer[i]); | 499 "%i vs %i\n", v->hrd_buffer[i-1], v->hrd_buffer[i]); |
500 return -1; | 500 return -1; |
534 v->extended_dmv = get_bits(gb, 1); | 534 v->extended_dmv = get_bits(gb, 1); |
535 | 535 |
536 /* 6.1.7, p21 */ | 536 /* 6.1.7, p21 */ |
537 if (get_bits(gb, 1) /* pic_size_flag */) | 537 if (get_bits(gb, 1) /* pic_size_flag */) |
538 { | 538 { |
539 avctx->coded_width = get_bits(gb, 12); | 539 avctx->coded_width = get_bits(gb, 12) << 1; |
540 avctx->coded_height = get_bits(gb, 12); | 540 avctx->coded_height = get_bits(gb, 12) << 1; |
541 if ( get_bits(gb, 1) /* disp_size_flag */) | 541 if ( get_bits(gb, 1) /* disp_size_flag */) |
542 { | 542 { |
543 avctx->width = get_bits(gb, 14); | 543 avctx->width = get_bits(gb, 14); |
544 avctx->height = get_bits(gb, 14); | 544 avctx->height = get_bits(gb, 14); |
545 } | 545 } |
546 | 546 |
547 /* 6.1.7.4, p22 */ | 547 /* 6.1.7.4, p23 */ |
548 if ( get_bits(gb, 1) /* aspect_ratio_flag */) | 548 if ( get_bits(gb, 1) /* aspect_ratio_flag */) |
549 { | 549 { |
550 aspect_ratio = get_bits(gb, 4); //SAR | 550 aspect_ratio = get_bits(gb, 4); //SAR |
551 if (aspect_ratio == 0x0F) //FF_ASPECT_EXTENDED | 551 if (aspect_ratio == 0x0F) //FF_ASPECT_EXTENDED |
552 { | 552 { |
553 avctx->sample_aspect_ratio.num = get_bits(gb, 8); | 553 avctx->sample_aspect_ratio.num = 1 + get_bits(gb, 8); |
554 avctx->sample_aspect_ratio.den = get_bits(gb, 8); | 554 avctx->sample_aspect_ratio.den = 1 + get_bits(gb, 8); |
555 } | 555 } |
556 else if (aspect_ratio == 0x0E) | 556 else if (aspect_ratio == 0x0E) |
557 { | 557 { |
558 av_log(avctx, AV_LOG_DEBUG, "Reserved AR found\n"); | 558 av_log(avctx, AV_LOG_DEBUG, "Reserved AR found\n"); |
559 } | 559 } |
568 avctx->coded_width = avctx->width; | 568 avctx->coded_width = avctx->width; |
569 avctx->coded_height = avctx->height; | 569 avctx->coded_height = avctx->height; |
570 } | 570 } |
571 | 571 |
572 /* 6.1.8, p23 */ | 572 /* 6.1.8, p23 */ |
573 if ( !get_bits(gb, 1) /* framerateflag */) | 573 if ( get_bits(gb, 1) /* framerateflag */) |
574 { | 574 { |
575 if ( get_bits(gb, 1) /* framerateind */) | 575 if ( !get_bits(gb, 1) /* framerateind */) |
576 { | 576 { |
577 nr = get_bits(gb, 8); | 577 nr = get_bits(gb, 8); |
578 dr = get_bits(gb, 4); | 578 dr = get_bits(gb, 4); |
579 if (nr<1) | 579 if (nr<1) |
580 { | 580 { |
583 } | 583 } |
584 if (nr>5) | 584 if (nr>5) |
585 { | 585 { |
586 av_log(avctx, AV_LOG_ERROR, | 586 av_log(avctx, AV_LOG_ERROR, |
587 "Reserved FRAMERATENR %i not handled\n", nr); | 587 "Reserved FRAMERATENR %i not handled\n", nr); |
588 nr = 5; /* overflow protection */ | |
588 } | 589 } |
589 if (dr<1) | 590 if (dr<1) |
590 { | 591 { |
591 av_log(avctx, AV_LOG_ERROR, "0 is forbidden for FRAMERATEDR\n"); | 592 av_log(avctx, AV_LOG_ERROR, "0 is forbidden for FRAMERATEDR\n"); |
593 return -1; | |
592 } | 594 } |
593 if (dr>2) | 595 if (dr>2) |
594 { | 596 { |
595 av_log(avctx, AV_LOG_ERROR, | 597 av_log(avctx, AV_LOG_ERROR, |
596 "Reserved FRAMERATEDR %i not handled\n", dr); | 598 "Reserved FRAMERATEDR %i not handled\n", dr); |
597 } | 599 dr = 2; /* overflow protection */ |
598 avctx->time_base.num = fps_nr[dr]; | 600 } |
599 avctx->time_base.den = fps_nr[nr]; | 601 avctx->time_base.num = fps_nr[dr - 1]; |
602 avctx->time_base.den = fps_nr[nr - 1]; | |
600 } | 603 } |
601 else | 604 else |
602 { | 605 { |
603 nr = get_bits(gb, 16); | 606 nr = get_bits(gb, 16); |
604 // 0.03125->2048Hz / 0.03125Hz | 607 // 0.03125->2048Hz / 0.03125Hz |
613 //Chromacity coordinates of color primaries | 616 //Chromacity coordinates of color primaries |
614 //like ITU-R BT.709-2, BT.470-2, ... | 617 //like ITU-R BT.709-2, BT.470-2, ... |
615 v->color_prim = get_bits(gb, 8); | 618 v->color_prim = get_bits(gb, 8); |
616 if (v->color_prim<1) | 619 if (v->color_prim<1) |
617 { | 620 { |
618 av_log(avctx, AV_LOG_ERROR, "0 for COLOR_PRIM is reserved\n"); | 621 av_log(avctx, AV_LOG_ERROR, "0 for COLOR_PRIM is forbidden\n"); |
619 return -1; | 622 return -1; |
620 } | 623 } |
621 if (v->color_prim == 3 || v->color_prim>6) | 624 if (v->color_prim == 3 || v->color_prim>6) |
622 { | 625 { |
623 av_log(avctx, AV_LOG_DEBUG, "Reserved COLOR_PRIM %i found\n", | 626 av_log(avctx, AV_LOG_DEBUG, "Reserved COLOR_PRIM %i found\n", |
625 return -1; | 628 return -1; |
626 } | 629 } |
627 | 630 |
628 //Opto-electronic transfer characteristics | 631 //Opto-electronic transfer characteristics |
629 v->transfer_char = get_bits(gb, 8); | 632 v->transfer_char = get_bits(gb, 8); |
633 if (v->transfer_char < 1) | |
634 { | |
635 av_log(avctx, AV_LOG_ERROR, "0 for TRAMSFER_CHAR is forbidden\n"); | |
636 return -1; | |
637 } | |
630 if (v->transfer_char == 3 || v->transfer_char>8) | 638 if (v->transfer_char == 3 || v->transfer_char>8) |
631 { | 639 { |
632 av_log(avctx, AV_LOG_DEBUG, "Reserved TRANSFERT_CHAR %i found\n", | 640 av_log(avctx, AV_LOG_DEBUG, "Reserved TRANSFERT_CHAR %i found\n", |
633 v->color_prim); | 641 v->color_prim); |
634 return -1; | 642 return -1; |
635 } | 643 } |
636 | 644 |
637 //Matrix coefficient for primariev->YCbCr | 645 //Matrix coefficient for primariev->YCbCr |
638 v->matrix_coef = get_bits(gb, 8); | 646 v->matrix_coef = get_bits(gb, 8); |
639 if (v->matrix_coef < 1) return -1; //forbidden | 647 if (v->matrix_coef < 1) |
640 if ((v->matrix_coef>3 && v->matrix_coef<6) || v->matrix_coef>7) | 648 { |
649 av_log(avctx, AV_LOG_ERROR, "0 for MATRIX_COEF is forbidden\n"); | |
650 return -1; | |
651 } | |
652 if ((v->matrix_coef > 2 && v->matrix_coef < 6) || v->matrix_coef > 7) | |
641 { | 653 { |
642 av_log(avctx, AV_LOG_DEBUG, "Reserved MATRIX_COEF %i found\n", | 654 av_log(avctx, AV_LOG_DEBUG, "Reserved MATRIX_COEF %i found\n", |
643 v->color_prim); | 655 v->color_prim); |
644 return -1; | 656 return -1; |
645 } | 657 } |
669 VC9Context *v = avctx->priv_data; | 681 VC9Context *v = avctx->priv_data; |
670 | 682 |
671 av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32)); | 683 av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32)); |
672 v->profile = get_bits(gb, 2); | 684 v->profile = get_bits(gb, 2); |
673 if (v->profile == 2) | 685 if (v->profile == 2) |
674 av_log(avctx, AV_LOG_ERROR, "Profile 2 is reserved\n"); | 686 { |
687 av_log(avctx, AV_LOG_ERROR, "Profile value 2 is forbidden\n"); | |
688 return -1; | |
689 } | |
675 | 690 |
676 #if HAS_ADVANCED_PROFILE | 691 #if HAS_ADVANCED_PROFILE |
677 if (v->profile == PROFILE_ADVANCED) | 692 if (v->profile == PROFILE_ADVANCED) |
678 { | 693 { |
679 v->level = get_bits(gb, 3); | 694 v->level = get_bits(gb, 3); |
695 if(v->level >= 5) | |
696 { | |
697 av_log(avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level); | |
698 } | |
680 v->chromaformat = get_bits(gb, 2); | 699 v->chromaformat = get_bits(gb, 2); |
681 if (v->chromaformat != 1) | 700 if (v->chromaformat != 1) |
682 { | 701 { |
683 av_log(avctx, AV_LOG_ERROR, | 702 av_log(avctx, AV_LOG_ERROR, |
684 "Only 4:2:0 chroma format supported\n"); | 703 "Only 4:2:0 chroma format supported\n"); |
700 // (fps-2)/4 (->30) | 719 // (fps-2)/4 (->30) |
701 v->frmrtq_postproc = get_bits(gb, 3); //common | 720 v->frmrtq_postproc = get_bits(gb, 3); //common |
702 // (bitrate-32kbps)/64kbps | 721 // (bitrate-32kbps)/64kbps |
703 v->bitrtq_postproc = get_bits(gb, 5); //common | 722 v->bitrtq_postproc = get_bits(gb, 5); //common |
704 v->s.loop_filter = get_bits(gb, 1); //common | 723 v->s.loop_filter = get_bits(gb, 1); //common |
724 if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE) | |
725 { | |
726 av_log(avctx, AV_LOG_ERROR, | |
727 "LOOPFILTER shell not be enabled in simple profile\n"); | |
728 } | |
705 | 729 |
706 #if HAS_ADVANCED_PROFILE | 730 #if HAS_ADVANCED_PROFILE |
707 if (v->profile < PROFILE_ADVANCED) | 731 if (v->profile < PROFILE_ADVANCED) |
708 #endif | 732 #endif |
709 { | 733 { |
760 if (v->profile < PROFILE_ADVANCED) | 784 if (v->profile < PROFILE_ADVANCED) |
761 #endif | 785 #endif |
762 { | 786 { |
763 v->s.resync_marker = get_bits(gb, 1); | 787 v->s.resync_marker = get_bits(gb, 1); |
764 v->rangered = get_bits(gb, 1); | 788 v->rangered = get_bits(gb, 1); |
789 if (v->rangered && v->profile == PROFILE_SIMPLE) | |
790 { | |
791 av_log(avctx, AV_LOG_DEBUG, | |
792 "RANGERED should be set to 0 in simple profile\n"); | |
793 } | |
765 } | 794 } |
766 | 795 |
767 v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common | 796 v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common |
768 v->quantizer_mode = get_bits(gb, 2); //common | 797 v->quantizer_mode = get_bits(gb, 2); //common |
769 | 798 |