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

Side by Side Diff: media/formats/mp4/box_reader.h

Issue 1170923005: Revert of Combine 'pssh' parsing routines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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.cc ('k') | media/formats/mp4/box_reader.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 #ifndef MEDIA_FORMATS_MP4_BOX_READER_H_ 5 #ifndef MEDIA_FORMATS_MP4_BOX_READER_H_
6 #define MEDIA_FORMATS_MP4_BOX_READER_H_ 6 #define MEDIA_FORMATS_MP4_BOX_READER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // true. The semantics of |*err| are the same as above. 94 // true. The semantics of |*err| are the same as above.
95 // 95 //
96 // |buf| is not retained. 96 // |buf| is not retained.
97 static bool StartTopLevelBox(const uint8* buf, 97 static bool StartTopLevelBox(const uint8* buf,
98 const int buf_size, 98 const int buf_size,
99 const LogCB& log_cb, 99 const LogCB& log_cb,
100 FourCC* type, 100 FourCC* type,
101 int* box_size, 101 int* box_size,
102 bool* err) WARN_UNUSED_RESULT; 102 bool* err) WARN_UNUSED_RESULT;
103 103
104 // Create a BoxReader from a buffer. |buf| must be the complete buffer, as
105 // errors are returned when sufficient data is not available. |buf| can start
106 // with any type of box -- it does not have to be IsValidTopLevelBox().
107 //
108 // |buf| is retained but not owned, and must outlive the BoxReader instance.
109 static BoxReader* ReadConcatentatedBoxes(const uint8* buf,
110 const int buf_size);
111
112 // Returns true if |type| is recognized to be a top-level box, false 104 // Returns true if |type| is recognized to be a top-level box, false
113 // otherwise. This returns true for some boxes which we do not parse. 105 // otherwise. This returns true for some boxes which we do not parse.
114 // Helpful in debugging misaligned appends. 106 // Helpful in debugging misaligned appends.
115 static bool IsValidTopLevelBox(const FourCC& type, 107 static bool IsValidTopLevelBox(const FourCC& type,
116 const LogCB& log_cb); 108 const LogCB& log_cb);
117 109
118 // Scan through all boxes within the current box, starting at the current 110 // Scan through all boxes within the current box, starting at the current
119 // buffer position. Must be called before any of the *Child functions work. 111 // buffer position. Must be called before any of the *Child functions work.
120 bool ScanChildren() WARN_UNUSED_RESULT; 112 bool ScanChildren() WARN_UNUSED_RESULT;
121 113
(...skipping 27 matching lines...) Expand all
149 // the box has been initialized, and does not re-read the main box header. 141 // the box has been initialized, and does not re-read the main box header.
150 bool ReadFullBoxHeader() WARN_UNUSED_RESULT; 142 bool ReadFullBoxHeader() WARN_UNUSED_RESULT;
151 143
152 FourCC type() const { return type_; } 144 FourCC type() const { return type_; }
153 uint8 version() const { return version_; } 145 uint8 version() const { return version_; }
154 uint32 flags() const { return flags_; } 146 uint32 flags() const { return flags_; }
155 147
156 const LogCB& log_cb() const { return log_cb_; } 148 const LogCB& log_cb() const { return log_cb_; }
157 149
158 private: 150 private:
159 // Create a BoxReader from |buf|. |is_EOS| should be true if |buf| is 151 BoxReader(const uint8* buf, const int size, const LogCB& log_cb);
160 // complete stream (i.e. no additional data is expected to be appended).
161 BoxReader(const uint8* buf, const int size, const LogCB& log_cb, bool is_EOS);
162 152
163 // Must be called immediately after init. If the return is false, this 153 // Must be called immediately after init. If the return is false, this
164 // indicates that the box header and its contents were not available in the 154 // indicates that the box header and its contents were not available in the
165 // stream or were nonsensical, and that the box must not be used further. In 155 // stream or were nonsensical, and that the box must not be used further. In
166 // this case, if |*err| is false, the problem was simply a lack of data, and 156 // this case, if |*err| is false, the problem was simply a lack of data, and
167 // should only be an error condition if some higher-level component knows that 157 // should only be an error condition if some higher-level component knows that
168 // no more data is coming (i.e. EOS or end of containing box). If |*err| is 158 // no more data is coming (i.e. EOS or end of containing box). If |*err| is
169 // true, the error is unrecoverable and the stream should be aborted. 159 // true, the error is unrecoverable and the stream should be aborted.
170 bool ReadHeader(bool* err); 160 bool ReadHeader(bool* err);
171 161
172 LogCB log_cb_; 162 LogCB log_cb_;
173 FourCC type_; 163 FourCC type_;
174 uint8 version_; 164 uint8 version_;
175 uint32 flags_; 165 uint32 flags_;
176 166
177 typedef std::multimap<FourCC, BoxReader> ChildMap; 167 typedef std::multimap<FourCC, BoxReader> ChildMap;
178 168
179 // The set of child box FourCCs and their corresponding buffer readers. Only 169 // The set of child box FourCCs and their corresponding buffer readers. Only
180 // valid if scanned_ is true. 170 // valid if scanned_ is true.
181 ChildMap children_; 171 ChildMap children_;
182 bool scanned_; 172 bool scanned_;
183
184 // True if the buffer provided to the reader is the complete stream.
185 const bool is_EOS_;
186 }; 173 };
187 174
188 // Template definitions 175 // Template definitions
189 template<typename T> bool BoxReader::ReadChildren(std::vector<T>* children) { 176 template<typename T> bool BoxReader::ReadChildren(std::vector<T>* children) {
190 RCHECK(MaybeReadChildren(children) && !children->empty()); 177 RCHECK(MaybeReadChildren(children) && !children->empty());
191 return true; 178 return true;
192 } 179 }
193 180
194 template<typename T> 181 template<typename T>
195 bool BoxReader::MaybeReadChildren(std::vector<T>* children) { 182 bool BoxReader::MaybeReadChildren(std::vector<T>* children) {
(...skipping 17 matching lines...) Expand all
213 << FourCCToString(child_type) << " boxes."; 200 << FourCCToString(child_type) << " boxes.";
214 return true; 201 return true;
215 } 202 }
216 203
217 template<typename T> 204 template<typename T>
218 bool BoxReader::ReadAllChildren(std::vector<T>* children) { 205 bool BoxReader::ReadAllChildren(std::vector<T>* children) {
219 DCHECK(!scanned_); 206 DCHECK(!scanned_);
220 scanned_ = true; 207 scanned_ = true;
221 208
222 bool err = false; 209 bool err = false;
223 while (pos_ < size_) { 210 while (pos() < size()) {
224 BoxReader child_reader(&buf_[pos_], size_ - pos_, log_cb_, is_EOS_); 211 BoxReader child_reader(&buf_[pos_], size_ - pos_, log_cb_);
225 if (!child_reader.ReadHeader(&err)) break; 212 if (!child_reader.ReadHeader(&err)) break;
226 T child; 213 T child;
227 RCHECK(child.Parse(&child_reader)); 214 RCHECK(child.Parse(&child_reader));
228 children->push_back(child); 215 children->push_back(child);
229 pos_ += child_reader.size(); 216 pos_ += child_reader.size();
230 } 217 }
231 218
232 return !err; 219 return !err;
233 } 220 }
234 221
235 } // namespace mp4 222 } // namespace mp4
236 } // namespace media 223 } // namespace media
237 224
238 #endif // MEDIA_FORMATS_MP4_BOX_READER_H_ 225 #endif // MEDIA_FORMATS_MP4_BOX_READER_H_
OLDNEW
« no previous file with comments | « media/formats/mp4/box_definitions.cc ('k') | media/formats/mp4/box_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698