2 * Copyright © 2015 Collabora Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 #include <drm_fourcc.h>
45 #include <linux/videodev2.h>
46 #include <linux/input.h>
48 #include <wayland-client.h>
49 #include "shared/zalloc.h"
50 #include "xdg-shell-unstable-v6-client-protocol.h"
51 #include "fullscreen-shell-unstable-v1-client-protocol.h"
52 #include "linux-dmabuf-unstable-v1-client-protocol.h"
54 #define CLEAR(x) memset(&(x), 0, sizeof(x))
57 redraw(void *data, struct wl_callback *callback, uint32_t time);
60 xioctl(int fh, int request, void *arg)
65 r = ioctl(fh, request, arg);
66 } while (r == -1 && errno == EINTR);
72 parse_format(const char fmt[4])
74 return fourcc_code(fmt[0], fmt[1], fmt[2], fmt[3]);
77 static inline const char *
78 dump_format(uint32_t format, char out[4])
80 #if BYTE_ORDER == BIG_ENDIAN
81 format = __builtin_bswap32(format);
83 memcpy(out, &format, 4);
87 struct buffer_format {
90 enum v4l2_buf_type type;
94 unsigned strides[VIDEO_MAX_PLANES];
98 struct wl_display *display;
99 struct wl_registry *registry;
100 struct wl_compositor *compositor;
101 struct wl_seat *seat;
102 struct wl_keyboard *keyboard;
103 struct zxdg_shell_v6 *shell;
104 struct zwp_fullscreen_shell_v1 *fshell;
105 struct zwp_linux_dmabuf_v1 *dmabuf;
106 bool requested_format_found;
109 struct buffer_format format;
114 struct wl_buffer *buffer;
115 struct display *display;
119 int dmabuf_fds[VIDEO_MAX_PLANES];
120 int data_offsets[VIDEO_MAX_PLANES];
123 #define NUM_BUFFERS 3
126 struct display *display;
127 struct wl_surface *surface;
128 struct zxdg_surface_v6 *xdg_surface;
129 struct zxdg_toplevel_v6 *xdg_toplevel;
130 struct buffer buffers[NUM_BUFFERS];
131 struct wl_callback *callback;
132 bool wait_for_configure;
136 static bool running = true;
139 queue(struct display *display, struct buffer *buffer)
141 struct v4l2_buffer buf;
142 struct v4l2_plane planes[VIDEO_MAX_PLANES];
146 buf.type = display->format.type;
147 buf.memory = V4L2_MEMORY_MMAP;
148 buf.index = buffer->index;
150 if (display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
152 buf.length = VIDEO_MAX_PLANES;
153 buf.m.planes = planes;
156 if (xioctl(display->v4l_fd, VIDIOC_QUERYBUF, &buf) == -1) {
157 perror("VIDIOC_QUERYBUF");
161 if (xioctl(display->v4l_fd, VIDIOC_QBUF, &buf) == -1) {
162 perror("VIDIOC_QBUF");
166 if (display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
167 if (display->format.num_planes != buf.length) {
168 fprintf(stderr, "Wrong number of planes returned by "
173 for (i = 0; i < buf.length; ++i)
174 buffer->data_offsets[i] = buf.m.planes[i].data_offset;
181 buffer_release(void *data, struct wl_buffer *buffer)
183 struct buffer *mybuf = data;
187 if (!queue(mybuf->display, mybuf))
191 static const struct wl_buffer_listener buffer_listener = {
196 set_format(struct display *display, uint32_t format)
198 struct v4l2_format fmt;
203 fmt.type = display->format.type;
205 if (xioctl(display->v4l_fd, VIDIOC_G_FMT, &fmt) == -1) {
206 perror("VIDIOC_G_FMT");
210 /* No need to set the format if it already is the one we want */
211 if (display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
212 fmt.fmt.pix.pixelformat == format)
214 if (display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
215 fmt.fmt.pix_mp.pixelformat == format)
216 return fmt.fmt.pix_mp.num_planes;
218 if (display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
219 fmt.fmt.pix.pixelformat = format;
221 fmt.fmt.pix_mp.pixelformat = format;
223 if (xioctl(display->v4l_fd, VIDIOC_S_FMT, &fmt) == -1) {
224 perror("VIDIOC_S_FMT");
228 if ((display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
229 fmt.fmt.pix.pixelformat != format) ||
230 (display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE &&
231 fmt.fmt.pix_mp.pixelformat != format)) {
232 fprintf(stderr, "Failed to set format to %.4s\n",
233 dump_format(format, buf));
237 if (display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
238 return fmt.fmt.pix_mp.num_planes;
244 v4l_connect(struct display *display, const char *dev_name)
246 struct v4l2_capability cap;
247 struct v4l2_requestbuffers req;
248 unsigned int num_planes;
250 display->v4l_fd = open(dev_name, O_RDWR);
251 if (display->v4l_fd < 0) {
256 if (xioctl(display->v4l_fd, VIDIOC_QUERYCAP, &cap) == -1) {
257 if (errno == EINVAL) {
258 fprintf(stderr, "%s is no V4L2 device\n", dev_name);
260 perror("VIDIOC_QUERYCAP");
265 if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
266 display->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
267 else if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
268 display->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
270 fprintf(stderr, "%s is no video capture device\n", dev_name);
274 if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
275 fprintf(stderr, "%s does not support dmabuf i/o\n", dev_name);
279 /* Select video input, video standard and tune here */
281 num_planes = set_format(display, display->format.format);
287 req.type = display->format.type;
288 req.memory = V4L2_MEMORY_MMAP;
289 req.count = NUM_BUFFERS * num_planes;
291 if (xioctl(display->v4l_fd, VIDIOC_REQBUFS, &req) == -1) {
292 if (errno == EINVAL) {
293 fprintf(stderr, "%s does not support dmabuf\n",
296 perror("VIDIOC_REQBUFS");
301 if (req.count < NUM_BUFFERS * num_planes) {
302 fprintf(stderr, "Insufficient buffer memory on %s\n", dev_name);
306 printf("Created %d buffers\n", req.count);
312 v4l_shutdown(struct display *display)
314 close(display->v4l_fd);
318 create_succeeded(void *data,
319 struct zwp_linux_buffer_params_v1 *params,
320 struct wl_buffer *new_buffer)
322 struct buffer *buffer = data;
325 buffer->buffer = new_buffer;
326 wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer);
328 zwp_linux_buffer_params_v1_destroy(params);
330 for (i = 0; i < buffer->display->format.num_planes; ++i)
331 close(buffer->dmabuf_fds[i]);
335 create_failed(void *data, struct zwp_linux_buffer_params_v1 *params)
337 struct buffer *buffer = data;
340 buffer->buffer = NULL;
342 zwp_linux_buffer_params_v1_destroy(params);
344 for (i = 0; i < buffer->display->format.num_planes; ++i)
345 close(buffer->dmabuf_fds[i]);
349 fprintf(stderr, "Error: zwp_linux_buffer_params.create failed.\n");
352 static const struct zwp_linux_buffer_params_v1_listener params_listener = {
358 create_dmabuf_buffer(struct display *display, struct buffer *buffer)
360 struct zwp_linux_buffer_params_v1 *params;
368 /* XXX: apparently some webcams may actually provide y-inverted images,
369 * in which case we should set
370 * flags = ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT
373 params = zwp_linux_dmabuf_v1_create_params(display->dmabuf);
374 for (i = 0; i < display->format.num_planes; ++i)
375 zwp_linux_buffer_params_v1_add(params,
376 buffer->dmabuf_fds[i],
378 buffer->data_offsets[i], /* offset */
379 display->format.strides[i],
381 modifier & 0xffffffff);
382 zwp_linux_buffer_params_v1_add_listener(params, ¶ms_listener,
384 zwp_linux_buffer_params_v1_create(params,
385 display->format.width,
386 display->format.height,
392 buffer_export(struct display *display, int index, int dmafd[])
394 struct v4l2_exportbuffer expbuf;
399 for (i = 0; i < display->format.num_planes; ++i) {
400 expbuf.type = display->format.type;
401 expbuf.index = index;
403 if (xioctl(display->v4l_fd, VIDIOC_EXPBUF, &expbuf) == -1) {
404 perror("VIDIOC_EXPBUF");
409 dmafd[i] = expbuf.fd;
416 queue_initial_buffers(struct display *display,
417 struct buffer buffers[NUM_BUFFERS])
419 struct buffer *buffer;
422 for (index = 0; index < NUM_BUFFERS; ++index) {
423 buffer = &buffers[index];
424 buffer->display = display;
425 buffer->index = index;
427 if (!queue(display, buffer)) {
428 fprintf(stderr, "Failed to queue buffer\n");
432 assert(!buffer->buffer);
433 if (!buffer_export(display, index, buffer->dmabuf_fds))
436 create_dmabuf_buffer(display, buffer);
443 dequeue(struct display *display)
445 struct v4l2_buffer buf;
446 struct v4l2_plane planes[VIDEO_MAX_PLANES];
449 buf.type = display->format.type;
450 buf.memory = V4L2_MEMORY_MMAP;
451 buf.length = VIDEO_MAX_PLANES;
452 buf.m.planes = planes;
454 /* This ioctl is blocking until a buffer is ready to be displayed */
455 if (xioctl(display->v4l_fd, VIDIOC_DQBUF, &buf) == -1) {
456 perror("VIDIOC_DQBUF");
464 fill_buffer_format(struct display *display)
466 struct v4l2_format fmt;
467 struct v4l2_pix_format *pix;
468 struct v4l2_pix_format_mplane *pix_mp;
473 fmt.type = display->format.type;
475 /* Preserve original settings as set by v4l2-ctl for example */
476 if (xioctl(display->v4l_fd, VIDIOC_G_FMT, &fmt) == -1) {
477 perror("VIDIOC_G_FMT");
481 if (display->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
484 printf("%d×%d, %.4s\n", pix->width, pix->height,
485 dump_format(pix->pixelformat, buf));
487 display->format.num_planes = 1;
488 display->format.width = pix->width;
489 display->format.height = pix->height;
490 display->format.strides[0] = pix->bytesperline;
492 pix_mp = &fmt.fmt.pix_mp;
494 display->format.num_planes = pix_mp->num_planes;
495 display->format.width = pix_mp->width;
496 display->format.height = pix_mp->height;
498 for (i = 0; i < pix_mp->num_planes; ++i)
499 display->format.strides[i] = pix_mp->plane_fmt[i].bytesperline;
501 printf("%d×%d, %.4s, %d planes\n",
502 pix_mp->width, pix_mp->height,
503 dump_format(pix_mp->pixelformat, buf),
511 v4l_init(struct display *display, struct buffer buffers[NUM_BUFFERS]) {
512 if (!fill_buffer_format(display)) {
513 fprintf(stderr, "Failed to fill buffer format\n");
517 if (!queue_initial_buffers(display, buffers)) {
518 fprintf(stderr, "Failed to queue initial buffers\n");
526 start_capture(struct display *display)
528 int type = display->format.type;
530 if (xioctl(display->v4l_fd, VIDIOC_STREAMON, &type) == -1) {
531 perror("VIDIOC_STREAMON");
539 xdg_surface_handle_configure(void *data, struct zxdg_surface_v6 *surface,
542 struct window *window = data;
544 zxdg_surface_v6_ack_configure(surface, serial);
546 if (window->initialized && window->wait_for_configure)
547 redraw(window, NULL, 0);
548 window->wait_for_configure = false;
551 static const struct zxdg_surface_v6_listener xdg_surface_listener = {
552 xdg_surface_handle_configure,
556 xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *toplevel,
557 int32_t width, int32_t height,
558 struct wl_array *states)
563 xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
568 static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
569 xdg_toplevel_handle_configure,
570 xdg_toplevel_handle_close,
573 static struct window *
574 create_window(struct display *display)
576 struct window *window;
578 window = zalloc(sizeof *window);
582 window->callback = NULL;
583 window->display = display;
584 window->surface = wl_compositor_create_surface(display->compositor);
586 if (display->shell) {
587 window->xdg_surface =
588 zxdg_shell_v6_get_xdg_surface(display->shell,
591 assert(window->xdg_surface);
593 zxdg_surface_v6_add_listener(window->xdg_surface,
594 &xdg_surface_listener, window);
596 window->xdg_toplevel =
597 zxdg_surface_v6_get_toplevel(window->xdg_surface);
599 assert(window->xdg_toplevel);
601 zxdg_toplevel_v6_add_listener(window->xdg_toplevel,
602 &xdg_toplevel_listener, window);
604 zxdg_toplevel_v6_set_title(window->xdg_toplevel, "simple-dmabuf-v4l");
606 window->wait_for_configure = true;
607 wl_surface_commit(window->surface);
608 } else if (display->fshell) {
609 zwp_fullscreen_shell_v1_present_surface(display->fshell,
611 ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_DEFAULT,
621 destroy_window(struct window *window)
626 if (window->callback)
627 wl_callback_destroy(window->callback);
629 if (window->xdg_toplevel)
630 zxdg_toplevel_v6_destroy(window->xdg_toplevel);
631 if (window->xdg_surface)
632 zxdg_surface_v6_destroy(window->xdg_surface);
633 wl_surface_destroy(window->surface);
635 for (i = 0; i < NUM_BUFFERS; i++) {
636 if (!window->buffers[i].buffer)
639 wl_buffer_destroy(window->buffers[i].buffer);
640 for (j = 0; j < window->display->format.num_planes; ++j)
641 close(window->buffers[i].dmabuf_fds[j]);
644 v4l_shutdown(window->display);
649 static const struct wl_callback_listener frame_listener;
652 redraw(void *data, struct wl_callback *callback, uint32_t time)
654 struct window *window = data;
655 struct buffer *buffer;
656 int index, num_busy = 0;
658 /* Check for a deadlock situation where we would block forever trying
659 * to dequeue a buffer while all of them are locked by the compositor.
661 for (index = 0; index < NUM_BUFFERS; ++index)
662 if (window->buffers[index].busy)
665 /* A robust application would just postpone redraw until it has queued
668 assert(num_busy < NUM_BUFFERS);
670 index = dequeue(window->display);
672 /* We couldn’t get any buffer out of the camera, exiting. */
677 buffer = &window->buffers[index];
678 assert(!buffer->busy);
680 wl_surface_attach(window->surface, buffer->buffer, 0, 0);
681 wl_surface_damage(window->surface, 0, 0,
682 window->display->format.width,
683 window->display->format.height);
686 wl_callback_destroy(callback);
688 window->callback = wl_surface_frame(window->surface);
689 wl_callback_add_listener(window->callback, &frame_listener, window);
690 wl_surface_commit(window->surface);
694 static const struct wl_callback_listener frame_listener = {
699 dmabuf_format(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
702 struct display *d = data;
704 if (format == d->drm_format)
705 d->requested_format_found = true;
708 static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {
713 keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
714 uint32_t format, int fd, uint32_t size)
716 /* Just so we don’t leak the keymap fd */
721 keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
722 uint32_t serial, struct wl_surface *surface,
723 struct wl_array *keys)
728 keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
729 uint32_t serial, struct wl_surface *surface)
734 keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
735 uint32_t serial, uint32_t time, uint32_t key,
738 struct display *d = data;
743 if (key == KEY_ESC && state)
748 keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
749 uint32_t serial, uint32_t mods_depressed,
750 uint32_t mods_latched, uint32_t mods_locked,
755 static const struct wl_keyboard_listener keyboard_listener = {
756 keyboard_handle_keymap,
757 keyboard_handle_enter,
758 keyboard_handle_leave,
760 keyboard_handle_modifiers,
764 seat_handle_capabilities(void *data, struct wl_seat *seat,
765 enum wl_seat_capability caps)
767 struct display *d = data;
769 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !d->keyboard) {
770 d->keyboard = wl_seat_get_keyboard(seat);
771 wl_keyboard_add_listener(d->keyboard, &keyboard_listener, d);
772 } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && d->keyboard) {
773 wl_keyboard_destroy(d->keyboard);
778 static const struct wl_seat_listener seat_listener = {
779 seat_handle_capabilities,
783 xdg_shell_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial)
785 zxdg_shell_v6_pong(shell, serial);
788 static const struct zxdg_shell_v6_listener xdg_shell_listener = {
793 registry_handle_global(void *data, struct wl_registry *registry,
794 uint32_t id, const char *interface, uint32_t version)
796 struct display *d = data;
798 if (strcmp(interface, "wl_compositor") == 0) {
800 wl_registry_bind(registry,
801 id, &wl_compositor_interface, 1);
802 } else if (strcmp(interface, "wl_seat") == 0) {
803 d->seat = wl_registry_bind(registry,
804 id, &wl_seat_interface, 1);
805 wl_seat_add_listener(d->seat, &seat_listener, d);
806 } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
807 d->shell = wl_registry_bind(registry,
808 id, &zxdg_shell_v6_interface, 1);
809 zxdg_shell_v6_add_listener(d->shell, &xdg_shell_listener, d);
810 } else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) {
811 d->fshell = wl_registry_bind(registry,
812 id, &zwp_fullscreen_shell_v1_interface,
814 } else if (strcmp(interface, "zwp_linux_dmabuf_v1") == 0) {
815 d->dmabuf = wl_registry_bind(registry,
816 id, &zwp_linux_dmabuf_v1_interface,
818 zwp_linux_dmabuf_v1_add_listener(d->dmabuf, &dmabuf_listener,
824 registry_handle_global_remove(void *data, struct wl_registry *registry,
829 static const struct wl_registry_listener registry_listener = {
830 registry_handle_global,
831 registry_handle_global_remove
834 static struct display *
835 create_display(uint32_t requested_format)
837 struct display *display;
839 display = malloc(sizeof *display);
840 if (display == NULL) {
841 fprintf(stderr, "out of memory\n");
844 display->display = wl_display_connect(NULL);
845 assert(display->display);
847 display->drm_format = requested_format;
849 display->registry = wl_display_get_registry(display->display);
850 wl_registry_add_listener(display->registry,
851 ®istry_listener, display);
852 wl_display_roundtrip(display->display);
853 if (display->dmabuf == NULL) {
854 fprintf(stderr, "No zwp_linux_dmabuf global\n");
858 wl_display_roundtrip(display->display);
860 /* XXX: fake, because the compositor does not yet advertise anything */
861 display->requested_format_found = true;
863 if (!display->requested_format_found) {
864 fprintf(stderr, "DRM_FORMAT_YUYV not available\n");
872 destroy_display(struct display *display)
875 zwp_linux_dmabuf_v1_destroy(display->dmabuf);
878 zxdg_shell_v6_destroy(display->shell);
881 zwp_fullscreen_shell_v1_release(display->fshell);
883 if (display->compositor)
884 wl_compositor_destroy(display->compositor);
886 wl_registry_destroy(display->registry);
887 wl_display_flush(display->display);
888 wl_display_disconnect(display->display);
893 usage(const char *argv0)
895 printf("Usage: %s [V4L2 device] [V4L2 format] [DRM format]\n"
897 "The default V4L2 device is /dev/video0\n"
899 "Both formats are FOURCC values (see http://fourcc.org/)\n"
900 "V4L2 formats are defined in <linux/videodev2.h>\n"
901 "DRM formats are defined in <libdrm/drm_fourcc.h>\n"
902 "The default for both formats is YUYV.\n"
903 "If the V4L2 and DRM formats differ, the data is simply "
904 "reinterpreted rather than converted.\n", argv0);
907 "How to set up Vivid the virtual video driver for testing:\n"
908 "- build your kernel with CONFIG_VIDEO_VIVID=m\n"
909 "- add this to a /etc/modprobe.d/ file:\n"
910 " options vivid node_types=0x1 num_inputs=1 input_types=0x00\n"
911 "- modprobe vivid and check which device was created,\n"
912 " here we assume /dev/video0\n"
913 "- set the pixel format:\n"
914 " $ v4l2-ctl -d /dev/video0 --set-fmt-video=width=640,pixelformat=XR24\n"
915 "- launch the demo:\n"
916 " $ %s /dev/video0 XR24 XR24\n"
917 "You should see a test pattern with color bars, and some text.\n"
919 "More about vivid: https://www.kernel.org/doc/Documentation/video4linux/vivid.txt\n"
926 signal_int(int signum)
932 main(int argc, char **argv)
934 struct sigaction sigint;
935 struct display *display;
936 struct window *window;
937 const char *v4l_device;
938 uint32_t v4l_format, drm_format;
942 v4l_device = "/dev/video0";
943 } else if (!strcmp(argv[1], "--help")) {
946 v4l_device = argv[1];
950 v4l_format = parse_format("YUYV");
952 v4l_format = parse_format(argv[2]);
955 drm_format = v4l_format;
957 drm_format = parse_format(argv[3]);
959 display = create_display(drm_format);
960 display->format.format = v4l_format;
962 window = create_window(display);
966 if (!v4l_connect(display, v4l_device))
969 if (!v4l_init(display, window->buffers))
972 sigint.sa_handler = signal_int;
973 sigemptyset(&sigint.sa_mask);
974 sigint.sa_flags = SA_RESETHAND;
975 sigaction(SIGINT, &sigint, NULL);
977 /* Here we retrieve the linux-dmabuf objects, or error */
978 wl_display_roundtrip(display->display);
980 /* In case of error, running will be 0 */
984 /* We got all of our buffers, we can start the capture! */
985 if (!start_capture(display))
988 window->initialized = true;
990 if (!window->wait_for_configure)
991 redraw(window, NULL, 0);
993 while (running && ret != -1)
994 ret = wl_display_dispatch(display->display);
996 fprintf(stderr, "simple-dmabuf-v4l exiting\n");
997 destroy_window(window);
998 destroy_display(display);