| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 587 |
| 588 VideoSampleEntry::VideoSampleEntry(const VideoSampleEntry& other) = default; | 588 VideoSampleEntry::VideoSampleEntry(const VideoSampleEntry& other) = default; |
| 589 | 589 |
| 590 VideoSampleEntry::~VideoSampleEntry() {} | 590 VideoSampleEntry::~VideoSampleEntry() {} |
| 591 FourCC VideoSampleEntry::BoxType() const { | 591 FourCC VideoSampleEntry::BoxType() const { |
| 592 DCHECK(false) << "VideoSampleEntry should be parsed according to the " | 592 DCHECK(false) << "VideoSampleEntry should be parsed according to the " |
| 593 << "handler type recovered in its Media ancestor."; | 593 << "handler type recovered in its Media ancestor."; |
| 594 return FOURCC_NULL; | 594 return FOURCC_NULL; |
| 595 } | 595 } |
| 596 | 596 |
| 597 namespace { | |
| 598 | |
| 599 bool IsFormatValidH264(const FourCC& format, | |
| 600 const ProtectionSchemeInfo& sinf) { | |
| 601 return format == FOURCC_AVC1 || format == FOURCC_AVC3 || | |
| 602 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 || | |
| 603 sinf.format.format == FOURCC_AVC3)); | |
| 604 } | |
| 605 | |
| 606 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | |
| 607 bool IsFormatValidHEVC(const FourCC& format, | |
| 608 const ProtectionSchemeInfo& sinf) { | |
| 609 return format == FOURCC_HEV1 || format == FOURCC_HVC1 || | |
| 610 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_HEV1 || | |
| 611 sinf.format.format == FOURCC_HVC1)); | |
| 612 } | |
| 613 #endif | |
| 614 | |
| 615 } | |
| 616 | |
| 617 bool VideoSampleEntry::Parse(BoxReader* reader) { | 597 bool VideoSampleEntry::Parse(BoxReader* reader) { |
| 618 format = reader->type(); | 598 format = reader->type(); |
| 619 RCHECK(reader->SkipBytes(6) && | 599 RCHECK(reader->SkipBytes(6) && |
| 620 reader->Read2(&data_reference_index) && | 600 reader->Read2(&data_reference_index) && |
| 621 reader->SkipBytes(16) && | 601 reader->SkipBytes(16) && |
| 622 reader->Read2(&width) && | 602 reader->Read2(&width) && |
| 623 reader->Read2(&height) && | 603 reader->Read2(&height) && |
| 624 reader->SkipBytes(50)); | 604 reader->SkipBytes(50)); |
| 625 | 605 |
| 626 RCHECK(reader->ScanChildren() && | 606 RCHECK(reader->ScanChildren() && |
| 627 reader->MaybeReadChild(&pixel_aspect)); | 607 reader->MaybeReadChild(&pixel_aspect)); |
| 628 | 608 |
| 629 if (format == FOURCC_ENCV) { | 609 if (format == FOURCC_ENCV) { |
| 630 // Continue scanning until a recognized protection scheme is found, or until | 610 // Continue scanning until a recognized protection scheme is found, or until |
| 631 // we run out of protection schemes. | 611 // we run out of protection schemes. |
| 632 while (sinf.type.type != FOURCC_CENC) { | 612 while (sinf.type.type != FOURCC_CENC) { |
| 633 if (!reader->ReadChild(&sinf)) | 613 if (!reader->ReadChild(&sinf)) |
| 634 return false; | 614 return false; |
| 635 } | 615 } |
| 636 } | 616 } |
| 637 | 617 |
| 638 if (IsFormatValidH264(format, sinf)) { | 618 const FourCC actual_format = |
| 639 DVLOG(2) << __FUNCTION__ | 619 format == FOURCC_ENCV ? sinf.format.format : format; |
| 640 << " reading AVCDecoderConfigurationRecord (avcC)"; | 620 switch (actual_format) { |
| 641 std::unique_ptr<AVCDecoderConfigurationRecord> avcConfig( | 621 case FOURCC_AVC1: |
| 642 new AVCDecoderConfigurationRecord()); | 622 case FOURCC_AVC3: { |
| 643 RCHECK(reader->ReadChild(avcConfig.get())); | 623 DVLOG(2) << __FUNCTION__ |
| 644 frame_bitstream_converter = | 624 << " reading AVCDecoderConfigurationRecord (avcC)"; |
| 645 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); | 625 std::unique_ptr<AVCDecoderConfigurationRecord> avcConfig( |
| 646 video_codec = kCodecH264; | 626 new AVCDecoderConfigurationRecord()); |
| 647 video_codec_profile = H264PROFILE_MAIN; | 627 RCHECK(reader->ReadChild(avcConfig.get())); |
| 628 frame_bitstream_converter = |
| 629 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); |
| 630 video_codec = kCodecH264; |
| 631 video_codec_profile = H264PROFILE_MAIN; |
| 632 break; |
| 633 } |
| 648 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 634 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 649 } else if (IsFormatValidHEVC(format, sinf)) { | 635 case FOURCC_HEV1: |
| 650 DVLOG(2) << __FUNCTION__ | 636 case FOURCC_HVC1: { |
| 651 << " parsing HEVCDecoderConfigurationRecord (hvcC)"; | 637 DVLOG(2) << __FUNCTION__ |
| 652 std::unique_ptr<HEVCDecoderConfigurationRecord> hevcConfig( | 638 << " parsing HEVCDecoderConfigurationRecord (hvcC)"; |
| 653 new HEVCDecoderConfigurationRecord()); | 639 std::unique_ptr<HEVCDecoderConfigurationRecord> hevcConfig( |
| 654 RCHECK(reader->ReadChild(hevcConfig.get())); | 640 new HEVCDecoderConfigurationRecord()); |
| 655 frame_bitstream_converter = | 641 RCHECK(reader->ReadChild(hevcConfig.get())); |
| 656 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); | 642 frame_bitstream_converter = |
| 657 video_codec = kCodecHEVC; | 643 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); |
| 644 video_codec = kCodecHEVC; |
| 645 break; |
| 646 } |
| 658 #endif | 647 #endif |
| 659 } else { | 648 #if BUILDFLAG(ENABLE_MP4_VP9_DEMUXING) |
| 660 // Unknown/unsupported format | 649 case FOURCC_VP09: |
| 661 MEDIA_LOG(ERROR, reader->media_log()) << __FUNCTION__ | 650 frame_bitstream_converter = NULL; |
| 662 << " unsupported video format " | 651 video_codec = kCodecVP9; |
| 663 << FourCCToString(format); | 652 // TODO(kqyang): Read VPCodecConfiguration and extract profile |
| 664 return false; | 653 // (crbug.com/604863). |
| 654 break; |
| 655 #endif |
| 656 default: |
| 657 // Unknown/unsupported format |
| 658 MEDIA_LOG(ERROR, reader->media_log()) << __FUNCTION__ |
| 659 << " unsupported video format " |
| 660 << FourCCToString(actual_format); |
| 661 return false; |
| 665 } | 662 } |
| 666 | 663 |
| 667 return true; | 664 return true; |
| 668 } | 665 } |
| 669 | 666 |
| 670 bool VideoSampleEntry::IsFormatValid() const { | 667 bool VideoSampleEntry::IsFormatValid() const { |
| 668 const FourCC actual_format = |
| 669 format == FOURCC_ENCV ? sinf.format.format : format; |
| 670 switch (actual_format) { |
| 671 case FOURCC_AVC1: |
| 672 case FOURCC_AVC3: |
| 671 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 673 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 672 if (IsFormatValidHEVC(format, sinf)) | 674 case FOURCC_HEV1: |
| 673 return true; | 675 case FOURCC_HVC1: |
| 674 #endif | 676 #endif |
| 675 return IsFormatValidH264(format, sinf); | 677 #if BUILDFLAG(ENABLE_MP4_VP9_DEMUXING) |
| 678 case FOURCC_VP09: |
| 679 #endif |
| 680 return true; |
| 681 default: |
| 682 return false; |
| 683 } |
| 676 } | 684 } |
| 677 | 685 |
| 678 ElementaryStreamDescriptor::ElementaryStreamDescriptor() | 686 ElementaryStreamDescriptor::ElementaryStreamDescriptor() |
| 679 : object_type(kForbidden) {} | 687 : object_type(kForbidden) {} |
| 680 | 688 |
| 681 ElementaryStreamDescriptor::ElementaryStreamDescriptor( | 689 ElementaryStreamDescriptor::ElementaryStreamDescriptor( |
| 682 const ElementaryStreamDescriptor& other) = default; | 690 const ElementaryStreamDescriptor& other) = default; |
| 683 | 691 |
| 684 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} | 692 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} |
| 685 | 693 |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 1224 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( |
| 1217 size_t i) const { | 1225 size_t i) const { |
| 1218 if (i >= sample_depends_on_.size()) | 1226 if (i >= sample_depends_on_.size()) |
| 1219 return kSampleDependsOnUnknown; | 1227 return kSampleDependsOnUnknown; |
| 1220 | 1228 |
| 1221 return sample_depends_on_[i]; | 1229 return sample_depends_on_[i]; |
| 1222 } | 1230 } |
| 1223 | 1231 |
| 1224 } // namespace mp4 | 1232 } // namespace mp4 |
| 1225 } // namespace media | 1233 } // namespace media |
| OLD | NEW |