 Chromium Code Reviews
 Chromium Code Reviews Issue 2640113004:
  Introduce Dolby Vision video codec and Demuxer support  (Closed)
    
  
    Issue 2640113004:
  Introduce Dolby Vision video codec and Demuxer support  (Closed) 
  | 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_HEVC_DEMUXING) | 23 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 
| 24 #include "media/formats/mp4/hevc.h" | 24 #include "media/formats/mp4/hevc.h" | 
| 25 #endif | 25 #endif | 
| 26 | 26 | 
| 27 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 28 #include "media/formats/mp4/dolby_vision.h" | |
| 
wolenetz
2017/01/25 23:42:42
nit: ordering of include: dolby_vision < hevc alph
 
erickung1
2017/02/03 18:18:31
Done.
 | |
| 29 #endif | |
| 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; | 
| 33 | 37 | 
| 34 } // namespace | 38 } // namespace | 
| 35 | 39 | 
| 36 FileType::FileType() {} | 40 FileType::FileType() {} | 
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 | 697 | 
| 694 bool VideoSampleEntry::Parse(BoxReader* reader) { | 698 bool VideoSampleEntry::Parse(BoxReader* reader) { | 
| 695 format = reader->type(); | 699 format = reader->type(); | 
| 696 RCHECK(reader->SkipBytes(6) && | 700 RCHECK(reader->SkipBytes(6) && | 
| 697 reader->Read2(&data_reference_index) && | 701 reader->Read2(&data_reference_index) && | 
| 698 reader->SkipBytes(16) && | 702 reader->SkipBytes(16) && | 
| 699 reader->Read2(&width) && | 703 reader->Read2(&width) && | 
| 700 reader->Read2(&height) && | 704 reader->Read2(&height) && | 
| 701 reader->SkipBytes(50)); | 705 reader->SkipBytes(50)); | 
| 702 | 706 | 
| 703 RCHECK(reader->ScanChildren() && | 707 RCHECK(reader->ScanChildren()); | 
| 704 reader->MaybeReadChild(&pixel_aspect)); | 708 if (reader->HasChild(&pixel_aspect)) { | 
| 
wolenetz
2017/01/25 23:42:41
Why "maybe", if it has the child? Why didn't previ
 
erickung1
2017/02/03 18:18:32
Done. Remove the code since it was just experiment
 | |
| 709 RCHECK(reader->MaybeReadChild(&pixel_aspect)); | |
| 710 } | |
| 705 | 711 | 
| 706 if (format == FOURCC_ENCV) { | 712 if (format == FOURCC_ENCV) { | 
| 707 // Continue scanning until a recognized protection scheme is found, or until | 713 // Continue scanning until a recognized protection scheme is found, or until | 
| 708 // we run out of protection schemes. | 714 // we run out of protection schemes. | 
| 709 while (!sinf.HasSupportedScheme()) { | 715 while (!sinf.HasSupportedScheme()) { | 
| 710 if (!reader->ReadChild(&sinf)) | 716 if (!reader->ReadChild(&sinf)) | 
| 711 return false; | 717 return false; | 
| 712 } | 718 } | 
| 713 } | 719 } | 
| 714 | 720 | 
| 715 const FourCC actual_format = | 721 const FourCC actual_format = | 
| 716 format == FOURCC_ENCV ? sinf.format.format : format; | 722 format == FOURCC_ENCV ? sinf.format.format : format; | 
| 717 switch (actual_format) { | 723 switch (actual_format) { | 
| 718 case FOURCC_AVC1: | 724 case FOURCC_AVC1: | 
| 719 case FOURCC_AVC3: { | 725 case FOURCC_AVC3: { | 
| 720 DVLOG(2) << __func__ << " reading AVCDecoderConfigurationRecord (avcC)"; | 726 DVLOG(2) << __func__ << " reading AVCDecoderConfigurationRecord (avcC)"; | 
| 721 std::unique_ptr<AVCDecoderConfigurationRecord> avcConfig( | 727 std::unique_ptr<AVCDecoderConfigurationRecord> avcConfig( | 
| 722 new AVCDecoderConfigurationRecord()); | 728 new AVCDecoderConfigurationRecord()); | 
| 723 RCHECK(reader->ReadChild(avcConfig.get())); | 729 RCHECK(reader->ReadChild(avcConfig.get())); | 
| 724 video_codec = kCodecH264; | 730 video_codec = kCodecH264; | 
| 725 video_codec_profile = H264Parser::ProfileIDCToVideoCodecProfile( | 731 video_codec_profile = H264Parser::ProfileIDCToVideoCodecProfile( | 
| 726 avcConfig->profile_indication); | 732 avcConfig->profile_indication); | 
| 727 frame_bitstream_converter = | 733 frame_bitstream_converter = | 
| 728 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); | 734 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); | 
| 735 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 736 // It can be Dolby Vision stream if there is DVCC box. | |
| 737 DolbyVisionConfiguration dvccConfig; | |
| 738 if (reader->HasChild(&dvccConfig) && reader->ReadChild(&dvccConfig)) { | |
| 
wolenetz
2017/01/25 23:42:41
Why not log reading dvcc here?
 
erickung1
2017/02/03 18:18:32
Done.
 | |
| 739 static_cast<AVCBitstreamConverter*>(frame_bitstream_converter.get()) | |
| 740 ->DisablePostAnnexbValidation(); | |
| 
wolenetz
2017/01/25 23:42:41
Comment why, please, and note this is only changin
 | |
| 741 video_codec = kCodecDolbyVision; | |
| 742 video_codec_profile = dvccConfig.codec_profile; | |
| 743 } | |
| 744 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 729 break; | 745 break; | 
| 730 } | 746 } | 
| 731 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 747 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 
| 732 case FOURCC_HEV1: | 748 case FOURCC_HEV1: | 
| 733 case FOURCC_HVC1: { | 749 case FOURCC_HVC1: { | 
| 734 DVLOG(2) << __func__ << " parsing HEVCDecoderConfigurationRecord (hvcC)"; | 750 DVLOG(2) << __func__ << " parsing HEVCDecoderConfigurationRecord (hvcC)"; | 
| 735 std::unique_ptr<HEVCDecoderConfigurationRecord> hevcConfig( | 751 std::unique_ptr<HEVCDecoderConfigurationRecord> hevcConfig( | 
| 736 new HEVCDecoderConfigurationRecord()); | 752 new HEVCDecoderConfigurationRecord()); | 
| 737 RCHECK(reader->ReadChild(hevcConfig.get())); | 753 RCHECK(reader->ReadChild(hevcConfig.get())); | 
| 738 video_codec = kCodecHEVC; | 754 video_codec = kCodecHEVC; | 
| 739 video_codec_profile = hevcConfig->GetVideoProfile(); | 755 video_codec_profile = hevcConfig->GetVideoProfile(); | 
| 740 frame_bitstream_converter = | 756 frame_bitstream_converter = | 
| 741 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); | 757 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); | 
| 758 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 759 // It can be Dolby Vision stream if there is DVCC box. | |
| 760 DolbyVisionConfiguration dvccConfig; | |
| 761 if (reader->HasChild(&dvccConfig) && reader->ReadChild(&dvccConfig)) { | |
| 
wolenetz
2017/01/25 23:42:41
why not DisablePostAnnexbValidation on it here?
 
wolenetz
2017/01/25 23:42:42
Also, why not log reading dvcc here?
 
erickung1
2017/02/03 18:18:31
Done.
 | |
| 762 video_codec = kCodecDolbyVision; | |
| 763 video_codec_profile = dvccConfig.codec_profile; | |
| 764 } | |
| 765 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 742 break; | 766 break; | 
| 743 } | 767 } | 
| 744 #endif | 768 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) | 
| 769 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 770 case FOURCC_DVAV: { | |
| 
wolenetz
2017/01/25 23:42:42
Is there no DVA1 or DVH1 needed?
 
erickung1
2017/02/03 18:18:32
Done.
 | |
| 771 DVLOG(2) << __func__ << " reading AVCDecoderConfigurationRecord (avcC)"; | |
| 772 std::unique_ptr<AVCDecoderConfigurationRecord> avcConfig( | |
| 773 new AVCDecoderConfigurationRecord()); | |
| 774 RCHECK(reader->ReadChild(avcConfig.get())); | |
| 775 frame_bitstream_converter = | |
| 
wolenetz
2017/01/25 23:42:41
Why not DisablePostAnnexbValidation on it here?
 | |
| 776 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); | |
| 777 DVLOG(2) << __func__ << " reading DolbyVisionConfiguration (dvcC)"; | |
| 778 DolbyVisionConfiguration dvccConfig; | |
| 779 RCHECK(reader->ReadChild(&dvccConfig)); | |
| 780 video_codec = kCodecDolbyVision; | |
| 781 video_codec_profile = dvccConfig.codec_profile; | |
| 782 break; | |
| 783 } | |
| 784 case FOURCC_DVHE: { | |
| 785 DVLOG(2) << __func__ << " reading HEVCDecoderConfigurationRecord (hvcC)"; | |
| 786 std::unique_ptr<HEVCDecoderConfigurationRecord> hevcConfig( | |
| 787 new HEVCDecoderConfigurationRecord()); | |
| 788 RCHECK(reader->ReadChild(hevcConfig.get())); | |
| 789 frame_bitstream_converter = | |
| 790 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); | |
| 
wolenetz
2017/01/25 23:42:41
Why not DisablePostAnnexbValidation on it here?
 | |
| 791 DVLOG(2) << __func__ << " reading DolbyVisionConfiguration (dvcC)"; | |
| 792 DolbyVisionConfiguration dvccConfig; | |
| 793 RCHECK(reader->ReadChild(&dvccConfig)); | |
| 794 video_codec = kCodecDolbyVision; | |
| 795 video_codec_profile = dvccConfig.codec_profile; | |
| 796 break; | |
| 797 } | |
| 798 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 745 case FOURCC_VP09: | 799 case FOURCC_VP09: | 
| 746 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 800 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 747 switches::kEnableVp9InMp4)) { | 801 switches::kEnableVp9InMp4)) { | 
| 748 DVLOG(2) << __func__ << " parsing VPCodecConfigurationRecord (vpcC)"; | 802 DVLOG(2) << __func__ << " parsing VPCodecConfigurationRecord (vpcC)"; | 
| 749 std::unique_ptr<VPCodecConfigurationRecord> vp_config( | 803 std::unique_ptr<VPCodecConfigurationRecord> vp_config( | 
| 750 new VPCodecConfigurationRecord()); | 804 new VPCodecConfigurationRecord()); | 
| 751 RCHECK(reader->ReadChild(vp_config.get())); | 805 RCHECK(reader->ReadChild(vp_config.get())); | 
| 752 frame_bitstream_converter = nullptr; | 806 frame_bitstream_converter = nullptr; | 
| 753 video_codec = kCodecVP9; | 807 video_codec = kCodecVP9; | 
| 754 video_codec_profile = vp_config->profile; | 808 video_codec_profile = vp_config->profile; | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 771 bool VideoSampleEntry::IsFormatValid() const { | 825 bool VideoSampleEntry::IsFormatValid() const { | 
| 772 const FourCC actual_format = | 826 const FourCC actual_format = | 
| 773 format == FOURCC_ENCV ? sinf.format.format : format; | 827 format == FOURCC_ENCV ? sinf.format.format : format; | 
| 774 switch (actual_format) { | 828 switch (actual_format) { | 
| 775 case FOURCC_AVC1: | 829 case FOURCC_AVC1: | 
| 776 case FOURCC_AVC3: | 830 case FOURCC_AVC3: | 
| 777 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 831 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 
| 778 case FOURCC_HEV1: | 832 case FOURCC_HEV1: | 
| 779 case FOURCC_HVC1: | 833 case FOURCC_HVC1: | 
| 780 #endif | 834 #endif | 
| 835 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 836 case FOURCC_DVAV: | |
| 
wolenetz
2017/01/25 23:42:41
ditto: DVA1? DVH1?
 
erickung1
2017/02/03 18:18:31
Done.
 | |
| 837 case FOURCC_DVHE: | |
| 838 #endif // BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | |
| 781 return true; | 839 return true; | 
| 782 case FOURCC_VP09: | 840 case FOURCC_VP09: | 
| 783 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 841 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| 784 switches::kEnableVp9InMp4); | 842 switches::kEnableVp9InMp4); | 
| 785 default: | 843 default: | 
| 786 return false; | 844 return false; | 
| 787 } | 845 } | 
| 788 } | 846 } | 
| 789 | 847 | 
| 790 ElementaryStreamDescriptor::ElementaryStreamDescriptor() | 848 ElementaryStreamDescriptor::ElementaryStreamDescriptor() | 
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1368 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 1426 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 
| 1369 size_t i) const { | 1427 size_t i) const { | 
| 1370 if (i >= sample_depends_on_.size()) | 1428 if (i >= sample_depends_on_.size()) | 
| 1371 return kSampleDependsOnUnknown; | 1429 return kSampleDependsOnUnknown; | 
| 1372 | 1430 | 
| 1373 return sample_depends_on_[i]; | 1431 return sample_depends_on_[i]; | 
| 1374 } | 1432 } | 
| 1375 | 1433 | 
| 1376 } // namespace mp4 | 1434 } // namespace mp4 | 
| 1377 } // namespace media | 1435 } // namespace media | 
| OLD | NEW |