uvgVPCCenc 1.2.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
commonMemory.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 (subject to the limitations in the disclaimer below) 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 Tampere University, 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 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
32 ****************************************************************************/
33
35
36#pragma once
37
38#include <cassert>
39#include <robin_hood.h>
40#include "utils/types.hpp"
41#include "constants.hpp"
42
43namespace uvgvpcc_enc {
44
46
47 public:
48 static CommonMemory& get(); // lf: leaky singleton
49
50 robin_hood::unordered_map<size_t,std::unique_ptr<std::array<std::vector<Patch>, MAX_GOF_SIZE>>> mapFramePatches;
51
52 robin_hood::unordered_map<size_t,std::unique_ptr<std::array<std::vector<uint8_t>, MAX_GOF_SIZE>>> mapFrameOccupancyMaps;
53 robin_hood::unordered_map<size_t,std::unique_ptr<std::array<std::vector<uint8_t>, MAX_GOF_SIZE>>> mapFrameOccupancyMapsColor;
54 robin_hood::unordered_map<size_t,std::unique_ptr<std::array<std::vector<uint8_t>, MAX_GOF_SIZE>>> mapFrameOccupancyMapsDS;
55 robin_hood::unordered_map<size_t,std::unique_ptr<std::array<std::vector<uint8_t>, MAX_GOF_SIZE>>> mapFrameGeometryMapsL1;
56 robin_hood::unordered_map<size_t,std::unique_ptr<std::array<std::vector<uint8_t>, MAX_GOF_SIZE>>> mapFrameGeometryMapsL2;
57 robin_hood::unordered_map<size_t,std::unique_ptr<std::array<std::vector<uint8_t>, MAX_GOF_SIZE>>> mapFrameAttributeMapsL1;
58 robin_hood::unordered_map<size_t,std::unique_ptr<std::array<std::vector<uint8_t>, MAX_GOF_SIZE>>> mapFrameAttributeMapsL2;
59
60
61 std::array<std::vector<Patch>, MAX_GOF_SIZE>* getOrCreateFramePatches (size_t gofId) { return getOrCreate(mapFramePatches, gofId); }
62 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* getOrCreateFrameOccupancyMaps (size_t gofId) { return getOrCreate(mapFrameOccupancyMaps, gofId); }
63 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* getOrCreateFrameOccupancyMapsColor (size_t gofId) { return getOrCreate(mapFrameOccupancyMapsColor,gofId); }
64 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* getOrCreateFrameOccupancyMapsDS (size_t gofId) { return getOrCreate(mapFrameOccupancyMapsDS, gofId); }
65 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* getOrCreateFrameGeometryMapsL1 (size_t gofId) { return getOrCreate(mapFrameGeometryMapsL1, gofId); }
66 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* getOrCreateFrameGeometryMapsL2 (size_t gofId) { return getOrCreate(mapFrameGeometryMapsL2, gofId); }
67 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* getOrCreateFrameAttributeMapsL1 (size_t gofId) { return getOrCreate(mapFrameAttributeMapsL1, gofId); }
68 std::array<std::vector<uint8_t>, MAX_GOF_SIZE>* getOrCreateFrameAttributeMapsL2 (size_t gofId) { return getOrCreate(mapFrameAttributeMapsL2, gofId); }
69
70 void clearGofMaps(const size_t& gofId);
71
72 private:
73 std::mutex mapMutex;
74
75 template<typename Map>
76 typename Map::mapped_type::element_type* getOrCreate(Map& map, size_t gofId) {
77 std::lock_guard<std::mutex> lock(mapMutex);
78 auto& ptr = map[gofId];
79 if (!ptr) {
80 ptr = std::make_unique<typename Map::mapped_type::element_type>();
81 }
82 return ptr.get();
83 }
84
85};
86
87
88
89
90} // namespace uvgvpcc_enc
Definition commonMemory.hpp:45
robin_hood::unordered_map< size_t, std::unique_ptr< std::array< std::vector< uint8_t >, MAX_GOF_SIZE > > > mapFrameGeometryMapsL2
Definition commonMemory.hpp:56
std::array< std::vector< Patch >, MAX_GOF_SIZE > * getOrCreateFramePatches(size_t gofId)
Definition commonMemory.hpp:61
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * getOrCreateFrameGeometryMapsL2(size_t gofId)
Definition commonMemory.hpp:66
robin_hood::unordered_map< size_t, std::unique_ptr< std::array< std::vector< uint8_t >, MAX_GOF_SIZE > > > mapFrameGeometryMapsL1
Definition commonMemory.hpp:55
robin_hood::unordered_map< size_t, std::unique_ptr< std::array< std::vector< uint8_t >, MAX_GOF_SIZE > > > mapFrameOccupancyMapsDS
Definition commonMemory.hpp:54
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * getOrCreateFrameAttributeMapsL2(size_t gofId)
Definition commonMemory.hpp:68
robin_hood::unordered_map< size_t, std::unique_ptr< std::array< std::vector< uint8_t >, MAX_GOF_SIZE > > > mapFrameOccupancyMapsColor
Definition commonMemory.hpp:53
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * getOrCreateFrameOccupancyMapsDS(size_t gofId)
Definition commonMemory.hpp:64
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * getOrCreateFrameGeometryMapsL1(size_t gofId)
Definition commonMemory.hpp:65
robin_hood::unordered_map< size_t, std::unique_ptr< std::array< std::vector< uint8_t >, MAX_GOF_SIZE > > > mapFrameAttributeMapsL2
Definition commonMemory.hpp:58
void clearGofMaps(const size_t &gofId)
Definition commonMemory.cpp:47
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * getOrCreateFrameOccupancyMaps(size_t gofId)
Definition commonMemory.hpp:62
robin_hood::unordered_map< size_t, std::unique_ptr< std::array< std::vector< uint8_t >, MAX_GOF_SIZE > > > mapFrameAttributeMapsL1
Definition commonMemory.hpp:57
robin_hood::unordered_map< size_t, std::unique_ptr< std::array< std::vector< uint8_t >, MAX_GOF_SIZE > > > mapFrameOccupancyMaps
Definition commonMemory.hpp:52
robin_hood::unordered_map< size_t, std::unique_ptr< std::array< std::vector< Patch >, MAX_GOF_SIZE > > > mapFramePatches
Definition commonMemory.hpp:50
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * getOrCreateFrameOccupancyMapsColor(size_t gofId)
Definition commonMemory.hpp:63
static CommonMemory & get()
Definition commonMemory.cpp:42
std::array< std::vector< uint8_t >, MAX_GOF_SIZE > * getOrCreateFrameAttributeMapsL1(size_t gofId)
Definition commonMemory.hpp:67
Definition uvgvpccenc.hpp:49
constexpr size_t MAX_GOF_SIZE
Definition constants.hpp:63
size_t gofId
Definition uvgvpccenc.cpp:94