OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_MP4_BOX_READER_H_ | 5 #ifndef MEDIA_MP4_BOX_READER_H_ |
6 #define MEDIA_MP4_BOX_READER_H_ | 6 #define MEDIA_MP4_BOX_READER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Read at least one child. False means error or no such child present. | 111 // Read at least one child. False means error or no such child present. |
112 template<typename T> bool ReadChildren( | 112 template<typename T> bool ReadChildren( |
113 std::vector<T>* children) WARN_UNUSED_RESULT; | 113 std::vector<T>* children) WARN_UNUSED_RESULT; |
114 | 114 |
115 // Read any number of children. False means error. | 115 // Read any number of children. False means error. |
116 template<typename T> bool MaybeReadChildren( | 116 template<typename T> bool MaybeReadChildren( |
117 std::vector<T>* children) WARN_UNUSED_RESULT; | 117 std::vector<T>* children) WARN_UNUSED_RESULT; |
118 | 118 |
119 // Read all children, regardless of FourCC. This is used from exactly one box, | 119 // Read all children, regardless of FourCC. This is used from exactly one box, |
120 // corresponding to a rather significant inconsistency in the BMFF spec. | 120 // corresponding to a rather significant inconsistency in the BMFF spec. |
| 121 // Note that this method is mutually exclusive with ScanChildren(). |
121 template<typename T> bool ReadAllChildren( | 122 template<typename T> bool ReadAllChildren( |
122 std::vector<T>* children) WARN_UNUSED_RESULT; | 123 std::vector<T>* children) WARN_UNUSED_RESULT; |
123 | 124 |
124 // Populate the values of 'version()' and 'flags()' from a full box header. | 125 // Populate the values of 'version()' and 'flags()' from a full box header. |
125 // Many boxes, but not all, use these values. This call should happen after | 126 // Many boxes, but not all, use these values. This call should happen after |
126 // the box has been initialized, and does not re-read the main box header. | 127 // the box has been initialized, and does not re-read the main box header. |
127 bool ReadFullBoxHeader() WARN_UNUSED_RESULT; | 128 bool ReadFullBoxHeader() WARN_UNUSED_RESULT; |
128 | 129 |
129 FourCC type() const { return type_; } | 130 FourCC type() const { return type_; } |
130 uint8 version() const { return version_; } | 131 uint8 version() const { return version_; } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 179 } |
179 children_.erase(start_itr, end_itr); | 180 children_.erase(start_itr, end_itr); |
180 | 181 |
181 DVLOG(2) << "Found " << children->size() << " " | 182 DVLOG(2) << "Found " << children->size() << " " |
182 << FourCCToString(child_type) << " boxes."; | 183 << FourCCToString(child_type) << " boxes."; |
183 return true; | 184 return true; |
184 } | 185 } |
185 | 186 |
186 template<typename T> | 187 template<typename T> |
187 bool BoxReader::ReadAllChildren(std::vector<T>* children) { | 188 bool BoxReader::ReadAllChildren(std::vector<T>* children) { |
188 DCHECK(scanned_); | 189 DCHECK(!scanned_); |
189 DCHECK(children->empty()); | 190 scanned_ = true; |
190 RCHECK(!children_.empty()); | |
191 | 191 |
192 children->resize(children_.size()); | 192 bool err = false; |
193 typename std::vector<T>::iterator child_itr = children->begin(); | 193 while (pos() < size()) { |
194 for (ChildMap::iterator itr = children_.begin(); | 194 BoxReader child_reader(&buf_[pos_], size_ - pos_); |
195 itr != children_.end(); ++itr) { | 195 if (!child_reader.ReadHeader(&err)) break; |
196 RCHECK(child_itr->Parse(&itr->second)); | 196 T child; |
197 ++child_itr; | 197 RCHECK(child.Parse(&child_reader)); |
| 198 children->push_back(child); |
| 199 pos_ += child_reader.size(); |
198 } | 200 } |
199 children_.clear(); | 201 |
200 return true; | 202 return !err; |
201 } | 203 } |
202 | 204 |
203 } // namespace mp4 | 205 } // namespace mp4 |
204 } // namespace media | 206 } // namespace media |
205 | 207 |
206 #endif // MEDIA_MP4_BOX_READER_H_ | 208 #endif // MEDIA_MP4_BOX_READER_H_ |
OLD | NEW |