Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: media/formats/mp4/box_definitions.cc

Issue 816353010: Implemented HEVC video demuxing and parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved back h265_parser_unittest.cc in media/BUILD.gn Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/formats/mp4/box_definitions.h ('k') | media/formats/mp4/fourccs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/video_types.h"
9 #include "media/base/video_util.h"
10 #include "media/formats/mp4/avc.h"
8 #include "media/formats/mp4/es_descriptor.h" 11 #include "media/formats/mp4/es_descriptor.h"
9 #include "media/formats/mp4/rcheck.h" 12 #include "media/formats/mp4/rcheck.h"
10 13
14 #if defined(ENABLE_HEVC_DEMUXING)
15 #include "media/formats/mp4/hevc.h"
16 #endif
17
11 namespace media { 18 namespace media {
12 namespace mp4 { 19 namespace mp4 {
13 20
14 FileType::FileType() {} 21 FileType::FileType() {}
15 FileType::~FileType() {} 22 FileType::~FileType() {}
16 FourCC FileType::BoxType() const { return FOURCC_FTYP; } 23 FourCC FileType::BoxType() const { return FOURCC_FTYP; }
17 24
18 bool FileType::Parse(BoxReader* reader) { 25 bool FileType::Parse(BoxReader* reader) {
19 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version)); 26 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version));
20 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC); 27 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 bool PixelAspectRatioBox::Parse(BoxReader* reader) { 455 bool PixelAspectRatioBox::Parse(BoxReader* reader) {
449 RCHECK(reader->Read4(&h_spacing) && 456 RCHECK(reader->Read4(&h_spacing) &&
450 reader->Read4(&v_spacing)); 457 reader->Read4(&v_spacing));
451 return true; 458 return true;
452 } 459 }
453 460
454 VideoSampleEntry::VideoSampleEntry() 461 VideoSampleEntry::VideoSampleEntry()
455 : format(FOURCC_NULL), 462 : format(FOURCC_NULL),
456 data_reference_index(0), 463 data_reference_index(0),
457 width(0), 464 width(0),
458 height(0) {} 465 height(0),
466 video_codec(kUnknownVideoCodec),
467 video_codec_profile(VIDEO_CODEC_PROFILE_UNKNOWN) {}
459 468
460 VideoSampleEntry::~VideoSampleEntry() {} 469 VideoSampleEntry::~VideoSampleEntry() {}
461 FourCC VideoSampleEntry::BoxType() const { 470 FourCC VideoSampleEntry::BoxType() const {
462 DCHECK(false) << "VideoSampleEntry should be parsed according to the " 471 DCHECK(false) << "VideoSampleEntry should be parsed according to the "
463 << "handler type recovered in its Media ancestor."; 472 << "handler type recovered in its Media ancestor.";
464 return FOURCC_NULL; 473 return FOURCC_NULL;
465 } 474 }
466 475
476 namespace {
477
478 bool IsFormatValidH264(const FourCC& format,
479 const ProtectionSchemeInfo& sinf) {
480 return format == FOURCC_AVC1 || format == FOURCC_AVC3 ||
481 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 ||
482 sinf.format.format == FOURCC_AVC3));
483 }
484
485 #if defined(ENABLE_HEVC_DEMUXING)
486 bool IsFormatValidHEVC(const FourCC& format,
487 const ProtectionSchemeInfo& sinf) {
488 return format == FOURCC_HEV1 || format == FOURCC_HVC1 ||
489 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_HEV1 ||
490 sinf.format.format == FOURCC_HVC1));
491 }
492 #endif
493
494 }
495
467 bool VideoSampleEntry::Parse(BoxReader* reader) { 496 bool VideoSampleEntry::Parse(BoxReader* reader) {
468 format = reader->type(); 497 format = reader->type();
469 RCHECK(reader->SkipBytes(6) && 498 RCHECK(reader->SkipBytes(6) &&
470 reader->Read2(&data_reference_index) && 499 reader->Read2(&data_reference_index) &&
471 reader->SkipBytes(16) && 500 reader->SkipBytes(16) &&
472 reader->Read2(&width) && 501 reader->Read2(&width) &&
473 reader->Read2(&height) && 502 reader->Read2(&height) &&
474 reader->SkipBytes(50)); 503 reader->SkipBytes(50));
475 504
476 RCHECK(reader->ScanChildren() && 505 RCHECK(reader->ScanChildren() &&
477 reader->MaybeReadChild(&pixel_aspect)); 506 reader->MaybeReadChild(&pixel_aspect));
478 507
479 if (format == FOURCC_ENCV) { 508 if (format == FOURCC_ENCV) {
480 // Continue scanning until a recognized protection scheme is found, or until 509 // Continue scanning until a recognized protection scheme is found, or until
481 // we run out of protection schemes. 510 // we run out of protection schemes.
482 while (sinf.type.type != FOURCC_CENC) { 511 while (sinf.type.type != FOURCC_CENC) {
483 if (!reader->ReadChild(&sinf)) 512 if (!reader->ReadChild(&sinf))
484 return false; 513 return false;
485 } 514 }
486 } 515 }
487 516
488 if (IsFormatValid()) { 517 if (IsFormatValidH264(format, sinf)) {
518 DVLOG(2) << __FUNCTION__
519 << " reading AVCDecoderConfigurationRecord (avcC)";
489 scoped_ptr<AVCDecoderConfigurationRecord> avcConfig( 520 scoped_ptr<AVCDecoderConfigurationRecord> avcConfig(
490 new AVCDecoderConfigurationRecord()); 521 new AVCDecoderConfigurationRecord());
491 RCHECK(reader->ReadChild(avcConfig.get())); 522 RCHECK(reader->ReadChild(avcConfig.get()));
492 frame_bitstream_converter = make_scoped_refptr( 523 frame_bitstream_converter = make_scoped_refptr(
493 new AVCBitstreamConverter(avcConfig.Pass())); 524 new AVCBitstreamConverter(avcConfig.Pass()));
525 video_codec = kCodecH264;
526 video_codec_profile = H264PROFILE_MAIN;
527 #if defined(ENABLE_HEVC_DEMUXING)
528 } else if (IsFormatValidHEVC(format, sinf)) {
529 DVLOG(2) << __FUNCTION__
530 << " parsing HEVCDecoderConfigurationRecord (hvcC)";
531 scoped_ptr<HEVCDecoderConfigurationRecord> hevcConfig(
532 new HEVCDecoderConfigurationRecord());
533 RCHECK(reader->ReadChild(hevcConfig.get()));
534 frame_bitstream_converter = make_scoped_refptr(
535 new HEVCBitstreamConverter(hevcConfig.Pass()));
536 video_codec = kCodecHEVC;
537 #endif
538 } else {
539 // Unknown/unsupported format
540 MEDIA_LOG(ERROR, reader->media_log()) << __FUNCTION__
541 << " unsupported video format "
542 << FourCCToString(format);
543 return false;
494 } 544 }
495 545
496 return true; 546 return true;
497 } 547 }
498 548
499 bool VideoSampleEntry::IsFormatValid() const { 549 bool VideoSampleEntry::IsFormatValid() const {
500 return format == FOURCC_AVC1 || format == FOURCC_AVC3 || 550 #if defined(ENABLE_HEVC_DEMUXING)
501 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 || 551 if (IsFormatValidHEVC(format, sinf))
502 sinf.format.format == FOURCC_AVC3)); 552 return true;
553 #endif
554 return IsFormatValidH264(format, sinf);
503 } 555 }
504 556
505 ElementaryStreamDescriptor::ElementaryStreamDescriptor() 557 ElementaryStreamDescriptor::ElementaryStreamDescriptor()
506 : object_type(kForbidden) {} 558 : object_type(kForbidden) {}
507 559
508 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} 560 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {}
509 561
510 FourCC ElementaryStreamDescriptor::BoxType() const { 562 FourCC ElementaryStreamDescriptor::BoxType() const {
511 return FOURCC_ESDS; 563 return FOURCC_ESDS;
512 } 564 }
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( 1039 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on(
988 size_t i) const { 1040 size_t i) const {
989 if (i >= sample_depends_on_.size()) 1041 if (i >= sample_depends_on_.size())
990 return kSampleDependsOnUnknown; 1042 return kSampleDependsOnUnknown;
991 1043
992 return sample_depends_on_[i]; 1044 return sample_depends_on_[i];
993 } 1045 }
994 1046
995 } // namespace mp4 1047 } // namespace mp4
996 } // namespace media 1048 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/mp4/box_definitions.h ('k') | media/formats/mp4/fourccs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698