VRS
A file format for sensor data.
Loading...
Searching...
No Matches
RecordFormatStreamPlayer.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <limits>
20#include <map>
21#include <tuple>
22
23#include <vrs/ContentBlockReader.h>
24#include <vrs/DataLayout.h>
25#include <vrs/RecordFormat.h>
26#include <vrs/StreamPlayer.h>
27#include <vrs/os/UndoWindows.h>
28
29namespace vrs {
30
31using std::map;
32using std::pair;
33using std::string;
34using std::tuple;
35using std::unique_ptr;
36using std::vector;
37
38class DataLayoutBlockReader;
39class ImageBlockReader;
40class AudioBlockReader;
41
42namespace datalayout_conventions {
43class VideoFrameSpec;
44}
45
49 double lastReadRecordTimestamp = std::numeric_limits<double>::max();
50 RecordFormat recordFormat;
51 vector<unique_ptr<ContentBlockReader>> contentReaders;
52 vector<unique_ptr<DataLayout>> expectedDataLayouts;
53 vector<unique_ptr<DataLayout>> legacyDataLayouts;
54};
55
65 public:
74 virtual bool
75 onDataLayoutRead(const CurrentRecord& /* record */, size_t /* blockIndex */, DataLayout&) {
76 return true; // we can go read the next block, if any, since we've read the data
77 }
78
94 virtual bool onImageRead(const CurrentRecord& record, size_t blockIndex, const ContentBlock& cb) {
95 return onUnsupportedBlock(record, blockIndex, cb);
96 }
97
107 virtual bool onAudioRead(const CurrentRecord& record, size_t blockIndex, const ContentBlock& cb) {
108 return onUnsupportedBlock(record, blockIndex, cb);
109 }
110
120 virtual bool onCustomBlockRead(const CurrentRecord& rec, size_t blkIdx, const ContentBlock& cb) {
121 return onUnsupportedBlock(rec, blkIdx, cb);
122 }
123
132 virtual bool onUnsupportedBlock(const CurrentRecord& rec, size_t blkIdx, const ContentBlock& cb);
133
140 void onAttachedToFileReader(RecordFileReader& recordFileReader, StreamId streamId) override;
141
144 bool processRecordHeader(const CurrentRecord& record, DataReference& outDataReference) override;
147 void processRecord(const CurrentRecord& record, uint32_t readSize) override;
148
152
156 return currentReader_;
157 }
158
159 protected:
160 // Helper class, to be used exclusively during onXXXRead() callbacks,
161 // to get the wished for DataLayout
162 template <class T>
163 inline T& getExpectedLayout(DataLayout& layout, size_t blockIndex) {
164 return getCachedLayout<T>(currentReader_->expectedDataLayouts, layout, blockIndex);
165 }
166 // Helper class, to be used exclusively during onXXXRead() callbacks,
167 // to get legacy fields no longer present in the official layout, for backward compatibility needs
168 template <class T>
169 inline T& getLegacyLayout(DataLayout& layout, size_t blockIndex) {
170 return getCachedLayout<T>(currentReader_->legacyDataLayouts, layout, blockIndex);
171 }
172 template <class T>
173 T& getCachedLayout(
174 vector<unique_ptr<DataLayout>>& layoutCache,
175 DataLayout& layout,
176 size_t blockIndex) {
177 if (layoutCache.size() <= blockIndex) {
178 layoutCache.resize(blockIndex + 1);
179 }
180 if (!layoutCache[blockIndex]) {
181 T* expectedLayout = new T;
182 layoutCache[blockIndex].reset(expectedLayout);
183 expectedLayout->mapLayout(layout);
184 }
185 return reinterpret_cast<T&>(*layoutCache[blockIndex].get());
186 }
187
188 RecordFileReader* recordFileReader_{};
189
190 // Keep the readers all separate,
191 // in case the same RecordFormatStreamPlayer is handling multiple streams.
192 map<tuple<StreamId, Record::Type, uint32_t>, RecordFormatReader> readers_;
193 map<pair<StreamId, Record::Type>, RecordFormatReader*> lastReader_;
194 RecordFormatReader* currentReader_{};
195};
196
197} // namespace vrs
Specification of a VRS record content block.
Definition RecordFormat.h:509
The DataLayout class describes the data stored inside a DataLayoutContentBlock.
Definition DataLayout.h:209
Container of data pointers, to tell where to write data when reading a record.
Definition DataReference.h:59
The class to read VRS files.
Definition RecordFileReader.h:75
Description of the format of a VRS record as a succession of typed blocks of content.
Definition RecordFormat.h:685
Specialized StreamPlayer designed to handle records which format is managed by RecordFormat,...
Definition RecordFormatStreamPlayer.h:64
virtual bool onImageRead(const CurrentRecord &record, size_t blockIndex, const ContentBlock &cb)
Definition RecordFormatStreamPlayer.h:94
virtual bool onUnsupportedBlock(const CurrentRecord &rec, size_t blkIdx, const ContentBlock &cb)
Definition RecordFormatStreamPlayer.cpp:28
virtual bool onCustomBlockRead(const CurrentRecord &rec, size_t blkIdx, const ContentBlock &cb)
Definition RecordFormatStreamPlayer.h:120
void onAttachedToFileReader(RecordFileReader &recordFileReader, StreamId streamId) override
Definition RecordFormatStreamPlayer.cpp:42
virtual bool onDataLayoutRead(const CurrentRecord &, size_t, DataLayout &)
Definition RecordFormatStreamPlayer.h:75
RecordFormatReader * getLastRecordFormatReader(StreamId id, Record::Type recordType) const
Definition RecordFormatStreamPlayer.cpp:123
virtual bool onAudioRead(const CurrentRecord &record, size_t blockIndex, const ContentBlock &cb)
Definition RecordFormatStreamPlayer.h:107
void processRecord(const CurrentRecord &record, uint32_t readSize) override
Definition RecordFormatStreamPlayer.cpp:80
RecordFormatReader * getCurrentRecordFormatReader() const
Definition RecordFormatStreamPlayer.h:155
bool processRecordHeader(const CurrentRecord &record, DataReference &outDataReference) override
Definition RecordFormatStreamPlayer.cpp:57
Type
Definition Record.h:90
VRS stream identifier class.
Definition StreamId.h:249
Class designed to receive record data when reading a VRS file.
Definition StreamPlayer.h:53
Definition Compressor.cpp:113
Class describing which record is being read. Most fields are really self explanatory.
Definition StreamPlayer.h:27
Internal data structure to hold various objects needed to decode a specific RecordFormat.
Definition RecordFormatStreamPlayer.h:48