HoviTron Video Pipeline
Data Structures | Public Member Functions
RaytrixStreamer Class Reference
Inheritance diagram for RaytrixStreamer:
Handle< RaytrixStreamer, HvtStreamingContext, HvtHandleType::CONTEXT >

Public Member Functions

 RaytrixStreamer (const uint8_t uuid[VK_UUID_SIZE])
 Launch all init functions defined in RaytrixStreamer class.
 
 ~RaytrixStreamer ()
 Free all the memories that were allocated during the streaming process.
 
void enumerateStreamsParameters (uint32_t *streamsCount, HvtRGBDStreamParameters *parameters) const
 
void importStreamImages (const HvtStreamImagesExportInfo &exportInfos)
 
void importSemaphore (const HvtSemaphoreExportInfo &exportInfos)
 
void destroySemaphore (Semaphore *sem) const
 
void startStreaming ()
 
void acquireStreamsFrames (const HvtAcquireStreamFramesInfo &infos)
 
void releaseStreamsFrames (Semaphore *waitSem)
 
void stopStreaming ()
 
float getMaxDepth ()
 Get the maximum depth.
 
float getMinDepth ()
 Get the minimum depth.
 
HvtIntrinsicsPerspective getRxIntrinsicParams (size_t idxCam)
 Get the intrinsic parameters of the camera of ID "idxCam". The intrinsic parameters are found through the Raytrix SDK.
 
HvtExtrinsics getRxExtrinsicParams (size_t idxCam)
 Get the extrinsic parameters of the camera of ID "idxCam". The extrinsic parameters are found through the Raytrix SDK and the extrinsic file.
 
Rx::LFR::CImageQueue & getCamBuffer (size_t idxCam)
 Get the camera buffer in the list of camera buffers.
 
 RaytrixStreamer (const uint8_t uuid[VK_UUID_SIZE])
 Launch all init functions defined in RaytrixStreamer class.
 
 ~RaytrixStreamer ()
 Free all the memories that were allocated during the streaming process.
 
void enumerateStreamsParameters (uint32_t *streamsCount, HvtRGBDStreamParameters *parameters) const
 
void importStreamImages (const HvtStreamImagesExportInfo &exportInfos)
 
void importSemaphore (const HvtSemaphoreExportInfo &exportInfos)
 
void destroySemaphore (Semaphore *sem) const
 
void startStreaming ()
 
void acquireStreamsFrames (const HvtAcquireStreamFramesInfo &infos)
 
void releaseStreamsFrames (Semaphore *waitSem)
 
void stopStreaming ()
 
float getMaxDepth ()
 Get the maximum depth.
 
float getMinDepth ()
 Get the minimum depth.
 
HvtIntrinsicsPerspective getRxIntrinsicParams (size_t idxCam)
 Get the intrinsic parameters of the camera of ID "idxCam". The intrinsic parameters are found through the Raytrix SDK.
 
HvtExtrinsics getRxExtrinsicParams (size_t idxCam)
 Get the extrinsic parameters of the camera of ID "idxCam". The extrinsic parameters are found through the Raytrix SDK and the extrinsic file.
 
Rx::LFR::CImageQueue & getCamBuffer (size_t idxCam)
 Get the camera buffer in the list of camera buffers.
 
- Public Member Functions inherited from Handle< RaytrixStreamer, HvtStreamingContext, HvtHandleType::CONTEXT >
HvtStreamingContext to_handle ()
 
HvtStreamingContext to_handle ()
 
HvtStreamingContext to_handle ()
 
HvtStreamingContext to_handle ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Handle< RaytrixStreamer, HvtStreamingContext, HvtHandleType::CONTEXT >
static RaytrixStreamercheck (HvtStreamingContext hvtHandle)
 
static RaytrixStreamercheck (HvtStreamingContext hvtHandle)
 
static RaytrixStreamercheck (HvtStreamingContext hvtHandle)
 
static RaytrixStreamercheck (HvtStreamingContext hvtHandle)
 
static RaytrixStreameropt_check (HvtStreamingContext hvtHandle)
 
static RaytrixStreameropt_check (HvtStreamingContext hvtHandle)
 
static RaytrixStreameropt_check (HvtStreamingContext hvtHandle)
 
static RaytrixStreameropt_check (HvtStreamingContext hvtHandle)
 
- Static Public Attributes inherited from Handle< RaytrixStreamer, HvtStreamingContext, HvtHandleType::CONTEXT >
static constexpr HvtHandleType staticType
 

Detailed Description

Definition at line 122 of file raytrixdll-v5/RaytrixStreamer.h.

Constructor & Destructor Documentation

◆ RaytrixStreamer() [1/2]

RaytrixStreamer::RaytrixStreamer ( const uint8_t  uuid[VK_UUID_SIZE])

Launch all init functions defined in RaytrixStreamer class.

Parameters
uuidThe UUID of the vulkan GPU.

Definition at line 1042 of file raytrixdll-v5/RaytrixStreamer.cpp.

1043{
1044 findVulkanGPU(uuid);
1045 readInfoFromJSON();
1046 initRxSDK();
1047 if (infoJSON.loadFromRawFile) {
1048 initRxRayFile();
1049 }
1050 else {
1051 initRxCams();
1052 }
1053 initRxCudaCompute();
1054 initStreamParameters();
1055 initArrayCuda();
1056 initMutex();
1057}

◆ ~RaytrixStreamer()

RaytrixStreamer::~RaytrixStreamer ( )

Free all the memories that were allocated during the streaming process.

Definition at line 1059 of file raytrixdll-v5/RaytrixStreamer.cpp.

1060{
1061 std::cout << "---- Destroy RaytrixStreamer dll ----" << std::endl;
1062 if (synthesisSem != NULL)
1063 delete synthesisSem;
1064 for (size_t i = 0; i < infoJSON.numCams; ++i) {
1065 xCamServer.GetCamera(i).Close();
1066 }
1067 if (infoJSON.loadFromRawFile) {
1068 delete[] seqReaders;
1069 delete[] rayImages;
1070 }
1071 Rx::LFR::CLightFieldRuntime::End();
1072}

◆ RaytrixStreamer() [2/2]

RaytrixStreamer::RaytrixStreamer ( const uint8_t  uuid[VK_UUID_SIZE])

Launch all init functions defined in RaytrixStreamer class.

Parameters
uuidThe UUID of the vulkan GPU.

Member Function Documentation

◆ acquireStreamsFrames()

void RaytrixStreamer::acquireStreamsFrames ( const HvtAcquireStreamFramesInfo infos)

Definition at line 1242 of file raytrixdll-v5/RaytrixStreamer.cpp.

1243{
1244 gpuErrchk(cudaSetDevice(vulkanGPU));
1245 if (infos.frameInfoCount != readStreams.size())
1246 {
1247 throw HvtResult::HVT_ERROR_WRONG_BUFFER_SIZE;
1248 }
1249
1250 swapPendingToReading();
1251
1252 auto imageIndex = slotReadingIndex;
1253
1254 for (uint32_t i = 0; i < infos.frameInfoCount; ++i)
1255 {
1256 gpuErrchk(cudaEventSynchronize(cudaEvents[i]));
1257
1258 auto& stream = readStreams.at(i);
1259 auto& desc = infos.pStreamFrameInfos[i];
1260 desc.extrinsics = stream.extrinsics;
1261 desc.intrinsics = stream.intrinsics;
1262 desc.imageIndex = imageIndex;
1263 }
1264}

◆ destroySemaphore()

void RaytrixStreamer::destroySemaphore ( Semaphore sem) const

Definition at line 1217 of file raytrixdll-v5/RaytrixStreamer.cpp.

1218{
1219 cudaSetDevice(vulkanGPU);
1220 delete sem;
1221}

◆ enumerateStreamsParameters()

void RaytrixStreamer::enumerateStreamsParameters ( uint32_t *  streamsCount,
HvtRGBDStreamParameters parameters 
) const

Definition at line 1075 of file raytrixdll-v5/RaytrixStreamer.cpp.

1076{
1077 cudaSetDevice(vulkanGPU);
1078 if (!parameters)
1079 {
1080 *streamsCount = readStreams.size();
1081 return;
1082 }
1083
1084 if (*streamsCount != readStreams.size())
1085 {
1086 throw HvtResult::HVT_ERROR_WRONG_BUFFER_SIZE;
1087 }
1088
1089 int i = 0;
1090 for (const auto& readStream : readStreams)
1091 {
1093 SP->colorResolution = { (uint32_t)readStream.width_color, (uint32_t)readStream.height_color };
1094 SP->depthResolution = { (uint32_t)readStream.width_depth, (uint32_t)readStream.height_depth };
1095 SP->nearDepth = readStream.anear;
1096 SP->farDepth = readStream.afar;
1097 SP->colorFormat = (HvtImageFormat)readStream.colorFormat;
1098 SP->depthFormat = (HvtImageFormat)readStream.depthFormat;
1099 SP->slotCount = numSlots;
1100 SP->projectionType = readStream.projectionType;
1101
1102 parameters[i] = *SP;
1103 //snprintf(parameters->name, HVT_MAX_STREAM_NAME_LENGHT, "%s", deviceNames.at(i).c_str());
1104 ++i;
1105 }
1106}
Description of an RGBD stream.

◆ getCamBuffer() [1/2]

Rx::LFR::CImageQueue & RaytrixStreamer::getCamBuffer ( size_t  idxCam)

Get the camera buffer in the list of camera buffers.

Parameters
idxCamID of the buffer.
Returns
A copy of the buffer.

Definition at line 614 of file raytrixdll-v5/RaytrixStreamer.cpp.

615{
616 return camBuffers[idxCam];
617}

◆ getCamBuffer() [2/2]

Rx::LFR::CImageQueue & RaytrixStreamer::getCamBuffer ( size_t  idxCam)

Get the camera buffer in the list of camera buffers.

Parameters
idxCamID of the buffer.
Returns
A copy of the buffer.

◆ getMaxDepth() [1/2]

float RaytrixStreamer::getMaxDepth ( )

Get the maximum depth.

Returns
maximum depth.

Definition at line 533 of file raytrixdll-v5/RaytrixStreamer.cpp.

533 {
534 const float ZFar = 1.3f; // -> !!! MAGIC NUMBER !!! from AcquKirt -> not used here
535 return ZFar;
536}

◆ getMaxDepth() [2/2]

float RaytrixStreamer::getMaxDepth ( )

Get the maximum depth.

Returns
maximum depth.

◆ getMinDepth() [1/2]

float RaytrixStreamer::getMinDepth ( )

Get the minimum depth.

Returns
minimum depth.

Definition at line 538 of file raytrixdll-v5/RaytrixStreamer.cpp.

538 {
539 const float ZNear = 0.4f; // -> !!! MAGIC NUMBER !!! from AcquKirt -> not used here
540 return ZNear;
541}

◆ getMinDepth() [2/2]

float RaytrixStreamer::getMinDepth ( )

Get the minimum depth.

Returns
minimum depth.

◆ getRxExtrinsicParams() [1/2]

HvtExtrinsics RaytrixStreamer::getRxExtrinsicParams ( size_t  idxCam)

Get the extrinsic parameters of the camera of ID "idxCam". The extrinsic parameters are found through the Raytrix SDK and the extrinsic file.

Parameters
idxCamID of the camera.
Returns
The extrinsic params through the structure HvtExtrinsics that is used by the Hovitron pipeline.

Definition at line 558 of file raytrixdll-v5/RaytrixStreamer.cpp.

558 {
559 HvtPosition pos;
560 HvtRotation rot;
561 unsigned isExCalib;
562 Rx::LFR::CParameters<Rx::LFR::Params::ECalib::ID>& paramsCal = camCalibrations[idxCam]->GetParams();
563 paramsCal.GetValue(Rx::LFR::Params::ECalib::IsExtrinsicCalibrated, isExCalib);
564 if (isExCalib != 1) {
565 std::cerr << "Camera " << idxCam << " is not extrinsincly calibrated... Reconstruction must be wrong." << std::endl;
566 }
567 Rx::CRxArrayDouble trans;
568 paramsCal.GetValue(Rx::LFR::Params::ECalib::Translation_Global_Sensor, trans);
569 double* dataPtr = (double*)trans.GetPointer();
570 size_t sizeData = trans.Length();
571 bool checkExParams = true;
572 if (sizeData < 1)
573 checkExParams = false;
574
575 std::ifstream jsonRead{ infoJSON.extrinsicParamsPath, std::ifstream::binary };
576 if (!jsonRead.good()) {
577 std::cout << "Impossible to read JSON extrinsic file, check path... Path given: " << infoJSON.extrinsicParamsPath << std::endl;
578 throw HVT_ERROR_NOT_FOUND;
579 }
580 nlohmann::json jsonContent;
581 jsonRead >> jsonContent;
582
583 if (checkExParams) {
584 pos.x = (float)dataPtr[2] + (double) jsonContent["cameras"][idxCam]["Position"][0]; // x is forward/backward
585 pos.y = (float)dataPtr[0] + (double) jsonContent["cameras"][idxCam]["Position"][1]; // y is left/right
586 pos.z = (float)dataPtr[1] + (double) jsonContent["cameras"][idxCam]["Position"][2]; // z is up/down
587 referencePlaneToCameraPlane[idxCam] = pos.x;
588 double data;
589 paramsCal.GetValue(Rx::LFR::Params::ECalib::Rotation_Global_Sensor_Pitch, data);
590 rot.pitch = (float)data + (double) jsonContent["cameras"][idxCam]["Rotation"][0];
591 paramsCal.GetValue(Rx::LFR::Params::ECalib::Rotation_Global_Sensor_Roll, data);
592 rot.roll = (float)data + (double) jsonContent["cameras"][idxCam]["Rotation"][1];
593 paramsCal.GetValue(Rx::LFR::Params::ECalib::Rotation_Global_Sensor_Yaw, data);
594 rot.yaw = (float)data + (double) jsonContent["cameras"][idxCam]["Rotation"][2];
595 }
596 else {
597 pos.x = 0.0f;
598 pos.y = 0.0f;
599 pos.z = 0.0f;
600 referencePlaneToCameraPlane[idxCam] = 1.0f;
601 rot.pitch = 0.0f;
602 rot.roll = 0.0f;
603 rot.yaw = 0.0f;
604 }
605 jsonRead.close();
606
607
608 HvtExtrinsics extrinsics;
609 extrinsics.position = pos;
610 extrinsics.rotation = rot;
611 return extrinsics;
612}

◆ getRxExtrinsicParams() [2/2]

HvtExtrinsics RaytrixStreamer::getRxExtrinsicParams ( size_t  idxCam)

Get the extrinsic parameters of the camera of ID "idxCam". The extrinsic parameters are found through the Raytrix SDK and the extrinsic file.

Parameters
idxCamID of the camera.
Returns
The extrinsic params through the structure HvtExtrinsics that is used by the Hovitron pipeline.

◆ getRxIntrinsicParams() [1/2]

HvtIntrinsicsPerspective RaytrixStreamer::getRxIntrinsicParams ( size_t  idxCam)

Get the intrinsic parameters of the camera of ID "idxCam". The intrinsic parameters are found through the Raytrix SDK.

Parameters
idxCamID of the camera.
Returns
The intrinsic params through the structure HvtIntrinsicsPerspective that is used by the Hovitron pipeline.

Definition at line 543 of file raytrixdll-v5/RaytrixStreamer.cpp.

543 {
544 Rx::LFR::CParameters<Rx::LFR::Params::ECalib::ID>& paramsCal = camCalibrations[idxCam]->GetParams();
545 double f, sizePixel;
546 paramsCal.GetValue(Rx::LFR::Params::ECalib::MainLensThick_NominalFocalLengthMM, f);
547 paramsCal.GetValue(Rx::LFR::Params::ECalib::Sensor_PhysicalPixelSizeMM, sizePixel);
548
549 HvtIntrinsicsPerspective intrinsicParams;
550 intrinsicParams.focalX = (float) f / (((float)widthDefault / (float)infoJSON.widthDepth) * sizePixel);
551 intrinsicParams.focalY = (float) f / (((float)heightDefault / (float)infoJSON.heightDepth) * sizePixel);
552 intrinsicParams.principlePointX = ((float)infoJSON.width) / 2.0f;
553 intrinsicParams.principlePointY = ((float)infoJSON.height) / 2.0f;
554
555 return intrinsicParams;
556}
Intrinsics parameters of a perspective projection.

◆ getRxIntrinsicParams() [2/2]

HvtIntrinsicsPerspective RaytrixStreamer::getRxIntrinsicParams ( size_t  idxCam)

Get the intrinsic parameters of the camera of ID "idxCam". The intrinsic parameters are found through the Raytrix SDK.

Parameters
idxCamID of the camera.
Returns
The intrinsic params through the structure HvtIntrinsicsPerspective that is used by the Hovitron pipeline.

◆ importSemaphore()

void RaytrixStreamer::importSemaphore ( const HvtSemaphoreExportInfo exportInfos)

Definition at line 1184 of file raytrixdll-v5/RaytrixStreamer.cpp.

1185{
1186 cudaSetDevice(vulkanGPU);
1187 if (exportInfos.semaphore == NULL)
1188 {
1189 synthesisSem->isValid = false;
1190 synthesisSem->sem = NULL;
1191 return;
1192 }
1193
1194 cudaExternalSemaphoreHandleDesc externalSemaphoreHandleDesc = {};
1195
1196 if (exportInfos.type & HvtSemaphoreType::HVT_SEMAPHORE_TYPE_OPAQUE_WIN32_BIT)
1197 {
1198 externalSemaphoreHandleDesc.type = cudaExternalSemaphoreHandleTypeOpaqueWin32;
1199 }
1200 else if (exportInfos.type & HvtSemaphoreType::HVT_SEMAPHORE_TYPE_OPAQUE_WIN32_KMT_BIT)
1201 {
1202 externalSemaphoreHandleDesc.type = cudaExternalSemaphoreHandleTypeOpaqueWin32Kmt;
1203 }
1204 else if (exportInfos.type & HvtSemaphoreType::HVT_SEMAPHORE_TYPE_SYNC_FD_BIT)
1205 {
1206 externalSemaphoreHandleDesc.type = cudaExternalSemaphoreHandleTypeOpaqueFd;
1207 }
1208
1209 externalSemaphoreHandleDesc.handle.win32.handle = (HANDLE)exportInfos.semaphore;
1210 externalSemaphoreHandleDesc.flags = 0;
1211
1212 cudaImportExternalSemaphore(&synthesisSem->sem, &externalSemaphoreHandleDesc);
1213 synthesisSem->isValid = true;
1214 // cudaWaitExternalSemaphoresAsync();
1215}

◆ importStreamImages()

void RaytrixStreamer::importStreamImages ( const HvtStreamImagesExportInfo exportInfos)

Definition at line 1108 of file raytrixdll-v5/RaytrixStreamer.cpp.

1109{
1110 cudaSetDevice(vulkanGPU);
1111 auto isDepth = (bool)exportInfos.depth;
1112 auto& stream = readStreams.at(exportInfos.streamIndex);
1113 //auto format = isDepth ? stream.depthFormat : stream.colorFormat;
1114 // auto size = isDepth ? stream.depthFrameSize : stream.colorFrameSize;
1115 auto& slots = isDepth ? stream.depthSlots : stream.colorSlots;
1116 auto mipLevels = 1;
1117
1118 // std::cout << "Init memory buffers CUDA" << std::endl;
1119
1120 if (exportInfos.imagesCount != numSlots)
1121 {
1122 throw HvtResult::HVT_ERROR_WRONG_BUFFER_SIZE;
1123 }
1124
1125 for (int i = 0; i < numSlots; ++i)
1126 {
1127 auto mem = exportInfos.pImages[i];
1128 // std::cout << "External Memory loop" << std::endl;
1129
1130 cudaExternalMemory_t cudaExtMemImageBuffer;
1131 cudaMipmappedArray_t cudaMipmappedImageArray;
1132
1133 cudaExternalMemoryHandleDesc cudaExtMemHandleDesc;
1134 memset(&cudaExtMemHandleDesc, 0, sizeof(cudaExtMemHandleDesc));
1135
1136 cudaExtMemHandleDesc.type = cudaExternalMemoryHandleTypeOpaqueWin32;
1137 cudaExtMemHandleDesc.handle.win32.handle = (HANDLE)mem.handle;
1138 cudaExtMemHandleDesc.size = mem.size;
1139
1140 gpuErrchk(cudaImportExternalMemory(&cudaExtMemImageBuffer, &cudaExtMemHandleDesc));
1141
1142 cudaExternalMemoryMipmappedArrayDesc externalMemoryMipmappedArrayDesc;
1143 memset(&externalMemoryMipmappedArrayDesc, 0, sizeof(externalMemoryMipmappedArrayDesc));
1144
1145 cudaExtent extent = isDepth ? make_cudaExtent(stream.width_depth, stream.height_depth, 0) : make_cudaExtent(stream.width_color, stream.height_color, 0);
1146 cudaChannelFormatDesc formatDesc;
1147 formatDesc.x = isDepth ? 32 : 8;
1148 formatDesc.y = isDepth ? 0 : 8;
1149 formatDesc.z = isDepth ? 0 : 8;
1150 formatDesc.w = isDepth ? 0 : 8;
1151 formatDesc.f = isDepth ? cudaChannelFormatKindFloat : cudaChannelFormatKindUnsigned;
1152
1153 externalMemoryMipmappedArrayDesc.offset = 0;
1154 externalMemoryMipmappedArrayDesc.formatDesc = formatDesc;
1155 externalMemoryMipmappedArrayDesc.extent = extent;
1156 externalMemoryMipmappedArrayDesc.flags = 0;
1157 externalMemoryMipmappedArrayDesc.numLevels = mipLevels;
1158
1159 gpuErrchk(cudaExternalMemoryGetMappedMipmappedArray(&cudaMipmappedImageArray, cudaExtMemImageBuffer, &externalMemoryMipmappedArrayDesc));
1160
1161 cudaArray_t cudaMipLevelArray;
1162 cudaResourceDesc resourceDesc;
1163
1164 gpuErrchk(cudaGetMipmappedArrayLevel(&cudaMipLevelArray, cudaMipmappedImageArray, 0));
1165 // cudaMemcpy2DArrayToArray(cudaMipLevelArray, 0, 0, cudaMipLevelArray, 0, 0, stream.width * sizeof(uchar4), stream.height, cudaMemcpyDeviceToDevice);
1166
1167 memset(&resourceDesc, 0, sizeof(resourceDesc));
1168 resourceDesc.resType = cudaResourceTypeArray;
1169 resourceDesc.res.array.array = cudaMipLevelArray;
1170
1171 cudaSurfaceObject_t surfaceObject;
1172 gpuErrchk(cudaCreateSurfaceObject(&surfaceObject, &resourceDesc));
1173
1174 ImageSlot IS;
1175 IS.size = mem.size;
1176 IS.vk_handle = &mem.handle;
1177 IS.cuda_ptr_surf = surfaceObject;
1178
1179 slots.at(i) = IS;
1180 }
1181 (isDepth ? stream.importedDepth : stream.importedColor) = true;
1182}

◆ releaseStreamsFrames()

void RaytrixStreamer::releaseStreamsFrames ( Semaphore waitSem)

Definition at line 1266 of file raytrixdll-v5/RaytrixStreamer.cpp.

1267{
1268 std::cout << "release frames" << std::endl;
1269}

◆ startStreaming()

void RaytrixStreamer::startStreaming ( )

Definition at line 1223 of file raytrixdll-v5/RaytrixStreamer.cpp.

1224{
1225 //cudaSetDevice(vulkanGPU);
1226 // assert that we have everything ready for streaming
1227 for (auto& stream : readStreams)
1228 {
1229 if (!stream.importedColor || !stream.importedDepth)
1230 {
1231 throw HvtResult::HVT_ERROR_CALL_ORDER;
1232 }
1233 }
1234
1235 // Start worker
1236 running = true;
1237 std::cout << "Starting streaming" << std::endl;
1238 streamingThread = std::thread([&]
1239 { streamingLoop(); });
1240}

◆ stopStreaming()

void RaytrixStreamer::stopStreaming ( )

Definition at line 1271 of file raytrixdll-v5/RaytrixStreamer.cpp.

1272{
1273 cudaSetDevice(vulkanGPU);
1274 running = false;
1275 if (streamingThread.joinable())
1276 {
1277 streamingThread.join();
1278 }
1279}

The documentation for this class was generated from the following files: