2 Copyright (c) 2005-2006, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 // seek an open file handle to the start of the RIP KLV packet
42 Result_t SeekToRIP(const FileReader&);
45 class RIP : public ASDCP::KLVFilePacket
47 ASDCP_NO_COPY_CONSTRUCT(RIP);
56 ui32_t Size() { return sizeof(ui32_t) + sizeof(ui64_t); }
58 inline const char* ToString(char* str_buf) const {
59 char intbuf[IntBufferLen];
60 snprintf(str_buf, IdentBufferLen, "%-6lu: %s", BodySID, ui64sz(ByteOffset, intbuf));
64 inline Result_t ReadFrom(ASDCP::MemIOReader& Reader) {
65 Result_t result = Reader.ReadUi32BE(&BodySID);
67 if ( ASDCP_SUCCESS(result) )
68 result = Reader.ReadUi64BE(&ByteOffset);
73 inline Result_t WriteTo(ASDCP::MemIOWriter& Writer) {
74 Result_t result = Writer.WriteUi32BE(BodySID);
76 if ( ASDCP_SUCCESS(result) )
77 result = Writer.WriteUi64BE(ByteOffset);
83 Array<Pair> PairArray;
87 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
88 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
89 virtual void Dump(FILE* = 0);
94 class Partition : public ASDCP::KLVFilePacket
96 ASDCP_NO_COPY_CONSTRUCT(Partition);
102 ui64_t ThisPartition;
103 ui64_t PreviousPartition;
104 ui64_t FooterPartition;
105 ui64_t HeaderByteCount;
106 ui64_t IndexByteCount;
110 UL OperationalPattern;
111 Batch<UL> EssenceContainers;
114 virtual ~Partition() {}
115 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
116 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
117 virtual void Dump(FILE* = 0);
122 class Primer : public ASDCP::KLVPacket, public ASDCP::IPrimerLookup
124 class h__PrimerLookup;
125 mem_ptr<h__PrimerLookup> m_Lookup;
126 ASDCP_NO_COPY_CONSTRUCT(Primer);
136 inline const char* ToString(char* str_buf) const {
137 snprintf(str_buf, IdentBufferLen, "%02x %02x: ", Tag.a, Tag.b);
138 UL.ToString(str_buf + strlen(str_buf));
142 inline Result_t ReadFrom(ASDCP::MemIOReader& Reader) {
143 Result_t result = Reader.ReadUi8(&Tag.a);
145 if ( ASDCP_SUCCESS(result) )
146 result = Reader.ReadUi8(&Tag.b);
148 if ( ASDCP_SUCCESS(result) )
149 result = UL.ReadFrom(Reader);
154 inline Result_t WriteTo(ASDCP::MemIOWriter& Writer) {
155 Result_t result = Writer.WriteUi8(Tag.a);
157 if ( ASDCP_SUCCESS(result) )
158 result = Writer.WriteUi8(Tag.b);
160 if ( ASDCP_SUCCESS(result) )
161 result = UL.WriteTo(Writer);
167 Batch<LocalTagEntry> LocalTagEntryBatch;
172 virtual void ClearTagList();
173 virtual Result_t InsertTag(const ASDCP::UL& Key, ASDCP::TagValue& Tag);
174 virtual Result_t TagForKey(const ASDCP::UL& Key, ASDCP::TagValue& Tag);
176 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
177 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
178 virtual void Dump(FILE* = 0);
183 class InterchangeObject : public ASDCP::KLVPacket
186 IPrimerLookup* m_Lookup;
190 InterchangeObject() : m_Lookup(0) {}
191 virtual ~InterchangeObject() {}
192 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
193 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
194 virtual bool IsA(const byte_t* label);
195 virtual void Dump(FILE* stream = 0);
199 InterchangeObject* CreateObject(const byte_t* label);
203 class Preface : public InterchangeObject
205 ASDCP_NO_COPY_CONSTRUCT(Preface);
209 Timestamp LastModifiedDate;
211 ui32_t ObjectModelVersion;
213 Batch<UID> Identifications;
215 UL OperationalPattern;
216 Batch<UL> EssenceContainers;
220 virtual ~Preface() {}
221 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
222 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer& Buffer);
223 virtual void Dump(FILE* = 0);
227 class IndexTableSegment : public InterchangeObject
229 ASDCP_NO_COPY_CONSTRUCT(IndexTableSegment);
240 Result_t ReadFrom(ASDCP::MemIOReader& Reader);
241 Result_t WriteTo(ASDCP::MemIOWriter& Writer);
242 inline const char* ToString(char* str_buf) const;
253 std::list<ui32_t> SliceOffset;
254 Array<Rational> PosTable;
256 Result_t ReadFrom(ASDCP::MemIOReader& Reader);
257 Result_t WriteTo(ASDCP::MemIOWriter& Writer);
258 inline const char* ToString(char* str_buf) const;
261 Rational IndexEditRate;
262 ui64_t IndexStartPosition;
263 ui64_t IndexDuration;
264 ui32_t EditUnitByteCount;
269 Batch<DeltaEntry> DeltaEntryArray;
270 Batch<IndexEntry> IndexEntryArray;
273 virtual ~IndexTableSegment();
274 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
275 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer& Buffer);
276 virtual void Dump(FILE* = 0);
279 //---------------------------------------------------------------------------------
281 class h__PacketList; // See MXF.cpp
282 class Identification;
286 class OPAtomHeader : public Partition
288 mem_ptr<h__PacketList> m_PacketList;
289 ASDCP_NO_COPY_CONSTRUCT(OPAtomHeader);
292 ASDCP::MXF::RIP m_RIP;
293 ASDCP::MXF::Primer m_Primer;
294 InterchangeObject* m_Preface;
295 ASDCP::FrameBuffer m_Buffer;
299 virtual ~OPAtomHeader();
300 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
301 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, ui32_t HeaderLength = 16384);
302 virtual void Dump(FILE* = 0);
303 virtual Result_t GetMDObjectByType(const byte_t*, InterchangeObject** = 0);
304 Identification* GetIdentification();
305 SourcePackage* GetSourcePackage();
309 class OPAtomIndexFooter : public Partition
311 mem_ptr<h__PacketList> m_PacketList;
312 ASDCP::FrameBuffer m_Buffer;
313 ASDCP_NO_COPY_CONSTRUCT(OPAtomIndexFooter);
316 IPrimerLookup* m_Lookup;
319 virtual ~OPAtomIndexFooter();
320 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
321 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
322 virtual void Dump(FILE* = 0);
324 virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&);