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
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_MP4_BOX_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_MP4_BOX_H_
|
2013-11-22 21:28:21 +00:00
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-04-06 23:21:45 +00:00
|
|
|
#include "packager/media/base/fourccs.h"
|
2013-11-22 21:28:21 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-11-22 21:28:21 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class BufferWriter;
|
|
|
|
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
class BoxBuffer;
|
|
|
|
class BoxReader;
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Defines the base ISO BMFF box objects as defined in ISO 14496-12:2012
|
|
|
|
/// ISO BMFF section 4.2. All ISO BMFF compatible boxes inherit from either
|
|
|
|
/// Box or FullBox.
|
2013-11-22 21:28:21 +00:00
|
|
|
struct Box {
|
|
|
|
public:
|
|
|
|
Box();
|
|
|
|
virtual ~Box();
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Parse the mp4 box.
|
|
|
|
/// @param reader points to a BoxReader object which parses the box.
|
2013-11-22 21:28:21 +00:00
|
|
|
bool Parse(BoxReader* reader);
|
2015-12-15 00:07:51 +00:00
|
|
|
/// Write the box to buffer. This function calls ComputeSize internally to
|
|
|
|
/// compute and update box size.
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @param writer points to a BufferWriter object which wraps the buffer for
|
|
|
|
/// writing.
|
2013-11-22 21:28:21 +00:00
|
|
|
void Write(BufferWriter* writer);
|
2015-12-15 00:07:51 +00:00
|
|
|
/// Write the box header to buffer. This function calls ComputeSize internally
|
|
|
|
/// to compute and update box size.
|
|
|
|
/// @param writer points to a BufferWriter object which wraps the buffer for
|
|
|
|
/// writing.
|
|
|
|
void WriteHeader(BufferWriter* writer);
|
|
|
|
/// Compute the size of this box. It will also update box size.
|
|
|
|
/// @return The size of result box including child boxes. A value of 0 should
|
|
|
|
/// be returned if the box should not be written.
|
|
|
|
uint32_t ComputeSize();
|
|
|
|
/// @return box header size in bytes.
|
|
|
|
virtual uint32_t HeaderSize() const;
|
|
|
|
/// @return box type.
|
2013-11-22 21:28:21 +00:00
|
|
|
virtual FourCC BoxType() const = 0;
|
|
|
|
|
2015-12-21 18:34:21 +00:00
|
|
|
/// @return The size of result box including child boxes. Note that this
|
|
|
|
// function expects that ComputeSize has been invoked already.
|
|
|
|
uint32_t box_size() { return box_size_; }
|
|
|
|
|
2013-11-22 21:28:21 +00:00
|
|
|
protected:
|
2015-12-21 18:34:21 +00:00
|
|
|
/// Read/write mp4 box header. Note that this function expects that
|
|
|
|
/// ComputeSize has been invoked already.
|
2015-12-15 00:07:51 +00:00
|
|
|
/// @return true on success, false otherwise.
|
|
|
|
virtual bool ReadWriteHeaderInternal(BoxBuffer* buffer);
|
|
|
|
|
|
|
|
private:
|
2013-11-22 21:28:21 +00:00
|
|
|
friend class BoxBuffer;
|
2015-12-15 00:07:51 +00:00
|
|
|
// Read/write the mp4 box from/to BoxBuffer. Note that this function expects
|
2015-12-21 18:34:21 +00:00
|
|
|
// that ComputeSize has been invoked already.
|
2015-12-15 00:07:51 +00:00
|
|
|
virtual bool ReadWriteInternal(BoxBuffer* buffer) = 0;
|
|
|
|
// Compute the size of this box. A value of 0 should be returned if the box
|
|
|
|
// should not be written. Note that this function won't update box size.
|
2016-11-09 02:11:13 +00:00
|
|
|
virtual size_t ComputeSizeInternal() = 0;
|
2013-11-22 21:28:21 +00:00
|
|
|
|
2015-12-21 18:34:21 +00:00
|
|
|
// We don't support 64-bit box sizes. 32-bit should be large enough for our
|
2015-12-15 00:07:51 +00:00
|
|
|
// current needs.
|
2015-12-21 18:34:21 +00:00
|
|
|
uint32_t box_size_;
|
2015-12-15 00:07:51 +00:00
|
|
|
|
|
|
|
// Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
|
|
|
|
// generated copy constructor and assignment operator.
|
2013-11-22 21:28:21 +00:00
|
|
|
};
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Defines FullBox, the other base ISO BMFF box objects as defined in
|
|
|
|
/// ISO 14496-12:2012 ISO BMFF section 4.2. All ISO BMFF compatible boxes
|
|
|
|
/// inherit from either Box or FullBox.
|
2013-11-22 21:28:21 +00:00
|
|
|
struct FullBox : Box {
|
|
|
|
public:
|
|
|
|
FullBox();
|
2015-07-22 23:40:45 +00:00
|
|
|
~FullBox() override;
|
2013-11-22 21:28:21 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
uint32_t HeaderSize() const final;
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint8_t version;
|
|
|
|
uint32_t flags;
|
2013-11-22 21:28:21 +00:00
|
|
|
|
|
|
|
protected:
|
2015-12-15 00:07:51 +00:00
|
|
|
bool ReadWriteHeaderInternal(BoxBuffer* buffer) final;
|
|
|
|
|
|
|
|
// Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
|
|
|
|
// generated copy constructor and assignment operator.
|
2013-11-22 21:28:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-11-22 21:28:21 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_MP4_BOX_H_
|