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;
44 typedef ASDCP::MXF::InterchangeObject* (*MXFObjectFactory_t)();
47 void SetObjectFactory(UL label, MXFObjectFactory_t factory);
50 InterchangeObject* CreateObject(const byte_t* label);
53 // seek an open file handle to the start of the RIP KLV packet
54 Result_t SeekToRIP(const Kumu::FileReader&);
57 class RIP : public ASDCP::KLVFilePacket
59 ASDCP_NO_COPY_CONSTRUCT(RIP);
63 class Pair : public Kumu::IArchive
69 Pair() : BodySID(0), ByteOffset(0) {}
70 Pair(ui32_t sid, ui64_t offset) : BodySID(sid), ByteOffset(offset) {}
73 ui32_t Size() { return sizeof(ui32_t) + sizeof(ui64_t); }
75 inline const char* EncodeString(char* str_buf, ui32_t buf_len) const {
76 Kumu::ui64Printer offset_str(ByteOffset);
77 snprintf(str_buf, buf_len, "%-6u: %s", BodySID, offset_str.c_str());
81 inline virtual bool Unarchive(Kumu::MemIOReader* Reader) {
82 if ( ! Reader->ReadUi32BE(&BodySID) ) return false;
83 if ( ! Reader->ReadUi64BE(&ByteOffset) ) return false;
87 inline virtual bool HasValue() const { return true; }
89 inline virtual bool Archive(Kumu::MemIOWriter* Writer) const {
90 if ( ! Writer->WriteUi32BE(BodySID) ) return false;
91 if ( ! Writer->WriteUi64BE(ByteOffset) ) return false;
96 Array<Pair> PairArray;
100 virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
101 virtual Result_t WriteToFile(Kumu::FileWriter& Writer);
102 virtual Result_t GetPairBySID(ui32_t, Pair&) const;
103 virtual void Dump(FILE* = 0);
108 class Partition : public ASDCP::KLVFilePacket
110 ASDCP_NO_COPY_CONSTRUCT(Partition);
114 mem_ptr<h__PacketList> m_PacketList;
120 ui64_t ThisPartition;
121 ui64_t PreviousPartition;
122 ui64_t FooterPartition;
123 ui64_t HeaderByteCount;
124 ui64_t IndexByteCount;
128 UL OperationalPattern;
129 Batch<UL> EssenceContainers;
132 virtual ~Partition();
133 virtual void AddChildObject(InterchangeObject*);
134 virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
135 virtual Result_t WriteToFile(Kumu::FileWriter& Writer, UL& PartitionLabel);
136 virtual ui32_t ArchiveSize(); // returns the size of the archived structure
137 virtual void Dump(FILE* = 0);
142 class Primer : public ASDCP::KLVFilePacket, public ASDCP::IPrimerLookup
144 class h__PrimerLookup;
145 mem_ptr<h__PrimerLookup> m_Lookup;
147 ASDCP_NO_COPY_CONSTRUCT(Primer);
157 inline const char* EncodeString(char* str_buf, ui32_t buf_len) const {
158 snprintf(str_buf, buf_len, "%02x %02x: ", Tag.a, Tag.b);
159 UL.EncodeString(str_buf + strlen(str_buf), buf_len - strlen(str_buf));
163 inline bool Unarchive(Kumu::MemIOReader* Reader) {
164 if ( ! Reader->ReadUi8(&Tag.a) ) return false;
165 if ( ! Reader->ReadUi8(&Tag.b) ) return false;
166 return UL.Unarchive(Reader);
169 inline bool Archive(Kumu::MemIOWriter* Writer) const {
170 if ( ! Writer->WriteUi8(Tag.a) ) return false;
171 if ( ! Writer->WriteUi8(Tag.b) ) return false;
172 return UL.Archive(Writer);
176 Batch<LocalTagEntry> LocalTagEntryBatch;
181 virtual void ClearTagList();
182 virtual Result_t InsertTag(const MDDEntry& Entry, ASDCP::TagValue& Tag);
183 virtual Result_t TagForKey(const ASDCP::UL& Key, ASDCP::TagValue& Tag);
185 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
186 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
187 virtual Result_t WriteToFile(Kumu::FileWriter& Writer);
188 virtual void Dump(FILE* = 0);
193 class InterchangeObject : public ASDCP::KLVPacket
196 const MDDEntry* m_Typeinfo;
199 IPrimerLookup* m_Lookup;
203 InterchangeObject() : m_Typeinfo(0), m_Lookup(0) {}
204 virtual ~InterchangeObject() {}
205 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
206 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
207 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
208 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
209 virtual bool IsA(const byte_t* label);
210 virtual const char* ObjectName() { return "InterchangeObject"; }
211 virtual void Dump(FILE* stream = 0);
215 class Preface : public InterchangeObject
217 ASDCP_NO_COPY_CONSTRUCT(Preface);
221 Timestamp LastModifiedDate;
223 ui32_t ObjectModelVersion;
225 Batch<UUID> Identifications;
227 UL OperationalPattern;
228 Batch<UL> EssenceContainers;
231 Preface() : Version(258), ObjectModelVersion(0) {}
232 virtual ~Preface() {}
233 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
234 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
235 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
236 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
237 virtual void Dump(FILE* = 0);
240 const ui32_t MaxIndexSegmentSize = 65536;
243 class IndexTableSegment : public InterchangeObject
245 ASDCP_NO_COPY_CONSTRUCT(IndexTableSegment);
256 DeltaEntry() : PosTableIndex(-1), Slice(0), ElementData(0) {}
257 bool Unarchive(Kumu::MemIOReader* Reader);
258 bool Archive(Kumu::MemIOWriter* Writer) const;
259 const char* EncodeString(char* str_buf, ui32_t buf_len) const;
271 // if you use these, you will need to change CBRIndexEntriesPerSegment in MXF.cpp
272 // to a more suitable value
273 // std::list<ui32_t> SliceOffset;
274 // Array<Rational> PosTable;
276 IndexEntry() : TemporalOffset(0), KeyFrameOffset(0), Flags(0), StreamOffset() {}
277 bool Unarchive(Kumu::MemIOReader* Reader);
278 bool Archive(Kumu::MemIOWriter* Writer) const;
279 const char* EncodeString(char* str_buf, ui32_t buf_len) const;
282 Rational IndexEditRate;
283 ui64_t IndexStartPosition;
284 ui64_t IndexDuration;
285 ui32_t EditUnitByteCount;
290 Batch<DeltaEntry> DeltaEntryArray;
291 Batch<IndexEntry> IndexEntryArray;
294 virtual ~IndexTableSegment();
295 virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
296 virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
297 virtual Result_t WriteToTLVSet(TLVWriter& TLVSet);
298 virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
299 virtual void Dump(FILE* = 0);
302 //---------------------------------------------------------------------------------
304 class Identification;
308 class OPAtomHeader : public Partition
310 ASDCP_NO_COPY_CONSTRUCT(OPAtomHeader);
313 ASDCP::MXF::RIP m_RIP;
314 ASDCP::MXF::Primer m_Primer;
316 ASDCP::FrameBuffer m_Buffer;
320 virtual ~OPAtomHeader();
321 virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
322 virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui32_t HeaderLength = 16384);
323 virtual void Dump(FILE* = 0);
324 virtual Result_t GetMDObjectByID(const UUID&, InterchangeObject** = 0);
325 virtual Result_t GetMDObjectByType(const byte_t*, InterchangeObject** = 0);
326 virtual Result_t GetMDObjectsByType(const byte_t* ObjectID, std::list<InterchangeObject*>& ObjectList);
327 Identification* GetIdentification();
328 SourcePackage* GetSourcePackage();
332 class OPAtomIndexFooter : public Partition
334 IndexTableSegment* m_CurrentSegment;
335 ASDCP::FrameBuffer m_Buffer;
336 ui32_t m_BytesPerEditUnit;
339 ASDCP_NO_COPY_CONSTRUCT(OPAtomIndexFooter);
342 Kumu::fpos_t m_ECOffset;
343 IPrimerLookup* m_Lookup;
346 virtual ~OPAtomIndexFooter();
347 virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
348 virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui64_t duration);
349 virtual void Dump(FILE* = 0);
351 virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&);
352 virtual void PushIndexEntry(const IndexTableSegment::IndexEntry&);
353 virtual void SetIndexParamsCBR(IPrimerLookup* lookup, ui32_t size, const Rational& Rate);
354 virtual void SetIndexParamsVBR(IPrimerLookup* lookup, const Rational& Rate, Kumu::fpos_t offset);