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 <cstdint>
11
12#include <packager/media/base/fourccs.h>
13
14namespace shaka {
15namespace media {
16
17class BufferWriter;
18
19namespace mp4 {
20
21class BoxBuffer;
22class BoxReader;
23
27struct 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
83struct 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_
Class for reading MP4 boxes.
Definition box_reader.h:28
All the methods that are virtual are virtual for mocking.
virtual uint32_t HeaderSize() const
Definition box.cc:57
void Write(BufferWriter *writer)
Definition box.cc:27
virtual bool ReadWriteHeaderInternal(BoxBuffer *buffer)
Definition box.cc:63
bool Parse(BoxReader *reader)
Definition box.cc:21
void WriteHeader(BufferWriter *writer)
Definition box.cc:40
uint32_t ComputeSize()
Definition box.cc:52
virtual FourCC BoxType() const =0
uint32_t box_size()
Definition box.h:55
uint32_t HeaderSize() const final
Definition box.cc:77
bool ReadWriteHeaderInternal(BoxBuffer *buffer) final
Definition box.cc:82