clients/dmabuf-v4l: Pass FLAGS_Y_INVERT to linux-dmabuf if v4l2 reports so

Zero-initialize the display as to correctly pass the options if it was
supplied (@emersion).

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
dev
Marius Vlad 5 years ago committed by Pekka Paalanen
parent 4960955e0f
commit baa1ef22e8
  1. 22
      clients/simple-dmabuf-v4l.c

@ -54,6 +54,7 @@
#include "shared/helpers.h" #include "shared/helpers.h"
#define CLEAR(x) memset(&(x), 0, sizeof(x)) #define CLEAR(x) memset(&(x), 0, sizeof(x))
#define OPT_FLAG_INVERT (1 << 0)
static void static void
redraw(void *data, struct wl_callback *callback, uint32_t time); redraw(void *data, struct wl_callback *callback, uint32_t time);
@ -106,6 +107,7 @@ struct display {
struct zwp_fullscreen_shell_v1 *fshell; struct zwp_fullscreen_shell_v1 *fshell;
struct zwp_linux_dmabuf_v1 *dmabuf; struct zwp_linux_dmabuf_v1 *dmabuf;
bool requested_format_found; bool requested_format_found;
uint32_t opts;
int v4l_fd; int v4l_fd;
struct buffer_format format; struct buffer_format format;
@ -247,6 +249,8 @@ v4l_connect(struct display *display, const char *dev_name)
{ {
struct v4l2_capability cap; struct v4l2_capability cap;
struct v4l2_requestbuffers req; struct v4l2_requestbuffers req;
struct v4l2_input input;
int index_input = -1;
unsigned int num_planes; unsigned int num_planes;
display->v4l_fd = open(dev_name, O_RDWR); display->v4l_fd = open(dev_name, O_RDWR);
@ -264,6 +268,16 @@ v4l_connect(struct display *display, const char *dev_name)
return 0; return 0;
} }
if (xioctl(display->v4l_fd, VIDIOC_G_INPUT, &index_input) == 0) {
input.index = index_input;
if (xioctl(display->v4l_fd, VIDIOC_ENUMINPUT, &input) == 0) {
if (input.status & V4L2_IN_ST_VFLIP) {
fprintf(stdout, "Found camera sensor y-flipped\n");
display->opts |= OPT_FLAG_INVERT;
}
}
}
if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
display->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; display->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
else if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) else if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
@ -367,10 +381,8 @@ create_dmabuf_buffer(struct display *display, struct buffer *buffer)
modifier = 0; modifier = 0;
flags = 0; flags = 0;
/* XXX: apparently some webcams may actually provide y-inverted images, if (display->opts & OPT_FLAG_INVERT)
* in which case we should set flags |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT;
* flags = ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT
*/
params = zwp_linux_dmabuf_v1_create_params(display->dmabuf); params = zwp_linux_dmabuf_v1_create_params(display->dmabuf);
for (i = 0; i < display->format.num_planes; ++i) for (i = 0; i < display->format.num_planes; ++i)
@ -847,7 +859,7 @@ create_display(uint32_t requested_format)
{ {
struct display *display; struct display *display;
display = malloc(sizeof *display); display = zalloc(sizeof *display);
if (display == NULL) { if (display == NULL) {
fprintf(stderr, "out of memory\n"); fprintf(stderr, "out of memory\n");
exit(1); exit(1);

Loading…
Cancel
Save