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

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: Add kCodecHEVC in media/base/android/demuxer_stream_player_params.cc Created 5 years, 5 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
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_util.h"
8 #include "media/formats/mp4/es_descriptor.h" 9 #include "media/formats/mp4/es_descriptor.h"
9 #include "media/formats/mp4/rcheck.h" 10 #include "media/formats/mp4/rcheck.h"
10 11
11 namespace media { 12 namespace media {
12 namespace mp4 { 13 namespace mp4 {
13 14
14 FileType::FileType() {} 15 FileType::FileType() {}
15 FileType::~FileType() {} 16 FileType::~FileType() {}
16 FourCC FileType::BoxType() const { return FOURCC_FTYP; } 17 FourCC FileType::BoxType() const { return FOURCC_FTYP; }
17 18
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 pps_list.resize(num_pps); 456 pps_list.resize(num_pps);
456 for (int i = 0; i < num_pps; i++) { 457 for (int i = 0; i < num_pps; i++) {
457 uint16 pps_length; 458 uint16 pps_length;
458 RCHECK(reader->Read2(&pps_length) && 459 RCHECK(reader->Read2(&pps_length) &&
459 reader->ReadVec(&pps_list[i], pps_length)); 460 reader->ReadVec(&pps_list[i], pps_length));
460 } 461 }
461 462
462 return true; 463 return true;
463 } 464 }
464 465
466 #if defined(ENABLE_HEVC_DEMUXING)
467 HEVCDecoderConfigurationRecord::HEVCDecoderConfigurationRecord()
468 : configurationVersion(0),
469 general_profile_space(0),
470 general_tier_flag(0),
471 general_profile_idc(0),
472 general_profile_compatibility_flags(0),
473 general_constraint_indicator_flags(0),
474 general_level_idc(0),
475 min_spatial_segmentation_idc(0),
476 parallelismType(0),
477 chromaFormat(0),
478 bitDepthLumaMinus8(0),
479 bitDepthChromaMinus8(0),
480 avgFrameRate(0),
481 constantFrameRate(0),
482 numTemporalLayers(0),
483 temporalIdNested(0),
484 lengthSizeMinusOne(0),
485 numOfArrays(0) {}
486
487 HEVCDecoderConfigurationRecord::~HEVCDecoderConfigurationRecord() {}
488 FourCC HEVCDecoderConfigurationRecord::BoxType() const { return FOURCC_HVCC; }
489
490 bool HEVCDecoderConfigurationRecord::Parse(BoxReader* reader) {
491 return ParseInternal(reader, reader->log_cb());
492 }
493
494 bool HEVCDecoderConfigurationRecord::Parse(const uint8* data, int data_size) {
495 BufferReader reader(data, data_size);
496 return ParseInternal(&reader, LogCB());
497 }
498
499 HEVCDecoderConfigurationRecord::HVCCNALArray::HVCCNALArray()
500 : first_byte(0) {}
501
502 HEVCDecoderConfigurationRecord::HVCCNALArray::~HVCCNALArray() {}
503
504 bool HEVCDecoderConfigurationRecord::ParseInternal(BufferReader* reader,
505 const LogCB& log_cb) {
506 uint8 profile_indication = 0;
507 uint32 general_constraint_indicator_flags_hi = 0;
508 uint16 general_constraint_indicator_flags_lo = 0;
509 uint8 misc = 0;
510 RCHECK(reader->Read1(&configurationVersion) && configurationVersion == 1 &&
511 reader->Read1(&profile_indication) &&
512 reader->Read4(&general_profile_compatibility_flags) &&
513 reader->Read4(&general_constraint_indicator_flags_hi) &&
514 reader->Read2(&general_constraint_indicator_flags_lo) &&
515 reader->Read1(&general_level_idc) &&
516 reader->Read2(&min_spatial_segmentation_idc) &&
517 reader->Read1(&parallelismType) &&
518 reader->Read1(&chromaFormat) &&
519 reader->Read1(&bitDepthLumaMinus8) &&
520 reader->Read1(&bitDepthChromaMinus8) &&
521 reader->Read2(&avgFrameRate) &&
522 reader->Read1(&misc) &&
523 reader->Read1(&numOfArrays));
524
525 general_profile_space = profile_indication >> 6;
526 general_tier_flag = (profile_indication >> 5) & 1;
527 general_profile_idc = profile_indication & 0x1f;
528
529 general_constraint_indicator_flags = general_constraint_indicator_flags_hi;
530 general_constraint_indicator_flags <<= 16;
531 general_constraint_indicator_flags |= general_constraint_indicator_flags_lo;
532
533 min_spatial_segmentation_idc &= 0xfff;
534 parallelismType &= 3;
535 chromaFormat &= 3;
536 bitDepthLumaMinus8 &= 7;
537 bitDepthChromaMinus8 &= 7;
538
539 constantFrameRate = misc >> 6;
540 numTemporalLayers = (misc >> 3) & 7;
541 temporalIdNested = (misc >> 2) & 1;
542 lengthSizeMinusOne = misc & 3;
543
544 DVLOG(2) << __FUNCTION__ << " numOfArrays=" << (int)numOfArrays;
545 arrays.resize(numOfArrays);
546 for (uint32 j = 0; j < numOfArrays; j++) {
547 RCHECK(reader->Read1(&arrays[j].first_byte));
548 uint16 numNalus = 0;
549 RCHECK(reader->Read2(&numNalus));
550 arrays[j].units.resize(numNalus);
551 for (uint32 i = 0; i < numNalus; ++i) {
552 uint16 naluLength = 0;
553 RCHECK(reader->Read2(&naluLength) &&
554 reader->ReadVec(&arrays[j].units[i], naluLength));
555 DVLOG(4) << __FUNCTION__ << " naluType="
556 << (int)(arrays[j].first_byte & 0x3f)
557 << " size=" << arrays[j].units[i].size();
558 }
559 }
560
561 if (!log_cb.is_null()) {
562 MEDIA_LOG(INFO, log_cb) << "Video codec: hevc";
563 }
564
565 return true;
566 }
567 #endif
568
465 PixelAspectRatioBox::PixelAspectRatioBox() : h_spacing(1), v_spacing(1) {} 569 PixelAspectRatioBox::PixelAspectRatioBox() : h_spacing(1), v_spacing(1) {}
466 PixelAspectRatioBox::~PixelAspectRatioBox() {} 570 PixelAspectRatioBox::~PixelAspectRatioBox() {}
467 FourCC PixelAspectRatioBox::BoxType() const { return FOURCC_PASP; } 571 FourCC PixelAspectRatioBox::BoxType() const { return FOURCC_PASP; }
468 572
469 bool PixelAspectRatioBox::Parse(BoxReader* reader) { 573 bool PixelAspectRatioBox::Parse(BoxReader* reader) {
470 RCHECK(reader->Read4(&h_spacing) && 574 RCHECK(reader->Read4(&h_spacing) &&
471 reader->Read4(&v_spacing)); 575 reader->Read4(&v_spacing));
472 return true; 576 return true;
473 } 577 }
474 578
(...skipping 24 matching lines...) Expand all
499 603
500 if (format == FOURCC_ENCV) { 604 if (format == FOURCC_ENCV) {
501 // Continue scanning until a recognized protection scheme is found, or until 605 // Continue scanning until a recognized protection scheme is found, or until
502 // we run out of protection schemes. 606 // we run out of protection schemes.
503 while (sinf.type.type != FOURCC_CENC) { 607 while (sinf.type.type != FOURCC_CENC) {
504 if (!reader->ReadChild(&sinf)) 608 if (!reader->ReadChild(&sinf))
505 return false; 609 return false;
506 } 610 }
507 } 611 }
508 612
509 if (IsFormatValid()) 613 VideoCodec codec = kUnknownVideoCodec;
510 RCHECK(reader->ReadChild(&avcc)); 614 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
615 if ((format == FOURCC_AVC1 || format == FOURCC_AVC3) ||
616 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 ||
617 sinf.format.format == FOURCC_AVC3))) {
618 DVLOG(2) << __FUNCTION__
619 << " reading AVCDecoderConfigurationRecord (avcC)";
620 RCHECK(reader->ReadChild(&avcConfig));
621 codec = kCodecH264;
622 profile = H264PROFILE_MAIN;
623 #if defined(ENABLE_HEVC_DEMUXING)
624 } else if ((format == FOURCC_HEV1 || format == FOURCC_HVC1) ||
625 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_HEV1 ||
626 sinf.format.format == FOURCC_HVC1))) {
627 DVLOG(2) << __FUNCTION__
628 << " parsing HEVCDecoderConfigurationRecord (hvcC)";
629 RCHECK(reader->ReadChild(&hevcConfig));
630 codec = kCodecHEVC;
631 #endif
632 } else {
633 // Unknown/unsupported format
634 MEDIA_LOG(ERROR, reader->log_cb()) << __FUNCTION__
635 << " unsupported video format "
636 << FourCCToString(format);
637 return false;
638 }
511 639
640 // TODO(strobe): Recover correct crop box
641 gfx::Size coded_size(width, height);
642 gfx::Rect visible_rect(coded_size);
643 gfx::Size natural_size = GetNaturalSize(visible_rect.size(),
644 pixel_aspect.h_spacing,
645 pixel_aspect.v_spacing);
646 bool is_encrypted = sinf.info.track_encryption.is_encrypted;
647 video_decoder_config_.Initialize(
648 codec, profile, VideoFrame::YV12, VideoFrame::COLOR_SPACE_UNSPECIFIED,
649 coded_size, visible_rect, natural_size,
650 // No decoder-specific buffer needed.
651 // Decoder parameters (SPS/PPS) are embedded in the video stream.
652 NULL, 0, is_encrypted, false);
512 return true; 653 return true;
513 } 654 }
514 655
515 bool VideoSampleEntry::IsFormatValid() const { 656 VideoDecoderConfig VideoSampleEntry::GetVideoDecoderConfig() const {
516 return format == FOURCC_AVC1 || format == FOURCC_AVC3 || 657 return video_decoder_config_;
517 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 ||
518 sinf.format.format == FOURCC_AVC3));
519 } 658 }
520 659
521 ElementaryStreamDescriptor::ElementaryStreamDescriptor() 660 ElementaryStreamDescriptor::ElementaryStreamDescriptor()
522 : object_type(kForbidden) {} 661 : object_type(kForbidden) {}
523 662
524 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} 663 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {}
525 664
526 FourCC ElementaryStreamDescriptor::BoxType() const { 665 FourCC ElementaryStreamDescriptor::BoxType() const {
527 return FOURCC_ESDS; 666 return FOURCC_ESDS;
528 } 667 }
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( 1138 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on(
1000 size_t i) const { 1139 size_t i) const {
1001 if (i >= sample_depends_on_.size()) 1140 if (i >= sample_depends_on_.size())
1002 return kSampleDependsOnUnknown; 1141 return kSampleDependsOnUnknown;
1003 1142
1004 return sample_depends_on_[i]; 1143 return sample_depends_on_[i];
1005 } 1144 }
1006 1145
1007 } // namespace mp4 1146 } // namespace mp4
1008 } // namespace media 1147 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698