| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/base/video_types.h" | 10 #include "media/base/video_types.h" |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 video_codec(kUnknownVideoCodec), | 469 video_codec(kUnknownVideoCodec), |
| 470 video_codec_profile(VIDEO_CODEC_PROFILE_UNKNOWN) {} | 470 video_codec_profile(VIDEO_CODEC_PROFILE_UNKNOWN) {} |
| 471 | 471 |
| 472 VideoSampleEntry::~VideoSampleEntry() {} | 472 VideoSampleEntry::~VideoSampleEntry() {} |
| 473 FourCC VideoSampleEntry::BoxType() const { | 473 FourCC VideoSampleEntry::BoxType() const { |
| 474 DCHECK(false) << "VideoSampleEntry should be parsed according to the " | 474 DCHECK(false) << "VideoSampleEntry should be parsed according to the " |
| 475 << "handler type recovered in its Media ancestor."; | 475 << "handler type recovered in its Media ancestor."; |
| 476 return FOURCC_NULL; | 476 return FOURCC_NULL; |
| 477 } | 477 } |
| 478 | 478 |
| 479 namespace { | |
| 480 | |
| 481 bool IsFormatValidH264(const FourCC& format, | |
| 482 const ProtectionSchemeInfo& sinf) { | |
| 483 return format == FOURCC_AVC1 || format == FOURCC_AVC3 || | |
| 484 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 || | |
| 485 sinf.format.format == FOURCC_AVC3)); | |
| 486 } | |
| 487 | |
| 488 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | |
| 489 bool IsFormatValidHEVC(const FourCC& format, | |
| 490 const ProtectionSchemeInfo& sinf) { | |
| 491 return format == FOURCC_HEV1 || format == FOURCC_HVC1 || | |
| 492 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_HEV1 || | |
| 493 sinf.format.format == FOURCC_HVC1)); | |
| 494 } | |
| 495 #endif | |
| 496 | |
| 497 } | |
| 498 | |
| 499 bool VideoSampleEntry::Parse(BoxReader* reader) { | 479 bool VideoSampleEntry::Parse(BoxReader* reader) { |
| 500 format = reader->type(); | 480 format = reader->type(); |
| 501 RCHECK(reader->SkipBytes(6) && | 481 RCHECK(reader->SkipBytes(6) && |
| 502 reader->Read2(&data_reference_index) && | 482 reader->Read2(&data_reference_index) && |
| 503 reader->SkipBytes(16) && | 483 reader->SkipBytes(16) && |
| 504 reader->Read2(&width) && | 484 reader->Read2(&width) && |
| 505 reader->Read2(&height) && | 485 reader->Read2(&height) && |
| 506 reader->SkipBytes(50)); | 486 reader->SkipBytes(50)); |
| 507 | 487 |
| 508 RCHECK(reader->ScanChildren() && | 488 RCHECK(reader->ScanChildren() && |
| 509 reader->MaybeReadChild(&pixel_aspect)); | 489 reader->MaybeReadChild(&pixel_aspect)); |
| 510 | 490 |
| 511 if (format == FOURCC_ENCV) { | 491 if (format == FOURCC_ENCV) { |
| 512 // Continue scanning until a recognized protection scheme is found, or until | 492 // Continue scanning until a recognized protection scheme is found, or until |
| 513 // we run out of protection schemes. | 493 // we run out of protection schemes. |
| 514 while (sinf.type.type != FOURCC_CENC) { | 494 while (sinf.type.type != FOURCC_CENC) { |
| 515 if (!reader->ReadChild(&sinf)) | 495 if (!reader->ReadChild(&sinf)) |
| 516 return false; | 496 return false; |
| 517 } | 497 } |
| 518 } | 498 } |
| 519 | 499 |
| 520 if (IsFormatValidH264(format, sinf)) { | 500 const FourCC actual_format = |
| 521 DVLOG(2) << __FUNCTION__ | 501 format == FOURCC_ENCV ? sinf.format.format : format; |
| 522 << " reading AVCDecoderConfigurationRecord (avcC)"; | 502 switch (actual_format) { |
| 523 scoped_ptr<AVCDecoderConfigurationRecord> avcConfig( | 503 case FOURCC_AVC1: |
| 524 new AVCDecoderConfigurationRecord()); | 504 case FOURCC_AVC3: { |
| 525 RCHECK(reader->ReadChild(avcConfig.get())); | 505 DVLOG(2) << __FUNCTION__ |
| 526 frame_bitstream_converter = | 506 << " reading AVCDecoderConfigurationRecord (avcC)"; |
| 527 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); | 507 scoped_ptr<AVCDecoderConfigurationRecord> avcConfig( |
| 528 video_codec = kCodecH264; | 508 new AVCDecoderConfigurationRecord()); |
| 529 video_codec_profile = H264PROFILE_MAIN; | 509 RCHECK(reader->ReadChild(avcConfig.get())); |
| 510 frame_bitstream_converter = |
| 511 make_scoped_refptr(new AVCBitstreamConverter(std::move(avcConfig))); |
| 512 video_codec = kCodecH264; |
| 513 video_codec_profile = H264PROFILE_MAIN; |
| 514 break; |
| 515 } |
| 530 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 516 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 531 } else if (IsFormatValidHEVC(format, sinf)) { | 517 case FOURCC_HEV1: |
| 532 DVLOG(2) << __FUNCTION__ | 518 case FOURCC_HVC1: { |
| 533 << " parsing HEVCDecoderConfigurationRecord (hvcC)"; | 519 DVLOG(2) << __FUNCTION__ |
| 534 scoped_ptr<HEVCDecoderConfigurationRecord> hevcConfig( | 520 << " parsing HEVCDecoderConfigurationRecord (hvcC)"; |
| 535 new HEVCDecoderConfigurationRecord()); | 521 scoped_ptr<HEVCDecoderConfigurationRecord> hevcConfig( |
| 536 RCHECK(reader->ReadChild(hevcConfig.get())); | 522 new HEVCDecoderConfigurationRecord()); |
| 537 frame_bitstream_converter = | 523 RCHECK(reader->ReadChild(hevcConfig.get())); |
| 538 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); | 524 frame_bitstream_converter = |
| 539 video_codec = kCodecHEVC; | 525 make_scoped_refptr(new HEVCBitstreamConverter(std::move(hevcConfig))); |
| 526 video_codec = kCodecHEVC; |
| 527 break; |
| 528 } |
| 540 #endif | 529 #endif |
| 541 } else { | 530 #if BUILDFLAG(ENABLE_MP4_VP8_VP9_DEMUXING) |
| 542 // Unknown/unsupported format | 531 case FOURCC_VP08: |
| 543 MEDIA_LOG(ERROR, reader->media_log()) << __FUNCTION__ | 532 frame_bitstream_converter = NULL; |
| 544 << " unsupported video format " | 533 video_codec = kCodecVP8; |
| 545 << FourCCToString(format); | 534 video_codec_profile = VP8PROFILE_ANY; |
| 546 return false; | 535 break; |
| 536 case FOURCC_VP09: |
| 537 frame_bitstream_converter = NULL; |
| 538 video_codec = kCodecVP9; |
| 539 video_codec_profile = VP9PROFILE_ANY; |
| 540 break; |
| 541 #endif |
| 542 default: |
| 543 // Unknown/unsupported format |
| 544 MEDIA_LOG(ERROR, reader->media_log()) << __FUNCTION__ |
| 545 << " unsupported video format " |
| 546 << FourCCToString(actual_format); |
| 547 return false; |
| 547 } | 548 } |
| 548 | 549 |
| 549 return true; | 550 return true; |
| 550 } | 551 } |
| 551 | 552 |
| 552 bool VideoSampleEntry::IsFormatValid() const { | 553 bool VideoSampleEntry::IsFormatValid() const { |
| 554 const FourCC actual_format = |
| 555 format == FOURCC_ENCV ? sinf.format.format : format; |
| 556 switch (actual_format) { |
| 557 case FOURCC_AVC1: |
| 558 case FOURCC_AVC3: |
| 553 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 559 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 554 if (IsFormatValidHEVC(format, sinf)) | 560 case FOURCC_HEV1: |
| 555 return true; | 561 case FOURCC_HVC1: |
| 556 #endif | 562 #endif |
| 557 return IsFormatValidH264(format, sinf); | 563 #if BUILDFLAG(ENABLE_MP4_VP8_VP9_DEMUXING) |
| 564 case FOURCC_VP08: |
| 565 case FOURCC_VP09: |
| 566 #endif |
| 567 return true; |
| 568 default: |
| 569 return false; |
| 570 } |
| 558 } | 571 } |
| 559 | 572 |
| 560 ElementaryStreamDescriptor::ElementaryStreamDescriptor() | 573 ElementaryStreamDescriptor::ElementaryStreamDescriptor() |
| 561 : object_type(kForbidden) {} | 574 : object_type(kForbidden) {} |
| 562 | 575 |
| 563 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} | 576 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} |
| 564 | 577 |
| 565 FourCC ElementaryStreamDescriptor::BoxType() const { | 578 FourCC ElementaryStreamDescriptor::BoxType() const { |
| 566 return FOURCC_ESDS; | 579 return FOURCC_ESDS; |
| 567 } | 580 } |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 1055 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( |
| 1043 size_t i) const { | 1056 size_t i) const { |
| 1044 if (i >= sample_depends_on_.size()) | 1057 if (i >= sample_depends_on_.size()) |
| 1045 return kSampleDependsOnUnknown; | 1058 return kSampleDependsOnUnknown; |
| 1046 | 1059 |
| 1047 return sample_depends_on_[i]; | 1060 return sample_depends_on_[i]; |
| 1048 } | 1061 } |
| 1049 | 1062 |
| 1050 } // namespace mp4 | 1063 } // namespace mp4 |
| 1051 } // namespace media | 1064 } // namespace media |
| OLD | NEW |