Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / formats / mp4 / es_descriptor.cc
blobe1da28a34e5f802ca5557cc29e8cda2073f5694c
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
3 // found in the LICENSE file.
5 #include "media/formats/mp4/es_descriptor.h"
7 #include "media/base/bit_reader.h"
8 #include "media/formats/mp4/rcheck.h"
10 // The elementary stream size is specific by up to 4 bytes.
11 // The MSB of a byte indicates if there are more bytes for the size.
12 static bool ReadESSize(media::BitReader* reader, uint32* size) {
13 uint8 msb;
14 uint8 byte;
16 *size = 0;
18 for (size_t i = 0; i < 4; ++i) {
19 RCHECK(reader->ReadBits(1, &msb));
20 RCHECK(reader->ReadBits(7, &byte));
21 *size = (*size << 7) + byte;
23 if (msb == 0)
24 break;
27 return true;
30 namespace media {
32 namespace mp4 {
34 // static
35 bool ESDescriptor::IsAAC(uint8 object_type) {
36 return object_type == kISO_14496_3 || object_type == kISO_13818_7_AAC_LC;
39 ESDescriptor::ESDescriptor()
40 : object_type_(kForbidden) {
43 ESDescriptor::~ESDescriptor() {}
45 bool ESDescriptor::Parse(const std::vector<uint8>& data) {
46 BitReader reader(&data[0], data.size());
47 uint8 tag;
48 uint32 size;
49 uint8 stream_dependency_flag;
50 uint8 url_flag;
51 uint8 ocr_stream_flag;
52 uint16 dummy;
54 RCHECK(reader.ReadBits(8, &tag));
55 RCHECK(tag == kESDescrTag);
56 RCHECK(ReadESSize(&reader, &size));
58 RCHECK(reader.ReadBits(16, &dummy)); // ES_ID
59 RCHECK(reader.ReadBits(1, &stream_dependency_flag));
60 RCHECK(reader.ReadBits(1, &url_flag));
61 RCHECK(!url_flag); // We don't support url flag
62 RCHECK(reader.ReadBits(1, &ocr_stream_flag));
63 RCHECK(reader.ReadBits(5, &dummy)); // streamPriority
65 if (stream_dependency_flag)
66 RCHECK(reader.ReadBits(16, &dummy)); // dependsOn_ES_ID
67 if (ocr_stream_flag)
68 RCHECK(reader.ReadBits(16, &dummy)); // OCR_ES_Id
70 RCHECK(ParseDecoderConfigDescriptor(&reader));
72 return true;
75 uint8 ESDescriptor::object_type() const {
76 return object_type_;
79 const std::vector<uint8>& ESDescriptor::decoder_specific_info() const {
80 return decoder_specific_info_;
83 bool ESDescriptor::ParseDecoderConfigDescriptor(BitReader* reader) {
84 uint8 tag;
85 uint32 size;
86 uint64 dummy;
88 RCHECK(reader->ReadBits(8, &tag));
89 RCHECK(tag == kDecoderConfigDescrTag);
90 RCHECK(ReadESSize(reader, &size));
92 RCHECK(reader->ReadBits(8, &object_type_));
93 RCHECK(reader->ReadBits(64, &dummy));
94 RCHECK(reader->ReadBits(32, &dummy));
95 RCHECK(ParseDecoderSpecificInfo(reader));
97 return true;
100 bool ESDescriptor::ParseDecoderSpecificInfo(BitReader* reader) {
101 uint8 tag;
102 uint32 size;
104 RCHECK(reader->ReadBits(8, &tag));
105 RCHECK(tag == kDecoderSpecificInfoTag);
106 RCHECK(ReadESSize(reader, &size));
108 decoder_specific_info_.resize(size);
109 for (uint32 i = 0; i < size; ++i)
110 RCHECK(reader->ReadBits(8, &decoder_specific_info_[i]));
112 return true;
115 } // namespace mp4
117 } // namespace media