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 Kumu::FileReader&);
47 class RIP : public ASDCP::KLVFilePacket
49 ASDCP_NO_COPY_CONSTRUCT(RIP);
53 class Pair : public Kumu::IArchive
59 Pair() : BodySID(0), ByteOffset(0) {}
60 Pair(ui32_t sid, ui64_t offset) : BodySID(sid), ByteOffset(offset) {}
63 ui32_t Size() { return sizeof(ui32_t) + sizeof(ui64_t); }
65 inline const char* EncodeString(char* str_buf, ui32_t buf_len) const {
66 Kumu::ui64Printer offset_str(ByteOffset);
67 snprintf(str_buf, buf_len, "%-6u: %s", BodySID, offset_str.c_str());
71 inline virtual bool Unarchive(Kumu::MemIOReader* Reader) {
72 if ( ! Reader->ReadUi32BE(&BodySID) ) return false;
73 if ( ! Reader->ReadUi64BE(&ByteOffset) ) return false;
77 inline virtual bool HasValue() const { return true; }
79 inline virtual bool Archive(Kumu::MemIOWriter* Writer) const {
80 if ( ! Writer->WriteUi32BE(BodySID) ) return false;
81 if ( ! Writer->WriteUi64BE(ByteOffset) ) return false;
86 Array<Pair> PairArray;
90 virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
91 virtual Result_t WriteToFile(Kumu::FileWriter& Writer);
92 virtual void Dump(FILE* = 0);
97 class Partition : public ASDCP::KLVFilePacket
99 ASDCP_NO_COPY_CONSTRUCT(Partition);
103 mem_ptr<h__PacketList> m_PacketList;
109 ui64_t ThisPartition;
110 ui64_t PreviousPartition;
111 ui64_t FooterPartition;
112 ui64_t HeaderByteCount;
113 ui64_t IndexByteCount;
117 UL OperationalPattern;
118 Batch<UL> EssenceContainers;
121 virtual ~Partition();
122 virtual void AddChildObject(InterchangeObject*);
123 virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
124 virtual Result_t WriteToFile(Kumu::FileWriter& Writer, UL& PartitionLabel);
125 virtual ui32_t ArchiveSize(); // returns the size of the archived structure
126 virtual void Dump(FILE* = 0);
131 class Primer : public ASDCP::KLVFilePacket, public ASDCP::IPrimerLookup
133 class h__PrimerLookup;
134 mem_ptr<h__PrimerLookup> m_Lookup;
136 ASDCP_NO_COPY_CONSTRUCT(Primer);
146 inline const char* EncodeString(char* str_buf, ui32_t buf_len) const {
147 snprintf(str_buf, buf_len, "%02x %02x: ", Tag.a, Tag.b);
148 UL.EncodeString(str_buf + strlen(str_buf), buf_len - strlen(str_buf));
152 inline bool Unarchive(Kumu::MemIOReader* Reader) {
153 if ( ! Reader->ReadUi8(&Tag.a) ) return false;
154 if ( ! Reader->ReadUi8(&Tag.b) ) return false;
155 return UL.Unarchive(Reader);
158 inline bool Archive(Kumu::MemIOWriter* Writer) const {
159 if ( ! Writer->WriteUi8(Tag.a) ) return false;
160 if ( ! Writer->WriteUi8(Tag.b) ) return false;
161 return UL.Archive(Writer);
165 Batch<LocalTagEntry> LocalTagEntryBatch;
170 virtual void ClearTagList();
171 virtual Result_t InsertTag(const MDDEntry& Entry, ASDCP::TagValue& Tag);
172 virtual Result_t TagForKey(const ASDCP::UL& Key, ASDCP::TagValue& Tag);
174 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
175 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
176 virtual Result_t WriteToFile(Kumu::FileWriter& Writer);
177 virtual void Dump(FILE* = 0);
182 class InterchangeObject : public ASDCP::KLVPacket
185 const MDDEntry* m_Typeinfo;
188 IPrimerLookup* m_Lookup;
192 InterchangeObject() : m_Typeinfo(0), m_Lookup(0) {}
193 virtual ~InterchangeObject() {}
194 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
195 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
196 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
197 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
198 virtual bool IsA(const byte_t* label);
199 virtual const char* ObjectName() { return "InterchangeObject"; }
200 virtual void Dump(FILE* stream = 0);
204 InterchangeObject* CreateObject(const byte_t* label);
207 class Preface : public InterchangeObject
209 ASDCP_NO_COPY_CONSTRUCT(Preface);
213 Timestamp LastModifiedDate;
215 ui32_t ObjectModelVersion;
217 Batch<UUID> Identifications;
219 UL OperationalPattern;
220 Batch<UL> EssenceContainers;
223 Preface() : Version(258), ObjectModelVersion(0) {}
224 virtual ~Preface() {}
225 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
226 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
227 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
228 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
229 virtual void Dump(FILE* = 0);
232 const ui32_t MaxIndexSegmentSize = 65536;
235 class IndexTableSegment : public InterchangeObject
237 ASDCP_NO_COPY_CONSTRUCT(IndexTableSegment);
248 DeltaEntry() : PosTableIndex(-1), Slice(0), ElementData(0) {}
249 bool Unarchive(Kumu::MemIOReader* Reader);
250 bool Archive(Kumu::MemIOWriter* Writer) const;
251 const char* EncodeString(char* str_buf, ui32_t buf_len) const;
262 // std::list<ui32_t> SliceOffset;
263 // Array<Rational> PosTable;
265 IndexEntry() : TemporalOffset(0), KeyFrameOffset(0), Flags(0), StreamOffset() {}
266 bool Unarchive(Kumu::MemIOReader* Reader);
267 bool Archive(Kumu::MemIOWriter* Writer) const;
268 const char* EncodeString(char* str_buf, ui32_t buf_len) const;
271 Rational IndexEditRate;
272 ui64_t IndexStartPosition;
273 ui64_t IndexDuration;
274 ui32_t EditUnitByteCount;
279 Batch<DeltaEntry> DeltaEntryArray;
280 Batch<IndexEntry> IndexEntryArray;
283 virtual ~IndexTableSegment();
284 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
285 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
286 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
287 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
288 virtual void Dump(FILE* = 0);
291 //---------------------------------------------------------------------------------
293 class h__PacketList; // See MXF.cpp
294 class Identification;
298 class OPAtomHeader : public Partition
300 ASDCP_NO_COPY_CONSTRUCT(OPAtomHeader);
303 ASDCP::MXF::RIP m_RIP;
304 ASDCP::MXF::Primer m_Primer;
306 ASDCP::FrameBuffer m_Buffer;
310 virtual ~OPAtomHeader();
311 virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
312 virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui32_t HeaderLength = 16384);
313 virtual void Dump(FILE* = 0);
314 virtual Result_t GetMDObjectByType(const byte_t*, InterchangeObject** = 0);
315 Identification* GetIdentification();
316 SourcePackage* GetSourcePackage();
320 class OPAtomIndexFooter : public Partition
322 IndexTableSegment* m_CurrentSegment;
323 ASDCP::FrameBuffer m_Buffer;
324 ui32_t m_BytesPerEditUnit;
327 ASDCP_NO_COPY_CONSTRUCT(OPAtomIndexFooter);
330 Kumu::fpos_t m_ECOffset;
331 IPrimerLookup* m_Lookup;
334 virtual ~OPAtomIndexFooter();
335 virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
336 virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui64_t duration);
337 virtual void Dump(FILE* = 0);
339 virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&);
340 virtual void PushIndexEntry(const IndexTableSegment::IndexEntry&);
341 virtual void SetIndexParamsCBR(IPrimerLookup* lookup, ui32_t size, const Rational& Rate);
342 virtual void SetIndexParamsVBR(IPrimerLookup* lookup, const Rational& Rate, Kumu::fpos_t offset);