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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 bool Edit::Parse(BoxReader* reader) { | 368 bool Edit::Parse(BoxReader* reader) { |
369 return reader->ScanChildren() && reader->ReadChild(&list); | 369 return reader->ScanChildren() && reader->ReadChild(&list); |
370 } | 370 } |
371 | 371 |
372 HandlerReference::HandlerReference() : type(kInvalid) {} | 372 HandlerReference::HandlerReference() : type(kInvalid) {} |
373 HandlerReference::~HandlerReference() {} | 373 HandlerReference::~HandlerReference() {} |
374 FourCC HandlerReference::BoxType() const { return FOURCC_HDLR; } | 374 FourCC HandlerReference::BoxType() const { return FOURCC_HDLR; } |
375 | 375 |
376 bool HandlerReference::Parse(BoxReader* reader) { | 376 bool HandlerReference::Parse(BoxReader* reader) { |
377 FourCC hdlr_type; | 377 FourCC hdlr_type; |
378 RCHECK(reader->SkipBytes(8) && reader->ReadFourCC(&hdlr_type)); | 378 RCHECK(reader->ReadFullBoxHeader() && reader->SkipBytes(4) && |
379 // Note: remaining fields in box ignored | 379 reader->ReadFourCC(&hdlr_type) && reader->SkipBytes(12)); |
380 | |
381 // Now we should be at the beginning of the |name| field of HDLR box. The | |
382 // |name| is a zero-terminated ASCII string in ISO BMFF, but it was a | |
383 // Pascal-style counted string in older QT/Mov formats. So we'll read the | |
384 // remaining box bytes first, then if the last one is zero, we strip the last | |
385 // zero byte, otherwise we'll string the first byte (containing the length of | |
386 // the Pascal-style string). | |
wolenetz
2016/03/05 03:26:20
A pascal-style string that is shorter than (remain
servolk
2016/03/07 23:45:01
Sure, I've added an RCHECK to ensure that the leng
| |
387 std::vector<uint8_t> name_bytes; | |
388 RCHECK(reader->ReadVec(&name_bytes, reader->size() - reader->pos())); | |
389 if (name_bytes.back() == 0) | |
390 name_bytes.pop_back(); | |
391 else | |
392 name_bytes.erase(name_bytes.begin()); | |
393 name = std::string(name_bytes.begin(), name_bytes.end()); | |
394 | |
380 if (hdlr_type == FOURCC_VIDE) { | 395 if (hdlr_type == FOURCC_VIDE) { |
381 type = kVideo; | 396 type = kVideo; |
382 } else if (hdlr_type == FOURCC_SOUN) { | 397 } else if (hdlr_type == FOURCC_SOUN) { |
383 type = kAudio; | 398 type = kAudio; |
384 } else { | 399 } else { |
385 type = kInvalid; | 400 type = kInvalid; |
386 } | 401 } |
387 return true; | 402 return true; |
388 } | 403 } |
389 | 404 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 | 640 |
626 // ESDS is not valid in case of EAC3. | 641 // ESDS is not valid in case of EAC3. |
627 RCHECK(reader->MaybeReadChild(&esds)); | 642 RCHECK(reader->MaybeReadChild(&esds)); |
628 return true; | 643 return true; |
629 } | 644 } |
630 | 645 |
631 MediaHeader::MediaHeader() | 646 MediaHeader::MediaHeader() |
632 : creation_time(0), | 647 : creation_time(0), |
633 modification_time(0), | 648 modification_time(0), |
634 timescale(0), | 649 timescale(0), |
635 duration(0) {} | 650 duration(0), |
651 language_code(0) {} | |
636 MediaHeader::~MediaHeader() {} | 652 MediaHeader::~MediaHeader() {} |
637 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; } | 653 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; } |
638 | 654 |
639 bool MediaHeader::Parse(BoxReader* reader) { | 655 bool MediaHeader::Parse(BoxReader* reader) { |
640 RCHECK(reader->ReadFullBoxHeader()); | 656 RCHECK(reader->ReadFullBoxHeader()); |
641 | 657 |
642 if (reader->version() == 1) { | 658 if (reader->version() == 1) { |
643 RCHECK(reader->Read8(&creation_time) && | 659 RCHECK(reader->Read8(&creation_time) && reader->Read8(&modification_time) && |
644 reader->Read8(&modification_time) && | 660 reader->Read4(×cale) && reader->Read8(&duration) && |
645 reader->Read4(×cale) && | 661 reader->Read2(&language_code)); |
646 reader->Read8(&duration)); | |
647 } else { | 662 } else { |
648 RCHECK(reader->Read4Into8(&creation_time) && | 663 RCHECK(reader->Read4Into8(&creation_time) && |
649 reader->Read4Into8(&modification_time) && | 664 reader->Read4Into8(&modification_time) && |
650 reader->Read4(×cale) && | 665 reader->Read4(×cale) && reader->Read4Into8(&duration) && |
651 reader->Read4Into8(&duration)); | 666 reader->Read2(&language_code)); |
652 } | 667 } |
653 // Skip language information | 668 // Skip playback quality information |
654 return reader->SkipBytes(4); | 669 return reader->SkipBytes(2); |
670 } | |
671 | |
672 std::string MediaHeader::language() const { | |
673 if (language_code == 0x7fff || language_code < 0x400) { | |
wolenetz
2016/03/05 03:26:21
A couple questions about this line:
1) Where do th
servolk
2016/03/07 23:45:01
1) I took those numbers from https://developer.app
wolenetz
2016/03/10 19:53:29
Acknowledged.
| |
674 return "und"; | |
675 } | |
676 char lang_chars[4]; | |
677 lang_chars[3] = 0; | |
678 lang_chars[2] = 0x60 + (language_code & 0x1f); | |
wolenetz
2016/03/05 03:26:21
nit: constrain each of lang_chars[0..2] to be with
servolk
2016/03/07 23:45:01
Done.
| |
679 lang_chars[1] = 0x60 + ((language_code >> 5) & 0x1f); | |
680 lang_chars[0] = 0x60 + ((language_code >> 10) & 0x1f); | |
681 return lang_chars; | |
655 } | 682 } |
656 | 683 |
657 MediaInformation::MediaInformation() {} | 684 MediaInformation::MediaInformation() {} |
658 MediaInformation::~MediaInformation() {} | 685 MediaInformation::~MediaInformation() {} |
659 FourCC MediaInformation::BoxType() const { return FOURCC_MINF; } | 686 FourCC MediaInformation::BoxType() const { return FOURCC_MINF; } |
660 | 687 |
661 bool MediaInformation::Parse(BoxReader* reader) { | 688 bool MediaInformation::Parse(BoxReader* reader) { |
662 return reader->ScanChildren() && | 689 return reader->ScanChildren() && |
663 reader->ReadChild(&sample_table); | 690 reader->ReadChild(&sample_table); |
664 } | 691 } |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1041 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( | 1068 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( |
1042 size_t i) const { | 1069 size_t i) const { |
1043 if (i >= sample_depends_on_.size()) | 1070 if (i >= sample_depends_on_.size()) |
1044 return kSampleDependsOnUnknown; | 1071 return kSampleDependsOnUnknown; |
1045 | 1072 |
1046 return sample_depends_on_[i]; | 1073 return sample_depends_on_[i]; |
1047 } | 1074 } |
1048 | 1075 |
1049 } // namespace mp4 | 1076 } // namespace mp4 |
1050 } // namespace media | 1077 } // namespace media |
OLD | NEW |