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
48 #include "wlvideoformat.h"
50 #include "wlshmallocator.h"
52 #include <gst/wayland/wayland.h>
53 #include <gst/video/videooverlay.h>
61 #ifdef GST_WLSINK_ENHANCEMENT
62 #define GST_TYPE_WAYLANDSINK_DISPLAY_GEOMETRY_METHOD (gst_waylandsink_display_geometry_method_get_type())
63 #define GST_TYPE_WAYLANDSINK_ROTATE_ANGLE (gst_waylandsink_rotate_angle_get_type())
64 #define GST_TYPE_WAYLANDSINK_FLIP (gst_waylandsink_flip_get_type())
67 gst_waylandsink_rotate_angle_get_type (void)
69 static GType waylandsink_rotate_angle_type = 0;
70 static const GEnumValue rotate_angle_type[] = {
71 {0, "No rotate", "DEGREE_0"},
72 {1, "Rotate 90 degree", "DEGREE_90"},
73 {2, "Rotate 180 degree", "DEGREE_180"},
74 {3, "Rotate 270 degree", "DEGREE_270"},
78 if (!waylandsink_rotate_angle_type) {
79 waylandsink_rotate_angle_type =
80 g_enum_register_static ("GstWaylandSinkRotateAngleType",
84 return waylandsink_rotate_angle_type;
89 gst_waylandsink_display_geometry_method_get_type (void)
91 static GType waylandsink_display_geometry_method_type = 0;
92 static const GEnumValue display_geometry_method_type[] = {
93 {0, "Letter box", "LETTER_BOX"},
94 {1, "Origin size", "ORIGIN_SIZE"},
95 {2, "Full-screen", "FULL_SCREEN"},
96 {3, "Cropped full-screen", "CROPPED_FULL_SCREEN"},
97 {4, "Origin size(if screen size is larger than video size(width/height)) or Letter box(if video size(width/height) is larger than screen size)", "ORIGIN_SIZE_OR_LETTER_BOX"},
101 if (!waylandsink_display_geometry_method_type) {
102 waylandsink_display_geometry_method_type =
103 g_enum_register_static ("GstWaylandSinkDisplayGeometryMethodType",
104 display_geometry_method_type);
106 return waylandsink_display_geometry_method_type;
110 gst_waylandsink_flip_get_type (void)
112 static GType waylandsink_flip_type = 0;
113 static const GEnumValue flip_type[] = {
114 {FLIP_NONE, "Flip NONE", "FLIP_NONE"},
115 {FLIP_HORIZONTAL, "Flip HORIZONTAL", "FLIP_HORIZONTAL"},
116 {FLIP_VERTICAL, "Flip VERTICAL", "FLIP_VERTICAL"},
117 {FLIP_BOTH, "Flip BOTH", "FLIP_BOTH"},
118 {FLIP_NUM, NULL, NULL},
121 if (!waylandsink_flip_type) {
122 waylandsink_flip_type =
123 g_enum_register_static ("GstWaylandSinkFlipType", flip_type);
126 return waylandsink_flip_type;
143 #ifdef GST_WLSINK_ENHANCEMENT
146 PROP_DISPLAY_GEOMETRY_METHOD,
153 GST_DEBUG_CATEGORY (gstwayland_debug);
154 #define GST_CAT_DEFAULT gstwayland_debug
156 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
159 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
160 ("{ BGRx, BGRA, RGBx, xBGR, xRGB, RGBA, ABGR, ARGB, RGB, BGR, "
161 "RGB16, BGR16, YUY2, YVYU, UYVY, AYUV, NV12, NV21, NV16, "
162 #ifdef GST_WLSINK_ENHANCEMENT
165 "YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }"))
168 static void gst_wayland_sink_get_property (GObject * object,
169 guint prop_id, GValue * value, GParamSpec * pspec);
170 static void gst_wayland_sink_set_property (GObject * object,
171 guint prop_id, const GValue * value, GParamSpec * pspec);
172 static void gst_wayland_sink_finalize (GObject * object);
174 static GstStateChangeReturn gst_wayland_sink_change_state (GstElement * element,
175 GstStateChange transition);
176 static void gst_wayland_sink_set_context (GstElement * element,
177 GstContext * context);
179 static GstCaps *gst_wayland_sink_get_caps (GstBaseSink * bsink,
181 static gboolean gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
182 static gboolean gst_wayland_sink_preroll (GstBaseSink * bsink,
185 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query);
186 static gboolean gst_wayland_sink_render (GstBaseSink * bsink,
189 /* VideoOverlay interface */
190 static void gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface *
192 static void gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay,
194 static void gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
195 gint x, gint y, gint w, gint h);
196 static void gst_wayland_sink_expose (GstVideoOverlay * overlay);
198 /* WaylandVideo interface */
199 static void gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface *
201 static void gst_wayland_sink_begin_geometry_change (GstWaylandVideo * video);
202 static void gst_wayland_sink_end_geometry_change (GstWaylandVideo * video);
203 #ifdef GST_WLSINK_ENHANCEMENT
204 static void gst_wayland_sink_update_window_geometry (GstWaylandSink * sink);
205 static void render_last_buffer (GstWaylandSink * sink);
207 #define gst_wayland_sink_parent_class parent_class
208 G_DEFINE_TYPE_WITH_CODE (GstWaylandSink, gst_wayland_sink, GST_TYPE_VIDEO_SINK,
209 G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY,
210 gst_wayland_sink_videooverlay_init)
211 G_IMPLEMENT_INTERFACE (GST_TYPE_WAYLAND_VIDEO,
212 gst_wayland_sink_waylandvideo_init));
215 gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
218 GObjectClass *gobject_class;
219 GstElementClass *gstelement_class;
220 GstBaseSinkClass *gstbasesink_class;
222 gobject_class = (GObjectClass *) klass;
223 gstelement_class = (GstElementClass *) klass;
224 gstbasesink_class = (GstBaseSinkClass *) klass;
226 gobject_class->set_property = gst_wayland_sink_set_property;
227 gobject_class->get_property = gst_wayland_sink_get_property;
228 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wayland_sink_finalize);
230 gst_element_class_add_pad_template (gstelement_class,
231 gst_static_pad_template_get (&sink_template));
233 gst_element_class_set_static_metadata (gstelement_class,
234 "wayland video sink", "Sink/Video",
235 "Output to wayland surface",
236 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>, "
237 "George Kiagiadakis <george.kiagiadakis@collabora.com>");
239 gstelement_class->change_state =
240 GST_DEBUG_FUNCPTR (gst_wayland_sink_change_state);
241 gstelement_class->set_context =
242 GST_DEBUG_FUNCPTR (gst_wayland_sink_set_context);
244 gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_get_caps);
245 gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_set_caps);
246 gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_wayland_sink_preroll);
247 gstbasesink_class->propose_allocation =
248 GST_DEBUG_FUNCPTR (gst_wayland_sink_propose_allocation);
249 gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_wayland_sink_render);
251 g_object_class_install_property (gobject_class, PROP_DISPLAY,
252 g_param_spec_string ("display", "Wayland Display name", "Wayland "
253 "display name to connect to, if not supplied via the GstContext",
254 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
255 #ifdef GST_WLSINK_ENHANCEMENT
256 g_object_class_install_property (gobject_class, PROP_USE_TBM,
257 g_param_spec_boolean ("use-tbm",
258 "Use Tizen Buffer Memory insted of Shared memory",
259 "When enabled, Memory is alloced by TBM insted of SHM ", TRUE,
260 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
262 g_object_class_install_property (gobject_class, PROP_ROTATE_ANGLE,
263 g_param_spec_enum ("rotate", "Rotate angle",
264 "Rotate angle of display output",
265 GST_TYPE_WAYLANDSINK_ROTATE_ANGLE, DEGREE_0,
266 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
268 g_object_class_install_property (gobject_class, PROP_DISPLAY_GEOMETRY_METHOD,
269 g_param_spec_enum ("display-geometry-method", "Display geometry method",
270 "Geometrical method for display",
271 GST_TYPE_WAYLANDSINK_DISPLAY_GEOMETRY_METHOD,
272 DEF_DISPLAY_GEOMETRY_METHOD,
273 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
275 g_object_class_install_property (gobject_class, PROP_ORIENTATION,
276 g_param_spec_enum ("orientation",
277 "Orientation information used for ROI/ZOOM",
278 "Orientation information for display",
279 GST_TYPE_WAYLANDSINK_ROTATE_ANGLE, DEGREE_0,
280 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
282 g_object_class_install_property (gobject_class, PROP_FLIP,
283 g_param_spec_enum ("flip", "Display flip",
285 GST_TYPE_WAYLANDSINK_FLIP, DEF_DISPLAY_FLIP,
286 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
293 __write_rawdata (const char *file, const void *data, unsigned int size)
297 fp = fopen (file, "wb");
301 fwrite ((char *) data, sizeof (char), size, fp);
308 gst_wayland_sink_init (GstWaylandSink * sink)
311 #ifdef GST_WLSINK_ENHANCEMENT
312 sink->USE_TBM = TRUE;
313 sink->display_geometry_method = DEF_DISPLAY_GEOMETRY_METHOD;
314 sink->flip = DEF_DISPLAY_FLIP;
315 sink->rotate_angle = DEGREE_0;
316 sink->orientation = DEGREE_0;
318 g_mutex_init (&sink->display_lock);
319 g_mutex_init (&sink->render_lock);
323 gst_wayland_sink_get_property (GObject * object,
324 guint prop_id, GValue * value, GParamSpec * pspec)
327 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
331 GST_OBJECT_LOCK (sink);
332 g_value_set_string (value, sink->display_name);
333 GST_OBJECT_UNLOCK (sink);
335 #ifdef GST_WLSINK_ENHANCEMENT
337 g_value_set_boolean (value, sink->USE_TBM);
339 case PROP_ROTATE_ANGLE:
340 g_value_set_enum (value, sink->rotate_angle);
342 case PROP_DISPLAY_GEOMETRY_METHOD:
343 g_value_set_enum (value, sink->display_geometry_method);
345 case PROP_ORIENTATION:
346 g_value_set_enum (value, sink->orientation);
349 g_value_set_enum (value, sink->flip);
353 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
359 gst_wayland_sink_set_property (GObject * object,
360 guint prop_id, const GValue * value, GParamSpec * pspec)
363 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
367 GST_OBJECT_LOCK (sink);
368 sink->display_name = g_value_dup_string (value);
369 GST_OBJECT_UNLOCK (sink);
371 #ifdef GST_WLSINK_ENHANCEMENT
373 sink->USE_TBM = g_value_get_boolean (value);
374 GST_LOG ("1:USE TBM 0: USE SHM set(%d)", sink->USE_TBM);
376 case PROP_ROTATE_ANGLE:
377 sink->rotate_angle = g_value_get_enum (value);
378 GST_WARNING_OBJECT (sink, "Rotate angle is set (%d)", sink->rotate_angle);
380 gst_wl_window_set_rotate_angle (sink->window, sink->rotate_angle);
382 sink->video_info_changed = TRUE;
383 if (GST_STATE (sink) == GST_STATE_PAUSED) {
384 /*need to render last buffer */
385 g_mutex_lock (&sink->render_lock);
386 render_last_buffer (sink);
387 g_mutex_unlock (&sink->render_lock);
390 case PROP_DISPLAY_GEOMETRY_METHOD:
391 sink->display_geometry_method = g_value_get_enum (value);
392 GST_WARNING_OBJECT (sink, "Display geometry method is set (%d)",
393 sink->display_geometry_method);
395 gst_wl_window_set_disp_geo_method (sink->window,
396 sink->display_geometry_method);
398 sink->video_info_changed = TRUE;
399 if (GST_STATE (sink) == GST_STATE_PAUSED) {
400 /*need to render last buffer */
401 g_mutex_lock (&sink->render_lock);
402 render_last_buffer (sink);
403 g_mutex_unlock (&sink->render_lock);
406 case PROP_ORIENTATION:
407 sink->orientation = g_value_get_enum (value);
408 GST_WARNING_OBJECT (sink, "Orientation is set (%d)", sink->orientation);
410 gst_wl_window_set_orientation (sink->window, sink->orientation);
412 sink->video_info_changed = TRUE;
413 if (GST_STATE (sink) == GST_STATE_PAUSED) {
414 /*need to render last buffer */
415 g_mutex_lock (&sink->render_lock);
416 render_last_buffer (sink);
417 g_mutex_unlock (&sink->render_lock);
421 sink->flip = g_value_get_enum (value);
422 GST_WARNING_OBJECT (sink, "flip is set (%d)", sink->flip);
424 gst_wl_window_set_flip (sink->window, sink->flip);
426 sink->video_info_changed = TRUE;
427 if (GST_STATE (sink) == GST_STATE_PAUSED) {
428 /*need to render last buffer */
429 g_mutex_lock (&sink->render_lock);
430 render_last_buffer (sink);
431 g_mutex_unlock (&sink->render_lock);
436 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
442 gst_wayland_sink_finalize (GObject * object)
445 GstWaylandSink *sink = GST_WAYLAND_SINK (object);
447 GST_DEBUG_OBJECT (sink, "Finalizing the sink..");
449 if (sink->last_buffer)
450 gst_buffer_unref (sink->last_buffer);
452 g_object_unref (sink->display);
454 g_object_unref (sink->window);
456 gst_object_unref (sink->pool);
458 if (sink->display_name)
459 g_free (sink->display_name);
461 g_mutex_clear (&sink->display_lock);
462 g_mutex_clear (&sink->render_lock);
464 G_OBJECT_CLASS (parent_class)->finalize (object);
467 /* must be called with the display_lock */
469 gst_wayland_sink_set_display_from_context (GstWaylandSink * sink,
470 GstContext * context)
473 struct wl_display *display;
474 GError *error = NULL;
476 display = gst_wayland_display_handle_context_get_handle (context);
477 sink->display = gst_wl_display_new_existing (display, FALSE, &error);
480 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
481 ("Could not set display handle"),
482 ("Failed to use the external wayland display: '%s'", error->message));
483 g_error_free (error);
485 #ifdef GST_WLSINK_ENHANCEMENT
486 sink->display->USE_TBM = sink->USE_TBM;
491 gst_wayland_sink_find_display (GstWaylandSink * sink)
496 GstContext *context = NULL;
497 GError *error = NULL;
500 g_mutex_lock (&sink->display_lock);
502 if (!sink->display) {
503 /* first query upstream for the needed display handle */
504 query = gst_query_new_context (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
505 if (gst_pad_peer_query (GST_VIDEO_SINK_PAD (sink), query)) {
506 gst_query_parse_context (query, &context);
507 gst_wayland_sink_set_display_from_context (sink, context);
509 gst_query_unref (query);
511 if (G_LIKELY (!sink->display)) {
512 /* now ask the application to set the display handle */
513 msg = gst_message_new_need_context (GST_OBJECT_CAST (sink),
514 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
516 g_mutex_unlock (&sink->display_lock);
517 gst_element_post_message (GST_ELEMENT_CAST (sink), msg);
518 /* at this point we expect gst_wayland_sink_set_context
519 * to get called and fill sink->display */
520 g_mutex_lock (&sink->display_lock);
522 if (!sink->display) {
523 /* if the application didn't set a display, let's create it ourselves */
524 GST_OBJECT_LOCK (sink);
525 sink->display = gst_wl_display_new (sink->display_name, &error);
526 GST_OBJECT_UNLOCK (sink);
529 GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
530 ("Could not initialise Wayland output"),
531 ("Failed to create GstWlDisplay: '%s'", error->message));
532 g_error_free (error);
535 #ifdef GST_WLSINK_ENHANCEMENT
536 sink->display->USE_TBM = sink->USE_TBM;
542 g_mutex_unlock (&sink->display_lock);
547 static GstStateChangeReturn
548 gst_wayland_sink_change_state (GstElement * element, GstStateChange transition)
551 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
552 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
554 switch (transition) {
555 case GST_STATE_CHANGE_NULL_TO_READY:
556 if (!gst_wayland_sink_find_display (sink))
557 return GST_STATE_CHANGE_FAILURE;
563 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
564 if (ret == GST_STATE_CHANGE_FAILURE)
567 switch (transition) {
568 case GST_STATE_CHANGE_PAUSED_TO_READY:
569 gst_buffer_replace (&sink->last_buffer, NULL);
571 if (gst_wl_window_is_toplevel (sink->window)) {
572 g_clear_object (&sink->window);
574 /* remove buffer from surface, show nothing */
575 gst_wl_window_render (sink->window, NULL, NULL);
579 case GST_STATE_CHANGE_READY_TO_NULL:
580 g_mutex_lock (&sink->display_lock);
581 /* If we had a toplevel window, we most likely have our own connection
582 * to the display too, and it is a good idea to disconnect and allow
583 * potentially the application to embed us with GstVideoOverlay
584 * (which requires to re-use the same display connection as the parent
585 * surface). If we didn't have a toplevel window, then the display
586 * connection that we have is definitely shared with the application
587 * and it's better to keep it around (together with the window handle)
588 * to avoid requesting them again from the application if/when we are
589 * restarted (GstVideoOverlay behaves like that in other sinks)
591 if (sink->display && !sink->window) { /* -> the window was toplevel */
592 g_clear_object (&sink->display);
594 g_mutex_unlock (&sink->display_lock);
595 g_clear_object (&sink->pool);
605 gst_wayland_sink_set_context (GstElement * element, GstContext * context)
608 GstWaylandSink *sink = GST_WAYLAND_SINK (element);
610 if (gst_context_has_context_type (context,
611 GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE)) {
612 g_mutex_lock (&sink->display_lock);
613 if (G_LIKELY (!sink->display))
614 gst_wayland_sink_set_display_from_context (sink, context);
616 GST_WARNING_OBJECT (element, "changing display handle is not supported");
617 #ifdef GST_WLSINK_ENHANCEMENT
618 g_mutex_unlock (&sink->display_lock);
622 g_mutex_unlock (&sink->display_lock);
625 if (GST_ELEMENT_CLASS (parent_class)->set_context)
626 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
630 gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
633 GstWaylandSink *sink;
636 sink = GST_WAYLAND_SINK (bsink);
638 caps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (sink));
640 g_mutex_lock (&sink->display_lock);
643 GValue list = G_VALUE_INIT;
644 GValue value = G_VALUE_INIT;
647 #ifdef GST_WLSINK_ENHANCEMENT
650 enum wl_shm_format fmt;
652 g_value_init (&list, GST_TYPE_LIST);
653 g_value_init (&value, G_TYPE_STRING);
654 #ifdef GST_WLSINK_ENHANCEMENT
655 if (sink->display->USE_TBM)
656 formats = sink->display->tbm_formats;
659 formats = sink->display->formats;
661 for (i = 0; i < formats->len; i++) {
662 #ifdef GST_WLSINK_ENHANCEMENT
664 tbm_fmt = g_array_index (formats, uint32_t, i);
665 g_value_set_string (&value, gst_wl_tbm_format_to_string (tbm_fmt));
666 gst_value_list_append_value (&list, &value);
667 /* TBM doesn't support SN12. So we add SN12 manually as supported format.
668 * SN12 is exactly same with NV12.
670 if (tbm_fmt == TBM_FORMAT_NV12) {
671 g_value_set_string (&value,
672 gst_video_format_to_string (GST_VIDEO_FORMAT_SN12));
673 gst_value_list_append_value (&list, &value);
675 } else { /* USE SHM */
676 fmt = g_array_index (formats, uint32_t, i);
677 g_value_set_string (&value, gst_wl_shm_format_to_string (fmt));
678 gst_value_list_append_value (&list, &value);
680 #else /* open source */
681 fmt = g_array_index (formats, uint32_t, i);
682 g_value_set_string (&value, gst_wl_shm_format_to_string (fmt));
683 gst_value_list_append_value (&list, &value);
687 caps = gst_caps_make_writable (caps);
688 gst_structure_set_value (gst_caps_get_structure (caps, 0), "format", &list);
690 GST_DEBUG_OBJECT (sink, "display caps: %" GST_PTR_FORMAT, caps);
693 g_mutex_unlock (&sink->display_lock);
696 GstCaps *intersection;
699 gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
700 gst_caps_unref (caps);
708 gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
711 GstWaylandSink *sink;
712 GstBufferPool *newpool;
714 #ifdef GST_WLSINK_ENHANCEMENT
717 enum wl_shm_format format;
721 GstStructure *structure;
723 sink = GST_WAYLAND_SINK (bsink);
725 GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
727 /* extract info from caps */
728 if (!gst_video_info_from_caps (&info, caps))
730 #ifdef GST_WLSINK_ENHANCEMENT
731 sink->caps = gst_caps_copy (caps);
734 gst_video_format_to_wl_tbm_format (GST_VIDEO_INFO_FORMAT (&info));
735 if ((gint) tbm_format == -1)
738 format = gst_video_format_to_wl_shm_format (GST_VIDEO_INFO_FORMAT (&info));
739 if ((gint) format == -1)
742 #else /* open source */
743 format = gst_video_format_to_wl_shm_format (GST_VIDEO_INFO_FORMAT (&info));
745 if ((gint) format == -1)
749 /* verify we support the requested format */
750 #ifdef GST_WLSINK_ENHANCEMENT
751 if (sink->display->USE_TBM) {
752 GST_ERROR ("USE TBM FORMAT");
753 formats = sink->display->tbm_formats;
754 for (i = 0; i < formats->len; i++) {
755 if (g_array_index (formats, uint32_t, i) == tbm_format)
758 } else { /* USE SHM */
759 GST_ERROR ("USE SHM FORMAT");
760 formats = sink->display->formats;
761 for (i = 0; i < formats->len; i++) {
762 if (g_array_index (formats, uint32_t, i) == format)
766 #else /* open source */
768 formats = sink->display->formats;
769 for (i = 0; i < formats->len; i++) {
770 if (g_array_index (formats, uint32_t, i) == format)
774 if (i >= formats->len)
775 goto unsupported_format;
777 #ifdef GST_WLSINK_ENHANCEMENT
779 if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_SN12 ||
780 GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_ST12) {
781 sink->display->is_native_format = TRUE;
783 /* store the video info */
784 sink->video_info = info;
785 sink->video_info_changed = TRUE;
787 sink->display->is_native_format = FALSE;
788 GstWlShmAllocator *self =
789 GST_WL_SHM_ALLOCATOR (gst_wl_shm_allocator_get ());
790 self->display = sink->display;
791 /* create a new pool for the new configuration */
792 newpool = gst_video_buffer_pool_new ();
796 structure = gst_buffer_pool_get_config (newpool);
797 gst_buffer_pool_config_set_params (structure, caps, info.size, 6, 0);
798 gst_buffer_pool_config_set_allocator (structure,
799 gst_wl_shm_allocator_get (), NULL);
800 if (!gst_buffer_pool_set_config (newpool, structure))
803 /* store the video info */
804 sink->video_info = info;
805 sink->video_info_changed = TRUE;
807 gst_object_replace ((GstObject **) & sink->pool, (GstObject *) newpool);
808 gst_object_unref (newpool);
810 } else { /* USE SHM */
812 GstWlShmAllocator *self =
813 GST_WL_SHM_ALLOCATOR (gst_wl_shm_allocator_get ());
814 self->display = sink->display;
816 /* create a new pool for the new configuration */
817 newpool = gst_video_buffer_pool_new ();
821 structure = gst_buffer_pool_get_config (newpool);
822 gst_buffer_pool_config_set_params (structure, caps, info.size, 6, 0);
823 gst_buffer_pool_config_set_allocator (structure,
824 gst_wl_shm_allocator_get (), NULL);
825 if (!gst_buffer_pool_set_config (newpool, structure))
828 /* store the video info */
829 sink->video_info = info;
830 sink->video_info_changed = TRUE;
832 gst_object_replace ((GstObject **) & sink->pool, (GstObject *) newpool);
833 gst_object_unref (newpool);
835 #else /*open source */
836 /* create a new pool for the new configuration */
837 newpool = gst_video_buffer_pool_new ();
841 structure = gst_buffer_pool_get_config (newpool);
842 gst_buffer_pool_config_set_params (structure, caps, info.size, 6, 0);
843 gst_buffer_pool_config_set_allocator (structure,
844 gst_wl_shm_allocator_get (), NULL);
845 if (!gst_buffer_pool_set_config (newpool, structure))
848 /* store the video info */
849 sink->video_info = info;
850 sink->video_info_changed = TRUE;
852 gst_object_replace ((GstObject **) & sink->pool, (GstObject *) newpool);
853 gst_object_unref (newpool);
860 GST_DEBUG_OBJECT (sink,
861 "Could not locate image format from caps %" GST_PTR_FORMAT, caps);
866 #ifdef GST_WLSINK_ENHANCEMENT
868 GST_DEBUG_OBJECT (sink, "Format %s is not available on the display",
869 gst_wl_tbm_format_to_string (tbm_format));
871 GST_DEBUG_OBJECT (sink, "Format %s is not available on the display",
872 gst_wl_shm_format_to_string (format));
873 #else /*open source */
874 GST_DEBUG_OBJECT (sink, "Format %s is not available on the display",
875 gst_wl_shm_format_to_string (format));
881 GST_DEBUG_OBJECT (sink, "Failed to create new pool");
886 GST_DEBUG_OBJECT (bsink, "failed setting config");
887 gst_object_unref (newpool);
893 gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
896 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
897 GstStructure *config;
898 guint size, min_bufs, max_bufs;
899 #ifdef GST_WLSINK_ENHANCEMENT
903 if (sink->display->is_native_format == TRUE)
906 gst_query_parse_allocation (query, &caps, &need_pool);
909 GST_DEBUG_OBJECT (bsink, "no caps specified");
914 config = gst_buffer_pool_get_config (sink->pool);
915 gst_buffer_pool_config_get_params (config, NULL, &size, &min_bufs, &max_bufs);
917 /* we do have a pool for sure (created in set_caps),
918 * so let's propose it anyway, but also propose the allocator on its own */
919 gst_query_add_allocation_pool (query, sink->pool, size, min_bufs, max_bufs);
920 gst_query_add_allocation_param (query, gst_wl_shm_allocator_get (), NULL);
922 gst_structure_free (config);
928 gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
931 GST_DEBUG_OBJECT (bsink, "preroll buffer %p", buffer);
932 return gst_wayland_sink_render (bsink, buffer);
936 frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time)
939 GstWaylandSink *sink = data;
941 GST_LOG ("frame_redraw_cb");
943 g_atomic_int_set (&sink->redraw_pending, FALSE);
944 wl_callback_destroy (callback);
947 static const struct wl_callback_listener frame_callback_listener = {
948 frame_redraw_callback
951 #ifdef GST_WLSINK_ENHANCEMENT
953 gst_wayland_sink_update_window_geometry (GstWaylandSink * sink)
956 g_return_if_fail (sink != NULL);
957 g_return_if_fail (sink->window != NULL);
959 gst_wl_window_set_rotate_angle (sink->window, sink->rotate_angle);
960 gst_wl_window_set_disp_geo_method (sink->window,
961 sink->display_geometry_method);
962 gst_wl_window_set_orientation (sink->window, sink->orientation);
963 gst_wl_window_set_flip (sink->window, sink->flip);
966 /* must be called with the render lock */
968 render_last_buffer (GstWaylandSink * sink)
971 GstWlBuffer *wlbuffer;
972 const GstVideoInfo *info = NULL;
973 struct wl_surface *surface;
974 struct wl_callback *callback;
976 wlbuffer = gst_buffer_get_wl_buffer (sink->last_buffer);
977 surface = gst_wl_window_get_wl_surface (sink->window);
979 g_atomic_int_set (&sink->redraw_pending, TRUE);
980 callback = wl_surface_frame (surface);
981 /* frame_callback_listener is called when wayland-client finish rendering the wl_buffer */
982 wl_callback_add_listener (callback, &frame_callback_listener, sink);
984 if (G_UNLIKELY (sink->video_info_changed)) {
985 info = &sink->video_info;
986 sink->video_info_changed = FALSE;
988 #ifdef GST_WLSINK_ENHANCEMENT
989 if (sink->last_buffer)
990 gst_wl_window_render (sink->window, wlbuffer, info);
992 if (G_UNLIKELY (info)) {
993 gst_wl_window_set_video_info (sink->window, &info);
997 gst_wl_window_render (sink->window, wlbuffer, info);
1001 static GstFlowReturn
1002 gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
1005 GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
1006 GstBuffer *to_render;
1007 GstWlBuffer *wlbuffer;
1008 GstFlowReturn ret = GST_FLOW_OK;
1010 g_mutex_lock (&sink->render_lock);
1012 GST_LOG_OBJECT (sink, "render buffer %p", buffer);
1014 if (G_UNLIKELY (!sink->window)) {
1015 /* ask for window handle. Unlock render_lock while doing that because
1016 * set_window_handle & friends will lock it in this context */
1017 g_mutex_unlock (&sink->render_lock);
1018 gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (sink));
1019 g_mutex_lock (&sink->render_lock);
1021 if (!sink->window) {
1022 /* if we were not provided a window, create one ourselves */
1024 gst_wl_window_new_toplevel (sink->display, &sink->video_info);
1027 #ifdef GST_WLSINK_ENHANCEMENT
1028 gst_wayland_sink_update_window_geometry (sink);
1029 sink->video_info_changed = TRUE;
1031 /* drop buffers until we get a frame callback */
1032 if (g_atomic_int_get (&sink->redraw_pending) == TRUE)
1034 /* make sure that the application has called set_render_rectangle() */
1035 if (G_UNLIKELY (sink->window->render_rectangle.w == 0))
1036 goto no_window_size;
1038 #ifdef GST_WLSINK_ENHANCEMENT
1040 wlbuffer = gst_buffer_get_wl_buffer (buffer);
1041 if (G_LIKELY (wlbuffer && wlbuffer->display == sink->display)) {
1042 GST_LOG_OBJECT (sink, "buffer %p has a wl_buffer from our display, " "writing directly", buffer); //buffer is from our pool and have wl_buffer
1043 GST_INFO ("wl_buffer (%p)", wlbuffer->wlbuffer);
1047 GstMapInfo mem_info = GST_MAP_INFO_INIT;
1048 int size = GST_VIDEO_INFO_SIZE (&sink->video_info);
1049 mem = gst_buffer_peek_memory (to_render, 0);
1050 gst_memory_map (mem, &mem_info, GST_MAP_READ);
1052 data = mem_info.data;
1054 char file_name[128];
1056 sprintf (file_name, "/home/owner/DUMP/_WLSINK_OUT_DUMP_%2.2d.dump",
1058 ret = __write_rawdata (file_name, data, size);
1060 GST_ERROR ("_write_rawdata() failed");
1062 GST_ERROR ("DUMP IMAGE %d, size (%d)", dump__cnt, size);
1063 gst_memory_unmap (mem, &mem_info);
1067 struct wl_buffer *wbuf = NULL;
1069 GST_LOG_OBJECT (sink, "buffer %p does not have a wl_buffer from our " "display, creating it", buffer); //buffer is from our pool but have not wl_buffer
1070 mem = gst_buffer_peek_memory (buffer, 0);
1071 if (gst_is_wl_shm_memory (mem)) {
1073 wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
1076 gst_buffer_add_wl_buffer (buffer, wbuf, sink->display); //careat GstWlBuffer and add gstbuffer, wlbuffer, display and etc
1079 } else { //buffer is not from our pool and have not wl_buffer
1081 /* we don't know how to create a wl_buffer directly from the provided
1082 * memory, so we have to copy the data to a memory that we know how
1085 GST_LOG_OBJECT (sink, "buffer %p is not from our pool", buffer);
1086 GST_LOG_OBJECT (sink, "buffer %p cannot have a wl_buffer, " "copying",
1089 if (sink->USE_TBM && sink->display->is_native_format) {
1090 /* in case of SN12 or ST12 */
1092 struct wl_buffer *wbuf = NULL;
1093 GstMapInfo mem_info = GST_MAP_INFO_INIT;
1094 MMVideoBuffer *mm_video_buf = NULL;
1096 mem = gst_buffer_peek_memory (buffer, 1);
1097 gst_memory_map (mem, &mem_info, GST_MAP_READ);
1098 mm_video_buf = (MMVideoBuffer *) mem_info.data;
1099 gst_memory_unmap (mem, &mem_info);
1101 if (mm_video_buf == NULL) {
1102 GST_WARNING_OBJECT (sink, "mm_video_buf is NULL. Skip rendering");
1105 /* assign mm_video_buf info */
1106 if (mm_video_buf->type == MM_VIDEO_BUFFER_TYPE_TBM_BO) {
1107 GST_DEBUG_OBJECT (sink, "TBM bo %p %p %p", mm_video_buf->handle.bo[0],
1108 mm_video_buf->handle.bo[1], mm_video_buf->handle.bo[2]);
1109 sink->display->native_video_size = 0;
1110 for (int i = 0; i < NV_BUF_PLANE_NUM; i++) {
1111 if (mm_video_buf->handle.bo[i] != NULL) {
1112 sink->display->bo[i] = mm_video_buf->handle.bo[i];
1114 sink->display->bo[i] = 0;
1116 sink->display->plane_size[i] = mm_video_buf->size[i];
1117 sink->display->stride_width[i] = mm_video_buf->stride_width[i];
1118 sink->display->stride_height[i] = mm_video_buf->stride_height[i];
1119 sink->display->native_video_size += sink->display->plane_size[i];
1122 GST_ERROR_OBJECT (sink, "Buffer type is not TBM");
1125 wlbuffer = gst_buffer_get_wl_buffer (buffer);
1126 if (G_UNLIKELY (!wlbuffer)) {
1128 gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
1130 if (G_UNLIKELY (!wbuf))
1133 gst_buffer_add_wl_buffer (buffer, wbuf, sink->display);
1137 else if (sink->USE_TBM && !sink->display->is_native_format) {
1139 /* sink->pool always exists (created in set_caps), but it may not
1140 * be active if upstream is not using it */
1141 if (!gst_buffer_pool_is_active (sink->pool)
1142 && !gst_buffer_pool_set_active (sink->pool, TRUE))
1143 goto activate_failed;
1145 ret = gst_buffer_pool_acquire_buffer (sink->pool, &to_render, NULL);
1146 if (ret != GST_FLOW_OK)
1150 //mem = gst_buffer_peek_memory (to_render, 0);
1151 //if (gst_is_wl_shm_memory (mem)) {
1152 GST_INFO ("to_render buffer is our buffer");
1154 /* the first time we acquire a buffer,
1155 * we need to attach a wl_buffer on it */
1156 wlbuffer = gst_buffer_get_wl_buffer (buffer);
1157 if (G_UNLIKELY (!wlbuffer)) {
1158 mem = gst_buffer_peek_memory (to_render, 0);
1159 wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
1161 if (G_UNLIKELY (!wbuf))
1164 wlbuffer = gst_buffer_add_wl_buffer (to_render, wbuf, sink->display);
1167 gst_buffer_map (buffer, &src, GST_MAP_READ);
1168 gst_buffer_fill (to_render, 0, src.data, src.size);
1169 gst_buffer_unmap (buffer, &src);
1170 } else { /* USE SHM */
1171 /* sink->pool always exists (created in set_caps), but it may not
1172 * be active if upstream is not using it */
1173 if (!gst_buffer_pool_is_active (sink->pool) &&
1174 !gst_buffer_pool_set_active (sink->pool, TRUE))
1175 goto activate_failed;
1176 ret = gst_buffer_pool_acquire_buffer (sink->pool, &to_render, NULL);
1177 if (ret != GST_FLOW_OK)
1179 /* the first time we acquire a buffer,
1180 * we need to attach a wl_buffer on it */
1181 wlbuffer = gst_buffer_get_wl_buffer (buffer);
1182 if (G_UNLIKELY (!wlbuffer)) {
1183 mem = gst_buffer_peek_memory (to_render, 0);
1184 wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
1186 if (G_UNLIKELY (!wbuf))
1189 gst_buffer_add_wl_buffer (to_render, wbuf, sink->display);
1193 gst_buffer_map (buffer, &src, GST_MAP_READ);
1194 gst_buffer_fill (to_render, 0, src.data, src.size);
1195 gst_buffer_unmap (buffer, &src);
1200 if (sink->USE_TBM && sink->display->is_native_format) {
1201 if (G_UNLIKELY (buffer == sink->last_buffer)) {
1202 GST_LOG_OBJECT (sink, "Buffer already being rendered");
1205 gst_buffer_replace (&sink->last_buffer, buffer);
1206 render_last_buffer (sink);
1209 } else { /* USE SHM or normal format */
1210 /* drop double rendering */
1211 if (G_UNLIKELY (buffer == sink->last_buffer)) {
1212 GST_LOG_OBJECT (sink, "Buffer already being rendered");
1215 gst_buffer_replace (&sink->last_buffer, to_render);
1216 render_last_buffer (sink);
1218 if (buffer != to_render)
1219 gst_buffer_unref (to_render);
1224 #else /* open source */
1226 wlbuffer = gst_buffer_get_wl_buffer (buffer);
1228 if (G_LIKELY (wlbuffer && wlbuffer->display == sink->display)) {
1229 GST_LOG_OBJECT (sink,
1230 "buffer %p has a wl_buffer from our display, " "writing directly",
1232 GST_INFO ("wl_buffer (%p)", wlbuffer->wlbuffer);
1237 struct wl_buffer *wbuf = NULL;
1239 GST_LOG_OBJECT (sink,
1240 "buffer %p does not have a wl_buffer from our " "display, creating it",
1242 mem = gst_buffer_peek_memory (buffer, 0);
1243 if (gst_is_wl_shm_memory (mem)) {
1245 wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
1249 gst_buffer_add_wl_buffer (buffer, wbuf, sink->display);
1254 /* we don't know how to create a wl_buffer directly from the provided
1255 * memory, so we have to copy the data to a memory that we know how
1258 GST_LOG_OBJECT (sink, "buffer %p is not from our pool", buffer);
1259 GST_LOG_OBJECT (sink, "buffer %p cannot have a wl_buffer, " "copying",
1261 /* sink->pool always exists (created in set_caps), but it may not
1262 * be active if upstream is not using it */
1263 if (!gst_buffer_pool_is_active (sink->pool) &&
1264 !gst_buffer_pool_set_active (sink->pool, TRUE))
1265 goto activate_failed;
1267 ret = gst_buffer_pool_acquire_buffer (sink->pool, &to_render, NULL);
1268 if (ret != GST_FLOW_OK)
1271 /* the first time we acquire a buffer,
1272 * we need to attach a wl_buffer on it */
1273 wlbuffer = gst_buffer_get_wl_buffer (buffer);
1274 if (G_UNLIKELY (!wlbuffer)) {
1275 mem = gst_buffer_peek_memory (to_render, 0);
1276 wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
1278 if (G_UNLIKELY (!wbuf))
1281 gst_buffer_add_wl_buffer (to_render, wbuf, sink->display);
1284 gst_buffer_map (buffer, &src, GST_MAP_READ);
1285 gst_buffer_fill (to_render, 0, src.data, src.size);
1286 gst_buffer_unmap (buffer, &src);
1289 /* drop double rendering */
1290 if (G_UNLIKELY (buffer == sink->last_buffer)) {
1291 GST_LOG_OBJECT (sink, "Buffer already being rendered");
1295 gst_buffer_replace (&sink->last_buffer, to_render);
1296 render_last_buffer (sink);
1298 if (buffer != to_render)
1299 gst_buffer_unref (to_render);
1303 #endif /* GST_WLSINK_ENHANCEMENT */
1307 GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
1308 ("Window has no size set"),
1309 ("Make sure you set the size after calling set_window_handle"));
1310 ret = GST_FLOW_ERROR;
1315 GST_WARNING_OBJECT (sink, "could not create buffer");
1320 GST_ERROR_OBJECT (sink, "could not create wl_buffer out of wl_shm memory");
1321 ret = GST_FLOW_ERROR;
1326 GST_ERROR_OBJECT (sink, "failed to activate bufferpool.");
1327 ret = GST_FLOW_ERROR;
1332 g_mutex_unlock (&sink->render_lock);
1338 gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface * iface)
1340 iface->set_window_handle = gst_wayland_sink_set_window_handle;
1341 iface->set_render_rectangle = gst_wayland_sink_set_render_rectangle;
1342 iface->expose = gst_wayland_sink_expose;
1346 gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
1349 #if GST_WLSINK_ENHANCEMENT /* use unique_id */
1350 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
1351 g_return_if_fail (sink != NULL);
1353 if (sink->window != NULL) {
1354 GST_WARNING_OBJECT (sink, "changing window handle is not supported");
1357 g_mutex_lock (&sink->render_lock);
1358 g_clear_object (&sink->window);
1360 GST_INFO ("parent_id %d %p", (int) handle, handle);
1363 if (G_LIKELY (gst_wayland_sink_find_display (sink))) {
1364 /* we cannot use our own display with an external window handle */
1365 if (G_UNLIKELY (sink->display->own_display)) {
1366 sink->display->parent_id = (int) handle;
1367 GST_INFO ("parent_id %d", sink->display->parent_id);
1368 //GST_DEBUG_OBJECT (sink, "Setting parent id %d", handle);
1369 sink->window = gst_wl_window_new_in_surface (sink->display, NULL);
1372 GST_ERROR_OBJECT (sink, "Failed to find display handle, "
1373 "ignoring window handle");
1376 gst_wayland_sink_update_window_geometry (sink);
1378 g_mutex_unlock (&sink->render_lock);
1382 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
1383 struct wl_surface *surface = (struct wl_surface *) handle;
1385 g_return_if_fail (sink != NULL);
1387 g_mutex_lock (&sink->render_lock);
1389 GST_DEBUG_OBJECT (sink, "Setting window handle %" GST_PTR_FORMAT,
1392 g_clear_object (&sink->window);
1395 if (G_LIKELY (gst_wayland_sink_find_display (sink))) {
1396 /* we cannot use our own display with an external window handle */
1397 if (G_UNLIKELY (sink->display->own_display)) {
1398 GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ_WRITE,
1399 ("waylandsink cannot use an externally-supplied surface without "
1400 "an externally-supplied display handle. Consider providing a "
1401 "display handle from your application with GstContext"));
1403 sink->window = gst_wl_window_new_in_surface (sink->display, surface);
1406 GST_ERROR_OBJECT (sink, "Failed to find display handle, "
1407 "ignoring window handle");
1410 g_mutex_unlock (&sink->render_lock);
1412 #endif /* use unique_id */
1416 gst_wayland_sink_set_render_rectangle (GstVideoOverlay * overlay,
1417 gint x, gint y, gint w, gint h)
1420 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
1422 g_return_if_fail (sink != NULL);
1424 g_mutex_lock (&sink->render_lock);
1425 if (!sink->window) {
1426 g_mutex_unlock (&sink->render_lock);
1427 GST_WARNING_OBJECT (sink,
1428 "set_render_rectangle called without window, ignoring");
1432 GST_DEBUG_OBJECT (sink, "window geometry changed to (%d, %d) %d x %d",
1434 gst_wl_window_set_render_rectangle (sink->window, x, y, w, h);
1436 g_mutex_unlock (&sink->render_lock);
1440 gst_wayland_sink_expose (GstVideoOverlay * overlay)
1443 GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
1445 g_return_if_fail (sink != NULL);
1447 GST_DEBUG_OBJECT (sink, "expose");
1449 g_mutex_lock (&sink->render_lock);
1450 if (sink->last_buffer && g_atomic_int_get (&sink->redraw_pending) == FALSE) {
1451 GST_DEBUG_OBJECT (sink, "redrawing last buffer");
1452 render_last_buffer (sink);
1454 g_mutex_unlock (&sink->render_lock);
1458 gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface * iface)
1460 iface->begin_geometry_change = gst_wayland_sink_begin_geometry_change;
1461 iface->end_geometry_change = gst_wayland_sink_end_geometry_change;
1465 gst_wayland_sink_begin_geometry_change (GstWaylandVideo * video)
1468 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
1469 g_return_if_fail (sink != NULL);
1471 g_mutex_lock (&sink->render_lock);
1472 if (!sink->window || !sink->window->area_subsurface) {
1473 g_mutex_unlock (&sink->render_lock);
1474 GST_INFO_OBJECT (sink,
1475 "begin_geometry_change called without window, ignoring");
1479 wl_subsurface_set_sync (sink->window->area_subsurface);
1480 g_mutex_unlock (&sink->render_lock);
1484 gst_wayland_sink_end_geometry_change (GstWaylandVideo * video)
1487 GstWaylandSink *sink = GST_WAYLAND_SINK (video);
1488 g_return_if_fail (sink != NULL);
1490 g_mutex_lock (&sink->render_lock);
1491 if (!sink->window || !sink->window->area_subsurface) {
1492 g_mutex_unlock (&sink->render_lock);
1493 GST_INFO_OBJECT (sink,
1494 "end_geometry_change called without window, ignoring");
1498 wl_subsurface_set_desync (sink->window->area_subsurface);
1499 g_mutex_unlock (&sink->render_lock);
1503 plugin_init (GstPlugin * plugin)
1505 GST_DEBUG_CATEGORY_INIT (gstwayland_debug, "waylandsink", 0,
1506 " wayland video sink");
1508 gst_wl_shm_allocator_register ();
1510 return gst_element_register (plugin, "waylandsink", GST_RANK_MARGINAL,
1511 GST_TYPE_WAYLAND_SINK);
1514 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1517 "Wayland Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,