uvgVPCCenc 1.1.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
jobManagement.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * This file is part of uvgVPCCenc V-PCC encoder.
3 *
4 * Copyright (c) 2024-present, 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#include <functional>
35#include <memory>
36#include <optional>
37#include <unordered_map>
38
39#include "threadqueue.hpp"
40#include "uvgvpcc/log.hpp"
41
42#define JOBF(gofId, frameId, priority, func, ...) \
43 uvgvpcc_enc::JobManager::make_job(gofId, frameId, priority, std::string(#func), func, ##__VA_ARGS__)
44
45#define JOBG(gofId, priority, func, ...) uvgvpcc_enc::JobManager::make_job(gofId, priority, std::string(#func), func, ##__VA_ARGS__)
46
47#define TO_STRING(x) #x
48
49namespace uvgvpcc_enc {
50
51class jobKey {
52 private:
53 size_t gofId_;
54 std::optional<size_t> frameId_;
55 std::string funcName_;
56
57 public:
58 jobKey(const size_t& gofId, const size_t& frameId, const std::string& funcName);
59 jobKey(const size_t& gofId, const std::string& funcName);
60 std::string toString() const;
61
62 // Getters
63 size_t getGofId() const;
64 std::optional<size_t> getFrameId() const;
65 std::string getFuncName() const;
66
67 bool operator==(const jobKey& other) const;
68};
69} // namespace uvgvpcc_enc
70
71namespace std {
72template <>
73struct hash<uvgvpcc_enc::jobKey> {
74 size_t operator()(const uvgvpcc_enc::jobKey& key) const;
75};
76} // namespace std
77
78namespace uvgvpcc_enc {
79
80struct JobManager {
81 static std::unique_ptr<ThreadQueue> threadQueue;
82 static std::unique_ptr<std::unordered_map<jobKey, std::shared_ptr<Job>>> previousGOFJobMap;
83 static std::unique_ptr<std::unordered_map<jobKey, std::shared_ptr<Job>>> previousFrameJobMap;
84 static std::unique_ptr<std::unordered_map<jobKey, std::shared_ptr<Job>>> currentGOFJobMap;
85 static std::unique_ptr<std::unordered_map<jobKey, std::shared_ptr<Job>>> currentFrameJobMap;
86
87 template <typename Func, typename... Args>
88 static std::shared_ptr<Job> make_job(const size_t& gofId, const size_t& frameId, std::size_t priority, std::string funcName, Func&& func,
89 Args&&... args);
90
91 template <typename Func, typename... Args>
92 static std::shared_ptr<Job> make_job(const size_t& gofId, std::size_t priority, std::string funcName, Func&& func, Args&&... args);
93
94 static std::shared_ptr<Job> getJob(size_t gofId, size_t frameId, const std::string& funcName);
95 static std::shared_ptr<Job> getJob(size_t gofId, const std::string& funcName);
96
97 static void initThreadQueue(uint16_t numThreads);
98
99 static void submitCurrentFrameJobs();
100
101 static void submitCurrentGOFJobs();
102};
103} // namespace uvgvpcc_enc
104
105// Include template implementations
106#include "jobManagement.tpp"
Definition jobManagement.hpp:51
std::optional< size_t > getFrameId() const
Definition jobManagement.cpp:118
std::string getFuncName() const
Definition jobManagement.cpp:120
size_t getGofId() const
Definition jobManagement.cpp:116
std::string toString() const
Definition jobManagement.cpp:109
bool operator==(const jobKey &other) const
Definition jobManagement.cpp:122
Definition jobManagement.cpp:168
Definition log.hpp:48
Definition jobManagement.hpp:80
static void initThreadQueue(uint16_t numThreads)
Definition jobManagement.cpp:138
static std::unique_ptr< std::unordered_map< jobKey, std::shared_ptr< Job > > > currentFrameJobMap
Definition jobManagement.hpp:85
static std::shared_ptr< Job > getJob(size_t gofId, size_t frameId, const std::string &funcName)
Definition jobManagement.cpp:127
static void submitCurrentGOFJobs()
Definition jobManagement.cpp:155
static std::unique_ptr< ThreadQueue > threadQueue
Definition jobManagement.hpp:81
static std::shared_ptr< Job > make_job(const size_t &gofId, std::size_t priority, std::string funcName, Func &&func, Args &&... args)
static std::shared_ptr< Job > make_job(const size_t &gofId, const size_t &frameId, std::size_t priority, std::string funcName, Func &&func, Args &&... args)
static void submitCurrentFrameJobs()
Definition jobManagement.cpp:145
static std::unique_ptr< std::unordered_map< jobKey, std::shared_ptr< Job > > > currentGOFJobMap
Definition jobManagement.hpp:84
static std::unique_ptr< std::unordered_map< jobKey, std::shared_ptr< Job > > > previousFrameJobMap
Definition jobManagement.hpp:83
static std::unique_ptr< std::unordered_map< jobKey, std::shared_ptr< Job > > > previousGOFJobMap
Definition jobManagement.hpp:82
size_t gofId
Definition uvgvpcc.cpp:89