Skip to content

Commit d99bc1d

Browse files
Georges Berengermeta-codesync[bot]
authored andcommitted
Report stream serial numbers more consistently
Summary: Report serial numbers more consistently everywhere we provide stream IDs. Reviewed By: liorda Differential Revision: D85787556 fbshipit-source-id: fa6ff6b3b0f43159f8ebdcea348efe879e018f52
1 parent fd1d734 commit d99bc1d

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

csrc/reader/MultiVRSReader.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,12 @@ PyObject* OssMultiVRSReader::getRecordInfo(
993993
string type = lowercaseTypeName(record.recordType);
994994
pyDict_SetItemWithDecRef(dic, pyObject("record_type"), pyObject(type));
995995
pyDict_SetItemWithDecRef(dic, pyObject("record_timestamp"), pyObject(record.timestamp));
996-
const std::string streamIdName = reader_.getUniqueStreamId(&record).getNumericName();
996+
UniqueStreamId uniqueStreamId = reader_.getUniqueStreamId(&record);
997+
const std::string streamIdName = uniqueStreamId.getNumericName();
997998
pyDict_SetItemWithDecRef(dic, pyObject("stream_id"), pyObject(streamIdName));
998999
pyDict_SetItemWithDecRef(dic, pyObject("recordable_id"), pyObject(streamIdName));
1000+
pyDict_SetItemWithDecRef(
1001+
dic, pyObject("serial_number"), pyObject(reader_.getSerialNumber(uniqueStreamId)));
9991002
return dic;
10001003
}
10011004

csrc/reader/MultiVRSReader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class OssMultiVRSReader : public VRSReaderBase {
265265
/// "record_timestamp": timestamp of the record.
266266
/// "stream_id": streamId of the record.
267267
/// "record_type": record type, either "configuration", "state" or "data".
268+
/// "serial_number": stream serial number.
268269
py::object getAllRecordsInfo();
269270

270271
/// Get basic record information for a number of records in the file.
@@ -275,6 +276,7 @@ class OssMultiVRSReader : public VRSReaderBase {
275276
/// "record_timestamp": timestamp of the record.
276277
/// "stream_id": streamId of the record.
277278
/// "record_type": record type, either "configuration", "state" or "data".
279+
/// "serial_number": stream serial number.
278280
py::object getRecordsInfo(int32_t firstIndex, int32_t count);
279281

280282
/// Get basic record information for all the read enabled streams' records.
@@ -283,6 +285,7 @@ class OssMultiVRSReader : public VRSReaderBase {
283285
/// "record_timestamp": timestamp of the record.
284286
/// "stream_id": streamId of the record.
285287
/// "record_type": record type, either "configuration", "state" or "data".
288+
/// "serial_number": stream serial number.
286289
py::object getEnabledStreamsRecordsInfo();
287290

288291
// ---------------
@@ -296,6 +299,7 @@ class OssMultiVRSReader : public VRSReaderBase {
296299
/// "record_timestamp": timestamp of the record.
297300
/// "stream_id": streamId of the record.
298301
/// "record_type": record type, either "configuration", "state" or "data".
302+
/// "serial_number": stream serial number.
299303
/// If there are no records for this index, throws an IndexError exception.
300304
py::object gotoRecord(int index);
301305

@@ -306,6 +310,7 @@ class OssMultiVRSReader : public VRSReaderBase {
306310
/// "record_timestamp": timestamp of the record.
307311
/// "stream_id": streamId of the record.
308312
/// "record_type": record type, either "configuration", "state" or "data".
313+
/// "serial_number": stream serial number.
309314
/// If there are no records at or after this timestamp, throws an IndexError exception.
310315
py::object gotoTime(double timestamp);
311316

@@ -356,6 +361,7 @@ class OssMultiVRSReader : public VRSReaderBase {
356361
/// "record_timestamp": timestamp of the record, as number of seconds (double).
357362
/// "stream_id": stream id of the stream the record was read from.
358363
/// "record_type": record type, either "configuration", "state" or "data".
364+
/// "serial_number": stream serial number.
359365
/// "metadata_count": number of metadata blocks read. Use getMetadata() to get them.
360366
/// "image_count": number of image blocks read. Use getImageXXX() to get them.
361367
/// "audio_block_count": number of audio blocks read. Use getAudioBlockXXX() to get them.

csrc/reader/VRSReader.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545

4646
namespace {
4747

48-
PyObject* getRecordInfo(const IndexRecord::RecordInfo& record, int32_t recordIndex) {
48+
PyObject* getRecordInfo(
49+
RecordFileReader& reader,
50+
const IndexRecord::RecordInfo& record,
51+
int32_t recordIndex) {
4952
PyObject* dic = PyDict_New();
5053
pyDict_SetItemWithDecRef(dic, pyObject("record_index"), pyObject(recordIndex));
5154
string type = lowercaseTypeName(record.recordType);
@@ -54,6 +57,10 @@ PyObject* getRecordInfo(const IndexRecord::RecordInfo& record, int32_t recordInd
5457
pyDict_SetItemWithDecRef(dic, pyObject("stream_id"), pyObject(record.streamId.getNumericName()));
5558
pyDict_SetItemWithDecRef(
5659
dic, pyObject("recordable_id"), pyObject(record.streamId.getNumericName()));
60+
pyDict_SetItemWithDecRef(
61+
dic, pyObject("recordable_id"), pyObject(record.streamId.getNumericName()));
62+
pyDict_SetItemWithDecRef(
63+
dic, pyObject("serial_number"), pyObject(reader.getSerialNumber(record.streamId)));
5764
return dic;
5865
}
5966

@@ -620,7 +627,7 @@ py::object OssVRSReader::getAllRecordsInfo() {
620627
PyObject* list = PyList_New(listSize);
621628
int32_t recordIndex = 0;
622629
for (const auto& record : index) {
623-
auto pyRecordInfo = getRecordInfo(record, recordIndex);
630+
auto pyRecordInfo = getRecordInfo(reader_, record, recordIndex);
624631
PyList_SetItem(list, recordIndex, pyRecordInfo);
625632
recordIndex++;
626633
}
@@ -640,7 +647,7 @@ py::object OssVRSReader::getRecordsInfo(int32_t firstIndex, int32_t count) {
640647
PyObject* list = PyList_New(last - first);
641648
int32_t recordIndex = 0;
642649
for (size_t sourceIndex = first; sourceIndex < last; ++sourceIndex, ++recordIndex) {
643-
auto pyRecordInfo = getRecordInfo(index[sourceIndex], sourceIndex);
650+
auto pyRecordInfo = getRecordInfo(reader_, index[sourceIndex], sourceIndex);
644651
PyList_SetItem(list, recordIndex, pyRecordInfo);
645652
}
646653
return pyWrap(list);
@@ -656,7 +663,7 @@ py::object OssVRSReader::getEnabledStreamsRecordsInfo() {
656663
int32_t recordIndex = 0;
657664
for (const auto& record : index) {
658665
if (enabledStreams_.find(record.streamId) != enabledStreams_.end()) {
659-
auto pyRecordInfo = getRecordInfo(record, recordIndex);
666+
auto pyRecordInfo = getRecordInfo(reader_, record, recordIndex);
660667
PyList_Append(list, pyRecordInfo);
661668
Py_DECREF(pyRecordInfo);
662669
}
@@ -686,7 +693,8 @@ py::object OssVRSReader::getNextRecordInfo(const char* errorMessage) {
686693
nextRecordIndex_ = static_cast<uint32_t>(index.size());
687694
throw py::index_error(errorMessage);
688695
}
689-
return pyWrap(getRecordInfo(index[nextRecordIndex_], static_cast<int32_t>(nextRecordIndex_)));
696+
return pyWrap(
697+
getRecordInfo(reader_, index[nextRecordIndex_], static_cast<int32_t>(nextRecordIndex_)));
690698
}
691699

692700
py::object OssVRSReader::readNextRecord() {

csrc/reader/VRSReader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ class OssVRSReader : public VRSReaderBase {
319319
/// "record_timestamp": timestamp of the record.
320320
/// "stream_id": streamId of the record.
321321
/// "record_type": record type, either "configuration", "state" or "data".
322+
/// "serial_number": stream serial number.
322323
py::object getAllRecordsInfo();
323324

324325
/// Get basic record information for a number of records in the file.
@@ -329,6 +330,7 @@ class OssVRSReader : public VRSReaderBase {
329330
/// "record_timestamp": timestamp of the record.
330331
/// "stream_id": streamId of the record.
331332
/// "record_type": record type, either "configuration", "state" or "data".
333+
/// "serial_number": stream serial number.
332334
py::object getRecordsInfo(int32_t firstIndex, int32_t count);
333335

334336
/// Get basic record information for all the read enabled streams' records.
@@ -337,6 +339,7 @@ class OssVRSReader : public VRSReaderBase {
337339
/// "record_timestamp": timestamp of the record.
338340
/// "stream_id": streamId of the record.
339341
/// "record_type": record type, either "configuration", "state" or "data".
342+
/// "serial_number": stream serial number.
340343
py::object getEnabledStreamsRecordsInfo();
341344

342345
// ---------------
@@ -350,6 +353,7 @@ class OssVRSReader : public VRSReaderBase {
350353
/// "record_timestamp": timestamp of the record.
351354
/// "stream_id": streamId of the record.
352355
/// "record_type": record type, either "configuration", "state" or "data".
356+
/// "serial_number": stream serial number.
353357
/// If there are no records for this index, throws an IndexError exception.
354358
py::object gotoRecord(int index);
355359

@@ -360,6 +364,7 @@ class OssVRSReader : public VRSReaderBase {
360364
/// "record_timestamp": timestamp of the record.
361365
/// "stream_id": streamId of the record.
362366
/// "record_type": record type, either "configuration", "state" or "data".
367+
/// "serial_number": stream serial number.
363368
/// If there are no records at or after this timestamp, throws an IndexError exception.
364369
py::object gotoTime(double timestamp);
365370

@@ -410,6 +415,7 @@ class OssVRSReader : public VRSReaderBase {
410415
/// "record_timestamp": timestamp of the record, as number of seconds (double).
411416
/// "stream_id": stream id of the stream the record was read from .
412417
/// "record_type": record type, either "configuration", "state" or "data".
418+
/// "serial_number": stream serial number.
413419
/// "metadata_count": number of metadata blocks read. Use getMetadata() to get them.
414420
/// "image_count": number of image blocks read. Use getImageXXX() to get them.
415421
/// "audio_block_count": number of audio blocks read. Use getAudioBlockXXX() to get them.

0 commit comments

Comments
 (0)