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