VRS
A file format for sensor data.
Loading...
Searching...
No Matches
FileFormat.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 "Record.h"
20
25
26namespace vrs {
27
56namespace FileFormat {
57#pragma pack(push, 1)
58
60struct FileHeader {
61 uint32_t magicHeader1{};
62 uint32_t magicHeader2{};
63 uint64_t creationId{};
64 uint32_t fileHeaderSize{};
65 uint32_t recordHeaderSize{};
68 int64_t
71 uint64_t future2{};
72 uint64_t future3{};
73 uint64_t future4{};
74 uint32_t magicHeader3{};
75 uint32_t fileFormatVersion{};
76
78 void init();
80 void init(uint32_t magic1, uint32_t magic2, uint32_t magic3, uint32_t formatVersion);
83 bool looksLikeAVRSFile() const;
86 bool looksLikeOurFiles(uint32_t magic1, uint32_t magic2, uint32_t magic3) const;
89 bool isFormatSupported() const;
103 int64_t getEndOfUserRecordsOffset(int64_t fileSize) const;
104};
105
106// Re-interpret legacy recordable Type id
107RecordableTypeId readRecordableTypeId(int32_t recordableTypeId);
108
112 RecordHeader();
115 StreamId streamId,
116 double timestamp,
117 uint32_t formatVersion,
119 uint32_t previousRecordSize,
120 uint32_t recordSize,
121 uint32_t uncompressedSize);
122 uint32_t recordSize{};
125 uint32_t formatVersion{};
126 double timestamp{};
128 uint8_t recordType{};
129 uint8_t compressionType{};
130 uint32_t uncompressedSize{};
131
134 inline void setRecordType(Record::Type type) {
135 recordType = static_cast<uint8_t>(type);
136 }
137
141 return static_cast<Record::Type>(recordType);
142 }
143
147 recordableTypeId = static_cast<int32_t>(typeId);
148 }
149
153 return readRecordableTypeId(recordableTypeId);
154 }
155
158 inline StreamId getStreamId() const {
159 return {getRecordableTypeId(), static_cast<uint16_t>(recordableInstanceId)};
160 }
161
165 return static_cast<CompressionType>(compressionType);
166 }
167
171 this->compressionType = static_cast<uint8_t>(type);
172 }
173
176 void initHeader(
178 StreamId streamId,
179 double timestamp,
180 uint32_t formatVersion,
182 uint32_t previousRecordSize,
183 uint32_t recordSize,
184 uint32_t uncompressedSize);
185
191 void initIndexHeader(
192 uint32_t formatVersion,
193 uint32_t indexSize,
194 uint32_t previousRecordSize,
196
202 uint32_t formatVersion,
203 uint32_t descriptionRecordSize,
204 uint32_t previousRecordSize);
205
208 bool isSanityCheckOk() const;
209};
210
211#pragma pack(pop)
212
215constexpr uint32_t fourCharCode(char a, char b, char c, char d) {
216 return static_cast<uint32_t>(a) | (static_cast<uint32_t>(b) << 8) |
217 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24);
218}
219
222bool printVRSFileInternals(std::unique_ptr<FileHandler>& file);
223
224} // namespace FileFormat
225
226} // namespace vrs
Type
Definition Record.h:88
VRS stream identifier class.
Definition StreamId.h:245
constexpr uint32_t fourCharCode(char a, char b, char c, char d)
Definition FileFormat.h:215
Definition Compressor.cpp:113
CompressionType
Type of compression. Used in VRS record headers, so never modify the values.
Definition Record.h:35
RecordableTypeId
VRS stream type or class identifier enum.
Definition StreamId.h:49
Every file starts with this header, which may grow but not shrink!
Definition FileFormat.h:60
bool looksLikeAVRSFile() const
Definition FileFormat.cpp:84
int64_t firstUserRecordOffset
Definition FileFormat.h:69
void enableFrontIndexRecordSupport()
Definition FileFormat.cpp:109
uint32_t recordHeaderSize
Record headers' size, in bytes (same for all).
Definition FileFormat.h:65
uint32_t magicHeader2
magic value #2
Definition FileFormat.h:62
uint32_t fileFormatVersion
file format version.
Definition FileFormat.h:75
uint32_t magicHeader1
magic value #1
Definition FileFormat.h:61
int64_t getEndOfUserRecordsOffset(int64_t fileSize) const
Definition FileFormat.cpp:113
uint64_t future3
For future use.
Definition FileFormat.h:72
int64_t descriptionRecordOffset
Description record offset in the whole file.
Definition FileFormat.h:67
uint64_t future4
For future use.
Definition FileFormat.h:73
bool looksLikeOurFiles(uint32_t magic1, uint32_t magic2, uint32_t magic3) const
Definition FileFormat.cpp:88
bool isFormatSupported() const
Definition FileFormat.cpp:103
uint64_t future2
For future use.
Definition FileFormat.h:71
int64_t indexRecordOffset
Index record offset in the whole file.
Definition FileFormat.h:66
uint32_t fileHeaderSize
This header size, in bytes.
Definition FileFormat.h:64
void init()
Initialize the structure's fixed values with default values for a regular VRS file.
Definition FileFormat.cpp:56
uint32_t magicHeader3
magic value #3
Definition FileFormat.h:74
uint64_t creationId
A timestamp, hopefully unique, to match files (future).
Definition FileFormat.h:63
Every record starts with this header, and is followed by a raw data blob, which semantic is private t...
Definition FileFormat.h:111
uint8_t compressionType
compression used, or 0 for none
Definition FileFormat.h:129
void setRecordableTypeId(RecordableTypeId typeId)
Definition FileFormat.h:146
RecordableTypeId getRecordableTypeId() const
Definition FileFormat.h:152
void setCompressionType(CompressionType type)
Definition FileFormat.h:170
void setRecordType(Record::Type type)
Definition FileFormat.h:134
void initHeader(Record::Type recordType, StreamId streamId, double timestamp, uint32_t formatVersion, CompressionType compressionType, uint32_t previousRecordSize, uint32_t recordSize, uint32_t uncompressedSize)
Definition FileFormat.cpp:145
Record::Type getRecordType() const
Definition FileFormat.h:140
void initDescriptionHeader(uint32_t formatVersion, uint32_t descriptionRecordSize, uint32_t previousRecordSize)
Definition FileFormat.cpp:179
uint32_t previousRecordSize
byte count to the previous record, header + data
Definition FileFormat.h:123
double timestamp
record presentation time stamp
Definition FileFormat.h:126
uint8_t recordType
See Record::Type.
Definition FileFormat.h:128
uint32_t uncompressedSize
uncompressed payload size without header. 0 if not compressed.
Definition FileFormat.h:130
uint32_t formatVersion
data format version, as declared by the data producer
Definition FileFormat.h:125
bool isSanityCheckOk() const
Definition FileFormat.cpp:191
StreamId getStreamId() const
Definition FileFormat.h:158
int32_t recordableTypeId
record handler type id
Definition FileFormat.h:124
uint16_t recordableInstanceId
record handle instance id
Definition FileFormat.h:127
void initIndexHeader(uint32_t formatVersion, uint32_t indexSize, uint32_t previousRecordSize, CompressionType compressionType)
Definition FileFormat.cpp:165
uint32_t recordSize
byte count to the next record, header + data
Definition FileFormat.h:122
CompressionType getCompressionType() const
Definition FileFormat.h:164