/*
-Copyright (c) 2008-2009, John Hurst
+Copyright (c) 2008-2013, John Hurst
All rights reserved.
Redistribution and use in source and binary forms, with or without
fprintf(stream, "ContainerDuration: %u\n", TDesc.ContainerDuration);
fprintf(stream, " AssetID: %s\n", TmpID.EncodeHex(buf, 64));
fprintf(stream, " NamespaceName: %s\n", TDesc.NamespaceName.c_str());
- fprintf(stream, " ResourceCount: %d\n", TDesc.ResourceList.size());
+ fprintf(stream, " ResourceCount: %zu\n", TDesc.ResourceList.size());
TimedText::ResourceList_t::const_iterator ri;
for ( ri = TDesc.ResourceList.begin() ; ri != TDesc.ResourceList.end(); ri++ )
typedef std::map<UUID, UUID> ResourceMap_t;
-class ASDCP::TimedText::MXFReader::h__Reader : public ASDCP::h__Reader
+class ASDCP::TimedText::MXFReader::h__Reader : public ASDCP::h__ASDCPReader
{
MXF::TimedTextDescriptor* m_EssenceDescriptor;
ResourceMap_t m_ResourceMap;
public:
TimedTextDescriptor m_TDesc;
- h__Reader() : m_EssenceDescriptor(0) {
+ h__Reader(const Dictionary& d) : ASDCP::h__ASDCPReader(d), m_EssenceDescriptor(0) {
memset(&m_TDesc.AssetID, 0, UUIDlen);
}
- Result_t OpenRead(const char*);
+ virtual ~h__Reader() {}
+
+ Result_t OpenRead(const std::string&);
Result_t MD_to_TimedText_TDesc(TimedText::TimedTextDescriptor& TDesc);
Result_t ReadTimedTextResource(FrameBuffer& FrameBuf, AESDecContext* Ctx, HMACContext* HMAC);
Result_t ReadAncillaryResource(const byte_t*, FrameBuffer& FrameBuf, AESDecContext* Ctx, HMACContext* HMAC);
//
ASDCP::Result_t
-ASDCP::TimedText::MXFReader::h__Reader::OpenRead(char const* filename)
+ASDCP::TimedText::MXFReader::h__Reader::OpenRead(const std::string& filename)
{
Result_t result = OpenMXFRead(filename);
result = MD_to_TimedText_TDesc(m_TDesc);
}
- if( ASDCP_SUCCESS(result) )
- result = InitMXFIndex();
-
- if( ASDCP_SUCCESS(result) )
- result = InitInfo();
-
return result;
}
if ( ! m_File.IsOpen() )
return RESULT_INIT;
- Result_t result = ReadEKLVFrame(0, FrameBuf, Dict::ul(MDD_TimedTextEssence), Ctx, HMAC);
+ assert(m_Dict);
+ Result_t result = ReadEKLVFrame(0, FrameBuf, m_Dict->ul(MDD_TimedTextEssence), Ctx, HMAC);
if( ASDCP_SUCCESS(result) )
{
{
Array<RIP::Pair>::const_iterator pi;
RIP::Pair TmpPair;
- ui32_t sequence = 1;
+ ui32_t sequence = 0;
// Look up the partition start in the RIP using the SID.
// Count the sequence length in because this is the sequence
// value needed to complete the HMAC.
- for ( pi = m_HeaderPart.m_RIP.PairArray.begin(); pi != m_HeaderPart.m_RIP.PairArray.end(); pi++, sequence++ )
+ for ( pi = m_RIP.PairArray.begin(); pi != m_RIP.PairArray.end(); ++pi, ++sequence )
{
if ( (*pi).BodySID == DescObject->EssenceStreamID )
{
}
// read the partition header
- MXF::Partition GSPart;
+ MXF::Partition GSPart(m_Dict);
result = GSPart.InitFromFile(m_File);
if( ASDCP_SUCCESS(result) )
}
// read the essence packet
+ assert(m_Dict);
if( ASDCP_SUCCESS(result) )
- result = ReadEKLVPacket(0, 1, FrameBuf, Dict::ul(MDD_GenericStream_DataElement), Ctx, HMAC);
+ result = ReadEKLVPacket(0, sequence, FrameBuf, m_Dict->ul(MDD_GenericStream_DataElement), Ctx, HMAC);
}
}
}
ASDCP::TimedText::MXFReader::MXFReader()
{
- m_Reader = new h__Reader;
+ m_Reader = new h__Reader(DefaultSMPTEDict());
}
{
}
+// Warning: direct manipulation of MXF structures can interfere
+// with the normal operation of the wrapper. Caveat emptor!
+//
+ASDCP::MXF::OP1aHeader&
+ASDCP::TimedText::MXFReader::OP1aHeader()
+{
+ if ( m_Reader.empty() )
+ {
+ assert(g_OP1aHeader);
+ return *g_OP1aHeader;
+ }
+
+ return m_Reader->m_HeaderPart;
+}
+
+// Warning: direct manipulation of MXF structures can interfere
+// with the normal operation of the wrapper. Caveat emptor!
+//
+ASDCP::MXF::OPAtomIndexFooter&
+ASDCP::TimedText::MXFReader::OPAtomIndexFooter()
+{
+ if ( m_Reader.empty() )
+ {
+ assert(g_OPAtomIndexFooter);
+ return *g_OPAtomIndexFooter;
+ }
+
+ return m_Reader->m_IndexAccess;
+}
+
+// Warning: direct manipulation of MXF structures can interfere
+// with the normal operation of the wrapper. Caveat emptor!
+//
+ASDCP::MXF::RIP&
+ASDCP::TimedText::MXFReader::RIP()
+{
+ if ( m_Reader.empty() )
+ {
+ assert(g_RIP);
+ return *g_RIP;
+ }
+
+ return m_Reader->m_RIP;
+}
+
// Open the file for reading. The file must exist. Returns error if the
// operation cannot be completed.
ASDCP::Result_t
-ASDCP::TimedText::MXFReader::OpenRead(const char* filename) const
+ASDCP::TimedText::MXFReader::OpenRead(const std::string& filename) const
{
return m_Reader->OpenRead(filename);
}
ASDCP::TimedText::MXFReader::DumpIndex(FILE* stream) const
{
if ( m_Reader->m_File.IsOpen() )
- m_Reader->m_FooterPart.Dump(stream);
+ m_Reader->m_IndexAccess.Dump(stream);
+}
+
+//
+ASDCP::Result_t
+ASDCP::TimedText::MXFReader::Close() const
+{
+ if ( m_Reader && m_Reader->m_File.IsOpen() )
+ {
+ m_Reader->Close();
+ return RESULT_OK;
+ }
+
+ return RESULT_INIT;
}
+
//------------------------------------------------------------------------------------------
//
-class ASDCP::TimedText::MXFWriter::h__Writer : public ASDCP::h__Writer
+class ASDCP::TimedText::MXFWriter::h__Writer : public ASDCP::h__ASDCPWriter
{
+ ASDCP_NO_COPY_CONSTRUCT(h__Writer);
+ h__Writer();
+
public:
TimedTextDescriptor m_TDesc;
byte_t m_EssenceUL[SMPTE_UL_LENGTH];
ui32_t m_EssenceStreamID;
- ASDCP_NO_COPY_CONSTRUCT(h__Writer);
-
- h__Writer() : m_EssenceStreamID(10) {
+ h__Writer(const Dictionary& d) : ASDCP::h__ASDCPWriter(d), m_EssenceStreamID(10) {
memset(m_EssenceUL, 0, SMPTE_UL_LENGTH);
}
- ~h__Writer(){}
+ virtual ~h__Writer() {}
- Result_t OpenWrite(const char*, ui32_t HeaderSize);
+ Result_t OpenWrite(const std::string&, ui32_t HeaderSize);
Result_t SetSourceStream(const TimedTextDescriptor&);
Result_t WriteTimedTextResource(const std::string& XMLDoc, AESEncContext* = 0, HMACContext* = 0);
Result_t WriteAncillaryResource(const FrameBuffer&, AESEncContext* = 0, HMACContext* = 0);
//
ASDCP::Result_t
-ASDCP::TimedText::MXFWriter::h__Writer::OpenWrite(char const* filename, ui32_t HeaderSize)
+ASDCP::TimedText::MXFWriter::h__Writer::OpenWrite(const std::string& filename, ui32_t HeaderSize)
{
if ( ! m_State.Test_BEGIN() )
return RESULT_STATE;
if ( ASDCP_SUCCESS(result) )
{
m_HeaderSize = HeaderSize;
- m_EssenceDescriptor = new MXF::TimedTextDescriptor();
+ m_EssenceDescriptor = new MXF::TimedTextDescriptor(m_Dict);
result = m_State.Goto_INIT();
}
for ( ri = m_TDesc.ResourceList.begin() ; ri != m_TDesc.ResourceList.end() && ASDCP_SUCCESS(result); ri++ )
{
- TimedTextResourceSubDescriptor* resourceSubdescriptor = new TimedTextResourceSubDescriptor;
+ TimedTextResourceSubDescriptor* resourceSubdescriptor = new TimedTextResourceSubDescriptor(m_Dict);
GenRandomValue(resourceSubdescriptor->InstanceUID);
resourceSubdescriptor->AncillaryResourceID.Set((*ri).ResourceID);
resourceSubdescriptor->MIMEMediaType = MIME2str((*ri).Type);
}
m_EssenceStreamID = 10;
+ assert(m_Dict);
if ( ASDCP_SUCCESS(result) )
{
InitHeader();
- AddDMSegment(m_TDesc.EditRate, 24, TIMED_TEXT_DEF_LABEL,
- UL(Dict::ul(MDD_PictureDataDef)), TIMED_TEXT_PACKAGE_LABEL);
- AddEssenceDescriptor(UL(Dict::ul(MDD_TimedTextWrapping)));
+ // First RIP Entry
+ if ( m_Info.LabelSetType == LS_MXF_SMPTE ) // ERK
+ {
+ m_RIP.PairArray.push_back(RIP::Pair(0, 0)); // 3-part, no essence in header
+ }
+ else
+ {
+ DefaultLogSink().Error("Unable to write Interop timed-text MXF file. Use SMOTE DCP options instead.\n");
+ return RESULT_FORMAT;
+ }
+
+ // timecode rate and essence rate are the same
+ AddDMSegment(m_TDesc.EditRate, m_TDesc.EditRate, derive_timecode_rate_from_edit_rate(m_TDesc.EditRate), TIMED_TEXT_DEF_LABEL,
+ UL(m_Dict->ul(MDD_DataDataDef)), TIMED_TEXT_PACKAGE_LABEL);
+
+ AddEssenceDescriptor(UL(m_Dict->ul(MDD_TimedTextWrappingClip)));
result = m_HeaderPart.WriteToFile(m_File, m_HeaderSize);
if ( ASDCP_SUCCESS(result) )
{
- memcpy(m_EssenceUL, Dict::ul(MDD_TimedTextEssence), SMPTE_UL_LENGTH);
+ memcpy(m_EssenceUL, m_Dict->ul(MDD_TimedTextEssence), SMPTE_UL_LENGTH);
m_EssenceUL[SMPTE_UL_LENGTH-1] = 1; // first (and only) essence container
result = m_State.Goto_READY();
}
return RESULT_STATE;
Kumu::fpos_t here = m_File.Tell();
+ assert(m_Dict);
// create generic stream partition header
- static UL GenericStream_DataElement(Dict::ul(MDD_GenericStream_DataElement));
- MXF::Partition GSPart;
+ static UL GenericStream_DataElement(m_Dict->ul(MDD_GenericStream_DataElement));
+ MXF::Partition GSPart(m_Dict);
GSPart.ThisPartition = here;
- GSPart.PreviousPartition = m_HeaderPart.m_RIP.PairArray.back().ByteOffset;
+ GSPart.PreviousPartition = m_RIP.PairArray.back().ByteOffset;
GSPart.BodySID = m_EssenceStreamID;
GSPart.OperationalPattern = m_HeaderPart.OperationalPattern;
- m_HeaderPart.m_RIP.PairArray.push_back(RIP::Pair(m_EssenceStreamID++, here));
- GSPart.EssenceContainers.push_back(UL(Dict::ul(MDD_TimedTextEssence)));
- UL TmpUL(Dict::ul(MDD_GenericStreamPartition));
+ m_RIP.PairArray.push_back(RIP::Pair(m_EssenceStreamID++, here));
+ GSPart.EssenceContainers.push_back(UL(m_Dict->ul(MDD_TimedTextEssence)));
+ UL TmpUL(m_Dict->ul(MDD_GenericStreamPartition));
Result_t result = GSPart.WriteToFile(m_File, TmpUL);
if ( ASDCP_SUCCESS(result) )
m_FramesWritten = m_TDesc.ContainerDuration;
m_State.Goto_FINAL();
- return WriteMXFFooter();
+ return WriteASDCPFooter();
}
{
}
+// Warning: direct manipulation of MXF structures can interfere
+// with the normal operation of the wrapper. Caveat emptor!
+//
+ASDCP::MXF::OP1aHeader&
+ASDCP::TimedText::MXFWriter::OP1aHeader()
+{
+ if ( m_Writer.empty() )
+ {
+ assert(g_OP1aHeader);
+ return *g_OP1aHeader;
+ }
+
+ return m_Writer->m_HeaderPart;
+}
+
+// Warning: direct manipulation of MXF structures can interfere
+// with the normal operation of the wrapper. Caveat emptor!
+//
+ASDCP::MXF::OPAtomIndexFooter&
+ASDCP::TimedText::MXFWriter::OPAtomIndexFooter()
+{
+ if ( m_Writer.empty() )
+ {
+ assert(g_OPAtomIndexFooter);
+ return *g_OPAtomIndexFooter;
+ }
+
+ return m_Writer->m_FooterPart;
+}
+
+// Warning: direct manipulation of MXF structures can interfere
+// with the normal operation of the wrapper. Caveat emptor!
+//
+ASDCP::MXF::RIP&
+ASDCP::TimedText::MXFWriter::RIP()
+{
+ if ( m_Writer.empty() )
+ {
+ assert(g_RIP);
+ return *g_RIP;
+ }
+
+ return m_Writer->m_RIP;
+}
// Open the file for writing. The file must not exist. Returns error if
// the operation cannot be completed.
ASDCP::Result_t
-ASDCP::TimedText::MXFWriter::OpenWrite(const char* filename, const WriterInfo& Info,
+ASDCP::TimedText::MXFWriter::OpenWrite(const std::string& filename, const WriterInfo& Info,
const TimedTextDescriptor& TDesc, ui32_t HeaderSize)
{
if ( Info.LabelSetType != LS_MXF_SMPTE )
return RESULT_FORMAT;
}
- m_Writer = new h__Writer;
+ m_Writer = new h__Writer(DefaultSMPTEDict());
m_Writer->m_Info = Info;
Result_t result = m_Writer->OpenWrite(filename, HeaderSize);