From e1dd59f749f78fafdeed898a60b664de8fb62242 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 9 Oct 2021 18:57:27 +0100 Subject: [PATCH] d/dai: Refactor out pipeline setup to helper function --- src/xrt/drivers/depthai/depthai_driver.cpp | 168 +++++++++++---------- 1 file changed, 88 insertions(+), 80 deletions(-) diff --git a/src/xrt/drivers/depthai/depthai_driver.cpp b/src/xrt/drivers/depthai/depthai_driver.cpp index dc41acb1d..d9e81eac1 100644 --- a/src/xrt/drivers/depthai/depthai_driver.cpp +++ b/src/xrt/drivers/depthai/depthai_driver.cpp @@ -298,6 +298,91 @@ depthai_destroy(struct depthai_fs *depthai) return true; } +static void +depthai_setup_single_pipeline(struct depthai_fs *depthai, enum depthai_camera_type camera_type) +{ + switch (camera_type) { +#if 0 + case (RGB_OV_9782): + depthai->width = 1280; + depthai->height = 800; + depthai->format = XRT_FORMAT_R8G8B8; + depthai->color_sensor_resoultion = dai::ColorCameraProperties::SensorResolution::THE_800_P; + depthai->image_orientation = dai::CameraImageOrientation::ROTATE_180_DEG; + depthai->fps = 60; // Currently only supports 60. + depthai->interleaved = true; + depthai->color_order = dai::ColorCameraProperties::ColorOrder::RGB; + break; +#endif + case (RGB_IMX_378): + depthai->width = 1920; + depthai->height = 1080; + depthai->format = XRT_FORMAT_R8G8B8; + depthai->color_sensor_resoultion = dai::ColorCameraProperties::SensorResolution::THE_1080_P; + depthai->image_orientation = dai::CameraImageOrientation::AUTO; + depthai->fps = 118; // Actual max. + depthai->interleaved = true; + depthai->color_order = dai::ColorCameraProperties::ColorOrder::RGB; + break; + case (MONO_OV_9282_L): + depthai->width = 1280; + depthai->height = 800; + depthai->format = XRT_FORMAT_L8; + depthai->camera_board_socket = dai::CameraBoardSocket::LEFT; + depthai->mono_sensor_resoultion = dai::MonoCameraProperties::SensorResolution::THE_800_P; + depthai->image_orientation = dai::CameraImageOrientation::AUTO; + depthai->fps = 60; // Currently only supports 60. + break; + case (MONO_OV_9282_R): + depthai->width = 1280; + depthai->height = 800; + depthai->format = XRT_FORMAT_L8; + depthai->camera_board_socket = dai::CameraBoardSocket::RIGHT; + depthai->mono_sensor_resoultion = dai::MonoCameraProperties::SensorResolution::THE_800_P; + depthai->image_orientation = dai::CameraImageOrientation::AUTO; + depthai->fps = 60; // Currently only supports 60. + break; + default: assert(false); + } + + dai::Pipeline p = {}; + + auto xlinkOut = p.create(); + xlinkOut->setStreamName("preview"); + + std::shared_ptr colorCam = nullptr; + std::shared_ptr monoCam = nullptr; + + if (depthai->format == XRT_FORMAT_R8G8B8) { + colorCam = p.create(); + colorCam->setPreviewSize(depthai->width, depthai->height); + colorCam->setResolution(depthai->color_sensor_resoultion); + colorCam->setImageOrientation(depthai->image_orientation); + colorCam->setInterleaved(depthai->interleaved); + colorCam->setFps(depthai->fps); + colorCam->setColorOrder(depthai->color_order); + + // Link plugins CAM -> XLINK + colorCam->preview.link(xlinkOut->input); + } + + if (depthai->format == XRT_FORMAT_L8) { + monoCam = p.create(); + monoCam->setBoardSocket(depthai->camera_board_socket); + monoCam->setResolution(depthai->mono_sensor_resoultion); + monoCam->setImageOrientation(depthai->image_orientation); + monoCam->setFps(depthai->fps); + + // Link plugins CAM -> XLINK + monoCam->out.link(xlinkOut->input); + } + + + // Start the pipeline + depthai->device->startPipeline(p); + depthai->queue = depthai->device->getOutputQueue("preview", 1, false).get(); // out of shared pointer +} + /* * @@ -448,50 +533,6 @@ depthai_fs_single_rgb(struct xrt_frame_context *xfctx) enum depthai_camera_type camera_type = RGB_IMX_378; - switch (camera_type) { -#if 0 - case (RGB_OV_9782): - depthai->width = 1280; - depthai->height = 800; - depthai->format = XRT_FORMAT_R8G8B8; - depthai->color_sensor_resoultion = dai::ColorCameraProperties::SensorResolution::THE_800_P; - depthai->image_orientation = dai::CameraImageOrientation::ROTATE_180_DEG; - depthai->fps = 60; // Currently only supports 60. - depthai->interleaved = true; - depthai->color_order = dai::ColorCameraProperties::ColorOrder::RGB; - break; -#endif - case (RGB_IMX_378): - depthai->width = 1920; - depthai->height = 1080; - depthai->format = XRT_FORMAT_R8G8B8; - depthai->color_sensor_resoultion = dai::ColorCameraProperties::SensorResolution::THE_1080_P; - depthai->image_orientation = dai::CameraImageOrientation::AUTO; - depthai->fps = 118; // Actual max. - depthai->interleaved = true; - depthai->color_order = dai::ColorCameraProperties::ColorOrder::RGB; - break; - case (MONO_OV_9282_L): - depthai->width = 1280; - depthai->height = 800; - depthai->format = XRT_FORMAT_L8; - depthai->camera_board_socket = dai::CameraBoardSocket::LEFT; - depthai->mono_sensor_resoultion = dai::MonoCameraProperties::SensorResolution::THE_800_P; - depthai->image_orientation = dai::CameraImageOrientation::AUTO; - depthai->fps = 60; // Currently only supports 60. - break; - case (MONO_OV_9282_R): - depthai->width = 1280; - depthai->height = 800; - depthai->format = XRT_FORMAT_L8; - depthai->camera_board_socket = dai::CameraBoardSocket::RIGHT; - depthai->mono_sensor_resoultion = dai::MonoCameraProperties::SensorResolution::THE_800_P; - depthai->image_orientation = dai::CameraImageOrientation::AUTO; - depthai->fps = 60; // Currently only supports 60. - break; - default: assert(false); - } - // Some debug printing. depthai_print_connected_cameras(depthai); depthai_print_calib(depthai); @@ -499,43 +540,10 @@ depthai_fs_single_rgb(struct xrt_frame_context *xfctx) // Make sure that the thread helper is initialised. os_thread_helper_init(&depthai->play_thread); - dai::Pipeline p = {}; - - auto xlinkOut = p.create(); - xlinkOut->setStreamName("preview"); - - std::shared_ptr colorCam = nullptr; - std::shared_ptr monoCam = nullptr; - - if (depthai->format == XRT_FORMAT_R8G8B8) { - colorCam = p.create(); - colorCam->setPreviewSize(depthai->width, depthai->height); - colorCam->setResolution(depthai->color_sensor_resoultion); - colorCam->setImageOrientation(depthai->image_orientation); - colorCam->setInterleaved(depthai->interleaved); - colorCam->setFps(depthai->fps); - colorCam->setColorOrder(depthai->color_order); - - // Link plugins CAM -> XLINK - colorCam->preview.link(xlinkOut->input); - } - - if (depthai->format == XRT_FORMAT_L8) { - monoCam = p.create(); - monoCam->setBoardSocket(depthai->camera_board_socket); - monoCam->setResolution(depthai->mono_sensor_resoultion); - monoCam->setImageOrientation(depthai->image_orientation); - monoCam->setFps(depthai->fps); - - // Link plugins CAM -> XLINK - monoCam->out.link(xlinkOut->input); - } - - - // Start the pipeline - d->startPipeline(p); - depthai->queue = d->getOutputQueue("preview", 1, false).get(); // out of shared pointer + // Last bit is to setup the pipeline. + depthai_setup_single_pipeline(depthai, camera_type); + // And finally add us to the context when we are done. xrt_frame_context_add(xfctx, &depthai->node); DEPTHAI_DEBUG(depthai, "DepthAI: Created");