2 Copyright (c) 2005-2012, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 \version $Id: Index.cpp,v 1.21 2012/02/03 19:49:56 jhurst Exp $
29 \brief MXF index segment objects
33 const ui32_t kl_length = ASDCP::SMPTE_UL_LENGTH + ASDCP::MXF_BER_LENGTH;
37 ASDCP::MXF::IndexTableSegment::IndexTableSegment(const Dictionary*& d) :
38 InterchangeObject(d), m_Dict(d),
39 IndexStartPosition(0), IndexDuration(0), EditUnitByteCount(0),
40 IndexSID(129), BodySID(1), SliceCount(0), PosTableCount(0)
43 m_UL = m_Dict->ul(MDD_IndexTableSegment);
47 ASDCP::MXF::IndexTableSegment::~IndexTableSegment()
53 ASDCP::MXF::IndexTableSegment::Copy(const IndexTableSegment& rhs)
55 InterchangeObject::Copy(rhs);
56 IndexEditRate = rhs.IndexEditRate;
57 IndexStartPosition = rhs.IndexStartPosition;
58 IndexDuration = rhs.IndexDuration;
59 EditUnitByteCount = rhs.EditUnitByteCount;
60 IndexSID = rhs.IndexSID;
61 BodySID = rhs.BodySID;
62 SliceCount = rhs.SliceCount;
63 PosTableCount = rhs.PosTableCount;
64 DeltaEntryArray = rhs.DeltaEntryArray;
65 IndexEntryArray = rhs.IndexEntryArray;
70 ASDCP::MXF::IndexTableSegment::InitFromTLVSet(TLVReader& TLVSet)
72 Result_t result = InterchangeObject::InitFromTLVSet(TLVSet);
73 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadObject(OBJ_READ_ARGS(IndexTableSegmentBase, IndexEditRate));
74 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi64(OBJ_READ_ARGS(IndexTableSegmentBase, IndexStartPosition));
75 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi64(OBJ_READ_ARGS(IndexTableSegmentBase, IndexDuration));
76 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(IndexTableSegmentBase, EditUnitByteCount));
77 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(IndexTableSegmentBase, IndexSID));
78 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(EssenceContainerData, BodySID));
79 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi8(OBJ_READ_ARGS(IndexTableSegmentBase, SliceCount));
80 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi8(OBJ_READ_ARGS(IndexTableSegmentBase, PosTableCount));
81 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadObject(OBJ_READ_ARGS(IndexTableSegment, DeltaEntryArray));
82 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadObject(OBJ_READ_ARGS(IndexTableSegment, IndexEntryArray));
88 ASDCP::MXF::IndexTableSegment::WriteToTLVSet(TLVWriter& TLVSet)
90 Result_t result = InterchangeObject::WriteToTLVSet(TLVSet);
91 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteObject(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexEditRate));
92 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi64(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexStartPosition));
93 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi64(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexDuration));
94 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(IndexTableSegmentBase, EditUnitByteCount));
95 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexSID));
96 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(EssenceContainerData, BodySID));
97 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi8(OBJ_WRITE_ARGS(IndexTableSegmentBase, SliceCount));
98 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi8(OBJ_WRITE_ARGS(IndexTableSegmentBase, PosTableCount));
99 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteObject(OBJ_WRITE_ARGS(IndexTableSegment, DeltaEntryArray));
100 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteObject(OBJ_WRITE_ARGS(IndexTableSegment, IndexEntryArray));
106 ASDCP::MXF::IndexTableSegment::InitFromBuffer(const byte_t* p, ui32_t l)
108 return InterchangeObject::InitFromBuffer(p, l);
113 ASDCP::MXF::IndexTableSegment::WriteToBuffer(ASDCP::FrameBuffer& Buffer)
115 return InterchangeObject::WriteToBuffer(Buffer);
120 ASDCP::MXF::IndexTableSegment::Dump(FILE* stream)
122 char identbuf[IdentBufferLen];
127 InterchangeObject::Dump(stream);
128 fprintf(stream, " IndexEditRate = %s\n", IndexEditRate.EncodeString(identbuf, IdentBufferLen));
129 fprintf(stream, " IndexStartPosition = %s\n", i64sz(IndexStartPosition, identbuf));
130 fprintf(stream, " IndexDuration = %s\n", i64sz(IndexDuration, identbuf));
131 fprintf(stream, " EditUnitByteCount = %u\n", EditUnitByteCount);
132 fprintf(stream, " IndexSID = %u\n", IndexSID);
133 fprintf(stream, " BodySID = %u\n", BodySID);
134 fprintf(stream, " SliceCount = %hu\n", SliceCount);
135 fprintf(stream, " PosTableCount = %hu\n", PosTableCount);
137 fprintf(stream, " DeltaEntryArray:\n"); DeltaEntryArray.Dump(stream);
139 if ( IndexEntryArray.size() < 100 )
141 fprintf(stream, " IndexEntryArray:\n");
142 IndexEntryArray.Dump(stream);
146 fprintf(stream, " IndexEntryArray: %zu entries\n", IndexEntryArray.size());
150 //------------------------------------------------------------------------------------------
155 ASDCP::MXF::IndexTableSegment::DeltaEntry::EncodeString(char* str_buf, ui32_t buf_len) const
157 snprintf(str_buf, buf_len, "%3d %-3hu %-3u", PosTableIndex, Slice, ElementData);
163 ASDCP::MXF::IndexTableSegment::DeltaEntry::Unarchive(Kumu::MemIOReader* Reader)
165 if ( ! Reader->ReadUi8((ui8_t*)&PosTableIndex) ) return false;
166 if ( ! Reader->ReadUi8(&Slice) ) return false;
167 if ( ! Reader->ReadUi32BE(&ElementData) ) return false;
173 ASDCP::MXF::IndexTableSegment::DeltaEntry::Archive(Kumu::MemIOWriter* Writer) const
175 if ( ! Writer->WriteUi8((ui8_t)PosTableIndex) ) return false;
176 if ( ! Writer->WriteUi8(Slice) ) return false;
177 if ( ! Writer->WriteUi32BE(ElementData) ) return false;
181 //------------------------------------------------------------------------------------------
185 // Bit 7: Random Access
186 // Bit 6: Sequence Header
187 // Bit 5: forward prediction flag
188 // Bit 4: backward prediction flag
190 // 00== I frame (no prediction)
191 // 10== P frame(forward prediction from previous frame)
192 // 01== B frame (backward prediction from future frame)
193 // 11== B frame (forward & backward prediction)
194 // Bits 0-3: reserved [RP210 Flags to indicate coding of elements in this edit unit]
198 ASDCP::MXF::IndexTableSegment::IndexEntry::EncodeString(char* str_buf, ui32_t buf_len) const
200 char intbuf[IntBufferLen];
203 txt_flags[0] = ( (Flags & 0x80) != 0 ) ? 'r' : ' ';
204 txt_flags[1] = ( (Flags & 0x40) != 0 ) ? 's' : ' ';
205 txt_flags[2] = ( (Flags & 0x20) != 0 ) ? 'f' : ' ';
206 txt_flags[3] = ( (Flags & 0x10) != 0 ) ? 'b' : ' ';
207 txt_flags[4] = ( (Flags & 0x0f) == 3 ) ? 'B' : ( (Flags & 0x0f) == 2 ) ? 'P' : 'I';
210 snprintf(str_buf, buf_len, "%3i %-3hu %s %s",
211 TemporalOffset, KeyFrameOffset, txt_flags,
212 i64sz(StreamOffset, intbuf));
219 ASDCP::MXF::IndexTableSegment::IndexEntry::Unarchive(Kumu::MemIOReader* Reader)
221 if ( ! Reader->ReadUi8((ui8_t*)&TemporalOffset) ) return false;
222 if ( ! Reader->ReadUi8((ui8_t*)&KeyFrameOffset) ) return false;
223 if ( ! Reader->ReadUi8(&Flags) ) return false;
224 if ( ! Reader->ReadUi64BE(&StreamOffset) ) return false;
230 ASDCP::MXF::IndexTableSegment::IndexEntry::Archive(Kumu::MemIOWriter* Writer) const
232 if ( ! Writer->WriteUi8((ui8_t)TemporalOffset) ) return false;
233 if ( ! Writer->WriteUi8((ui8_t)KeyFrameOffset) ) return false;
234 if ( ! Writer->WriteUi8(Flags) ) return false;
235 if ( ! Writer->WriteUi64BE(StreamOffset) ) return false;