The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/vf: Refactor code to add videotestsrc capability and break out gstreamer detection

+113 -64
+4 -1
CMakeLists.txt
··· 128 128 cmake_dependent_option(XRT_HAVE_OPENGLES "Enable OpenGL-ES Graphics API support" ON "OpenGLES_FOUND" OFF) 129 129 cmake_dependent_option(XRT_HAVE_EGL "Enable OpenGL on EGL Graphics API support" ON "EGL_FOUND; XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES" OFF) 130 130 cmake_dependent_option(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" ON "DBUS_FOUND" OFF) 131 - cmake_dependent_option(XRT_HAVE_VF "Enable gstreamer support (for video file support)" ON "GST_FOUND" OFF) 132 131 cmake_dependent_option(XRT_FEATURE_COMPOSITOR_MAIN "Build main compositor host functionality" ON "XRT_HAVE_VULKAN; XRT_HAVE_WAYLAND OR XRT_HAVE_XCB OR ANDROID OR WIN32" OFF) 133 132 cmake_dependent_option(XRT_FEATURE_OPENXR "Build OpenXR runtime target" ON "XRT_FEATURE_COMPOSITOR_MAIN" OFF) 134 133 cmake_dependent_option(XRT_FEATURE_SERVICE "Enable separate service module for OpenXR runtime" ON "NOT WIN32" OFF) ··· 172 171 cmake_dependent_option(XRT_HAVE_FFMPEG "Enable ffmpeg testing video driver" ON "FFMPEG_FOUND" OFF) 173 172 cmake_dependent_option(XRT_HAVE_SDL2 "Enable use of SDL2" ON "SDL2_FOUND AND XRT_HAVE_OPENGL" OFF) 174 173 cmake_dependent_option(XRT_HAVE_SYSTEM_CJSON "Enable cJSON from system, instead of bundled source" ON "CJSON_FOUND" OFF) 174 + cmake_dependent_option(XRT_HAVE_GST "Enable gstreamer" ON "GST_FOUND" OFF) 175 175 176 176 177 177 cmake_dependent_option(XRT_BUILD_DRIVER_PSVR "Enable PSVR HMD driver" ON "HIDAPI_FOUND" OFF) ··· 191 191 cmake_dependent_option(XRT_BUILD_DRIVER_PSMV "Enable Playstation Move driver" ON "XRT_HAVE_INTERNAL_HID" OFF) 192 192 cmake_dependent_option(XRT_BUILD_DRIVER_HYDRA "Enable Hydra driver" ON "XRT_HAVE_INTERNAL_HID" OFF) 193 193 cmake_dependent_option(XRT_BUILD_DRIVER_NS "Enable North Star driver" ON "XRT_HAVE_INTERNAL_HID" OFF) 194 + cmake_dependent_option(XRT_BUILD_DRIVER_VF "Build video frame driver (for video file support, uses gstreamer)" ON "XRT_HAVE_GST" OFF) 194 195 195 196 # This one defaults to off, even if we find the deps. 196 197 cmake_dependent_option(XRT_BUILD_DRIVER_SURVIVE "Enable libsurvive driver" ON "SURVIVE_FOUND" OFF) ··· 216 217 "REMOTE" 217 218 "SURVIVE" 218 219 "V4L2" 220 + "VF" 219 221 "VIVE" 220 222 ) 221 223 ··· 348 350 message(STATUS "# DRIVER_RS: ${XRT_BUILD_DRIVER_RS}") 349 351 message(STATUS "# DRIVER_REMOTE: ${XRT_BUILD_DRIVER_REMOTE}") 350 352 message(STATUS "# DRIVER_SURVIVE: ${XRT_BUILD_DRIVER_SURVIVE}") 353 + message(STATUS "# DRIVER_VF: ${XRT_BUILD_DRIVER_VF}") 351 354 message(STATUS "# DRIVER_VIVE: ${XRT_BUILD_DRIVER_VIVE}") 352 355 message(STATUS "#####----- Config -----#####")
+1 -1
src/xrt/drivers/CMakeLists.txt
··· 192 192 list(APPEND ENABLED_DRIVERS v4l2) 193 193 endif() 194 194 195 - if(XRT_HAVE_VF) 195 + if(XRT_BUILD_DRIVER_VF) 196 196 set(VF_SOURCE_FILES 197 197 vf/vf_driver.c 198 198 )
+90 -49
src/xrt/drivers/vf/vf_driver.c
··· 61 61 62 62 struct os_thread_helper play_thread; 63 63 64 - const char *path; 65 64 GMainLoop *loop; 66 65 GstElement *source; 67 66 GstElement *testsink; ··· 280 279 gst_structure_get_int(structure, "width", &width); 281 280 gst_structure_get_int(structure, "height", &height); 282 281 283 - VF_DEBUG(vid, "video size is %dx%d\n", width, height); 282 + VF_DEBUG(vid, "video size is %dx%d", width, height); 284 283 vid->got_sample = true; 285 284 vid->width = width; 286 285 vid->height = height; ··· 303 302 gchar *dbg_info = NULL; 304 303 305 304 gst_message_parse_error(message, &err, &dbg_info); 306 - U_LOG_E("ERROR from element %s: %s\n", GST_OBJECT_NAME(message->src), err->message); 307 - U_LOG_E("Debugging info: %s\n", (dbg_info) ? dbg_info : "none"); 305 + U_LOG_E("ERROR from element %s: %s", GST_OBJECT_NAME(message->src), err->message); 306 + U_LOG_E("Debugging info: %s", (dbg_info) ? dbg_info : "none"); 308 307 g_error_free(err); 309 308 g_free(dbg_info); 310 309 } ··· 315 314 /* nil */ 316 315 switch (GST_MESSAGE_TYPE(message)) { 317 316 case GST_MESSAGE_EOS: 318 - VF_DEBUG(vid, "Finished playback\n"); 317 + VF_DEBUG(vid, "Finished playback."); 319 318 g_main_loop_quit(vid->loop); 320 319 break; 321 320 case GST_MESSAGE_ERROR: 322 - VF_ERROR(vid, "Received error\n"); 321 + VF_ERROR(vid, "Received error."); 323 322 print_gst_error(message); 324 323 g_main_loop_quit(vid->loop); 325 324 break; ··· 333 332 { 334 333 struct vf_fs *vid = (struct vf_fs *)ptr; 335 334 336 - VF_DEBUG(vid, "Let's run!\n"); 335 + VF_DEBUG(vid, "Let's run!"); 337 336 g_main_loop_run(vid->loop); 338 - VF_DEBUG(vid, "Going out\n"); 337 + VF_DEBUG(vid, "Going out!"); 339 338 340 339 gst_object_unref(vid->testsink); 341 340 gst_element_set_state(vid->source, GST_STATE_NULL); ··· 347 346 return NULL; 348 347 } 349 348 350 - struct xrt_fs * 351 - vf_fs_create(struct xrt_frame_context *xfctx, const char *path) 349 + static struct xrt_fs * 350 + alloc_and_init_common(struct xrt_frame_context *xfctx, // 351 + enum xrt_format format, // 352 + enum xrt_stereo_format stereo_format, // 353 + gchar *pipeline_string) // 352 354 { 353 - if (path == NULL) { 354 - U_LOG_E("No path given"); 355 - return NULL; 356 - } 357 - 358 - 359 355 struct vf_fs *vid = U_TYPED_CALLOC(struct vf_fs); 360 - vid->path = path; 361 356 vid->got_sample = false; 362 - 363 - gchar *loop = "false"; 357 + vid->format = format; 358 + vid->stereo_format = stereo_format; 364 359 365 - gchar *string = NULL; 366 360 GstBus *bus = NULL; 367 361 368 - 369 - gst_init(0, NULL); 370 - 371 - if (!g_file_test(path, G_FILE_TEST_EXISTS)) { 372 - VF_ERROR(vid, "File %s does not exist\n", path); 362 + int ret = os_thread_helper_init(&vid->play_thread); 363 + if (ret < 0) { 364 + VF_ERROR(vid, "Failed to init thread"); 365 + g_free(pipeline_string); 366 + free(vid); 373 367 return NULL; 374 368 } 375 369 376 370 vid->loop = g_main_loop_new(NULL, FALSE); 377 - 378 - #if 0 379 - const gchar *caps = "video/x-raw,format=RGB"; 380 - vid->format = XRT_FORMAT_R8G8B8; 381 - vid->stereo_format = XRT_STEREO_FORMAT_SBS; 382 - #endif 383 - 384 - #if 1 385 - const gchar *caps = "video/x-raw,format=YUY2"; 386 - vid->format = XRT_FORMAT_YUYV422; 387 - vid->stereo_format = XRT_STEREO_FORMAT_SBS; 388 - #endif 371 + VF_DEBUG(vid, "Pipeline: %s", pipeline_string); 389 372 390 - string = g_strdup_printf( 391 - "multifilesrc location=\"%s\" loop=%s ! decodebin ! videoconvert ! " 392 - "appsink caps=\"%s\" name=testsink", 393 - path, loop, caps); 394 - VF_DEBUG(vid, "Pipeline: %s\n", string); 395 - vid->source = gst_parse_launch(string, NULL); 396 - g_free(string); 373 + vid->source = gst_parse_launch(pipeline_string, NULL); 374 + g_free(pipeline_string); 397 375 398 376 if (vid->source == NULL) { 399 - VF_ERROR(vid, "Bad source\n"); 377 + VF_ERROR(vid, "Bad source"); 400 378 g_main_loop_unref(vid->loop); 401 379 free(vid); 402 380 return NULL; ··· 410 388 gst_bus_add_watch(bus, (GstBusFunc)on_source_message, vid); 411 389 gst_object_unref(bus); 412 390 413 - int ret = os_thread_helper_start(&vid->play_thread, run_play_thread, vid); 414 - if (!ret) { 415 - VF_ERROR(vid, "Failed to start thread"); 391 + ret = os_thread_helper_start(&vid->play_thread, run_play_thread, vid); 392 + if (ret != 0) { 393 + VF_ERROR(vid, "Failed to start thread '%i'", ret); 394 + g_main_loop_unref(vid->loop); 395 + free(vid); 396 + return NULL; 416 397 } 417 398 418 - // we need one sample to determine frame size 399 + // We need one sample to determine frame size. 400 + VF_DEBUG(vid, "Waiting for frame"); 419 401 gst_element_set_state(vid->source, GST_STATE_PLAYING); 420 402 while (!vid->got_sample) { 421 403 os_nanosleep(100 * 1000 * 1000); 422 404 } 405 + VF_DEBUG(vid, "Got first sample"); 423 406 gst_element_set_state(vid->source, GST_STATE_PAUSED); 424 407 425 408 vid->base.enumerate_modes = vf_fs_enumerate_modes; ··· 443 426 444 427 return &(vid->base); 445 428 } 429 + 430 + struct xrt_fs * 431 + vf_fs_videotestsource(struct xrt_frame_context *xfctx, uint32_t width, uint32_t height) 432 + { 433 + gst_init(0, NULL); 434 + 435 + enum xrt_format format = XRT_FORMAT_R8G8B8; 436 + enum xrt_stereo_format stereo_format = XRT_STEREO_FORMAT_NONE; 437 + 438 + gchar *pipeline_string = g_strdup_printf( 439 + "videotestsrc name=source ! " 440 + "videoconvert ! " 441 + "videoscale ! " 442 + "video/x-raw,format=RGB,width=%u,height=%u ! " 443 + "appsink name=testsink", 444 + width, height); 445 + 446 + return alloc_and_init_common(xfctx, format, stereo_format, pipeline_string); 447 + } 448 + 449 + struct xrt_fs * 450 + vf_fs_open_file(struct xrt_frame_context *xfctx, const char *path) 451 + { 452 + if (path == NULL) { 453 + U_LOG_E("No path given"); 454 + return NULL; 455 + } 456 + 457 + gst_init(0, NULL); 458 + 459 + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { 460 + U_LOG_E("File %s does not exist", path); 461 + return NULL; 462 + } 463 + 464 + #if 0 465 + const gchar *caps = "video/x-raw,format=RGB"; 466 + enum xrt_format format = XRT_FORMAT_R8G8B8; 467 + enum xrt_stereo_format stereo_format = XRT_STEREO_FORMAT_NONE; 468 + #endif 469 + 470 + #if 1 471 + const gchar *caps = "video/x-raw,format=YUY2"; 472 + enum xrt_format format = XRT_FORMAT_YUYV422; 473 + enum xrt_stereo_format stereo_format = XRT_STEREO_FORMAT_SBS; 474 + #endif 475 + 476 + gchar *loop = "false"; 477 + 478 + gchar *pipeline_string = g_strdup_printf( 479 + "multifilesrc location=\"%s\" loop=%s ! " 480 + "decodebin ! " 481 + "videoconvert ! " 482 + "appsink caps=\"%s\" name=testsink", 483 + path, loop, caps); 484 + 485 + return alloc_and_init_common(xfctx, format, stereo_format, pipeline_string); 486 + }
+13 -4
src/xrt/drivers/vf/vf_interface.h
··· 1 - // Copyright 2029, Collabora, Ltd. 1 + // Copyright 2020-2021, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 10 10 #pragma once 11 11 12 12 #include "xrt/xrt_frameserver.h" 13 + 13 14 14 15 #ifdef __cplusplus 15 16 extern "C" { ··· 23 24 */ 24 25 25 26 /*! 26 - * Create a vf frameserver 27 + * Create a vf frameserver by opening a video file. 28 + * 29 + * @ingroup drv_vf 30 + */ 31 + struct xrt_fs * 32 + vf_fs_open_file(struct xrt_frame_context *xfctx, const char *path); 33 + 34 + /*! 35 + * Create a vf frameserver that uses the videotestsource. 27 36 * 28 37 * @ingroup drv_vf 29 38 */ 30 39 struct xrt_fs * 31 - vf_fs_create(struct xrt_frame_context *xfctx, const char *path); 40 + vf_fs_videotestsource(struct xrt_frame_context *xfctx, uint32_t width, uint32_t height); 41 + 32 42 33 43 #ifdef __cplusplus 34 44 } 35 - 36 45 #endif
-4
src/xrt/include/xrt/meson.build
··· 68 68 have_conf.set('XRT_HAVE_V4L2', true) 69 69 endif 70 70 71 - if 'vf' in drivers 72 - have_conf.set('XRT_HAVE_VF', true) 73 - endif 74 - 75 71 if true 76 72 have_conf.set('XRT_HAVE_VULKAN', true) 77 73 endif
+1 -1
src/xrt/include/xrt/xrt_config_have.h.cmake_in
··· 10 10 #pragma once 11 11 12 12 #cmakedefine XRT_HAVE_DBUS 13 - #cmakedefine XRT_HAVE_VF 14 13 #cmakedefine XRT_HAVE_EGL 15 14 #cmakedefine XRT_HAVE_FFMPEG 15 + #cmakedefine XRT_HAVE_GST 16 16 #cmakedefine XRT_HAVE_JPEG 17 17 #cmakedefine XRT_HAVE_LIBUDEV 18 18 #cmakedefine XRT_HAVE_LIBUSB
+3 -3
src/xrt/state_trackers/prober/p_prober.c
··· 20 20 #include "v4l2/v4l2_interface.h" 21 21 #endif 22 22 23 - #ifdef XRT_HAVE_VF 23 + #ifdef XRT_BUILD_DRIVER_VF 24 24 #include "vf/vf_interface.h" 25 25 #endif 26 26 ··· 742 742 { 743 743 XRT_MAYBE_UNUSED struct prober_device *pdev = (struct prober_device *)xpdev; 744 744 745 - #if defined(XRT_HAVE_VF) 745 + #if defined(XRT_BUILD_DRIVER_VF) 746 746 const char *path = debug_get_option_vf_path(); 747 747 if (path != NULL) { 748 - struct xrt_fs *xfs = vf_fs_create(xfctx, path); 748 + struct xrt_fs *xfs = vf_fs_open_file(xfctx, path); 749 749 if (xfs) { 750 750 *out_xfs = xfs; 751 751 return 0;
+1 -1
src/xrt/targets/common/CMakeLists.txt
··· 72 72 target_link_libraries(target_lists PRIVATE drv_v4l2) 73 73 endif() 74 74 75 - if(XRT_HAVE_VF) 75 + if(XRT_BUILD_DRIVER_VF) 76 76 target_link_libraries(target_lists PRIVATE drv_vf) 77 77 endif() 78 78