2 * Copyright (c) 2005, David McPaul
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.
28 #include "QTStructs.h"
31 #include <MediaDefs.h>
32 #include <MediaFormats.h>
33 #include <SupportDefs.h>
41 streamOffset : FilePtr;
44 atomType : int32; // Can be a number or a 4 char FOURCC
45 atomChildren : Array of AtomBase;
48 ProcessMetaData() - Reads in the basic Atom Meta Data
49 - Calls OnProcessMetaData()
50 - Calls ProcessMetaData on each child atom
51 (ensures stream is correct for child via offset)
52 OnProcessMetaData() - Subclass override to read/set meta data
54 AddChild(AtomBase) - Adds a child atom to the children array
56 MoveToEnd() - Moves stream ptr to end of atom
58 GetTypeAsString() - returns the type as something the user can read*/
62 typedef AtomBase
* AtomBasePtr
;
63 typedef std::map
<uint32
, AtomBasePtr
, std::less
<uint32
> > AtomArray
;
69 This is the basic or standard atom. It contains data describing some aspect of the file/stream
78 char fourcc
[5]; // make this an alias to atomType
82 BPositionIO
*theStream
;
83 void Indent(uint32 pindent
);
86 AtomBase(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
89 virtual bool IsContainer() {return false;};
91 virtual BPositionIO
*OnGetStream();
92 BPositionIO
*getStream();
94 bool IsExtended() {return false;};
95 bool IsEndOfAtom() {return (getStream()->Position() >= off_t(streamOffset
+ atomSize
));};
97 // Is this a known atom type
100 virtual void DisplayAtoms(uint32 pindent
);
102 uint64
getAtomSize() {return atomSize
;};
103 uint32
getAtomType() {return atomType
;};
104 off_t
getAtomOffset() {return atomOffset
;};
105 off_t
getStreamOffset() {return streamOffset
;};
107 uint64
getDataSize() {return atomSize
- 8;};
109 uint64
getBytesRemaining();
111 bool IsType(uint32 patomType
) {return patomType
== atomType
;};
113 void setAtomOffset(off_t patomOffset
) {atomOffset
= patomOffset
;};
114 void setStreamOffset(off_t pstreamOffset
) {streamOffset
= pstreamOffset
;};
118 virtual char *OnGetAtomName();
120 // ProcessMetaData() - Reads in the basic Atom Meta Data
121 // - Calls OnProcessMetaData()
122 virtual void ProcessMetaData();
124 // OnProcessMetaData() - Subclass override to read/set meta data
125 virtual void OnProcessMetaData();
127 // Move stream ptr to where atom ends in stream (return false on failure)
132 // Many atoms use an array header
133 void ReadArrayHeader(array_header
*pHeader
);
135 void setParent(AtomBase
*pParent
) {parentAtom
= pParent
;};
136 AtomBase
*getParent() { return parentAtom
;};
138 void Read(uint64
*value
);
139 void Read(uint32
*value
);
140 void Read(uint16
*value
);
141 void Read(uint8
*value
);
142 void Read(char *value
, uint32 maxread
);
143 void Read(uint8
*value
, uint32 maxread
);
146 class AtomContainer
: public AtomBase
{
150 This is an Atom that contains other atoms. It has children that may be Containter Atoms or Standard Atoms
155 AtomArray atomChildren
;
156 uint32 TotalChildren
;
158 virtual void DisplayAtoms(uint32 pindent
);
161 AtomContainer(BPositionIO
*pStream
, off_t pstreamOffset
, uint32 patomType
, uint64 patomSize
);
162 virtual ~AtomContainer();
164 virtual bool IsContainer() {return true;};
165 AtomBase
*GetChildAtom(uint32 patomType
, uint32 offset
=0);
166 uint32
CountChildAtoms(uint32 patomType
);
168 // ProcessMetaData() - Reads in the basic Atom Meta Data
169 // - Calls OnProcessMetaData()
170 // - Calls ProcessMetaData on each child atom
171 // (ensures stream is correct for child via offset)
172 virtual void ProcessMetaData();
174 // Add a atom to the children array (return false on failure)
175 bool AddChild(AtomBase
*pChildAtom
);
177 // OnProcessMetaData() - Subclass override to read/set meta data
178 virtual void OnProcessMetaData();
179 virtual void OnChildProcessingComplete() {};
182 extern AtomBase
*getAtom(BPositionIO
*pStream
);
184 #endif // _MOV_ATOM_H