| 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 "media/formats/mp4/box_definitions.h" | 5 #include "media/formats/mp4/box_definitions.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
| 15 #include "media/base/video_types.h" | 15 #include "media/base/video_types.h" |
| 16 #include "media/base/video_util.h" | 16 #include "media/base/video_util.h" |
| 17 #include "media/filters/h264_parser.h" | 17 #include "media/filters/h264_parser.h" |
| 18 #include "media/formats/mp4/avc.h" | 18 #include "media/formats/mp4/avc.h" |
| 19 #include "media/formats/mp4/es_descriptor.h" | 19 #include "media/formats/mp4/es_descriptor.h" |
| 20 #include "media/formats/mp4/rcheck.h" | 20 #include "media/formats/mp4/rcheck.h" |
| 21 #include "media/media_features.h" | 21 #include "media/media_features.h" |
| 22 | 22 |
| 23 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 24 #include "media/formats/mp4/dolby_vision.h" |
| 25 #endif |
| 26 |
| 23 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 27 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 24 #include "media/formats/mp4/hevc.h" | 28 #include "media/formats/mp4/hevc.h" |
| 25 #endif | 29 #endif |
| 26 | 30 |
| 27 namespace media { | 31 namespace media { |
| 28 namespace mp4 { | 32 namespace mp4 { |
| 29 | 33 |
| 30 namespace { | 34 namespace { |
| 31 | 35 |
| 32 const size_t kKeyIdSize = 16; | 36 const size_t kKeyIdSize = 16; |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 | 703 |
| 700 bool VideoSampleEntry::Parse(BoxReader* reader) { | 704 bool VideoSampleEntry::Parse(BoxReader* reader) { |
| 701 format = reader->type(); | 705 format = reader->type(); |
| 702 RCHECK(reader->SkipBytes(6) && | 706 RCHECK(reader->SkipBytes(6) && |
| 703 reader->Read2(&data_reference_index) && | 707 reader->Read2(&data_reference_index) && |
| 704 reader->SkipBytes(16) && | 708 reader->SkipBytes(16) && |
| 705 reader->Read2(&width) && | 709 reader->Read2(&width) && |
| 706 reader->Read2(&height) && | 710 reader->Read2(&height) && |
| 707 reader->SkipBytes(50)); | 711 reader->SkipBytes(50)); |
| 708 | 712 |
| 709 RCHECK(reader->ScanChildren() && | 713 RCHECK(reader->ScanChildren()); |
| 710 reader->MaybeReadChild(&pixel_aspect)); | 714 if (reader->HasChild(&pixel_aspect)) { |
| 715 RCHECK(reader->MaybeReadChild(&pixel_aspect)); |
| 716 } |
| 711 | 717 |
| 712 if (format == FOURCC_ENCV) { | 718 if (format == FOURCC_ENCV) { |
| 713 // Continue scanning until a recognized protection scheme is found, or until | 719 // Continue scanning until a recognized protection scheme is found, or until |
| 714 // we run out of protection schemes. | 720 // we run out of protection schemes. |
| 715 while (!sinf.HasSupportedScheme()) { | 721 while (!sinf.HasSupportedScheme()) { |
| 716 if (!reader->ReadChild(&sinf)) | 722 if (!reader->ReadChild(&sinf)) |
| 717 return false; | 723 return false; |
| 718 } | 724 } |
| 719 } | 725 } |
| 720 | 726 |
| 721 const FourCC actual_format = | 727 const FourCC actual_format = |
| 722 format == FOURCC_ENCV ? sinf.format.format : format; | 728 format == FOURCC_ENCV ? sinf.format.format : format; |
| 723 switch (actual_format) { | 729 switch (actual_format) { |
| 724 case FOURCC_AVC1: | 730 case FOURCC_AVC1: |
| 725 case FOURCC_AVC3: { | 731 case FOURCC_AVC3: { |
| 726 DVLOG(2) << __func__ << " reading AVCDecoderConfigurationRecord (avcC)"; | 732 DVLOG(2) << __func__ << " reading AVCDecoderConfigurationRecord (avcC)"; |
| 727 std::unique_ptr<AVCDecoderConfigurationRecord> avcConfig( | 733 std::unique_ptr<AVCDecoderConfigurationRecord> avcConfig( |
| 728 new AVCDecoderConfigurationRecord()); | 734 new AVCDecoderConfigurationRecord()); |
| 729 RCHECK(reader->ReadChild(avcConfig.get())); | 735 RCHECK(reader->ReadChild(avcConfig.get())); |
| 730 video_codec = kCodecH264; | 736 video_codec = kCodecH264; |
| 731 video_codec_profile = H264Parser::ProfileIDCToVideoCodecProfile( | 737 video_codec_profile = H264Parser::ProfileIDCToVideoCodecProfile( |
| 732 avcConfig->profile_indication); | 738 avcConfig->profile_indication); |
| 733 frame_bitstream_converter = | 739 frame_bitstream_converter = |
| 734 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); | 740 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); |
| 741 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 742 // It can be Dolby Vision stream if there is DVCC box. |
| 743 DolbyVisionConfiguration dvccConfig; |
| 744 if (reader->HasChild(&dvccConfig) && reader->ReadChild(&dvccConfig)) { |
| 745 DVLOG(2) << __func__ << " reading DolbyVisionConfiguration (dvcC)"; |
| 746 static_cast<AVCBitstreamConverter*>(frame_bitstream_converter.get()) |
| 747 ->DisablePostAnnexbValidation(); |
| 748 video_codec = kCodecDolbyVision; |
| 749 video_codec_profile = dvccConfig.codec_profile; |
| 750 } |
| 751 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 735 break; | 752 break; |
| 736 } | 753 } |
| 737 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 754 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 738 case FOURCC_HEV1: | 755 case FOURCC_HEV1: |
| 739 case FOURCC_HVC1: { | 756 case FOURCC_HVC1: { |
| 740 DVLOG(2) << __func__ << " parsing HEVCDecoderConfigurationRecord (hvcC)"; | 757 DVLOG(2) << __func__ << " parsing HEVCDecoderConfigurationRecord (hvcC)"; |
| 741 std::unique_ptr<HEVCDecoderConfigurationRecord> hevcConfig( | 758 std::unique_ptr<HEVCDecoderConfigurationRecord> hevcConfig( |
| 742 new HEVCDecoderConfigurationRecord()); | 759 new HEVCDecoderConfigurationRecord()); |
| 743 RCHECK(reader->ReadChild(hevcConfig.get())); | 760 RCHECK(reader->ReadChild(hevcConfig.get())); |
| 744 video_codec = kCodecHEVC; | 761 video_codec = kCodecHEVC; |
| 745 video_codec_profile = hevcConfig->GetVideoProfile(); | 762 video_codec_profile = hevcConfig->GetVideoProfile(); |
| 746 frame_bitstream_converter = | 763 frame_bitstream_converter = |
| 747 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); | 764 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); |
| 765 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 766 // It can be Dolby Vision stream if there is DVCC box. |
| 767 DolbyVisionConfiguration dvccConfig; |
| 768 if (reader->HasChild(&dvccConfig) && reader->ReadChild(&dvccConfig)) { |
| 769 DVLOG(2) << __func__ << " reading DolbyVisionConfiguration (dvcC)"; |
| 770 video_codec = kCodecDolbyVision; |
| 771 video_codec_profile = dvccConfig.codec_profile; |
| 772 } |
| 773 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 748 break; | 774 break; |
| 749 } | 775 } |
| 750 #endif | 776 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 777 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 778 case FOURCC_DVA1: |
| 779 case FOURCC_DVAV: { |
| 780 DVLOG(2) << __func__ << " reading AVCDecoderConfigurationRecord (avcC)"; |
| 781 std::unique_ptr<AVCDecoderConfigurationRecord> avcConfig( |
| 782 new AVCDecoderConfigurationRecord()); |
| 783 RCHECK(reader->ReadChild(avcConfig.get())); |
| 784 frame_bitstream_converter = |
| 785 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); |
| 786 DVLOG(2) << __func__ << " reading DolbyVisionConfiguration (dvcC)"; |
| 787 DolbyVisionConfiguration dvccConfig; |
| 788 RCHECK(reader->ReadChild(&dvccConfig)); |
| 789 video_codec = kCodecDolbyVision; |
| 790 video_codec_profile = dvccConfig.codec_profile; |
| 791 break; |
| 792 } |
| 793 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 794 case FOURCC_DVH1: |
| 795 case FOURCC_DVHE: { |
| 796 DVLOG(2) << __func__ << " reading HEVCDecoderConfigurationRecord (hvcC)"; |
| 797 std::unique_ptr<HEVCDecoderConfigurationRecord> hevcConfig( |
| 798 new HEVCDecoderConfigurationRecord()); |
| 799 RCHECK(reader->ReadChild(hevcConfig.get())); |
| 800 frame_bitstream_converter = |
| 801 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); |
| 802 DVLOG(2) << __func__ << " reading DolbyVisionConfiguration (dvcC)"; |
| 803 DolbyVisionConfiguration dvccConfig; |
| 804 RCHECK(reader->ReadChild(&dvccConfig)); |
| 805 video_codec = kCodecDolbyVision; |
| 806 video_codec_profile = dvccConfig.codec_profile; |
| 807 break; |
| 808 } |
| 809 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 810 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 751 case FOURCC_VP09: | 811 case FOURCC_VP09: |
| 752 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 812 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 753 switches::kEnableVp9InMp4)) { | 813 switches::kEnableVp9InMp4)) { |
| 754 DVLOG(2) << __func__ << " parsing VPCodecConfigurationRecord (vpcC)"; | 814 DVLOG(2) << __func__ << " parsing VPCodecConfigurationRecord (vpcC)"; |
| 755 std::unique_ptr<VPCodecConfigurationRecord> vp_config( | 815 std::unique_ptr<VPCodecConfigurationRecord> vp_config( |
| 756 new VPCodecConfigurationRecord()); | 816 new VPCodecConfigurationRecord()); |
| 757 RCHECK(reader->ReadChild(vp_config.get())); | 817 RCHECK(reader->ReadChild(vp_config.get())); |
| 758 frame_bitstream_converter = nullptr; | 818 frame_bitstream_converter = nullptr; |
| 759 video_codec = kCodecVP9; | 819 video_codec = kCodecVP9; |
| 760 video_codec_profile = vp_config->profile; | 820 video_codec_profile = vp_config->profile; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 776 | 836 |
| 777 bool VideoSampleEntry::IsFormatValid() const { | 837 bool VideoSampleEntry::IsFormatValid() const { |
| 778 const FourCC actual_format = | 838 const FourCC actual_format = |
| 779 format == FOURCC_ENCV ? sinf.format.format : format; | 839 format == FOURCC_ENCV ? sinf.format.format : format; |
| 780 switch (actual_format) { | 840 switch (actual_format) { |
| 781 case FOURCC_AVC1: | 841 case FOURCC_AVC1: |
| 782 case FOURCC_AVC3: | 842 case FOURCC_AVC3: |
| 783 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 843 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 784 case FOURCC_HEV1: | 844 case FOURCC_HEV1: |
| 785 case FOURCC_HVC1: | 845 case FOURCC_HVC1: |
| 786 #endif | 846 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 847 case FOURCC_DVH1: |
| 848 case FOURCC_DVHE: |
| 849 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 850 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 851 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 852 case FOURCC_DVA1: |
| 853 case FOURCC_DVAV: |
| 854 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 787 return true; | 855 return true; |
| 788 case FOURCC_VP09: | 856 case FOURCC_VP09: |
| 789 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 857 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 790 switches::kEnableVp9InMp4); | 858 switches::kEnableVp9InMp4); |
| 791 default: | 859 default: |
| 792 return false; | 860 return false; |
| 793 } | 861 } |
| 794 } | 862 } |
| 795 | 863 |
| 796 ElementaryStreamDescriptor::ElementaryStreamDescriptor() | 864 ElementaryStreamDescriptor::ElementaryStreamDescriptor() |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 1468 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( |
| 1401 size_t i) const { | 1469 size_t i) const { |
| 1402 if (i >= sample_depends_on_.size()) | 1470 if (i >= sample_depends_on_.size()) |
| 1403 return kSampleDependsOnUnknown; | 1471 return kSampleDependsOnUnknown; |
| 1404 | 1472 |
| 1405 return sample_depends_on_[i]; | 1473 return sample_depends_on_[i]; |
| 1406 } | 1474 } |
| 1407 | 1475 |
| 1408 } // namespace mp4 | 1476 } // namespace mp4 |
| 1409 } // namespace media | 1477 } // namespace media |
| OLD | NEW |