![]() |
VRS
A file format for sensor data.
|
Facilitates reading multiple VRS files simultaneously. Records are sorted by timestamps across all the files, therefore it is essential that *** all the files must have their timestamps in the same time domain. *** Operates in a manner similar to RecordFileReader
, but with multiple files.
More...
#include <MultiRecordFileReader.h>
Public Types | |
using | UniqueStreamId = StreamId |
Public Member Functions | |
MultiRecordFileReader (const MultiRecordFileReader &)=delete | |
MultiRecordFileReader & | operator= (const MultiRecordFileReader &)=delete |
int | open (const std::vector< std::string > &paths) |
int | open (const std::vector< FileSpec > &fileSpecs) |
int | open (const std::string &path) |
int | open (const FileSpec &fileSpec) |
int | close () |
const set< UniqueStreamId > & | getStreams () const |
bool | isOpened () const |
uint32_t | getRecordCount () const |
uint32_t | getRecordCount (UniqueStreamId uniqueStreamId) const |
uint32_t | getRecordCount (UniqueStreamId uniqueStreamId, Record::Type recordType) const |
const StreamTags & | getTags (UniqueStreamId uniqueStreamId) const |
const string & | getTag (const string &name) const |
const string & | getTag (UniqueStreamId uniqueStreamId, const string &name) const |
vector< std::pair< string, int64_t > > | getFileChunks () const |
const string & | getFlavor (UniqueStreamId uniqueStreamId) const |
const string & | getSerialNumber (UniqueStreamId uniqueStreamId) const |
vector< UniqueStreamId > | getStreams (RecordableTypeId typeId, const string &flavor={}) const |
UniqueStreamId | getStreamForName (const string &name) const |
UniqueStreamId | getStreamForTag (const string &tagName, const string &tag, RecordableTypeId typeId=RecordableTypeId::Undefined) const |
UniqueStreamId | getStreamForSerialNumber (const string &serialNumber) const |
bool | mightContainImages (UniqueStreamId uniqueStreamId) const |
bool | mightContainAudio (UniqueStreamId uniqueStreamId) const |
uint32_t | getRecordIndex (const IndexRecord::RecordInfo *record) const |
const IndexRecord::RecordInfo * | getRecord (uint32_t globalIndex) const |
uint32_t | getRecordSize (uint32_t globalIndex) const |
const IndexRecord::RecordInfo * | getRecord (UniqueStreamId streamId, uint32_t indexNumber) const |
const IndexRecord::RecordInfo * | getRecord (UniqueStreamId streamId, Record::Type recordType, uint32_t indexNumber) const |
const IndexRecord::RecordInfo * | getLastRecord (UniqueStreamId streamId, Record::Type recordType) const |
const vector< const IndexRecord::RecordInfo * > & | getIndex (UniqueStreamId streamId) const |
const string & | getOriginalRecordableTypeName (UniqueStreamId streamId) const |
void | setStreamPlayer (UniqueStreamId streamId, StreamPlayer *streamPlayer) |
uint32_t | getRecordFormats (UniqueStreamId streamId, RecordFormatMap &outFormats) const |
int | readRecord (const IndexRecord::RecordInfo &recordInfo) |
int | readRecord (const IndexRecord::RecordInfo &recordInfo, StreamPlayer *player, bool setupPlayer) |
bool | setCachingStrategy (CachingStrategy cachingStrategy) |
CachingStrategy | getCachingStrategy () const |
bool | prefetchRecordSequence (const vector< const IndexRecord::RecordInfo * > &records, bool clearSequence=true) |
bool | isRecordAvailableOrPrefetch (const IndexRecord::RecordInfo &record) const |
bool | purgeFileCache () |
const map< string, string > & | getTags () const |
const IndexRecord::RecordInfo * | getFirstRecord (Record::Type recordType) const |
const IndexRecord::RecordInfo * | getLastRecord (Record::Type recordType) const |
const IndexRecord::RecordInfo * | getRecordByTime (double timestamp) const |
const IndexRecord::RecordInfo * | getRecordByTime (UniqueStreamId streamId, double timestamp) const |
const IndexRecord::RecordInfo * | getRecordByTime (StreamId streamId, Record::Type recordType, double timestamp) const |
const IndexRecord::RecordInfo * | getNearestRecordByTime (double timestamp, double epsilon, StreamId streamId={}, Record::Type recordType=Record::Type::UNDEFINED) const |
std::unique_ptr< FileHandler > | getFileHandler () const |
UniqueStreamId | getUniqueStreamId (const IndexRecord::RecordInfo *record) const |
int64_t | getTotalSourceSize () const |
bool | readFirstConfigurationRecord (UniqueStreamId uniqueStreamId, StreamPlayer *streamPlayer=nullptr) |
bool | readFirstConfigurationRecords (StreamPlayer *streamPlayer=nullptr) |
bool | readFirstConfigurationRecordsForType (RecordableTypeId typeId, StreamPlayer *streamPlayer=nullptr) |
const std::vector< unique_ptr< RecordFileReader > > & | getReaders () const |
Get the list of RecordFileReader objects used to read all the streams. | |
Static Public Attributes | |
static const string | kRelatedFileTags [] |
Facilitates reading multiple VRS files simultaneously. Records are sorted by timestamps across all the files, therefore it is essential that *** all the files must have their timestamps in the same time domain. *** Operates in a manner similar to RecordFileReader
, but with multiple files.
int vrs::MultiRecordFileReader::close | ( | ) |
Close the underlying files, if any are open.
CachingStrategy vrs::MultiRecordFileReader::getCachingStrategy | ( | ) | const |
Get Caching strategy for all the underlying file handlers. The same strategy is supposed to be used by all file handlers.
vector< pair< string, int64_t > > vrs::MultiRecordFileReader::getFileChunks | ( | ) | const |
Get a list of the constituent paths + sizes (in bytes) across all files. When no file is open, an empty vector is returned. When a single file is open, the underlying chunks with their sizes are returned. When multiple files are open, file paths and their sizes are returned.
unique_ptr< FileHandler > vrs::MultiRecordFileReader::getFileHandler | ( | ) | const |
Get a clone of the current file handler, for use elsewhere.
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getFirstRecord | ( | Record::Type | recordType | ) | const |
Get the record with smallest timestamp across all streams and files, of a specified record type.
recordType | Type of record to look for. |
const string & vrs::MultiRecordFileReader::getFlavor | ( | UniqueStreamId | uniqueStreamId | ) | const |
Streams using << Recordable Class >> ids require a << flavor >>, which must be provided when the stream was created. Use this API to get the recordable flavor provided, if any, when the stream was created.
uniqueStreamId | StreamId of the record stream to consider. |
const vector< const IndexRecord::RecordInfo * > & vrs::MultiRecordFileReader::getIndex | ( | UniqueStreamId | streamId | ) | const |
Get a record index limited to a specific stream.
streamId | UniqueStreamId of the record stream to consider. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getLastRecord | ( | Record::Type | recordType | ) | const |
Get the record with largest timestamp across all streams and files, of a specified record type.
recordType | Type of record to look for. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getLastRecord | ( | UniqueStreamId | streamId, |
Record::Type | recordType | ||
) | const |
Find the last record for a specific stream and specific type.
streamId | UniqueStreamId of the record stream to consider. |
recordType | Type of the records to consider. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getNearestRecordByTime | ( | double | timestamp, |
double | epsilon, | ||
StreamId | streamId = {} , |
||
Record::Type | recordType = Record::Type::UNDEFINED |
||
) | const |
Find the nearest record of a specific stream within the range of (timestamp - epsilon) - (timestamp + epsilon).
timestamp | timestamp to seek. |
epsilon | the threshold we search for the index. |
streamId | StreamId of the stream to consider. Leave undefined to search all streams |
recordType | record type to find, or Record::Type::UNDEFINED for any record type. |
|
inline |
RecordableTypeId text descriptions may change over time, so at the time of recording, we capture the text name, so that we can see what it was when the file was recorded.
streamId | UniqueStreamId of the record stream to consider. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getRecord | ( | uint32_t | globalIndex | ) | const |
Get the record corresponding to the given index position in the global index.
globalIndex | Position in the global index to look up. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getRecord | ( | UniqueStreamId | streamId, |
Record::Type | recordType, | ||
uint32_t | indexNumber | ||
) | const |
Find a specific record for a specific stream and type, by index number. nullptr is returned if no record is found for that index number.
streamId | UniqueStreamId of the record stream to consider. |
recordType | Type of the records to consider. |
indexNumber | Index of the record to look for. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getRecord | ( | UniqueStreamId | streamId, |
uint32_t | indexNumber | ||
) | const |
Find a specific record for a specific stream, regardless of type, by index number.
streamId | UniqueStreamId of the record stream to consider. |
indexNumber | Index position (for streamId - not global index) of the record to look for. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getRecordByTime | ( | double | timestamp | ) | const |
Find the first record at or after a timestamp.
timestamp | timestamp to seek. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getRecordByTime | ( | StreamId | streamId, |
Record::Type | recordType, | ||
double | timestamp | ||
) | const |
Find the first record of a specific stream of a specific type at or after a timestamp.
streamId | StreamId of the stream to consider. |
recordType | record type to find. |
timestamp | timestamp to seek. |
const IndexRecord::RecordInfo * vrs::MultiRecordFileReader::getRecordByTime | ( | UniqueStreamId | streamId, |
double | timestamp | ||
) | const |
Find the first record of a specific stream at or after a timestamp.
streamId | UniqueStreamId of the stream to consider. |
timestamp | timestamp to seek. |
uint32_t vrs::MultiRecordFileReader::getRecordCount | ( | ) | const |
Get the number of records across all open files.
uint32_t vrs::MultiRecordFileReader::getRecordCount | ( | UniqueStreamId | uniqueStreamId | ) | const |
Get the number of records of a specific stream.
uniqueStreamId | StreamId of the record stream to consider. |
uint32_t vrs::MultiRecordFileReader::getRecordCount | ( | UniqueStreamId | uniqueStreamId, |
Record::Type | recordType | ||
) | const |
Get the number of records for a specific stream and specific record type. Attention: this computation has a linear complexity, so cache the result!
uniqueStreamId | StreamId of the record stream to consider. |
recordType | Type of records to count. |
uint32_t vrs::MultiRecordFileReader::getRecordFormats | ( | UniqueStreamId | streamId, |
RecordFormatMap & | outFormats | ||
) | const |
Get all the RecordFormat description used in this VRS file. Mostly useful for tools like VRStool & VRSplayer.
streamId | UniqueStreamId of the record stream to consider. |
outFormats | Reference to be set. |
uint32_t vrs::MultiRecordFileReader::getRecordIndex | ( | const IndexRecord::RecordInfo * | record | ) | const |
Get a record's index in the global index, which is ordered by timestamp across all open files.
record | Pointer of the record. |
uint32_t vrs::MultiRecordFileReader::getRecordSize | ( | uint32_t | globalIndex | ) | const |
Get a record's size in the global index.
globalIndex | Position in the global index to look up. |
const string & vrs::MultiRecordFileReader::getSerialNumber | ( | UniqueStreamId | uniqueStreamId | ) | const |
Get a stream's serial number.
uniqueStreamId | StreamId of the record stream to consider. |
MultiRecordFileReader::UniqueStreamId vrs::MultiRecordFileReader::getStreamForName | ( | const string & | name | ) | const |
Find a stream from an absolute or relative numeric name. Absolute numeric names are in the form <numeric_recordable_type_id>-<instance_id>, eg 1201-1 Relative numeric names are in the form <numeric_recordable_type_id>+<instance_id>, eg 1201+1 Relative numeric names have instance ids interpreted as the nth stream of that type, eg 1201+3 is the 3rd stream with the recordable type id 1201 (if there is such a stream). In all cases, use isValid() to verify that the stream was found in the file.
name | an absolute or relative numeric name |
UniqueStreamId vrs::MultiRecordFileReader::getStreamForSerialNumber | ( | const string & | serialNumber | ) | const |
Find the stream with the given serial number.
serialNumber | the serial number to look for. |
UniqueStreamId vrs::MultiRecordFileReader::getStreamForTag | ( | const string & | tagName, |
const string & | tag, | ||
RecordableTypeId | typeId = RecordableTypeId::Undefined |
||
) | const |
Find the first stream with given tag name + value pair and RecordableTypeId
tagName | The name of the tag to look for. |
tag | The tag value to look for. |
typeId | The RecordableTypeId to limit the search to, or RecordableTypeId::Undefined to look for any device type. Note: if more than one streams match the criteria, the "first" one is returned, which means the one with the lowest RecordableTypeId enum value, or if equal, the one with the lowest UniqueStreamId instanceId. |
const set< UniqueStreamId > & vrs::MultiRecordFileReader::getStreams | ( | ) | const |
vector< UniqueStreamId > vrs::MultiRecordFileReader::getStreams | ( | RecordableTypeId | typeId, |
const string & | flavor = {} |
||
) | const |
Get a set of StreamId for a specific type, and an optional flavor.
typeId | a recordable type id, maybe a Recordable Class. Use RecordableTypeId::Undefined to match any recordable type. |
flavor | an option flavor. |
|
inline |
Get a specific file tag by name. (Not to be confused with stream tags) If multiple files are opened and they have multiple values for the same tag name, one of the values is returned arbitrarily.
name | Name of the tag to look for. |
|
inline |
Get a specific tag for a specific record stream.
uniqueStreamId | StreamId of the record stream to consider. |
name | Name of the tag to look for. |
|
inline |
Get the tags map for all the underlying files. Does not include any stream tags.
const StreamTags & vrs::MultiRecordFileReader::getTags | ( | UniqueStreamId | uniqueStreamId | ) | const |
Get the tags for a specific record stream.
uniqueStreamId | StreamId of the record stream to consider. |
int64_t vrs::MultiRecordFileReader::getTotalSourceSize | ( | ) | const |
Get the total size of all underlying files.
UniqueStreamId vrs::MultiRecordFileReader::getUniqueStreamId | ( | const IndexRecord::RecordInfo * | record | ) | const |
Get UniqueStreamId corresponding to the given record. This must be used as opposed to reading the StreamId from RecordInfo directly since it handles StreamId collisions between streams from multiple files.
record | Record whose UniqueStreamId is supposed to be determined |
|
inline |
Tell if files are being read. Must be true for most operations.
bool vrs::MultiRecordFileReader::isRecordAvailableOrPrefetch | ( | const IndexRecord::RecordInfo & | record | ) | const |
Check if a file record is available for immediate loading (e.g. on disk or in-cache). If not, begin background prefetching at the requested frame (but do not wait for results).
recordInfo | RecordInfo reference of the record to read. |
bool vrs::MultiRecordFileReader::mightContainAudio | ( | UniqueStreamId | uniqueStreamId | ) | const |
Tell if a stream might contain some audio data (and probably will). This is a best guess effort, but it is still possible that no audio will actually be found!
streamId | StreamId of the record stream to check. |
bool vrs::MultiRecordFileReader::mightContainImages | ( | UniqueStreamId | uniqueStreamId | ) | const |
Tell if a stream might contain at least one image (and probably will). This is a best guess effort, but it is still possible that no images are actually found!
streamId | StreamId of the record stream to check. |
|
inline |
Open a single VRS file. This method is expected to be invoked only once per instance.
fileSpec | VRS fileSpec to open. |
|
inline |
Open a single VRS file. This method is expected to be invoked only once per instance.
path | VRS file path to open. |
int vrs::MultiRecordFileReader::open | ( | const std::vector< FileSpec > & | fileSpecs | ) |
Open the given VRS files. Only related files are allowed to be opened together. i.e. the files which have the same values for tags defined in kRelatedFileTags
. If these tags are present, then the values must match. All the files must have their timestamps in the same time domain. This method is expected to be invoked only once per instance.
fileSpecs | VRS file specs to open. |
int vrs::MultiRecordFileReader::open | ( | const std::vector< std::string > & | paths | ) |
Open the given VRS files. Only related files are allowed to be opened together. i.e. the files which have the same values for tags defined in kRelatedFileTags
. If these tags are present, then the values must match. All the files must have their timestamps in the same time domain. This method is expected to be invoked only once per instance.
paths | VRS file paths to open. |
bool vrs::MultiRecordFileReader::prefetchRecordSequence | ( | const vector< const IndexRecord::RecordInfo * > & | records, |
bool | clearSequence = true |
||
) |
When streaming VRS files from the cloud, it may be very beneficial to tell before hand which records will be read, in order, so that the data can be prefetched optimally. Note the only some FileHandlers implement this, others will just ignore the request, which is always safe to make.
records | a sequence of records in the exact order they will be read. It's ok to skip one or more records, but:
|
clearSequence | Flag on whether to cancel any pre-existing custom read sequence upon caching starts. |
bool vrs::MultiRecordFileReader::purgeFileCache | ( | ) |
If the underlying file handler caches data on reads, purge its caches to free memory. Sets the caching strategy to Passive, and clears any pending read sequence.
bool vrs::MultiRecordFileReader::readFirstConfigurationRecord | ( | UniqueStreamId | uniqueStreamId, |
StreamPlayer * | streamPlayer = nullptr |
||
) |
Helper function: Read the first configuration record of a particular stream. This might be necessary to properly read records containing image or audio blocks, if their configuration is contained in the configuration record using datalayout conventions. Notes:
uniqueStreamId | UniqueStreamId of the record stream to consider. |
streamPlayer | (optional): provide a streamPlayer that will receive the records. If provided, and a stream player is already registered to receive records for that stream, the provided stream player will get the data, and the registered stream player will not get anything. |
bool vrs::MultiRecordFileReader::readFirstConfigurationRecords | ( | StreamPlayer * | streamPlayer = nullptr | ) |
Helper function: Read the first configuration record of all the streams. This might be necessary to properly read records containing image or audio blocks, if their configuration is contained in the configuration record using datalayout conventions. Notes:
streamPlayer | (optional): provide a stream player that will receive the records. If provided, and a stream player is already registered to receive records for that stream, the provided stream player will get the data, and the registered stream player will not get anything. |
bool vrs::MultiRecordFileReader::readFirstConfigurationRecordsForType | ( | RecordableTypeId | typeId, |
StreamPlayer * | streamPlayer = nullptr |
||
) |
Helper function: Read the first configuration record for all the streams of a particular recordable type. See readFirstConfigurationRecord() for limitations.
typeId | The RecordableTypeId of the type of device to look for. |
streamPlayer | (optional): provide a stream player that will receive the records. If provided, and a stream player is already registered to receive records for that stream, the provided stream player will get the data, and the registered stream player will not get anything. |
int vrs::MultiRecordFileReader::readRecord | ( | const IndexRecord::RecordInfo & | recordInfo | ) |
Preferred way to read records.
recordInfo | RecordInfo reference of the record to read. |
int vrs::MultiRecordFileReader::readRecord | ( | const IndexRecord::RecordInfo & | recordInfo, |
StreamPlayer * | player, | ||
bool | setupPlayer | ||
) |
Read a record with a specific stream player. Attention! Unlike the RecordFileReader version of this API, do not read different streams with the same stream player, or you might get unexpected results. Stream players should not be used with different RecordFileReader objects, which this class might do.
recordInfo | RecordInfo reference of the record to read. |
setupPlayer | tell if the player should be initialized through its onAttachedToFileReader callback. This must happen at least once per player, the first time around. This operation can be expensive, so this should be done only once. |
bool vrs::MultiRecordFileReader::setCachingStrategy | ( | CachingStrategy | cachingStrategy | ) |
Set Caching strategy for all the underlying file handlers. This should be called after opening the files, as open might replace the file handler.
cachingStrategy | Caching strategy desired. |
void vrs::MultiRecordFileReader::setStreamPlayer | ( | UniqueStreamId | streamId, |
StreamPlayer * | streamPlayer | ||
) |
Hook a stream player to a specific stream after opening a file and before reading records. The file player does not take ownership of the StreamPlayer. Using the same StreamPlayer instance for multiple streams is supported. So the caller is responsible for deleting the StreamPlayer objects after the file is read. Disconnect the StreamPlayer by passing a nullptr for the stream id.
streamId | UniqueStreamId to hook the stream player to. |
streamPlayer | StreamPlayer to attach. |
|
inlinestatic |
Tags which determine whether VRS files are related to each other. Related files are expected to have the same value for these tags.