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
) {
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
;
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());
49 uint8 stream_dependency_flag
;
51 uint8 ocr_stream_flag
;
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
68 RCHECK(reader
.ReadBits(16, &dummy
)); // OCR_ES_Id
70 RCHECK(ParseDecoderConfigDescriptor(&reader
));
75 uint8
ESDescriptor::object_type() const {
79 const std::vector
<uint8
>& ESDescriptor::decoder_specific_info() const {
80 return decoder_specific_info_
;
83 bool ESDescriptor::ParseDecoderConfigDescriptor(BitReader
* reader
) {
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
));
100 bool ESDescriptor::ParseDecoderSpecificInfo(BitReader
* reader
) {
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
]));