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 #ifdef GST_WLSINK_ENHANCEMENT
46 #include "tizen-wlvideoformat.h"
48 #include "wlvideoformat.h"
50 #include "waylandpool.h"
52 #include <gst/wayland/wayland.h>
53 #include <gst/video/videooverlay.h>
69 GST_DEBUG_CATEGORY (gstwayland_debug);
70 #define GST_CAT_DEFAULT gstwayland_debug
72 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
75 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
76 ("{ BGRx, BGRA, RGBx, xBGR, xRGB, RGBA, ABGR, ARGB, RGB, BGR, "
77 "RGB16, BGR16, YUY2, YVYU, UYVY, AYUV, NV12, NV21, NV16, "
78 "YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }"))
81 static void gst_wayland_sink_get_property (GObject * object,
82 guint prop_id, GValue * value, GParamSpec * pspec);
83 static void gst_wayland_sink_set_property (GObject * object,
84 guint prop_id, const GValue * value, GParamSpec * pspec);
85 static void gst_wayland_sink_finalize (GObject * object);
87 static GstStateChangeReturn gst_wayland_sink_change_state (GstElement * element,
88 GstStateChange transition);
89 static void gst_wayland_sink_set_context (GstElement * element,
90 GstContext * context);
92 static GstCaps *gst_wayland_sink_get_caps (GstBaseSink * bsink,
94 static gboolean gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
95 static gboolean gst_wayland_sink_preroll (GstBaseSink * bsink,
98 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query);
99 static gboolean gst_wayland_sink_render (GstBaseSink * bsink,
102 /* VideoOverlay interface */
103 static void gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface *
105 static void gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay,
107 static void gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
108 gint x, gint y, gint w, gint h);
109 static void gst_wayland_sink_expose (GstVideoOverlay * overlay);
111 /* WaylandVideo interface */
112 static void gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface *
114 static void gst_wayland_sink_begin_geometry_change (GstWaylandVideo * video);
115 static void gst_wayland_sink_end_geometry_change (GstWaylandVideo * video);
117 #define gst_wayland_sink_parent_class parent_class
118 G_DEFINE_TYPE_WITH_CODE (GstWaylandSink, gst_wayland_sink, GST_TYPE_VIDEO_SINK,
119 G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY,
120 gst_wayland_sink_videooverlay_init)
121 G_IMPLEMENT_INTERFACE (GST_TYPE_WAYLAND_VIDEO,
122 gst_wayland_sink_waylandvideo_init));
125 gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
128 GObjectClass *gobject_class;
129 GstElementClass *gstelement_class;
130 GstBaseSinkClass *gstbasesink_class;
132 gobject_class = (GObjectClass *) klass;
133 gstelement_class = (GstElementClass *) klass;
134 gstbasesink_class = (GstBaseSinkClass *) klass;
136 gobject_class->set_property = gst_wayland_sink_set_property;
137 gobject_class->get_property = gst_wayland_sink_get_property;
138 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wayland_sink_finalize);
140 gst_element_class_add_pad_template (gstelement_class,
141 gst_static_pad_template_get (&sink_template));
143 gst_element_class_set_static_metadata (gstelement_class,
144 "wayland video sink", "Sink/Video",
145 "Output to wayland surface",
146 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>, "
147 "George Kiagiadakis <george.kiagiadakis@collabora.com>");
149 gstelement_class->change_state =
150 GST_DEBUG_FUNCPTR (gst_wayland_sink_change_state);
151 gstelement_class->set_context =
152 GST_DEBUG_FUNCPTR (gst_wayland_sink_set_context);
154 gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_get_caps);
155 gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_set_caps);
156 gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_wayland_sink_preroll);
157 gstbasesink_class->propose_allocation =
158 GST_DEBUG_FUNCPTR (gst_wayland_sink_propose_allocation);
159 gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_wayland_sink_render);
161 g_object_class_install_property (gobject_class, PROP_DISPLAY,
162 g_param_spec_string ("display", "Wayland Display name", "Wayland "
163 "display name to connect to, if not supplied via the GstContext",
164 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
168 gst_wayland_sink_init (GstWaylandSink * sink)
171 g_mutex_init (&sink->display_lock);
172 g_mutex_init (&sink->render_lock);
176 gst_wayland_sink_get_property (GObject * object,
177 guint prop_id, GValue * value, GParamSpec * pspec)
181 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
184 GST_OBJECT_LOCK (sink);
185 g_value_set_string (value, sink->display_name);
186 GST_OBJECT_UNLOCK (sink);
189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
195 gst_wayland_sink_set_property (GObject * object,
196 guint prop_id, const GValue * value, GParamSpec * pspec)
200 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
203 GST_OBJECT_LOCK (sink);
204 sink->display_name = g_value_dup_string (value);
205 GST_OBJECT_UNLOCK (sink);
208 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
214 gst_wayland_sink_finalize (GObject * object)
218 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
219 GST_DEBUG_OBJECT (sink, "Finalizing the sink..");
221 if (sink->last_buffer)
222 gst_buffer_unref (sink->last_buffer);
224 /* see comment about this call in gst_wayland_sink_change_state() */
226 gst_wayland_compositor_release_all_buffers (GST_WAYLAND_BUFFER_POOL
229 g_object_unref (sink->display);
232 g_object_unref (sink->window);
234 gst_object_unref (sink->pool);
236 if (sink->display_name)
237 g_free (sink->display_name);
239 g_mutex_clear (&sink->display_lock);
240 g_mutex_clear (&sink->render_lock);
242 G_OBJECT_CLASS (parent_class)->finalize (object);
245 /* must be called with the display_lock */
247 gst_wayland_sink_set_display_from_context (GstWaylandSink * sink,
248 GstContext * context)
252 struct wl_display *display;
253 GError *error = NULL;
255 display = gst_wayland_display_handle_context_get_handle (context);
256 sink->display = gst_wl_display_new_existing (display, FALSE, &error);
259 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
260 ("Could not set display handle"),
261 ("Failed to use the external wayland display: '%s'", error->message));
262 g_error_free (error);
267 gst_wayland_sink_find_display (GstWaylandSink * sink)
273 GstContext *context = NULL;
274 GError *error = NULL;
277 g_mutex_lock (&sink->display_lock);
279 if (!sink->display) {
280 /* first query upstream for the needed display handle */
281 query = gst_query_new_context (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
282 if (gst_pad_peer_query (GST_VIDEO_SINK_PAD (sink), query)) {
283 gst_query_parse_context (query, &context);
284 gst_wayland_sink_set_display_from_context (sink, context);
286 gst_query_unref (query);
288 if (G_LIKELY (!sink->display)) {
289 /* now ask the application to set the display handle */
290 msg = gst_message_new_need_context (GST_OBJECT_CAST (sink),
291 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
293 g_mutex_unlock (&sink->display_lock);
294 gst_element_post_message (GST_ELEMENT_CAST (sink), msg);
295 /* at this point we expect gst_wayland_sink_set_context
296 * to get called and fill sink->display */
297 g_mutex_lock (&sink->display_lock);
299 if (!sink->display) {
300 /* if the application didn't set a display, let's create it ourselves */
301 GST_OBJECT_LOCK (sink);
302 sink->display = gst_wl_display_new (sink->display_name, &error);
303 GST_OBJECT_UNLOCK (sink);
306 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
307 ("Could not initialise Wayland output"),
308 ("Failed to create GstWlDisplay: '%s'", error->message));
309 g_error_free (error);
312 /* inform the world about the new display */
314 gst_wayland_display_handle_context_new (sink->display->display);
315 msg = gst_message_new_have_context (GST_OBJECT_CAST (sink), context);
316 gst_element_post_message (GST_ELEMENT_CAST (sink), msg);
322 g_mutex_unlock (&sink->display_lock);
327 static GstStateChangeReturn
328 gst_wayland_sink_change_state (GstElement * element, GstStateChange transition)
332 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
333 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
335 switch (transition) {
336 case GST_STATE_CHANGE_NULL_TO_READY:
337 if (!gst_wayland_sink_find_display (sink))
338 return GST_STATE_CHANGE_FAILURE;
344 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
345 if (ret == GST_STATE_CHANGE_FAILURE)
348 switch (transition) {
349 case GST_STATE_CHANGE_PAUSED_TO_READY:
350 gst_buffer_replace (&sink->last_buffer, NULL);
352 if (gst_wl_window_is_toplevel (sink->window)) {
353 g_clear_object (&sink->window);
355 /* remove buffer from surface, show nothing */
356 wl_surface_attach (sink->window->surface, NULL, 0, 0);
357 wl_surface_damage (sink->window->surface, 0, 0,
358 sink->window->surface_width, sink->window->surface_height);
359 wl_surface_commit (sink->window->surface);
360 wl_display_flush (sink->display->display);
364 case GST_STATE_CHANGE_READY_TO_NULL:
365 g_mutex_lock (&sink->display_lock);
366 /* If we had a toplevel window, we most likely have our own connection
367 * to the display too, and it is a good idea to disconnect and allow
368 * potentially the application to embed us with GstVideoOverlay
369 * (which requires to re-use the same display connection as the parent
370 * surface). If we didn't have a toplevel window, then the display
371 * connection that we have is definitely shared with the application
372 * and it's better to keep it around (together with the window handle)
373 * to avoid requesting them again from the application if/when we are
374 * restarted (GstVideoOverlay behaves like that in other sinks)
376 if (sink->display && !sink->window) { /* -> the window was toplevel */
377 /* Force all buffers to return to the pool, regardless of
378 * whether the compositor has released them or not. We are
379 * going to kill the display, so we need to return all buffers
380 * to be destroyed before this happens.
381 * Note that this is done here instead of the pool destructor
382 * because the buffers hold a reference to the pool. Also,
383 * the buffers can only be unref'ed from the display's event loop
384 * and the pool holds a reference to the display. If we drop
385 * our references here, when the compositor releases the buffers,
386 * they will be unref'ed from the event loop thread, which will
387 * unref the pool and therefore the display, which will try to
388 * stop the thread from within itself and cause a deadlock.
391 gst_wayland_compositor_release_all_buffers (GST_WAYLAND_BUFFER_POOL
394 g_clear_object (&sink->display);
395 g_clear_object (&sink->pool);
397 g_mutex_unlock (&sink->display_lock);
407 gst_wayland_sink_set_context (GstElement * element, GstContext * context)
411 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
412 if (gst_context_has_context_type (context,
413 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE)) {
414 g_mutex_lock (&sink->display_lock);
415 if (G_LIKELY (!sink->display)) {
416 gst_wayland_sink_set_display_from_context (sink, context);
418 GST_WARNING_OBJECT (element, "changing display handle is not supported");
419 g_mutex_unlock (&sink->display_lock);
422 g_mutex_unlock (&sink->display_lock);
425 GST_INFO ("element %p context %p", element, context);
426 if (GST_ELEMENT_CLASS (parent_class)->set_context)
427 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
431 gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
435 GstWaylandSink *sink;
437 sink = GST_WAYLAND_SINK (bsink);
439 caps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (sink));
441 g_mutex_lock (&sink->display_lock);
444 GValue list = G_VALUE_INIT;
445 GValue value = G_VALUE_INIT;
448 #ifdef GST_WLSINK_ENHANCEMENT
449 enum tizen_buffer_pool_format fmt;
451 enum wl_shm_format fmt;
454 g_value_init (&list, GST_TYPE_LIST);
455 g_value_init (&value, G_TYPE_STRING);
457 formats = sink->display->formats;
458 for (i = 0; i < formats->len; i++) {
459 fmt = g_array_index (formats, uint32_t, i);
460 g_value_set_string (&value, gst_wayland_format_to_string (fmt));
461 gst_value_list_append_value (&list, &value);
464 caps = gst_caps_make_writable (caps);
465 gst_structure_set_value (gst_caps_get_structure (caps, 0), "format", &list);
467 GST_DEBUG_OBJECT (sink, "display caps: %" GST_PTR_FORMAT, caps);
470 g_mutex_unlock (&sink->display_lock);
473 GstCaps *intersection;
476 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
477 gst_caps_unref (caps);
485 gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
489 GstWaylandSink *sink;
490 GstBufferPool *newpool;
492 #ifdef GST_WLSINK_ENHANCEMENT
493 enum tizen_buffer_pool_format format;
495 enum wl_shm_format format;
499 GstStructure *structure;
500 static GstAllocationParams params = { 0, 0, 0, 15, };
501 sink = GST_WAYLAND_SINK (bsink);
503 GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
505 /* extract info from caps */
506 if (!gst_video_info_from_caps (&info, caps))
509 format = gst_video_format_to_wayland_format (GST_VIDEO_INFO_FORMAT (&info));
510 if ((gint) format == -1)
513 /* verify we support the requested format */
514 formats = sink->display->formats;
515 for (i = 0; i < formats->len; i++) {
516 if (g_array_index (formats, uint32_t, i) == format)
520 if (i >= formats->len)
521 goto unsupported_format;
523 /* create a new pool for the new configuration */
524 newpool = gst_wayland_buffer_pool_new (sink->display);
528 structure = gst_buffer_pool_get_config (newpool);
529 gst_buffer_pool_config_set_params (structure, caps, info.size, 2, 0);
530 gst_buffer_pool_config_set_allocator (structure, NULL, ¶ms);
531 if (!gst_buffer_pool_set_config (newpool, structure))
534 /* store the video info */
535 sink->video_info = info;
536 sink->video_info_changed = TRUE;
538 gst_object_replace ((GstObject **) & sink->pool, (GstObject *) newpool);
539 gst_object_unref (newpool);
545 GST_DEBUG_OBJECT (sink,
546 "Could not locate image format from caps %" GST_PTR_FORMAT, caps);
551 GST_DEBUG_OBJECT (sink, "Format %s is not available on the display",
552 gst_wayland_format_to_string (format));
557 GST_DEBUG_OBJECT (sink, "Failed to create new pool");
562 GST_DEBUG_OBJECT (bsink, "failed setting config");
563 gst_object_unref (newpool);
569 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
573 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
574 GstBufferPool *pool = NULL;
575 GstStructure *config;
580 gst_query_parse_allocation (query, &caps, &need_pool);
586 pool = gst_object_ref (sink->pool);
591 /* we had a pool, check caps */
592 config = gst_buffer_pool_get_config (pool);
593 gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
595 if (!gst_caps_is_equal (caps, pcaps)) {
596 /* different caps, we can't use this pool */
597 gst_object_unref (pool);
600 gst_structure_free (config);
603 if (pool == NULL && need_pool) {
606 if (!gst_video_info_from_caps (&info, caps))
609 GST_DEBUG_OBJECT (sink, "create new pool");
610 pool = gst_wayland_buffer_pool_new (sink->display);
612 /* the normal size of a frame */
615 config = gst_buffer_pool_get_config (pool);
616 gst_buffer_pool_config_set_params (config, caps, size, 2, 0);
617 if (!gst_buffer_pool_set_config (pool, config))
621 gst_query_add_allocation_pool (query, pool, size, 2, 0);
622 gst_object_unref (pool);
630 GST_DEBUG_OBJECT (bsink, "no caps specified");
635 GST_DEBUG_OBJECT (bsink, "invalid caps specified");
640 GST_DEBUG_OBJECT (bsink, "failed setting config");
641 gst_object_unref (pool);
647 gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
651 GST_DEBUG_OBJECT (bsink, "preroll buffer %p", buffer);
652 return gst_wayland_sink_render (bsink, buffer);
656 frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time)
660 GstWaylandSink *sink = data;
662 GST_LOG ("frame_redraw_cb");
664 g_atomic_int_set (&sink->redraw_pending, FALSE);
665 wl_callback_destroy (callback);
668 static const struct wl_callback_listener frame_callback_listener = {
669 frame_redraw_callback
672 /* must be called with the render lock */
674 render_last_buffer (GstWaylandSink * sink)
679 struct wl_surface *surface;
680 struct wl_callback *callback;
682 meta = gst_buffer_get_wl_meta (sink->last_buffer);
683 surface = gst_wl_window_get_wl_surface (sink->window);
685 g_atomic_int_set (&sink->redraw_pending, TRUE);
686 callback = wl_surface_frame (surface);
687 wl_callback_add_listener (callback, &frame_callback_listener, sink);
689 /* Here we essentially add a reference to the buffer. This represents
690 * the fact that the compositor is using the buffer and it should
691 * not return back to the pool and be reused until the compositor
692 * releases it. The release is handled internally in the pool */
693 gst_wayland_compositor_acquire_buffer (meta->pool, sink->last_buffer);
695 wl_surface_attach (surface, meta->wbuffer, 0, 0);
696 wl_surface_damage (surface, 0, 0, sink->window->surface_width,
697 sink->window->surface_height);
699 wl_surface_commit (surface);
700 wl_display_flush (sink->display->display);
704 gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
708 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
709 GstBuffer *to_render;
711 GstFlowReturn ret = GST_FLOW_OK;
713 g_mutex_lock (&sink->render_lock);
715 GST_LOG_OBJECT (sink, "render buffer %p", buffer);
717 if (G_UNLIKELY (!sink->window)) {
718 /* ask for window handle. Unlock render_lock while doing that because
719 * set_window_handle & friends will lock it in this context */
720 g_mutex_unlock (&sink->render_lock);
721 gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (sink));
722 g_mutex_lock (&sink->render_lock);
725 /* inform the window about our caps */
726 gst_wl_window_set_video_info (sink->window, &sink->video_info);
728 /* if we were not provided a window, create one ourselves */
730 gst_wl_window_new_toplevel (sink->display, &sink->video_info);
732 sink->video_info_changed = FALSE;
735 /* drop buffers until we get a frame callback */
736 if (g_atomic_int_get (&sink->redraw_pending) == TRUE)
739 if (G_UNLIKELY (sink->video_info_changed)) {
740 gst_wl_window_set_video_info (sink->window, &sink->video_info);
741 sink->video_info_changed = FALSE;
744 GST_INFO ("window->render_rectangle(%d,%d %d x %d)",
745 sink->window->render_rectangle.x,
746 sink->window->render_rectangle.y,
747 sink->window->render_rectangle.w, sink->window->render_rectangle.h);
748 GST_INFO ("window->surface_width(%d),window->surface_height(%d)",
749 sink->window->surface_width, sink->window->surface_height);
751 /* now that we have for sure set the video info on the window, it must have
752 * a valid size, otherwise this means that the application has called
753 * set_window_handle() without calling set_render_rectangle(), which is
754 * absolutely necessary for us.
756 if (G_UNLIKELY (sink->window->surface_width == 0 ||
757 sink->window->surface_height == 0))
760 meta = gst_buffer_get_wl_meta (buffer);
762 if (meta && meta->pool->display == sink->display) {
763 GST_LOG_OBJECT (sink, "buffer %p from our pool, writing directly", buffer);
767 GST_LOG_OBJECT (sink, "buffer %p not from our pool, copying", buffer);
772 if (!gst_buffer_pool_set_active (sink->pool, TRUE))
773 goto activate_failed;
775 ret = gst_buffer_pool_acquire_buffer (sink->pool, &to_render, NULL);
776 if (ret != GST_FLOW_OK)
779 gst_buffer_map (buffer, &src, GST_MAP_READ);
780 gst_buffer_fill (to_render, 0, src.data, src.size);
781 gst_buffer_unmap (buffer, &src);
784 gst_buffer_replace (&sink->last_buffer, to_render);
785 render_last_buffer (sink);
787 if (buffer != to_render)
788 gst_buffer_unref (to_render);
793 GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
794 ("Window has no size set"),
795 ("Make sure you set the size after calling set_window_handle"));
796 ret = GST_FLOW_ERROR;
801 GST_WARNING_OBJECT (sink, "could not create image");
806 GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
807 ("Internal error: can't allocate images"),
808 ("We don't have a bufferpool negotiated"));
809 ret = GST_FLOW_ERROR;
814 GST_ERROR_OBJECT (sink, "failed to activate bufferpool.");
815 ret = GST_FLOW_ERROR;
820 g_mutex_unlock (&sink->render_lock);
826 gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface * iface)
830 iface->set_window_handle = gst_wayland_sink_set_window_handle;
831 iface->set_render_rectangle = gst_wayland_sink_set_render_rectangle;
832 iface->expose = gst_wayland_sink_expose;
836 gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
840 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
841 struct wl_surface *surface = (struct wl_surface *) handle;
843 g_return_if_fail (sink != NULL);
845 if (sink->window != NULL) {
846 GST_WARNING_OBJECT (sink, "changing window handle is not supported");
850 g_mutex_lock (&sink->render_lock);
852 GST_DEBUG_OBJECT (sink, "Setting window handle %" GST_PTR_FORMAT,
855 g_clear_object (&sink->window);
858 if (G_LIKELY (gst_wayland_sink_find_display (sink))) {
859 /* we cannot use our own display with an external window handle */
860 if (G_UNLIKELY (sink->display->own_display)) {
861 GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ_WRITE,
862 ("Application did not provide a wayland display handle"),
863 ("waylandsink cannot use an externally-supplied surface without "
864 "an externally-supplied display handle. Consider providing a "
865 "display handle from your application with GstContext"));
867 sink->window = gst_wl_window_new_in_surface (sink->display, surface);
868 GST_ERROR ("sink->window %p", sink->window);
871 GST_ERROR_OBJECT (sink, "Failed to find display handle, "
872 "ignoring window handle");
876 g_mutex_unlock (&sink->render_lock);
880 gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
881 gint x, gint y, gint w, gint h)
885 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
887 g_return_if_fail (sink != NULL);
889 g_mutex_lock (&sink->render_lock);
891 g_mutex_unlock (&sink->render_lock);
892 GST_WARNING_OBJECT (sink,
893 "set_render_rectangle called without window, ignoring");
897 GST_DEBUG_OBJECT (sink, "window geometry changed to (%d, %d) %d x %d",
899 gst_wl_window_set_render_rectangle (sink->window, x, y, w, h);
901 g_mutex_unlock (&sink->render_lock);
905 gst_wayland_sink_expose (GstVideoOverlay * overlay)
909 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
911 g_return_if_fail (sink != NULL);
913 GST_DEBUG_OBJECT (sink, "expose");
915 g_mutex_lock (&sink->render_lock);
916 if (sink->last_buffer && g_atomic_int_get (&sink->redraw_pending) == FALSE) {
917 GST_DEBUG_OBJECT (sink, "redrawing last buffer");
918 render_last_buffer (sink);
920 g_mutex_unlock (&sink->render_lock);
924 gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface * iface)
928 iface->begin_geometry_change = gst_wayland_sink_begin_geometry_change;
929 iface->end_geometry_change = gst_wayland_sink_end_geometry_change;
933 gst_wayland_sink_begin_geometry_change (GstWaylandVideo * video)
937 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
938 g_return_if_fail (sink != NULL);
940 g_mutex_lock (&sink->render_lock);
941 if (!sink->window || !sink->window->subsurface) {
942 g_mutex_unlock (&sink->render_lock);
943 GST_INFO_OBJECT (sink,
944 "begin_geometry_change called without window, ignoring");
948 wl_subsurface_set_sync (sink->window->subsurface);
949 g_mutex_unlock (&sink->render_lock);
953 gst_wayland_sink_end_geometry_change (GstWaylandVideo * video)
957 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
958 g_return_if_fail (sink != NULL);
960 g_mutex_lock (&sink->render_lock);
961 if (!sink->window || !sink->window->subsurface) {
962 g_mutex_unlock (&sink->render_lock);
963 GST_INFO_OBJECT (sink,
964 "end_geometry_change called without window, ignoring");
968 wl_subsurface_set_desync (sink->window->subsurface);
969 g_mutex_unlock (&sink->render_lock);
973 plugin_init (GstPlugin * plugin)
977 GST_DEBUG_CATEGORY_INIT (gstwayland_debug, "waylandsink", 0,
978 " wayland video sink");
980 return gst_element_register (plugin, "waylandsink", GST_RANK_MARGINAL,
981 GST_TYPE_WAYLAND_SINK);
984 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
987 "Wayland Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,