Shaka Packager SDK
Loading...
Searching...
No Matches
box.h
1// Copyright 2014 Google LLC. 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 <cstddef>
11#include <cstdint>
12
13#include <packager/media/base/fourccs.h>
14
15namespace shaka {
16namespace media {
17
18class BufferWriter;
19
20namespace mp4 {
21
22class BoxBuffer;
23class BoxReader;
24
28struct Box {
29 public:
30 Box();
31 virtual ~Box();
34 bool Parse(BoxReader* reader);
39 void Write(BufferWriter* writer);
44 void WriteHeader(BufferWriter* writer);
48 uint32_t ComputeSize();
50 virtual uint32_t HeaderSize() const;
52 virtual FourCC BoxType() const = 0;
53
55 // function expects that ComputeSize has been invoked already.
56 uint32_t box_size() { return box_size_; }
57
58 protected:
62 virtual bool ReadWriteHeaderInternal(BoxBuffer* buffer);
63
64 private:
65 friend class BoxBuffer;
66 // Read/write the mp4 box from/to BoxBuffer. Note that this function expects
67 // that ComputeSize has been invoked already.
68 virtual bool ReadWriteInternal(BoxBuffer* buffer) = 0;
69 // Compute the size of this box. A value of 0 should be returned if the box
70 // should not be written. Note that this function won't update box size.
71 virtual size_t ComputeSizeInternal() = 0;
72
73 // We don't support 64-bit box sizes. 32-bit should be large enough for our
74 // current needs.
75 uint32_t box_size_;
76
77 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
78 // generated copy constructor and assignment operator.
79};
80
84struct FullBox : Box {
85 public:
86 FullBox();
87 ~FullBox() override;
88
89 uint32_t HeaderSize() const final;
90
91 uint8_t version = 0;
92 uint32_t flags = 0;
93
94 protected:
95 bool ReadWriteHeaderInternal(BoxBuffer* buffer) final;
96
97 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
98 // generated copy constructor and assignment operator.
99};
100
101} // namespace mp4
102} // namespace media
103} // namespace shaka
104
105#endif // PACKAGER_MEDIA_FORMATS_MP4_BOX_H_
Class for reading MP4 boxes.
Definition box_reader.h:30
All the methods that are virtual are virtual for mocking.
virtual uint32_t HeaderSize() const
Definition box.cc:61
void Write(BufferWriter *writer)
Definition box.cc:31
virtual bool ReadWriteHeaderInternal(BoxBuffer *buffer)
Definition box.cc:67
bool Parse(BoxReader *reader)
Definition box.cc:25
void WriteHeader(BufferWriter *writer)
Definition box.cc:44
uint32_t ComputeSize()
Definition box.cc:56
virtual FourCC BoxType() const =0
uint32_t box_size()
Definition box.h:56
uint32_t HeaderSize() const final
Definition box.cc:81
bool ReadWriteHeaderInternal(BoxBuffer *buffer) final
Definition box.cc:86