Query key ID and set decrypt key on an MXF file opened for reading.
[asdcplib.git] / src / MXF.h
index b43fc84dccc01081767d93e9ffeb7e726f11fd70..06d06a0521756de7621d73cb35dcb2c101c15d05 100755 (executable)
--- a/src/MXF.h
+++ b/src/MXF.h
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2005-2006, John Hurst
+Copyright (c) 2005-2009, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -78,15 +78,16 @@ 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;
@@ -132,6 +133,7 @@ namespace ASDCP
          virtual ~Partition();
          virtual void     AddChildObject(InterchangeObject*);
          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);
@@ -148,7 +150,7 @@ namespace ASDCP
 
        public:
          //
-         class LocalTagEntry
+       class LocalTagEntry : Kumu::IArchive
            {
            public:
              TagValue    Tag;
@@ -160,6 +162,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;
@@ -246,7 +251,7 @@ namespace ASDCP
 
        public:
          //
-         class DeltaEntry
+       class DeltaEntry : public Kumu::IArchive
            {
            public:
              i8_t    PosTableIndex;
@@ -254,13 +259,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,6 +281,8 @@ 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;
@@ -319,6 +328,8 @@ namespace ASDCP
          OPAtomHeader();
          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);
@@ -345,10 +356,12 @@ namespace ASDCP
          OPAtomIndexFooter();
          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);