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);
37 const size_t buf_size,
39 std::unique_ptr<BoxReader> reader(
new BoxReader(buf, buf_size));
40 if (!reader->ReadHeader(err))
44 if (reader->type() == FOURCC_mdat)
45 return reader.release();
47 if (reader->size() <= buf_size)
48 return reader.release();
55 const size_t buf_size,
60 if (!reader.ReadHeader(err))
62 *type = reader.type();
63 *box_size = reader.size();
71 while (pos() < size()) {
72 std::unique_ptr<BoxReader> child(
73 new BoxReader(&data()[pos()], size() - pos()));
75 if (!child->ReadHeader(&err))
78 FourCC box_type = child->type();
80 children_.insert(std::pair<FourCC, std::unique_ptr<BoxReader>>(
81 box_type, std::move(child)));
82 RCHECK(SkipBytes(box_size));
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.get()));
101 return children_.count(child->
BoxType()) > 0;
105 if (!children_.count(child->
BoxType()))
107 return ReadChild(child);
110 bool BoxReader::ReadHeader(
bool* err) {
114 if (!ReadNBytesInto8(&size,
sizeof(uint32_t)) || !ReadFourCC(&type_))
119 NOTIMPLEMENTED() << base::StringPrintf(
"Box '%s' run to EOS.",
120 FourCCToString(type_).c_str());
123 }
else if (size == 1) {
130 LOG(ERROR) << base::StringPrintf(
"Box '%s' with size (%" PRIu64
132 FourCCToString(type_).c_str(),
139 if (size > static_cast<uint64_t>(std::numeric_limits<int32_t>::max()) &&
140 type_ != FOURCC_mdat) {
141 LOG(ERROR) << base::StringPrintf(
"Box '%s' size (%" PRIu64
143 FourCCToString(type_).c_str(),
All the methods that are virtual are virtual for mocking.