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"
46 #include "waylandpool.h"
48 #include <gst/wayland/wayland.h>
49 #include <gst/video/videooverlay.h>
65 GST_DEBUG_CATEGORY (gstwayland_debug);
66 #define GST_CAT_DEFAULT gstwayland_debug
68 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
71 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
72 ("{ BGRx, BGRA, RGBx, xBGR, xRGB, RGBA, ABGR, ARGB, RGB, BGR, "
73 "RGB16, BGR16, YUY2, YVYU, UYVY, AYUV, NV12, NV21, NV16, "
74 "YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }"))
77 static void gst_wayland_sink_get_property (GObject * object,
78 guint prop_id, GValue * value, GParamSpec * pspec);
79 static void gst_wayland_sink_set_property (GObject * object,
80 guint prop_id, const GValue * value, GParamSpec * pspec);
81 static void gst_wayland_sink_finalize (GObject * object);
83 static GstStateChangeReturn gst_wayland_sink_change_state (GstElement * element,
84 GstStateChange transition);
85 static void gst_wayland_sink_set_context (GstElement * element,
86 GstContext * context);
88 static GstCaps *gst_wayland_sink_get_caps (GstBaseSink * bsink,
90 static gboolean gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
91 static gboolean gst_wayland_sink_preroll (GstBaseSink * bsink,
94 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query);
95 static gboolean gst_wayland_sink_render (GstBaseSink * bsink,
98 /* VideoOverlay interface */
99 static void gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface *
101 static void gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay,
103 static void gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
104 gint x, gint y, gint w, gint h);
105 static void gst_wayland_sink_expose (GstVideoOverlay * overlay);
107 /* WaylandVideo interface */
108 static void gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface *
110 static void gst_wayland_sink_begin_geometry_change (GstWaylandVideo * video);
111 static void gst_wayland_sink_end_geometry_change (GstWaylandVideo * video);
113 #define gst_wayland_sink_parent_class parent_class
114 G_DEFINE_TYPE_WITH_CODE (GstWaylandSink, gst_wayland_sink, GST_TYPE_VIDEO_SINK,
115 G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY,
116 gst_wayland_sink_videooverlay_init)
117 G_IMPLEMENT_INTERFACE (GST_TYPE_WAYLAND_VIDEO,
118 gst_wayland_sink_waylandvideo_init));
121 gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
123 GObjectClass *gobject_class;
124 GstElementClass *gstelement_class;
125 GstBaseSinkClass *gstbasesink_class;
127 gobject_class = (GObjectClass *) klass;
128 gstelement_class = (GstElementClass *) klass;
129 gstbasesink_class = (GstBaseSinkClass *) klass;
131 gobject_class->set_property = gst_wayland_sink_set_property;
132 gobject_class->get_property = gst_wayland_sink_get_property;
133 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wayland_sink_finalize);
135 gst_element_class_add_pad_template (gstelement_class,
136 gst_static_pad_template_get (&sink_template));
138 gst_element_class_set_static_metadata (gstelement_class,
139 "wayland video sink", "Sink/Video",
140 "Output to wayland surface",
141 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>, "
142 "George Kiagiadakis <george.kiagiadakis@collabora.com>");
144 gstelement_class->change_state =
145 GST_DEBUG_FUNCPTR (gst_wayland_sink_change_state);
146 gstelement_class->set_context =
147 GST_DEBUG_FUNCPTR (gst_wayland_sink_set_context);
149 gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_get_caps);
150 gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_set_caps);
151 gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_wayland_sink_preroll);
152 gstbasesink_class->propose_allocation =
153 GST_DEBUG_FUNCPTR (gst_wayland_sink_propose_allocation);
154 gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_wayland_sink_render);
156 g_object_class_install_property (gobject_class, PROP_DISPLAY,
157 g_param_spec_string ("display", "Wayland Display name", "Wayland "
158 "display name to connect to, if not supplied via the GstContext",
159 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
163 gst_wayland_sink_init (GstWaylandSink * sink)
165 g_mutex_init (&sink->display_lock);
166 g_mutex_init (&sink->render_lock);
170 gst_wayland_sink_get_property (GObject * object,
171 guint prop_id, GValue * value, GParamSpec * pspec)
173 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
177 GST_OBJECT_LOCK (sink);
178 g_value_set_string (value, sink->display_name);
179 GST_OBJECT_UNLOCK (sink);
182 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
188 gst_wayland_sink_set_property (GObject * object,
189 guint prop_id, const GValue * value, GParamSpec * pspec)
191 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
195 GST_OBJECT_LOCK (sink);
196 sink->display_name = g_value_dup_string (value);
197 GST_OBJECT_UNLOCK (sink);
200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
206 gst_wayland_sink_finalize (GObject * object)
208 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
210 GST_DEBUG_OBJECT (sink, "Finalizing the sink..");
212 if (sink->last_buffer)
213 gst_buffer_unref (sink->last_buffer);
215 /* see comment about this call in gst_wayland_sink_change_state() */
217 gst_wayland_compositor_release_all_buffers (GST_WAYLAND_BUFFER_POOL
220 g_object_unref (sink->display);
223 g_object_unref (sink->window);
225 gst_object_unref (sink->pool);
227 if (sink->display_name)
228 g_free (sink->display_name);
230 g_mutex_clear (&sink->display_lock);
231 g_mutex_clear (&sink->render_lock);
233 G_OBJECT_CLASS (parent_class)->finalize (object);
236 /* must be called with the display_lock */
238 gst_wayland_sink_set_display_from_context (GstWaylandSink * sink,
239 GstContext * context)
241 struct wl_display *display;
242 GError *error = NULL;
244 display = gst_wayland_display_handle_context_get_handle (context);
245 sink->display = gst_wl_display_new_existing (display, FALSE, &error);
248 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
249 ("Could not set display handle"),
250 ("Failed to use the external wayland display: '%s'", error->message));
251 g_error_free (error);
256 gst_wayland_sink_find_display (GstWaylandSink * sink)
260 GstContext *context = NULL;
261 GError *error = NULL;
264 g_mutex_lock (&sink->display_lock);
266 if (!sink->display) {
267 /* first query upstream for the needed display handle */
268 query = gst_query_new_context (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
269 if (gst_pad_peer_query (GST_VIDEO_SINK_PAD (sink), query)) {
270 gst_query_parse_context (query, &context);
271 gst_wayland_sink_set_display_from_context (sink, context);
273 gst_query_unref (query);
275 if (G_LIKELY (!sink->display)) {
276 /* now ask the application to set the display handle */
277 msg = gst_message_new_need_context (GST_OBJECT_CAST (sink),
278 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
280 g_mutex_unlock (&sink->display_lock);
281 gst_element_post_message (GST_ELEMENT_CAST (sink), msg);
282 /* at this point we expect gst_wayland_sink_set_context
283 * to get called and fill sink->display */
284 g_mutex_lock (&sink->display_lock);
286 if (!sink->display) {
287 /* if the application didn't set a display, let's create it ourselves */
288 GST_OBJECT_LOCK (sink);
289 sink->display = gst_wl_display_new (sink->display_name, &error);
290 GST_OBJECT_UNLOCK (sink);
293 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
294 ("Could not initialise Wayland output"),
295 ("Failed to create GstWlDisplay: '%s'", error->message));
296 g_error_free (error);
299 /* inform the world about the new display */
301 gst_wayland_display_handle_context_new (sink->display->display);
302 msg = gst_message_new_have_context (GST_OBJECT_CAST (sink), context);
303 gst_element_post_message (GST_ELEMENT_CAST (sink), msg);
309 g_mutex_unlock (&sink->display_lock);
314 static GstStateChangeReturn
315 gst_wayland_sink_change_state (GstElement * element, GstStateChange transition)
317 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
318 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
320 switch (transition) {
321 case GST_STATE_CHANGE_NULL_TO_READY:
322 if (!gst_wayland_sink_find_display (sink))
323 return GST_STATE_CHANGE_FAILURE;
329 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
330 if (ret == GST_STATE_CHANGE_FAILURE)
333 switch (transition) {
334 case GST_STATE_CHANGE_PAUSED_TO_READY:
335 gst_buffer_replace (&sink->last_buffer, NULL);
337 if (gst_wl_window_is_toplevel (sink->window)) {
338 g_clear_object (&sink->window);
340 /* remove buffer from surface, show nothing */
341 wl_surface_attach (sink->window->surface, NULL, 0, 0);
342 wl_surface_damage (sink->window->surface, 0, 0,
343 sink->window->surface_width, sink->window->surface_height);
344 wl_surface_commit (sink->window->surface);
345 wl_display_flush (sink->display->display);
349 case GST_STATE_CHANGE_READY_TO_NULL:
350 g_mutex_lock (&sink->display_lock);
351 /* If we had a toplevel window, we most likely have our own connection
352 * to the display too, and it is a good idea to disconnect and allow
353 * potentially the application to embed us with GstVideoOverlay
354 * (which requires to re-use the same display connection as the parent
355 * surface). If we didn't have a toplevel window, then the display
356 * connection that we have is definitely shared with the application
357 * and it's better to keep it around (together with the window handle)
358 * to avoid requesting them again from the application if/when we are
359 * restarted (GstVideoOverlay behaves like that in other sinks)
361 if (sink->display && !sink->window) { /* -> the window was toplevel */
362 /* Force all buffers to return to the pool, regardless of
363 * whether the compositor has released them or not. We are
364 * going to kill the display, so we need to return all buffers
365 * to be destroyed before this happens.
366 * Note that this is done here instead of the pool destructor
367 * because the buffers hold a reference to the pool. Also,
368 * the buffers can only be unref'ed from the display's event loop
369 * and the pool holds a reference to the display. If we drop
370 * our references here, when the compositor releases the buffers,
371 * they will be unref'ed from the event loop thread, which will
372 * unref the pool and therefore the display, which will try to
373 * stop the thread from within itself and cause a deadlock.
376 gst_wayland_compositor_release_all_buffers (GST_WAYLAND_BUFFER_POOL
379 g_clear_object (&sink->display);
380 g_clear_object (&sink->pool);
382 g_mutex_unlock (&sink->display_lock);
392 gst_wayland_sink_set_context (GstElement * element, GstContext * context)
394 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
396 if (gst_context_has_context_type (context,
397 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE)) {
398 g_mutex_lock (&sink->display_lock);
399 if (G_LIKELY (!sink->display))
400 gst_wayland_sink_set_display_from_context (sink, context);
402 GST_WARNING_OBJECT (element, "changing display handle is not supported");
403 g_mutex_unlock (&sink->display_lock);
406 if (GST_ELEMENT_CLASS (parent_class)->set_context)
407 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
411 gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
413 GstWaylandSink *sink;
416 sink = GST_WAYLAND_SINK (bsink);
418 caps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (sink));
420 g_mutex_lock (&sink->display_lock);
423 GValue list = G_VALUE_INIT;
424 GValue value = G_VALUE_INIT;
427 enum wl_shm_format fmt;
429 g_value_init (&list, GST_TYPE_LIST);
430 g_value_init (&value, G_TYPE_STRING);
432 formats = sink->display->formats;
433 for (i = 0; i < formats->len; i++) {
434 fmt = g_array_index (formats, uint32_t, i);
435 g_value_set_string (&value, gst_wayland_format_to_string (fmt));
436 gst_value_list_append_value (&list, &value);
439 caps = gst_caps_make_writable (caps);
440 gst_structure_set_value (gst_caps_get_structure (caps, 0), "format", &list);
442 GST_DEBUG_OBJECT (sink, "display caps: %" GST_PTR_FORMAT, caps);
445 g_mutex_unlock (&sink->display_lock);
448 GstCaps *intersection;
451 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
452 gst_caps_unref (caps);
460 gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
462 GstWaylandSink *sink;
463 GstBufferPool *newpool;
465 enum wl_shm_format format;
468 GstStructure *structure;
469 static GstAllocationParams params = { 0, 0, 0, 15, };
471 sink = GST_WAYLAND_SINK (bsink);
473 GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
475 /* extract info from caps */
476 if (!gst_video_info_from_caps (&info, caps))
479 format = gst_video_format_to_wayland_format (GST_VIDEO_INFO_FORMAT (&info));
480 if ((gint) format == -1)
483 /* verify we support the requested format */
484 formats = sink->display->formats;
485 for (i = 0; i < formats->len; i++) {
486 if (g_array_index (formats, uint32_t, i) == format)
490 if (i >= formats->len)
491 goto unsupported_format;
493 /* create a new pool for the new configuration */
494 newpool = gst_wayland_buffer_pool_new (sink->display);
498 structure = gst_buffer_pool_get_config (newpool);
499 gst_buffer_pool_config_set_params (structure, caps, info.size, 2, 0);
500 gst_buffer_pool_config_set_allocator (structure, NULL, ¶ms);
501 if (!gst_buffer_pool_set_config (newpool, structure))
504 /* store the video info */
505 sink->video_info = info;
506 sink->video_info_changed = TRUE;
508 gst_object_replace ((GstObject **) & sink->pool, (GstObject *) newpool);
509 gst_object_unref (newpool);
515 GST_DEBUG_OBJECT (sink,
516 "Could not locate image format from caps %" GST_PTR_FORMAT, caps);
521 GST_DEBUG_OBJECT (sink, "Format %s is not available on the display",
522 gst_wayland_format_to_string (format));
527 GST_DEBUG_OBJECT (sink, "Failed to create new pool");
532 GST_DEBUG_OBJECT (bsink, "failed setting config");
538 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
540 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
541 GstBufferPool *pool = NULL;
542 GstStructure *config;
547 gst_query_parse_allocation (query, &caps, &need_pool);
553 pool = gst_object_ref (sink->pool);
558 /* we had a pool, check caps */
559 config = gst_buffer_pool_get_config (pool);
560 gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
562 if (!gst_caps_is_equal (caps, pcaps)) {
563 /* different caps, we can't use this pool */
564 gst_object_unref (pool);
567 gst_structure_free (config);
570 if (pool == NULL && need_pool) {
573 if (!gst_video_info_from_caps (&info, caps))
576 GST_DEBUG_OBJECT (sink, "create new pool");
577 pool = gst_wayland_buffer_pool_new (sink->display);
579 /* the normal size of a frame */
582 config = gst_buffer_pool_get_config (pool);
583 gst_buffer_pool_config_set_params (config, caps, size, 2, 0);
584 if (!gst_buffer_pool_set_config (pool, config))
588 gst_query_add_allocation_pool (query, pool, size, 2, 0);
589 gst_object_unref (pool);
597 GST_DEBUG_OBJECT (bsink, "no caps specified");
602 GST_DEBUG_OBJECT (bsink, "invalid caps specified");
607 GST_DEBUG_OBJECT (bsink, "failed setting config");
608 gst_object_unref (pool);
614 gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
616 GST_DEBUG_OBJECT (bsink, "preroll buffer %p", buffer);
617 return gst_wayland_sink_render (bsink, buffer);
621 frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time)
623 GstWaylandSink *sink = data;
625 GST_LOG ("frame_redraw_cb");
627 g_atomic_int_set (&sink->redraw_pending, FALSE);
628 wl_callback_destroy (callback);
631 static const struct wl_callback_listener frame_callback_listener = {
632 frame_redraw_callback
635 /* must be called with the render lock */
637 render_last_buffer (GstWaylandSink * sink)
640 struct wl_surface *surface;
641 struct wl_callback *callback;
643 meta = gst_buffer_get_wl_meta (sink->last_buffer);
644 surface = gst_wl_window_get_wl_surface (sink->window);
646 g_atomic_int_set (&sink->redraw_pending, TRUE);
647 callback = wl_surface_frame (surface);
648 wl_callback_add_listener (callback, &frame_callback_listener, sink);
650 /* Here we essentially add a reference to the buffer. This represents
651 * the fact that the compositor is using the buffer and it should
652 * not return back to the pool and be reused until the compositor
653 * releases it. The release is handled internally in the pool */
654 gst_wayland_compositor_acquire_buffer (meta->pool, sink->last_buffer);
656 wl_surface_attach (surface, meta->wbuffer, 0, 0);
657 wl_surface_damage (surface, 0, 0, sink->window->surface_width,
658 sink->window->surface_height);
660 wl_surface_commit (surface);
661 wl_display_flush (sink->display->display);
665 gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
667 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
668 GstBuffer *to_render;
670 GstFlowReturn ret = GST_FLOW_OK;
672 g_mutex_lock (&sink->render_lock);
674 GST_LOG_OBJECT (sink, "render buffer %p", buffer);
676 if (G_UNLIKELY (!sink->window)) {
677 /* ask for window handle. Unlock render_lock while doing that because
678 * set_window_handle & friends will lock it in this context */
679 g_mutex_unlock (&sink->render_lock);
680 gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (sink));
681 g_mutex_lock (&sink->render_lock);
684 /* inform the window about our caps */
685 gst_wl_window_set_video_info (sink->window, &sink->video_info);
687 /* if we were not provided a window, create one ourselves */
689 gst_wl_window_new_toplevel (sink->display, &sink->video_info);
691 sink->video_info_changed = FALSE;
694 /* drop buffers until we get a frame callback */
695 if (g_atomic_int_get (&sink->redraw_pending) == TRUE)
698 if (G_UNLIKELY (sink->video_info_changed)) {
699 gst_wl_window_set_video_info (sink->window, &sink->video_info);
700 sink->video_info_changed = FALSE;
703 /* now that we have for sure set the video info on the window, it must have
704 * a valid size, otherwise this means that the application has called
705 * set_window_handle() without calling set_render_rectangle(), which is
706 * absolutely necessary for us.
708 if (G_UNLIKELY (sink->window->surface_width == 0 ||
709 sink->window->surface_height == 0))
712 meta = gst_buffer_get_wl_meta (buffer);
714 if (meta && meta->pool->display == sink->display) {
715 GST_LOG_OBJECT (sink, "buffer %p from our pool, writing directly", buffer);
719 GST_LOG_OBJECT (sink, "buffer %p not from our pool, copying", buffer);
724 if (!gst_buffer_pool_set_active (sink->pool, TRUE))
725 goto activate_failed;
727 ret = gst_buffer_pool_acquire_buffer (sink->pool, &to_render, NULL);
728 if (ret != GST_FLOW_OK)
731 gst_buffer_map (buffer, &src, GST_MAP_READ);
732 gst_buffer_fill (to_render, 0, src.data, src.size);
733 gst_buffer_unmap (buffer, &src);
736 gst_buffer_replace (&sink->last_buffer, to_render);
737 render_last_buffer (sink);
739 if (buffer != to_render)
740 gst_buffer_unref (to_render);
745 GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
746 ("Window has no size set"),
747 ("Make sure you set the size after calling set_window_handle"));
748 ret = GST_FLOW_ERROR;
753 GST_WARNING_OBJECT (sink, "could not create image");
758 GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
759 ("Internal error: can't allocate images"),
760 ("We don't have a bufferpool negotiated"));
761 ret = GST_FLOW_ERROR;
766 GST_ERROR_OBJECT (sink, "failed to activate bufferpool.");
767 ret = GST_FLOW_ERROR;
772 g_mutex_unlock (&sink->render_lock);
778 gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface * iface)
780 iface->set_window_handle = gst_wayland_sink_set_window_handle;
781 iface->set_render_rectangle = gst_wayland_sink_set_render_rectangle;
782 iface->expose = gst_wayland_sink_expose;
786 gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
788 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
789 struct wl_surface *surface = (struct wl_surface *) handle;
791 g_return_if_fail (sink != NULL);
793 g_mutex_lock (&sink->render_lock);
795 GST_DEBUG_OBJECT (sink, "Setting window handle %" GST_PTR_FORMAT,
798 g_clear_object (&sink->window);
801 if (G_LIKELY (gst_wayland_sink_find_display (sink))) {
802 /* we cannot use our own display with an external window handle */
803 if (G_UNLIKELY (sink->display->own_display)) {
804 GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ_WRITE,
805 ("Application did not provide a wayland display handle"),
806 ("waylandsink cannot use an externally-supplied surface without "
807 "an externally-supplied display handle. Consider providing a "
808 "display handle from your application with GstContext"));
810 sink->window = gst_wl_window_new_in_surface (sink->display, surface);
813 GST_ERROR_OBJECT (sink, "Failed to find display handle, "
814 "ignoring window handle");
818 g_mutex_unlock (&sink->render_lock);
822 gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
823 gint x, gint y, gint w, gint h)
825 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
827 g_return_if_fail (sink != NULL);
829 g_mutex_lock (&sink->render_lock);
831 g_mutex_unlock (&sink->render_lock);
832 GST_WARNING_OBJECT (sink,
833 "set_render_rectangle called without window, ignoring");
837 GST_DEBUG_OBJECT (sink, "window geometry changed to (%d, %d) %d x %d",
839 gst_wl_window_set_render_rectangle (sink->window, x, y, w, h);
841 g_mutex_unlock (&sink->render_lock);
845 gst_wayland_sink_expose (GstVideoOverlay * overlay)
847 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
849 g_return_if_fail (sink != NULL);
851 GST_DEBUG_OBJECT (sink, "expose");
853 g_mutex_lock (&sink->render_lock);
854 if (sink->last_buffer && g_atomic_int_get (&sink->redraw_pending) == FALSE) {
855 GST_DEBUG_OBJECT (sink, "redrawing last buffer");
856 render_last_buffer (sink);
858 g_mutex_unlock (&sink->render_lock);
862 gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface * iface)
864 iface->begin_geometry_change = gst_wayland_sink_begin_geometry_change;
865 iface->end_geometry_change = gst_wayland_sink_end_geometry_change;
869 gst_wayland_sink_begin_geometry_change (GstWaylandVideo * video)
871 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
872 g_return_if_fail (sink != NULL);
874 g_mutex_lock (&sink->render_lock);
875 if (!sink->window || !sink->window->subsurface) {
876 g_mutex_unlock (&sink->render_lock);
877 GST_INFO_OBJECT (sink,
878 "begin_geometry_change called without window, ignoring");
882 wl_subsurface_set_sync (sink->window->subsurface);
883 g_mutex_unlock (&sink->render_lock);
887 gst_wayland_sink_end_geometry_change (GstWaylandVideo * video)
889 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
890 g_return_if_fail (sink != NULL);
892 g_mutex_lock (&sink->render_lock);
893 if (!sink->window || !sink->window->subsurface) {
894 g_mutex_unlock (&sink->render_lock);
895 GST_INFO_OBJECT (sink,
896 "end_geometry_change called without window, ignoring");
900 wl_subsurface_set_desync (sink->window->subsurface);
901 g_mutex_unlock (&sink->render_lock);
905 plugin_init (GstPlugin * plugin)
907 GST_DEBUG_CATEGORY_INIT (gstwayland_debug, "waylandsink", 0,
908 " wayland video sink");
910 return gst_element_register (plugin, "waylandsink", GST_RANK_MARGINAL,
911 GST_TYPE_WAYLAND_SINK);
914 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
917 "Wayland Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,