5 #ifndef MEDIA_FORMATS_MP4_BOX_READER_H_
6 #define MEDIA_FORMATS_MP4_BOX_READER_H_
12 #include "packager/base/compiler_specific.h"
13 #include "packager/base/logging.h"
14 #include "packager/media/base/buffer_reader.h"
15 #include "packager/media/base/fourccs.h"
16 #include "packager/media/base/rcheck.h"
40 const size_t buf_size,
52 static bool StartBox(
const uint8_t* buf,
53 const size_t buf_size,
56 bool* err) WARN_UNUSED_RESULT;
79 bool ReadChildren(std::vector<T>* children) WARN_UNUSED_RESULT;
92 bool ReadFourCC(FourCC* fourcc) {
96 *fourcc =
static_cast<FourCC
>(val);
100 FourCC type()
const {
return type_; }
103 BoxReader(
const uint8_t* buf,
size_t size);
112 bool ReadHeader(
bool* err);
116 typedef std::multimap<FourCC, std::unique_ptr<BoxReader>> ChildMap;
127 template <
typename T>
133 template <
typename T>
136 DCHECK(children->empty());
139 FourCC child_type = (*children)[0].BoxType();
141 ChildMap::iterator start_itr = children_.lower_bound(child_type);
142 ChildMap::iterator end_itr = children_.upper_bound(child_type);
143 children->resize(std::distance(start_itr, end_itr));
144 typename std::vector<T>::iterator child_itr = children->begin();
145 for (ChildMap::iterator itr = start_itr; itr != end_itr; ++itr) {
146 RCHECK(child_itr->Parse(itr->second.get()));
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_