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

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

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

Powered by Google App Engine
This is Rietveld 408576698