From 3054451560cd3822e9303d74da007ac9b1dec7de Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 13 Dec 2024 03:13:10 -0800 Subject: [PATCH] add function to return last data record timestamp Summary: analagous to getFirstDataRecordTime() this is useful for testing purpose when, for example, writing a tool that translates timestamps Reviewed By: georges-berenger Differential Revision: D67035162 fbshipit-source-id: 200a678939d0a7a8ef8dec62cbbf06e716c70dc2 --- tools/vrs/test/VrsAppTest.cpp | 1 + vrs/RecordFileReader.cpp | 9 +++++++++ vrs/RecordFileReader.h | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/tools/vrs/test/VrsAppTest.cpp b/tools/vrs/test/VrsAppTest.cpp index ddb99281..5a4ac6dd 100644 --- a/tools/vrs/test/VrsAppTest.cpp +++ b/tools/vrs/test/VrsAppTest.cpp @@ -300,6 +300,7 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(mergeTimeFilterTest)) { // Data records are constrained by the +0.2 range EXPECT_NEAR(reader.getFirstDataRecordTime(), 2.002, 0.0001); EXPECT_NEAR(reader.getIndex().back().timestamp, 12.071, 0.0001); + EXPECT_NEAR(reader.getLastDataRecordTime(), 12.071, 0.0001); remove(outputFile.c_str()); } diff --git a/vrs/RecordFileReader.cpp b/vrs/RecordFileReader.cpp index 6f818189..0db31a95 100644 --- a/vrs/RecordFileReader.cpp +++ b/vrs/RecordFileReader.cpp @@ -843,6 +843,15 @@ double RecordFileReader::getFirstDataRecordTime() const { return 0; // no data record... } +double RecordFileReader::getLastDataRecordTime() const { + for (auto iter = recordIndex_.rbegin(); iter != recordIndex_.rend(); ++iter) { + if (iter->recordType == Record::Type::DATA) { + return iter->timestamp; + } + } + return 0; +} + bool RecordFileReader::readConfigRecords( const set& configRecords, StreamPlayer* streamPlayer) { diff --git a/vrs/RecordFileReader.h b/vrs/RecordFileReader.h index 1ad37cb8..bd14bfad 100644 --- a/vrs/RecordFileReader.h +++ b/vrs/RecordFileReader.h @@ -352,6 +352,10 @@ class RecordFileReader { /// @return The timestamp for the file data record, or 0, if the file contains no data record. double getFirstDataRecordTime() const; + /// Timestamp for the last data record in the whole file. + /// @return The timestamp for the file data record, or 0, if the file contains no data record. + double getLastDataRecordTime() const; + /// Helper function: Read a stream's first configuration record. /// This might be necessary to properly read records containing image or audio blocks, /// if their configuration is defined in a configuration record using datalayout conventions.