7 #include "packager/media/formats/mp4/box.h"
9 #include "packager/base/logging.h"
10 #include "packager/media/formats/mp4/box_buffer.h"
16 Box::Box() : box_size_(0) {}
22 return ReadWriteInternal(&buffer);
28 uint32_t size = ComputeSize();
29 DCHECK_EQ(size, box_size_);
31 size_t buffer_size_before_write = writer->Size();
33 CHECK(ReadWriteInternal(&buffer));
34 DCHECK_EQ(box_size_, writer->Size() - buffer_size_before_write)
35 << FourCCToString(BoxType());
41 uint32_t size = ComputeSize();
42 DCHECK_EQ(size, box_size_);
44 size_t buffer_size_before_write = writer->Size();
46 CHECK(ReadWriteHeaderInternal(&buffer));
47 DCHECK_EQ(HeaderSize(), writer->Size() - buffer_size_before_write);
50 uint32_t Box::ComputeSize() {
51 box_size_ =
static_cast<uint32_t
>(ComputeSizeInternal());
55 uint32_t Box::HeaderSize()
const {
56 const uint32_t kFourCCSize = 4;
58 return kFourCCSize +
sizeof(uint32_t);
61 bool Box::ReadWriteHeaderInternal(
BoxBuffer* buffer) {
65 CHECK(buffer->ReadWriteUInt32(&box_size_));
66 FourCC fourcc = BoxType();
67 CHECK(buffer->ReadWriteFourCC(&fourcc));
72 FullBox::FullBox() =
default;
73 FullBox::~FullBox() =
default;
75 uint32_t FullBox::HeaderSize()
const {
77 return Box::HeaderSize() + 1 + 3;
80 bool FullBox::ReadWriteHeaderInternal(
BoxBuffer* buffer) {
81 RCHECK(Box::ReadWriteHeaderInternal(buffer));
85 RCHECK(buffer->ReadWriteUInt32(&vflags));
86 this->version = vflags >> 24;
87 this->flags = vflags & 0x00FFFFFF;
89 vflags = (this->version << 24) | this->flags;
90 RCHECK(buffer->ReadWriteUInt32(&vflags));
All the methods that are virtual are virtual for mocking.