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);
53 class Pair : public IArchive
59 Pair() : BodySID(0), ByteOffset(0) {}
60 Pair(ui32_t sid, ui64_t offset) : BodySID(sid), ByteOffset(offset) {}
62 ui32_t Size() { return sizeof(ui32_t) + sizeof(ui64_t); }
64 inline const char* ToString(char* str_buf) const {
65 char intbuf[IntBufferLen];
66 snprintf(str_buf, IdentBufferLen, "%-6lu: %s", BodySID, ui64sz(ByteOffset, intbuf));
70 inline Result_t Unarchive(ASDCP::MemIOReader& Reader) {
71 Result_t result = Reader.ReadUi32BE(&BodySID);
73 if ( ASDCP_SUCCESS(result) )
74 result = Reader.ReadUi64BE(&ByteOffset);
79 inline bool HasValue() const { return true; }
81 inline Result_t Archive(ASDCP::MemIOWriter& Writer) const {
82 Result_t result = Writer.WriteUi32BE(BodySID);
84 if ( ASDCP_SUCCESS(result) )
85 result = Writer.WriteUi64BE(ByteOffset);
91 Array<Pair> PairArray;
95 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
96 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
97 virtual void Dump(FILE* = 0);
102 class Partition : public ASDCP::KLVFilePacket
104 ASDCP_NO_COPY_CONSTRUCT(Partition);
108 mem_ptr<h__PacketList> m_PacketList;
114 ui64_t ThisPartition;
115 ui64_t PreviousPartition;
116 ui64_t FooterPartition;
117 ui64_t HeaderByteCount;
118 ui64_t IndexByteCount;
122 UL OperationalPattern;
123 Batch<UL> EssenceContainers;
126 virtual ~Partition();
127 virtual void AddChildObject(InterchangeObject*);
128 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
129 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, UL& PartitionLabel);
130 virtual ui32_t ArchiveSize(); // returns the size of the archived structure
131 virtual void Dump(FILE* = 0);
136 class Primer : public ASDCP::KLVFilePacket, public ASDCP::IPrimerLookup
138 class h__PrimerLookup;
139 mem_ptr<h__PrimerLookup> m_Lookup;
141 ASDCP_NO_COPY_CONSTRUCT(Primer);
151 inline const char* ToString(char* str_buf) const {
152 snprintf(str_buf, IdentBufferLen, "%02x %02x: ", Tag.a, Tag.b);
153 UL.ToString(str_buf + strlen(str_buf));
157 inline Result_t Unarchive(ASDCP::MemIOReader& Reader) {
158 Result_t result = Reader.ReadUi8(&Tag.a);
159 if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8(&Tag.b);
160 if ( ASDCP_SUCCESS(result) ) result = UL.Unarchive(Reader);
164 inline Result_t Archive(ASDCP::MemIOWriter& Writer) const {
165 Result_t result = Writer.WriteUi8(Tag.a);
166 if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8(Tag.b);
167 if ( ASDCP_SUCCESS(result) ) result = UL.Archive(Writer);
172 Batch<LocalTagEntry> LocalTagEntryBatch;
177 virtual void ClearTagList();
178 virtual Result_t InsertTag(const MDDEntry& Entry, ASDCP::TagValue& Tag);
179 virtual Result_t TagForKey(const ASDCP::UL& Key, ASDCP::TagValue& Tag);
181 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
182 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
183 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
184 virtual void Dump(FILE* = 0);
189 class InterchangeObject : public ASDCP::KLVPacket
192 const MDDEntry* m_Typeinfo;
195 IPrimerLookup* m_Lookup;
199 InterchangeObject() : m_Typeinfo(0), m_Lookup(0) {}
200 virtual ~InterchangeObject() {}
201 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
202 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
203 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
204 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
205 virtual bool IsA(const byte_t* label);
206 virtual const char* ObjectName() { return "InterchangeObject"; }
207 virtual void Dump(FILE* stream = 0);
211 InterchangeObject* CreateObject(const byte_t* label);
214 class Preface : public InterchangeObject
216 ASDCP_NO_COPY_CONSTRUCT(Preface);
220 Timestamp LastModifiedDate;
222 ui32_t ObjectModelVersion;
224 Batch<UUID> Identifications;
226 UL OperationalPattern;
227 Batch<UL> EssenceContainers;
230 Preface() : Version(258), ObjectModelVersion(0) {}
231 virtual ~Preface() {}
232 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
233 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
234 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
235 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
236 virtual void Dump(FILE* = 0);
239 const ui32_t MaxIndexSegmentSize = 65536;
242 class IndexTableSegment : public InterchangeObject
244 ASDCP_NO_COPY_CONSTRUCT(IndexTableSegment);
255 DeltaEntry() : PosTableIndex(-1), Slice(0), ElementData(0) {}
256 Result_t Unarchive(ASDCP::MemIOReader& Reader);
257 Result_t Archive(ASDCP::MemIOWriter& Writer) const;
258 const char* ToString(char* str_buf) const;
269 // std::list<ui32_t> SliceOffset;
270 // Array<Rational> PosTable;
272 IndexEntry() : TemporalOffset(0), KeyFrameOffset(0), Flags(0), StreamOffset() {}
273 Result_t Unarchive(ASDCP::MemIOReader& Reader);
274 Result_t Archive(ASDCP::MemIOWriter& Writer) const;
275 const char* ToString(char* str_buf) const;
278 Rational IndexEditRate;
279 ui64_t IndexStartPosition;
280 ui64_t IndexDuration;
281 ui32_t EditUnitByteCount;
286 Batch<DeltaEntry> DeltaEntryArray;
287 Batch<IndexEntry> IndexEntryArray;
290 virtual ~IndexTableSegment();
291 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
292 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
293 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
294 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
295 virtual void Dump(FILE* = 0);
298 //---------------------------------------------------------------------------------
300 class h__PacketList; // See MXF.cpp
301 class Identification;
305 class OPAtomHeader : public Partition
307 ASDCP_NO_COPY_CONSTRUCT(OPAtomHeader);
310 ASDCP::MXF::RIP m_RIP;
311 ASDCP::MXF::Primer m_Primer;
313 ASDCP::FrameBuffer m_Buffer;
317 virtual ~OPAtomHeader();
318 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
319 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, ui32_t HeaderLength = 16384);
320 virtual void Dump(FILE* = 0);
321 virtual Result_t GetMDObjectByType(const byte_t*, InterchangeObject** = 0);
322 Identification* GetIdentification();
323 SourcePackage* GetSourcePackage();
327 class OPAtomIndexFooter : public Partition
329 IndexTableSegment* m_CurrentSegment;
330 ASDCP::FrameBuffer m_Buffer;
331 ui32_t m_BytesPerEditUnit;
334 ASDCP_NO_COPY_CONSTRUCT(OPAtomIndexFooter);
338 IPrimerLookup* m_Lookup;
341 virtual ~OPAtomIndexFooter();
342 virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
343 virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, ui64_t duration);
344 virtual void Dump(FILE* = 0);
346 virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&);
347 virtual void PushIndexEntry(const IndexTableSegment::IndexEntry&);
348 virtual void SetIndexParamsCBR(IPrimerLookup* lookup, ui32_t size, const Rational& Rate);
349 virtual void SetIndexParamsVBR(IPrimerLookup* lookup, const Rational& Rate, fpos_t offset);