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

Side by Side Diff: media/formats/mp4/box_definitions.cc

Issue 1735003004: Implement reading of media track info from WebM and MP4 containers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@demuxer-tracks2
Patch Set: CR feedback Created 4 years, 9 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
« no previous file with comments | « media/formats/mp4/box_definitions.h ('k') | media/formats/mp4/mp4_stream_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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).
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 // Check that the length of the Pascal-style string is correct.
393 RCHECK(name_bytes[0] == (name_bytes.size() - 1));
wolenetz 2016/03/10 19:53:29 Is it possible that a 0-byte name_bytes might occu
servolk 2016/03/10 22:25:38 Done.
394 name_bytes.erase(name_bytes.begin());
395 }
396 name = std::string(name_bytes.begin(), name_bytes.end());
397
380 if (hdlr_type == FOURCC_VIDE) { 398 if (hdlr_type == FOURCC_VIDE) {
381 type = kVideo; 399 type = kVideo;
382 } else if (hdlr_type == FOURCC_SOUN) { 400 } else if (hdlr_type == FOURCC_SOUN) {
383 type = kAudio; 401 type = kAudio;
384 } else { 402 } else {
385 type = kInvalid; 403 type = kInvalid;
386 } 404 }
387 return true; 405 return true;
388 } 406 }
389 407
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 643
626 // ESDS is not valid in case of EAC3. 644 // ESDS is not valid in case of EAC3.
627 RCHECK(reader->MaybeReadChild(&esds)); 645 RCHECK(reader->MaybeReadChild(&esds));
628 return true; 646 return true;
629 } 647 }
630 648
631 MediaHeader::MediaHeader() 649 MediaHeader::MediaHeader()
632 : creation_time(0), 650 : creation_time(0),
633 modification_time(0), 651 modification_time(0),
634 timescale(0), 652 timescale(0),
635 duration(0) {} 653 duration(0),
654 language_code(0) {}
636 MediaHeader::~MediaHeader() {} 655 MediaHeader::~MediaHeader() {}
637 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; } 656 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; }
638 657
639 bool MediaHeader::Parse(BoxReader* reader) { 658 bool MediaHeader::Parse(BoxReader* reader) {
wolenetz 2016/03/10 19:53:29 aside: please reference potential for mp4 ELNG to
servolk 2016/03/10 22:25:38 Done: crbug.com/593904
640 RCHECK(reader->ReadFullBoxHeader()); 659 RCHECK(reader->ReadFullBoxHeader());
641 660
642 if (reader->version() == 1) { 661 if (reader->version() == 1) {
643 RCHECK(reader->Read8(&creation_time) && 662 RCHECK(reader->Read8(&creation_time) && reader->Read8(&modification_time) &&
644 reader->Read8(&modification_time) && 663 reader->Read4(&timescale) && reader->Read8(&duration) &&
645 reader->Read4(&timescale) && 664 reader->Read2(&language_code));
646 reader->Read8(&duration));
647 } else { 665 } else {
648 RCHECK(reader->Read4Into8(&creation_time) && 666 RCHECK(reader->Read4Into8(&creation_time) &&
649 reader->Read4Into8(&modification_time) && 667 reader->Read4Into8(&modification_time) &&
650 reader->Read4(&timescale) && 668 reader->Read4(&timescale) && reader->Read4Into8(&duration) &&
651 reader->Read4Into8(&duration)); 669 reader->Read2(&language_code));
652 } 670 }
653 // Skip language information 671 // ISO 639-2/T language code only uses 15 lower bits, so reset the 16th bit.
654 return reader->SkipBytes(4); 672 language_code &= 0x7fff;
673 // Skip playback quality information
674 return reader->SkipBytes(2);
675 }
676
677 std::string MediaHeader::language() const {
678 if (language_code == 0x7fff || language_code < 0x400) {
679 return "und";
680 }
681 char lang_chars[4];
682 lang_chars[3] = 0;
683 lang_chars[2] = 0x60 + (language_code & 0x1f);
684 lang_chars[1] = 0x60 + ((language_code >> 5) & 0x1f);
685 lang_chars[0] = 0x60 + ((language_code >> 10) & 0x1f);
686
687 if (lang_chars[0] < 'a' || lang_chars[0] > 'z' || lang_chars[1] < 'a' ||
688 lang_chars[1] > 'z' || lang_chars[2] < 'a' || lang_chars[2] > 'z') {
689 // Got unexpected characteds in ISO 639-2/T language code. Something must be
690 // wrong with the input file, report 'und' language to be safe.
691 DVLOG(2) << "Ignoring MDHD language_code (non ISO 639-2 compliant): "
692 << lang_chars;
693 lang_chars[0] = 'u';
694 lang_chars[1] = 'n';
695 lang_chars[2] = 'd';
696 }
697
698 return lang_chars;
655 } 699 }
656 700
657 MediaInformation::MediaInformation() {} 701 MediaInformation::MediaInformation() {}
658 MediaInformation::~MediaInformation() {} 702 MediaInformation::~MediaInformation() {}
659 FourCC MediaInformation::BoxType() const { return FOURCC_MINF; } 703 FourCC MediaInformation::BoxType() const { return FOURCC_MINF; }
660 704
661 bool MediaInformation::Parse(BoxReader* reader) { 705 bool MediaInformation::Parse(BoxReader* reader) {
662 return reader->ScanChildren() && 706 return reader->ScanChildren() &&
663 reader->ReadChild(&sample_table); 707 reader->ReadChild(&sample_table);
664 } 708 }
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on( 1085 SampleDependsOn IndependentAndDisposableSamples::sample_depends_on(
1042 size_t i) const { 1086 size_t i) const {
1043 if (i >= sample_depends_on_.size()) 1087 if (i >= sample_depends_on_.size())
1044 return kSampleDependsOnUnknown; 1088 return kSampleDependsOnUnknown;
1045 1089
1046 return sample_depends_on_[i]; 1090 return sample_depends_on_[i];
1047 } 1091 }
1048 1092
1049 } // namespace mp4 1093 } // namespace mp4
1050 } // namespace media 1094 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/mp4/box_definitions.h ('k') | media/formats/mp4/mp4_stream_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698