Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: content/common/gpu/media/h264_parser.cc

Issue 10411085: Build AVC decoder configuration record (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compontent build Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/gpu/media/h264_parser.h" 5 #include "content/common/gpu/media/h264_parser.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 10
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte()) 135 if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte())
136 return false; 136 return false;
137 137
138 // On last byte? 138 // On last byte?
139 if (bytes_left_) 139 if (bytes_left_)
140 return true; 140 return true;
141 141
142 // Last byte, look for stop bit; 142 // Last byte, look for stop bit;
143 // We have more RBSP data if the last non-zero bit we find is not the 143 // We have more RBSP data if the last non-zero bit we find is not the
144 // first available bit. 144 // first available bit.
145 return curr_byte_ & ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1); 145 return (curr_byte_ &
146 ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0;
146 } 147 }
147 148
148 #define READ_BITS_OR_RETURN(num_bits, out) \ 149 #define READ_BITS_OR_RETURN(num_bits, out) \
149 do { \ 150 do { \
150 int _out; \ 151 int _out; \
151 if (!br_.ReadBits(num_bits, &_out)) { \ 152 if (!br_.ReadBits(num_bits, &_out)) { \
152 DVLOG(1) << "Error in stream: unexpected EOS while trying to read " #out; \ 153 DVLOG(1) << "Error in stream: unexpected EOS while trying to read " #out; \
153 return kInvalidStream; \ 154 return kInvalidStream; \
154 } \ 155 } \
155 *out = _out; \ 156 *out = _out; \
156 } while (0) 157 } while (0)
157 158
159 #define READ_BOOL_OR_RETURN(out) \
160 do { \
161 int _out; \
162 if (!br_.ReadBits(1, &_out)) { \
163 DVLOG(1) << "Error in stream: unexpected EOS while trying to read " #out; \
164 return kInvalidStream; \
165 } \
166 *out = _out != 0; \
167 } while (0)
168
158 #define READ_UE_OR_RETURN(out) \ 169 #define READ_UE_OR_RETURN(out) \
159 do { \ 170 do { \
160 if (ReadUE(out) != kOk) { \ 171 if (ReadUE(out) != kOk) { \
161 DVLOG(1) << "Error in stream: invalid value while trying to read " #out; \ 172 DVLOG(1) << "Error in stream: invalid value while trying to read " #out; \
162 return kInvalidStream; \ 173 return kInvalidStream; \
163 } \ 174 } \
164 } while (0) 175 } while (0)
165 176
166 #define READ_SE_OR_RETURN(out) \ 177 #define READ_SE_OR_RETURN(out) \
167 do { \ 178 do { \
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 545 }
535 546
536 H264Parser::Result H264Parser::ParseSPSScalingLists(H264SPS* sps) { 547 H264Parser::Result H264Parser::ParseSPSScalingLists(H264SPS* sps) {
537 // See 7.4.2.1.1. 548 // See 7.4.2.1.1.
538 bool seq_scaling_list_present_flag; 549 bool seq_scaling_list_present_flag;
539 bool use_default; 550 bool use_default;
540 Result res; 551 Result res;
541 552
542 // Parse scaling_list4x4. 553 // Parse scaling_list4x4.
543 for (int i = 0; i < 6; ++i) { 554 for (int i = 0; i < 6; ++i) {
544 READ_BITS_OR_RETURN(1, &seq_scaling_list_present_flag); 555 READ_BOOL_OR_RETURN(&seq_scaling_list_present_flag);
545 556
546 if (seq_scaling_list_present_flag) { 557 if (seq_scaling_list_present_flag) {
547 res = ParseScalingList(sizeof(sps->scaling_list4x4[i]), 558 res = ParseScalingList(sizeof(sps->scaling_list4x4[i]),
548 sps->scaling_list4x4[i], &use_default); 559 sps->scaling_list4x4[i], &use_default);
549 if (res != kOk) 560 if (res != kOk)
550 return res; 561 return res;
551 562
552 if (use_default) 563 if (use_default)
553 DefaultScalingList4x4(i, sps->scaling_list4x4); 564 DefaultScalingList4x4(i, sps->scaling_list4x4);
554 565
555 } else { 566 } else {
556 FallbackScalingList4x4(i, kDefault4x4Intra, kDefault4x4Inter, 567 FallbackScalingList4x4(i, kDefault4x4Intra, kDefault4x4Inter,
557 sps->scaling_list4x4); 568 sps->scaling_list4x4);
558 } 569 }
559 } 570 }
560 571
561 // Parse scaling_list8x8. 572 // Parse scaling_list8x8.
562 for (int i = 0; i < (sps->chroma_format_idc != 3) ? 2 : 6; ++i) { 573 for (int i = 0; i < ((sps->chroma_format_idc != 3) ? 2 : 6); ++i) {
563 READ_BITS_OR_RETURN(1, &seq_scaling_list_present_flag); 574 READ_BOOL_OR_RETURN(&seq_scaling_list_present_flag);
564 575
565 if (seq_scaling_list_present_flag) { 576 if (seq_scaling_list_present_flag) {
566 res = ParseScalingList(sizeof(sps->scaling_list8x8[i]), 577 res = ParseScalingList(sizeof(sps->scaling_list8x8[i]),
567 sps->scaling_list8x8[i], &use_default); 578 sps->scaling_list8x8[i], &use_default);
568 if (res != kOk) 579 if (res != kOk)
569 return res; 580 return res;
570 581
571 if (use_default) 582 if (use_default)
572 DefaultScalingList8x8(i, sps->scaling_list8x8); 583 DefaultScalingList8x8(i, sps->scaling_list8x8);
573 584
574 } else { 585 } else {
575 FallbackScalingList8x8(i, kDefault8x8Intra, kDefault8x8Inter, 586 FallbackScalingList8x8(i, kDefault8x8Intra, kDefault8x8Inter,
576 sps->scaling_list8x8); 587 sps->scaling_list8x8);
577 } 588 }
578 } 589 }
579 590
580 return kOk; 591 return kOk;
581 } 592 }
582 593
583 H264Parser::Result H264Parser::ParsePPSScalingLists(const H264SPS& sps, 594 H264Parser::Result H264Parser::ParsePPSScalingLists(const H264SPS& sps,
584 H264PPS* pps) { 595 H264PPS* pps) {
585 // See 7.4.2.2. 596 // See 7.4.2.2.
586 bool pic_scaling_list_present_flag; 597 bool pic_scaling_list_present_flag;
587 bool use_default; 598 bool use_default;
588 Result res; 599 Result res;
589 600
590 for (int i = 0; i < 6; ++i) { 601 for (int i = 0; i < 6; ++i) {
591 READ_BITS_OR_RETURN(1, &pic_scaling_list_present_flag); 602 READ_BOOL_OR_RETURN(&pic_scaling_list_present_flag);
592 603
593 if (pic_scaling_list_present_flag) { 604 if (pic_scaling_list_present_flag) {
594 res = ParseScalingList(sizeof(pps->scaling_list4x4[i]), 605 res = ParseScalingList(sizeof(pps->scaling_list4x4[i]),
595 pps->scaling_list4x4[i], &use_default); 606 pps->scaling_list4x4[i], &use_default);
596 if (res != kOk) 607 if (res != kOk)
597 return res; 608 return res;
598 609
599 if (use_default) 610 if (use_default)
600 DefaultScalingList4x4(i, pps->scaling_list4x4); 611 DefaultScalingList4x4(i, pps->scaling_list4x4);
601 612
602 } else { 613 } else {
603 if (sps.seq_scaling_matrix_present_flag) { 614 if (sps.seq_scaling_matrix_present_flag) {
604 // Table 7-2 fallback rule A in spec. 615 // Table 7-2 fallback rule A in spec.
605 FallbackScalingList4x4(i, kDefault4x4Intra, kDefault4x4Inter, 616 FallbackScalingList4x4(i, kDefault4x4Intra, kDefault4x4Inter,
606 pps->scaling_list4x4); 617 pps->scaling_list4x4);
607 } else { 618 } else {
608 // Table 7-2 fallback rule B in spec. 619 // Table 7-2 fallback rule B in spec.
609 FallbackScalingList4x4(i, sps.scaling_list4x4[0], 620 FallbackScalingList4x4(i, sps.scaling_list4x4[0],
610 sps.scaling_list4x4[3], pps->scaling_list4x4); 621 sps.scaling_list4x4[3], pps->scaling_list4x4);
611 } 622 }
612 } 623 }
613 } 624 }
614 625
615 if (pps->transform_8x8_mode_flag) { 626 if (pps->transform_8x8_mode_flag) {
616 for (int i = 0; i < (sps.chroma_format_idc != 3) ? 2 : 6; ++i) { 627 for (int i = 0; i < ((sps.chroma_format_idc != 3) ? 2 : 6); ++i) {
617 READ_BITS_OR_RETURN(1, &pic_scaling_list_present_flag); 628 READ_BOOL_OR_RETURN(&pic_scaling_list_present_flag);
618 629
619 if (pic_scaling_list_present_flag) { 630 if (pic_scaling_list_present_flag) {
620 res = ParseScalingList(sizeof(pps->scaling_list8x8[i]), 631 res = ParseScalingList(sizeof(pps->scaling_list8x8[i]),
621 pps->scaling_list8x8[i], &use_default); 632 pps->scaling_list8x8[i], &use_default);
622 if (res != kOk) 633 if (res != kOk)
623 return res; 634 return res;
624 635
625 if (use_default) 636 if (use_default)
626 DefaultScalingList8x8(i, pps->scaling_list8x8); 637 DefaultScalingList8x8(i, pps->scaling_list8x8);
627 638
(...skipping 22 matching lines...) Expand all
650 H264Parser::Result H264Parser::ParseSPS(int* sps_id) { 661 H264Parser::Result H264Parser::ParseSPS(int* sps_id) {
651 // See 7.4.2.1. 662 // See 7.4.2.1.
652 int data; 663 int data;
653 Result res; 664 Result res;
654 665
655 *sps_id = -1; 666 *sps_id = -1;
656 667
657 scoped_ptr<H264SPS> sps(new H264SPS()); 668 scoped_ptr<H264SPS> sps(new H264SPS());
658 669
659 READ_BITS_OR_RETURN(8, &sps->profile_idc); 670 READ_BITS_OR_RETURN(8, &sps->profile_idc);
660 // Skip constraint_setx_flag and reserved flags. 671 READ_BITS_OR_RETURN(6, &sps->constraint_setx_flag);
661 READ_BITS_OR_RETURN(8, &data); 672 READ_BITS_OR_RETURN(2, &data);
662 READ_BITS_OR_RETURN(8, &sps->level_idc); 673 READ_BITS_OR_RETURN(8, &sps->level_idc);
663 READ_UE_OR_RETURN(&sps->seq_parameter_set_id); 674 READ_UE_OR_RETURN(&sps->seq_parameter_set_id);
664 TRUE_OR_RETURN(sps->seq_parameter_set_id < 32); 675 TRUE_OR_RETURN(sps->seq_parameter_set_id < 32);
665 676
666 if (sps->profile_idc == 100 || sps->profile_idc == 110 || 677 if (sps->profile_idc == 100 || sps->profile_idc == 110 ||
667 sps->profile_idc == 122 || sps->profile_idc == 244 || 678 sps->profile_idc == 122 || sps->profile_idc == 244 ||
668 sps->profile_idc == 44 || sps->profile_idc == 83 || 679 sps->profile_idc == 44 || sps->profile_idc == 83 ||
669 sps->profile_idc == 86 || sps->profile_idc == 118 || 680 sps->profile_idc == 86 || sps->profile_idc == 118 ||
670 sps->profile_idc == 128) { 681 sps->profile_idc == 128) {
671 READ_UE_OR_RETURN(&sps->chroma_format_idc); 682 READ_UE_OR_RETURN(&sps->chroma_format_idc);
672 TRUE_OR_RETURN(sps->chroma_format_idc < 4); 683 TRUE_OR_RETURN(sps->chroma_format_idc < 4);
673 684
674 if (sps->chroma_format_idc == 3) 685 if (sps->chroma_format_idc == 3)
675 READ_BITS_OR_RETURN(1, &sps->separate_colour_plane_flag); 686 READ_BOOL_OR_RETURN(&sps->separate_colour_plane_flag);
676 687
677 if (sps->separate_colour_plane_flag) 688 if (sps->separate_colour_plane_flag)
678 sps->chroma_array_type = 0; 689 sps->chroma_array_type = 0;
679 else 690 else
680 sps->chroma_array_type = sps->chroma_format_idc; 691 sps->chroma_array_type = sps->chroma_format_idc;
681 692
682 READ_UE_OR_RETURN(&sps->bit_depth_luma_minus8); 693 READ_UE_OR_RETURN(&sps->bit_depth_luma_minus8);
683 TRUE_OR_RETURN(sps->bit_depth_luma_minus8 < 7); 694 TRUE_OR_RETURN(sps->bit_depth_luma_minus8 < 7);
684 695
685 READ_UE_OR_RETURN(&sps->bit_depth_chroma_minus8); 696 READ_UE_OR_RETURN(&sps->bit_depth_chroma_minus8);
686 TRUE_OR_RETURN(sps->bit_depth_chroma_minus8 < 7); 697 TRUE_OR_RETURN(sps->bit_depth_chroma_minus8 < 7);
687 698
688 READ_BITS_OR_RETURN(1, &sps->qpprime_y_zero_transform_bypass_flag); 699 READ_BOOL_OR_RETURN(&sps->qpprime_y_zero_transform_bypass_flag);
689 READ_BITS_OR_RETURN(1, &sps->seq_scaling_matrix_present_flag); 700 READ_BOOL_OR_RETURN(&sps->seq_scaling_matrix_present_flag);
690 701
691 if (sps->seq_scaling_matrix_present_flag) { 702 if (sps->seq_scaling_matrix_present_flag) {
692 DVLOG(4) << "Scaling matrix present"; 703 DVLOG(4) << "Scaling matrix present";
693 res = ParseSPSScalingLists(sps.get()); 704 res = ParseSPSScalingLists(sps.get());
694 if (res != kOk) 705 if (res != kOk)
695 return res; 706 return res;
696 } else { 707 } else {
697 FillDefaultSeqScalingLists(sps.get()); 708 FillDefaultSeqScalingLists(sps.get());
698 } 709 }
699 } 710 }
700 711
701 READ_UE_OR_RETURN(&sps->log2_max_frame_num_minus4); 712 READ_UE_OR_RETURN(&sps->log2_max_frame_num_minus4);
702 TRUE_OR_RETURN(sps->log2_max_frame_num_minus4 < 13); 713 TRUE_OR_RETURN(sps->log2_max_frame_num_minus4 < 13);
703 714
704 READ_UE_OR_RETURN(&sps->pic_order_cnt_type); 715 READ_UE_OR_RETURN(&sps->pic_order_cnt_type);
705 TRUE_OR_RETURN(sps->pic_order_cnt_type < 3); 716 TRUE_OR_RETURN(sps->pic_order_cnt_type < 3);
706 717
707 if (sps->pic_order_cnt_type == 0) { 718 if (sps->pic_order_cnt_type == 0) {
708 READ_UE_OR_RETURN(&sps->log2_max_pic_order_cnt_lsb_minus4); 719 READ_UE_OR_RETURN(&sps->log2_max_pic_order_cnt_lsb_minus4);
709 TRUE_OR_RETURN(sps->log2_max_pic_order_cnt_lsb_minus4 < 13); 720 TRUE_OR_RETURN(sps->log2_max_pic_order_cnt_lsb_minus4 < 13);
710 } else if (sps->pic_order_cnt_type == 1) { 721 } else if (sps->pic_order_cnt_type == 1) {
711 READ_BITS_OR_RETURN(1, &sps->delta_pic_order_always_zero_flag); 722 READ_BOOL_OR_RETURN(&sps->delta_pic_order_always_zero_flag);
712 READ_SE_OR_RETURN(&sps->offset_for_non_ref_pic); 723 READ_SE_OR_RETURN(&sps->offset_for_non_ref_pic);
713 READ_SE_OR_RETURN(&sps->offset_for_top_to_bottom_field); 724 READ_SE_OR_RETURN(&sps->offset_for_top_to_bottom_field);
714 READ_UE_OR_RETURN(&sps->num_ref_frames_in_pic_order_cnt_cycle); 725 READ_UE_OR_RETURN(&sps->num_ref_frames_in_pic_order_cnt_cycle);
715 for (int i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; ++i) 726 for (int i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; ++i)
716 READ_SE_OR_RETURN(&sps->offset_for_ref_frame[i]); 727 READ_SE_OR_RETURN(&sps->offset_for_ref_frame[i]);
717 } 728 }
718 729
719 READ_UE_OR_RETURN(&sps->max_num_ref_frames); 730 READ_UE_OR_RETURN(&sps->max_num_ref_frames);
720 READ_BITS_OR_RETURN(1, &sps->gaps_in_frame_num_value_allowed_flag); 731 READ_BOOL_OR_RETURN(&sps->gaps_in_frame_num_value_allowed_flag);
721 732
722 if (sps->gaps_in_frame_num_value_allowed_flag) 733 if (sps->gaps_in_frame_num_value_allowed_flag)
723 return kUnsupportedStream; 734 return kUnsupportedStream;
724 735
725 READ_UE_OR_RETURN(&sps->pic_width_in_mbs_minus1); 736 READ_UE_OR_RETURN(&sps->pic_width_in_mbs_minus1);
726 READ_UE_OR_RETURN(&sps->pic_height_in_map_units_minus1); 737 READ_UE_OR_RETURN(&sps->pic_height_in_map_units_minus1);
727 738
728 READ_BITS_OR_RETURN(1, &sps->frame_mbs_only_flag); 739 READ_BOOL_OR_RETURN(&sps->frame_mbs_only_flag);
729 if (!sps->frame_mbs_only_flag) 740 if (!sps->frame_mbs_only_flag)
730 READ_BITS_OR_RETURN(1, &sps->mb_adaptive_frame_field_flag); 741 READ_BOOL_OR_RETURN(&sps->mb_adaptive_frame_field_flag);
731 742
732 READ_BITS_OR_RETURN(1, &sps->direct_8x8_inference_flag); 743 READ_BOOL_OR_RETURN(&sps->direct_8x8_inference_flag);
733 744
734 READ_BITS_OR_RETURN(1, &sps->frame_cropping_flag); 745 READ_BOOL_OR_RETURN(&sps->frame_cropping_flag);
735 if (sps->frame_cropping_flag) { 746 if (sps->frame_cropping_flag) {
736 READ_UE_OR_RETURN(&sps->frame_crop_left_offset); 747 READ_UE_OR_RETURN(&sps->frame_crop_left_offset);
737 READ_UE_OR_RETURN(&sps->frame_crop_right_offset); 748 READ_UE_OR_RETURN(&sps->frame_crop_right_offset);
738 READ_UE_OR_RETURN(&sps->frame_crop_top_offset); 749 READ_UE_OR_RETURN(&sps->frame_crop_top_offset);
739 READ_UE_OR_RETURN(&sps->frame_crop_bottom_offset); 750 READ_UE_OR_RETURN(&sps->frame_crop_bottom_offset);
740 } 751 }
741 752
742 READ_BITS_OR_RETURN(1, &sps->vui_parameters_present_flag); 753 READ_BOOL_OR_RETURN(&sps->vui_parameters_present_flag);
743 if (sps->vui_parameters_present_flag) { 754 if (sps->vui_parameters_present_flag) {
744 DVLOG(1) << "VUI parameters present in SPS, ignoring"; 755 DVLOG(1) << "VUI parameters present in SPS, ignoring";
745 } 756 }
746 757
747 // If an SPS with the same id already exists, replace it. 758 // If an SPS with the same id already exists, replace it.
748 *sps_id = sps->seq_parameter_set_id; 759 *sps_id = sps->seq_parameter_set_id;
749 delete active_SPSes_[*sps_id]; 760 delete active_SPSes_[*sps_id];
750 active_SPSes_[*sps_id] = sps.release(); 761 active_SPSes_[*sps_id] = sps.release();
751 762
752 return kOk; 763 return kOk;
753 } 764 }
754 765
755 H264Parser::Result H264Parser::ParsePPS(int* pps_id) { 766 H264Parser::Result H264Parser::ParsePPS(int* pps_id) {
756 // See 7.4.2.2. 767 // See 7.4.2.2.
757 const H264SPS* sps; 768 const H264SPS* sps;
758 Result res; 769 Result res;
759 770
760 *pps_id = -1; 771 *pps_id = -1;
761 772
762 scoped_ptr<H264PPS> pps(new H264PPS()); 773 scoped_ptr<H264PPS> pps(new H264PPS());
763 774
764 READ_UE_OR_RETURN(&pps->pic_parameter_set_id); 775 READ_UE_OR_RETURN(&pps->pic_parameter_set_id);
765 READ_UE_OR_RETURN(&pps->seq_parameter_set_id); 776 READ_UE_OR_RETURN(&pps->seq_parameter_set_id);
766 TRUE_OR_RETURN(pps->seq_parameter_set_id < 32); 777 TRUE_OR_RETURN(pps->seq_parameter_set_id < 32);
767 778
768 sps = GetSPS(pps->seq_parameter_set_id); 779 sps = GetSPS(pps->seq_parameter_set_id);
769 TRUE_OR_RETURN(sps); 780 TRUE_OR_RETURN(sps);
770 781
771 READ_BITS_OR_RETURN(1, &pps->entropy_coding_mode_flag); 782 READ_BOOL_OR_RETURN(&pps->entropy_coding_mode_flag);
772 READ_BITS_OR_RETURN(1, &pps->bottom_field_pic_order_in_frame_present_flag); 783 READ_BOOL_OR_RETURN(&pps->bottom_field_pic_order_in_frame_present_flag);
773 784
774 READ_UE_OR_RETURN(&pps->num_slice_groups_minus1); 785 READ_UE_OR_RETURN(&pps->num_slice_groups_minus1);
775 if (pps->num_slice_groups_minus1 > 1) { 786 if (pps->num_slice_groups_minus1 > 1) {
776 DVLOG(1) << "Slice groups not supported"; 787 DVLOG(1) << "Slice groups not supported";
777 return kUnsupportedStream; 788 return kUnsupportedStream;
778 } 789 }
779 790
780 READ_UE_OR_RETURN(&pps->num_ref_idx_l0_default_active_minus1); 791 READ_UE_OR_RETURN(&pps->num_ref_idx_l0_default_active_minus1);
781 TRUE_OR_RETURN(pps->num_ref_idx_l0_default_active_minus1 < 32); 792 TRUE_OR_RETURN(pps->num_ref_idx_l0_default_active_minus1 < 32);
782 793
783 READ_UE_OR_RETURN(&pps->num_ref_idx_l1_default_active_minus1); 794 READ_UE_OR_RETURN(&pps->num_ref_idx_l1_default_active_minus1);
784 TRUE_OR_RETURN(pps->num_ref_idx_l1_default_active_minus1 < 32); 795 TRUE_OR_RETURN(pps->num_ref_idx_l1_default_active_minus1 < 32);
785 796
786 READ_BITS_OR_RETURN(1, &pps->weighted_pred_flag); 797 READ_BOOL_OR_RETURN(&pps->weighted_pred_flag);
787 READ_BITS_OR_RETURN(2, &pps->weighted_bipred_idc); 798 READ_BITS_OR_RETURN(2, &pps->weighted_bipred_idc);
788 TRUE_OR_RETURN(pps->weighted_bipred_idc < 3); 799 TRUE_OR_RETURN(pps->weighted_bipred_idc < 3);
789 800
790 READ_SE_OR_RETURN(&pps->pic_init_qp_minus26); 801 READ_SE_OR_RETURN(&pps->pic_init_qp_minus26);
791 IN_RANGE_OR_RETURN(pps->pic_init_qp_minus26, -26, 25); 802 IN_RANGE_OR_RETURN(pps->pic_init_qp_minus26, -26, 25);
792 803
793 READ_SE_OR_RETURN(&pps->pic_init_qs_minus26); 804 READ_SE_OR_RETURN(&pps->pic_init_qs_minus26);
794 IN_RANGE_OR_RETURN(pps->pic_init_qs_minus26, -26, 25); 805 IN_RANGE_OR_RETURN(pps->pic_init_qs_minus26, -26, 25);
795 806
796 READ_SE_OR_RETURN(&pps->chroma_qp_index_offset); 807 READ_SE_OR_RETURN(&pps->chroma_qp_index_offset);
797 IN_RANGE_OR_RETURN(pps->chroma_qp_index_offset, -12, 12); 808 IN_RANGE_OR_RETURN(pps->chroma_qp_index_offset, -12, 12);
798 809
799 READ_BITS_OR_RETURN(1, &pps->deblocking_filter_control_present_flag); 810 READ_BOOL_OR_RETURN(&pps->deblocking_filter_control_present_flag);
800 READ_BITS_OR_RETURN(1, &pps->constrained_intra_pred_flag); 811 READ_BOOL_OR_RETURN(&pps->constrained_intra_pred_flag);
801 READ_BITS_OR_RETURN(1, &pps->redundant_pic_cnt_present_flag); 812 READ_BOOL_OR_RETURN(&pps->redundant_pic_cnt_present_flag);
802 813
803 if (br_.HasMoreRBSPData()) { 814 if (br_.HasMoreRBSPData()) {
804 READ_BITS_OR_RETURN(1, &pps->transform_8x8_mode_flag); 815 READ_BOOL_OR_RETURN(&pps->transform_8x8_mode_flag);
805 READ_BITS_OR_RETURN(1, &pps->pic_scaling_matrix_present_flag); 816 READ_BOOL_OR_RETURN(&pps->pic_scaling_matrix_present_flag);
806 817
807 if (pps->pic_scaling_matrix_present_flag) { 818 if (pps->pic_scaling_matrix_present_flag) {
808 DVLOG(4) << "Picture scaling matrix present"; 819 DVLOG(4) << "Picture scaling matrix present";
809 res = ParsePPSScalingLists(*sps, pps.get()); 820 res = ParsePPSScalingLists(*sps, pps.get());
810 if (res != kOk) 821 if (res != kOk)
811 return res; 822 return res;
812 } 823 }
813 824
814 READ_SE_OR_RETURN(&pps->second_chroma_qp_index_offset); 825 READ_SE_OR_RETURN(&pps->second_chroma_qp_index_offset);
815 } 826 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 TRUE_OR_RETURN(modification_of_pic_nums_idc == 3); 874 TRUE_OR_RETURN(modification_of_pic_nums_idc == 3);
864 875
865 return kOk; 876 return kOk;
866 } 877 }
867 878
868 H264Parser::Result H264Parser::ParseRefPicListModifications( 879 H264Parser::Result H264Parser::ParseRefPicListModifications(
869 H264SliceHeader* shdr) { 880 H264SliceHeader* shdr) {
870 Result res; 881 Result res;
871 882
872 if (!shdr->IsISlice() && !shdr->IsSISlice()) { 883 if (!shdr->IsISlice() && !shdr->IsSISlice()) {
873 READ_BITS_OR_RETURN(1, &shdr->ref_pic_list_modification_flag_l0); 884 READ_BOOL_OR_RETURN(&shdr->ref_pic_list_modification_flag_l0);
874 if (shdr->ref_pic_list_modification_flag_l0) { 885 if (shdr->ref_pic_list_modification_flag_l0) {
875 res = ParseRefPicListModification(shdr->num_ref_idx_l0_active_minus1, 886 res = ParseRefPicListModification(shdr->num_ref_idx_l0_active_minus1,
876 shdr->ref_list_l0_modifications); 887 shdr->ref_list_l0_modifications);
877 if (res != kOk) 888 if (res != kOk)
878 return res; 889 return res;
879 } 890 }
880 } 891 }
881 892
882 if (shdr->IsBSlice()) { 893 if (shdr->IsBSlice()) {
883 READ_BITS_OR_RETURN(1, &shdr->ref_pic_list_modification_flag_l1); 894 READ_BOOL_OR_RETURN(&shdr->ref_pic_list_modification_flag_l1);
884 if (shdr->ref_pic_list_modification_flag_l1) { 895 if (shdr->ref_pic_list_modification_flag_l1) {
885 res = ParseRefPicListModification(shdr->num_ref_idx_l1_active_minus1, 896 res = ParseRefPicListModification(shdr->num_ref_idx_l1_active_minus1,
886 shdr->ref_list_l1_modifications); 897 shdr->ref_list_l1_modifications);
887 if (res != kOk) 898 if (res != kOk)
888 return res; 899 return res;
889 } 900 }
890 } 901 }
891 902
892 return kOk; 903 return kOk;
893 } 904 }
894 905
895 H264Parser::Result H264Parser::ParseWeightingFactors( 906 H264Parser::Result H264Parser::ParseWeightingFactors(
896 int num_ref_idx_active_minus1, 907 int num_ref_idx_active_minus1,
897 int chroma_array_type, 908 int chroma_array_type,
898 int luma_log2_weight_denom, 909 int luma_log2_weight_denom,
899 int chroma_log2_weight_denom, 910 int chroma_log2_weight_denom,
900 H264WeightingFactors* w_facts) { 911 H264WeightingFactors* w_facts) {
901 912
902 int def_luma_weight = 1 << luma_log2_weight_denom; 913 int def_luma_weight = 1 << luma_log2_weight_denom;
903 int def_chroma_weight = 1 << chroma_log2_weight_denom; 914 int def_chroma_weight = 1 << chroma_log2_weight_denom;
904 915
905 for (int i = 0; i < num_ref_idx_active_minus1 + 1; ++i) { 916 for (int i = 0; i < num_ref_idx_active_minus1 + 1; ++i) {
906 READ_BITS_OR_RETURN(1, &w_facts->luma_weight_flag); 917 READ_BOOL_OR_RETURN(&w_facts->luma_weight_flag);
907 if (w_facts->luma_weight_flag) { 918 if (w_facts->luma_weight_flag) {
908 READ_SE_OR_RETURN(&w_facts->luma_weight[i]); 919 READ_SE_OR_RETURN(&w_facts->luma_weight[i]);
909 IN_RANGE_OR_RETURN(w_facts->luma_weight[i], -128, 127); 920 IN_RANGE_OR_RETURN(w_facts->luma_weight[i], -128, 127);
910 921
911 READ_SE_OR_RETURN(&w_facts->luma_offset[i]); 922 READ_SE_OR_RETURN(&w_facts->luma_offset[i]);
912 IN_RANGE_OR_RETURN(w_facts->luma_offset[i], -128, 127); 923 IN_RANGE_OR_RETURN(w_facts->luma_offset[i], -128, 127);
913 } else { 924 } else {
914 w_facts->luma_weight[i] = def_luma_weight; 925 w_facts->luma_weight[i] = def_luma_weight;
915 w_facts->luma_offset[i] = 0; 926 w_facts->luma_offset[i] = 0;
916 } 927 }
917 928
918 if (chroma_array_type != 0) { 929 if (chroma_array_type != 0) {
919 READ_BITS_OR_RETURN(1, &w_facts->chroma_weight_flag); 930 READ_BOOL_OR_RETURN(&w_facts->chroma_weight_flag);
920 if (w_facts->chroma_weight_flag) { 931 if (w_facts->chroma_weight_flag) {
921 for (int j = 0; j < 2; ++j) { 932 for (int j = 0; j < 2; ++j) {
922 READ_SE_OR_RETURN(&w_facts->chroma_weight[i][j]); 933 READ_SE_OR_RETURN(&w_facts->chroma_weight[i][j]);
923 IN_RANGE_OR_RETURN(w_facts->chroma_weight[i][j], -128, 127); 934 IN_RANGE_OR_RETURN(w_facts->chroma_weight[i][j], -128, 127);
924 935
925 READ_SE_OR_RETURN(&w_facts->chroma_offset[i][j]); 936 READ_SE_OR_RETURN(&w_facts->chroma_offset[i][j]);
926 IN_RANGE_OR_RETURN(w_facts->chroma_offset[i][j], -128, 127); 937 IN_RANGE_OR_RETURN(w_facts->chroma_offset[i][j], -128, 127);
927 } 938 }
928 } else { 939 } else {
929 for (int j = 0; j < 2; ++j) { 940 for (int j = 0; j < 2; ++j) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 &shdr->pred_weight_table_l1); 973 &shdr->pred_weight_table_l1);
963 if (res != kOk) 974 if (res != kOk)
964 return res; 975 return res;
965 } 976 }
966 977
967 return kOk; 978 return kOk;
968 } 979 }
969 980
970 H264Parser::Result H264Parser::ParseDecRefPicMarking(H264SliceHeader *shdr) { 981 H264Parser::Result H264Parser::ParseDecRefPicMarking(H264SliceHeader *shdr) {
971 if (shdr->idr_pic_flag) { 982 if (shdr->idr_pic_flag) {
972 READ_BITS_OR_RETURN(1, &shdr->no_output_of_prior_pics_flag); 983 READ_BOOL_OR_RETURN(&shdr->no_output_of_prior_pics_flag);
973 READ_BITS_OR_RETURN(1, &shdr->long_term_reference_flag); 984 READ_BOOL_OR_RETURN(&shdr->long_term_reference_flag);
974 } else { 985 } else {
975 READ_BITS_OR_RETURN(1, &shdr->adaptive_ref_pic_marking_mode_flag); 986 READ_BOOL_OR_RETURN(&shdr->adaptive_ref_pic_marking_mode_flag);
976 987
977 H264DecRefPicMarking* marking; 988 H264DecRefPicMarking* marking;
978 if (shdr->adaptive_ref_pic_marking_mode_flag) { 989 if (shdr->adaptive_ref_pic_marking_mode_flag) {
979 size_t i; 990 size_t i;
980 for (i = 0; i < arraysize(shdr->ref_pic_marking); ++i) { 991 for (i = 0; i < arraysize(shdr->ref_pic_marking); ++i) {
981 marking = &shdr->ref_pic_marking[i]; 992 marking = &shdr->ref_pic_marking[i];
982 993
983 READ_UE_OR_RETURN(&marking->memory_mgmnt_control_operation); 994 READ_UE_OR_RETURN(&marking->memory_mgmnt_control_operation);
984 if (marking->memory_mgmnt_control_operation == 0) 995 if (marking->memory_mgmnt_control_operation == 0)
985 break; 996 break;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 TRUE_OR_RETURN(sps); 1050 TRUE_OR_RETURN(sps);
1040 1051
1041 if (sps->separate_colour_plane_flag) { 1052 if (sps->separate_colour_plane_flag) {
1042 DVLOG(1) << "Interlaced streams not supported"; 1053 DVLOG(1) << "Interlaced streams not supported";
1043 return kUnsupportedStream; 1054 return kUnsupportedStream;
1044 } 1055 }
1045 1056
1046 READ_BITS_OR_RETURN(sps->log2_max_frame_num_minus4 + 4, 1057 READ_BITS_OR_RETURN(sps->log2_max_frame_num_minus4 + 4,
1047 &shdr->frame_num); 1058 &shdr->frame_num);
1048 if (!sps->frame_mbs_only_flag) { 1059 if (!sps->frame_mbs_only_flag) {
1049 READ_BITS_OR_RETURN(1, &shdr->field_pic_flag); 1060 READ_BOOL_OR_RETURN(&shdr->field_pic_flag);
1050 if (shdr->field_pic_flag) { 1061 if (shdr->field_pic_flag) {
1051 DVLOG(1) << "Interlaced streams not supported"; 1062 DVLOG(1) << "Interlaced streams not supported";
1052 return kUnsupportedStream; 1063 return kUnsupportedStream;
1053 } 1064 }
1054 } 1065 }
1055 1066
1056 if (shdr->idr_pic_flag) 1067 if (shdr->idr_pic_flag)
1057 READ_UE_OR_RETURN(&shdr->idr_pic_id); 1068 READ_UE_OR_RETURN(&shdr->idr_pic_id);
1058 1069
1059 if (sps->pic_order_cnt_type == 0) { 1070 if (sps->pic_order_cnt_type == 0) {
(...skipping 10 matching lines...) Expand all
1070 !shdr->field_pic_flag) 1081 !shdr->field_pic_flag)
1071 READ_SE_OR_RETURN(&shdr->delta_pic_order_cnt[1]); 1082 READ_SE_OR_RETURN(&shdr->delta_pic_order_cnt[1]);
1072 } 1083 }
1073 1084
1074 if (pps->redundant_pic_cnt_present_flag) { 1085 if (pps->redundant_pic_cnt_present_flag) {
1075 READ_UE_OR_RETURN(&shdr->redundant_pic_cnt); 1086 READ_UE_OR_RETURN(&shdr->redundant_pic_cnt);
1076 TRUE_OR_RETURN(shdr->redundant_pic_cnt < 128); 1087 TRUE_OR_RETURN(shdr->redundant_pic_cnt < 128);
1077 } 1088 }
1078 1089
1079 if (shdr->IsBSlice()) 1090 if (shdr->IsBSlice())
1080 READ_BITS_OR_RETURN(1, &shdr->direct_spatial_mv_pred_flag); 1091 READ_BOOL_OR_RETURN(&shdr->direct_spatial_mv_pred_flag);
1081 1092
1082 if (shdr->IsPSlice() || shdr->IsSPSlice() || shdr->IsBSlice()) { 1093 if (shdr->IsPSlice() || shdr->IsSPSlice() || shdr->IsBSlice()) {
1083 READ_BITS_OR_RETURN(1, &shdr->num_ref_idx_active_override_flag); 1094 READ_BOOL_OR_RETURN(&shdr->num_ref_idx_active_override_flag);
1084 if (shdr->num_ref_idx_active_override_flag) { 1095 if (shdr->num_ref_idx_active_override_flag) {
1085 READ_UE_OR_RETURN(&shdr->num_ref_idx_l0_active_minus1); 1096 READ_UE_OR_RETURN(&shdr->num_ref_idx_l0_active_minus1);
1086 if (shdr->IsBSlice()) 1097 if (shdr->IsBSlice())
1087 READ_UE_OR_RETURN(&shdr->num_ref_idx_l1_active_minus1); 1098 READ_UE_OR_RETURN(&shdr->num_ref_idx_l1_active_minus1);
1088 } else { 1099 } else {
1089 shdr->num_ref_idx_l0_active_minus1 = 1100 shdr->num_ref_idx_l0_active_minus1 =
1090 pps->num_ref_idx_l0_default_active_minus1; 1101 pps->num_ref_idx_l0_default_active_minus1;
1091 shdr->num_ref_idx_l1_active_minus1 = 1102 shdr->num_ref_idx_l1_active_minus1 =
1092 pps->num_ref_idx_l1_default_active_minus1; 1103 pps->num_ref_idx_l1_default_active_minus1;
1093 } 1104 }
(...skipping 30 matching lines...) Expand all
1124 if (pps->entropy_coding_mode_flag && 1135 if (pps->entropy_coding_mode_flag &&
1125 !shdr->IsISlice() && !shdr->IsSISlice()) { 1136 !shdr->IsISlice() && !shdr->IsSISlice()) {
1126 READ_UE_OR_RETURN(&shdr->cabac_init_idc); 1137 READ_UE_OR_RETURN(&shdr->cabac_init_idc);
1127 TRUE_OR_RETURN(shdr->cabac_init_idc < 3); 1138 TRUE_OR_RETURN(shdr->cabac_init_idc < 3);
1128 } 1139 }
1129 1140
1130 READ_SE_OR_RETURN(&shdr->slice_qp_delta); 1141 READ_SE_OR_RETURN(&shdr->slice_qp_delta);
1131 1142
1132 if (shdr->IsSPSlice() || shdr->IsSISlice()) { 1143 if (shdr->IsSPSlice() || shdr->IsSISlice()) {
1133 if (shdr->IsSPSlice()) 1144 if (shdr->IsSPSlice())
1134 READ_BITS_OR_RETURN(1, &shdr->sp_for_switch_flag); 1145 READ_BOOL_OR_RETURN(&shdr->sp_for_switch_flag);
1135 READ_SE_OR_RETURN(&shdr->slice_qs_delta); 1146 READ_SE_OR_RETURN(&shdr->slice_qs_delta);
1136 } 1147 }
1137 1148
1138 if (pps->deblocking_filter_control_present_flag) { 1149 if (pps->deblocking_filter_control_present_flag) {
1139 READ_UE_OR_RETURN(&shdr->disable_deblocking_filter_idc); 1150 READ_UE_OR_RETURN(&shdr->disable_deblocking_filter_idc);
1140 TRUE_OR_RETURN(shdr->disable_deblocking_filter_idc < 3); 1151 TRUE_OR_RETURN(shdr->disable_deblocking_filter_idc < 3);
1141 1152
1142 if (shdr->disable_deblocking_filter_idc != 1) { 1153 if (shdr->disable_deblocking_filter_idc != 1) {
1143 READ_SE_OR_RETURN(&shdr->slice_alpha_c0_offset_div2); 1154 READ_SE_OR_RETURN(&shdr->slice_alpha_c0_offset_div2);
1144 IN_RANGE_OR_RETURN(shdr->slice_alpha_c0_offset_div2, -6, 6); 1155 IN_RANGE_OR_RETURN(shdr->slice_alpha_c0_offset_div2, -6, 6);
(...skipping 30 matching lines...) Expand all
1175 READ_BITS_OR_RETURN(8, &byte); 1186 READ_BITS_OR_RETURN(8, &byte);
1176 } 1187 }
1177 sei_msg->payload_size += byte; 1188 sei_msg->payload_size += byte;
1178 1189
1179 DVLOG(4) << "Found SEI message type: " << sei_msg->type 1190 DVLOG(4) << "Found SEI message type: " << sei_msg->type
1180 << " payload size: " << sei_msg->payload_size; 1191 << " payload size: " << sei_msg->payload_size;
1181 1192
1182 switch (sei_msg->type) { 1193 switch (sei_msg->type) {
1183 case H264SEIMessage::kSEIRecoveryPoint: 1194 case H264SEIMessage::kSEIRecoveryPoint:
1184 READ_UE_OR_RETURN(&sei_msg->recovery_point.recovery_frame_cnt); 1195 READ_UE_OR_RETURN(&sei_msg->recovery_point.recovery_frame_cnt);
1185 READ_BITS_OR_RETURN(1, &sei_msg->recovery_point.exact_match_flag); 1196 READ_BOOL_OR_RETURN(&sei_msg->recovery_point.exact_match_flag);
1186 READ_BITS_OR_RETURN(1, &sei_msg->recovery_point.broken_link_flag); 1197 READ_BOOL_OR_RETURN(&sei_msg->recovery_point.broken_link_flag);
1187 READ_BITS_OR_RETURN(2, 1198 READ_BITS_OR_RETURN(2,
1188 &sei_msg->recovery_point.changing_slice_group_idc); 1199 &sei_msg->recovery_point.changing_slice_group_idc);
1189 break; 1200 break;
1190 1201
1191 default: 1202 default:
1192 DVLOG(4) << "Unsupported SEI message"; 1203 DVLOG(4) << "Unsupported SEI message";
1193 break; 1204 break;
1194 } 1205 }
1195 1206
1196 return kOk; 1207 return kOk;
1197 } 1208 }
1198 1209
1199 } // namespace content 1210 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/h264_parser.h ('k') | content/common/gpu/media/mac_video_decode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698