5 #include "packager/media/formats/mp4/box_reader.h"
11 #include "packager/base/logging.h"
12 #include "packager/base/memory/scoped_ptr.h"
13 #include "packager/base/strings/stringprintf.h"
14 #include "packager/media/formats/mp4/box.h"
16 namespace edash_packager {
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 scoped_ptr<BoxReader> reader(
new BoxReader(buf, buf_size));
41 if (!reader->ReadHeader(err))
45 if (reader->type() == FOURCC_mdat)
46 return reader.release();
53 if (reader->size() <= buf_size)
54 return reader.release();
61 const size_t buf_size,
66 if (!reader.ReadHeader(err))
72 *type = reader.type();
73 *box_size = reader.size();
98 LOG(ERROR) <<
"Unrecognized top-level box type 0x" << std::hex << type;
107 while (pos() < size()) {
108 scoped_ptr<BoxReader> child(
109 new BoxReader(&data()[pos()], size() - pos()));
111 if (!child->ReadHeader(&err))
114 FourCC box_type = child->type();
115 size_t box_size = child->size();
116 children_.insert(std::pair<FourCC, BoxReader*>(box_type, child.release()));
125 FourCC child_type = child->
BoxType();
127 ChildMap::iterator itr = children_.find(child_type);
128 RCHECK(itr != children_.end());
129 DVLOG(2) <<
"Found a " << FourCCToString(child_type) <<
" box.";
130 RCHECK(child->
Parse(itr->second));
132 children_.erase(itr);
137 return children_.count(child->
BoxType()) > 0;
141 if (!children_.count(child->
BoxType()))
146 bool BoxReader::ReadHeader(
bool* err) {
155 NOTIMPLEMENTED() << base::StringPrintf(
"Box '%s' run to EOS.",
156 FourCCToString(type_).c_str());
159 }
else if (size == 1) {
166 LOG(ERROR) << base::StringPrintf(
"Box '%s' with size (%" PRIu64
168 FourCCToString(type_).c_str(),
175 if (size > static_cast<uint64_t>(std::numeric_limits<int32_t>::max()) &&
176 type_ != FOURCC_mdat) {
177 LOG(ERROR) << base::StringPrintf(
"Box '%s' size (%" PRIu64
179 FourCCToString(type_).c_str(),