compile fixes
[asdcplib.git] / src / MXF.h
index cda4408fa0f6aa3e421836fcd0aa8df55f74b4bd..6041772a08c7abbd5e6ddbc20d7f6c61b18e3ad7 100755 (executable)
--- a/src/MXF.h
+++ b/src/MXF.h
@@ -1,5 +1,5 @@
 /*
-Copyright (c) 2005-2013, John Hurst
+Copyright (c) 2005-2014, John Hurst
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -47,7 +47,7 @@ namespace ASDCP
       typedef ASDCP::MXF::InterchangeObject* (*MXFObjectFactory_t)(const Dictionary*&);
 
       //
-      void SetObjectFactory(UL label, MXFObjectFactory_t factory);
+      void SetObjectFactory(const UL& label, MXFObjectFactory_t factory);
 
       //
       InterchangeObject* CreateObject(const Dictionary*& Dict, const UL& label);
@@ -218,7 +218,29 @@ namespace ASDCP
          virtual void     Dump(FILE* = 0);
        };
 
+      // wrapper object manages optional properties
+      template <class PropertyType>
+       class optional_property
+       {
+         PropertyType m_property;
+         bool m_has_value;
 
+       public:
+       optional_property() : m_has_value(false) {}
+       optional_property(const PropertyType& value) : m_property(value), m_has_value(false) {}
+         const optional_property<PropertyType>& operator=(const PropertyType& rhs) { this->m_property = rhs; this->m_has_value = true; return *this; }
+         bool operator==(const PropertyType& rhs) const { return this->m_property == rhs; }
+         bool operator==(const optional_property<PropertyType>& rhs) const { return this->m_property == rhs.m_property; }
+         operator PropertyType&() { return this->m_property; }
+         void set(const PropertyType& rhs) { this->m_property = rhs; this->m_has_value = true; }
+         void set_has_value(bool has_value = true) { this->m_has_value = has_value; }
+         void reset(const PropertyType& rhs) { this->m_has_value = false; }
+         bool empty() const { return ! m_has_value; }
+         PropertyType& get() { return m_property; }
+         const PropertyType& const_get() const { return m_property; }
+       };
+
+      // base class of all metadata objects
       //
       class InterchangeObject : public ASDCP::KLVPacket
        {
@@ -228,7 +250,7 @@ namespace ASDCP
          const Dictionary*& m_Dict;
          IPrimerLookup* m_Lookup;
          UUID           InstanceUID;
-         UUID           GenerationUID;
+         optional_property<UUID>  GenerationUID;
 
        InterchangeObject(const Dictionary*& d) : m_Dict(d), m_Lookup(0) {}
          virtual ~InterchangeObject() {}
@@ -256,13 +278,14 @@ namespace ASDCP
          const Dictionary*& m_Dict;
          Kumu::Timestamp    LastModifiedDate;
          ui16_t       Version;
-         ui32_t       ObjectModelVersion;
-         UUID         PrimaryPackage;
+         optional_property<ui32_t> ObjectModelVersion;
+         optional_property<UUID> PrimaryPackage;
          Batch<UUID>  Identifications;
          UUID         ContentStorage;
          UL           OperationalPattern;
          Batch<UL>    EssenceContainers;
          Batch<UL>    DMSchemes;
+         optional_property<Batch<UL> > ApplicationSchemes;
 
          Preface(const Dictionary*& d);
          virtual ~Preface() {}
@@ -280,6 +303,7 @@ namespace ASDCP
       //
       class IndexTableSegment : public InterchangeObject
        {
+         IndexTableSegment();
          ASDCP_NO_COPY_CONSTRUCT(IndexTableSegment);
 
        public:
@@ -291,7 +315,7 @@ namespace ASDCP
              ui8_t   Slice;
              ui32_t  ElementData;
 
-             DeltaEntry() : PosTableIndex(-1), Slice(0), ElementData(0) {}
+             DeltaEntry() : PosTableIndex(0), Slice(0), ElementData(0) {}
              DeltaEntry(i8_t pos, ui8_t slice, ui32_t data) : PosTableIndex(pos), Slice(slice), ElementData(data) {}
              inline bool HasValue() const { return true; }
              ui32_t      ArchiveLength() const { return sizeof(ui32_t) + 2; }
@@ -381,6 +405,10 @@ namespace ASDCP
          SourcePackage*   GetSourcePackage();
        };
 
+      // Searches the header object and returns the edit rate based on the contents of the
+      // File Package items.  Logs an error message and returns false if anthing goes wrong.
+      bool GetEditRateFromFP(ASDCP::MXF::OP1aHeader& header, ASDCP::Rational& edit_rate);
+
       //
       class OPAtomIndexFooter : public Partition
        {
@@ -389,6 +417,7 @@ namespace ASDCP
          ui32_t              m_BytesPerEditUnit;
          Rational            m_EditRate;
          ui32_t              m_BodySID;
+         IndexTableSegment::DeltaEntry m_DefaultDeltaEntry;
 
          ASDCP_NO_COPY_CONSTRUCT(OPAtomIndexFooter);
          OPAtomIndexFooter();
@@ -412,6 +441,7 @@ namespace ASDCP
 
          virtual Result_t Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry&) const;
          virtual void     PushIndexEntry(const IndexTableSegment::IndexEntry&);
+         virtual void     SetDeltaParams(const IndexTableSegment::DeltaEntry&);
          virtual void     SetIndexParamsCBR(IPrimerLookup* lookup, ui32_t size, const Rational& Rate);
          virtual void     SetIndexParamsVBR(IPrimerLookup* lookup, const Rational& Rate, Kumu::fpos_t offset);
        };
@@ -433,8 +463,20 @@ namespace ASDCP
        }
       };
 
-      typedef std::map<const std::string, const UL, ci_comp> mca_label_map_t;
-      bool decode_mca_string(const std::string& s, const mca_label_map_t& labels, const Dictionary& dict, const std::string& language, InterchangeObject_list_t&, ui32_t&);
+      struct label_traits
+      {
+        const std::string tag_name;
+       const bool requires_prefix;
+       const UL ul;
+
+      label_traits(const std::string& tag_name, const bool requires_prefix, const UL ul) : 
+       tag_name(tag_name), requires_prefix(requires_prefix), ul(ul) { }
+      };
+
+      typedef std::map<const std::string, const label_traits, ci_comp> mca_label_map_t;
+
+      bool decode_mca_string(const std::string& s, const mca_label_map_t& labels,
+                            const Dictionary*& dict, const std::string& language, InterchangeObject_list_t&, ui32_t&);
 
       //
       class ASDCP_MCAConfigParser : public InterchangeObject_list_t
@@ -450,7 +492,7 @@ namespace ASDCP
          
        public:
          ASDCP_MCAConfigParser(const Dictionary*&);
-         bool DecodeString(const std::string& s, const std::string& language = "en");
+         bool DecodeString(const std::string& s, const std::string& language = "en-US");
 
          // Valid only after a successful call to DecodeString
          ui32_t ChannelCount() const;