3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / media / plugins / mp4_reader / libMP4 / MP4Atom.h
blob4aa89f7ed4e5285dde9451f9602467a5d32b97f4
1 /*
2 * Copyright (c) 2005, David McPaul
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23 * OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef _MP4_ATOM_H
26 #define _MP4_ATOM_H
29 #include "MP4Structs.h"
31 #include <File.h>
32 #include <MediaDefs.h>
33 #include <MediaFormats.h>
34 #include <SupportDefs.h>
36 #include <vector>
40 AtomBase
41 theStream : Stream;
42 streamOffset : FilePtr;
43 atomOffset : FilePtr;
44 atomSize : int64;
45 atomType : int32; // Can be a number or a 4 char FOURCC
46 atomChildren : Array of AtomBase;
48 public
49 ProcessMetaData() - Reads in the basic Atom Meta Data
50 - Calls OnProcessMetaData()
51 - Calls ProcessMetaData on each child atom
52 (ensures stream is correct for child via offset)
53 OnProcessMetaData() - Subclass override to read/set meta data
55 AddChild(AtomBase) - Adds a child atom to the children array
57 MoveToEnd() - Moves stream ptr to end of atom
59 GetTypeAsString() - returns the type as something the user can read*/
62 class AtomBase;
65 typedef AtomBase* AtomBasePtr;
66 typedef std::vector<AtomBasePtr> AtomArray;
69 class AtomBase {
71 This is the basic or standard atom. It contains data describing some aspect of the file/stream
73 private:
74 off_t streamOffset;
75 off_t atomOffset;
76 uint32 atomType;
77 uint64 atomSize;
78 char fourcc[5]; // make this an alias to atomType
79 AtomBase* parentAtom;
81 protected:
82 BPositionIO *theStream;
83 void Indent(uint32 pindent);
85 public:
86 AtomBase(BPositionIO *pStream, off_t pstreamOffset,
87 uint32 patomType, uint64 patomSize);
88 virtual ~AtomBase();
90 virtual bool IsContainer() {return false;};
92 virtual BPositionIO *OnGetStream();
93 BPositionIO *GetStream();
95 bool IsExtended() {return false;};
96 bool IsEndOfAtom() {return (GetStream()->Position() >=
97 off_t(streamOffset + atomSize));};
99 // Is this a known atom type
100 bool IsKnown();
102 virtual void DisplayAtoms(uint32 pindent);
104 uint64 GetAtomSize() {return atomSize;};
105 uint32 GetAtomType() {return atomType;};
106 char* GetAtomTypeAsFourcc();
107 off_t GetAtomOffset() { return atomOffset; };
108 off_t GetStreamOffset() { return streamOffset; };
110 uint64 GetDataSize() { return atomSize - 8;};
112 uint64 GetBytesRemaining();
114 bool IsType(uint32 patomType) { return patomType == atomType; };
116 void SetAtomOffset(off_t patomOffset) { atomOffset = patomOffset; };
117 void SetStreamOffset(off_t pstreamOffset) { streamOffset = pstreamOffset; };
119 const char *GetAtomName();
121 virtual const char *OnGetAtomName();
123 // ProcessMetaData() - Reads in the basic Atom Meta Data
124 // - Calls OnProcessMetaData()
125 virtual void ProcessMetaData();
127 // OnProcessMetaData() - Subclass override to read/set meta data
128 virtual void OnProcessMetaData();
130 // Move stream ptr to where atom ends in stream (return false on failure)
131 bool MoveToEnd();
133 void DisplayAtoms();
135 // Many atoms use an array header
136 void ReadArrayHeader(array_header *pHeader);
138 void SetParent(AtomBase *pParent) {parentAtom = pParent;};
139 AtomBase* GetParent() { return parentAtom;};
141 void Read(uint64 *value);
142 void Read(uint32 *value);
143 void Read(int32 *value);
144 void Read(uint16 *value);
145 void Read(uint8 *value);
146 void Read(char *value, uint32 maxread);
147 void Read(uint8 *value, uint32 maxread);
149 uint64 GetBits(uint64 buffer, uint8 startBit, uint8 totalBits);
150 uint32 GetBits(uint32 buffer, uint8 startBit, uint8 totalBits);
154 class FullAtom : public AtomBase {
155 public:
156 FullAtom(BPositionIO *pStream, off_t pstreamOffset,
157 uint32 patomType, uint64 patomSize);
158 virtual ~FullAtom();
160 virtual void OnProcessMetaData();
161 uint8 GetVersion() {return Version;};
162 uint8 GetFlags1() {return Flags1;};
163 uint8 GetFlags2() {return Flags2;};
164 uint8 GetFlags3() {return Flags3;};
166 private:
167 uint8 Version;
168 uint8 Flags1;
169 uint8 Flags2;
170 uint8 Flags3;
174 class AtomContainer : public AtomBase {
176 This is an Atom that contains other atoms. It has children that may be Container Atoms or Standard Atoms
178 private:
179 AtomArray atomChildren;
180 uint32 TotalChildren;
182 virtual void DisplayAtoms(uint32 pindent);
184 public:
185 AtomContainer(BPositionIO *pStream, off_t pstreamOffset,
186 uint32 patomType, uint64 patomSize);
187 virtual ~AtomContainer();
189 virtual bool IsContainer() {return true;};
190 AtomBase *GetChildAtom(uint32 patomType, uint32 offset=0);
191 uint32 CountChildAtoms(uint32 patomType);
193 // ProcessMetaData() - Reads in the basic Atom Meta Data
194 // - Calls OnProcessMetaData()
195 // - Calls ProcessMetaData on each child atom
196 // (ensures stream is correct for child via offset)
197 virtual void ProcessMetaData();
199 // Add a atom to the children array (return false on failure)
200 bool AddChild(AtomBase *pChildAtom);
202 // OnProcessMetaData() - Subclass override to read/set meta data
203 virtual void OnProcessMetaData();
204 virtual void OnChildProcessingComplete() {};
208 extern AtomBase *GetAtom(BPositionIO *pStream);
211 #endif // _MP4_ATOM_H