Skip to content

Commit

Permalink
rdd9: set index segment byte counts equal if possible
Browse files Browse the repository at this point in the history
RDD 9 2013, section B.6 states that the Index Byte Count of the last
Index Table Segment should equal the value of the other Index Table
Segments even when the Index Duration of the last Index Table Segment is
shorter.
  • Loading branch information
philipnbbc committed Apr 25, 2023
1 parent 58cd3e7 commit 7358725
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/bmx/rdd9_mxf/RDD9IndexTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class RDD9IndexTable
std::vector<RDD9IndexTableSegment*> mIndexSegments;
int64_t mDuration;
int64_t mStreamOffset;
int64_t mFirstIndexSegmentCount;

std::vector<RDD9IndexTableSegment*> mWrittenIndexSegments;
};
Expand Down
18 changes: 17 additions & 1 deletion src/rdd9_mxf/RDD9IndexTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ RDD9IndexTable::RDD9IndexTable(uint32_t index_sid, uint32_t body_sid, Rational e
mIndexEntrySize = 0;
mDuration = 0;
mStreamOffset = 0;
mFirstIndexSegmentCount = 0;
}

RDD9IndexTable::~RDD9IndexTable()
Expand Down Expand Up @@ -479,6 +480,8 @@ void RDD9IndexTable::WriteVBESegments(File *mxf_file, Partition *partition, vect
{
size_t i;
for (i = 0; i < segments.size(); i++) {
int64_t segment_start_file_pos = mxf_file->tell();

IndexTableSegment *segment = segments[i]->GetSegment();
ByteArray *entries = segments[i]->GetEntries();

Expand All @@ -498,7 +501,20 @@ void RDD9IndexTable::WriteVBESegments(File *mxf_file, Partition *partition, vect
segment->writeIndexEntryArrayHeader(mxf_file, mSliceCount, 0, (uint32_t)segment->getIndexDuration());
mxf_file->write(entries->GetBytes(), entries->GetSize());

partition->fillToKag(mxf_file);
// The index byte count for all index segments should all be equal.
// The index durations for all index segments, except the last, should all be equal.
// The last index segment may have a shorter index duration and the code below should
// ensure that it has the same index byte count (as the first index segment).
if (mFirstIndexSegmentCount == 0) {
mFirstIndexSegmentCount = mxf_file->tell() - segment_start_file_pos;
partition->fillToKag(mxf_file);
} else {
int64_t current_count = mxf_file->tell() - segment_start_file_pos;
if (current_count < mFirstIndexSegmentCount)
partition->allocateSpaceToKag(mxf_file, mFirstIndexSegmentCount - current_count);
else
partition->fillToKag(mxf_file);
}
}
}

0 comments on commit 7358725

Please sign in to comment.