2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-11-22 21:28:21 +00:00
|
|
|
|
2014-04-10 21:42:38 +00:00
|
|
|
#include "media/formats/mp4/box.h"
|
2013-11-22 21:28:21 +00:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2014-04-10 21:42:38 +00:00
|
|
|
#include "media/formats/mp4/box_buffer.h"
|
2013-11-22 21:28:21 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-11-22 21:28:21 +00:00
|
|
|
namespace media {
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
Box::Box() : atom_size(0) {}
|
|
|
|
Box::~Box() {}
|
|
|
|
|
|
|
|
bool Box::Parse(BoxReader* reader) {
|
|
|
|
DCHECK(reader != NULL);
|
|
|
|
BoxBuffer buffer(reader);
|
|
|
|
return ReadWrite(&buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Box::Write(BufferWriter* writer) {
|
|
|
|
DCHECK(writer != NULL);
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t size = ComputeSize();
|
2013-11-22 21:28:21 +00:00
|
|
|
DCHECK_EQ(size, this->atom_size);
|
|
|
|
|
|
|
|
size_t buffer_size_before_write = writer->Size();
|
|
|
|
BoxBuffer buffer(writer);
|
|
|
|
CHECK(ReadWrite(&buffer));
|
|
|
|
DCHECK_EQ(this->atom_size, writer->Size() - buffer_size_before_write);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Box::ReadWrite(BoxBuffer* buffer) {
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
// Skip for read mode, which is handled already in BoxReader.
|
|
|
|
} else {
|
|
|
|
CHECK(buffer->ReadWriteUInt32(&this->atom_size));
|
|
|
|
FourCC fourcc = BoxType();
|
|
|
|
CHECK(buffer->ReadWriteFourCC(&fourcc));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
FullBox::FullBox() : version(0), flags(0) {}
|
|
|
|
FullBox::~FullBox() {}
|
|
|
|
|
|
|
|
bool FullBox::ReadWrite(BoxBuffer* buffer) {
|
|
|
|
RCHECK(Box::ReadWrite(buffer));
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t vflags;
|
2013-11-22 21:28:21 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&vflags));
|
|
|
|
this->version = vflags >> 24;
|
|
|
|
this->flags = vflags & 0x00FFFFFF;
|
|
|
|
} else {
|
|
|
|
vflags = (this->version << 24) | this->flags;
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&vflags));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|