+ // Reads a Generic Stream Partition payload. Returns RESULT_FORMAT if the SID is
+ // not present in the RIP, or if the actual partition at ByteOffset does not have
+ // a matching BodySID value. Encryption is not currently supported.
+ Result_t ReadGenericStreamPartitionPayload(const ui32_t sid, ASDCP::FrameBuffer& frame_buf,
+ AESDecContext* Ctx, HMACContext* HMAC)
+ {
+ Kumu::fpos_t start_offset = 0, end_offset = 0;
+ ui32_t sequence = 0;
+
+ // locate SID, record the offset
+ // Count the sequence length in because this is the sequence
+ // value needed to complete the HMAC.
+ ASDCP::MXF::RIP::const_pair_iterator i;
+ for ( i = m_RIP.PairArray.begin(); i != m_RIP.PairArray.end(); ++i, ++sequence )
+ {
+ if ( sid == i->BodySID )
+ {
+ start_offset = i->ByteOffset;
+ }
+ else if ( start_offset != 0 )
+ {
+ end_offset = i->ByteOffset;
+ break;
+ }
+ }
+
+ if ( start_offset == 0 || end_offset == 0 )
+ {
+ DefaultLogSink().Error("Body SID not found: %d.\n", sid);
+ return RESULT_NOT_FOUND;
+ }
+
+ // Read the Partition header and then read the payload.
+ Result_t result = m_File.Seek(start_offset);
+
+ if ( KM_SUCCESS(result) )
+ {
+ result = frame_buf.Capacity(end_offset-start_offset);
+ }
+
+ if ( KM_SUCCESS(result) )
+ {
+ // read the partition header
+ ASDCP::MXF::Partition GSPart(m_Dict);
+ result = GSPart.InitFromFile(m_File);
+
+ if ( KM_SUCCESS(result) )
+ {
+ // check the SID
+ if ( GSPart.BodySID != sid )
+ {
+ DefaultLogSink().Error("Generic stream partition Body SID differs: %s\n", sid);
+ result = RESULT_FORMAT;
+ }
+ else
+ {
+ result = ReadEKLVPacket(0, sequence, frame_buf, m_Dict->ul(MDD_GenericStream_DataElement), Ctx, HMAC);
+ }
+ }
+ }
+
+ return result;
+ }
+