VRS
A file format for sensor data.
Loading...
Searching...
No Matches
Decompressor.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#include <vector>
21
22#include "ForwardDefinitions.h"
23
24namespace vrs {
25
35 public:
38
39 void setCompressionType(CompressionType compressionType);
40 CompressionType getCompressionType() const {
41 return compressionType_;
42 }
43
44 size_t getRecommendedInputBufferSize() const;
45
49 int decompress(void* destination, uint32_t destinationSize, uint32_t& outReadSize);
50
56 void* allocateCompressedDataBuffer(size_t requestSize);
57
62 return readSize_ - decodedSize_;
63 }
64
84 int initFrame(FileHandler& file, size_t& outFrameSize, size_t& inOutMaxReadSize);
91 int readFrame(FileHandler& file, void* dst, size_t frameSize, size_t& inOutMaxReadSize);
92
94 void reset();
95
96 private:
97 const void* getCompressedData() const {
98 return compressedBuffer_.data() + decodedSize_;
99 }
100 size_t getCompressedDataSize() const {
101 return readSize_ - decodedSize_;
102 }
103
104 class Lz4Decompressor;
105 std::unique_ptr<Lz4Decompressor> lz4Context_;
106 class ZstdDecompressor;
107 std::unique_ptr<ZstdDecompressor> zstdContext_;
108 std::vector<uint8_t> compressedBuffer_;
109 CompressionType compressionType_{};
110 size_t readSize_ = {};
111 size_t decodedSize_ = {};
112 size_t lastResult_ = {};
113};
114
115} // namespace vrs
Decompressor helper class, to decompresses data at a target location.
Definition Decompressor.h:34
void * allocateCompressedDataBuffer(size_t requestSize)
Definition Decompressor.cpp:112
int decompress(void *destination, uint32_t destinationSize, uint32_t &outReadSize)
Definition Decompressor.cpp:250
void reset()
Forget any remaining compressed data, get ready for a new frame.
Definition Decompressor.cpp:165
int readFrame(FileHandler &file, void *dst, size_t frameSize, size_t &inOutMaxReadSize)
Definition Decompressor.cpp:222
int initFrame(FileHandler &file, size_t &outFrameSize, size_t &inOutMaxReadSize)
Definition Decompressor.cpp:207
size_t getRemainingCompressedDataBufferSize() const
Definition Decompressor.h:61
Class to abstract VRS file system operations, to enable support for alternate storage methods,...
Definition FileHandler.h:71
Definition AsyncDiskFileChunk.hpp:49
CompressionType
Type of compression. Used in VRS record headers, so never modify the values.
Definition Record.h:35