Fix timestamp computation when copying within first block.

When computing the last copied sample's timestamp, first_block_offset_ needs to be taken into account.

PiperOrigin-RevId: 542643291
This commit is contained in:
MediaPipe Team 2023-06-22 12:58:43 -07:00 committed by Copybara-Service
parent 98d493f37a
commit 2f5fc16a38

View File

@ -208,6 +208,7 @@ Matrix TimeSeriesFramerCalculator::SampleBlockBuffer::CopySamples(
int offset = first_block_offset_;
int n;
Timestamp last_block_ts;
int last_sample_index;
for (auto it = blocks_.begin(); it != blocks_.end() && count > 0; ++it) {
n = std::min(it->num_samples() - offset, count);
@ -216,12 +217,13 @@ Matrix TimeSeriesFramerCalculator::SampleBlockBuffer::CopySamples(
count -= n;
num_copied += n;
last_block_ts = it->timestamp;
last_sample_index = offset + n - 1;
offset = 0; // No samples have been discarded in subsequent blocks.
}
// Compute the timestamp of the last copied sample.
*last_timestamp =
last_block_ts + std::round(ts_units_per_sample_ * (n - 1));
last_block_ts + std::round(ts_units_per_sample_ * last_sample_index);
}
if (count > 0) {