27#include <glm/vec2.hpp>
29#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
30#include <vulkan/vulkan.hpp>
32#define HVT_FUNCTION_PROTOTYPES
35#define HVT_ENTRY_ATTR __declspec(dllexport)
37#include "../RVSVulkan/SourcesVulkan/HvtStreamingAPI.h"
39#include "../RVSVulkan/RVSConfig/include/Config.h"
43enum class InternalFormatClass {
48enum class HvtHandleType {
53template<
typename OurType,
typename HvtHandle, HvtHandleType htype>
56 static constexpr HvtHandleType staticType = htype;
58 static OurType* check(HvtHandle hvtHandle) {
60 if (h && staticType == h->type) {
61 return static_cast<OurType*
>(h);
64 throw HvtResult::HVT_ERROR_INVALID_HANDLE;
68 static OurType* opt_check(HvtHandle hvtHandle) {
72 return check(hvtHandle);
75 HvtHandle to_handle() {
76 return reinterpret_cast<HvtHandle
>(
this);
82struct Semaphore :
public Handle<Semaphore, HvtSemaphore, HvtHandleType::SEMAPHORE>
84 vk::UniqueSemaphore sem;
90 using Clock = std::chrono::steady_clock;
91 static constexpr auto numSlots = 3;
97 void destroySemaphore(
Semaphore* sem)
const;
98 void startStreaming();
100 void releaseStreamsFrames(
Semaphore* waitSem);
101 void stopStreaming();
104 void initVk(std::span<const uint8_t, VK_UUID_SIZE> uuid);
105 uint32_t findMemoryType(uint32_t typeFilter, vk::MemoryPropertyFlags properties);
107 void initVkResources();
109 template<
typename Closure>
110 void oneTimeSubmit(Closure&& func, vk::SubmitInfo submitInfo = vk::SubmitInfo({}, {}, {}, {}));
113 vk::UniqueImage image;
114 vk::UniqueDeviceMemory memory;
118 std::ifstream colorFile;
119 std::ifstream depthFile;
120 size_t colorFrameStride;
121 size_t colorFrameSize;
122 size_t depthFrameStride;
123 size_t depthFrameSize;
125 glm::ivec2 resolution;
126 HvtProjectionType projectionType;
130 float anear;
float afar;
132 vk::Format colorFormat;
133 vk::Format depthFormat;
134 vk::UniqueDeviceMemory stagingMemory;
135 vk::UniqueBuffer stagingBuffer;
136 char* stagingMapping =
nullptr;
138 std::array<ImageSlot, numSlots> colorSlots;
139 std::array<ImageSlot, numSlots> depthSlots;
140 bool importedColor =
false;
141 bool importedDepth =
false;
143 Clock::duration framePeriod;
145 int streamedFrame = -1;
147 std::string fileNameColor =
"";
148 std::string fileNameDepth =
"";
150 int frameIndex(Clock::duration time)
const;
151 bool nextFrameReady(Clock::duration time)
const;
154 void streamingLoop();
155 void uploadFrame(vk::CommandBuffer cmd,
int streamId, ReadStream& stream,
int frame);
156 void swapStreamingToPending();
157 void swapPendingToReading();
159 std::optional<rvs::Config> config;
160 InternalFormatClass internalFormat = InternalFormatClass::YUV;
162 std::vector<ReadStream> readStreams;
164 vk::UniqueInstance instance;
165 vk::PhysicalDevice phyDevice = VK_NULL_HANDLE;
166 vk::UniqueDevice device;
167 uint32_t queueFamilyIndex;
170 std::mutex queueMutex;
173 std::array<Semaphore*, numSlots> usageWaitSemaphores{};
174 uint32_t slotReadingIndex = 0;
175 uint32_t slotPendingIndex = 1;
176 uint32_t slotStreamingIndex = 2;
177 std::atomic_bool newDataInPending =
false;
178 std::mutex indicesMutex;
180 std::atomic_bool running =
false;
181 std::thread streamingThread;
Parameters for query of the current frames infos.
Description of an RGBD stream.
Export info for images of a stream.
Union of possible intrinsics types data.