Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 // Read at least one child. False means error or no such child present. | 133 // Read at least one child. False means error or no such child present. |
| 134 template<typename T> bool ReadChildren( | 134 template<typename T> bool ReadChildren( |
| 135 std::vector<T>* children) WARN_UNUSED_RESULT; | 135 std::vector<T>* children) WARN_UNUSED_RESULT; |
| 136 | 136 |
| 137 // Read any number of children. False means error. | 137 // Read any number of children. False means error. |
| 138 template<typename T> bool MaybeReadChildren( | 138 template<typename T> bool MaybeReadChildren( |
| 139 std::vector<T>* children) WARN_UNUSED_RESULT; | 139 std::vector<T>* children) WARN_UNUSED_RESULT; |
| 140 | 140 |
| 141 // Read all children, regardless of FourCC. This is used from exactly one box, | 141 // Read all children, regardless of FourCC. This is used from exactly one box, |
| 142 // corresponding to a rather significant inconsistency in the BMFF spec. | 142 // corresponding to a rather significant inconsistency in the BMFF spec. |
| 143 // Note that this method is mutually exclusive with ScanChildren(). | 143 // Note that this method is mutually exclusive with ScanChildren(). |
|
ddorwin
2015/07/01 20:22:35
and ReadAllChildrenAndCheckFourCC()
jrummell
2015/07/01 20:57:59
Done.
| |
| 144 template<typename T> bool ReadAllChildren( | 144 template <typename T> |
| 145 std::vector<T>* children) WARN_UNUSED_RESULT; | 145 bool ReadAllChildren(std::vector<T>* children) WARN_UNUSED_RESULT { |
|
ddorwin
2015/07/01 20:22:35
Given the comment about this being called in one p
jrummell
2015/07/01 20:57:59
Acknowledged.
| |
| 146 return ReadAllChildrenInternal(children, false); | |
| 147 } | |
| 148 | |
| 149 // Read all children and verify that the FourCC matches what is expected. | |
| 150 // Note that this method is mutually exclusive with ScanChildren(). | |
|
ddorwin
2015/07/01 20:22:35
and ReadAllChildren()
jrummell
2015/07/01 20:57:59
Done.
| |
| 151 template <typename T> | |
|
ddorwin
2015/07/01 20:22:35
// Returns true if all children are successfully p
jrummell
2015/07/01 20:57:59
Done.
| |
| 152 bool ReadAllChildrenAndCheckFourCC(std::vector<T>* children) | |
| 153 WARN_UNUSED_RESULT { | |
| 154 return ReadAllChildrenInternal(children, true); | |
| 155 } | |
| 146 | 156 |
| 147 // Populate the values of 'version()' and 'flags()' from a full box header. | 157 // Populate the values of 'version()' and 'flags()' from a full box header. |
| 148 // Many boxes, but not all, use these values. This call should happen after | 158 // Many boxes, but not all, use these values. This call should happen after |
| 149 // the box has been initialized, and does not re-read the main box header. | 159 // the box has been initialized, and does not re-read the main box header. |
| 150 bool ReadFullBoxHeader() WARN_UNUSED_RESULT; | 160 bool ReadFullBoxHeader() WARN_UNUSED_RESULT; |
| 151 | 161 |
| 152 FourCC type() const { return type_; } | 162 FourCC type() const { return type_; } |
| 153 uint8 version() const { return version_; } | 163 uint8 version() const { return version_; } |
| 154 uint32 flags() const { return flags_; } | 164 uint32 flags() const { return flags_; } |
| 155 | 165 |
| 156 const LogCB& log_cb() const { return log_cb_; } | 166 const LogCB& log_cb() const { return log_cb_; } |
| 157 | 167 |
| 158 private: | 168 private: |
| 159 // Create a BoxReader from |buf|. |is_EOS| should be true if |buf| is | 169 // Create a BoxReader from |buf|. |is_EOS| should be true if |buf| is |
| 160 // complete stream (i.e. no additional data is expected to be appended). | 170 // 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); | 171 BoxReader(const uint8* buf, const int size, const LogCB& log_cb, bool is_EOS); |
| 162 | 172 |
| 163 // Must be called immediately after init. If the return is false, this | 173 // 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 | 174 // 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 | 175 // 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 | 176 // 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 | 177 // 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 | 178 // 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. | 179 // true, the error is unrecoverable and the stream should be aborted. |
| 170 bool ReadHeader(bool* err); | 180 bool ReadHeader(bool* err); |
| 171 | 181 |
| 182 // Read all children, optionally checking FourCC. Note that this method is | |
| 183 // mutually exclusive with ScanChildren(). | |
| 184 template <typename T> | |
|
ddorwin
2015/07/01 20:22:35
// Returns true if all children are successfully p
jrummell
2015/07/01 20:57:59
Done.
| |
| 185 bool ReadAllChildrenInternal(std::vector<T>* children, bool check_box_type); | |
| 186 | |
| 172 LogCB log_cb_; | 187 LogCB log_cb_; |
| 173 FourCC type_; | 188 FourCC type_; |
| 174 uint8 version_; | 189 uint8 version_; |
| 175 uint32 flags_; | 190 uint32 flags_; |
| 176 | 191 |
| 177 typedef std::multimap<FourCC, BoxReader> ChildMap; | 192 typedef std::multimap<FourCC, BoxReader> ChildMap; |
| 178 | 193 |
| 179 // The set of child box FourCCs and their corresponding buffer readers. Only | 194 // The set of child box FourCCs and their corresponding buffer readers. Only |
| 180 // valid if scanned_ is true. | 195 // valid if scanned_ is true. |
| 181 ChildMap children_; | 196 ChildMap children_; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 207 RCHECK(child_itr->Parse(&itr->second)); | 222 RCHECK(child_itr->Parse(&itr->second)); |
| 208 ++child_itr; | 223 ++child_itr; |
| 209 } | 224 } |
| 210 children_.erase(start_itr, end_itr); | 225 children_.erase(start_itr, end_itr); |
| 211 | 226 |
| 212 DVLOG(2) << "Found " << children->size() << " " | 227 DVLOG(2) << "Found " << children->size() << " " |
| 213 << FourCCToString(child_type) << " boxes."; | 228 << FourCCToString(child_type) << " boxes."; |
| 214 return true; | 229 return true; |
| 215 } | 230 } |
| 216 | 231 |
| 217 template<typename T> | 232 template <typename T> |
| 218 bool BoxReader::ReadAllChildren(std::vector<T>* children) { | 233 bool BoxReader::ReadAllChildrenInternal(std::vector<T>* children, |
| 234 bool check_box_type) { | |
| 219 DCHECK(!scanned_); | 235 DCHECK(!scanned_); |
| 220 scanned_ = true; | 236 scanned_ = true; |
| 221 | 237 |
| 222 bool err = false; | 238 bool err = false; |
| 223 while (pos_ < size_) { | 239 while (pos_ < size_) { |
| 224 BoxReader child_reader(&buf_[pos_], size_ - pos_, log_cb_, is_EOS_); | 240 BoxReader child_reader(&buf_[pos_], size_ - pos_, log_cb_, is_EOS_); |
| 225 if (!child_reader.ReadHeader(&err)) break; | 241 if (!child_reader.ReadHeader(&err)) break; |
| 226 T child; | 242 T child; |
| 243 RCHECK(!check_box_type || child_reader.type() == child.BoxType()); | |
| 227 RCHECK(child.Parse(&child_reader)); | 244 RCHECK(child.Parse(&child_reader)); |
| 228 children->push_back(child); | 245 children->push_back(child); |
| 229 pos_ += child_reader.size(); | 246 pos_ += child_reader.size(); |
| 230 } | 247 } |
| 231 | 248 |
| 232 return !err; | 249 return !err; |
| 233 } | 250 } |
| 234 | 251 |
| 235 } // namespace mp4 | 252 } // namespace mp4 |
| 236 } // namespace media | 253 } // namespace media |
| 237 | 254 |
| 238 #endif // MEDIA_FORMATS_MP4_BOX_READER_H_ | 255 #endif // MEDIA_FORMATS_MP4_BOX_READER_H_ |
| OLD | NEW |