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_expose (GstVideoOverlay * overlay);
105 /* WaylandVideo interface */
106 static void gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface *
108 static void gst_wayland_sink_set_surface_size (GstWaylandVideo * video,
110 static void gst_wayland_sink_pause_rendering (GstWaylandVideo * video);
111 static void gst_wayland_sink_resume_rendering (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_cond_init (&sink->render_cond);
169 gst_wayland_sink_get_property (GObject * object,
170 guint prop_id, GValue * value, GParamSpec * pspec)
172 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
176 g_value_set_string (value, sink->display_name);
179 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
185 gst_wayland_sink_set_property (GObject * object,
186 guint prop_id, const GValue * value, GParamSpec * pspec)
188 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
192 sink->display_name = g_value_dup_string (value);
195 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
201 gst_wayland_sink_finalize (GObject * object)
203 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
205 GST_DEBUG_OBJECT (sink, "Finalizing the sink..");
207 if (sink->last_buffer)
208 gst_buffer_unref (sink->last_buffer);
210 /* see comment about this call in gst_wayland_sink_change_state() */
212 gst_wayland_compositor_release_all_buffers (GST_WAYLAND_BUFFER_POOL
215 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_cond_clear (&sink->render_cond);
227 G_OBJECT_CLASS (parent_class)->finalize (object);
231 gst_wayland_sink_find_display (GstWaylandSink * sink)
235 GstContext *context = NULL;
236 GError *error = NULL;
239 if (!sink->display) {
240 /* first query upstream for the needed display handle */
241 query = gst_query_new_context (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
242 if (gst_pad_peer_query (GST_VIDEO_SINK_PAD (sink), query)) {
243 gst_query_parse_context (query, &context);
244 gst_wayland_sink_set_context (GST_ELEMENT (sink), context);
246 gst_query_unref (query);
248 if (G_LIKELY (!sink->display)) {
249 /* now ask the application to set the display handle */
250 msg = gst_message_new_need_context (GST_OBJECT_CAST (sink),
251 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
252 gst_element_post_message (GST_ELEMENT_CAST (sink), msg);
253 /* at this point we expect gst_wayland_sink_set_context
254 * to get called and fill sink->display */
256 if (!sink->display) {
257 /* if the application didn't set a display, let's create it ourselves */
258 sink->display = gst_wl_display_new (sink->display_name, &error);
260 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
261 ("Could not initialise Wayland output"),
262 ("Failed to create GstWlDisplay: '%s'", error->message));
263 g_error_free (error);
266 /* inform the world about the new display */
268 gst_context_new (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE, FALSE);
269 gst_structure_set (gst_context_writable_structure (context),
270 "handle", G_TYPE_POINTER, sink->display->display, NULL);
271 msg = gst_message_new_have_context (GST_OBJECT_CAST (sink), context);
272 gst_element_post_message (GST_ELEMENT_CAST (sink), msg);
281 static GstStateChangeReturn
282 gst_wayland_sink_change_state (GstElement * element, GstStateChange transition)
284 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
285 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
287 switch (transition) {
288 case GST_STATE_CHANGE_NULL_TO_READY:
289 if (!gst_wayland_sink_find_display (sink))
290 return GST_STATE_CHANGE_FAILURE;
296 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
297 if (ret == GST_STATE_CHANGE_FAILURE)
300 switch (transition) {
301 case GST_STATE_CHANGE_PAUSED_TO_READY:
302 if (sink->window && gst_wl_window_is_toplevel (sink->window)) {
303 gst_buffer_replace (&sink->last_buffer, NULL);
304 g_clear_object (&sink->window);
307 case GST_STATE_CHANGE_READY_TO_NULL:
308 /* We don't need to keep the display around, unless we are embedded
309 * in another window as a subsurface, in which case we should continue
310 * to respond to expose() and therefore both the window and the display
312 if (sink->display && !sink->window) { /* -> the window was toplevel */
313 /* Force all buffers to return to the pool, regardless of
314 * whether the compositor has released them or not. We are
315 * going to kill the display, so we need to return all buffers
316 * to be destroyed before this happens.
317 * Note that this is done here instead of the pool destructor
318 * because the buffers hold a reference to the pool. Also,
319 * the buffers can only be unref'ed from the display's event loop
320 * and the pool holds a reference to the display. If we drop
321 * our references here, when the compositor releases the buffers,
322 * they will be unref'ed from the event loop thread, which will
323 * unref the pool and therefore the display, which will try to
324 * stop the thread from within itself and cause a deadlock.
327 gst_wayland_compositor_release_all_buffers (GST_WAYLAND_BUFFER_POOL
330 g_clear_object (&sink->display);
331 g_clear_object (&sink->pool);
342 gst_wayland_sink_set_context (GstElement * element, GstContext * context)
344 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
346 if (gst_context_has_context_type (context,
347 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE)) {
348 const GstStructure *s;
349 struct wl_display *display;
350 GError *error = NULL;
352 s = gst_context_get_structure (context);
353 gst_structure_get (s, "handle", G_TYPE_POINTER, &display, NULL);
354 sink->display = gst_wl_display_new_existing (display, FALSE, &error);
356 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
357 ("Could not set display handle"),
358 ("Failed to use the external wayland display: '%s'", error->message));
359 g_error_free (error);
363 if (GST_ELEMENT_CLASS (parent_class)->set_context)
364 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
368 gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
370 GstWaylandSink *sink;
373 sink = GST_WAYLAND_SINK (bsink);
375 caps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (sink));
378 GValue list = G_VALUE_INIT;
379 GValue value = G_VALUE_INIT;
382 enum wl_shm_format fmt;
384 g_value_init (&list, GST_TYPE_LIST);
385 g_value_init (&value, G_TYPE_STRING);
387 formats = sink->display->formats;
388 for (i = 0; i < formats->len; i++) {
389 fmt = g_array_index (formats, uint32_t, i);
390 g_value_set_string (&value, gst_wayland_format_to_string (fmt));
391 gst_value_list_append_value (&list, &value);
394 caps = gst_caps_make_writable (caps);
395 gst_structure_set_value (gst_caps_get_structure (caps, 0), "format", &list);
397 GST_DEBUG_OBJECT (sink, "display caps: %" GST_PTR_FORMAT, caps);
401 GstCaps *intersection;
404 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
405 gst_caps_unref (caps);
413 gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
415 GstWaylandSink *sink;
416 GstBufferPool *newpool;
418 enum wl_shm_format format;
421 GstStructure *structure;
422 static GstAllocationParams params = { 0, 0, 0, 15, };
424 sink = GST_WAYLAND_SINK (bsink);
425 GST_OBJECT_LOCK (sink);
427 GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
429 /* extract info from caps */
430 if (!gst_video_info_from_caps (&info, caps))
433 format = gst_video_format_to_wayland_format (GST_VIDEO_INFO_FORMAT (&info));
437 /* store the video size */
438 sink->video_width = info.width;
439 sink->video_height = info.height;
441 /* verify we support the requested format */
442 formats = sink->display->formats;
443 for (i = 0; i < formats->len; i++) {
444 if (g_array_index (formats, uint32_t, i) == format)
448 if (i >= formats->len)
449 goto unsupported_format;
451 /* create a new pool for the new configuration */
452 newpool = gst_wayland_buffer_pool_new (sink->display);
456 structure = gst_buffer_pool_get_config (newpool);
457 gst_buffer_pool_config_set_params (structure, caps, info.size, 2, 0);
458 gst_buffer_pool_config_set_allocator (structure, NULL, ¶ms);
459 if (!gst_buffer_pool_set_config (newpool, structure))
462 gst_object_replace ((GstObject **) & sink->pool, (GstObject *) newpool);
463 gst_object_unref (newpool);
465 GST_OBJECT_UNLOCK (sink);
470 GST_DEBUG_OBJECT (sink,
471 "Could not locate image format from caps %" GST_PTR_FORMAT, caps);
476 GST_DEBUG_OBJECT (sink, "Format %s is not available on the display",
477 gst_wayland_format_to_string (format));
482 GST_DEBUG_OBJECT (sink, "Failed to create new pool");
487 GST_DEBUG_OBJECT (bsink, "failed setting config");
492 GST_OBJECT_UNLOCK (sink);
498 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
500 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
501 GstBufferPool *pool = NULL;
502 GstStructure *config;
507 gst_query_parse_allocation (query, &caps, &need_pool);
513 pool = gst_object_ref (sink->pool);
518 /* we had a pool, check caps */
519 config = gst_buffer_pool_get_config (pool);
520 gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
522 if (!gst_caps_is_equal (caps, pcaps)) {
523 /* different caps, we can't use this pool */
524 gst_object_unref (pool);
527 gst_structure_free (config);
530 if (pool == NULL && need_pool) {
533 if (!gst_video_info_from_caps (&info, caps))
536 GST_DEBUG_OBJECT (sink, "create new pool");
537 pool = gst_wayland_buffer_pool_new (sink->display);
539 /* the normal size of a frame */
542 config = gst_buffer_pool_get_config (pool);
543 gst_buffer_pool_config_set_params (config, caps, size, 2, 0);
544 if (!gst_buffer_pool_set_config (pool, config))
548 gst_query_add_allocation_pool (query, pool, size, 2, 0);
549 gst_object_unref (pool);
557 GST_DEBUG_OBJECT (bsink, "no caps specified");
562 GST_DEBUG_OBJECT (bsink, "invalid caps specified");
567 GST_DEBUG_OBJECT (bsink, "failed setting config");
568 gst_object_unref (pool);
574 gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
576 GST_DEBUG_OBJECT (bsink, "preroll buffer %p", buffer);
577 return gst_wayland_sink_render (bsink, buffer);
581 frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time)
583 GstWaylandSink *sink = data;
585 GST_LOG ("frame_redraw_cb");
587 g_atomic_int_set (&sink->redraw_pending, FALSE);
588 wl_callback_destroy (callback);
591 static const struct wl_callback_listener frame_callback_listener = {
592 frame_redraw_callback
595 /* must be called with the object lock */
597 render_last_buffer (GstWaylandSink * sink)
600 struct wl_surface *surface;
601 struct wl_callback *callback;
602 GstVideoRectangle src, dst, res;
604 meta = gst_buffer_get_wl_meta (sink->last_buffer);
605 surface = gst_wl_window_get_wl_surface (sink->window);
607 g_atomic_int_set (&sink->redraw_pending, TRUE);
608 callback = wl_surface_frame (surface);
609 wl_callback_add_listener (callback, &frame_callback_listener, sink);
611 /* Here we essentially add a reference to the buffer. This represents
612 * the fact that the compositor is using the buffer and it should
613 * not return back to the pool and be reused until the compositor
614 * releases it. The release is handled internally in the pool */
615 gst_wayland_compositor_acquire_buffer (meta->pool, sink->last_buffer);
617 src.w = sink->video_width;
618 src.h = sink->video_height;
619 dst.w = sink->window->width;
620 dst.h = sink->window->height;
621 gst_video_sink_center_rect (src, dst, &res, FALSE);
623 wl_viewport_set_destination (sink->window->viewport, res.w, res.h);
625 wl_surface_attach (surface, meta->wbuffer, 0, 0);
626 wl_surface_damage (surface, 0, 0, res.w, res.h);
628 wl_surface_commit (surface);
629 wl_display_flush (sink->display->display);
633 gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
635 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
636 GstBuffer *to_render;
638 GstFlowReturn ret = GST_FLOW_OK;
640 /* ask for window handle. do that before locking the sink, because
641 * set_window_handle & friends will lock it in this context */
643 gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (sink));
645 GST_OBJECT_LOCK (sink);
647 GST_LOG_OBJECT (sink, "render buffer %p", buffer);
649 /* if we were not provided a window, create one ourselves */
651 sink->window = gst_wl_window_new_toplevel (sink->display, sink->video_width,
653 else if (sink->window->width == 0 || sink->window->height == 0)
656 /* surface is resizing - drop buffers until finished */
657 if (sink->drawing_frozen)
660 /* drop buffers until we get a frame callback */
661 if (g_atomic_int_get (&sink->redraw_pending) == TRUE)
664 meta = gst_buffer_get_wl_meta (buffer);
666 if (meta && meta->pool->display == sink->display) {
667 GST_LOG_OBJECT (sink, "buffer %p from our pool, writing directly", buffer);
671 GST_LOG_OBJECT (sink, "buffer %p not from our pool, copying", buffer);
676 if (!gst_buffer_pool_set_active (sink->pool, TRUE))
677 goto activate_failed;
679 ret = gst_buffer_pool_acquire_buffer (sink->pool, &to_render, NULL);
680 if (ret != GST_FLOW_OK)
683 gst_buffer_map (buffer, &src, GST_MAP_READ);
684 gst_buffer_fill (to_render, 0, src.data, src.size);
685 gst_buffer_unmap (buffer, &src);
688 gst_buffer_replace (&sink->last_buffer, to_render);
689 render_last_buffer (sink);
691 /* notify _resume_rendering() in case it's waiting */
692 sink->rendered = TRUE;
693 g_cond_broadcast (&sink->render_cond);
695 if (buffer != to_render)
696 gst_buffer_unref (to_render);
701 GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
702 ("Window has no size set"),
703 ("Make sure you set the size after calling set_window_handle"));
704 ret = GST_FLOW_ERROR;
709 GST_WARNING_OBJECT (sink, "could not create image");
714 GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
715 ("Internal error: can't allocate images"),
716 ("We don't have a bufferpool negotiated"));
717 ret = GST_FLOW_ERROR;
722 GST_ERROR_OBJECT (sink, "failed to activate bufferpool.");
723 ret = GST_FLOW_ERROR;
728 GST_OBJECT_UNLOCK (sink);
734 gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface * iface)
736 iface->set_window_handle = gst_wayland_sink_set_window_handle;
737 iface->expose = gst_wayland_sink_expose;
741 gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
743 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
744 struct wl_surface *surface = (struct wl_surface *) handle;
746 g_return_if_fail (sink != NULL);
748 GST_OBJECT_LOCK (sink);
750 GST_DEBUG_OBJECT (sink, "Setting window handle %" GST_PTR_FORMAT,
753 g_clear_object (&sink->window);
756 if (G_LIKELY (gst_wayland_sink_find_display (sink))) {
757 /* we cannot use our own display with an external window handle */
758 if (G_UNLIKELY (sink->display->own_display)) {
759 GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ_WRITE,
760 ("Application did not provide a wayland display handle"),
761 ("waylandsink cannot use an externally-supplied surface without "
762 "an externally-supplied display handle. Consider providing a "
763 "display handle from your application with GstContext"));
765 sink->window = gst_wl_window_new_from_surface (sink->display, surface);
768 GST_ERROR_OBJECT (sink, "Failed to find display handle, "
769 "ignoring window handle");
773 GST_OBJECT_UNLOCK (sink);
777 gst_wayland_sink_expose (GstVideoOverlay * overlay)
779 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
781 g_return_if_fail (sink != NULL);
783 GST_DEBUG_OBJECT (sink, "expose");
785 GST_OBJECT_LOCK (sink);
786 if (sink->last_buffer && g_atomic_int_get (&sink->redraw_pending) == FALSE) {
787 GST_DEBUG_OBJECT (sink, "redrawing last buffer");
788 render_last_buffer (sink);
790 GST_OBJECT_UNLOCK (sink);
794 gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface * iface)
796 iface->set_surface_size = gst_wayland_sink_set_surface_size;
797 iface->pause_rendering = gst_wayland_sink_pause_rendering;
798 iface->resume_rendering = gst_wayland_sink_resume_rendering;
802 gst_wayland_sink_set_surface_size (GstWaylandVideo * video, gint w, gint h)
804 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
806 g_return_if_fail (sink != NULL);
807 g_return_if_fail (sink->window != NULL);
809 GST_OBJECT_LOCK (sink);
811 GST_OBJECT_UNLOCK (sink);
812 GST_WARNING_OBJECT (sink,
813 "set_surface_size called without window, ignoring");
817 GST_DEBUG_OBJECT (sink, "changing window size to %d x %d", w, h);
818 gst_wl_window_set_size (sink->window, w, h);
819 GST_OBJECT_UNLOCK (sink);
823 gst_wayland_sink_pause_rendering (GstWaylandVideo * video)
825 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
826 g_return_if_fail (sink != NULL);
828 GST_OBJECT_LOCK (sink);
829 sink->drawing_frozen = TRUE;
830 GST_OBJECT_UNLOCK (sink);
834 gst_wayland_sink_resume_rendering (GstWaylandVideo * video)
836 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
837 g_return_if_fail (sink != NULL);
839 GST_DEBUG_OBJECT (sink, "resuming rendering");
841 GST_OBJECT_LOCK (sink);
842 sink->drawing_frozen = FALSE;
844 if (GST_STATE (sink) == GST_STATE_PLAYING) {
845 sink->rendered = FALSE;
846 while (sink->rendered == FALSE)
847 g_cond_wait (&sink->render_cond, GST_OBJECT_GET_LOCK (sink));
848 GST_DEBUG_OBJECT (sink, "synchronized with render()");
849 } else if (sink->window && sink->last_buffer &&
850 g_atomic_int_get (&sink->redraw_pending) == FALSE) {
851 render_last_buffer (sink);
852 GST_DEBUG_OBJECT (sink, "last buffer redrawn");
855 GST_OBJECT_UNLOCK (sink);
859 plugin_init (GstPlugin * plugin)
861 GST_DEBUG_CATEGORY_INIT (gstwayland_debug, "waylandsink", 0,
862 " wayland video sink");
864 return gst_element_register (plugin, "waylandsink", GST_RANK_MARGINAL,
865 GST_TYPE_WAYLAND_SINK);
868 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
871 "Wayland Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,