1 From 78ddc83ebfe7cf69c62610e1f7d14e7f49bf65c9 Mon Sep 17 00:00:00 2001
2 From: Pooja Prajod <a0132412@ti.com>
3 Date: Wed, 25 Jan 2017 17:09:35 +0530
4 Subject: [gst-bad-1.8] gstwaylandsink: Add DRM support on waylandsink
6 Add wl_drm interface on waylandsink.
7 The following features are supported:
8 1. Support for mouse drag and drop.
9 2. Support for video cropping
11 The following bug fixes identified earlier have been picked:
12 1. Consolidate header files to avoid circular dependency
13 2. Fix bug reported on waylandsink incase of same process looping
15 Signed-off-by: Pooja Prajod <a0132412@ti.com>
18 ext/wayland/Makefile.am | 17 +-
19 ext/wayland/gstwaylandsink.c | 82 ++++++-
20 ext/wayland/gstwaylandsink.h | 4 +-
21 ext/wayland/wayland-drm-client-protocol.h | 213 ++++++++++++++++++
22 ext/wayland/wayland-drm-protocol.c | 74 +++++++
23 ext/wayland/wlbuffer.c | 2 +-
24 ext/wayland/wlbuffer.h | 67 ------
25 ext/wayland/wldisplay-wlwindow-wlbuffer.h | 216 ++++++++++++++++++
26 ext/wayland/wldisplay.c | 350 +++++++++++++++++++++++++++++-
27 ext/wayland/wldisplay.h | 84 -------
28 ext/wayland/wldrm.c | 69 ++++++
29 ext/wayland/wldrm.h | 3 +
30 ext/wayland/wlshmallocator.h | 2 +-
31 ext/wayland/wlvideoformat.c | 8 +-
32 ext/wayland/wlwindow.c | 47 +++-
33 ext/wayland/wlwindow.h | 84 -------
34 17 files changed, 1056 insertions(+), 270 deletions(-)
35 create mode 100644 ext/wayland/wayland-drm-client-protocol.h
36 create mode 100644 ext/wayland/wayland-drm-protocol.c
37 delete mode 100644 ext/wayland/wlbuffer.h
38 create mode 100644 ext/wayland/wldisplay-wlwindow-wlbuffer.h
39 delete mode 100644 ext/wayland/wldisplay.h
40 create mode 100644 ext/wayland/wldrm.c
41 create mode 100644 ext/wayland/wldrm.h
42 delete mode 100644 ext/wayland/wlwindow.h
44 diff --git a/configure.ac b/configure.ac
45 index 9fdfbc7..76166cb 100644
48 @@ -2172,8 +2172,10 @@ AG_GST_CHECK_FEATURE(DIRECTFB, [directfb], dfbvideosink , [
50 translit(dnm, m, l) AM_CONDITIONAL(USE_WAYLAND, true)
51 AC_PATH_PROG([wayland_scanner], [wayland-scanner])
52 -AG_GST_CHECK_FEATURE(WAYLAND, [wayland sink], wayland , [
53 +AG_GST_CHECK_FEATURE(WAYLAND, [wayland sink], wayland libdrm libdrm_omap, [
54 PKG_CHECK_MODULES(WAYLAND, wayland-client >= 1.4.0, [
55 + AC_SUBST(DRM_CFLAGS)
57 if test "x$wayland_scanner" != "x"; then
60 diff --git a/ext/wayland/Makefile.am b/ext/wayland/Makefile.am
61 index c742bfc..eb6e326 100644
62 --- a/ext/wayland/Makefile.am
63 +++ b/ext/wayland/Makefile.am
64 @@ -3,31 +3,34 @@ plugin_LTLIBRARIES = libgstwaylandsink.la
65 libgstwaylandsink_la_SOURCES = \
75 + wayland-drm-protocol.c
77 libgstwaylandsink_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) \
78 - $(WAYLAND_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS)
79 + $(WAYLAND_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(DRM_CFLAGS)
80 libgstwaylandsink_la_LIBADD = \
81 $(GST_PLUGINS_BASE_LIBS) \
82 -lgstvideo-$(GST_API_VERSION) \
83 -lgstallocators-$(GST_API_VERSION) \
85 - $(top_builddir)/gst-libs/gst/wayland/libgstwayland-$(GST_API_VERSION).la
86 + $(top_builddir)/gst-libs/gst/wayland/libgstwayland-$(GST_API_VERSION).la \
87 + $(top_builddir)/gst-libs/gst/drm/libgstdrm-$(GST_API_VERSION).la
88 libgstwaylandsink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
89 libgstwaylandsink_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
97 + wldisplay-wlwindow-wlbuffer.h \
100 - scaler-client-protocol.h
101 + scaler-client-protocol.h \
102 + wayland-drm-client-protocol.h
104 EXTRA_DIST = scaler.xml
105 CLEANFILES = scaler-protocol.c scaler-client-protocol.h
106 diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c
107 index f4f34a8..3e8ff19 100644
108 --- a/ext/wayland/gstwaylandsink.c
109 +++ b/ext/wayland/gstwaylandsink.c
112 #include "gstwaylandsink.h"
113 #include "wlvideoformat.h"
114 -#include "wlbuffer.h"
115 #include "wlshmallocator.h"
118 +#include <gst/drm/gstdrmallocator.h>
119 +#include "wayland-drm-client-protocol.h"
120 +#include <omap_drm.h>
121 +#include <omap_drmif.h>
122 +#include <wayland-client.h>
124 #include <gst/wayland/wayland.h>
125 #include <gst/video/videooverlay.h>
126 @@ -60,7 +66,8 @@ enum
135 GST_DEBUG_CATEGORY (gstwayland_debug);
136 @@ -75,6 +82,7 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
137 "YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }"))
141 static void gst_wayland_sink_get_property (GObject * object,
142 guint prop_id, GValue * value, GParamSpec * pspec);
143 static void gst_wayland_sink_set_property (GObject * object,
144 @@ -158,6 +166,11 @@ gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
145 g_param_spec_string ("display", "Wayland Display name", "Wayland "
146 "display name to connect to, if not supplied via the GstContext",
147 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
149 + g_object_class_install_property (gobject_class, PROP_ALLOCATION,
150 + g_param_spec_boolean ("use-drm", "Wayland Allocation name", "Wayland "
151 + "Use DRM based memory for allocation",
152 + FALSE, G_PARAM_WRITABLE));
156 @@ -197,6 +210,11 @@ gst_wayland_sink_set_property (GObject * object,
157 sink->display_name = g_value_dup_string (value);
158 GST_OBJECT_UNLOCK (sink);
160 + case PROP_ALLOCATION:
161 + GST_OBJECT_LOCK (sink);
162 + sink->use_drm = g_value_get_boolean (value);
163 + GST_OBJECT_UNLOCK (sink);
166 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
168 @@ -281,6 +299,7 @@ gst_wayland_sink_find_display (GstWaylandSink * sink)
169 /* if the application didn't set a display, let's create it ourselves */
170 GST_OBJECT_LOCK (sink);
171 sink->display = gst_wl_display_new (sink->display_name, &error);
172 + sink->display->use_drm = sink->use_drm;
173 GST_OBJECT_UNLOCK (sink);
176 @@ -408,7 +427,6 @@ gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
178 caps = gst_caps_make_writable (caps);
179 gst_structure_set_value (gst_caps_get_structure (caps, 0), "format", &list);
181 GST_DEBUG_OBJECT (sink, "display caps: %" GST_PTR_FORMAT, caps);
184 @@ -426,6 +444,18 @@ gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
189 +wait_authentication (GstWaylandSink * sink)
191 + GST_DEBUG_OBJECT (sink, "Before wait aunthenticated value is %d : \n", sink->display->authenticated );
192 + while (!sink->display->authenticated) {
193 + GST_DEBUG_OBJECT (sink, "waiting for authentication");
194 + wl_display_roundtrip (sink->display->display);
196 + GST_DEBUG_OBJECT (sink, "After wait aunthenticated value is %d : \n", sink->display->authenticated );
201 gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
203 @@ -436,11 +466,20 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
206 GstStructure *structure;
208 + gboolean use_drm = 0;
209 + int num_buffers = 0;
211 sink = GST_WAYLAND_SINK (bsink);
213 GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
215 + wait_authentication (sink);
217 + while (!sink->display->authenticated) {
218 + GST_DEBUG_OBJECT (sink, "not authenticated yet");
221 /* extract info from caps */
222 if (!gst_video_info_from_caps (&info, caps))
224 @@ -460,14 +499,27 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
225 goto unsupported_format;
227 /* create a new pool for the new configuration */
228 - newpool = gst_video_buffer_pool_new ();
230 + s = gst_caps_get_structure (caps, 0);
231 + gst_structure_get_boolean (s, "drm_mem", &use_drm);
232 + gst_structure_get_int (s, "max-ref-frames", &num_buffers);
234 + num_buffers = num_buffers + 2;
236 + newpool = gst_buffer_pool_new ();
240 structure = gst_buffer_pool_get_config (newpool);
241 - gst_buffer_pool_config_set_params (structure, caps, info.size, 2, 0);
242 - gst_buffer_pool_config_set_allocator (structure, gst_wl_shm_allocator_get (),
244 + gst_buffer_pool_config_set_params (structure, caps, info.size, 2, num_buffers);
246 + gst_buffer_pool_config_set_allocator (structure, gst_drm_allocator_get (),
248 + sink->display->use_drm = TRUE;
250 + gst_buffer_pool_config_set_allocator (structure, gst_wl_shm_allocator_get (),
253 if (!gst_buffer_pool_set_config (newpool, structure))
256 @@ -518,8 +570,11 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
257 /* we do have a pool for sure (created in set_caps),
258 * so let's propose it anyway, but also propose the allocator on its own */
259 gst_query_add_allocation_pool (query, sink->pool, size, min_bufs, max_bufs);
260 - gst_query_add_allocation_param (query, gst_wl_shm_allocator_get (), NULL);
262 + if (sink->display->use_drm) {
263 + gst_query_add_allocation_param (query, gst_drm_allocator_get (), NULL);
265 + gst_query_add_allocation_param (query, gst_wl_shm_allocator_get (), NULL);
267 gst_structure_free (config);
270 @@ -582,6 +637,10 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
272 GST_LOG_OBJECT (sink, "render buffer %p", buffer);
274 + if (sink->display) {
275 + sink->display->crop = gst_buffer_get_video_crop_meta (buffer);
278 if (G_UNLIKELY (!sink->window)) {
279 /* ask for window handle. Unlock render_lock while doing that because
280 * set_window_handle & friends will lock it in this context */
281 @@ -623,6 +682,11 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
282 wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
286 + if (gst_is_drm_memory (mem)) {
287 + wbuf = gst_wl_drm_memory_construct_wl_buffer (mem, sink->display,
288 + &sink->video_info);
292 gst_buffer_add_wl_buffer (buffer, wbuf, sink->display);
293 diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h
294 index afbed40..c1092ce 100644
295 --- a/ext/wayland/gstwaylandsink.h
296 +++ b/ext/wayland/gstwaylandsink.h
299 #include <wayland-client.h>
301 -#include "wldisplay.h"
302 -#include "wlwindow.h"
303 +#include "wldisplay-wlwindow-wlbuffer.h"
307 @@ -61,6 +60,7 @@ struct _GstWaylandSink
308 GstVideoInfo video_info;
313 gboolean redraw_pending;
315 diff --git a/ext/wayland/wayland-drm-client-protocol.h b/ext/wayland/wayland-drm-client-protocol.h
317 index 0000000..7ddb614
319 +++ b/ext/wayland/wayland-drm-client-protocol.h
322 + * Copyright © 2008-2011 Kristian Høgsberg
323 + * Copyright © 2010-2011 Intel Corporation
325 + * Permission to use, copy, modify, distribute, and sell this
326 + * software and its documentation for any purpose is hereby granted
327 + * without fee, provided that\n the above copyright notice appear in
328 + * all copies and that both that copyright notice and this permission
329 + * notice appear in supporting documentation, and that the name of
330 + * the copyright holders not be used in advertising or publicity
331 + * pertaining to distribution of the software without specific,
332 + * written prior permission. The copyright holders make no
333 + * representations about the suitability of this software for any
334 + * purpose. It is provided "as is" without express or implied
337 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
338 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
339 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
340 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
341 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
342 + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
343 + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
347 +#ifndef DRM_CLIENT_PROTOCOL_H
348 +#define DRM_CLIENT_PROTOCOL_H
356 +#include "wayland-util.h"
363 +extern const struct wl_interface wl_drm_interface;
365 +#ifndef WL_DRM_ERROR_ENUM
366 +#define WL_DRM_ERROR_ENUM
368 + WL_DRM_ERROR_AUTHENTICATE_FAIL = 0,
369 + WL_DRM_ERROR_INVALID_FORMAT = 1,
370 + WL_DRM_ERROR_INVALID_NAME = 2,
372 +#endif /* WL_DRM_ERROR_ENUM */
374 +#ifndef WL_DRM_FORMAT_ENUM
375 +#define WL_DRM_FORMAT_ENUM
376 +enum wl_drm_format {
377 + WL_DRM_FORMAT_C8 = 0x20203843,
378 + WL_DRM_FORMAT_RGB332 = 0x38424752,
379 + WL_DRM_FORMAT_BGR233 = 0x38524742,
380 + WL_DRM_FORMAT_XRGB4444 = 0x32315258,
381 + WL_DRM_FORMAT_XBGR4444 = 0x32314258,
382 + WL_DRM_FORMAT_RGBX4444 = 0x32315852,
383 + WL_DRM_FORMAT_BGRX4444 = 0x32315842,
384 + WL_DRM_FORMAT_ARGB4444 = 0x32315241,
385 + WL_DRM_FORMAT_ABGR4444 = 0x32314241,
386 + WL_DRM_FORMAT_RGBA4444 = 0x32314152,
387 + WL_DRM_FORMAT_BGRA4444 = 0x32314142,
388 + WL_DRM_FORMAT_XRGB1555 = 0x35315258,
389 + WL_DRM_FORMAT_XBGR1555 = 0x35314258,
390 + WL_DRM_FORMAT_RGBX5551 = 0x35315852,
391 + WL_DRM_FORMAT_BGRX5551 = 0x35315842,
392 + WL_DRM_FORMAT_ARGB1555 = 0x35315241,
393 + WL_DRM_FORMAT_ABGR1555 = 0x35314241,
394 + WL_DRM_FORMAT_RGBA5551 = 0x35314152,
395 + WL_DRM_FORMAT_BGRA5551 = 0x35314142,
396 + WL_DRM_FORMAT_RGB565 = 0x36314752,
397 + WL_DRM_FORMAT_BGR565 = 0x36314742,
398 + WL_DRM_FORMAT_RGB888 = 0x34324752,
399 + WL_DRM_FORMAT_BGR888 = 0x34324742,
400 + WL_DRM_FORMAT_XRGB8888 = 0x34325258,
401 + WL_DRM_FORMAT_XBGR8888 = 0x34324258,
402 + WL_DRM_FORMAT_RGBX8888 = 0x34325852,
403 + WL_DRM_FORMAT_BGRX8888 = 0x34325842,
404 + WL_DRM_FORMAT_ARGB8888 = 0x34325241,
405 + WL_DRM_FORMAT_ABGR8888 = 0x34324241,
406 + WL_DRM_FORMAT_RGBA8888 = 0x34324152,
407 + WL_DRM_FORMAT_BGRA8888 = 0x34324142,
408 + WL_DRM_FORMAT_XRGB2101010 = 0x30335258,
409 + WL_DRM_FORMAT_XBGR2101010 = 0x30334258,
410 + WL_DRM_FORMAT_RGBX1010102 = 0x30335852,
411 + WL_DRM_FORMAT_BGRX1010102 = 0x30335842,
412 + WL_DRM_FORMAT_ARGB2101010 = 0x30335241,
413 + WL_DRM_FORMAT_ABGR2101010 = 0x30334241,
414 + WL_DRM_FORMAT_RGBA1010102 = 0x30334152,
415 + WL_DRM_FORMAT_BGRA1010102 = 0x30334142,
416 + WL_DRM_FORMAT_YUYV = 0x56595559,
417 + WL_DRM_FORMAT_YVYU = 0x55595659,
418 + WL_DRM_FORMAT_UYVY = 0x59565955,
419 + WL_DRM_FORMAT_VYUY = 0x59555956,
420 + WL_DRM_FORMAT_AYUV = 0x56555941,
421 + WL_DRM_FORMAT_NV12 = 0x3231564e,
422 + WL_DRM_FORMAT_NV21 = 0x3132564e,
423 + WL_DRM_FORMAT_NV16 = 0x3631564e,
424 + WL_DRM_FORMAT_NV61 = 0x3136564e,
425 + WL_DRM_FORMAT_YUV410 = 0x39565559,
426 + WL_DRM_FORMAT_YVU410 = 0x39555659,
427 + WL_DRM_FORMAT_YUV411 = 0x31315559,
428 + WL_DRM_FORMAT_YVU411 = 0x31315659,
429 + WL_DRM_FORMAT_YUV420 = 0x32315559,
430 + WL_DRM_FORMAT_YVU420 = 0x32315659,
431 + WL_DRM_FORMAT_YUV422 = 0x36315559,
432 + WL_DRM_FORMAT_YVU422 = 0x36315659,
433 + WL_DRM_FORMAT_YUV444 = 0x34325559,
434 + WL_DRM_FORMAT_YVU444 = 0x34325659,
436 +#endif /* WL_DRM_FORMAT_ENUM */
438 +struct wl_drm_listener {
443 + void (*device)(void *data,
444 + struct wl_drm *wl_drm,
450 + void (*format)(void *data,
451 + struct wl_drm *wl_drm,
454 + * authenticated - (none)
456 + void (*authenticated)(void *data,
457 + struct wl_drm *wl_drm);
461 +wl_drm_add_listener(struct wl_drm *wl_drm,
462 + const struct wl_drm_listener *listener, void *data)
464 + return wl_proxy_add_listener((struct wl_proxy *) wl_drm,
465 + (void (**)(void)) listener, data);
468 +#define WL_DRM_AUTHENTICATE 0
469 +#define WL_DRM_CREATE_BUFFER 1
470 +#define WL_DRM_CREATE_PLANAR_BUFFER 2
473 +wl_drm_set_user_data(struct wl_drm *wl_drm, void *user_data)
475 + wl_proxy_set_user_data((struct wl_proxy *) wl_drm, user_data);
478 +static inline void *
479 +wl_drm_get_user_data(struct wl_drm *wl_drm)
481 + return wl_proxy_get_user_data((struct wl_proxy *) wl_drm);
485 +wl_drm_destroy(struct wl_drm *wl_drm)
487 + wl_proxy_destroy((struct wl_proxy *) wl_drm);
491 +wl_drm_authenticate(struct wl_drm *wl_drm, uint32_t id)
493 + wl_proxy_marshal((struct wl_proxy *) wl_drm,
494 + WL_DRM_AUTHENTICATE, id);
497 +static inline struct wl_buffer *
498 +wl_drm_create_buffer(struct wl_drm *wl_drm, uint32_t name, int32_t width, int32_t height, uint32_t stride, uint32_t format)
500 + struct wl_proxy *id;
502 + id = wl_proxy_create((struct wl_proxy *) wl_drm,
503 + &wl_buffer_interface);
507 + wl_proxy_marshal((struct wl_proxy *) wl_drm,
508 + WL_DRM_CREATE_BUFFER, id, name, width, height, stride, format);
510 + return (struct wl_buffer *) id;
513 +static inline struct wl_buffer *
514 +wl_drm_create_planar_buffer(struct wl_drm *wl_drm, uint32_t name, int32_t width, int32_t height, uint32_t format, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2)
516 + struct wl_proxy *id;
518 + id = wl_proxy_create((struct wl_proxy *) wl_drm,
519 + &wl_buffer_interface);
523 + wl_proxy_marshal((struct wl_proxy *) wl_drm,
524 + WL_DRM_CREATE_PLANAR_BUFFER, id, name, width, height, format, offset0, stride0, offset1, stride1, offset2, stride2);
526 + return (struct wl_buffer *) id;
534 diff --git a/ext/wayland/wayland-drm-protocol.c b/ext/wayland/wayland-drm-protocol.c
536 index 0000000..939af53
538 +++ b/ext/wayland/wayland-drm-protocol.c
541 + * Copyright © 2008-2011 Kristian Høgsberg
542 + * Copyright © 2010-2011 Intel Corporation
544 + * Permission to use, copy, modify, distribute, and sell this
545 + * software and its documentation for any purpose is hereby granted
546 + * without fee, provided that\n the above copyright notice appear in
547 + * all copies and that both that copyright notice and this permission
548 + * notice appear in supporting documentation, and that the name of
549 + * the copyright holders not be used in advertising or publicity
550 + * pertaining to distribution of the software without specific,
551 + * written prior permission. The copyright holders make no
552 + * representations about the suitability of this software for any
553 + * purpose. It is provided "as is" without express or implied
556 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
557 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
558 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
559 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
560 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
561 + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
562 + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
568 +#include "wayland-util.h"
570 +#define ARRAY_LENGTH(a) (sizeof (a) /sizeof (a)[0])
572 +extern const struct wl_interface wl_buffer_interface;
573 +extern const struct wl_interface wl_buffer_interface;
575 +static const struct wl_interface *types[] = {
577 + &wl_buffer_interface,
583 + &wl_buffer_interface,
596 +static const struct wl_message wl_drm_requests[] = {
597 + { "authenticate", "u", types + 0 },
598 + { "create_buffer", "nuiiuu", types + 1 },
599 + { "create_planar_buffer", "nuiiuiiiiii", types + 7 },
602 +static const struct wl_message wl_drm_events[] = {
603 + { "device", "s", types + 0 },
604 + { "format", "u", types + 0 },
605 + { "authenticated", "", types + 0 },
608 +WL_EXPORT const struct wl_interface wl_drm_interface = {
610 + ARRAY_LENGTH(wl_drm_requests), wl_drm_requests,
611 + ARRAY_LENGTH(wl_drm_events), wl_drm_events,
614 diff --git a/ext/wayland/wlbuffer.c b/ext/wayland/wlbuffer.c
615 index 4ac99ef..0e38d2e 100644
616 --- a/ext/wayland/wlbuffer.c
617 +++ b/ext/wayland/wlbuffer.c
619 * as soon as we remove the reference that GstWlDisplay holds.
622 -#include "wlbuffer.h"
623 +#include "wldisplay-wlwindow-wlbuffer.h"
625 GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
626 #define GST_CAT_DEFAULT gstwayland_debug
627 diff --git a/ext/wayland/wlbuffer.h b/ext/wayland/wlbuffer.h
628 deleted file mode 100644
629 index cbb50f7..0000000
630 --- a/ext/wayland/wlbuffer.h
633 -/* GStreamer Wayland video sink
635 - * Copyright (C) 2014 Collabora Ltd.
637 - * This library is free software; you can redistribute it and/or
638 - * modify it under the terms of the GNU Library General Public
639 - * License as published by the Free Software Foundation; either
640 - * version 2 of the License, or (at your option) any later version.
642 - * This library is distributed in the hope that it will be useful,
643 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
644 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
645 - * Library General Public License for more details.
647 - * You should have received a copy of the GNU Library General Public
648 - * License along with this library; if not, write to the Free
649 - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
650 - * Boston, MA 02110-1301 USA.
653 -#ifndef __GST_WL_BUFFER_H__
654 -#define __GST_WL_BUFFER_H__
656 -#include "wldisplay.h"
660 -#define GST_TYPE_WL_BUFFER (gst_wl_buffer_get_type ())
661 -#define GST_WL_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_BUFFER, GstWlBuffer))
662 -#define GST_IS_WL_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_BUFFER))
663 -#define GST_WL_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_BUFFER, GstWlBufferClass))
664 -#define GST_IS_WL_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_BUFFER))
665 -#define GST_WL_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_BUFFER, GstWlBufferClass))
667 -typedef struct _GstWlBuffer GstWlBuffer;
668 -typedef struct _GstWlBufferClass GstWlBufferClass;
672 - GObject parent_instance;
674 - struct wl_buffer * wlbuffer;
675 - GstBuffer *gstbuffer;
677 - GstWlDisplay *display;
679 - gboolean used_by_compositor;
682 -struct _GstWlBufferClass
684 - GObjectClass parent_class;
687 -GType gst_wl_buffer_get_type (void);
689 -GstWlBuffer * gst_buffer_add_wl_buffer (GstBuffer * gstbuffer,
690 - struct wl_buffer * wlbuffer, GstWlDisplay * display);
691 -GstWlBuffer * gst_buffer_get_wl_buffer (GstBuffer * gstbuffer);
693 -void gst_wl_buffer_force_release_and_unref (GstWlBuffer * self);
695 -void gst_wl_buffer_attach (GstWlBuffer * self, struct wl_surface *surface);
699 -#endif /* __GST_WL_BUFFER_H__ */
700 diff --git a/ext/wayland/wldisplay-wlwindow-wlbuffer.h b/ext/wayland/wldisplay-wlwindow-wlbuffer.h
702 index 0000000..684d145
704 +++ b/ext/wayland/wldisplay-wlwindow-wlbuffer.h
706 +/* GStreamer Wayland video sink
708 + * Copyright (C) 2014 Collabora Ltd.
710 + * This library is free software; you can redistribute it and/or
711 + * modify it under the terms of the GNU Library General Public
712 + * License as published by the Free Software Foundation; either
713 + * version 2 of the License, or (at your option) any later version.
715 + * This library is distributed in the hope that it will be useful,
716 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
717 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718 + * Library General Public License for more details.
720 + * You should have received a copy of the GNU Library General Public
721 + * License along with this library; if not, write to the Free
722 + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
723 + * Boston, MA 02110-1301 USA.
726 +#ifndef __GST_WL_DISPLAY_WL_WINDOW_H__
727 +#define __GST_WL_DISPLAY_WL_WINDOW_H__
729 +#include <gst/gst.h>
732 +#include <wayland-client.h>
733 +#include "scaler-client-protocol.h"
734 +#include <gst/video/video.h>
735 +#include <gst/video/gstvideometa.h>
739 +#define GST_TYPE_WL_DISPLAY (gst_wl_display_get_type ())
740 +#define GST_WL_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplay))
741 +#define GST_IS_WL_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_DISPLAY))
742 +#define GST_WL_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
743 +#define GST_IS_WL_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_DISPLAY))
744 +#define GST_WL_DISPLAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
746 +#define GST_TYPE_WL_WINDOW (gst_wl_window_get_type ())
747 +#define GST_WL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_WINDOW, GstWlWindow))
748 +#define GST_IS_WL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_WINDOW))
749 +#define GST_WL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_WINDOW, GstWlWindowClass))
750 +#define GST_IS_WL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_WINDOW))
751 +#define GST_WL_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_WINDOW, GstWlWindowClass))
753 +#define GST_TYPE_WL_BUFFER (gst_wl_buffer_get_type ())
754 +#define GST_WL_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_BUFFER, GstWlBuffer))
755 +#define GST_IS_WL_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_BUFFER))
756 +#define GST_WL_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_BUFFER, GstWlBufferClass))
757 +#define GST_IS_WL_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_BUFFER))
758 +#define GST_WL_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_BUFFER, GstWlBufferClass))
760 +typedef struct _GstWlBuffer GstWlBuffer;
761 +typedef struct _GstWlBufferClass GstWlBufferClass;
763 +typedef struct _GstWlWindow GstWlWindow;
764 +typedef struct _GstWlWindowClass GstWlWindowClass;
766 +typedef struct _GstWlDisplay GstWlDisplay;
767 +typedef struct _GstWlDisplayClass GstWlDisplayClass;
771 + GObject parent_instance;
773 + struct wl_buffer * wlbuffer;
774 + GstBuffer *gstbuffer;
776 + GstWlDisplay *display;
778 + gboolean used_by_compositor;
781 +struct _GstWlBufferClass
783 + GObjectClass parent_class;
786 +GType gst_wl_buffer_get_type (void);
788 +GstWlBuffer * gst_buffer_add_wl_buffer (GstBuffer * gstbuffer,
789 + struct wl_buffer * wlbuffer, GstWlDisplay * display);
790 +GstWlBuffer * gst_buffer_get_wl_buffer (GstBuffer * gstbuffer);
792 +void gst_wl_buffer_force_release_and_unref (GstWlBuffer * self);
794 +void gst_wl_buffer_attach (GstWlBuffer * self, struct wl_surface *surface);
800 + struct wl_list link;
805 + GstWlDisplay *display;
806 + struct wl_seat *seat;
807 + struct wl_pointer *pointer;
808 + struct wl_touch *touch;
809 + struct wl_list touch_point_list;
810 + GstWlWindow *pointer_focus;
811 + GstWlWindow *touch_focus;
812 + struct wl_list link;
819 + GObject parent_instance;
821 + GstWlDisplay *display;
822 + struct wl_surface *area_surface;
823 + struct wl_subsurface *area_subsurface;
824 + struct wl_viewport *area_viewport;
825 + struct wl_surface *video_surface;
826 + struct wl_subsurface *video_subsurface;
827 + struct wl_viewport *video_viewport;
828 + struct wl_shell_surface *shell_surface;
830 + /* the size and position of the area_(sub)surface */
831 + GstVideoRectangle render_rectangle;
832 + /* the size of the video in the buffers */
833 + gint video_width, video_height;
834 + /* the size of the video_(sub)surface */
835 + gint surface_width, surface_height;
838 +struct _GstWlWindowClass
840 + GObjectClass parent_class;
843 +GType gst_wl_window_get_type (void);
845 +GstWlWindow *gst_wl_window_new_toplevel (GstWlDisplay * display,
846 + const GstVideoInfo * info);
847 +GstWlWindow *gst_wl_window_new_in_surface (GstWlDisplay * display,
848 + struct wl_surface * parent);
850 +GstWlDisplay *gst_wl_window_get_display (GstWlWindow * window);
851 +struct wl_surface *gst_wl_window_get_wl_surface (GstWlWindow * window);
852 +gboolean gst_wl_window_is_toplevel (GstWlWindow *window);
854 +void gst_wl_window_render (GstWlWindow * window, GstWlBuffer * buffer,
855 + const GstVideoInfo * info);
856 +void gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y,
860 +struct _GstWlDisplay
862 + GObject parent_instance;
864 + /* public objects */
865 + struct wl_display *display;
866 + struct wl_event_queue *queue;
869 + struct wl_registry *registry;
870 + struct wl_compositor *compositor;
871 + struct wl_subcompositor *subcompositor;
872 + struct wl_shell *shell;
873 + struct wl_shm *shm;
874 + struct wl_drm *drm;
875 + struct wl_scaler *scaler;
876 + GArray *shm_formats;
879 + gboolean own_display;
881 + GstPoll *wl_fd_poll;
883 + GMutex buffers_mutex;
884 + GHashTable *buffers;
885 + gboolean shutting_down;
887 + /* the drm device.. needed for sharing direct-render buffers..
888 + * TODO nothing about this should really be omapdrm specific. But some
889 + * of the code, like hashtable of imported buffers in libdrm_omap should
890 + * be refactored out into some generic libdrm code..
892 + struct omap_device *dev;
897 + struct wl_list input_list;
901 + GstVideoCropMeta *crop;
904 +struct _GstWlDisplayClass
906 + GObjectClass parent_class;
909 +GType gst_wl_display_get_type (void);
911 +GstWlDisplay *gst_wl_display_new (const gchar * name, GError ** error);
912 +GstWlDisplay *gst_wl_display_new_existing (struct wl_display * display,
913 + gboolean take_ownership, GError ** error);
915 +/* see wlbuffer.c for explanation */
916 +void gst_wl_display_register_buffer (GstWlDisplay * self, gpointer buf);
917 +void gst_wl_display_unregister_buffer (GstWlDisplay * self, gpointer buf);
921 +#endif /* __GST_WL_DISPLAY_WL_WINDOW_H__ */
922 diff --git a/ext/wayland/wldisplay.c b/ext/wayland/wldisplay.c
923 index 3318095..2f58fd2 100644
924 --- a/ext/wayland/wldisplay.c
925 +++ b/ext/wayland/wldisplay.c
930 -#include "wldisplay.h"
931 -#include "wlbuffer.h"
933 +#include "wldisplay-wlwindow-wlbuffer.h"
935 +#include <wayland-client-protocol.h>
936 +#include "wayland-drm-client-protocol.h"
937 +#include <linux/input.h>
938 +#include <omap_drm.h>
939 +#include <omap_drmif.h>
944 GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
945 @@ -33,6 +39,8 @@ GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
946 G_DEFINE_TYPE (GstWlDisplay, gst_wl_display, G_TYPE_OBJECT);
948 static void gst_wl_display_finalize (GObject * gobject);
949 +static void input_grab (struct input *input, GstWlWindow *window);
950 +static void input_ungrab (struct input *input);
953 gst_wl_display_class_init (GstWlDisplayClass * klass)
954 @@ -45,12 +53,62 @@ static void
955 gst_wl_display_init (GstWlDisplay * self)
957 self->shm_formats = g_array_new (FALSE, FALSE, sizeof (uint32_t));
959 + self->use_drm = FALSE;
960 self->wl_fd_poll = gst_poll_new (TRUE);
961 self->buffers = g_hash_table_new (g_direct_hash, g_direct_equal);
962 g_mutex_init (&self->buffers_mutex);
966 +input_grab (struct input *input, GstWlWindow *window)
968 + input->grab = window;
972 +input_ungrab (struct input *input)
974 + input->grab = NULL;
978 +input_remove_pointer_focus (struct input *input)
980 + GstWlWindow *window = input->pointer_focus;
985 + input->pointer_focus = NULL;
989 +input_destroy (struct input *input)
991 + input_remove_pointer_focus (input);
993 + if (input->display->seat_version >= 3) {
994 + if (input->pointer)
995 + wl_pointer_release (input->pointer);
998 + wl_list_remove (&input->link);
999 + wl_seat_destroy (input->seat);
1004 +display_destroy_inputs (GstWlDisplay *display)
1006 + struct input *tmp;
1007 + struct input *input;
1009 + wl_list_for_each_safe (input, tmp, &display->input_list, link)
1010 + input_destroy (input);
1014 gst_wl_display_finalize (GObject * gobject)
1016 GstWlDisplay *self = GST_WL_DISPLAY (gobject);
1017 @@ -71,13 +129,26 @@ gst_wl_display_finalize (GObject * gobject)
1018 g_hash_table_remove_all (self->buffers);
1020 g_array_unref (self->shm_formats);
1023 + omap_device_del (self->dev);
1026 + if (self->fd !=-1)
1029 gst_poll_free (self->wl_fd_poll);
1030 g_hash_table_unref (self->buffers);
1031 g_mutex_clear (&self->buffers_mutex);
1033 + display_destroy_inputs (self);
1036 wl_shm_destroy (self->shm);
1039 + wl_drm_destroy (self->drm);
1042 wl_shell_destroy (self->shell);
1044 @@ -138,12 +209,277 @@ shm_format (void *data, struct wl_shm *wl_shm, uint32_t format)
1045 GstWlDisplay *self = data;
1047 g_array_append_val (self->shm_formats, format);
1048 + GST_DEBUG ("shm got format: %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (format));
1051 static const struct wl_shm_listener shm_listener = {
1055 +/* For wl_drm_listener */
1058 +drm_handle_device (void *data, struct wl_drm *drm, const char *device)
1060 + GstWlDisplay *d = data;
1061 + drm_magic_t magic;
1062 + d->fd = open (device, O_RDWR | O_CLOEXEC);
1063 + if (d->fd == -1) {
1064 + GST_ERROR ("could not open %s: %m", device);
1067 + drmGetMagic (d->fd, &magic);
1068 + wl_drm_authenticate (d->drm, magic);
1072 +drm_handle_format (void *data, struct wl_drm *drm, uint32_t format)
1074 + GstWlDisplay *self = data;
1075 + g_array_append_val (self->shm_formats, format);
1076 + GST_DEBUG ("drm got format: %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (format));
1080 +drm_handle_authenticated (void *data, struct wl_drm *drm)
1082 + GstWlDisplay *d = data;
1083 + GST_DEBUG ("authenticated");
1084 + d->dev = omap_device_new (d->fd);
1085 + d->authenticated = 1;
1086 + GST_DEBUG ("drm_handle_authenticated: dev: %p, d->authenticated: %d\n",
1087 + d->dev, d->authenticated);
1090 +static const struct wl_drm_listener drm_listener = {
1091 + drm_handle_device,
1092 + drm_handle_format,
1093 + drm_handle_authenticated
1098 +pointer_handle_enter (void *data, struct wl_pointer *pointer,
1099 + uint32_t serial, struct wl_surface *surface,
1100 + wl_fixed_t sx_w, wl_fixed_t sy_w)
1102 + struct input *input = data;
1105 + /* enter event for a window we've just destroyed */
1109 + input->display->serial = serial;
1110 + input->pointer_focus = wl_surface_get_user_data (surface);
1114 +pointer_handle_leave (void *data, struct wl_pointer *pointer,
1115 + uint32_t serial, struct wl_surface *surface)
1117 + struct input *input = data;
1119 + input_remove_pointer_focus (input);
1123 +pointer_handle_motion (void *data, struct wl_pointer *pointer,
1124 + uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
1126 + struct input *input = data;
1127 + GstWlWindow *window = input->pointer_focus;
1133 + wl_shell_surface_move (input->grab->shell_surface, input->seat,
1134 + input->display->serial);
1139 +pointer_handle_button (void *data, struct wl_pointer *pointer, uint32_t serial,
1140 + uint32_t time, uint32_t button, uint32_t state_w)
1142 + struct input *input = data;
1143 + enum wl_pointer_button_state state = state_w;
1144 + input->display->serial = serial;
1146 + if (button == BTN_LEFT) {
1147 + if (state == WL_POINTER_BUTTON_STATE_PRESSED)
1148 + input_grab (input, input->pointer_focus);
1150 + if (input->grab && state == WL_POINTER_BUTTON_STATE_RELEASED)
1151 + input_ungrab (input);
1155 + wl_shell_surface_move (input->grab->shell_surface, input->seat,
1156 + input->display->serial);
1160 +pointer_handle_axis (void *data, struct wl_pointer *pointer,
1161 + uint32_t time, uint32_t axis, wl_fixed_t value)
1165 +static const struct wl_pointer_listener pointer_listener = {
1166 + pointer_handle_enter,
1167 + pointer_handle_leave,
1168 + pointer_handle_motion,
1169 + pointer_handle_button,
1170 + pointer_handle_axis,
1174 +touch_handle_down (void *data, struct wl_touch *wl_touch,
1175 + uint32_t serial, uint32_t time, struct wl_surface *surface,
1176 + int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
1178 + struct input *input = data;
1179 + struct touch_point *tp;
1181 + input->display->serial = serial;
1182 + input->touch_focus = wl_surface_get_user_data (surface);
1183 + if (!input->touch_focus) {
1187 + tp = malloc (sizeof *tp);
1190 + wl_list_insert (&input->touch_point_list, &tp->link);
1191 + wl_shell_surface_move (input->touch_focus->shell_surface, input->seat,
1197 +touch_handle_motion (void *data, struct wl_touch *wl_touch,
1198 + uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
1200 + struct input *input = data;
1201 + struct touch_point *tp;
1204 + if (!input->touch_focus) {
1207 + wl_list_for_each (tp, &input->touch_point_list, link) {
1211 + wl_shell_surface_move (input->touch_focus->shell_surface, input->seat,
1212 + input->display->serial);
1219 +touch_handle_frame (void *data, struct wl_touch *wl_touch)
1224 +touch_handle_cancel (void *data, struct wl_touch *wl_touch)
1229 +touch_handle_up (void *data, struct wl_touch *wl_touch,
1230 + uint32_t serial, uint32_t time, int32_t id)
1232 + struct input *input = data;
1233 + struct touch_point *tp, *tmp;
1235 + if (!input->touch_focus) {
1239 + wl_list_for_each_safe (tp, tmp, &input->touch_point_list, link) {
1243 + wl_list_remove (&tp->link);
1250 +static const struct wl_touch_listener touch_listener = {
1251 + touch_handle_down,
1253 + touch_handle_motion,
1254 + touch_handle_frame,
1255 + touch_handle_cancel,
1260 +seat_handle_capabilities (void *data, struct wl_seat *seat,
1261 + enum wl_seat_capability caps)
1263 + struct input *input = data;
1265 + if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
1266 + input->pointer = wl_seat_get_pointer (seat);
1267 + wl_pointer_set_user_data (input->pointer, input);
1268 + wl_pointer_add_listener (input->pointer, &pointer_listener, input);
1269 + } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
1270 + wl_pointer_destroy (input->pointer);
1271 + input->pointer = NULL;
1274 + if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
1275 + input->touch = wl_seat_get_touch (seat);
1276 + wl_touch_set_user_data (input->touch, input);
1277 + wl_touch_add_listener (input->touch, &touch_listener, input);
1278 + } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) {
1279 + wl_touch_destroy (input->touch);
1280 + input->touch = NULL;
1285 +seat_handle_name (void *data, struct wl_seat *seat, const char *name)
1290 +static const struct wl_seat_listener seat_listener = {
1291 + seat_handle_capabilities,
1296 +display_add_input (GstWlDisplay *d, uint32_t id)
1298 + struct input *input;
1300 + input = calloc (1, sizeof (*input));
1301 + if (input == NULL) {
1302 + fprintf (stderr, "%s: out of memory\n", "gst-wayland-sink");
1303 + exit (EXIT_FAILURE);
1305 + input->display = d;
1306 + input->seat = wl_registry_bind (d->registry, id, &wl_seat_interface,
1307 + MAX (d->seat_version, 3));
1308 + input->touch_focus = NULL;
1309 + input->pointer_focus = NULL;
1310 + wl_list_init (&input->touch_point_list);
1311 + wl_list_insert (d->input_list.prev, &input->link);
1313 + wl_seat_add_listener (input->seat, &seat_listener, input);
1314 + wl_seat_set_user_data (input->seat, input);
1320 registry_handle_global (void *data, struct wl_registry *registry,
1321 uint32_t id, const char *interface, uint32_t version)
1322 @@ -161,6 +497,12 @@ registry_handle_global (void *data, struct wl_registry *registry,
1323 } else if (g_strcmp0 (interface, "wl_shm") == 0) {
1324 self->shm = wl_registry_bind (registry, id, &wl_shm_interface, 1);
1325 wl_shm_add_listener (self->shm, &shm_listener, self);
1326 + } else if (g_strcmp0 (interface, "wl_drm") == 0) {
1327 + self->drm = wl_registry_bind (registry, id, &wl_drm_interface, 1);
1328 + wl_drm_add_listener (self->drm, &drm_listener, self);
1329 + } else if (g_strcmp0 (interface, "wl_seat") == 0) {
1330 + self->seat_version = version;
1331 + display_add_input (self, id);
1332 } else if (g_strcmp0 (interface, "wl_scaler") == 0) {
1333 self->scaler = wl_registry_bind (registry, id, &wl_scaler_interface, 2);
1335 @@ -238,6 +580,7 @@ gst_wl_display_new_existing (struct wl_display * display,
1336 self->own_display = take_ownership;
1338 self->queue = wl_display_create_queue (self->display);
1339 + wl_list_init (&self->input_list);
1340 self->registry = wl_display_get_registry (self->display);
1341 wl_proxy_set_queue ((struct wl_proxy *) self->registry, self->queue);
1342 wl_registry_add_listener (self->registry, ®istry_listener, self);
1343 @@ -266,6 +609,7 @@ gst_wl_display_new_existing (struct wl_display * display,
1344 VERIFY_INTERFACE_EXISTS (subcompositor, "wl_subcompositor");
1345 VERIFY_INTERFACE_EXISTS (shell, "wl_shell");
1346 VERIFY_INTERFACE_EXISTS (shm, "wl_shm");
1347 + VERIFY_INTERFACE_EXISTS (drm, "wl_drm");
1348 VERIFY_INTERFACE_EXISTS (scaler, "wl_scaler");
1350 #undef VERIFY_INTERFACE_EXISTS
1351 diff --git a/ext/wayland/wldisplay.h b/ext/wayland/wldisplay.h
1352 deleted file mode 100644
1353 index e9df749..0000000
1354 --- a/ext/wayland/wldisplay.h
1357 -/* GStreamer Wayland video sink
1359 - * Copyright (C) 2014 Collabora Ltd.
1361 - * This library is free software; you can redistribute it and/or
1362 - * modify it under the terms of the GNU Library General Public
1363 - * License as published by the Free Software Foundation; either
1364 - * version 2 of the License, or (at your option) any later version.
1366 - * This library is distributed in the hope that it will be useful,
1367 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1368 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1369 - * Library General Public License for more details.
1371 - * You should have received a copy of the GNU Library General Public
1372 - * License along with this library; if not, write to the Free
1373 - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1374 - * Boston, MA 02110-1301 USA.
1377 -#ifndef __GST_WL_DISPLAY_H__
1378 -#define __GST_WL_DISPLAY_H__
1380 -#include <gst/gst.h>
1381 -#include <wayland-client.h>
1382 -#include "scaler-client-protocol.h"
1386 -#define GST_TYPE_WL_DISPLAY (gst_wl_display_get_type ())
1387 -#define GST_WL_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplay))
1388 -#define GST_IS_WL_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_DISPLAY))
1389 -#define GST_WL_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
1390 -#define GST_IS_WL_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_DISPLAY))
1391 -#define GST_WL_DISPLAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
1393 -typedef struct _GstWlDisplay GstWlDisplay;
1394 -typedef struct _GstWlDisplayClass GstWlDisplayClass;
1396 -struct _GstWlDisplay
1398 - GObject parent_instance;
1400 - /* public objects */
1401 - struct wl_display *display;
1402 - struct wl_event_queue *queue;
1405 - struct wl_registry *registry;
1406 - struct wl_compositor *compositor;
1407 - struct wl_subcompositor *subcompositor;
1408 - struct wl_shell *shell;
1409 - struct wl_shm *shm;
1410 - struct wl_scaler *scaler;
1411 - GArray *shm_formats;
1414 - gboolean own_display;
1416 - GstPoll *wl_fd_poll;
1418 - GMutex buffers_mutex;
1419 - GHashTable *buffers;
1420 - gboolean shutting_down;
1423 -struct _GstWlDisplayClass
1425 - GObjectClass parent_class;
1428 -GType gst_wl_display_get_type (void);
1430 -GstWlDisplay *gst_wl_display_new (const gchar * name, GError ** error);
1431 -GstWlDisplay *gst_wl_display_new_existing (struct wl_display * display,
1432 - gboolean take_ownership, GError ** error);
1434 -/* see wlbuffer.c for explanation */
1435 -void gst_wl_display_register_buffer (GstWlDisplay * self, gpointer buf);
1436 -void gst_wl_display_unregister_buffer (GstWlDisplay * self, gpointer buf);
1440 -#endif /* __GST_WL_DISPLAY_H__ */
1441 diff --git a/ext/wayland/wldrm.c b/ext/wayland/wldrm.c
1442 new file mode 100644
1443 index 0000000..3dc9c21
1445 +++ b/ext/wayland/wldrm.c
1447 +#include "wldisplay-wlwindow-wlbuffer.h"
1448 +#include <gst/drm/gstdrmallocator.h>
1449 +#include "wayland-drm-client-protocol.h"
1450 +#include <omap_drm.h>
1451 +#include <omap_drmif.h>
1452 +#include <wayland-client.h>
1455 +gst_wl_drm_memory_construct_wl_buffer (GstMemory * mem, GstWlDisplay * display,
1456 + const GstVideoInfo * info)
1458 + gint video_width = GST_VIDEO_INFO_WIDTH (info);
1459 + gint video_height = GST_VIDEO_INFO_HEIGHT (info);
1461 + struct omap_bo *bo;
1462 + struct wl_buffer *buffer;
1464 + /* TODO get format, etc from caps.. and query device for
1465 + * supported formats, and make this all more flexible to
1466 + * cope with various formats:
1468 + uint32_t fourcc = GST_MAKE_FOURCC ('N', 'V', '1', '2');
1470 + /* note: wayland and mesa use the terminology:
1471 + * stride - rowstride in bytes
1472 + * pitch - rowstride in pixels
1474 + uint32_t strides[3] = {
1475 + GST_ROUND_UP_4 (video_width), GST_ROUND_UP_4 (video_width), 0,
1477 + uint32_t offsets[3] = {
1478 + 0, strides[0] * video_height, 0
1481 + fd = gst_fd_memory_get_fd (mem);
1484 + GST_DEBUG ("Invalid fd");
1488 + bo = omap_bo_from_dmabuf (display->dev, fd);
1490 + struct drm_gem_flink req = {
1491 + .handle = omap_bo_handle(bo),
1495 + ret = drmIoctl(display->fd, DRM_IOCTL_GEM_FLINK, &req);
1497 + GST_DEBUG ("could not get name, DRM_IOCTL_GEM_FLINK returned %d", ret);
1503 + GST_LOG ("width = %d , height = %d , fourcc = %d ", video_width, video_height, fourcc );
1504 + buffer = wl_drm_create_planar_buffer (display->drm, name,
1505 + video_width, video_height, fourcc,
1506 + offsets[0], strides[0],
1507 + offsets[1], strides[1],
1508 + offsets[2], strides[2]);
1510 + GST_DEBUG ("create planar buffer: %p (name=%d)",
1516 diff --git a/ext/wayland/wldrm.h b/ext/wayland/wldrm.h
1517 new file mode 100644
1518 index 0000000..9751029
1520 +++ b/ext/wayland/wldrm.h
1523 +gst_wl_drm_memory_construct_wl_buffer (GstMemory * mem, GstWlDisplay * display,
1524 + const GstVideoInfo * info);
1525 diff --git a/ext/wayland/wlshmallocator.h b/ext/wayland/wlshmallocator.h
1526 index 07ae17f..2860fc3 100644
1527 --- a/ext/wayland/wlshmallocator.h
1528 +++ b/ext/wayland/wlshmallocator.h
1530 #include <gst/video/video.h>
1531 #include <gst/allocators/allocators.h>
1532 #include <wayland-client-protocol.h>
1533 -#include "wldisplay.h"
1534 +#include "wldisplay-wlwindow-wlbuffer.h"
1538 diff --git a/ext/wayland/wlvideoformat.c b/ext/wayland/wlvideoformat.c
1539 index 1302da6..aa336aa 100644
1540 --- a/ext/wayland/wlvideoformat.c
1541 +++ b/ext/wayland/wlvideoformat.c
1542 @@ -106,6 +106,10 @@ gst_wl_shm_format_to_video_format (enum wl_shm_format wl_format)
1544 gst_wl_shm_format_to_string (enum wl_shm_format wl_format)
1546 - return gst_video_format_to_string
1547 - (gst_wl_shm_format_to_video_format (wl_format));
1548 + GstVideoFormat fmt = gst_wl_shm_format_to_video_format (wl_format);
1549 + if (fmt != GST_VIDEO_FORMAT_UNKNOWN) {
1550 + return gst_video_format_to_string (fmt);
1555 diff --git a/ext/wayland/wlwindow.c b/ext/wayland/wlwindow.c
1556 index 79000ae..f7e3324 100644
1557 --- a/ext/wayland/wlwindow.c
1558 +++ b/ext/wayland/wlwindow.c
1563 -#include "wlwindow.h"
1564 +#include "wldisplay-wlwindow-wlbuffer.h"
1565 #include "wlshmallocator.h"
1566 -#include "wlbuffer.h"
1568 +#include <gst/drm/gstdrmallocator.h>
1570 GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
1571 #define GST_CAT_DEFAULT gstwayland_debug
1572 @@ -111,6 +112,8 @@ gst_wl_window_new_internal (GstWlDisplay * display)
1574 window->area_surface = wl_compositor_create_surface (display->compositor);
1575 window->video_surface = wl_compositor_create_surface (display->compositor);
1576 + wl_surface_set_user_data (window->area_surface, window);
1577 + wl_surface_set_user_data (window->video_surface, window);
1579 wl_proxy_set_queue ((struct wl_proxy *) window->area_surface, display->queue);
1580 wl_proxy_set_queue ((struct wl_proxy *) window->video_surface,
1581 @@ -126,6 +129,21 @@ gst_wl_window_new_internal (GstWlDisplay * display)
1582 window->area_surface);
1583 window->video_viewport = wl_scaler_get_viewport (display->scaler,
1584 window->video_surface);
1585 + if (display->crop) {
1586 + GST_DEBUG ("Setting source crop : %d %d %d %d",display->crop->x, display->crop->y,
1587 + display->crop->width, display->crop->height);
1588 + wl_viewport_set_source (window->area_viewport,
1589 + wl_fixed_from_int(display->crop->x),
1590 + wl_fixed_from_int(display->crop->y),
1591 + wl_fixed_from_int(display->crop->width),
1592 + wl_fixed_from_int(display->crop->height));
1593 + wl_viewport_set_source (window->video_viewport,
1594 + wl_fixed_from_int(display->crop->x),
1595 + wl_fixed_from_int(display->crop->y),
1596 + wl_fixed_from_int(display->crop->width),
1597 + wl_fixed_from_int(display->crop->height));
1601 /* draw the area_subsurface */
1602 gst_video_info_set_format (&info,
1603 @@ -136,14 +154,25 @@ gst_wl_window_new_internal (GstWlDisplay * display)
1604 GST_VIDEO_FORMAT_BGRx,
1608 - buf = gst_buffer_new_allocate (gst_wl_shm_allocator_get (), info.size, NULL);
1609 + if (display->use_drm) {
1610 + buf = gst_buffer_new_allocate (gst_drm_allocator_get (), info.size, NULL);
1612 + buf = gst_buffer_new_allocate (gst_wl_shm_allocator_get (), info.size, NULL);
1614 gst_buffer_map (buf, &mapinfo, GST_MAP_WRITE);
1615 - *((guint32 *) mapinfo.data) = 0; /* paint it black */
1616 - gst_buffer_unmap (buf, &mapinfo);
1618 - gst_wl_shm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0),
1620 + *((guint32 *) mapinfo.data) = 0; /* paint it black */
1621 + gst_buffer_unmap (buf, &mapinfo);
1623 + if (display->use_drm) {
1625 + gst_wl_drm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0),
1629 + gst_wl_shm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0),
1633 gwlbuf = gst_buffer_add_wl_buffer (buf, wlbuf, display);
1634 gst_wl_buffer_attach (gwlbuf, window->area_surface);
1636 diff --git a/ext/wayland/wlwindow.h b/ext/wayland/wlwindow.h
1637 deleted file mode 100644
1638 index e22cb26..0000000
1639 --- a/ext/wayland/wlwindow.h
1642 -/* GStreamer Wayland video sink
1644 - * Copyright (C) 2014 Collabora Ltd.
1646 - * This library is free software; you can redistribute it and/or
1647 - * modify it under the terms of the GNU Library General Public
1648 - * License as published by the Free Software Foundation; either
1649 - * version 2 of the License, or (at your option) any later version.
1651 - * This library is distributed in the hope that it will be useful,
1652 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1653 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1654 - * Library General Public License for more details.
1656 - * You should have received a copy of the GNU Library General Public
1657 - * License along with this library; if not, write to the Free
1658 - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1659 - * Boston, MA 02110-1301 USA.
1662 -#ifndef __GST_WL_WINDOW_H__
1663 -#define __GST_WL_WINDOW_H__
1665 -#include "wldisplay.h"
1666 -#include "wlbuffer.h"
1667 -#include <gst/video/video.h>
1671 -#define GST_TYPE_WL_WINDOW (gst_wl_window_get_type ())
1672 -#define GST_WL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_WINDOW, GstWlWindow))
1673 -#define GST_IS_WL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_WINDOW))
1674 -#define GST_WL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_WINDOW, GstWlWindowClass))
1675 -#define GST_IS_WL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_WINDOW))
1676 -#define GST_WL_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_WINDOW, GstWlWindowClass))
1678 -typedef struct _GstWlWindow GstWlWindow;
1679 -typedef struct _GstWlWindowClass GstWlWindowClass;
1681 -struct _GstWlWindow
1683 - GObject parent_instance;
1685 - GstWlDisplay *display;
1686 - struct wl_surface *area_surface;
1687 - struct wl_subsurface *area_subsurface;
1688 - struct wl_viewport *area_viewport;
1689 - struct wl_surface *video_surface;
1690 - struct wl_subsurface *video_subsurface;
1691 - struct wl_viewport *video_viewport;
1692 - struct wl_shell_surface *shell_surface;
1694 - /* the size and position of the area_(sub)surface */
1695 - GstVideoRectangle render_rectangle;
1696 - /* the size of the video in the buffers */
1697 - gint video_width, video_height;
1698 - /* the size of the video_(sub)surface */
1699 - gint surface_width, surface_height;
1702 -struct _GstWlWindowClass
1704 - GObjectClass parent_class;
1707 -GType gst_wl_window_get_type (void);
1709 -GstWlWindow *gst_wl_window_new_toplevel (GstWlDisplay * display,
1710 - const GstVideoInfo * info);
1711 -GstWlWindow *gst_wl_window_new_in_surface (GstWlDisplay * display,
1712 - struct wl_surface * parent);
1714 -GstWlDisplay *gst_wl_window_get_display (GstWlWindow * window);
1715 -struct wl_surface *gst_wl_window_get_wl_surface (GstWlWindow * window);
1716 -gboolean gst_wl_window_is_toplevel (GstWlWindow *window);
1718 -void gst_wl_window_render (GstWlWindow * window, GstWlBuffer * buffer,
1719 - const GstVideoInfo * info);
1720 -void gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y,
1725 -#endif /* __GST_WL_WINDOW_H__ */