make way for MCA
[asdcplib.git] / src / MXF.h
index b43fc84dccc01081767d93e9ffeb7e726f11fd70..fbae83419bd21be9201357cbf3cb6d50191e2691 100755 (executable)
--- a/src/MXF.h
+++ b/src/MXF.h
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2005-2006, John Hurst
+Copyright (c) 2005-2012, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -41,13 +41,13 @@ namespace ASDCP
       class InterchangeObject;
 
       //
-      typedef ASDCP::MXF::InterchangeObject* (*MXFObjectFactory_t)();
+      typedef ASDCP::MXF::InterchangeObject* (*MXFObjectFactory_t)(const Dictionary*&);
 
       //
       void SetObjectFactory(UL label, MXFObjectFactory_t factory);
 
       //
-      InterchangeObject* CreateObject(const byte_t* label);
+      InterchangeObject* CreateObject(const Dictionary*& Dict, const UL& label);
 
 
       // seek an open file handle to the start of the RIP KLV packet
@@ -57,6 +57,7 @@ namespace ASDCP
       class RIP : public ASDCP::KLVFilePacket
        {
          ASDCP_NO_COPY_CONSTRUCT(RIP);
+         RIP();
 
        public:
          //
@@ -78,24 +79,26 @@ namespace ASDCP
                return str_buf;
              }
 
-             inline virtual bool Unarchive(Kumu::MemIOReader* Reader) {
+             inline bool HasValue() const { return true; }
+             inline ui32_t ArchiveLength() const { return sizeof(ui32_t) + sizeof(ui64_t); }
+
+             inline bool Unarchive(Kumu::MemIOReader* Reader) {
                if ( ! Reader->ReadUi32BE(&BodySID) ) return false;
                if ( ! Reader->ReadUi64BE(&ByteOffset) ) return false;
                return true;
              }
              
-             inline virtual bool HasValue() const { return true; }
-         
-             inline virtual bool Archive(Kumu::MemIOWriter* Writer) const {
+             inline bool Archive(Kumu::MemIOWriter* Writer) const {
                if ( ! Writer->WriteUi32BE(BodySID) ) return false;
                if ( ! Writer->WriteUi64BE(ByteOffset) ) return false;
                return true;
              }
            };
 
+         const Dictionary*& m_Dict;
          Array<Pair> PairArray;
 
-         RIP() {}
+       RIP(const Dictionary*& d) : m_Dict(d) {}
          virtual ~RIP() {}
          virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
          virtual Result_t WriteToFile(Kumu::FileWriter& Writer);
@@ -108,12 +111,15 @@ namespace ASDCP
       class Partition : public ASDCP::KLVFilePacket
        {
          ASDCP_NO_COPY_CONSTRUCT(Partition);
+         Partition();
 
        protected:
          class h__PacketList;
          mem_ptr<h__PacketList> m_PacketList;
 
        public:
+         const Dictionary*& m_Dict;
+
          ui16_t    MajorVersion;
          ui16_t    MinorVersion;
          ui32_t    KAGSize;
@@ -128,10 +134,11 @@ namespace ASDCP
          UL        OperationalPattern;
          Batch<UL> EssenceContainers;
 
-         Partition();
+         Partition(const Dictionary*&);
          virtual ~Partition();
-         virtual void     AddChildObject(InterchangeObject*);
+         virtual void     AddChildObject(InterchangeObject*); // takes ownership
          virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
          virtual Result_t WriteToFile(Kumu::FileWriter& Writer, UL& PartitionLabel);
          virtual ui32_t   ArchiveSize(); // returns the size of the archived structure
          virtual void     Dump(FILE* = 0);
@@ -145,10 +152,11 @@ namespace ASDCP
          mem_ptr<h__PrimerLookup> m_Lookup;
          ui8_t   m_LocalTag;
          ASDCP_NO_COPY_CONSTRUCT(Primer);
+         Primer();
 
        public:
          //
-         class LocalTagEntry
+       class LocalTagEntry : Kumu::IArchive
            {
            public:
              TagValue    Tag;
@@ -160,6 +168,9 @@ namespace ASDCP
                return str_buf;
              }
 
+             inline bool HasValue() const { return UL.HasValue(); }
+             inline ui32_t ArchiveLength() const { return 2 + UL.ArchiveLength(); }
+
              inline bool Unarchive(Kumu::MemIOReader* Reader) {
                if ( ! Reader->ReadUi8(&Tag.a) ) return false;
                if ( ! Reader->ReadUi8(&Tag.b) ) return false;
@@ -174,8 +185,9 @@ namespace ASDCP
            };
 
          Batch<LocalTagEntry> LocalTagEntryBatch;
+         const Dictionary*& m_Dict;
 
-         Primer();
+         Primer(const Dictionary*&);
          virtual ~Primer();
 
          virtual void     ClearTagList();
@@ -192,15 +204,18 @@ namespace ASDCP
       //
       class InterchangeObject : public ASDCP::KLVPacket
        {
+         InterchangeObject();
+
        protected:
          const MDDEntry* m_Typeinfo;
 
        public:
+         const Dictionary*& m_Dict;
          IPrimerLookup* m_Lookup;
          UUID           InstanceUID;
          UUID           GenerationUID;
 
-         InterchangeObject() : m_Typeinfo(0), m_Lookup(0) {}
+       InterchangeObject(const Dictionary*& d) : m_Typeinfo(0), m_Dict(d), m_Lookup(0) {}
          virtual ~InterchangeObject() {}
           virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
          virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
@@ -215,8 +230,10 @@ namespace ASDCP
       class Preface : public InterchangeObject
        {
          ASDCP_NO_COPY_CONSTRUCT(Preface);
+         Preface();
 
        public:
+         const Dictionary*& m_Dict;
          UUID         GenerationUID;
          Timestamp    LastModifiedDate;
          ui16_t       Version;
@@ -228,7 +245,7 @@ namespace ASDCP
          Batch<UL>    EssenceContainers;
          Batch<UL>    DMSchemes;
 
-         Preface() : Version(258), ObjectModelVersion(0) {}
+       Preface(const Dictionary*& d) : InterchangeObject(d), m_Dict(d), Version(258), ObjectModelVersion(0) {}
          virtual ~Preface() {}
           virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
          virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
@@ -246,7 +263,7 @@ namespace ASDCP
 
        public:
          //
-         class DeltaEntry
+       class DeltaEntry : public Kumu::IArchive
            {
            public:
              i8_t    PosTableIndex;
@@ -254,13 +271,15 @@ namespace ASDCP
              ui32_t  ElementData;
 
              DeltaEntry() : PosTableIndex(-1), Slice(0), ElementData(0) {}
+             inline bool HasValue() const { return true; }
+             ui32_t      ArchiveLength() const { return sizeof(ui32_t) + 2; }
              bool        Unarchive(Kumu::MemIOReader* Reader);
              bool        Archive(Kumu::MemIOWriter* Writer) const;
              const char* EncodeString(char* str_buf, ui32_t buf_len) const;
            };
 
          //
-         class IndexEntry
+         class IndexEntry : public Kumu::IArchive
            {
            public:
              i8_t               TemporalOffset;
@@ -274,11 +293,15 @@ namespace ASDCP
              //              Array<Rational>    PosTable;
 
              IndexEntry() : TemporalOffset(0), KeyFrameOffset(0), Flags(0), StreamOffset() {}
+             inline bool HasValue() const { return true; }
+             ui32_t      ArchiveLength() const { return sizeof(ui64_t) + 3; };
              bool        Unarchive(Kumu::MemIOReader* Reader);
              bool        Archive(Kumu::MemIOWriter* Writer) const;
              const char* EncodeString(char* str_buf, ui32_t buf_len) const;
            };
 
+         const Dictionary*& m_Dict;
+
          Rational    IndexEditRate;
          ui64_t      IndexStartPosition;
          ui64_t      IndexDuration;
@@ -290,7 +313,7 @@ namespace ASDCP
          Batch<DeltaEntry> DeltaEntryArray;
          Batch<IndexEntry> IndexEntryArray;
 
-         IndexTableSegment();
+         IndexTableSegment(const Dictionary*&);
          virtual ~IndexTableSegment();
          virtual Result_t InitFromTLVSet(TLVReader& TLVSet);
          virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
@@ -308,17 +331,21 @@ namespace ASDCP
       class OPAtomHeader : public Partition
        {
          ASDCP_NO_COPY_CONSTRUCT(OPAtomHeader);
+         OPAtomHeader();
 
        public:
+         const Dictionary*&   m_Dict;
          ASDCP::MXF::RIP     m_RIP;
          ASDCP::MXF::Primer  m_Primer;
          Preface*            m_Preface;
          ASDCP::FrameBuffer  m_Buffer;
          bool                m_HasRIP;
 
-         OPAtomHeader();
+         OPAtomHeader(const Dictionary*&);
          virtual ~OPAtomHeader();
          virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         virtual Result_t InitFromPartitionBuffer(const byte_t* p, ui32_t l);
+         virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
          virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui32_t HeaderLength = 16384);
          virtual void     Dump(FILE* = 0);
          virtual Result_t GetMDObjectByID(const UUID&, InterchangeObject** = 0);
@@ -336,19 +363,24 @@ namespace ASDCP
          ui32_t              m_BytesPerEditUnit;
          Rational            m_EditRate;
          ui32_t              m_BodySID;
+
          ASDCP_NO_COPY_CONSTRUCT(OPAtomIndexFooter);
+         OPAtomIndexFooter();
 
        public:
+         const Dictionary*&   m_Dict;
          Kumu::fpos_t        m_ECOffset;
          IPrimerLookup*      m_Lookup;
         
-         OPAtomIndexFooter();
+         OPAtomIndexFooter(const Dictionary*&);
          virtual ~OPAtomIndexFooter();
          virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         virtual Result_t InitFromPartitionBuffer(const byte_t* p, ui32_t l);
+         virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
          virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui64_t duration);
          virtual void     Dump(FILE* = 0);
 
-         virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&);
+         virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&) const;
          virtual void     PushIndexEntry(const IndexTableSegment::IndexEntry&);
          virtual void     SetIndexParamsCBR(IPrimerLookup* lookup, ui32_t size, const Rational& Rate);
          virtual void     SetIndexParamsVBR(IPrimerLookup* lookup, const Rational& Rate, Kumu::fpos_t offset);