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 "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 Loading... |
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(¶llelismType) && |
| 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(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 Loading... |
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(reader->log_cb()) << __FUNCTION__ << " unsupported video format " |
| 586 << FourCCToString(format); |
| 587 return false; |
| 588 } |
462 | 589 |
| 590 // TODO(strobe): Recover correct crop box |
| 591 gfx::Size coded_size(width, height); |
| 592 gfx::Rect visible_rect(coded_size); |
| 593 gfx::Size natural_size = GetNaturalSize(visible_rect.size(), |
| 594 pixel_aspect.h_spacing, |
| 595 pixel_aspect.v_spacing); |
| 596 bool is_encrypted = sinf.info.track_encryption.is_encrypted; |
| 597 video_decoder_config_.Initialize( |
| 598 codec, profile, VideoFrame::YV12, |
| 599 coded_size, visible_rect, natural_size, |
| 600 // No decoder-specific buffer needed. |
| 601 // Decoder parameters (SPS/PPS) are embedded in the video stream. |
| 602 NULL, 0, is_encrypted, false); |
463 return true; | 603 return true; |
464 } | 604 } |
465 | 605 |
466 bool VideoSampleEntry::IsFormatValid() const { | 606 VideoDecoderConfig VideoSampleEntry::GetVideoDecoderConfig() const { |
467 return format == FOURCC_AVC1 || format == FOURCC_AVC3 || | 607 return video_decoder_config_; |
468 (format == FOURCC_ENCV && (sinf.format.format == FOURCC_AVC1 || | |
469 sinf.format.format == FOURCC_AVC3)); | |
470 } | 608 } |
471 | 609 |
472 ElementaryStreamDescriptor::ElementaryStreamDescriptor() | 610 ElementaryStreamDescriptor::ElementaryStreamDescriptor() |
473 : object_type(kForbidden) {} | 611 : object_type(kForbidden) {} |
474 | 612 |
475 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} | 613 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} |
476 | 614 |
477 FourCC ElementaryStreamDescriptor::BoxType() const { | 615 FourCC ElementaryStreamDescriptor::BoxType() const { |
478 return FOURCC_ESDS; | 616 return FOURCC_ESDS; |
479 } | 617 } |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 1085 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( |
948 size_t i) const { | 1086 size_t i) const { |
949 if (i >= sample_depends_on_.size()) | 1087 if (i >= sample_depends_on_.size()) |
950 return kSampleDependsOnUnknown; | 1088 return kSampleDependsOnUnknown; |
951 | 1089 |
952 return sample_depends_on_[i]; | 1090 return sample_depends_on_[i]; |
953 } | 1091 } |
954 | 1092 |
955 } // namespace mp4 | 1093 } // namespace mp4 |
956 } // namespace media | 1094 } // namespace media |
OLD | NEW |