uvgVPCCenc 1.1.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
uvgvpcc.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * This file is part of uvgVPCCenc V-PCC encoder.
3 *
4 * Copyright (c) 2024, Tampere University, ITU/ISO/IEC, project contributors
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice, this
14 * list of conditions and the following disclaimer in the documentation and/or
15 * other materials provided with the distribution.
16 *
17 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
31 ****************************************************************************/
32
33#pragma once
34
35#include <array>
36#include <cassert>
37#include <cstddef>
38#include <cstdint>
39#include <iostream>
40#include <memory>
41#include <queue>
42#include <semaphore>
43#include <sstream>
44#include <string>
45#include <vector>
46
47#include "../utils/parameters.hpp"
48#include "../utils/constants.hpp"
49#include "uvgutils/utils.hpp"
50// #include "../utils/commonMemory.hpp"
51
53
54// TODO(lf): why in include/uvgvpcc/ ? What about the related .cpp Why not "include/" only ?
55
56namespace uvgvpcc_enc {
57
58// A patch is a 3D object. Though, the word 'patch' can refer to the "2D version" of this patch
59struct Patch {
61 size_t patchPpi_; // viewId
62
63 size_t normalAxis_; // x
64 size_t tangentAxis_; // y
65 size_t bitangentAxis_; // z
66
67 size_t posU_; // u1_ minU_ // tangential shift
68 size_t posV_; // v1_ minV_ // bitangential shift
69 size_t posD_; // d1_ minD_ // depth shift
70
71 bool projectionMode_; // 0: related to the min depth value; 1: related to the max value
72
73 size_t sizeD_; // while posD_ is the minimum 'depth', sizeD_ store the maximum depth. TODO(lf): check if it is usefull
74
75 std::vector<uint8_t> patchOccupancyMap_; // patch occupancy map (boolean vector)
76
77 size_t widthInPixel_ = 0; // size for U // width of the patch occupancy map (in pixels)
78 size_t heightInPixel_ = 0; // size for V // height of the patch occupancy map (in pixels)
79
80 size_t widthInOccBlk_; // sizeU0_ // width of the patch occupancy map within the down-scaled frame occupancy map (in DS occupancy map
81 // blocks).
82 size_t heightInOccBlk_; // sizeV0_ // height of the patch occupancy map within the down-scaled frame occupancy map (in DS occupancy
83 // map blocks).
84
85 size_t omDSPosX_; // u0_ // location in down-scaled occupancy map // lf posBlkU
86 size_t omDSPosY_; // v0_ // location in down-scaled occupancy map
87
88 bool axisSwap_; // patch orientation // in canvas atlas (false default, true axis swap)
89
90 std::vector<typeGeometryInput> depthL1_; // depth value First layer // TODO(lf): Using the geo type here might lead to issue?
91 std::vector<typeGeometryInput> depthL2_; // depth value Second layer
92
93 // Index of the point in the PC for attribute retrieving during attribute map generation TODO(lf): use for Surface separation?
94 std::vector<size_t> depthPCidxL1_;
95 std::vector<size_t> depthPCidxL2_;
96
97 // inter packing //
98 size_t area_ = 0;
99
101 // Store the id of the best reference patch in the previous frame. Notice that even if the current patch is not
102 // matched, a reference patch id is still found. Then, this reference id will be used to check if the iou treshold
103 // is respected or not, then indicating if this patch is matched or not.
104
106 // Store not the id but the position in the list of patch of the best reference patch in the previous frame. Notice that even if
107 // the current patch is not matched, a reference patch id is still found. Then, this reference id will be used to check if the
108 // iou treshold is respected or not, then indicating if this patch is matched or not.
109 bool isLinkToAMegaPatch = false;
111
112 bool isDiscarded = false; // If dynamicMapHeight=false et minimumMapHeight=??? is too small, then some patch can't be packed. There are then discarded (they will not be encoded).
113
114 void setAxis(size_t normalAxis, size_t tangentAxis, size_t bitangentAxis, bool projectionMode) {
115 normalAxis_ = normalAxis;
116 tangentAxis_ = tangentAxis;
117 bitangentAxis_ = bitangentAxis;
118 projectionMode_ = projectionMode; // TODO(lf): projection mode optimization per patch
119 }
120
121 inline void setPatchPpiAndAxis(size_t patchPpi) {
122 patchPpi_ = patchPpi;
123 // now set the other variables according to the viewId
124 switch (patchPpi_) {
125 case 0:
126 setAxis(0, 2, 1, 0);
127 break;
128 case 1:
129 setAxis(1, 2, 0, 0);
130 break;
131 case 2:
132 setAxis(2, 0, 1, 0);
133 break;
134 case 3:
135 setAxis(0, 2, 1, 1);
136 break;
137 case 4:
138 setAxis(1, 2, 0, 1);
139 break;
140 case 5:
141 setAxis(2, 0, 1, 1);
142 break;
143 default:
144 throw std::runtime_error("ViewId (" + std::to_string(patchPpi) + ") not allowed... exiting");
145 break;
146 }
147 }
148
149 std::string toString() const {
150 std::stringstream str;
151 str << "patchIndex=" << patchIndex_;
152 str << ", patchPpi=" << patchPpi_;
153 str << ", normalAxis=" << normalAxis_;
154 str << ", tangentAxis=" << tangentAxis_;
155 str << ", bitangentAxis=" << bitangentAxis_;
156 str << ", projectionMode=" << projectionMode_;
157 str << ", minU=" << posU_;
158 str << ", minV=" << posV_;
159 str << ", minD=" << posD_;
160 str << ", sizeD=" << sizeD_;
161 str << ", sizeU=" << widthInPixel_;
162 str << ", sizeV=" << heightInPixel_;
163 str << ", sizeUom=" << widthInOccBlk_;
164 str << ", sizeVom=" << heightInOccBlk_;
165 str << ", omDSPosX_=" << omDSPosX_;
166 str << ", omDSPosY_=" << omDSPosY_;
167 str << ", axisSwap=" << axisSwap_;
168 return str.str();
169 }
170};
171
172struct GOF;
173
174// TODO(lf): Avid using both constant sized and dynamic sized memory member within the same struct.
175struct Frame {
176 size_t frameId; // aka relative index (0 if first encoded frame)
177 size_t gofId;
178 size_t frameNumber; // aka number from the input frame file name (TODO(lf): correct)
179 std::weak_ptr<GOF> gof;
180 std::shared_ptr<std::counting_semaphore<UINT16_MAX>> conccurentFrameSem;
181
182 std::string pointCloudPath;
183
185 std::vector<uvgutils::VectorN<typeGeometryInput, 3>> pointsGeometry;
186 std::vector<uvgutils::VectorN<uint8_t, 3>> pointsAttribute;
187
188 size_t mapHeight = 0;
189 size_t mapHeightDS = 0;
190
191 Frame(const size_t& frameId, const size_t& frameNumber, const std::string& pointCloudPath)
192 : frameId(frameId), frameNumber(frameNumber), pointCloudPath(pointCloudPath), pointCount(0), mapHeight(p_->minimumMapHeight), mapHeightDS(p_->minimumMapHeight / p_->occupancyMapDSResolution),patchList(nullptr) {}
194 if (conccurentFrameSem) {
195 conccurentFrameSem->release();
196 }
197 };
198 void printInfo() const;
199
200 // lf: Centralized memory handling //
201 std::vector<Patch>* patchList;
202
203 std::vector<uint8_t>* occupancyMap; // (boolean vector)
204 std::vector<uint8_t>* occupancyMapDS; // Down-scaled occupancy map of the frame (boolean vector)
205 std::vector<uint8_t>* geometryMapL1; // first layer
206 std::vector<uint8_t>* geometryMapL2; // second layer
207 std::vector<uint8_t>* attributeMapL1; // Store the three channels continuously (all R, then all G, than all B)
208 std::vector<uint8_t>* attributeMapL2;
209
210};
211
212struct GOF {
213 std::vector<std::shared_ptr<Frame>> frames;
214 size_t nbFrames;
215 size_t gofId;
216
219
220 std::vector<uint8_t> bitstreamOccupancy;
221 std::vector<uint8_t> bitstreamGeometry;
222 std::vector<uint8_t> bitstreamAttribute;
223
224 // lf: centralized memory handling //
225 std::array<std::vector<Patch>, MAX_GOF_SIZE>* framePatches;
226 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameOccupancyMaps;
227 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameOccupancyMapsDS;
228 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameGeometryMapsL1;
229 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameGeometryMapsL2;
230 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameAttributeMapsL1;
231 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* frameAttributeMapsL2;
232
233 GOF(const size_t& gofId);
234 void setFrameMemoryPtrs(std::shared_ptr<Frame>& frame);
235 ~GOF();
236};
237
239namespace API {
240
242struct v3c_chunk {
243 size_t len = 0; // Length of data in buffer
244 std::unique_ptr<char[]> data; // Actual data (char type can be used to describe a byte. No need for uint8_t or unsigned char types.)
245 std::vector<size_t> v3c_unit_sizes = {};
246
247 v3c_chunk() = default;
248 v3c_chunk(size_t len, std::unique_ptr<char[]> data) : len(len), data(std::move(data)) {}
249};
250
251// ht: A V3C unit stream is composed of only V3C units without parsing information in the bitstream itself. The parsing information is here
252// given separately.
255 std::queue<v3c_chunk> v3c_chunks = {};
256 std::counting_semaphore<> available_chunks{0};
257 std::mutex io_mutex; // Locks production and consumption in the v3c_chunks queue
258};
259
260void initializeEncoder();
261void setParameter(const std::string& parameterName, const std::string& parameterValue);
262void encodeFrame(std::shared_ptr<Frame>& frame, v3c_unit_stream* output);
263void emptyFrameQueue();
264void stopEncoder();
265
266} // namespace API
267
268}; // namespace uvgvpcc_enc
Definition jobManagement.hpp:71
void stopEncoder()
Insure a proper end of the encoder execution.
Definition uvgvpcc.cpp:687
void initializeEncoder()
Create the context of the uvgVPCCenc encoder. Parse the input parameters and verify if the given conf...
Definition uvgvpcc.cpp:563
void setParameter(const std::string &parameterName, const std::string &parameterValue)
The only way to modify the exposed uvgVPCCenc parameters is by calling this function.
Definition uvgvpcc.cpp:583
void emptyFrameQueue()
This function is called when all frames to be processed have been sent to the encoder....
Definition uvgvpcc.cpp:676
void encodeFrame(std::shared_ptr< Frame > &frame, v3c_unit_stream *output)
Entry point of the uvgVPCCenc library. Take as input a frame. Create all the jobs for processing this...
Definition uvgvpcc.cpp:602
Definition uvgvpcc.hpp:56
constexpr size_t INVALID_PATCH_INDEX
Definition constants.hpp:54
constexpr size_t MAX_GOF_SIZE
Definition constants.hpp:62
const Parameters * p_
Definition uvgvpcc.cpp:522
const size_t g_infinitenumber
Definition constants.hpp:51
Bitstream writing miscellaneous.
Definition uvgvpcc.hpp:242
std::unique_ptr< char[]> data
Definition uvgvpcc.hpp:244
v3c_chunk(size_t len, std::unique_ptr< char[]> data)
Definition uvgvpcc.hpp:248
size_t len
Definition uvgvpcc.hpp:243
std::vector< size_t > v3c_unit_sizes
Definition uvgvpcc.hpp:245
Definition uvgvpcc.hpp:253
std::queue< v3c_chunk > v3c_chunks
Definition uvgvpcc.hpp:255
std::counting_semaphore available_chunks
Definition uvgvpcc.hpp:256
std::mutex io_mutex
Definition uvgvpcc.hpp:257
size_t v3c_unit_size_precision_bytes
Definition uvgvpcc.hpp:254
Definition uvgvpcc.hpp:175
size_t mapHeight
Definition uvgvpcc.hpp:188
std::string pointCloudPath
Definition uvgvpcc.hpp:182
std::vector< uint8_t > * geometryMapL2
Definition uvgvpcc.hpp:206
std::vector< Patch > * patchList
Definition uvgvpcc.hpp:201
size_t pointCount
Definition uvgvpcc.hpp:184
std::weak_ptr< GOF > gof
Definition uvgvpcc.hpp:179
std::vector< uint8_t > * attributeMapL2
Definition uvgvpcc.hpp:208
size_t gofId
Definition uvgvpcc.hpp:177
Frame(const size_t &frameId, const size_t &frameNumber, const std::string &pointCloudPath)
Definition uvgvpcc.hpp:191
std::vector< uvgutils::VectorN< typeGeometryInput, 3 > > pointsGeometry
Definition uvgvpcc.hpp:185
std::shared_ptr< std::counting_semaphore< UINT16_MAX > > conccurentFrameSem
Definition uvgvpcc.hpp:180
~Frame()
Definition uvgvpcc.hpp:193
std::vector< uint8_t > * occupancyMapDS
Definition uvgvpcc.hpp:204
size_t mapHeightDS
Definition uvgvpcc.hpp:189
std::vector< uint8_t > * occupancyMap
Definition uvgvpcc.hpp:203
size_t frameNumber
Definition uvgvpcc.hpp:178
void printInfo() const
Definition uvgvpcc.cpp:524
std::vector< uint8_t > * attributeMapL1
Definition uvgvpcc.hpp:207
size_t frameId
Definition uvgvpcc.hpp:176
std::vector< uint8_t > * geometryMapL1
Definition uvgvpcc.hpp:205
std::vector< uvgutils::VectorN< uint8_t, 3 > > pointsAttribute
Definition uvgvpcc.hpp:186
Definition uvgvpcc.hpp:212
std::vector< std::shared_ptr< Frame > > frames
Definition uvgvpcc.hpp:213
size_t mapHeightGOF
Definition uvgvpcc.hpp:217
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameAttributeMapsL1
Definition uvgvpcc.hpp:230
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameOccupancyMaps
Definition uvgvpcc.hpp:226
void setFrameMemoryPtrs(std::shared_ptr< Frame > &frame)
Definition uvgvpcc.cpp:544
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameGeometryMapsL1
Definition uvgvpcc.hpp:228
std::vector< uint8_t > bitstreamAttribute
Definition uvgvpcc.hpp:222
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameAttributeMapsL2
Definition uvgvpcc.hpp:231
std::vector< uint8_t > bitstreamGeometry
Definition uvgvpcc.hpp:221
size_t nbFrames
Definition uvgvpcc.hpp:214
size_t mapHeightDSGOF
Definition uvgvpcc.hpp:218
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameGeometryMapsL2
Definition uvgvpcc.hpp:229
size_t gofId
Definition uvgvpcc.hpp:215
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * frameOccupancyMapsDS
Definition uvgvpcc.hpp:227
std::vector< uint8_t > bitstreamOccupancy
Definition uvgvpcc.hpp:220
std::array< std::vector< Patch >, MAX_GOF_SIZE > * framePatches
Definition uvgvpcc.hpp:225
~GOF()
Definition uvgvpcc.cpp:557
Definition uvgvpcc.hpp:59
size_t posU_
Definition uvgvpcc.hpp:67
bool isLinkToAMegaPatch
Definition uvgvpcc.hpp:109
bool axisSwap_
Definition uvgvpcc.hpp:88
size_t widthInPixel_
Definition uvgvpcc.hpp:77
size_t patchIndex_
Definition uvgvpcc.hpp:60
size_t area_
Definition uvgvpcc.hpp:98
std::string toString() const
Definition uvgvpcc.hpp:149
size_t sizeD_
Definition uvgvpcc.hpp:73
std::vector< typeGeometryInput > depthL2_
Definition uvgvpcc.hpp:91
size_t heightInOccBlk_
Definition uvgvpcc.hpp:82
void setPatchPpiAndAxis(size_t patchPpi)
Definition uvgvpcc.hpp:121
bool projectionMode_
Definition uvgvpcc.hpp:71
size_t omDSPosY_
Definition uvgvpcc.hpp:86
size_t posD_
Definition uvgvpcc.hpp:69
size_t bestMatchIdx
Definition uvgvpcc.hpp:105
size_t bitangentAxis_
Definition uvgvpcc.hpp:65
size_t normalAxis_
Definition uvgvpcc.hpp:63
std::vector< size_t > depthPCidxL2_
Definition uvgvpcc.hpp:95
size_t referencePatchId_
Definition uvgvpcc.hpp:100
std::vector< typeGeometryInput > depthL1_
Definition uvgvpcc.hpp:90
size_t heightInPixel_
Definition uvgvpcc.hpp:78
std::vector< size_t > depthPCidxL1_
Definition uvgvpcc.hpp:94
size_t tangentAxis_
Definition uvgvpcc.hpp:64
size_t posV_
Definition uvgvpcc.hpp:68
std::vector< uint8_t > patchOccupancyMap_
Definition uvgvpcc.hpp:75
size_t unionPatchReferenceIdx
Definition uvgvpcc.hpp:110
size_t widthInOccBlk_
Definition uvgvpcc.hpp:80
bool isDiscarded
Definition uvgvpcc.hpp:112
void setAxis(size_t normalAxis, size_t tangentAxis, size_t bitangentAxis, bool projectionMode)
Definition uvgvpcc.hpp:114
size_t omDSPosX_
Definition uvgvpcc.hpp:85
size_t patchPpi_
Definition uvgvpcc.hpp:61