2 Copyright (c) 2005-2006, 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.
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() :
38 IndexStartPosition(0), IndexDuration(0), EditUnitByteCount(0),
39 IndexSID(129), BodySID(1), SliceCount(0), PosTableCount(0)
44 ASDCP::MXF::IndexTableSegment::~IndexTableSegment()
50 ASDCP::MXF::IndexTableSegment::InitFromTLVSet(TLVReader& TLVSet)
52 Result_t result = InterchangeObject::InitFromTLVSet(TLVSet);
53 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadObject(OBJ_READ_ARGS(IndexTableSegmentBase, IndexEditRate));
54 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi64(OBJ_READ_ARGS(IndexTableSegmentBase, IndexStartPosition));
55 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi64(OBJ_READ_ARGS(IndexTableSegmentBase, IndexDuration));
56 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(IndexTableSegmentBase, EditUnitByteCount));
57 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(IndexTableSegmentBase, IndexSID));
58 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi32(OBJ_READ_ARGS(IndexTableSegmentBase, BodySID));
59 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi8(OBJ_READ_ARGS(IndexTableSegmentBase, SliceCount));
60 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadUi8(OBJ_READ_ARGS(IndexTableSegmentBase, PosTableCount));
61 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadObject(OBJ_READ_ARGS(IndexTableSegment, DeltaEntryArray));
62 if ( ASDCP_SUCCESS(result) ) result = TLVSet.ReadObject(OBJ_READ_ARGS(IndexTableSegment, IndexEntryArray));
65 if ( ASDCP_SUCCESS(result) )
67 Batch<IndexEntry>::iterator i;
69 for ( i = IndexEntryArray.begin(); i != IndexEntryArray.end(); i++ )
71 if ( (*i).Flags == 0x40 )
74 (*i).KeyFrameOffset = offset++;
84 ASDCP::MXF::IndexTableSegment::WriteToTLVSet(TLVWriter& TLVSet)
86 Result_t result = InterchangeObject::WriteToTLVSet(TLVSet);
87 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteObject(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexEditRate));
88 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi64(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexStartPosition));
89 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi64(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexDuration));
90 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(IndexTableSegmentBase, EditUnitByteCount));
91 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(IndexTableSegmentBase, IndexSID));
92 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi32(OBJ_WRITE_ARGS(IndexTableSegmentBase, BodySID));
93 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi8(OBJ_WRITE_ARGS(IndexTableSegmentBase, SliceCount));
94 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteUi8(OBJ_WRITE_ARGS(IndexTableSegmentBase, PosTableCount));
95 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteObject(OBJ_WRITE_ARGS(IndexTableSegment, DeltaEntryArray));
96 if ( ASDCP_SUCCESS(result) ) result = TLVSet.WriteObject(OBJ_WRITE_ARGS(IndexTableSegment, IndexEntryArray));
102 ASDCP::MXF::IndexTableSegment::InitFromBuffer(const byte_t* p, ui32_t l)
104 m_Typeinfo = &Dict::Type(MDD_IndexTableSegment);
105 return InterchangeObject::InitFromBuffer(p, l);
110 ASDCP::MXF::IndexTableSegment::WriteToBuffer(ASDCP::FrameBuffer& Buffer)
112 m_Typeinfo = &Dict::Type(MDD_IndexTableSegment);
113 return InterchangeObject::WriteToBuffer(Buffer);
118 ASDCP::MXF::IndexTableSegment::Dump(FILE* stream)
120 char identbuf[IdentBufferLen];
125 InterchangeObject::Dump(stream);
126 fprintf(stream, " IndexEditRate = %s\n", IndexEditRate.ToString(identbuf));
127 fprintf(stream, " IndexStartPosition = %s\n", i64sz(IndexStartPosition, identbuf));
128 fprintf(stream, " IndexDuration = %s\n", i64sz(IndexDuration, identbuf));
129 fprintf(stream, " EditUnitByteCount = %lu\n", EditUnitByteCount);
130 fprintf(stream, " IndexSID = %lu\n", IndexSID);
131 fprintf(stream, " BodySID = %lu\n", BodySID);
132 fprintf(stream, " SliceCount = %hu\n", SliceCount);
133 fprintf(stream, " PosTableCount = %hu\n", PosTableCount);
135 fprintf(stream, " DeltaEntryArray:\n"); DeltaEntryArray.Dump(stream);
137 if ( IndexEntryArray.size() < 100 )
139 fprintf(stream, " IndexEntryArray:\n");
140 IndexEntryArray.Dump(stream);
144 fprintf(stream, " IndexEntryArray: %lu entries\n", IndexEntryArray.size());
148 //------------------------------------------------------------------------------------------
153 ASDCP::MXF::IndexTableSegment::DeltaEntry::ToString(char* str_buf) const
155 snprintf(str_buf, IdentBufferLen, "%3i %-3hu %-3lu", PosTableIndex, Slice, ElementData);
161 ASDCP::MXF::IndexTableSegment::DeltaEntry::Unarchive(ASDCP::MemIOReader& Reader)
163 Result_t result = Reader.ReadUi8((ui8_t*)&PosTableIndex);
164 if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8(&Slice);
165 if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi32BE(&ElementData);
171 ASDCP::MXF::IndexTableSegment::DeltaEntry::Archive(ASDCP::MemIOWriter& Writer)
173 Result_t result = Writer.WriteUi8((ui8_t)PosTableIndex);
174 if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8(Slice);
175 if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi32BE(ElementData);
179 //------------------------------------------------------------------------------------------
183 // Bit 7: Random Access
184 // Bit 6: Sequence Header
185 // Bit 5: forward prediction flag
186 // Bit 4: backward prediction flag
188 // 00== I frame (no prediction)
189 // 10== P frame(forward prediction from previous frame)
190 // 01== B frame (backward prediction from future frame)
191 // 11== B frame (forward & backward prediction)
192 // Bits 0-3: reserved [RP210 Flags to indicate coding of elements in this edit unit]
196 ASDCP::MXF::IndexTableSegment::IndexEntry::ToString(char* str_buf) const
198 char intbuf[IntBufferLen];
201 txt_flags[0] = ( (Flags & 0x80) != 0 ) ? 'r' : ' ';
202 txt_flags[1] = ( (Flags & 0x40) != 0 ) ? 's' : ' ';
203 txt_flags[2] = ( (Flags & 0x20) != 0 ) ? 'f' : ' ';
204 txt_flags[3] = ( (Flags & 0x10) != 0 ) ? 'b' : ' ';
205 txt_flags[4] = ( (Flags & 0x0f) == 3 ) ? 'B' : ( (Flags & 0x0f) == 2 ) ? 'P' : 'I';
208 snprintf(str_buf, IdentBufferLen, "%3i %-3hu %s %s",
209 TemporalOffset, KeyFrameOffset, txt_flags,
210 i64sz(StreamOffset, intbuf));
217 ASDCP::MXF::IndexTableSegment::IndexEntry::Unarchive(ASDCP::MemIOReader& Reader)
219 Result_t result = Reader.ReadUi8((ui8_t*)&TemporalOffset);
220 if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8((ui8_t*)&KeyFrameOffset);
221 if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi8(&Flags);
222 if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi64BE(&StreamOffset);
228 ASDCP::MXF::IndexTableSegment::IndexEntry::Archive(ASDCP::MemIOWriter& Writer)
230 Result_t result = Writer.WriteUi8((ui8_t)TemporalOffset);
231 if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8((ui8_t)KeyFrameOffset);
232 if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi8(Flags);
233 if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi64BE(StreamOffset);