xrt: Add interface to prober to open video devices

This commit is contained in:
Jakob Bornecrantz 2019-09-02 13:25:52 +01:00
parent 3b1abffa2d
commit c021199b98
3 changed files with 58 additions and 0 deletions

View file

@ -24,6 +24,8 @@ extern "C" {
* *
*/ */
struct xrt_fs;
struct xrt_frame_context;
struct xrt_prober; struct xrt_prober;
struct xrt_prober_device; struct xrt_prober_device;
@ -144,6 +146,10 @@ struct xrt_prober
struct xrt_prober_device *xpdev, struct xrt_prober_device *xpdev,
int interface, int interface,
struct os_hid_device **out_hid_dev); struct os_hid_device **out_hid_dev);
int (*open_video_device)(struct xrt_prober *xp,
struct xrt_prober_device *xpdev,
struct xrt_frame_context *xfctx,
struct xrt_fs **out_xfs);
int (*list_video_devices)(struct xrt_prober *xp, int (*list_video_devices)(struct xrt_prober *xp,
xrt_prober_list_video_cb cb, xrt_prober_list_video_cb cb,
void *ptr); void *ptr);
@ -220,6 +226,20 @@ xrt_prober_get_string_descriptor(struct xrt_prober *xp,
length); length);
} }
/*!
* Helper function for @ref xrt_prober::xrt_prober_open_video_device.
*
* @ingroup xrt_iface
*/
XRT_MAYBE_UNUSED static inline int
xrt_prober_open_video_device(struct xrt_prober *xp,
struct xrt_prober_device *xpdev,
struct xrt_frame_context *xfctx,
struct xrt_fs **out_xfs)
{
return xp->open_video_device(xp, xpdev, xfctx, out_xfs);
}
/*! /*!
* Helper function for @ref xrt_prober::list_video_devices. * Helper function for @ref xrt_prober::list_video_devices.
* *

View file

@ -4,6 +4,7 @@
include_directories( include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../include ${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../auxiliary ${CMAKE_CURRENT_SOURCE_DIR}/../../auxiliary
${CMAKE_CURRENT_SOURCE_DIR}/../../drivers
${CMAKE_CURRENT_SOURCE_DIR}/../../../external ${CMAKE_CURRENT_SOURCE_DIR}/../../../external
) )

View file

@ -12,6 +12,10 @@
#include "util/u_debug.h" #include "util/u_debug.h"
#include "p_prober.h" #include "p_prober.h"
#ifdef XRT_OS_LINUX
#include "v4l2/v4l2_interface.h"
#endif
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -54,6 +58,12 @@ open_hid_interface(struct xrt_prober* xp,
int interface, int interface,
struct os_hid_device** out_hid_dev); struct os_hid_device** out_hid_dev);
static int
open_video_device(struct xrt_prober* xp,
struct xrt_prober_device* xpdev,
struct xrt_frame_context* xfctx,
struct xrt_fs** out_xfs);
static int static int
list_video_devices(struct xrt_prober* xp, list_video_devices(struct xrt_prober* xp,
xrt_prober_list_video_cb cb, xrt_prober_list_video_cb cb,
@ -235,6 +245,7 @@ initialize(struct prober* p, struct xrt_prober_entry_lists* lists)
p->base.dump = dump; p->base.dump = dump;
p->base.select = select_device; p->base.select = select_device;
p->base.open_hid_interface = open_hid_interface; p->base.open_hid_interface = open_hid_interface;
p->base.open_video_device = open_video_device;
p->base.list_video_devices = list_video_devices; p->base.list_video_devices = list_video_devices;
p->base.get_string_descriptor = get_string_descriptor; p->base.get_string_descriptor = get_string_descriptor;
p->base.destroy = destroy; p->base.destroy = destroy;
@ -567,6 +578,32 @@ open_hid_interface(struct xrt_prober* xp,
return -1; return -1;
} }
static int
open_video_device(struct xrt_prober* xp,
struct xrt_prober_device* xpdev,
struct xrt_frame_context* xfctx,
struct xrt_fs** out_xfs)
{
struct prober_device* pdev = (struct prober_device*)xpdev;
#ifdef XRT_OS_LINUX
if (pdev->num_v4ls == 0) {
return -1;
}
struct xrt_fs* xfs = v4l2_fs_create(xfctx, pdev->v4ls[0].path);
if (xfs == NULL) {
return -1;
}
*out_xfs = xfs;
return 0;
#else
(void)pdev;
return -1;
#endif
}
static int static int
list_video_devices(struct xrt_prober* xp, list_video_devices(struct xrt_prober* xp,
xrt_prober_list_video_cb cb, xrt_prober_list_video_cb cb,