/*
-Copyright (c) 2005-2009, John Hurst
+Copyright (c) 2005-2013, John Hurst
All rights reserved.
Redistribution and use in source and binary forms, with or without
//------------------------------------------------------------------------------------------
//
-const ui32_t kl_length = ASDCP::SMPTE_UL_LENGTH + ASDCP::MXF_BER_LENGTH;
-
//
ASDCP::Result_t
ASDCP::MXF::SeekToRIP(const Kumu::FileReader& Reader)
if ( ASDCP_SUCCESS(result)
&& end_pos < (SMPTE_UL_LENGTH+MXF_BER_LENGTH) )
- result = RESULT_FAIL; // File is smaller than an empty packet!
+ {
+ DefaultLogSink().Error("File is smaller than an empty KLV packet.\n");
+ result = RESULT_FAIL;
+ }
if ( ASDCP_SUCCESS(result) )
result = Reader.Seek(end_pos - 4);
result = Reader.Read(intbuf, MXF_BER_LENGTH, &read_count);
if ( ASDCP_SUCCESS(result) && read_count != 4 )
- result = RESULT_FAIL;
+ {
+ DefaultLogSink().Error("RIP contains fewer than four bytes.\n");
+ result = RESULT_FAIL;
+ }
}
if ( ASDCP_SUCCESS(result) )
rip_size = KM_i32_BE(Kumu::cp2i<ui32_t>(intbuf));
if ( rip_size > end_pos ) // RIP can't be bigger than the file
- return RESULT_FAIL;
+ {
+ DefaultLogSink().Error("RIP size impossibly large.\n");
+ return RESULT_FAIL;
+ }
}
// reposition to start of RIP
ASDCP::Result_t
ASDCP::MXF::RIP::InitFromFile(const Kumu::FileReader& Reader)
{
- Result_t result = KLVFilePacket::InitFromFile(Reader, Dict::ul(MDD_RandomIndexMetadata));
+ assert(m_Dict);
+ Result_t result = KLVFilePacket::InitFromFile(Reader, m_Dict->ul(MDD_RandomIndexMetadata));
if ( ASDCP_SUCCESS(result) )
{
ASDCP::Result_t
ASDCP::MXF::RIP::WriteToFile(Kumu::FileWriter& Writer)
{
+ assert(m_Dict);
ASDCP::FrameBuffer Buffer;
ui32_t RIPSize = ( PairArray.size() * (sizeof(ui32_t) + sizeof(ui64_t)) ) + 4;
Result_t result = Buffer.Capacity(RIPSize);
if ( ASDCP_SUCCESS(result) )
- result = WriteKLToFile(Writer, Dict::ul(MDD_RandomIndexMetadata), RIPSize);
+ result = WriteKLToFile(Writer, m_Dict->ul(MDD_RandomIndexMetadata), RIPSize);
if ( ASDCP_SUCCESS(result) )
{
if ( stream == 0 )
stream = stderr;
- KLVFilePacket::Dump(stream, false);
+ KLVFilePacket::Dump(stream, *m_Dict, false);
PairArray.Dump(stream, false);
}
//
//
-class ASDCP::MXF::Partition::h__PacketList
-{
-public:
- std::list<InterchangeObject*> m_List;
- std::map<UUID, InterchangeObject*> m_Map;
-
- ~h__PacketList() {
- while ( ! m_List.empty() )
- {
- delete m_List.back();
- m_List.pop_back();
- }
- }
+ASDCP::MXF::Partition::PacketList::~PacketList() {
+ while ( ! m_List.empty() )
+ {
+ delete m_List.back();
+ m_List.pop_back();
+ }
+}
- //
- void AddPacket(InterchangeObject* ThePacket)
- {
- assert(ThePacket);
- m_Map.insert(std::map<UUID, InterchangeObject*>::value_type(ThePacket->InstanceUID, ThePacket));
- m_List.push_back(ThePacket);
- }
+//
+void
+ASDCP::MXF::Partition::PacketList::AddPacket(InterchangeObject* ThePacket) // takes ownership
+{
+ assert(ThePacket);
+ m_Map.insert(std::map<UUID, InterchangeObject*>::value_type(ThePacket->InstanceUID, ThePacket));
+ m_List.push_back(ThePacket);
+}
- //
- Result_t GetMDObjectByID(const UUID& ObjectID, InterchangeObject** Object)
- {
- ASDCP_TEST_NULL(Object);
+//
+ASDCP::Result_t
+ASDCP::MXF::Partition::PacketList::GetMDObjectByID(const UUID& ObjectID, InterchangeObject** Object)
+{
+ ASDCP_TEST_NULL(Object);
- std::map<UUID, InterchangeObject*>::iterator mi = m_Map.find(ObjectID);
+ std::map<UUID, InterchangeObject*>::iterator mi = m_Map.find(ObjectID);
+
+ if ( mi == m_Map.end() )
+ {
+ *Object = 0;
+ return RESULT_FAIL;
+ }
- if ( mi == m_Map.end() )
- {
- *Object = 0;
- return RESULT_FAIL;
- }
+ *Object = (*mi).second;
+ return RESULT_OK;
+}
- *Object = (*mi).second;
- return RESULT_OK;
- }
+//
+ASDCP::Result_t
+ASDCP::MXF::Partition::PacketList::GetMDObjectByType(const byte_t* ObjectID, InterchangeObject** Object)
+{
+ ASDCP_TEST_NULL(ObjectID);
+ ASDCP_TEST_NULL(Object);
+ std::list<InterchangeObject*>::iterator li;
+ *Object = 0;
- //
- Result_t GetMDObjectByType(const byte_t* ObjectID, InterchangeObject** Object)
- {
- ASDCP_TEST_NULL(ObjectID);
- ASDCP_TEST_NULL(Object);
- std::list<InterchangeObject*>::iterator li;
- *Object = 0;
-
- for ( li = m_List.begin(); li != m_List.end(); li++ )
- {
- if ( (*li)->HasUL(ObjectID) )
- {
- *Object = *li;
- return RESULT_OK;
- }
- }
+ for ( li = m_List.begin(); li != m_List.end(); li++ )
+ {
+ if ( (*li)->HasUL(ObjectID) )
+ {
+ *Object = *li;
+ return RESULT_OK;
+ }
+ }
- return RESULT_FAIL;
- }
+ return RESULT_FAIL;
+}
- //
- Result_t GetMDObjectsByType(const byte_t* ObjectID, std::list<InterchangeObject*>& ObjectList)
- {
- ASDCP_TEST_NULL(ObjectID);
- std::list<InterchangeObject*>::iterator li;
+//
+ASDCP::Result_t
+ASDCP::MXF::Partition::PacketList::GetMDObjectsByType(const byte_t* ObjectID, std::list<InterchangeObject*>& ObjectList)
+{
+ ASDCP_TEST_NULL(ObjectID);
+ std::list<InterchangeObject*>::iterator li;
- for ( li = m_List.begin(); li != m_List.end(); li++ )
- {
- if ( (*li)->HasUL(ObjectID) )
- ObjectList.push_back(*li);
- }
+ for ( li = m_List.begin(); li != m_List.end(); li++ )
+ {
+ if ( (*li)->HasUL(ObjectID) )
+ ObjectList.push_back(*li);
+ }
- return ObjectList.empty() ? RESULT_FAIL : RESULT_OK;
- }
-};
+ return ObjectList.empty() ? RESULT_FAIL : RESULT_OK;
+}
//------------------------------------------------------------------------------------------
//
-ASDCP::MXF::Partition::Partition() :
+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)
{
- m_PacketList = new h__PacketList;
+ m_PacketList = new PacketList;
}
ASDCP::MXF::Partition::~Partition()
{
}
-//
+// takes ownership
void
ASDCP::MXF::Partition::AddChildObject(InterchangeObject* Object)
{
if ( stream == 0 )
stream = stderr;
- KLVFilePacket::Dump(stream, false);
+ KLVFilePacket::Dump(stream, *m_Dict, false);
fprintf(stream, " MajorVersion = %hu\n", MajorVersion);
fprintf(stream, " MinorVersion = %hu\n", MinorVersion);
fprintf(stream, " KAGSize = %u\n", KAGSize);
fprintf(stream, " BodyOffset = %s\n", ui64sz(BodyOffset, identbuf));
fprintf(stream, " BodySID = %u\n", BodySID);
fprintf(stream, " OperationalPattern = %s\n", OperationalPattern.EncodeString(identbuf, IdentBufferLen));
- fputs("Essence Containers:\n", stream); EssenceContainers.Dump(stream, false);
+ fputs("Essence Containers:\n", stream); EssenceContainers.Dump(stream);
}
//
-ASDCP::MXF::Primer::Primer() : m_LocalTag(0xff) {}
+ASDCP::MXF::Primer::Primer(const Dictionary*& d) : m_LocalTag(0xff), m_Dict(d) {
+ m_UL = m_Dict->ul(MDD_Primer);
+}
//
ASDCP::MXF::Primer::~Primer() {}
ASDCP::Result_t
ASDCP::MXF::Primer::InitFromBuffer(const byte_t* p, ui32_t l)
{
- Result_t result = KLVPacket::InitFromBuffer(p, l, Dict::ul(MDD_Primer));
+ assert(m_Dict);
+ Result_t result = KLVPacket::InitFromBuffer(p, l, m_Dict->ul(MDD_Primer));
if ( ASDCP_SUCCESS(result) )
{
ASDCP::Result_t
ASDCP::MXF::Primer::WriteToBuffer(ASDCP::FrameBuffer& Buffer)
{
+ assert(m_Dict);
ASDCP::FrameBuffer LocalTagBuffer;
Kumu::MemIOWriter MemWRT(Buffer.Data() + kl_length, Buffer.Capacity() - kl_length);
Result_t result = LocalTagEntryBatch.Archive(&MemWRT) ? RESULT_OK : RESULT_KLV_CODING;
if ( ASDCP_SUCCESS(result) )
{
ui32_t packet_length = MemWRT.Length();
- result = WriteKLToBuffer(Buffer, Dict::ul(MDD_Primer), packet_length);
+ result = WriteKLToBuffer(Buffer, packet_length);
if ( ASDCP_SUCCESS(result) )
Buffer.Size(Buffer.Size() + packet_length);
void
ASDCP::MXF::Primer::Dump(FILE* stream)
{
+ assert(m_Dict);
char identbuf[IdentBufferLen];
if ( stream == 0 )
stream = stderr;
- KLVPacket::Dump(stream, false);
+ KLVPacket::Dump(stream, *m_Dict, false);
fprintf(stream, "Primer: %u %s\n",
(ui32_t)LocalTagEntryBatch.size(),
( LocalTagEntryBatch.size() == 1 ? "entry" : "entries" ));
Batch<LocalTagEntry>::iterator i = LocalTagEntryBatch.begin();
for ( ; i != LocalTagEntryBatch.end(); i++ )
{
- const MDDEntry* Entry = Dict::FindUL((*i).UL.Value());
+ const MDDEntry* Entry = m_Dict->FindUL((*i).UL.Value());
fprintf(stream, " %s %s\n", (*i).EncodeString(identbuf, IdentBufferLen), (Entry ? Entry->name : "Unknown"));
}
}
//------------------------------------------------------------------------------------------
//
+//
+ASDCP::MXF::Preface::Preface(const Dictionary*& d) :
+ InterchangeObject(d), m_Dict(d), Version(258), ObjectModelVersion(0)
+{
+ assert(m_Dict);
+ m_UL = m_Dict->Type(MDD_Preface).ul;
+}
+
+//
+void
+ASDCP::MXF::Preface::Copy(const Preface& rhs)
+{
+ InterchangeObject::Copy(rhs);
+
+ LastModifiedDate = rhs.LastModifiedDate;
+ Version = rhs.Version;
+ ObjectModelVersion = rhs.ObjectModelVersion;
+ PrimaryPackage = rhs.PrimaryPackage;
+ Identifications = rhs.Identifications;
+ ContentStorage = rhs.ContentStorage;
+ OperationalPattern = rhs.OperationalPattern;
+ EssenceContainers = rhs.EssenceContainers;
+ DMSchemes = rhs.DMSchemes;
+}
+
//
ASDCP::Result_t
ASDCP::MXF::Preface::InitFromTLVSet(TLVReader& TLVSet)
ASDCP::Result_t
ASDCP::MXF::Preface::InitFromBuffer(const byte_t* p, ui32_t l)
{
- m_Typeinfo = &Dict::Type(MDD_Preface);
return InterchangeObject::InitFromBuffer(p, l);
}
ASDCP::Result_t
ASDCP::MXF::Preface::WriteToBuffer(ASDCP::FrameBuffer& Buffer)
{
- m_Typeinfo = &Dict::Type(MDD_Preface);
return InterchangeObject::WriteToBuffer(Buffer);
}
//------------------------------------------------------------------------------------------
//
-ASDCP::MXF::OPAtomHeader::OPAtomHeader() : m_Preface(0), m_HasRIP(false) {}
-ASDCP::MXF::OPAtomHeader::~OPAtomHeader() {}
+ASDCP::MXF::OP1aHeader::OP1aHeader(const Dictionary*& d) : Partition(d), m_Dict(d), m_Primer(d), m_Preface(0) {}
+ASDCP::MXF::OP1aHeader::~OP1aHeader() {}
//
ASDCP::Result_t
-ASDCP::MXF::OPAtomHeader::InitFromFile(const Kumu::FileReader& Reader)
+ASDCP::MXF::OP1aHeader::InitFromFile(const Kumu::FileReader& Reader)
{
- m_HasRIP = false;
- Result_t result = SeekToRIP(Reader);
+ Result_t result = result = Partition::InitFromFile(Reader);
- if ( ASDCP_SUCCESS(result) )
- {
- result = m_RIP.InitFromFile(Reader);
- ui32_t test_s = m_RIP.PairArray.size();
+ if ( ASDCP_FAILURE(result) )
+ return result;
- if ( ASDCP_FAILURE(result) )
+ if ( m_Dict == &DefaultCompositeDict() )
+ {
+ // select more explicit dictionary if one is available
+ if ( OperationalPattern.ExactMatch(MXFInterop_OPAtom_Entry().ul) )
{
- DefaultLogSink().Error("File contains no RIP\n");
- result = RESULT_OK;
+ m_Dict = &DefaultInteropDict();
}
- else if ( test_s == 0 )
+ else if ( OperationalPattern.ExactMatch(SMPTE_390_OPAtom_Entry().ul) )
{
- DefaultLogSink().Error("RIP contains no Pairs.\n");
- result = RESULT_FORMAT;
- }
- else
- {
- if ( test_s < 2 )
- {
- // OP-Atom states that there will be either two or three partitions:
- // one closed header and one closed footer with an optional body
- // SMPTE 429-5 files may have many partitions, see SMPTE 410M
- DefaultLogSink().Warn("RIP count is less than 2: %u\n", test_s);
- }
-
- m_HasRIP = true;
-
- if ( m_RIP.PairArray.front().ByteOffset != 0 )
- {
- DefaultLogSink().Error("First Partition in RIP is not at offset 0.\n");
- result = RESULT_FORMAT;
- }
+ m_Dict = &DefaultSMPTEDict();
}
}
- if ( ASDCP_SUCCESS(result) )
- result = Reader.Seek(0);
-
- if ( ASDCP_SUCCESS(result) )
- result = Partition::InitFromFile(Reader); // test UL and OP
-
- if ( ASDCP_FAILURE(result) )
- return result;
-
- // is it really OP-Atom?
- UL OPAtomUL(Dict::ul(MDD_OPAtom));
- UL InteropOPAtomUL(Dict::ul(MDD_MXFInterop_OPAtom));
-
- if ( ! ( OperationalPattern == OPAtomUL || OperationalPattern == InteropOPAtomUL ) )
- {
- char strbuf[IdentBufferLen];
- const MDDEntry* Entry = Dict::FindUL(OperationalPattern.Value());
- if ( Entry == 0 )
- DefaultLogSink().Warn("Operational pattern is not OP-Atom: %s\n", OperationalPattern.EncodeString(strbuf, IdentBufferLen));
- else
- DefaultLogSink().Warn("Operational pattern is not OP-Atom: %s\n", Entry->name);
- }
-
// slurp up the remainder of the header
if ( HeaderByteCount < 1024 )
DefaultLogSink().Warn("Improbably small HeaderByteCount value: %u\n", HeaderByteCount);
assert (HeaderByteCount <= 0xFFFFFFFFL);
- result = m_Buffer.Capacity((ui32_t) HeaderByteCount);
+ result = m_HeaderData.Capacity((ui32_t)HeaderByteCount);
if ( ASDCP_SUCCESS(result) )
{
ui32_t read_count;
- result = Reader.Read(m_Buffer.Data(), m_Buffer.Capacity(), &read_count);
+ result = Reader.Read(m_HeaderData.Data(), m_HeaderData.Capacity(), &read_count);
if ( ASDCP_FAILURE(result) )
- return result;
+ {
+ DefaultLogSink().Error("OP1aHeader::InitFromFile, Read failed\n");
+ return result;
+ }
- if ( read_count != m_Buffer.Capacity() )
+ if ( read_count != m_HeaderData.Capacity() )
{
DefaultLogSink().Error("Short read of OP-Atom header metadata; wanted %u, got %u\n",
- m_Buffer.Capacity(), read_count);
+ m_HeaderData.Capacity(), read_count);
return RESULT_KLV_CODING;
}
}
if ( ASDCP_SUCCESS(result) )
- result = InitFromBuffer(m_Buffer.RoData(), m_Buffer.Capacity());
+ result = InitFromBuffer(m_HeaderData.RoData(), m_HeaderData.Capacity());
return result;
}
//
ASDCP::Result_t
-ASDCP::MXF::OPAtomHeader::InitFromPartitionBuffer(const byte_t* p, ui32_t l)
+ASDCP::MXF::OP1aHeader::InitFromPartitionBuffer(const byte_t* p, ui32_t l)
{
Result_t result = KLVPacket::InitFromBuffer(p, l);
//
ASDCP::Result_t
-ASDCP::MXF::OPAtomHeader::InitFromBuffer(const byte_t* p, ui32_t l)
+ASDCP::MXF::OP1aHeader::InitFromBuffer(const byte_t* p, ui32_t l)
{
+ assert(m_Dict);
Result_t result = RESULT_OK;
const byte_t* end_p = p + l;
while ( ASDCP_SUCCESS(result) && p < end_p )
{
// parse the packets and index them by uid, discard KLVFill items
- InterchangeObject* object = CreateObject(p);
+ InterchangeObject* object = CreateObject(m_Dict, p);
assert(object);
object->m_Lookup = &m_Primer;
if ( ASDCP_SUCCESS(result) )
{
- if ( object->IsA(Dict::ul(MDD_KLVFill)) )
+ if ( object->IsA(m_Dict->ul(MDD_KLVFill)) )
{
delete object;
}
- else if ( object->IsA(Dict::ul(MDD_Primer)) )
+ else if ( object->IsA(m_Dict->ul(MDD_Primer)) ) // TODO: only one primer should be found
{
delete object;
result = m_Primer.InitFromBuffer(redo_p, end_p - redo_p);
}
else
{
- m_PacketList->AddPacket(object);
+ m_PacketList->AddPacket(object); // takes ownership
- if ( object->IsA(Dict::ul(MDD_Preface)) && m_Preface == 0 )
+ if ( object->IsA(m_Dict->ul(MDD_Preface)) && m_Preface == 0 )
m_Preface = (Preface*)object;
}
}
}
ASDCP::Result_t
-ASDCP::MXF::OPAtomHeader::GetMDObjectByID(const UUID& ObjectID, InterchangeObject** Object)
+ASDCP::MXF::OP1aHeader::GetMDObjectByID(const UUID& ObjectID, InterchangeObject** Object)
{
return m_PacketList->GetMDObjectByID(ObjectID, Object);
}
//
ASDCP::Result_t
-ASDCP::MXF::OPAtomHeader::GetMDObjectByType(const byte_t* ObjectID, InterchangeObject** Object)
+ASDCP::MXF::OP1aHeader::GetMDObjectByType(const byte_t* ObjectID, InterchangeObject** Object)
{
InterchangeObject* TmpObject;
//
ASDCP::Result_t
-ASDCP::MXF::OPAtomHeader::GetMDObjectsByType(const byte_t* ObjectID, std::list<InterchangeObject*>& ObjectList)
+ASDCP::MXF::OP1aHeader::GetMDObjectsByType(const byte_t* ObjectID, std::list<InterchangeObject*>& ObjectList)
{
return m_PacketList->GetMDObjectsByType(ObjectID, ObjectList);
}
//
ASDCP::MXF::Identification*
-ASDCP::MXF::OPAtomHeader::GetIdentification()
+ASDCP::MXF::OP1aHeader::GetIdentification()
{
InterchangeObject* Object;
//
ASDCP::MXF::SourcePackage*
-ASDCP::MXF::OPAtomHeader::GetSourcePackage()
+ASDCP::MXF::OP1aHeader::GetSourcePackage()
{
InterchangeObject* Object;
return 0;
}
-
//
ASDCP::Result_t
-ASDCP::MXF::OPAtomHeader::WriteToFile(Kumu::FileWriter& Writer, ui32_t HeaderSize)
+ASDCP::MXF::OP1aHeader::WriteToFile(Kumu::FileWriter& Writer, ui32_t HeaderSize)
{
+ assert(m_Dict);
if ( m_Preface == 0 )
return RESULT_STATE;
if ( ASDCP_SUCCESS(result) )
{
- UL TmpUL(Dict::ul(MDD_ClosedCompleteHeader));
+ UL TmpUL(m_Dict->ul(MDD_ClosedCompleteHeader));
result = Partition::WriteToFile(Writer, TmpUL);
}
}
klv_fill_length -= kl_length;
- result = WriteKLToFile(Writer, Dict::ul(MDD_KLVFill), klv_fill_length);
+ result = WriteKLToFile(Writer, m_Dict->ul(MDD_KLVFill), klv_fill_length);
if ( ASDCP_SUCCESS(result) )
result = NilBuf.Capacity(klv_fill_length);
//
void
-ASDCP::MXF::OPAtomHeader::Dump(FILE* stream)
+ASDCP::MXF::OP1aHeader::Dump(FILE* stream)
{
if ( stream == 0 )
stream = stderr;
//------------------------------------------------------------------------------------------
//
-ASDCP::MXF::OPAtomIndexFooter::OPAtomIndexFooter() :
+ASDCP::MXF::OPAtomIndexFooter::OPAtomIndexFooter(const Dictionary*& d) :
+ Partition(d), m_Dict(d),
m_CurrentSegment(0), m_BytesPerEditUnit(0), m_BodySID(0),
m_ECOffset(0), m_Lookup(0)
{
Result_t result = Partition::InitFromFile(Reader); // test UL and OP
// slurp up the remainder of the footer
- ui32_t read_count;
+ ui32_t read_count = 0;
- if ( ASDCP_SUCCESS(result) )
+ if ( ASDCP_SUCCESS(result) && IndexByteCount > 0 )
{
assert (IndexByteCount <= 0xFFFFFFFFL);
- result = m_Buffer.Capacity((ui32_t) IndexByteCount);
- }
+ // At this point, m_FooterData may not have been initialized
+ // so it's capacity is zero and data pointer is NULL
+ // However, if IndexByteCount is zero then the capacity
+ // doesn't change and the data pointer is not set.
+ result = m_FooterData.Capacity((ui32_t) IndexByteCount);
- if ( ASDCP_SUCCESS(result) )
- result = Reader.Read(m_Buffer.Data(), m_Buffer.Capacity(), &read_count);
+ if ( ASDCP_SUCCESS(result) )
+ result = Reader.Read(m_FooterData.Data(), m_FooterData.Capacity(), &read_count);
- if ( ASDCP_SUCCESS(result) && read_count != m_Buffer.Capacity() )
- {
- DefaultLogSink().Error("Short read of footer partition: got %u, expecting %u\n",
- read_count, m_Buffer.Capacity());
- return RESULT_FAIL;
- }
+ if ( ASDCP_SUCCESS(result) && read_count != m_FooterData.Capacity() )
+ {
+ DefaultLogSink().Error("Short read of footer partition: got %u, expecting %u\n",
+ read_count, m_FooterData.Capacity());
+ return RESULT_FAIL;
+ }
+ else if( ASDCP_SUCCESS(result) && !m_FooterData.Data() )
+ {
+ DefaultLogSink().Error( "Buffer for footer partition not created: IndexByteCount = %u\n",
+ IndexByteCount );
+ return RESULT_FAIL;
+ }
- if ( ASDCP_SUCCESS(result) )
- result = InitFromBuffer(m_Buffer.RoData(), m_Buffer.Capacity());
+ if ( ASDCP_SUCCESS(result) )
+ result = InitFromBuffer(m_FooterData.RoData(), m_FooterData.Capacity());
+ }
return result;
}
while ( ASDCP_SUCCESS(result) && p < end_p )
{
// parse the packets and index them by uid, discard KLVFill items
- InterchangeObject* object = CreateObject(p);
+ InterchangeObject* object = CreateObject(m_Dict, p);
assert(object);
object->m_Lookup = m_Lookup;
if ( ASDCP_SUCCESS(result) )
{
- m_PacketList->AddPacket(object);
+ m_PacketList->AddPacket(object); // takes ownership
}
else
{
ASDCP::Result_t
ASDCP::MXF::OPAtomIndexFooter::WriteToFile(Kumu::FileWriter& Writer, ui64_t duration)
{
+ assert(m_Dict);
ASDCP::FrameBuffer FooterBuffer;
ui32_t footer_size = m_PacketList->m_List.size() * MaxIndexSegmentSize; // segment-count * max-segment-size
Result_t result = FooterBuffer.Capacity(footer_size);
if ( ASDCP_SUCCESS(result) )
{
IndexByteCount = FooterBuffer.Size();
- UL FooterUL(Dict::ul(MDD_CompleteFooter));
+ UL FooterUL(m_Dict->ul(MDD_CompleteFooter));
result = Partition::WriteToFile(Writer, FooterUL);
}
(*i)->Dump(stream);
}
+ASDCP::Result_t
+ASDCP::MXF::OPAtomIndexFooter::GetMDObjectByID(const UUID& ObjectID, InterchangeObject** Object)
+{
+ return m_PacketList->GetMDObjectByID(ObjectID, Object);
+}
+
+//
+ASDCP::Result_t
+ASDCP::MXF::OPAtomIndexFooter::GetMDObjectByType(const byte_t* ObjectID, InterchangeObject** Object)
+{
+ InterchangeObject* TmpObject;
+
+ if ( Object == 0 )
+ Object = &TmpObject;
+
+ return m_PacketList->GetMDObjectByType(ObjectID, Object);
+}
+
+//
+ASDCP::Result_t
+ASDCP::MXF::OPAtomIndexFooter::GetMDObjectsByType(const byte_t* ObjectID, std::list<InterchangeObject*>& ObjectList)
+{
+ return m_PacketList->GetMDObjectsByType(ObjectID, ObjectList);
+}
+
//
ASDCP::Result_t
ASDCP::MXF::OPAtomIndexFooter::Lookup(ui32_t frame_num, IndexTableSegment::IndexEntry& Entry) const
m_BytesPerEditUnit = size;
m_EditRate = Rate;
- IndexTableSegment* Index = new IndexTableSegment;
+ IndexTableSegment* Index = new IndexTableSegment(m_Dict);
AddChildObject(Index);
Index->EditUnitByteCount = m_BytesPerEditUnit;
Index->IndexEditRate = Rate;
// do we have an available segment?
if ( m_CurrentSegment == 0 )
{ // no, set up a new segment
- m_CurrentSegment = new IndexTableSegment;
+ m_CurrentSegment = new IndexTableSegment(m_Dict);
assert(m_CurrentSegment);
AddChildObject(m_CurrentSegment);
m_CurrentSegment->DeltaEntryArray.push_back(IndexTableSegment::DeltaEntry());
m_CurrentSegment->IndexDuration = m_CurrentSegment->IndexEntryArray.size();
ui64_t StartPosition = m_CurrentSegment->IndexStartPosition + m_CurrentSegment->IndexDuration;
- m_CurrentSegment = new IndexTableSegment;
+ m_CurrentSegment = new IndexTableSegment(m_Dict);
assert(m_CurrentSegment);
AddChildObject(m_CurrentSegment);
m_CurrentSegment->DeltaEntryArray.push_back(IndexTableSegment::DeltaEntry());
//------------------------------------------------------------------------------------------
//
+//
+void
+ASDCP::MXF::InterchangeObject::Copy(const InterchangeObject& rhs)
+{
+ m_UL = rhs.m_UL;
+ InstanceUID = rhs.InstanceUID;
+ GenerationUID = rhs.GenerationUID;
+}
+
//
ASDCP::Result_t
ASDCP::MXF::InterchangeObject::InitFromTLVSet(TLVReader& TLVSet)
ASDCP_TEST_NULL(p);
Result_t result = RESULT_FALSE;
- if ( m_Typeinfo == 0 )
- {
- result = KLVPacket::InitFromBuffer(p, l);
- }
- else
+ if ( m_UL.HasValue() )
{
- result = KLVPacket::InitFromBuffer(p, l, m_Typeinfo->ul);
+ result = KLVPacket::InitFromBuffer(p, l, m_UL);
if ( ASDCP_SUCCESS(result) )
{
result = InitFromTLVSet(MemRDR);
}
}
+ else
+ {
+ result = KLVPacket::InitFromBuffer(p, l);
+ }
return result;
}
ASDCP::Result_t
ASDCP::MXF::InterchangeObject::WriteToBuffer(ASDCP::FrameBuffer& Buffer)
{
- if ( m_Typeinfo == 0 )
+ if ( ! m_UL.HasValue() )
return RESULT_STATE;
TLVWriter MemWRT(Buffer.Data() + kl_length, Buffer.Capacity() - kl_length, m_Lookup);
if ( ASDCP_SUCCESS(result) )
{
ui32_t packet_length = MemWRT.Length();
- result = WriteKLToBuffer(Buffer, m_Typeinfo->ul, packet_length);
+ result = WriteKLToBuffer(Buffer, packet_length);
if ( ASDCP_SUCCESS(result) )
Buffer.Size(Buffer.Size() + packet_length);
char identbuf[IdentBufferLen];
fputc('\n', stream);
- KLVPacket::Dump(stream, false);
+ KLVPacket::Dump(stream, *m_Dict, false);
fprintf(stream, " InstanceUID = %s\n", InstanceUID.EncodeHex(identbuf, IdentBufferLen));
fprintf(stream, " GenerationUID = %s\n", GenerationUID.EncodeHex(identbuf, IdentBufferLen));
}
s_FactoryList.Insert(label, factory);
}
-
//
ASDCP::MXF::InterchangeObject*
-ASDCP::MXF::CreateObject(const byte_t* label)
+ASDCP::MXF::CreateObject(const Dictionary*& Dict, const UL& label)
{
- if ( label == 0 )
- return 0;
-
if ( ! s_TypesInit )
{
Kumu::AutoMutex BlockLock(s_InitLock);
if ( ! s_TypesInit )
{
- MXF::Metadata_InitTypes();
+ MXF::Metadata_InitTypes(Dict);
s_TypesInit = true;
}
}
- FLi_t i = s_FactoryList.find(label);
+ FLi_t i = s_FactoryList.find(label.Value());
if ( i == s_FactoryList.end() )
- return new InterchangeObject;
+ return new InterchangeObject(Dict);
- return i->second();
+ return i->second(Dict);
}
-
//
// end MXF.cpp
//