VRS
A file format for sensor data.
Loading...
Searching...
No Matches
ContentBlockReader.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 <memory>
20
21#include <vrs/DataLayout.h>
22#include <vrs/DataLayoutConventions.h>
23#include <vrs/StreamPlayer.h>
24#include <vrs/VrsExport.h>
25
26namespace vrs {
27
28using std::unique_ptr;
29
30class ContentBlock;
31class RecordFormatStreamPlayer;
32struct RecordFormatReader;
33
40class VRS_API ContentBlockReader {
41 public:
48 static unique_ptr<ContentBlockReader>
49 build(const RecordFormat& recordFormat, size_t blockIndex, unique_ptr<DataLayout>&& blockLayout);
50
53
58
59 protected:
60 ContentBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
61 : recordFormat_(recordFormat), blockIndex_(blockIndex) {}
62 bool findNextContentBlockSpec(const CurrentRecord& record, RecordFormatStreamPlayer& player);
63 size_t findContentBlockSize(const CurrentRecord& record, RecordFormatStreamPlayer& player);
64 uint32_t findAudioSampleCount(const CurrentRecord& record, RecordFormatStreamPlayer& player);
65
66 const RecordFormat& recordFormat_;
67 const size_t blockIndex_;
68 unique_ptr<datalayout_conventions::NextContentBlockSpec> contentBlockSpec_;
69};
70
73class VRS_API ImageBlockReader : public ContentBlockReader {
74 public:
75 ImageBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
76 : ContentBlockReader(recordFormat, blockIndex) {}
77
78 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
79
80 protected:
81 bool
82 onImageFound(const CurrentRecord& rec, RecordFormatStreamPlayer& player, const ContentBlock& cb);
83
85 unique_ptr<datalayout_conventions::VideoFrameSpec> videoFrameSpec_;
86};
87
90class VRS_API AudioBlockReader : public ContentBlockReader {
91 public:
92 AudioBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
93 : ContentBlockReader(recordFormat, blockIndex) {}
94
95 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
96
97 protected:
98 bool readAudioContentBlock(const CurrentRecord&, RecordFormatStreamPlayer&, const ContentBlock&);
99 bool findAudioSpec(
100 const CurrentRecord&,
103 size_t indexUpperLimit,
104 size_t lastIndexToCheck,
105 bool& readNextBlock);
106 bool audioContentFromAudioSpec(
107 const CurrentRecord&,
109 ContentBlock& outAudioContentBlock);
110 bool tryCurrentAudioSpec(const CurrentRecord&, RecordFormatStreamPlayer&, bool& readNextBlock);
111
113};
114
118class VRS_API CustomBlockReader : public ContentBlockReader {
119 public:
120 CustomBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
121 : ContentBlockReader(recordFormat, blockIndex) {}
122
123 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
124};
125
130 public:
131 UnsupportedBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
132 : ContentBlockReader(recordFormat, blockIndex) {}
133
134 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
135};
136
142class VRS_API EmptyBlockReader : public ContentBlockReader {
143 public:
144 EmptyBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
145 : ContentBlockReader(recordFormat, blockIndex) {}
146
147 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
148};
149
153 public:
155 const RecordFormat& recordFormat,
156 size_t blockIndex,
157 unique_ptr<DataLayout>&& blockLayout)
158 : ContentBlockReader(recordFormat, blockIndex), blockLayout_{std::move(blockLayout)} {}
159
160 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
161
165 bool mapToBlockLayout(DataLayout& desiredLayout) {
166 if (blockLayout_) {
167 desiredLayout.mapLayout(*blockLayout_);
168 return true;
169 }
170 return false;
171 }
172
173 private:
174 unique_ptr<DataLayout> blockLayout_;
175};
176
177} // namespace vrs
Specialized version of ContentBlockReader to handle content blocks containing audio data.
Definition ContentBlockReader.h:90
Specification of a VRS record content block.
Definition RecordFormat.h:512
Abstract class to handle the interpretation of a record format's content block.
Definition ContentBlockReader.h:40
virtual ~ContentBlockReader()
Virtual destructor, since this is an abstract class.
virtual bool readBlock(const CurrentRecord &, RecordFormatStreamPlayer &)=0
Specialized version of ContentBlockReader to handle a content block containing custom data....
Definition ContentBlockReader.h:118
Specialized version of ContentBlockReader to handle DataLayout blocks.
Definition ContentBlockReader.h:152
bool mapToBlockLayout(DataLayout &desiredLayout)
Definition ContentBlockReader.h:165
The DataLayout class describes the data stored inside a DataLayoutContentBlock.
Definition DataLayout.h:211
bool mapLayout(DataLayout &targetLayout)
Definition DataLayout.cpp:130
Specialized version of ContentBlockReader to handle an empty content block.
Definition ContentBlockReader.h:142
Specialized version of ContentBlockReader to handle content blocks containing an image.
Definition ContentBlockReader.h:73
Description of the format of a VRS record as a succession of typed blocks of content.
Definition RecordFormat.h:688
Specialized StreamPlayer designed to handle records which format is managed by RecordFormat,...
Definition RecordFormatStreamPlayer.h:65
Specialized version of ContentBlockReader to handle data that could not be handled by another better ...
Definition ContentBlockReader.h:129
DataLayout definitions use to describe what's in an audio content block.
Definition DataLayoutConventions.h:145
DataLayout definitions use to describe what's in an image content block.
Definition DataLayoutConventions.h:65
Definition Compressor.cpp:113
Class describing which record is being read. Most fields are really self explanatory.
Definition StreamPlayer.h:28
Internal data structure to hold various objects needed to decode a specific RecordFormat.
Definition RecordFormatStreamPlayer.h:49