7 #include <packager/media/formats/mp4/box.h>
9 #include <absl/log/check.h>
10 #include <absl/log/log.h>
12 #include <packager/media/formats/mp4/box_buffer.h>
18 Box::Box() : box_size_(0) {}
24 return ReadWriteInternal(&buffer);
30 uint32_t size = ComputeSize();
31 DCHECK_EQ(size, box_size_);
33 size_t buffer_size_before_write = writer->Size();
35 CHECK(ReadWriteInternal(&buffer));
36 DCHECK_EQ(box_size_, writer->Size() - buffer_size_before_write)
37 << FourCCToString(BoxType());
43 uint32_t size = ComputeSize();
44 DCHECK_EQ(size, box_size_);
46 size_t buffer_size_before_write = writer->Size();
48 CHECK(ReadWriteHeaderInternal(&buffer));
49 DCHECK_EQ(HeaderSize(), writer->Size() - buffer_size_before_write);
52 uint32_t Box::ComputeSize() {
53 box_size_ =
static_cast<uint32_t
>(ComputeSizeInternal());
57 uint32_t Box::HeaderSize()
const {
58 const uint32_t kFourCCSize = 4;
60 return kFourCCSize +
sizeof(uint32_t);
63 bool Box::ReadWriteHeaderInternal(
BoxBuffer* buffer) {
67 CHECK(buffer->ReadWriteUInt32(&box_size_));
68 FourCC fourcc = BoxType();
69 CHECK(buffer->ReadWriteFourCC(&fourcc));
74 FullBox::FullBox() =
default;
75 FullBox::~FullBox() =
default;
77 uint32_t FullBox::HeaderSize()
const {
79 return Box::HeaderSize() + 1 + 3;
82 bool FullBox::ReadWriteHeaderInternal(
BoxBuffer* buffer) {
83 RCHECK(Box::ReadWriteHeaderInternal(buffer));
87 RCHECK(buffer->ReadWriteUInt32(&vflags));
88 this->version = vflags >> 24;
89 this->flags = vflags & 0x00FFFFFF;
91 vflags = (this->version << 24) | this->flags;
92 RCHECK(buffer->ReadWriteUInt32(&vflags));
All the methods that are virtual are virtual for mocking.