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

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: Rebase to ToT Created 5 years, 7 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 pps_list.resize(num_pps); 407 pps_list.resize(num_pps);
407 for (int i = 0; i < num_pps; i++) { 408 for (int i = 0; i < num_pps; i++) {
408 uint16 pps_length; 409 uint16 pps_length;
409 RCHECK(reader->Read2(&pps_length) && 410 RCHECK(reader->Read2(&pps_length) &&
410 reader->ReadVec(&pps_list[i], pps_length)); 411 reader->ReadVec(&pps_list[i], pps_length));
411 } 412 }
412 413
413 return true; 414 return true;
414 } 415 }
415 416
417 #if defined(ENABLE_HEVC_DEMUXING)
418 HEVCDecoderConfigurationRecord::HEVCDecoderConfigurationRecord()
419 : configurationVersion(0),
420 general_profile_space(0),
421 general_tier_flag(0),
422 general_profile_idc(0),
423 general_profile_compatibility_flags(0),
424 general_constraint_indicator_flags(0),
425 general_level_idc(0),
426 min_spatial_segmentation_idc(0),
427 parallelismType(0),
428 chromaFormat(0),
429 bitDepthLumaMinus8(0),
430 bitDepthChromaMinus8(0),
431 avgFrameRate(0),
432 constantFrameRate(0),
433 numTemporalLayers(0),
434 temporalIdNested(0),
435 lengthSizeMinusOne(0),
436 numOfArrays(0) {}
437
438 HEVCDecoderConfigurationRecord::~HEVCDecoderConfigurationRecord() {}
439 FourCC HEVCDecoderConfigurationRecord::BoxType() const { return FOURCC_HVCC; }
440
441 bool HEVCDecoderConfigurationRecord::Parse(BoxReader* reader) {
442 return ParseInternal(reader, reader->log_cb());
443 }
444
445 bool HEVCDecoderConfigurationRecord::Parse(const uint8* data, int data_size) {
446 BufferReader reader(data, data_size);
447 return ParseInternal(&reader, LogCB());
448 }
449
450 HEVCDecoderConfigurationRecord::HVCCNALArray::HVCCNALArray()
451 : first_byte(0) {}
452
453 HEVCDecoderConfigurationRecord::HVCCNALArray::~HVCCNALArray() {}
454
455 bool HEVCDecoderConfigurationRecord::ParseInternal(BufferReader* reader,
456 const LogCB& log_cb) {
457 uint8 profile_indication = 0;
458 uint32 general_constraint_indicator_flags_hi = 0;
459 uint16 general_constraint_indicator_flags_lo = 0;
460 uint8 misc = 0;
461 RCHECK(reader->Read1(&configurationVersion) && configurationVersion == 1 &&
462 reader->Read1(&profile_indication) &&
463 reader->Read4(&general_profile_compatibility_flags) &&
464 reader->Read4(&general_constraint_indicator_flags_hi) &&
465 reader->Read2(&general_constraint_indicator_flags_lo) &&
466 reader->Read1(&general_level_idc) &&
467 reader->Read2(&min_spatial_segmentation_idc) &&
468 reader->Read1(&parallelismType) &&
469 reader->Read1(&chromaFormat) &&
470 reader->Read1(&bitDepthLumaMinus8) &&
471 reader->Read1(&bitDepthChromaMinus8) &&
472 reader->Read2(&avgFrameRate) &&
473 reader->Read1(&misc) &&
474 reader->Read1(&numOfArrays));
475
476 general_profile_space = profile_indication >> 6;
477 general_tier_flag = (profile_indication >> 5) & 1;
478 general_profile_idc = profile_indication & 0x1f;
479
480 general_constraint_indicator_flags = general_constraint_indicator_flags_hi;
481 general_constraint_indicator_flags <<= 16;
482 general_constraint_indicator_flags |= general_constraint_indicator_flags_lo;
483
484 min_spatial_segmentation_idc &= 0xfff;
485 parallelismType &= 3;
486 chromaFormat &= 3;
487 bitDepthLumaMinus8 &= 7;
488 bitDepthChromaMinus8 &= 7;
489
490 constantFrameRate = misc >> 6;
491 numTemporalLayers = (misc >> 3) & 7;
492 temporalIdNested = (misc >> 2) & 1;
493 lengthSizeMinusOne = misc & 3;
494
495 DVLOG(2) << __FUNCTION__ << " numOfArrays=" << (int)numOfArrays;
496 arrays.resize(numOfArrays);
497 for (uint32 j = 0; j < numOfArrays; j++) {
498 RCHECK(reader->Read1(&arrays[j].first_byte));
499 uint16 numNalus = 0;
500 RCHECK(reader->Read2(&numNalus));
501 arrays[j].units.resize(numNalus);
502 for (uint32 i = 0; i < numNalus; ++i) {
503 uint16 naluLength = 0;
504 RCHECK(reader->Read2(&naluLength) &&
505 reader->ReadVec(&arrays[j].units[i], naluLength));
506 DVLOG(4) << __FUNCTION__ << " naluType="
507 << (int)(arrays[j].first_byte & 0x3f)
508 << " size=" << arrays[j].units[i].size();
509 }
510 }
511
512 if (!log_cb.is_null()) {
513 MEDIA_LOG(INFO, log_cb) << "Video codec: hevc";
514 }
515
516 return true;
517 }
518 #endif
519
416 PixelAspectRatioBox::PixelAspectRatioBox() : h_spacing(1), v_spacing(1) {} 520 PixelAspectRatioBox::PixelAspectRatioBox() : h_spacing(1), v_spacing(1) {}
417 PixelAspectRatioBox::~PixelAspectRatioBox() {} 521 PixelAspectRatioBox::~PixelAspectRatioBox() {}
418 FourCC PixelAspectRatioBox::BoxType() const { return FOURCC_PASP; } 522 FourCC PixelAspectRatioBox::BoxType() const { return FOURCC_PASP; }
419 523
420 bool PixelAspectRatioBox::Parse(BoxReader* reader) { 524 bool PixelAspectRatioBox::Parse(BoxReader* reader) {
421 RCHECK(reader->Read4(&h_spacing) && 525 RCHECK(reader->Read4(&h_spacing) &&
422 reader->Read4(&v_spacing)); 526 reader->Read4(&v_spacing));
423 return true; 527 return true;
424 } 528 }
425 529
(...skipping 24 matching lines...) Expand all
450 554
451 if (format == FOURCC_ENCV) { 555 if (format == FOURCC_ENCV) {
452 // Continue scanning until a recognized protection scheme is found, or until 556 // Continue scanning until a recognized protection scheme is found, or until
453 // we run out of protection schemes. 557 // we run out of protection schemes.
454 while (sinf.type.type != FOURCC_CENC) { 558 while (sinf.type.type != FOURCC_CENC) {
455 if (!reader->ReadChild(&sinf)) 559 if (!reader->ReadChild(&sinf))
456 return false; 560 return false;
457 } 561 }
458 } 562 }
459 563
460 if (IsFormatValid()) 564 VideoCodec codec = kUnknownVideoCodec;
461 RCHECK(reader->ReadChild(&avcc)); 565 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
566 if ((format == FOURCC_AVC1 || format == FOURCC_AVC3) ||
567 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 ||
568 sinf.format.format == FOURCC_AVC3))) {
569 DVLOG(2) << __FUNCTION__
570 << " reading AVCDecoderConfigurationRecord (avcC)";
571 RCHECK(reader->ReadChild(&avcConfig));
572 codec = kCodecH264;
573 profile = H264PROFILE_MAIN;
574 #if defined(ENABLE_HEVC_DEMUXING)
575 } else if ((format == FOURCC_HEV1 || format == FOURCC_HVC1) ||
576 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_HEV1 ||
577 sinf.format.format == FOURCC_HVC1))) {
578 DVLOG(2) << __FUNCTION__
579 << " parsing HEVCDecoderConfigurationRecord (hvcC)";
580 RCHECK(reader->ReadChild(&hevcConfig));
581 codec = kCodecHEVC;
582 #endif
583 } else {
584 // Unknown/unsupported format
585 MEDIA_LOG(ERROR, reader->log_cb()) << __FUNCTION__
586 << " unsupported video format "
587 << FourCCToString(format);
588 return false;
589 }
462 590
591 // TODO(strobe): Recover correct crop box
592 gfx::Size coded_size(width, height);
593 gfx::Rect visible_rect(coded_size);
594 gfx::Size natural_size = GetNaturalSize(visible_rect.size(),
595 pixel_aspect.h_spacing,
596 pixel_aspect.v_spacing);
597 bool is_encrypted = sinf.info.track_encryption.is_encrypted;
598 video_decoder_config_.Initialize(
599 codec, profile, VideoFrame::YV12,
600 coded_size, visible_rect, natural_size,
601 // No decoder-specific buffer needed.
602 // Decoder parameters (SPS/PPS) are embedded in the video stream.
603 NULL, 0, is_encrypted, false);
463 return true; 604 return true;
464 } 605 }
465 606
466 bool VideoSampleEntry::IsFormatValid() const { 607 VideoDecoderConfig VideoSampleEntry::GetVideoDecoderConfig() const {
467 return format == FOURCC_AVC1 || format == FOURCC_AVC3 || 608 return video_decoder_config_;
468 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 ||
469 sinf.format.format == FOURCC_AVC3));
470 } 609 }
471 610
472 ElementaryStreamDescriptor::ElementaryStreamDescriptor() 611 ElementaryStreamDescriptor::ElementaryStreamDescriptor()
473 : object_type(kForbidden) {} 612 : object_type(kForbidden) {}
474 613
475 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} 614 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {}
476 615
477 FourCC ElementaryStreamDescriptor::BoxType() const { 616 FourCC ElementaryStreamDescriptor::BoxType() const {
478 return FOURCC_ESDS; 617 return FOURCC_ESDS;
479 } 618 }
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( 1089 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on(
951 size_t i) const { 1090 size_t i) const {
952 if (i >= sample_depends_on_.size()) 1091 if (i >= sample_depends_on_.size())
953 return kSampleDependsOnUnknown; 1092 return kSampleDependsOnUnknown;
954 1093
955 return sample_depends_on_[i]; 1094 return sample_depends_on_[i];
956 } 1095 }
957 1096
958 } // namespace mp4 1097 } // namespace mp4
959 } // namespace media 1098 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698