5 #ifndef MEDIA_FORMATS_MP4_BOX_READER_H_
6 #define MEDIA_FORMATS_MP4_BOX_READER_H_
11 #include "packager/base/compiler_specific.h"
12 #include "packager/base/logging.h"
13 #include "packager/media/base/buffer_reader.h"
14 #include "packager/media/base/fourccs.h"
15 #include "packager/media/base/rcheck.h"
39 const size_t buf_size,
51 static bool StartBox(
const uint8_t* buf,
52 const size_t buf_size,
55 bool* err) WARN_UNUSED_RESULT;
78 bool ReadChildren(std::vector<T>* children) WARN_UNUSED_RESULT;
91 bool ReadFourCC(FourCC* fourcc) {
95 *fourcc =
static_cast<FourCC
>(val);
99 FourCC type()
const {
return type_; }
102 BoxReader(
const uint8_t* buf,
size_t size);
111 bool ReadHeader(
bool* err);
115 typedef std::multimap<FourCC, BoxReader*> ChildMap;
126 template <
typename T>
132 template <
typename T>
135 DCHECK(children->empty());
138 FourCC child_type = (*children)[0].BoxType();
140 ChildMap::iterator start_itr = children_.lower_bound(child_type);
141 ChildMap::iterator end_itr = children_.upper_bound(child_type);
142 children->resize(std::distance(start_itr, end_itr));
143 typename std::vector<T>::iterator child_itr = children->begin();
144 for (ChildMap::iterator itr = start_itr; itr != end_itr; ++itr) {
145 RCHECK(child_itr->Parse(itr->second));
149 children_.erase(start_itr, end_itr);
151 DVLOG(2) <<
"Found " << children->size() <<
" " << FourCCToString(child_type)
156 template <
typename T>
161 while (pos() < size()) {
162 BoxReader child_reader(&data()[pos()], size() - pos());
164 if (!child_reader.ReadHeader(&err))
168 RCHECK(child.Parse(&child_reader));
169 children->push_back(child);
180 #endif // MEDIA_FORMATS_MP4_BOX_READER_H_