OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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. | |
4 | |
5 #include "media/mp4/es_descriptor.h" | |
6 | |
7 #include "media/base/bit_reader.h" | |
8 #include "media/mp4/rcheck.h" | |
9 | |
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; | |
15 | |
16 *size = 0; | |
17 | |
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; | |
22 | |
23 if (msb == 0) | |
24 break; | |
25 } | |
26 | |
27 return true; | |
28 } | |
29 | |
30 namespace media { | |
31 | |
32 namespace mp4 { | |
33 | |
34 ESDescriptor::ESDescriptor() | |
35 : object_type_(kForbidden) { | |
36 } | |
37 | |
38 ESDescriptor::~ESDescriptor() {} | |
39 | |
40 bool ESDescriptor::Parse(const std::vector<uint8>& data) { | |
41 BitReader reader(&data[0], data.size()); | |
42 uint8 tag; | |
43 uint32 size; | |
44 uint8 stream_dependency_flag; | |
45 uint8 url_flag; | |
46 uint8 ocr_stream_flag; | |
47 | |
48 RCHECK(reader.ReadBits(8, &tag)); | |
49 RCHECK(tag == kESDescrTag); | |
50 RCHECK(ReadESSize(&reader, &size)); | |
51 RCHECK(static_cast<off_t>(size * CHAR_BIT) <= reader.NumBitsLeft()); | |
acolwell GONE FROM CHROMIUM
2012/07/17 20:07:32
Any reason not to use 8 instead of CHAR_BIT here a
xiaomings
2012/07/17 22:09:44
Use 8 instead.
| |
52 | |
53 RCHECK(reader.SkipBits(16)); // ES_ID | |
54 RCHECK(reader.ReadBits(1, &stream_dependency_flag)); | |
55 RCHECK(reader.ReadBits(1, &url_flag)); | |
56 RCHECK(reader.ReadBits(1, &ocr_stream_flag)); | |
57 RCHECK(reader.SkipBits(5)); // streamPriority | |
58 | |
59 if (stream_dependency_flag) | |
60 reader.SkipBits(16); // dependsOn_ES_ID; | |
61 RCHECK(!url_flag); // We don't support url flag | |
62 if (ocr_stream_flag) | |
63 reader.SkipBits(16); // OCR_ES_Id | |
64 | |
65 RCHECK(ParseDecoderConfigDescriptor(&reader)); | |
66 | |
67 return true; | |
68 } | |
69 | |
70 uint8 ESDescriptor::object_type() const { | |
71 return object_type_; | |
72 } | |
73 | |
74 const std::vector<uint8>& ESDescriptor::decoder_specific_info() const { | |
75 return decoder_specific_info_; | |
76 } | |
77 | |
78 bool ESDescriptor::ParseDecoderConfigDescriptor(BitReader* reader) { | |
79 uint8 tag; | |
80 uint32 size; | |
81 | |
82 RCHECK(reader->ReadBits(8, &tag)); | |
83 RCHECK(tag == kDecoderConfigDescrTag); | |
84 RCHECK(ReadESSize(reader, &size)); | |
85 RCHECK(static_cast<off_t>(size * CHAR_BIT) <= reader->NumBitsLeft()); | |
86 | |
87 RCHECK(reader->ReadBits(8, &object_type_)); | |
88 RCHECK(reader->SkipBits(96)); | |
89 RCHECK(ParseDecoderSpecificInfo(reader)); | |
90 | |
91 return true; | |
92 } | |
93 | |
94 bool ESDescriptor::ParseDecoderSpecificInfo(BitReader* reader) { | |
95 uint8 tag; | |
96 uint32 size; | |
97 | |
98 RCHECK(reader->ReadBits(8, &tag)); | |
99 RCHECK(tag == kDecoderSpecificInfoTag); | |
100 RCHECK(ReadESSize(reader, &size)); | |
101 RCHECK(static_cast<off_t>(size * CHAR_BIT) <= reader->NumBitsLeft()); | |
102 | |
103 decoder_specific_info_.resize(size); | |
104 for (uint32 i = 0; i < size; ++i) | |
105 RCHECK(reader->ReadBits(8, &decoder_specific_info_[i])); | |
106 | |
107 return true; | |
108 } | |
109 | |
110 } // namespace mp4 | |
111 | |
112 } // namespace media | |
OLD | NEW |