diff options
| author | jhurst <jhurst@cinecert.com> | 2021-04-13 15:50:50 -0700 |
|---|---|---|
| committer | jhurst <jhurst@cinecert.com> | 2021-04-13 15:50:50 -0700 |
| commit | b14d706a72c706c9c59dbdf64a9e41f32465e060 (patch) | |
| tree | 642c62a644544afb531a8fdbfd4e610bb72728ed /src/MXF.cpp | |
| parent | 4e0891ab9ee94b822043126ea07e97641015e9b7 (diff) | |
o Added a Clone() method to InterchangeObject and derivatives
that allows making a descriptor copy that is not owned by
any other strucure. The caller must arrange to delete the
object pointer returned.
o While implementing the above it became obvious that the
reference-to-a-pointer-to-the-dictionary idiom that is used
throughout the lower levels of the MXF library was the
cause of much more grief than it was originally designed to
prevent. This was made even more obvious when I replaced all
of it with simple pointers, which revealed several shadow
instances of m_Dict that were only reliable while the object
that held them was valid.
Diffstat (limited to 'src/MXF.cpp')
| -rwxr-xr-x | src/MXF.cpp | 58 |
1 files changed, 46 insertions, 12 deletions
diff --git a/src/MXF.cpp b/src/MXF.cpp index 83954f7..173f97b 100755 --- a/src/MXF.cpp +++ b/src/MXF.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2005-2015, John Hurst +Copyright (c) 2005-2021, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -262,13 +262,14 @@ ASDCP::MXF::Partition::PacketList::GetMDObjectsByType(const byte_t* ObjectID, st // -ASDCP::MXF::Partition::Partition(const Dictionary*& d) : +ASDCP::MXF::Partition::Partition(const Dictionary* d) : m_Dict(d), MajorVersion(1), MinorVersion(2), KAGSize(1), ThisPartition(0), PreviousPartition(0), FooterPartition(0), HeaderByteCount(0), IndexByteCount(0), IndexSID(0), BodyOffset(0), BodySID(0) { + assert(d); m_PacketList = new PacketList; } @@ -429,7 +430,7 @@ public: // -ASDCP::MXF::Primer::Primer(const Dictionary*& d) : m_LocalTag(0xff), m_Dict(d) { +ASDCP::MXF::Primer::Primer(const Dictionary* d) : m_LocalTag(0xff), m_Dict(d) { m_UL = m_Dict->ul(MDD_Primer); } @@ -595,14 +596,21 @@ ASDCP::MXF::Primer::Dump(FILE* stream) // // -ASDCP::MXF::Preface::Preface(const Dictionary*& d) : - InterchangeObject(d), m_Dict(d), Version(258) +ASDCP::MXF::Preface::Preface(const Dictionary* d) : + InterchangeObject(d), Version(258) { assert(m_Dict); m_UL = m_Dict->Type(MDD_Preface).ul; ObjectModelVersion = 0; } +ASDCP::MXF::Preface::Preface(const Preface& rhs) : InterchangeObject(rhs.m_Dict) +{ + assert(m_Dict); + m_UL = rhs.m_UL; + Copy(rhs); +} + // void ASDCP::MXF::Preface::Copy(const Preface& rhs) @@ -623,6 +631,13 @@ ASDCP::MXF::Preface::Copy(const Preface& rhs) } // +ASDCP::MXF::InterchangeObject* +ASDCP::MXF::Preface::Clone() const +{ + return new Preface(*this); +} + +// ASDCP::Result_t ASDCP::MXF::Preface::InitFromTLVSet(TLVReader& TLVSet) { @@ -725,7 +740,12 @@ ASDCP::MXF::Preface::Dump(FILE* stream) //------------------------------------------------------------------------------------------ // -ASDCP::MXF::OP1aHeader::OP1aHeader(const Dictionary*& d) : Partition(d), m_Dict(d), m_Primer(d), m_Preface(0) {} +ASDCP::MXF::OP1aHeader::OP1aHeader(const Dictionary* d) : + Partition(d), m_Primer(d), m_Preface(0) +{ + assert(m_Dict); +} + ASDCP::MXF::OP1aHeader::~OP1aHeader() {} // @@ -1025,8 +1045,8 @@ ASDCP::MXF::OP1aHeader::Dump(FILE* stream) //------------------------------------------------------------------------------------------ // -ASDCP::MXF::OPAtomIndexFooter::OPAtomIndexFooter(const Dictionary*& d) : - Partition(d), m_Dict(d), +ASDCP::MXF::OPAtomIndexFooter::OPAtomIndexFooter(const Dictionary* d) : + Partition(d), m_CurrentSegment(0), m_BytesPerEditUnit(0), m_BodySID(0), m_ECOffset(0), m_Lookup(0) { @@ -1367,6 +1387,11 @@ ASDCP::MXF::OPAtomIndexFooter::PushIndexEntry(const IndexTableSegment::IndexEntr //------------------------------------------------------------------------------------------ // +ASDCP::MXF::InterchangeObject::InterchangeObject(const Dictionary* d) : + KLVPacket(), m_Dict(d), m_Lookup(0) {} + +ASDCP::MXF::InterchangeObject::~InterchangeObject() {} + // void ASDCP::MXF::InterchangeObject::Copy(const InterchangeObject& rhs) @@ -1377,6 +1402,15 @@ ASDCP::MXF::InterchangeObject::Copy(const InterchangeObject& rhs) } // +ASDCP::MXF::InterchangeObject* +ASDCP::MXF::InterchangeObject::Clone() const +{ + ASDCP::MXF::InterchangeObject* obj = new ASDCP::MXF::InterchangeObject(m_Dict); + obj->Copy(*this); + return obj; +} + +// ASDCP::Result_t ASDCP::MXF::InterchangeObject::InitFromTLVSet(TLVReader& TLVSet) { @@ -1540,7 +1574,7 @@ ASDCP::MXF::SetObjectFactory(const ASDCP::UL& label, ASDCP::MXF::MXFObjectFactor // ASDCP::MXF::InterchangeObject* -ASDCP::MXF::CreateObject(const Dictionary*& Dict, const UL& label) +ASDCP::MXF::CreateObject(const Dictionary* Dict, const UL& label) { if ( ! s_TypesInit ) { @@ -1595,7 +1629,7 @@ ul_is_an_mca_channel(const ASDCP::UL& ul) // bool -ASDCP::MXF::decode_mca_string(const std::string& s, const mca_label_map_t& labels, const Dictionary*& dict, const std::string& language, +ASDCP::MXF::decode_mca_string(const std::string& s, const mca_label_map_t& labels, const Dictionary* dict, const std::string& language, InterchangeObject_list_t& descriptor_list, ui32_t& channel_count) { std::string symbol_buf; @@ -1788,7 +1822,7 @@ ASDCP::MXF::decode_mca_string(const std::string& s, const mca_label_map_t& label } // -ASDCP::MXF::ASDCP_MCAConfigParser::ASDCP_MCAConfigParser(const Dictionary*& d) : m_Dict(d), m_ChannelCount(0) +ASDCP::MXF::ASDCP_MCAConfigParser::ASDCP_MCAConfigParser(const Dictionary* d) : m_Dict(d), m_ChannelCount(0) { typedef mca_label_map_t::value_type pair; m_LabelMap.insert(pair("L", label_traits("Left" , true, m_Dict->ul(MDD_DCAudioChannel_L)))); @@ -1832,7 +1866,7 @@ ASDCP::MXF::ASDCP_MCAConfigParser::DecodeString(const std::string& s, const std: } // ST(L,R),DNS(NSC001,NSC002),-,VIN -ASDCP::MXF::AS02_MCAConfigParser::AS02_MCAConfigParser(const Dictionary*& d) : ASDCP::MXF::ASDCP_MCAConfigParser(d) +ASDCP::MXF::AS02_MCAConfigParser::AS02_MCAConfigParser(const Dictionary* d) : ASDCP::MXF::ASDCP_MCAConfigParser(d) { typedef mca_label_map_t::value_type pair; m_LabelMap.insert(pair("M1", label_traits("Mono One", true, m_Dict->ul(MDD_IMFAudioChannel_M1)))); |
