5 #include "packager/media/formats/mp4/box_reader.h"
12 #include "packager/base/logging.h"
13 #include "packager/base/strings/stringprintf.h"
14 #include "packager/media/formats/mp4/box.h"
20 BoxReader::BoxReader(
const uint8_t* buf,
size_t size)
21 : BufferReader(buf, size), type_(FOURCC_NULL), scanned_(false) {
26 BoxReader::~BoxReader() {
27 if (scanned_ && !children_.empty()) {
28 for (ChildMap::iterator itr = children_.begin(); itr != children_.end();
30 DVLOG(1) <<
"Skipping unknown box: " << FourCCToString(itr->first);
38 const size_t buf_size,
40 std::unique_ptr<BoxReader> reader(
new BoxReader(buf, buf_size));
41 if (!reader->ReadHeader(err))
45 if (reader->type() == FOURCC_mdat)
46 return reader.release();
48 if (reader->size() <= buf_size)
49 return reader.release();
56 const size_t buf_size,
61 if (!reader.ReadHeader(err))
63 *type = reader.type();
64 *box_size = reader.size();
72 while (pos() < size()) {
73 std::unique_ptr<BoxReader> child(
74 new BoxReader(&data()[pos()], size() - pos()));
76 if (!child->ReadHeader(&err))
79 FourCC box_type = child->type();
80 size_t box_size = child->size();
81 children_.insert(std::pair<FourCC, BoxReader*>(box_type, child.release()));
90 FourCC child_type = child->
BoxType();
92 ChildMap::iterator itr = children_.find(child_type);
93 RCHECK(itr != children_.end());
94 DVLOG(2) <<
"Found a " << FourCCToString(child_type) <<
" box.";
95 RCHECK(child->
Parse(itr->second));
102 return children_.count(child->
BoxType()) > 0;
106 if (!children_.count(child->
BoxType()))
111 bool BoxReader::ReadHeader(
bool* err) {
120 NOTIMPLEMENTED() << base::StringPrintf(
"Box '%s' run to EOS.",
121 FourCCToString(type_).c_str());
124 }
else if (size == 1) {
131 LOG(ERROR) << base::StringPrintf(
"Box '%s' with size (%" PRIu64
133 FourCCToString(type_).c_str(),
140 if (size > static_cast<uint64_t>(std::numeric_limits<int32_t>::max()) &&
141 type_ != FOURCC_mdat) {
142 LOG(ERROR) << base::StringPrintf(
"Box '%s' size (%" PRIu64
144 FourCCToString(type_).c_str(),