Commit fixes found in porting.
[asdcplib.git] / src / MXF.h
index 27f3b3e03543ec3f5af77a91d3a8f7da6bc204b1..6a9b14d47dca824db2cd5aa00242bcc614c30e15 100755 (executable)
--- a/src/MXF.h
+++ b/src/MXF.h
@@ -40,8 +40,18 @@ namespace ASDCP
     {
       class InterchangeObject;
 
+      //
+      typedef ASDCP::MXF::InterchangeObject* (*MXFObjectFactory_t)();
+
+      //
+      void SetObjectFactory(UL label, MXFObjectFactory_t factory);
+
+      //
+      InterchangeObject* CreateObject(const byte_t* label);
+
+
       // seek an open file handle to the start of the RIP KLV packet
-      Result_t SeekToRIP(const FileReader&);
+      Result_t SeekToRIP(const Kumu::FileReader&);
       
       //
       class RIP : public ASDCP::KLVFilePacket
@@ -50,7 +60,7 @@ namespace ASDCP
 
        public:
          //
-         class Pair : public IArchive
+         class Pair : public Kumu::IArchive
            {
            public:
              ui32_t BodySID;
@@ -58,33 +68,29 @@ namespace ASDCP
 
              Pair() : BodySID(0), ByteOffset(0) {}
              Pair(ui32_t sid, ui64_t offset) : BodySID(sid), ByteOffset(offset) {}
+             virtual ~Pair() {}
 
              ui32_t Size() { return sizeof(ui32_t) + sizeof(ui64_t); }
 
-             inline const char* ToString(char* str_buf) const {
-               char intbuf[IntBufferLen];
-               snprintf(str_buf, IdentBufferLen, "%-6lu: %s", BodySID, ui64sz(ByteOffset, intbuf));
+             inline const char* EncodeString(char* str_buf, ui32_t buf_len) const {
+               Kumu::ui64Printer offset_str(ByteOffset);
+               snprintf(str_buf, buf_len, "%-6u: %s", BodySID, offset_str.c_str());
                return str_buf;
              }
 
-             inline Result_t Unarchive(ASDCP::MemIOReader& Reader) {
-               Result_t result = Reader.ReadUi32BE(&BodySID);
-
-               if ( ASDCP_SUCCESS(result) )
-                 result = Reader.ReadUi64BE(&ByteOffset);
+             inline bool HasValue() const { return true; }
+             inline ui32_t ArchiveLength() const { return sizeof(ui32_t) + sizeof(ui64_t); }
 
-               return result;
+             inline bool Unarchive(Kumu::MemIOReader* Reader) {
+               if ( ! Reader->ReadUi32BE(&BodySID) ) return false;
+               if ( ! Reader->ReadUi64BE(&ByteOffset) ) return false;
+               return true;
              }
              
-             inline bool HasValue() const { return true; }
-         
-             inline Result_t Archive(ASDCP::MemIOWriter& Writer) const {
-               Result_t result = Writer.WriteUi32BE(BodySID);
-
-               if ( ASDCP_SUCCESS(result) )
-                 result = Writer.WriteUi64BE(ByteOffset);
-
-               return result;
+             inline bool Archive(Kumu::MemIOWriter* Writer) const {
+               if ( ! Writer->WriteUi32BE(BodySID) ) return false;
+               if ( ! Writer->WriteUi64BE(ByteOffset) ) return false;
+               return true;
              }
            };
 
@@ -92,15 +98,16 @@ namespace ASDCP
 
          RIP() {}
          virtual ~RIP() {}
-         virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
-         virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
+         virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         virtual Result_t WriteToFile(Kumu::FileWriter& Writer);
+         virtual Result_t GetPairBySID(ui32_t, Pair&) const;
          virtual void     Dump(FILE* = 0);
        };
 
 
       //
       class Partition : public ASDCP::KLVFilePacket
-       {       
+       {
          ASDCP_NO_COPY_CONSTRUCT(Partition);
 
        protected:
@@ -125,8 +132,8 @@ namespace ASDCP
          Partition();
          virtual ~Partition();
          virtual void     AddChildObject(InterchangeObject*);
-         virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
-         virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, UL& PartitionLabel);
+         virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         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);
        };
@@ -142,30 +149,31 @@ namespace ASDCP
 
        public:
          //
-         class LocalTagEntry
+       class LocalTagEntry : Kumu::IArchive
            {
            public:
              TagValue    Tag;
              ASDCP::UL   UL;
 
-             inline const char* ToString(char* str_buf) const {
-               snprintf(str_buf, IdentBufferLen, "%02x %02x: ", Tag.a, Tag.b);
-               UL.ToString(str_buf + strlen(str_buf));
+             inline const char* EncodeString(char* str_buf, ui32_t buf_len) const {
+               snprintf(str_buf, buf_len, "%02x %02x: ", Tag.a, Tag.b);
+               UL.EncodeString(str_buf + strlen(str_buf), buf_len - strlen(str_buf));
                return str_buf;
              }
 
-             inline Result_t Unarchive(ASDCP::MemIOReader& Reader) {
-               Result_t result = Reader.ReadUi8(&Tag.a);
-               if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8(&Tag.b);
-               if ( ASDCP_SUCCESS(result) ) result = UL.Unarchive(Reader);
-               return result;
+             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;
+               return UL.Unarchive(Reader);
              }
 
-             inline Result_t Archive(ASDCP::MemIOWriter& Writer) const {
-               Result_t result = Writer.WriteUi8(Tag.a);
-               if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8(Tag.b);
-               if ( ASDCP_SUCCESS(result) ) result = UL.Archive(Writer);
-               return result;
+             inline bool Archive(Kumu::MemIOWriter* Writer) const {
+               if ( ! Writer->WriteUi8(Tag.a) ) return false;
+               if ( ! Writer->WriteUi8(Tag.b) ) return false;
+               return UL.Archive(Writer);
              }
            };
 
@@ -180,7 +188,7 @@ namespace ASDCP
 
           virtual Result_t InitFromBuffer(const byte_t* p, ui32_t l);
           virtual Result_t WriteToBuffer(ASDCP::FrameBuffer&);
-         virtual Result_t WriteToFile(ASDCP::FileWriter& Writer);
+         virtual Result_t WriteToFile(Kumu::FileWriter& Writer);
          virtual void     Dump(FILE* = 0);
        };
 
@@ -207,9 +215,6 @@ namespace ASDCP
          virtual void     Dump(FILE* stream = 0);
        };
 
-      //
-      InterchangeObject* CreateObject(const byte_t* label);
-
       //
       class Preface : public InterchangeObject
        {
@@ -245,7 +250,7 @@ namespace ASDCP
 
        public:
          //
-         class DeltaEntry
+       class DeltaEntry : public Kumu::IArchive
            {
            public:
              i8_t    PosTableIndex;
@@ -253,26 +258,33 @@ namespace ASDCP
              ui32_t  ElementData;
 
              DeltaEntry() : PosTableIndex(-1), Slice(0), ElementData(0) {}
-             Result_t    Unarchive(ASDCP::MemIOReader& Reader);
-             Result_t    Archive(ASDCP::MemIOWriter& Writer) const;
-             const char* ToString(char* str_buf) const;
+             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;
              i8_t               KeyFrameOffset;
              ui8_t              Flags;
              ui64_t             StreamOffset;
+
+             // if you use these, you will need to change CBRIndexEntriesPerSegment in MXF.cpp
+             // to a more suitable value
              //              std::list<ui32_t>  SliceOffset;
              //              Array<Rational>    PosTable;
 
              IndexEntry() : TemporalOffset(0), KeyFrameOffset(0), Flags(0), StreamOffset() {}
-             Result_t    Unarchive(ASDCP::MemIOReader& Reader);
-             Result_t    Archive(ASDCP::MemIOWriter& Writer) const;
-             const char* ToString(char* str_buf) const;
+             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;
            };
 
          Rational    IndexEditRate;
@@ -297,7 +309,6 @@ namespace ASDCP
 
       //---------------------------------------------------------------------------------
       //
-      class h__PacketList; // See MXF.cpp
       class Identification;
       class SourcePackage;
 
@@ -315,10 +326,12 @@ namespace ASDCP
 
          OPAtomHeader();
          virtual ~OPAtomHeader();
-         virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
-         virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, ui32_t HeaderLength = 16384);
+         virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         virtual Result_t WriteToFile(Kumu::FileWriter& Writer, ui32_t HeaderLength = 16384);
          virtual void     Dump(FILE* = 0);
+         virtual Result_t GetMDObjectByID(const UUID&, InterchangeObject** = 0);
          virtual Result_t GetMDObjectByType(const byte_t*, InterchangeObject** = 0);
+         virtual Result_t GetMDObjectsByType(const byte_t* ObjectID, std::list<InterchangeObject*>& ObjectList);
          Identification*  GetIdentification();
          SourcePackage*   GetSourcePackage();
        };
@@ -334,19 +347,19 @@ namespace ASDCP
          ASDCP_NO_COPY_CONSTRUCT(OPAtomIndexFooter);
 
        public:
-         fpos_t              m_ECOffset;
+         Kumu::fpos_t        m_ECOffset;
          IPrimerLookup*      m_Lookup;
         
          OPAtomIndexFooter();
          virtual ~OPAtomIndexFooter();
-         virtual Result_t InitFromFile(const ASDCP::FileReader& Reader);
-         virtual Result_t WriteToFile(ASDCP::FileWriter& Writer, ui64_t duration);
+         virtual Result_t InitFromFile(const Kumu::FileReader& Reader);
+         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, fpos_t offset);
+         virtual void     SetIndexParamsVBR(IPrimerLookup* lookup, const Rational& Rate, Kumu::fpos_t offset);
        };
 
     } // namespace MXF