DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerator
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 MEDIA_FORMATS_MP4_BOX_H_
8 #define MEDIA_FORMATS_MP4_BOX_H_
9 
10 #include <stdint.h>
11 
12 #include "packager/media/formats/mp4/fourccs.h"
13 
14 namespace edash_packager {
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 
53  protected:
57  virtual bool ReadWriteHeaderInternal(BoxBuffer* buffer);
58 
59  private:
60  friend class BoxBuffer;
61  // Read/write the mp4 box from/to BoxBuffer. Note that this function expects
62  // box size updated already.
63  virtual bool ReadWriteInternal(BoxBuffer* buffer) = 0;
64  // Compute the size of this box. A value of 0 should be returned if the box
65  // should not be written. Note that this function won't update box size.
66  virtual uint32_t ComputeSizeInternal() = 0;
67 
68  // We don't support 64-bit atom sizes. 32-bit should be large enough for our
69  // current needs.
70  uint32_t atom_size;
71 
72  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
73  // generated copy constructor and assignment operator.
74 };
75 
79 struct FullBox : Box {
80  public:
81  FullBox();
82  ~FullBox() override;
83 
84  uint32_t HeaderSize() const final;
85 
86  uint8_t version;
87  uint32_t flags;
88 
89  protected:
90  bool ReadWriteHeaderInternal(BoxBuffer* buffer) final;
91 
92  // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
93  // generated copy constructor and assignment operator.
94 };
95 
96 } // namespace mp4
97 } // namespace media
98 } // namespace edash_packager
99 
100 #endif // MEDIA_FORMATS_MP4_BOX_H_
virtual bool ReadWriteHeaderInternal(BoxBuffer *buffer)
Definition: box.cc:60
bool ReadWriteHeaderInternal(BoxBuffer *buffer) final
Definition: box.cc:79
bool Parse(BoxReader *reader)
Definition: box.cc:19
void WriteHeader(BufferWriter *writer)
Definition: box.cc:37
virtual uint32_t HeaderSize() const
Definition: box.cc:54
void Write(BufferWriter *writer)
Definition: box.cc:25
virtual FourCC BoxType() const =0
Class for reading MP4 boxes.
Definition: box_reader.h:24
uint32_t HeaderSize() const final
Definition: box.cc:74