Shaka Packager SDK
box.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_FORMATS_MP4_BOX_H_
8 #define PACKAGER_MEDIA_FORMATS_MP4_BOX_H_
9 
10 #include <stdint.h>
11 
12 #include "packager/media/base/fourccs.h"
13 
14 namespace shaka {
15 namespace media {
16 
17 class BufferWriter;
18 
19 namespace mp4 {
20 
21 class BoxBuffer;
22 class BoxReader;
23 
27 struct Box {
28  public:
29  Box();
30  virtual ~Box();
33  bool Parse(BoxReader* reader);
38  void Write(BufferWriter* writer);
43  void WriteHeader(BufferWriter* writer);
47  uint32_t ComputeSize();
49  virtual uint32_t HeaderSize() const;
51  virtual FourCC BoxType() const = 0;
52 
54  // function expects that ComputeSize has been invoked already.
55  uint32_t box_size() { return box_size_; }
56 
57  protected:
61  virtual bool ReadWriteHeaderInternal(BoxBuffer* buffer);
62 
63  private:
64  friend class BoxBuffer;
65  // Read/write the mp4 box from/to BoxBuffer. Note that this function expects
66  // that ComputeSize has been invoked already.
67  virtual bool ReadWriteInternal(BoxBuffer* buffer) = 0;
68  // Compute the size of this box. A value of 0 should be returned if the box
69  // should not be written. Note that this function won't update box size.
70  virtual size_t ComputeSizeInternal() = 0;
71 
72  // We don't support 64-bit box sizes. 32-bit should be large enough for our
73  // current needs.
74  uint32_t box_size_;
75 
76  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
77  // generated copy constructor and assignment operator.
78 };
79 
83 struct FullBox : Box {
84  public:
85  FullBox();
86  ~FullBox() override;
87 
88  uint32_t HeaderSize() const final;
89 
90  uint8_t version = 0;
91  uint32_t flags = 0;
92 
93  protected:
94  bool ReadWriteHeaderInternal(BoxBuffer* buffer) final;
95 
96  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
97  // generated copy constructor and assignment operator.
98 };
99 
100 } // namespace mp4
101 } // namespace media
102 } // namespace shaka
103 
104 #endif // PACKAGER_MEDIA_FORMATS_MP4_BOX_H_
shaka::media::mp4::BoxBuffer
Definition: box_buffer.h:25
shaka::media::BufferWriter
Definition: buffer_writer.h:23
shaka::media::mp4::Box::WriteHeader
void WriteHeader(BufferWriter *writer)
Definition: box.cc:38
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::media::mp4::Box::ReadWriteHeaderInternal
virtual bool ReadWriteHeaderInternal(BoxBuffer *buffer)
Definition: box.cc:61
shaka::media::mp4::FullBox::HeaderSize
uint32_t HeaderSize() const final
Definition: box.cc:75
shaka::media::mp4::FullBox::ReadWriteHeaderInternal
bool ReadWriteHeaderInternal(BoxBuffer *buffer) final
Definition: box.cc:80
shaka::media::mp4::FullBox
Definition: box.h:83
shaka::media::mp4::Box::box_size
uint32_t box_size()
Definition: box.h:55
shaka::media::mp4::BoxReader
Class for reading MP4 boxes.
Definition: box_reader.h:25
shaka::media::mp4::Box::ComputeSize
uint32_t ComputeSize()
Definition: box.cc:50
shaka::media::mp4::Box::HeaderSize
virtual uint32_t HeaderSize() const
Definition: box.cc:55
shaka::media::mp4::Box
Definition: box.h:27
shaka::media::mp4::Box::Write
void Write(BufferWriter *writer)
Definition: box.cc:25
shaka::media::mp4::Box::BoxType
virtual FourCC BoxType() const =0
shaka::media::mp4::Box::Parse
bool Parse(BoxReader *reader)
Definition: box.cc:19