st/gui: Add support for depthAI camera in record scene

Co-authored-by: Jakob Bornecrantz <jakob@collabora.com>
This commit is contained in:
Moses Turner 2021-06-10 14:31:42 -05:00
parent 37cbbb6660
commit d555b255fe
4 changed files with 85 additions and 3 deletions

View file

@ -67,6 +67,12 @@ if(XRT_HAVE_GST)
)
endif()
if(XRT_BUILD_DRIVER_DEPTHAI)
target_link_libraries(st_gui PRIVATE
drv_depthai
)
endif()
if(XRT_BUILD_DRIVER_REMOTE)
target_link_libraries(st_gui PRIVATE
drv_remote

View file

@ -51,12 +51,16 @@ scene_render(struct gui_scene *scene, struct gui_program *p)
gui_scene_debug(p);
}
if (igButton("Record (DepthAI)", button_dims)) {
gui_scene_delete_me(p, scene);
gui_scene_record(p, "depthai");
}
if (igButton("Record (Index)", button_dims)) {
gui_scene_delete_me(p, scene);
gui_scene_record(p, "index");
}
if (igButton("Record (Leap Motion)", button_dims)) {
gui_scene_delete_me(p, scene);
gui_scene_record(p, "leap_motion");

View file

@ -35,6 +35,10 @@
#include "vf/vf_interface.h"
#endif
#ifdef XRT_BUILD_DRIVER_DEPTHAI
#include "depthai/depthai_interface.h"
#endif
#include "gui_common.h"
#include "gui_imgui.h"
@ -65,8 +69,12 @@ struct record_window
struct
{
// Use DepthAI camera.
bool depthai;
// Use leap_motion.
bool leap_motion;
// Use index.
bool index;
} use;
@ -372,9 +380,13 @@ window_create(struct gui_program *p, const char *camera)
rw->sink.push_frame = window_frame;
rw->use.index = camera == NULL ? false : strcmp(camera, "index") == 0;
rw->use.leap_motion = camera == NULL ? false : strcmp(camera, "leap_motion") == 0;
rw->use.depthai = camera == NULL ? false : strcmp(camera, "depthai") == 0;
if (!rw->use.index && !rw->use.leap_motion) {
U_LOG_W("Can't recongnize camera name '%s', options are 'index' & 'leap_motion'", camera);
if (!rw->use.index && !rw->use.leap_motion && !rw->use.depthai) {
U_LOG_W(
"Can't recongnize camera name '%s', options are 'depthai', index' & 'leap_motion'."
"\n\tFalling back to 'index'.",
camera);
rw->use.index = true;
}
@ -399,6 +411,56 @@ window_create(struct gui_program *p, const char *camera)
}
/*
*
* DepthAI functions
*
*/
#ifdef XRT_BUILD_DRIVER_DEPTHAI
static void
create_depthai(struct record_window *rw)
{
// Should we be using a DepthAI camera?
if (!rw->use.depthai) {
return;
}
rw->camera.xfs = depthai_fs_single_rgb(&rw->camera.xfctx);
// Just after the camera create a quirk stream.
struct u_sink_quirk_params qp;
U_ZERO(&qp);
qp.stereo_sbs = false;
qp.ps4_cam = false;
qp.leap_motion = false;
struct xrt_frame_sink *tmp = &rw->sink;
u_sink_quirk_create(&rw->camera.xfctx, tmp, &qp, &tmp);
struct xrt_fs_mode *modes = NULL;
uint32_t mode_count = 0;
xrt_fs_enumerate_modes(rw->camera.xfs, &modes, &mode_count);
assert(mode_count > 0);
// Just use the first one.
uint32_t mode_index = 0;
rw->camera.mode = modes[mode_index];
free(modes);
modes = NULL;
// Now that we have setup a node graph, start it.
xrt_fs_stream_start(rw->camera.xfs, tmp, 0, XRT_FS_CAPTURE_TYPE_TRACKING);
// If it's a large mode, scale to 50%
if (rw->camera.mode.width > 640) {
rw->texture.scale = 2;
}
}
#endif /* XRT_BUILD_DRIVER_DEPTHAI */
/*
*
* Video frame functions
@ -572,6 +634,12 @@ gui_scene_record(struct gui_program *p, const char *camera)
rs->window = window_create(p, camera);
#ifdef XRT_BUILD_DRIVER_DEPTHAI
if (!window_has_source(rs->window)) {
create_depthai(rs->window);
}
#endif
if (!window_has_source(rs->window)) {
xrt_prober_list_video_devices(p->xp, on_video_device, rs->window);
}

View file

@ -46,6 +46,10 @@ if 'vf' in drivers
gui_deps += [drv_vf]
endif
if 'depthai' in drivers
gui_deps += [drv_depthai]
endif
lib_st_gui = static_library(
'st_gui',
files(gui_sources),