Monado OpenXR Runtime
v4l2_driver.c File Reference

V4L2 frameserver implementation. More...

#include "os/os_time.h"
#include "util/u_var.h"
#include "util/u_sink.h"
#include "util/u_misc.h"
#include "util/u_debug.h"
#include "util/u_format.h"
#include "util/u_logging.h"
#include "util/u_trace_marker.h"
#include "v4l2_interface.h"
#include "v4l2_driver.h"
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <linux/videodev2.h>
#include <linux/v4l2-common.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
Include dependency graph for v4l2_driver.c:

Macros

#define V_CONTROL_GET(VID, CONTROL)
 
#define V_CONTROL_SET(VID, CONTROL, VALUE)
 
#define ADD(CONTROL, WANT1, WANT2, WANT3, WANT4, NAME)
 
#define CASE(CONTROL)    case V4L2_CID_##CONTROL: str = "V4L2_CID_" #CONTROL; break
 
#define V_CHECK(FLAG)
 

Functions

static void * v4l2_fs_mainloop (void *ptr)
 Streaming thread entrypoint. More...
 
static void dump_controls (struct v4l2_fs *vid)
 
static void dump_contron_name (uint32_t id)
 
static size_t align_up (size_t size, size_t align)
 
static void v4l2_free_frame (struct xrt_frame *xf)
 
static XRT_MAYBE_UNUSED int v4l2_control_get (struct v4l2_fs *vid, uint32_t id, int *out_value)
 
static int v4l2_control_set (struct v4l2_fs *vid, uint32_t id, int value)
 
static void v4l2_add_control_state (struct v4l2_fs *vid, int control, struct v4l2_state_want want[2], int force, const char *name)
 
static int v4l2_query_cap_and_validate (struct v4l2_fs *vid)
 
static int v4l2_try_userptr (struct v4l2_fs *vid, struct v4l2_requestbuffers *v_bufrequest)
 
static int v4l2_try_mmap (struct v4l2_fs *vid, struct v4l2_requestbuffers *v_bufrequest)
 
static int v4l2_setup_mmap_buffer (struct v4l2_fs *vid, struct v4l2_frame *vf, struct v4l2_buffer *v_buf)
 
static int v4l2_setup_userptr_buffer (struct v4l2_fs *vid, struct v4l2_frame *vf, struct v4l2_buffer *v_buf)
 
static struct v4l2_source_descriptorv4l2_add_descriptor (struct v4l2_fs *vid)
 
static void v4l2_list_modes_interval (struct v4l2_fs *vid, const struct v4l2_fmtdesc *fmt, const struct v4l2_frmsizeenum *size, const struct v4l2_frmivalenum *interval)
 
static void v4l2_list_modes_size (struct v4l2_fs *vid, const struct v4l2_fmtdesc *fmt, const struct v4l2_frmsizeenum *size)
 
static void v4l2_list_modes_fmt (struct v4l2_fs *vid, const struct v4l2_fmtdesc *fmt)
 
static void v4l2_list_modes (struct v4l2_fs *vid)
 
static void v4l2_set_control_if_diff (struct v4l2_fs *vid, struct v4l2_control_state *state)
 
static void v4l2_update_controls (struct v4l2_fs *vid)
 
bool v4l2_fs_setup_format (struct v4l2_fs *vid)
 
static bool v4l2_fs_enumerate_modes (struct xrt_fs *xfs, struct xrt_fs_mode **out_modes, uint32_t *out_count)
 
static bool v4l2_fs_configure_capture (struct xrt_fs *xfs, struct xrt_fs_capture_parameters *cp)
 
static bool v4l2_fs_stream_start (struct xrt_fs *xfs, struct xrt_frame_sink *xs, enum xrt_fs_capture_type capture_type, uint32_t descriptor_index)
 
static bool v4l2_fs_stream_stop (struct xrt_fs *xfs)
 
static bool v4l2_fs_is_running (struct xrt_fs *xfs)
 
static void v4l2_fs_destroy (struct v4l2_fs *vid)
 
static void v4l2_fs_node_break_apart (struct xrt_frame_node *node)
 
static void v4l2_fs_node_destroy (struct xrt_frame_node *node)
 
struct xrt_fsv4l2_fs_create (struct xrt_frame_context *xfctx, const char *path, const char *product, const char *manufacturer, const char *serial)
 Create a v4l2 frameserver. More...
 
static void dump_integer (struct v4l2_fs *vid, struct v4l2_queryctrl *queryctrl)
 
static void dump_menu (struct v4l2_fs *vid, uint32_t id, uint32_t min, uint32_t max)
 

Detailed Description

V4L2 frameserver implementation.

Author
Pete Black pblac.nosp@m.k@co.nosp@m.llabo.nosp@m.ra.c.nosp@m.om
Jakob Bornecrantz jakob.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m

Macro Definition Documentation

◆ ADD

#define ADD (   CONTROL,
  WANT1,
  WANT2,
  WANT3,
  WANT4,
  NAME 
)
Value:
do { \
struct v4l2_state_want want[2] = {{WANT1, WANT2}, {WANT3, WANT4}}; \
v4l2_add_control_state(vid, V4L2_CID_##CONTROL, want, 2, NAME); \
} while (false)
Definition: v4l2_driver.h:53

◆ V_CHECK

#define V_CHECK (   FLAG)
Value:
do { \
if (queryctrl.flags & V4L2_CTRL_FLAG_##FLAG) { \
fprintf(stderr, ", " #FLAG); \
} \
} while (false)

◆ V_CONTROL_GET

#define V_CONTROL_GET (   VID,
  CONTROL 
)
Value:
do { \
int _value = 0; \
if (v4l2_control_get(VID, V4L2_CID_##CONTROL, &_value) != 0) { \
V4L2_ERROR(VID, "failed to get V4L2_CID_" #CONTROL); \
} else { \
V4L2_DEBUG(VID, "V4L2_CID_" #CONTROL " = %i", _value); \
} \
} while (false);

◆ V_CONTROL_SET

#define V_CONTROL_SET (   VID,
  CONTROL,
  VALUE 
)
Value:
do { \
if (v4l2_control_set(VID, V4L2_CID_##CONTROL, VALUE) != 0) { \
V4L2_ERROR(VID, "failed to set V4L2_CID_" #CONTROL); \
} \
} while (false);

Function Documentation

◆ v4l2_fs_configure_capture()

static bool v4l2_fs_configure_capture ( struct xrt_fs xfs,
struct xrt_fs_capture_parameters cp 
)
static

◆ v4l2_fs_mainloop()

void * v4l2_fs_mainloop ( void *  ptr)
static

Streaming thread entrypoint.

Todo:
Sequence number and timestamp.