/*
-Copyright (c) 2008-2012, John Hurst
+Copyright (c) 2008-2018, John Hurst
All rights reserved.
Redistribution and use in source and binary forms, with or without
//------------------------------------------------------------------------------------------
-const char*
+//
+static const char*
MIME2str(TimedText::MIMEType_t m)
{
if ( m == TimedText::MT_PNG )
return "image/png";
- else if ( m == TimedText::MT_OPENTYPE )
+ else if( m == TimedText::MT_OPENTYPE )
return "application/x-font-opentype";
-
+
return "application/octet-stream";
}
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++ )
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);
memcpy(TDesc.AssetID, TDescObj->ResourceID.Value(), UUIDlen);
TDesc.NamespaceName = TDescObj->NamespaceURI;
TDesc.EncodingName = TDescObj->UCSEncoding;
+ TDesc.ResourceList.clear();
- Batch<UUID>::const_iterator sdi = TDescObj->SubDescriptors.begin();
+ Array<UUID>::const_iterator sdi = TDescObj->SubDescriptors.begin();
TimedTextResourceSubDescriptor* DescObject = 0;
Result_t result = RESULT_OK;
//
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;
}
//
ASDCP::Result_t
-ASDCP::TimedText::MXFReader::h__Reader::ReadAncillaryResource(const byte_t* uuid, FrameBuffer& FrameBuf,
+ASDCP::TimedText::MXFReader::h__Reader::ReadAncillaryResource(const byte_t* uuid, FrameBuffer& frame_buf,
AESDecContext* Ctx, HMACContext* HMAC)
{
KM_TEST_NULL_L(uuid);
return RESULT_RANGE;
}
- TimedTextResourceSubDescriptor* DescObject = 0;
// get the subdescriptor
InterchangeObject* tmp_iobj = 0;
Result_t result = m_HeaderPart.GetMDObjectByID((*ri).second, &tmp_iobj);
- DescObject = static_cast<TimedTextResourceSubDescriptor*>(tmp_iobj);
+ TimedTextResourceSubDescriptor* desc_object = dynamic_cast<TimedTextResourceSubDescriptor*>(tmp_iobj);
if ( KM_SUCCESS(result) )
{
- Array<RIP::Pair>::const_iterator pi;
- RIP::Pair TmpPair;
- 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 )
- {
- if ( (*pi).BodySID == DescObject->EssenceStreamID )
- {
- TmpPair = *pi;
- break;
- }
- }
-
- if ( TmpPair.ByteOffset == 0 )
- {
- DefaultLogSink().Error("Body SID not found in RIP set: %d\n", DescObject->EssenceStreamID);
- return RESULT_FORMAT;
- }
+ assert(desc_object);
+ result = ReadGenericStreamPartitionPayload(desc_object->EssenceStreamID, frame_buf, Ctx, HMAC);
+ }
- if ( KM_SUCCESS(result) )
- {
- FrameBuf.AssetID(uuid);
- FrameBuf.MIMEType(DescObject->MIMEMediaType);
-
- // seek tp the start of the partition
- if ( (Kumu::fpos_t)TmpPair.ByteOffset != m_LastPosition )
- {
- m_LastPosition = TmpPair.ByteOffset;
- result = m_File.Seek(TmpPair.ByteOffset);
- }
-
- // read the partition header
- MXF::Partition GSPart(m_Dict);
- result = GSPart.InitFromFile(m_File);
-
- if( ASDCP_SUCCESS(result) )
- {
- // check the SID
- if ( DescObject->EssenceStreamID != GSPart.BodySID )
- {
- char buf[64];
- DefaultLogSink().Error("Generic stream partition body differs: %s\n", RID.EncodeHex(buf, 64));
- return RESULT_FORMAT;
- }
-
- // read the essence packet
- assert(m_Dict);
- if( ASDCP_SUCCESS(result) )
- result = ReadEKLVPacket(0, sequence, FrameBuf, m_Dict->ul(MDD_GenericStream_DataElement), Ctx, HMAC);
- }
- }
+ if ( KM_SUCCESS(result) )
+ {
+ frame_buf.AssetID(uuid);
+ frame_buf.MIMEType(desc_object->MIMEMediaType);
}
return result;
// Warning: direct manipulation of MXF structures can interfere
// with the normal operation of the wrapper. Caveat emptor!
//
-ASDCP::MXF::OPAtomHeader&
-ASDCP::TimedText::MXFReader::OPAtomHeader()
+ASDCP::MXF::OP1aHeader&
+ASDCP::TimedText::MXFReader::OP1aHeader()
{
if ( m_Reader.empty() )
{
- assert(g_OPAtomHeader);
- return *g_OPAtomHeader;
+ assert(g_OP1aHeader);
+ return *g_OP1aHeader;
}
return m_Reader->m_HeaderPart;
return *g_OPAtomIndexFooter;
}
- return m_Reader->m_FooterPart;
+ 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);
}
//
//
-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();
byte_t m_EssenceUL[SMPTE_UL_LENGTH];
ui32_t m_EssenceStreamID;
- h__Writer(const Dictionary& d) : ASDCP::h__Writer(d), 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;
resourceSubdescriptor->EssenceStreamID = m_EssenceStreamID++;
m_EssenceSubDescriptorList.push_back((FileDescriptor*)resourceSubdescriptor);
m_EssenceDescriptor->SubDescriptors.push_back(resourceSubdescriptor->InstanceUID);
+
+ // 72 == sizeof K, L, instanceuid, uuid + sizeof int32 + tag/len * 4
+ m_HeaderSize += ( resourceSubdescriptor->MIMEMediaType.ArchiveLength() * 2 /*ArchiveLength is broken*/ ) + 72;
}
m_EssenceStreamID = 10;
if ( ASDCP_SUCCESS(result) )
{
- InitHeader();
- AddDMSegment(m_TDesc.EditRate, 24, TIMED_TEXT_DEF_LABEL,
- UL(m_Dict->ul(MDD_PictureDataDef)), TIMED_TEXT_PACKAGE_LABEL);
+ InitHeader(MXFVersion_2004);
+
+ // First RIP Entry
+ if ( m_Info.LabelSetType == LS_MXF_SMPTE ) // ERK
+ {
+ m_RIP.PairArray.push_back(RIP::PartitionPair(0, 0)); // 3-part, no essence in header
+ }
+ else
+ {
+ DefaultLogSink().Error("Unable to write Interop timed-text MXF file. Use SMPTE DCP options instead.\n");
+ return RESULT_FORMAT;
+ }
- AddEssenceDescriptor(UL(m_Dict->ul(MDD_TimedTextWrapping)));
+ // timecode rate and essence rate are the same
+ AddSourceClip(m_TDesc.EditRate, m_TDesc.EditRate, derive_timecode_rate_from_edit_rate(m_TDesc.EditRate),
+ TIMED_TEXT_DEF_LABEL, m_EssenceUL, 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 ( KM_SUCCESS(result) )
IndexTableSegment::IndexEntry Entry;
Entry.StreamOffset = m_StreamOffset;
-
- if ( ASDCP_SUCCESS(result) )
- result = WriteEKLVPacket(FrameBuf, m_EssenceUL, Ctx, HMAC);
+ result = WriteEKLVPacket(FrameBuf, m_EssenceUL, MXF_BER_LENGTH, Ctx, HMAC);
if ( ASDCP_SUCCESS(result) )
{
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(m_Dict->ul(MDD_TimedTextEssence)));
+ m_RIP.PairArray.push_back(RIP::PartitionPair(m_EssenceStreamID++, here));
+ GSPart.EssenceContainers = m_HeaderPart.EssenceContainers;
UL TmpUL(m_Dict->ul(MDD_GenericStreamPartition));
Result_t result = GSPart.WriteToFile(m_File, TmpUL);
if ( ASDCP_SUCCESS(result) )
- result = WriteEKLVPacket(FrameBuf, GenericStream_DataElement.Value(), Ctx, HMAC);
+ result = WriteEKLVPacket(FrameBuf, GenericStream_DataElement.Value(), MXF_BER_LENGTH, Ctx, HMAC);
m_FramesWritten++;
return 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::OPAtomHeader&
-ASDCP::TimedText::MXFWriter::OPAtomHeader()
+ASDCP::MXF::OP1aHeader&
+ASDCP::TimedText::MXFWriter::OP1aHeader()
{
if ( m_Writer.empty() )
{
- assert(g_OPAtomHeader);
- return *g_OPAtomHeader;
+ assert(g_OP1aHeader);
+ return *g_OP1aHeader;
}
return m_Writer->m_HeaderPart;
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 )