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 "DataLayout.h"
22#include "DataLayoutConventions.h"
23#include "StreamPlayer.h"
24
25namespace vrs {
26
27using std::unique_ptr;
28
29class ContentBlock;
30class RecordFormatStreamPlayer;
31struct RecordFormatReader;
32
40 public:
47 static unique_ptr<ContentBlockReader>
48 build(const RecordFormat& recordFormat, size_t blockIndex, unique_ptr<DataLayout>&& blockLayout);
49
52
57
58 protected:
59 ContentBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
60 : recordFormat_(recordFormat), blockIndex_(blockIndex) {}
61 bool findNextContentBlockSpec(const CurrentRecord& record, RecordFormatStreamPlayer& player);
62 size_t findContentBlockSize(const CurrentRecord& record, RecordFormatStreamPlayer& player);
63 uint32_t findAudioSampleCount(const CurrentRecord& record, RecordFormatStreamPlayer& player);
64
65 const RecordFormat& recordFormat_;
66 const size_t blockIndex_;
67 unique_ptr<datalayout_conventions::NextContentBlockSpec> contentBlockSpec_;
68};
69
73 public:
74 ImageBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
75 : ContentBlockReader(recordFormat, blockIndex) {}
76
77 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
78
79 protected:
80 bool
81 onImageFound(const CurrentRecord& rec, RecordFormatStreamPlayer& player, const ContentBlock& cb);
82
84 unique_ptr<datalayout_conventions::VideoFrameSpec> videoFrameSpec_;
85};
86
90 public:
91 AudioBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
92 : ContentBlockReader(recordFormat, blockIndex) {}
93
94 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
95
96 protected:
97 bool readAudioContentBlock(const CurrentRecord&, RecordFormatStreamPlayer&, const ContentBlock&);
98 bool findAudioSpec(
99 const CurrentRecord&,
102 size_t indexUpperLimit,
103 size_t lastIndexToCheck,
104 bool& readNextBlock);
105 bool audioContentFromAudioSpec(
106 const CurrentRecord&,
108 ContentBlock& outAudioContentBlock);
109 bool tryCurrentAudioSpec(const CurrentRecord&, RecordFormatStreamPlayer&, bool& readNextBlock);
110
112};
113
118 public:
119 CustomBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
120 : ContentBlockReader(recordFormat, blockIndex) {}
121
122 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
123};
124
129 public:
130 UnsupportedBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
131 : ContentBlockReader(recordFormat, blockIndex) {}
132
133 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
134};
135
142 public:
143 EmptyBlockReader(const RecordFormat& recordFormat, size_t blockIndex)
144 : ContentBlockReader(recordFormat, blockIndex) {}
145
146 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
147};
148
152 public:
154 const RecordFormat& recordFormat,
155 size_t blockIndex,
156 unique_ptr<DataLayout>&& blockLayout)
157 : ContentBlockReader(recordFormat, blockIndex), blockLayout_{std::move(blockLayout)} {}
158
159 bool readBlock(const CurrentRecord&, RecordFormatStreamPlayer&) override;
160
164 bool mapToBlockLayout(DataLayout& desiredLayout) {
165 if (blockLayout_) {
166 desiredLayout.mapLayout(*blockLayout_);
167 return true;
168 }
169 return false;
170 }
171
172 private:
173 unique_ptr<DataLayout> blockLayout_;
174};
175
176} // namespace vrs
Specialized version of ContentBlockReader to handle content blocks containing audio data.
Definition ContentBlockReader.h:89
bool readBlock(const CurrentRecord &, RecordFormatStreamPlayer &) override
Definition ContentBlockReader.cpp:204
Specification of a VRS record content block.
Definition RecordFormat.h:474
Abstract class to handle the interpretation of a record format's content block.
Definition ContentBlockReader.h:39
virtual ~ContentBlockReader()
Virtual destructor, since this is an abstract class.
virtual bool readBlock(const CurrentRecord &, RecordFormatStreamPlayer &)=0
static unique_ptr< ContentBlockReader > build(const RecordFormat &recordFormat, size_t blockIndex, unique_ptr< DataLayout > &&blockLayout)
Definition ContentBlockReader.cpp:87
Specialized version of ContentBlockReader to handle a content block containing custom data....
Definition ContentBlockReader.h:117
bool readBlock(const CurrentRecord &, RecordFormatStreamPlayer &) override
Definition ContentBlockReader.cpp:408
Specialized version of ContentBlockReader to handle DataLayout blocks.
Definition ContentBlockReader.h:151
bool mapToBlockLayout(DataLayout &desiredLayout)
Definition ContentBlockReader.h:164
bool readBlock(const CurrentRecord &, RecordFormatStreamPlayer &) override
Definition ContentBlockReader.cpp:430
The DataLayout class describes the data stored inside a DataLayoutContentBlock.
Definition DataLayout.h:191
bool mapLayout(DataLayout &targetLayout)
Definition DataLayout.cpp:126
Specialized version of ContentBlockReader to handle an empty content block.
Definition ContentBlockReader.h:141
bool readBlock(const CurrentRecord &, RecordFormatStreamPlayer &) override
Definition ContentBlockReader.cpp:472
Specialized version of ContentBlockReader to handle content blocks containing an image.
Definition ContentBlockReader.h:72
bool readBlock(const CurrentRecord &, RecordFormatStreamPlayer &) override
Definition ContentBlockReader.cpp:322
Description of the format of a VRS record as a succession of typed blocks of content.
Definition RecordFormat.h:644
Specialized StreamPlayer designed to handle records which format is managed by RecordFormat,...
Definition RecordFormatStreamPlayer.h:63
Specialized version of ContentBlockReader to handle data that could not be handled by another better ...
Definition ContentBlockReader.h:128
bool readBlock(const CurrentRecord &, RecordFormatStreamPlayer &) override
Definition ContentBlockReader.cpp:423
DataLayout definitions use to describe what's in an audio content block.
Definition DataLayoutConventions.h:137
DataLayout definitions use to describe what's in an image content block.
Definition DataLayoutConventions.h:63
Definition AsyncDiskFileChunk.hpp:49
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:47