OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 | 8 |
9 #include "media/filters/h264_parser.h" | 9 #include "media/filters/h264_parser.h" |
10 | 10 |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 sps.scaling_list8x8[0], | 572 sps.scaling_list8x8[0], |
573 sps.scaling_list8x8[1], | 573 sps.scaling_list8x8[1], |
574 pps->scaling_list8x8); | 574 pps->scaling_list8x8); |
575 } | 575 } |
576 } | 576 } |
577 } | 577 } |
578 } | 578 } |
579 return kOk; | 579 return kOk; |
580 } | 580 } |
581 | 581 |
| 582 H264Parser::Result H264Parser::ParseAndIgnoreHRDParameters( |
| 583 bool* hrd_parameters_present) { |
| 584 int data; |
| 585 READ_BOOL_OR_RETURN(&data); // {nal,vcl}_hrd_parameters_present_flag |
| 586 if (!data) |
| 587 return kOk; |
| 588 |
| 589 *hrd_parameters_present = true; |
| 590 |
| 591 int cpb_cnt_minus1; |
| 592 READ_UE_OR_RETURN(&cpb_cnt_minus1); |
| 593 IN_RANGE_OR_RETURN(cpb_cnt_minus1, 0, 31); |
| 594 READ_BITS_OR_RETURN(8, &data); // bit_rate_scale, cpb_size_scale |
| 595 for (int i = 0; i <= cpb_cnt_minus1; ++i) { |
| 596 READ_UE_OR_RETURN(&data); // bit_rate_value_minus1[i] |
| 597 READ_UE_OR_RETURN(&data); // cpb_size_value_minus1[i] |
| 598 READ_BOOL_OR_RETURN(&data); // cbr_flag |
| 599 } |
| 600 READ_BITS_OR_RETURN(20, &data); // cpb/dpb delays, etc. |
| 601 |
| 602 return kOk; |
| 603 } |
| 604 |
| 605 H264Parser::Result H264Parser::ParseVUIParameters(H264SPS* sps) { |
| 606 bool aspect_ratio_info_present_flag; |
| 607 READ_BOOL_OR_RETURN(&aspect_ratio_info_present_flag); |
| 608 if (aspect_ratio_info_present_flag) { |
| 609 int aspect_ratio_idc; |
| 610 READ_BITS_OR_RETURN(8, &aspect_ratio_idc); |
| 611 if (aspect_ratio_idc == kExtendedSar) { |
| 612 READ_BITS_OR_RETURN(16, &sps->sar_width); |
| 613 READ_BITS_OR_RETURN(16, &sps->sar_height); |
| 614 } else { |
| 615 const int max_aspect_ratio_idc = arraysize(kTableSarWidth) - 1; |
| 616 IN_RANGE_OR_RETURN(aspect_ratio_idc, 0, max_aspect_ratio_idc); |
| 617 sps->sar_width = kTableSarWidth[aspect_ratio_idc]; |
| 618 sps->sar_height = kTableSarHeight[aspect_ratio_idc]; |
| 619 } |
| 620 } |
| 621 |
| 622 int data; |
| 623 // Read and ignore overscan and video signal type info. |
| 624 READ_BOOL_OR_RETURN(&data); // overscan_info_present_flag |
| 625 if (data) |
| 626 READ_BOOL_OR_RETURN(&data); // overscan_appropriate_flag |
| 627 |
| 628 READ_BOOL_OR_RETURN(&data); // video_signal_type_present_flag |
| 629 if (data) { |
| 630 READ_BITS_OR_RETURN(3, &data); // video_format |
| 631 READ_BOOL_OR_RETURN(&data); // video_full_range_flag |
| 632 READ_BOOL_OR_RETURN(&data); // colour_description_present_flag |
| 633 if (data) |
| 634 READ_BITS_OR_RETURN(24, &data); // color description syntax elements |
| 635 } |
| 636 |
| 637 READ_BOOL_OR_RETURN(&data); // chroma_loc_info_present_flag |
| 638 if (data) { |
| 639 READ_UE_OR_RETURN(&data); // chroma_sample_loc_type_top_field |
| 640 READ_UE_OR_RETURN(&data); // chroma_sample_loc_type_bottom_field |
| 641 } |
| 642 |
| 643 // Read and ignore timing info. |
| 644 READ_BOOL_OR_RETURN(&data); // timing_info_present_flag |
| 645 if (data) { |
| 646 READ_BITS_OR_RETURN(16, &data); // num_units_in_tick |
| 647 READ_BITS_OR_RETURN(16, &data); // num_units_in_tick |
| 648 READ_BITS_OR_RETURN(16, &data); // time_scale |
| 649 READ_BITS_OR_RETURN(16, &data); // time_scale |
| 650 READ_BOOL_OR_RETURN(&data); // fixed_frame_rate_flag |
| 651 } |
| 652 |
| 653 // Read and ignore NAL HRD parameters, if present. |
| 654 bool hrd_parameters_present = false; |
| 655 Result res = ParseAndIgnoreHRDParameters(&hrd_parameters_present); |
| 656 if (res != kOk) |
| 657 return res; |
| 658 |
| 659 // Read and ignore VCL HRD parameters, if present. |
| 660 res = ParseAndIgnoreHRDParameters(&hrd_parameters_present); |
| 661 if (res != kOk) |
| 662 return res; |
| 663 |
| 664 if (hrd_parameters_present) // One of NAL or VCL params present is enough. |
| 665 READ_BOOL_OR_RETURN(&data); // low_delay_hrd_flag |
| 666 |
| 667 READ_BOOL_OR_RETURN(&data); // pic_struct_present_flag |
| 668 READ_BOOL_OR_RETURN(&sps->bitstream_restriction_flag); |
| 669 if (sps->bitstream_restriction_flag) { |
| 670 READ_BOOL_OR_RETURN(&data); // motion_vectors_over_pic_boundaries_flag |
| 671 READ_UE_OR_RETURN(&data); // max_bytes_per_pic_denom |
| 672 READ_UE_OR_RETURN(&data); // max_bits_per_mb_denom |
| 673 READ_UE_OR_RETURN(&data); // log2_max_mv_length_horizontal |
| 674 READ_UE_OR_RETURN(&data); // log2_max_mv_length_vertical |
| 675 READ_UE_OR_RETURN(&sps->max_num_reorder_frames); |
| 676 READ_UE_OR_RETURN(&sps->max_dec_frame_buffering); |
| 677 TRUE_OR_RETURN(sps->max_dec_frame_buffering >= sps->max_num_ref_frames); |
| 678 IN_RANGE_OR_RETURN( |
| 679 sps->max_num_reorder_frames, 0, sps->max_dec_frame_buffering); |
| 680 } |
| 681 |
| 682 return kOk; |
| 683 } |
| 684 |
582 static void FillDefaultSeqScalingLists(H264SPS* sps) { | 685 static void FillDefaultSeqScalingLists(H264SPS* sps) { |
583 for (int i = 0; i < 6; ++i) | 686 for (int i = 0; i < 6; ++i) |
584 for (int j = 0; j < kH264ScalingList4x4Length; ++j) | 687 for (int j = 0; j < kH264ScalingList4x4Length; ++j) |
585 sps->scaling_list4x4[i][j] = 16; | 688 sps->scaling_list4x4[i][j] = 16; |
586 | 689 |
587 for (int i = 0; i < 6; ++i) | 690 for (int i = 0; i < 6; ++i) |
588 for (int j = 0; j < kH264ScalingList8x8Length; ++j) | 691 for (int j = 0; j < kH264ScalingList8x8Length; ++j) |
589 sps->scaling_list8x8[i][j] = 16; | 692 sps->scaling_list8x8[i][j] = 16; |
590 } | 693 } |
591 | 694 |
592 H264Parser::Result H264Parser::ParseSPS(int* sps_id) { | 695 H264Parser::Result H264Parser::ParseSPS(int* sps_id) { |
593 // See 7.4.2.1. | 696 // See 7.4.2.1. |
594 int data; | 697 int data; |
595 Result res; | 698 Result res; |
596 | 699 |
597 *sps_id = -1; | 700 *sps_id = -1; |
598 | 701 |
599 scoped_ptr<H264SPS> sps(new H264SPS()); | 702 scoped_ptr<H264SPS> sps(new H264SPS()); |
600 | 703 |
601 READ_BITS_OR_RETURN(8, &sps->profile_idc); | 704 READ_BITS_OR_RETURN(8, &sps->profile_idc); |
602 READ_BITS_OR_RETURN(6, &sps->constraint_setx_flag); | 705 READ_BOOL_OR_RETURN(&sps->constraint_set0_flag); |
603 READ_BITS_OR_RETURN(2, &data); | 706 READ_BOOL_OR_RETURN(&sps->constraint_set1_flag); |
| 707 READ_BOOL_OR_RETURN(&sps->constraint_set2_flag); |
| 708 READ_BOOL_OR_RETURN(&sps->constraint_set3_flag); |
| 709 READ_BOOL_OR_RETURN(&sps->constraint_set4_flag); |
| 710 READ_BOOL_OR_RETURN(&sps->constraint_set5_flag); |
| 711 READ_BITS_OR_RETURN(2, &data); // reserved_zero_2bits |
604 READ_BITS_OR_RETURN(8, &sps->level_idc); | 712 READ_BITS_OR_RETURN(8, &sps->level_idc); |
605 READ_UE_OR_RETURN(&sps->seq_parameter_set_id); | 713 READ_UE_OR_RETURN(&sps->seq_parameter_set_id); |
606 TRUE_OR_RETURN(sps->seq_parameter_set_id < 32); | 714 TRUE_OR_RETURN(sps->seq_parameter_set_id < 32); |
607 | 715 |
608 if (sps->profile_idc == 100 || sps->profile_idc == 110 || | 716 if (sps->profile_idc == 100 || sps->profile_idc == 110 || |
609 sps->profile_idc == 122 || sps->profile_idc == 244 || | 717 sps->profile_idc == 122 || sps->profile_idc == 244 || |
610 sps->profile_idc == 44 || sps->profile_idc == 83 || | 718 sps->profile_idc == 44 || sps->profile_idc == 83 || |
611 sps->profile_idc == 86 || sps->profile_idc == 118 || | 719 sps->profile_idc == 86 || sps->profile_idc == 118 || |
612 sps->profile_idc == 128) { | 720 sps->profile_idc == 128) { |
613 READ_UE_OR_RETURN(&sps->chroma_format_idc); | 721 READ_UE_OR_RETURN(&sps->chroma_format_idc); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 READ_BOOL_OR_RETURN(&sps->frame_cropping_flag); | 793 READ_BOOL_OR_RETURN(&sps->frame_cropping_flag); |
686 if (sps->frame_cropping_flag) { | 794 if (sps->frame_cropping_flag) { |
687 READ_UE_OR_RETURN(&sps->frame_crop_left_offset); | 795 READ_UE_OR_RETURN(&sps->frame_crop_left_offset); |
688 READ_UE_OR_RETURN(&sps->frame_crop_right_offset); | 796 READ_UE_OR_RETURN(&sps->frame_crop_right_offset); |
689 READ_UE_OR_RETURN(&sps->frame_crop_top_offset); | 797 READ_UE_OR_RETURN(&sps->frame_crop_top_offset); |
690 READ_UE_OR_RETURN(&sps->frame_crop_bottom_offset); | 798 READ_UE_OR_RETURN(&sps->frame_crop_bottom_offset); |
691 } | 799 } |
692 | 800 |
693 READ_BOOL_OR_RETURN(&sps->vui_parameters_present_flag); | 801 READ_BOOL_OR_RETURN(&sps->vui_parameters_present_flag); |
694 if (sps->vui_parameters_present_flag) { | 802 if (sps->vui_parameters_present_flag) { |
695 bool aspect_ratio_info_present_flag; | 803 DVLOG(4) << "VUI parameters present"; |
696 READ_BOOL_OR_RETURN(&aspect_ratio_info_present_flag); | 804 res = ParseVUIParameters(sps.get()); |
697 if (aspect_ratio_info_present_flag) { | 805 if (res != kOk) |
698 int aspect_ratio_idc; | 806 return res; |
699 READ_BITS_OR_RETURN(8, &aspect_ratio_idc); | |
700 if (aspect_ratio_idc == kExtendedSar) { | |
701 READ_BITS_OR_RETURN(16, &sps->sar_width); | |
702 READ_BITS_OR_RETURN(16, &sps->sar_height); | |
703 } else { | |
704 const int max_aspect_ratio_idc = arraysize(kTableSarWidth) - 1; | |
705 IN_RANGE_OR_RETURN(aspect_ratio_idc, 0, max_aspect_ratio_idc); | |
706 sps->sar_width = kTableSarWidth[aspect_ratio_idc]; | |
707 sps->sar_height = kTableSarHeight[aspect_ratio_idc]; | |
708 } | |
709 } | |
710 } | 807 } |
711 | 808 |
712 // If an SPS with the same id already exists, replace it. | 809 // If an SPS with the same id already exists, replace it. |
713 *sps_id = sps->seq_parameter_set_id; | 810 *sps_id = sps->seq_parameter_set_id; |
714 delete active_SPSes_[*sps_id]; | 811 delete active_SPSes_[*sps_id]; |
715 active_SPSes_[*sps_id] = sps.release(); | 812 active_SPSes_[*sps_id] = sps.release(); |
716 | 813 |
717 return kOk; | 814 return kOk; |
718 } | 815 } |
719 | 816 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 | 1255 |
1159 default: | 1256 default: |
1160 DVLOG(4) << "Unsupported SEI message"; | 1257 DVLOG(4) << "Unsupported SEI message"; |
1161 break; | 1258 break; |
1162 } | 1259 } |
1163 | 1260 |
1164 return kOk; | 1261 return kOk; |
1165 } | 1262 } |
1166 | 1263 |
1167 } // namespace media | 1264 } // namespace media |
OLD | NEW |