5 #ifndef PACKAGER_MEDIA_FORMATS_MP4_BOX_READER_H_
6 #define PACKAGER_MEDIA_FORMATS_MP4_BOX_READER_H_
12 #include <absl/log/check.h>
13 #include <absl/log/log.h>
15 #include <packager/macros/classes.h>
16 #include <packager/macros/logging.h>
17 #include <packager/media/base/buffer_reader.h>
18 #include <packager/media/base/fourccs.h>
19 #include <packager/media/base/rcheck.h>
43 const size_t buf_size,
55 [[nodiscard]]
static bool StartBox(
const uint8_t* buf,
56 const size_t buf_size,
82 [[nodiscard]]
bool ReadChildren(std::vector<T>* children);
95 bool ReadFourCC(FourCC* fourcc) {
99 *fourcc =
static_cast<FourCC
>(val);
103 FourCC type()
const {
return type_; }
106 BoxReader(
const uint8_t* buf,
size_t size);
115 bool ReadHeader(
bool* err);
119 typedef std::multimap<FourCC, std::unique_ptr<BoxReader>> ChildMap;
130 template <
typename T>
136 template <
typename T>
139 DCHECK(children->empty());
142 FourCC child_type = (*children)[0].BoxType();
144 ChildMap::iterator start_itr = children_.lower_bound(child_type);
145 ChildMap::iterator end_itr = children_.upper_bound(child_type);
146 children->resize(std::distance(start_itr, end_itr));
147 typename std::vector<T>::iterator child_itr = children->begin();
148 for (ChildMap::iterator itr = start_itr; itr != end_itr; ++itr) {
149 RCHECK(child_itr->Parse(itr->second.get()));
152 children_.erase(start_itr, end_itr);
154 DVLOG(2) <<
"Found " << children->size() <<
" " << FourCCToString(child_type)
159 template <
typename T>
164 while (pos() < size()) {
165 BoxReader child_reader(&data()[pos()], size() - pos());
167 if (!child_reader.ReadHeader(&err))
171 RCHECK(child.Parse(&child_reader));
172 children->push_back(child);
All the methods that are virtual are virtual for mocking.