1 /* GStreamer Wayland video sink
3 * Copyright (C) 2011 Intel Corporation
4 * Copyright (C) 2011 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
5 * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
6 * Copyright (C) 2014 Collabora Ltd.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
25 * SECTION:element-waylandsink
27 * The waylandsink is creating its own window and render the decoded video frames to that.
28 * Setup the Wayland environment as described in
29 * <ulink url="http://wayland.freedesktop.org/building.html">Wayland</ulink> home page.
30 * The current implementaion is based on weston compositor.
33 * <title>Example pipelines</title>
35 * gst-launch -v videotestsrc ! waylandsink
36 * ]| test the video rendering in wayland
44 #include "gstwaylandsink.h"
45 #include "wlvideoformat.h"
47 #include "wlshmallocator.h"
49 #include <gst/wayland/wayland.h>
50 #include <gst/video/videooverlay.h>
66 GST_DEBUG_CATEGORY (gstwayland_debug);
67 #define GST_CAT_DEFAULT gstwayland_debug
69 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
72 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
73 ("{ BGRx, BGRA, RGBx, xBGR, xRGB, RGBA, ABGR, ARGB, RGB, BGR, "
74 "RGB16, BGR16, YUY2, YVYU, UYVY, AYUV, NV12, NV21, NV16, "
75 "YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }"))
78 static void gst_wayland_sink_get_property (GObject * object,
79 guint prop_id, GValue * value, GParamSpec * pspec);
80 static void gst_wayland_sink_set_property (GObject * object,
81 guint prop_id, const GValue * value, GParamSpec * pspec);
82 static void gst_wayland_sink_finalize (GObject * object);
84 static GstStateChangeReturn gst_wayland_sink_change_state (GstElement * element,
85 GstStateChange transition);
86 static void gst_wayland_sink_set_context (GstElement * element,
87 GstContext * context);
89 static GstCaps *gst_wayland_sink_get_caps (GstBaseSink * bsink,
91 static gboolean gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
92 static gboolean gst_wayland_sink_preroll (GstBaseSink * bsink,
95 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query);
96 static gboolean gst_wayland_sink_render (GstBaseSink * bsink,
99 /* VideoOverlay interface */
100 static void gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface *
102 static void gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay,
104 static void gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
105 gint x, gint y, gint w, gint h);
106 static void gst_wayland_sink_expose (GstVideoOverlay * overlay);
108 /* WaylandVideo interface */
109 static void gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface *
111 static void gst_wayland_sink_begin_geometry_change (GstWaylandVideo * video);
112 static void gst_wayland_sink_end_geometry_change (GstWaylandVideo * video);
114 #define gst_wayland_sink_parent_class parent_class
115 G_DEFINE_TYPE_WITH_CODE (GstWaylandSink, gst_wayland_sink, GST_TYPE_VIDEO_SINK,
116 G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY,
117 gst_wayland_sink_videooverlay_init)
118 G_IMPLEMENT_INTERFACE (GST_TYPE_WAYLAND_VIDEO,
119 gst_wayland_sink_waylandvideo_init));
122 gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
124 GObjectClass *gobject_class;
125 GstElementClass *gstelement_class;
126 GstBaseSinkClass *gstbasesink_class;
128 gobject_class = (GObjectClass *) klass;
129 gstelement_class = (GstElementClass *) klass;
130 gstbasesink_class = (GstBaseSinkClass *) klass;
132 gobject_class->set_property = gst_wayland_sink_set_property;
133 gobject_class->get_property = gst_wayland_sink_get_property;
134 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wayland_sink_finalize);
136 gst_element_class_add_pad_template (gstelement_class,
137 gst_static_pad_template_get (&sink_template));
139 gst_element_class_set_static_metadata (gstelement_class,
140 "wayland video sink", "Sink/Video",
141 "Output to wayland surface",
142 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>, "
143 "George Kiagiadakis <george.kiagiadakis@collabora.com>");
145 gstelement_class->change_state =
146 GST_DEBUG_FUNCPTR (gst_wayland_sink_change_state);
147 gstelement_class->set_context =
148 GST_DEBUG_FUNCPTR (gst_wayland_sink_set_context);
150 gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_get_caps);
151 gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_set_caps);
152 gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_wayland_sink_preroll);
153 gstbasesink_class->propose_allocation =
154 GST_DEBUG_FUNCPTR (gst_wayland_sink_propose_allocation);
155 gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_wayland_sink_render);
157 g_object_class_install_property (gobject_class, PROP_DISPLAY,
158 g_param_spec_string ("display", "Wayland Display name", "Wayland "
159 "display name to connect to, if not supplied via the GstContext",
160 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
164 gst_wayland_sink_init (GstWaylandSink * sink)
166 g_mutex_init (&sink->display_lock);
167 g_mutex_init (&sink->render_lock);
171 gst_wayland_sink_get_property (GObject * object,
172 guint prop_id, GValue * value, GParamSpec * pspec)
174 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
178 GST_OBJECT_LOCK (sink);
179 g_value_set_string (value, sink->display_name);
180 GST_OBJECT_UNLOCK (sink);
183 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
189 gst_wayland_sink_set_property (GObject * object,
190 guint prop_id, const GValue * value, GParamSpec * pspec)
192 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
196 GST_OBJECT_LOCK (sink);
197 sink->display_name = g_value_dup_string (value);
198 GST_OBJECT_UNLOCK (sink);
201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
207 gst_wayland_sink_finalize (GObject * object)
209 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
211 GST_DEBUG_OBJECT (sink, "Finalizing the sink..");
213 if (sink->last_buffer)
214 gst_buffer_unref (sink->last_buffer);
216 g_object_unref (sink->display);
218 g_object_unref (sink->window);
220 gst_object_unref (sink->pool);
222 if (sink->display_name)
223 g_free (sink->display_name);
225 g_mutex_clear (&sink->display_lock);
226 g_mutex_clear (&sink->render_lock);
228 G_OBJECT_CLASS (parent_class)->finalize (object);
231 /* must be called with the display_lock */
233 gst_wayland_sink_set_display_from_context (GstWaylandSink * sink,
234 GstContext * context)
236 struct wl_display *display;
237 GError *error = NULL;
239 display = gst_wayland_display_handle_context_get_handle (context);
240 sink->display = gst_wl_display_new_existing (display, FALSE, &error);
243 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
244 ("Could not set display handle"),
245 ("Failed to use the external wayland display: '%s'", error->message));
246 g_error_free (error);
251 gst_wayland_sink_find_display (GstWaylandSink * sink)
255 GstContext *context = NULL;
256 GError *error = NULL;
259 g_mutex_lock (&sink->display_lock);
261 if (!sink->display) {
262 /* first query upstream for the needed display handle */
263 query = gst_query_new_context (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
264 if (gst_pad_peer_query (GST_VIDEO_SINK_PAD (sink), query)) {
265 gst_query_parse_context (query, &context);
266 gst_wayland_sink_set_display_from_context (sink, context);
268 gst_query_unref (query);
270 if (G_LIKELY (!sink->display)) {
271 /* now ask the application to set the display handle */
272 msg = gst_message_new_need_context (GST_OBJECT_CAST (sink),
273 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
275 g_mutex_unlock (&sink->display_lock);
276 gst_element_post_message (GST_ELEMENT_CAST (sink), msg);
277 /* at this point we expect gst_wayland_sink_set_context
278 * to get called and fill sink->display */
279 g_mutex_lock (&sink->display_lock);
281 if (!sink->display) {
282 /* if the application didn't set a display, let's create it ourselves */
283 GST_OBJECT_LOCK (sink);
284 sink->display = gst_wl_display_new (sink->display_name, &error);
285 GST_OBJECT_UNLOCK (sink);
288 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
289 ("Could not initialise Wayland output"),
290 ("Failed to create GstWlDisplay: '%s'", error->message));
291 g_error_free (error);
298 g_mutex_unlock (&sink->display_lock);
303 static GstStateChangeReturn
304 gst_wayland_sink_change_state (GstElement * element, GstStateChange transition)
306 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
307 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
309 switch (transition) {
310 case GST_STATE_CHANGE_NULL_TO_READY:
311 if (!gst_wayland_sink_find_display (sink))
312 return GST_STATE_CHANGE_FAILURE;
318 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
319 if (ret == GST_STATE_CHANGE_FAILURE)
322 switch (transition) {
323 case GST_STATE_CHANGE_PAUSED_TO_READY:
324 gst_buffer_replace (&sink->last_buffer, NULL);
326 if (gst_wl_window_is_toplevel (sink->window)) {
327 g_clear_object (&sink->window);
329 /* remove buffer from surface, show nothing */
330 gst_wl_window_render (sink->window, NULL, NULL);
334 case GST_STATE_CHANGE_READY_TO_NULL:
335 g_mutex_lock (&sink->display_lock);
336 /* If we had a toplevel window, we most likely have our own connection
337 * to the display too, and it is a good idea to disconnect and allow
338 * potentially the application to embed us with GstVideoOverlay
339 * (which requires to re-use the same display connection as the parent
340 * surface). If we didn't have a toplevel window, then the display
341 * connection that we have is definitely shared with the application
342 * and it's better to keep it around (together with the window handle)
343 * to avoid requesting them again from the application if/when we are
344 * restarted (GstVideoOverlay behaves like that in other sinks)
346 if (sink->display && !sink->window) { /* -> the window was toplevel */
347 g_clear_object (&sink->display);
349 g_mutex_unlock (&sink->display_lock);
350 g_clear_object (&sink->pool);
360 gst_wayland_sink_set_context (GstElement * element, GstContext * context)
362 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
364 if (gst_context_has_context_type (context,
365 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE)) {
366 g_mutex_lock (&sink->display_lock);
367 if (G_LIKELY (!sink->display))
368 gst_wayland_sink_set_display_from_context (sink, context);
370 GST_WARNING_OBJECT (element, "changing display handle is not supported");
371 g_mutex_unlock (&sink->display_lock);
374 if (GST_ELEMENT_CLASS (parent_class)->set_context)
375 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
379 gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
381 GstWaylandSink *sink;
384 sink = GST_WAYLAND_SINK (bsink);
386 caps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (sink));
388 g_mutex_lock (&sink->display_lock);
391 GValue list = G_VALUE_INIT;
392 GValue value = G_VALUE_INIT;
395 enum wl_shm_format fmt;
397 g_value_init (&list, GST_TYPE_LIST);
398 g_value_init (&value, G_TYPE_STRING);
400 formats = sink->display->formats;
401 for (i = 0; i < formats->len; i++) {
402 fmt = g_array_index (formats, uint32_t, i);
403 g_value_set_string (&value, gst_wl_shm_format_to_string (fmt));
404 gst_value_list_append_value (&list, &value);
407 caps = gst_caps_make_writable (caps);
408 gst_structure_set_value (gst_caps_get_structure (caps, 0), "format", &list);
410 GST_DEBUG_OBJECT (sink, "display caps: %" GST_PTR_FORMAT, caps);
413 g_mutex_unlock (&sink->display_lock);
416 GstCaps *intersection;
419 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
420 gst_caps_unref (caps);
428 gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
430 GstWaylandSink *sink;
431 GstBufferPool *newpool;
433 enum wl_shm_format format;
436 GstStructure *structure;
438 sink = GST_WAYLAND_SINK (bsink);
440 GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
442 /* extract info from caps */
443 if (!gst_video_info_from_caps (&info, caps))
446 format = gst_video_format_to_wl_shm_format (GST_VIDEO_INFO_FORMAT (&info));
447 if ((gint) format == -1)
450 /* verify we support the requested format */
451 formats = sink->display->formats;
452 for (i = 0; i < formats->len; i++) {
453 if (g_array_index (formats, uint32_t, i) == format)
457 if (i >= formats->len)
458 goto unsupported_format;
460 /* create a new pool for the new configuration */
461 newpool = gst_video_buffer_pool_new ();
465 structure = gst_buffer_pool_get_config (newpool);
466 gst_buffer_pool_config_set_params (structure, caps, info.size, 2, 0);
467 gst_buffer_pool_config_set_allocator (structure, gst_wl_shm_allocator_get (),
469 if (!gst_buffer_pool_set_config (newpool, structure))
472 /* store the video info */
473 sink->video_info = info;
474 sink->video_info_changed = TRUE;
476 gst_object_replace ((GstObject **) & sink->pool, (GstObject *) newpool);
477 gst_object_unref (newpool);
483 GST_DEBUG_OBJECT (sink,
484 "Could not locate image format from caps %" GST_PTR_FORMAT, caps);
489 GST_DEBUG_OBJECT (sink, "Format %s is not available on the display",
490 gst_wl_shm_format_to_string (format));
495 GST_DEBUG_OBJECT (sink, "Failed to create new pool");
500 GST_DEBUG_OBJECT (bsink, "failed setting config");
501 gst_object_unref (newpool);
507 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
509 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
510 GstStructure *config;
511 guint size, min_bufs, max_bufs;
513 config = gst_buffer_pool_get_config (sink->pool);
514 gst_buffer_pool_config_get_params (config, NULL, &size, &min_bufs, &max_bufs);
516 /* we do have a pool for sure (created in set_caps),
517 * so let's propose it anyway, but also propose the allocator on its own */
518 gst_query_add_allocation_pool (query, sink->pool, size, min_bufs, max_bufs);
519 gst_query_add_allocation_param (query, gst_wl_shm_allocator_get (), NULL);
521 gst_structure_free (config);
527 gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
529 GST_DEBUG_OBJECT (bsink, "preroll buffer %p", buffer);
530 return gst_wayland_sink_render (bsink, buffer);
534 frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time)
536 GstWaylandSink *sink = data;
538 GST_LOG ("frame_redraw_cb");
540 g_atomic_int_set (&sink->redraw_pending, FALSE);
541 wl_callback_destroy (callback);
544 static const struct wl_callback_listener frame_callback_listener = {
545 frame_redraw_callback
548 /* must be called with the render lock */
550 render_last_buffer (GstWaylandSink * sink)
552 GstWlBuffer *wlbuffer;
553 const GstVideoInfo *info = NULL;
554 struct wl_surface *surface;
555 struct wl_callback *callback;
557 wlbuffer = gst_buffer_get_wl_buffer (sink->last_buffer);
558 surface = gst_wl_window_get_wl_surface (sink->window);
560 g_atomic_int_set (&sink->redraw_pending, TRUE);
561 callback = wl_surface_frame (surface);
562 wl_callback_add_listener (callback, &frame_callback_listener, sink);
564 if (G_UNLIKELY (sink->video_info_changed)) {
565 info = &sink->video_info;
566 sink->video_info_changed = FALSE;
568 gst_wl_window_render (sink->window, wlbuffer, info);
572 gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
574 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
575 GstBuffer *to_render;
576 GstWlBuffer *wlbuffer;
577 GstFlowReturn ret = GST_FLOW_OK;
579 g_mutex_lock (&sink->render_lock);
581 GST_LOG_OBJECT (sink, "render buffer %p", buffer);
583 if (G_UNLIKELY (!sink->window)) {
584 /* ask for window handle. Unlock render_lock while doing that because
585 * set_window_handle & friends will lock it in this context */
586 g_mutex_unlock (&sink->render_lock);
587 gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (sink));
588 g_mutex_lock (&sink->render_lock);
591 /* if we were not provided a window, create one ourselves */
593 gst_wl_window_new_toplevel (sink->display, &sink->video_info);
597 /* drop buffers until we get a frame callback */
598 if (g_atomic_int_get (&sink->redraw_pending) == TRUE)
601 /* make sure that the application has called set_render_rectangle() */
602 if (G_UNLIKELY (sink->window->render_rectangle.w == 0))
605 wlbuffer = gst_buffer_get_wl_buffer (buffer);
607 if (G_LIKELY (wlbuffer && wlbuffer->display == sink->display)) {
608 GST_LOG_OBJECT (sink, "buffer %p has a wl_buffer from our display, "
609 "writing directly", buffer);
613 struct wl_buffer *wbuf = NULL;
615 GST_LOG_OBJECT (sink, "buffer %p does not have a wl_buffer from our "
616 "display, creating it", buffer);
618 mem = gst_buffer_peek_memory (buffer, 0);
620 if (gst_is_wl_shm_memory (mem)) {
621 wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
626 gst_buffer_add_wl_buffer (buffer, wbuf, sink->display);
630 /* we don't know how to create a wl_buffer directly from the provided
631 * memory, so we have to copy the data to a memory that we know how
634 GST_LOG_OBJECT (sink, "buffer %p cannot have a wl_buffer, "
635 "copying to wl_shm memory", buffer);
637 /* sink->pool always exists (created in set_caps), but it may not
638 * be active if upstream is not using it */
639 if (!gst_buffer_pool_is_active (sink->pool) &&
640 !gst_buffer_pool_set_active (sink->pool, TRUE))
641 goto activate_failed;
643 ret = gst_buffer_pool_acquire_buffer (sink->pool, &to_render, NULL);
644 if (ret != GST_FLOW_OK)
647 /* the first time we acquire a buffer,
648 * we need to attach a wl_buffer on it */
649 wlbuffer = gst_buffer_get_wl_buffer (buffer);
650 if (G_UNLIKELY (!wlbuffer)) {
651 mem = gst_buffer_peek_memory (to_render, 0);
652 wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
654 if (G_UNLIKELY (!wbuf))
657 gst_buffer_add_wl_buffer (buffer, wbuf, sink->display);
660 gst_buffer_map (buffer, &src, GST_MAP_READ);
661 gst_buffer_fill (to_render, 0, src.data, src.size);
662 gst_buffer_unmap (buffer, &src);
666 /* drop double rendering */
667 if (G_UNLIKELY (to_render == sink->last_buffer)) {
668 GST_LOG_OBJECT (sink, "Buffer already being rendered");
672 gst_buffer_replace (&sink->last_buffer, to_render);
673 render_last_buffer (sink);
675 if (buffer != to_render)
676 gst_buffer_unref (to_render);
681 GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
682 ("Window has no size set"),
683 ("Make sure you set the size after calling set_window_handle"));
684 ret = GST_FLOW_ERROR;
689 GST_WARNING_OBJECT (sink, "could not create buffer");
694 GST_ERROR_OBJECT (sink, "could not create wl_buffer out of wl_shm memory");
695 ret = GST_FLOW_ERROR;
700 GST_ERROR_OBJECT (sink, "failed to activate bufferpool.");
701 ret = GST_FLOW_ERROR;
706 g_mutex_unlock (&sink->render_lock);
712 gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface * iface)
714 iface->set_window_handle = gst_wayland_sink_set_window_handle;
715 iface->set_render_rectangle = gst_wayland_sink_set_render_rectangle;
716 iface->expose = gst_wayland_sink_expose;
720 gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
722 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
723 struct wl_surface *surface = (struct wl_surface *) handle;
725 g_return_if_fail (sink != NULL);
727 g_mutex_lock (&sink->render_lock);
729 GST_DEBUG_OBJECT (sink, "Setting window handle %" GST_PTR_FORMAT,
732 g_clear_object (&sink->window);
735 if (G_LIKELY (gst_wayland_sink_find_display (sink))) {
736 /* we cannot use our own display with an external window handle */
737 if (G_UNLIKELY (sink->display->own_display)) {
738 GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ_WRITE,
739 ("Application did not provide a wayland display handle"),
740 ("waylandsink cannot use an externally-supplied surface without "
741 "an externally-supplied display handle. Consider providing a "
742 "display handle from your application with GstContext"));
744 sink->window = gst_wl_window_new_in_surface (sink->display, surface);
747 GST_ERROR_OBJECT (sink, "Failed to find display handle, "
748 "ignoring window handle");
752 g_mutex_unlock (&sink->render_lock);
756 gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
757 gint x, gint y, gint w, gint h)
759 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
761 g_return_if_fail (sink != NULL);
763 g_mutex_lock (&sink->render_lock);
765 g_mutex_unlock (&sink->render_lock);
766 GST_WARNING_OBJECT (sink,
767 "set_render_rectangle called without window, ignoring");
771 GST_DEBUG_OBJECT (sink, "window geometry changed to (%d, %d) %d x %d",
773 gst_wl_window_set_render_rectangle (sink->window, x, y, w, h);
775 g_mutex_unlock (&sink->render_lock);
779 gst_wayland_sink_expose (GstVideoOverlay * overlay)
781 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
783 g_return_if_fail (sink != NULL);
785 GST_DEBUG_OBJECT (sink, "expose");
787 g_mutex_lock (&sink->render_lock);
788 if (sink->last_buffer && g_atomic_int_get (&sink->redraw_pending) == FALSE) {
789 GST_DEBUG_OBJECT (sink, "redrawing last buffer");
790 render_last_buffer (sink);
792 g_mutex_unlock (&sink->render_lock);
796 gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface * iface)
798 iface->begin_geometry_change = gst_wayland_sink_begin_geometry_change;
799 iface->end_geometry_change = gst_wayland_sink_end_geometry_change;
803 gst_wayland_sink_begin_geometry_change (GstWaylandVideo * video)
805 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
806 g_return_if_fail (sink != NULL);
808 g_mutex_lock (&sink->render_lock);
809 if (!sink->window || !sink->window->area_subsurface) {
810 g_mutex_unlock (&sink->render_lock);
811 GST_INFO_OBJECT (sink,
812 "begin_geometry_change called without window, ignoring");
816 wl_subsurface_set_sync (sink->window->area_subsurface);
817 g_mutex_unlock (&sink->render_lock);
821 gst_wayland_sink_end_geometry_change (GstWaylandVideo * video)
823 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
824 g_return_if_fail (sink != NULL);
826 g_mutex_lock (&sink->render_lock);
827 if (!sink->window || !sink->window->area_subsurface) {
828 g_mutex_unlock (&sink->render_lock);
829 GST_INFO_OBJECT (sink,
830 "end_geometry_change called without window, ignoring");
834 wl_subsurface_set_desync (sink->window->area_subsurface);
835 g_mutex_unlock (&sink->render_lock);
839 plugin_init (GstPlugin * plugin)
841 GST_DEBUG_CATEGORY_INIT (gstwayland_debug, "waylandsink", 0,
842 " wayland video sink");
844 gst_wl_shm_allocator_register ();
846 return gst_element_register (plugin, "waylandsink", GST_RANK_MARGINAL,
847 GST_TYPE_WAYLAND_SINK);
850 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
853 "Wayland Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,