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 class InterchangeObject;
43 // seek an open file handle to the start of the RIP KLV packet
44 Result_t SeekToRIP(const FileReader&);
47 class RIP : public ASDCP::KLVFilePacket
49 ASDCP_NO_COPY_CONSTRUCT(RIP);
58 Pair() : BodySID(0), ByteOffset(0) {}
59 Pair(ui32_t sid, ui64_t offset) : BodySID(sid), ByteOffset(offset) {}
61 ui32_t Size() { return sizeof(ui32_t) + sizeof(ui64_t); }
63 inline const char* ToString(char* str_buf) const {
64 char intbuf[IntBufferLen];
65 snprintf(str_buf, IdentBufferLen, "%-6lu: %s", BodySID, ui64sz(ByteOffset, intbuf));
69 inline Result_t Unarchive(ASDCP::MemIOReader& Reader) {
70 Result_t result = Reader.ReadUi32BE(&BodySID);
72 if ( ASDCP_SUCCESS(result) )
73 result = Reader.ReadUi64BE(&ByteOffset);
78 inline Result_t Archive(ASDCP::MemIOWriter& Writer) {
79 Result_t result = Writer.WriteUi32BE(BodySID);
81 if ( ASDCP_SUCCESS(result) )
82 result = Writer.WriteUi64BE(ByteOffset);
88 Array<Pair> PairArray;
92 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
93 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
94 virtual void Dump(FILE* = 0);
99 class Partition : public ASDCP::KLVFilePacket
101 ASDCP_NO_COPY_CONSTRUCT(Partition);
105 mem_ptr<h__PacketList> m_PacketList;
111 ui64_t ThisPartition;
112 ui64_t PreviousPartition;
113 ui64_t FooterPartition;
114 ui64_t HeaderByteCount;
115 ui64_t IndexByteCount;
119 UL OperationalPattern;
120 Batch<UL> EssenceContainers;
123 virtual ~Partition();
124 virtual void AddChildObject(InterchangeObject*);
125 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
126 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, UL& PartitionLabel);
127 virtual void Dump(FILE* = 0);
132 class Primer : public ASDCP::KLVFilePacket, public ASDCP::IPrimerLookup
134 class h__PrimerLookup;
135 mem_ptr<h__PrimerLookup> m_Lookup;
137 ASDCP_NO_COPY_CONSTRUCT(Primer);
147 inline const char* ToString(char* str_buf) const {
148 snprintf(str_buf, IdentBufferLen, "%02x %02x: ", Tag.a, Tag.b);
149 UL.ToString(str_buf + strlen(str_buf));
153 inline Result_t Unarchive(ASDCP::MemIOReader& Reader) {
154 Result_t result = Reader.ReadUi8(&Tag.a);
155 if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8(&Tag.b);
156 if ( ASDCP_SUCCESS(result) ) result = UL.Unarchive(Reader);
160 inline Result_t Archive(ASDCP::MemIOWriter& Writer) {
161 Result_t result = Writer.WriteUi8(Tag.a);
162 if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8(Tag.b);
163 if ( ASDCP_SUCCESS(result) ) result = UL.Archive(Writer);
168 Batch<LocalTagEntry> LocalTagEntryBatch;
173 virtual void ClearTagList();
174 virtual Result_t InsertTag(const MDDEntry& Entry, ASDCP::TagValue& Tag);
175 virtual Result_t TagForKey(const ASDCP::UL& Key, ASDCP::TagValue& Tag);
177 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
178 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
179 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
180 virtual void Dump(FILE* = 0);
185 class InterchangeObject : public ASDCP::KLVPacket
188 const MDDEntry* m_Typeinfo;
191 IPrimerLookup* m_Lookup;
195 InterchangeObject() : m_Typeinfo(0), m_Lookup(0) {}
196 virtual ~InterchangeObject() {}
197 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
198 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
199 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
200 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
201 virtual bool IsA(const byte_t* label);
202 virtual const char* ObjectName() { return "InterchangeObject"; }
203 virtual void Dump(FILE* stream = 0);
207 InterchangeObject* CreateObject(const byte_t* label);
210 class Preface : public InterchangeObject
212 ASDCP_NO_COPY_CONSTRUCT(Preface);
216 Timestamp LastModifiedDate;
218 ui32_t ObjectModelVersion;
220 Batch<UUID> Identifications;
222 UL OperationalPattern;
223 Batch<UL> EssenceContainers;
226 Preface() : Version(258), ObjectModelVersion(0) {}
227 virtual ~Preface() {}
228 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
229 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
230 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
231 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
232 virtual void Dump(FILE* = 0);
235 const ui32_t MaxIndexSegmentSize = 65536;
238 class IndexTableSegment : public InterchangeObject
240 ASDCP_NO_COPY_CONSTRUCT(IndexTableSegment);
251 DeltaEntry() : PosTableIndex(-1), Slice(0), ElementData(0) {}
252 Result_t Unarchive(ASDCP::MemIOReader& Reader);
253 Result_t Archive(ASDCP::MemIOWriter& Writer);
254 const char* ToString(char* str_buf) const;
265 // std::list<ui32_t> SliceOffset;
266 // Array<Rational> PosTable;
268 Result_t Unarchive(ASDCP::MemIOReader& Reader);
269 Result_t Archive(ASDCP::MemIOWriter& Writer);
270 const char* ToString(char* str_buf) const;
273 Rational IndexEditRate;
274 ui64_t IndexStartPosition;
275 ui64_t IndexDuration;
276 ui32_t EditUnitByteCount;
281 Batch<DeltaEntry> DeltaEntryArray;
282 Batch<IndexEntry> IndexEntryArray;
285 virtual ~IndexTableSegment();
286 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
287 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
288 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
289 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
290 virtual void Dump(FILE* = 0);
293 //---------------------------------------------------------------------------------
295 class h__PacketList; // See MXF.cpp
296 class Identification;
300 class OPAtomHeader : public Partition
302 ASDCP_NO_COPY_CONSTRUCT(OPAtomHeader);
305 ASDCP::MXF::RIP m_RIP;
306 ASDCP::MXF::Primer m_Primer;
308 ASDCP::FrameBuffer m_Buffer;
312 virtual ~OPAtomHeader();
313 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
314 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, ui32_t HeaderLength = 16384);
315 virtual void Dump(FILE* = 0);
316 virtual Result_t GetMDObjectByType(const byte_t*, InterchangeObject** = 0);
317 Identification* GetIdentification();
318 SourcePackage* GetSourcePackage();
322 class OPAtomIndexFooter : public Partition
324 IndexTableSegment* m_CurrentSegment;
325 ASDCP::FrameBuffer m_Buffer;
326 ui32_t m_BytesPerEditUnit;
329 ASDCP_NO_COPY_CONSTRUCT(OPAtomIndexFooter);
333 IPrimerLookup* m_Lookup;
336 virtual ~OPAtomIndexFooter();
337 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
338 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, ui64_t duration);
339 virtual void Dump(FILE* = 0);
341 virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&);
342 virtual void PushIndexEntry(const IndexTableSegment::IndexEntry&);
343 virtual void SetIndexParamsCBR(IPrimerLookup* lookup, ui32_t size, const Rational& Rate);
344 virtual void SetIndexParamsVBR(IPrimerLookup* lookup, const Rational& Rate, fpos_t offset);