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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 bool Edit::Parse(BoxReader* reader) { | 427 bool Edit::Parse(BoxReader* reader) { |
428 return reader->ScanChildren() && reader->ReadChild(&list); | 428 return reader->ScanChildren() && reader->ReadChild(&list); |
429 } | 429 } |
430 | 430 |
431 HandlerReference::HandlerReference() : type(kInvalid) {} | 431 HandlerReference::HandlerReference() : type(kInvalid) {} |
432 HandlerReference::~HandlerReference() {} | 432 HandlerReference::~HandlerReference() {} |
433 FourCC HandlerReference::BoxType() const { return FOURCC_HDLR; } | 433 FourCC HandlerReference::BoxType() const { return FOURCC_HDLR; } |
434 | 434 |
435 bool HandlerReference::Parse(BoxReader* reader) { | 435 bool HandlerReference::Parse(BoxReader* reader) { |
436 FourCC hdlr_type; | 436 FourCC hdlr_type; |
437 RCHECK(reader->SkipBytes(8) && reader->ReadFourCC(&hdlr_type)); | 437 RCHECK(reader->ReadFullBoxHeader() && reader->SkipBytes(4) && |
438 // Note: remaining fields in box ignored | 438 reader->ReadFourCC(&hdlr_type) && reader->SkipBytes(12)); |
| 439 |
| 440 // Now we should be at the beginning of the |name| field of HDLR box. The |
| 441 // |name| is a zero-terminated ASCII string in ISO BMFF, but it was a |
| 442 // Pascal-style counted string in older QT/Mov formats. So we'll read the |
| 443 // remaining box bytes first, then if the last one is zero, we strip the last |
| 444 // zero byte, otherwise we'll string the first byte (containing the length of |
| 445 // the Pascal-style string). |
| 446 std::vector<uint8_t> name_bytes; |
| 447 RCHECK(reader->ReadVec(&name_bytes, reader->size() - reader->pos())); |
| 448 if (name_bytes.size() == 0) { |
| 449 name = ""; |
| 450 } else if (name_bytes.back() == 0) { |
| 451 // This is a zero-terminated C-style string, exclude the last byte. |
| 452 name = std::string(name_bytes.begin(), name_bytes.end() - 1); |
| 453 } else { |
| 454 // Check that the length of the Pascal-style string is correct. |
| 455 RCHECK(name_bytes[0] == (name_bytes.size() - 1)); |
| 456 // Skip the first byte, containing the length of the Pascal-string. |
| 457 name = std::string(name_bytes.begin() + 1, name_bytes.end()); |
| 458 } |
| 459 |
439 if (hdlr_type == FOURCC_VIDE) { | 460 if (hdlr_type == FOURCC_VIDE) { |
440 type = kVideo; | 461 type = kVideo; |
441 } else if (hdlr_type == FOURCC_SOUN) { | 462 } else if (hdlr_type == FOURCC_SOUN) { |
442 type = kAudio; | 463 type = kAudio; |
443 } else { | 464 } else { |
444 type = kInvalid; | 465 type = kInvalid; |
445 } | 466 } |
446 return true; | 467 return true; |
447 } | 468 } |
448 | 469 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 | 705 |
685 // ESDS is not valid in case of EAC3. | 706 // ESDS is not valid in case of EAC3. |
686 RCHECK(reader->MaybeReadChild(&esds)); | 707 RCHECK(reader->MaybeReadChild(&esds)); |
687 return true; | 708 return true; |
688 } | 709 } |
689 | 710 |
690 MediaHeader::MediaHeader() | 711 MediaHeader::MediaHeader() |
691 : creation_time(0), | 712 : creation_time(0), |
692 modification_time(0), | 713 modification_time(0), |
693 timescale(0), | 714 timescale(0), |
694 duration(0) {} | 715 duration(0), |
| 716 language_code(0) {} |
695 MediaHeader::~MediaHeader() {} | 717 MediaHeader::~MediaHeader() {} |
696 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; } | 718 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; } |
697 | 719 |
698 bool MediaHeader::Parse(BoxReader* reader) { | 720 bool MediaHeader::Parse(BoxReader* reader) { |
699 RCHECK(reader->ReadFullBoxHeader()); | 721 RCHECK(reader->ReadFullBoxHeader()); |
700 | 722 |
701 if (reader->version() == 1) { | 723 if (reader->version() == 1) { |
702 RCHECK(reader->Read8(&creation_time) && | 724 RCHECK(reader->Read8(&creation_time) && reader->Read8(&modification_time) && |
703 reader->Read8(&modification_time) && | 725 reader->Read4(×cale) && reader->Read8(&duration) && |
704 reader->Read4(×cale) && | 726 reader->Read2(&language_code)); |
705 reader->Read8(&duration)); | |
706 } else { | 727 } else { |
707 RCHECK(reader->Read4Into8(&creation_time) && | 728 RCHECK(reader->Read4Into8(&creation_time) && |
708 reader->Read4Into8(&modification_time) && | 729 reader->Read4Into8(&modification_time) && |
709 reader->Read4(×cale) && | 730 reader->Read4(×cale) && reader->Read4Into8(&duration) && |
710 reader->Read4Into8(&duration)); | 731 reader->Read2(&language_code)); |
711 } | 732 } |
712 // Skip language information | 733 // ISO 639-2/T language code only uses 15 lower bits, so reset the 16th bit. |
713 return reader->SkipBytes(4); | 734 language_code &= 0x7fff; |
| 735 // Skip playback quality information |
| 736 return reader->SkipBytes(2); |
| 737 } |
| 738 |
| 739 std::string MediaHeader::language() const { |
| 740 if (language_code == 0x7fff || language_code < 0x400) { |
| 741 return "und"; |
| 742 } |
| 743 char lang_chars[4]; |
| 744 lang_chars[3] = 0; |
| 745 lang_chars[2] = 0x60 + (language_code & 0x1f); |
| 746 lang_chars[1] = 0x60 + ((language_code >> 5) & 0x1f); |
| 747 lang_chars[0] = 0x60 + ((language_code >> 10) & 0x1f); |
| 748 |
| 749 if (lang_chars[0] < 'a' || lang_chars[0] > 'z' || lang_chars[1] < 'a' || |
| 750 lang_chars[1] > 'z' || lang_chars[2] < 'a' || lang_chars[2] > 'z') { |
| 751 // Got unexpected characteds in ISO 639-2/T language code. Something must be |
| 752 // wrong with the input file, report 'und' language to be safe. |
| 753 DVLOG(2) << "Ignoring MDHD language_code (non ISO 639-2 compliant): " |
| 754 << lang_chars; |
| 755 lang_chars[0] = 'u'; |
| 756 lang_chars[1] = 'n'; |
| 757 lang_chars[2] = 'd'; |
| 758 } |
| 759 |
| 760 return lang_chars; |
714 } | 761 } |
715 | 762 |
716 MediaInformation::MediaInformation() {} | 763 MediaInformation::MediaInformation() {} |
717 MediaInformation::~MediaInformation() {} | 764 MediaInformation::~MediaInformation() {} |
718 FourCC MediaInformation::BoxType() const { return FOURCC_MINF; } | 765 FourCC MediaInformation::BoxType() const { return FOURCC_MINF; } |
719 | 766 |
720 bool MediaInformation::Parse(BoxReader* reader) { | 767 bool MediaInformation::Parse(BoxReader* reader) { |
721 return reader->ScanChildren() && | 768 return reader->ScanChildren() && |
722 reader->ReadChild(&sample_table); | 769 reader->ReadChild(&sample_table); |
723 } | 770 } |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 1147 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( |
1101 size_t i) const { | 1148 size_t i) const { |
1102 if (i >= sample_depends_on_.size()) | 1149 if (i >= sample_depends_on_.size()) |
1103 return kSampleDependsOnUnknown; | 1150 return kSampleDependsOnUnknown; |
1104 | 1151 |
1105 return sample_depends_on_[i]; | 1152 return sample_depends_on_[i]; |
1106 } | 1153 } |
1107 | 1154 |
1108 } // namespace mp4 | 1155 } // namespace mp4 |
1109 } // namespace media | 1156 } // namespace media |
OLD | NEW |