X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fh__Reader.cpp;h=77f532e7fe20c1edd6d90a29d37b9ec9f1900c55;hb=5d86f368b2bade7bca7700c74f198ef7f4129b44;hp=77d732f9f2aaae9536691767f8163fd5d7d65c18;hpb=252740d6f7d8924c6af30e55d2da487356a0acdc;p=asdcplib.git diff --git a/src/h__Reader.cpp b/src/h__Reader.cpp index 77d732f..77f532e 100755 --- a/src/h__Reader.cpp +++ b/src/h__Reader.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2012, John Hurst +Copyright (c) 2004-2015, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -38,7 +38,7 @@ using namespace ASDCP::MXF; static Kumu::Mutex sg_DefaultMDInitLock; static bool sg_DefaultMDTypesInit = false; -static const ASDCP::Dictionary *sg_dict; +static const ASDCP::Dictionary *sg_dict = 0; // void @@ -51,8 +51,9 @@ ASDCP::default_md_object_init() if ( ! sg_DefaultMDTypesInit ) { sg_dict = &DefaultSMPTEDict(); - g_OPAtomHeader = new ASDCP::MXF::OPAtomHeader(sg_dict); + g_OP1aHeader = new ASDCP::MXF::OP1aHeader(sg_dict); g_OPAtomIndexFooter = new ASDCP::MXF::OPAtomIndexFooter(sg_dict); + g_RIP = new ASDCP::MXF::RIP(sg_dict); sg_DefaultMDTypesInit = true; } } @@ -63,95 +64,106 @@ ASDCP::default_md_object_init() // // -ASDCP::h__ASDCPReader::h__ASDCPReader(const Dictionary& d) : MXF::TrackFileReader(d), m_BodyPart(m_Dict) {} +ASDCP::h__ASDCPReader::h__ASDCPReader(const Dictionary& d) : MXF::TrackFileReader(d), m_BodyPart(m_Dict) {} ASDCP::h__ASDCPReader::~h__ASDCPReader() {} // AS-DCP method of opening an MXF file for read Result_t -ASDCP::h__ASDCPReader::OpenMXFRead(const char* filename) +ASDCP::h__ASDCPReader::OpenMXFRead(const std::string& filename) { - Result_t result = ASDCP::MXF::TrackFileReader::OpenMXFRead(filename); + Result_t result = ASDCP::MXF::TrackFileReader::OpenMXFRead(filename); if ( KM_SUCCESS(result) ) - { - // if this is a three partition file, go to the body - // partition and read the partition pack - if ( m_HeaderPart.m_RIP.PairArray.size() > 2 ) - { - Array::iterator r_i = m_HeaderPart.m_RIP.PairArray.begin(); - r_i++; - m_File.Seek((*r_i).ByteOffset); - result = m_BodyPart.InitFromFile(m_File); - if( !ASDCP_SUCCESS(result) ) - { - DefaultLogSink().Error("ASDCP::h__Reader::OpenMXFRead, m_BodyPart.InitFromFile failed\n"); - } - } - } - else - DefaultLogSink().Error("ASDCP::h__Reader::OpenMXFRead, TrackFileReader::OpenMXFRead failed\n"); - - - if ( KM_SUCCESS(result) ) - m_HeaderPart.BodyOffset = m_File.Tell(); - - return result; -} - -// -Result_t -ASDCP::h__ASDCPReader::InitInfo() -{ - Result_t result = ASDCP::MXF::TrackFileReader::InitInfo(); + result = ASDCP::MXF::TrackFileReader::InitInfo(); if( KM_SUCCESS(result) ) { + // InterchangeObject* Object; m_Info.LabelSetType = LS_MXF_UNKNOWN; - if ( m_HeaderPart.OperationalPattern.ExactMatch(MXFInterop_OPAtom_Entry().ul) ) + if ( m_HeaderPart.OperationalPattern.MatchExact(MXFInterop_OPAtom_Entry().ul) ) { - m_Info.LabelSetType = LS_MXF_INTEROP; + m_Info.LabelSetType = LS_MXF_INTEROP; } - else if ( m_HeaderPart.OperationalPattern.ExactMatch(SMPTE_390_OPAtom_Entry().ul) ) + else if ( m_HeaderPart.OperationalPattern.MatchExact(SMPTE_390_OPAtom_Entry().ul) ) { m_Info.LabelSetType = LS_MXF_SMPTE; } - } + else + { + char strbuf[IdentBufferLen]; + const MDDEntry* Entry = m_Dict->FindULExact(m_HeaderPart.OperationalPattern.Value()); - return result; -} + if ( Entry == 0 ) + { + DefaultLogSink().Warn("Operational pattern is not OP-Atom: %s\n", + m_HeaderPart.OperationalPattern.EncodeString(strbuf, IdentBufferLen)); + } + else + { + DefaultLogSink().Warn("Operational pattern is not OP-Atom: %s\n", Entry->name); + } + } -// AS-DCP method of populating the in-memory index -Result_t -ASDCP::h__ASDCPReader::InitMXFIndex() -{ - if ( ! m_File.IsOpen() ) - return RESULT_INIT; + if ( !m_RIP.PairArray.empty() && m_RIP.PairArray.front().ByteOffset != 0 ) + { + DefaultLogSink().Error("First Partition in RIP is not at offset 0.\n"); + result = RESULT_FORMAT; + } - Result_t result = m_File.Seek(m_HeaderPart.FooterPartition); + // + if ( m_RIP.PairArray.size() < 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 ST 410. + DefaultLogSink().Warn("RIP entry count is less than 2: %u\n", m_RIP.PairArray.size()); + } + else if ( m_RIP.PairArray.size() > 2 ) + { + // if this is a three partition file, go to the body + // partition and read the partition pack + RIP::const_pair_iterator r_i = m_RIP.PairArray.begin(); + r_i++; + m_File.Seek((*r_i).ByteOffset); + result = m_BodyPart.InitFromFile(m_File); + + if( ASDCP_FAILURE(result) ) + { + DefaultLogSink().Error("ASDCP::h__ASDCPReader::OpenMXFRead, m_BodyPart.InitFromFile failed\n"); + } + } + } - if ( ASDCP_SUCCESS(result) ) + if ( KM_SUCCESS(result) ) { - m_FooterPart.m_Lookup = &m_HeaderPart.m_Primer; - result = m_FooterPart.InitFromFile(m_File); - } + // this position will be at either + // a) the spot in the header partition where essence units appear, or + // b) right after the body partition header (where essence units appear) + m_HeaderPart.BodyOffset = m_File.Tell(); - if ( ASDCP_SUCCESS(result) ) - m_File.Seek(m_HeaderPart.BodyOffset); + result = m_File.Seek(m_HeaderPart.FooterPartition); + + if ( ASDCP_SUCCESS(result) ) + { + m_IndexAccess.m_Lookup = &m_HeaderPart.m_Primer; + result = m_IndexAccess.InitFromFile(m_File); + } + } + m_File.Seek(m_HeaderPart.BodyOffset); return result; } - // AS-DCP method of reading a plaintext or encrypted frame Result_t ASDCP::h__ASDCPReader::ReadEKLVFrame(ui32_t FrameNum, ASDCP::FrameBuffer& FrameBuf, const byte_t* EssenceUL, AESDecContext* Ctx, HMACContext* HMAC) { - return ASDCP::MXF::TrackFileReader::ReadEKLVFrame(m_HeaderPart, FrameNum, FrameBuf, + return ASDCP::MXF::TrackFileReader::ReadEKLVFrame(m_HeaderPart.BodyOffset, FrameNum, FrameBuf, EssenceUL, Ctx, HMAC); } @@ -159,7 +171,7 @@ Result_t ASDCP::h__ASDCPReader::LocateFrame(ui32_t FrameNum, Kumu::fpos_t& streamOffset, i8_t& temporalOffset, i8_t& keyFrameOffset) { - return ASDCP::MXF::TrackFileReader::LocateFrame(m_HeaderPart, FrameNum, + return ASDCP::MXF::TrackFileReader::LocateFrame(m_HeaderPart.BodyOffset, FrameNum, streamOffset, temporalOffset, keyFrameOffset); } @@ -200,7 +212,7 @@ ASDCP::KLReader::ReadKLFromFile(Kumu::FileReader& Reader) if ( ber_size < MXF_BER_LENGTH ) { - DefaultLogSink().Error("BER size %d shorter than AS-DCP minimum %d.\n", + DefaultLogSink().Error("BER size %d shorter than AS-DCP/AS-02 minimum %d.\n", ber_size, MXF_BER_LENGTH); return RESULT_FORMAT; } @@ -223,9 +235,14 @@ ASDCP::KLReader::ReadKLFromFile(Kumu::FileReader& Reader) return InitFromBuffer(m_KeyBuf, header_length); } + +//------------------------------------------------------------------------------------------ +// + + // base subroutine for reading a KLV packet, assumes file position is at the first byte of the packet Result_t -ASDCP::Read_EKLV_Packet(Kumu::FileReader& File, const ASDCP::Dictionary& Dict, const MXF::OPAtomHeader& HeaderPart, +ASDCP::Read_EKLV_Packet(Kumu::FileReader& File, const ASDCP::Dictionary& Dict, const ASDCP::WriterInfo& Info, Kumu::fpos_t& LastPosition, ASDCP::FrameBuffer& CtFrameBuf, ui32_t FrameNum, ui32_t SequenceNum, ASDCP::FrameBuffer& FrameBuf, const byte_t* EssenceUL, AESDecContext* Ctx, HMACContext* HMAC) @@ -295,13 +312,20 @@ ASDCP::Read_EKLV_Packet(Kumu::FileReader& File, const ASDCP::Dictionary& Dict, c if ( ! UL(ess_p).MatchIgnoreStream(EssenceUL) ) // ignore the stream number { char strbuf[IntBufferLen]; - const MDDEntry* Entry = Dict.FindUL(Key.Value()); + const MDDEntry* Entry = Dict.FindULAnyVersion(Key.Value()); + if ( Entry == 0 ) - DefaultLogSink().Warn("Unexpected Essence UL found: %s.\n", Key.EncodeString(strbuf, IntBufferLen)); + { + DefaultLogSink().Warn("Unexpected Essence UL found: %s.\n", Key.EncodeString(strbuf, IntBufferLen)); + } else - DefaultLogSink().Warn("Unexpected Essence UL found: %s.\n", Entry->name); + { + DefaultLogSink().Warn("Unexpected Essence UL found: %s.\n", Entry->name); + } + return RESULT_FORMAT; } + ess_p += SMPTE_UL_LENGTH; // read SourceLength length @@ -407,11 +431,16 @@ ASDCP::Read_EKLV_Packet(Kumu::FileReader& File, const ASDCP::Dictionary& Dict, c else { char strbuf[IntBufferLen]; - const MDDEntry* Entry = Dict.FindUL(Key.Value()); + const MDDEntry* Entry = Dict.FindULAnyVersion(Key.Value()); + if ( Entry == 0 ) - DefaultLogSink().Warn("Unexpected Essence UL found: %s.\n", Key.EncodeString(strbuf, IntBufferLen)); + { + DefaultLogSink().Warn("Unexpected Essence UL found: %s.\n", Key.EncodeString(strbuf, IntBufferLen)); + } else - DefaultLogSink().Warn("Unexpected Essence UL found: %s.\n", Entry->name); + { + DefaultLogSink().Warn("Unexpected Essence UL found: %s.\n", Entry->name); + } return RESULT_FORMAT; }