2012-08-08 14:10:28 +00:00
|
|
|
/* GStreamer Wayland video sink
|
2011-11-02 09:02:11 +00:00
|
|
|
*
|
2012-03-07 23:48:56 +00:00
|
|
|
* Copyright (C) 2011 Intel Corporation
|
|
|
|
* Copyright (C) 2011 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
|
2012-05-23 10:07:14 +00:00
|
|
|
* Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
|
2014-03-07 14:16:30 +00:00
|
|
|
* Copyright (C) 2014 Collabora Ltd.
|
2012-05-23 10:07:14 +00:00
|
|
|
*
|
2011-11-02 09:02:11 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
2012-08-18 19:31:17 +00:00
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA.
|
2011-11-02 09:02:11 +00:00
|
|
|
*/
|
|
|
|
|
2012-03-07 23:48:56 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-waylandsink
|
|
|
|
*
|
|
|
|
* The waylandsink is creating its own window and render the decoded video frames to that.
|
|
|
|
* Setup the Wayland environment as described in
|
|
|
|
* <ulink url="http://wayland.freedesktop.org/building.html">Wayland</ulink> home page.
|
2012-05-23 10:07:14 +00:00
|
|
|
* The current implementaion is based on weston compositor.
|
2012-03-07 23:48:56 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example pipelines</title>
|
|
|
|
* |[
|
|
|
|
* gst-launch -v videotestsrc ! waylandsink
|
|
|
|
* ]| test the video rendering in wayland
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstwaylandsink.h"
|
2014-02-13 09:02:54 +00:00
|
|
|
#include "wlvideoformat.h"
|
2014-02-13 12:15:31 +00:00
|
|
|
#include "waylandpool.h"
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
#include <gst/wayland/wayland.h>
|
|
|
|
#include <gst/video/videooverlay.h>
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
/* signals */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2014-02-26 12:56:21 +00:00
|
|
|
PROP_DISPLAY
|
2011-11-02 09:02:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (gstwayland_debug);
|
|
|
|
#define GST_CAT_DEFAULT gstwayland_debug
|
|
|
|
|
2013-06-18 11:47:54 +00:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
|
|
#define CAPS "{xRGB, ARGB}"
|
|
|
|
#else
|
|
|
|
#define CAPS "{BGRx, BGRA}"
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2013-06-18 11:47:54 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (CAPS))
|
|
|
|
);
|
2012-03-07 23:48:56 +00:00
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static void gst_wayland_sink_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_wayland_sink_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_wayland_sink_finalize (GObject * object);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
|
|
|
static GstStateChangeReturn gst_wayland_sink_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
static GstCaps *gst_wayland_sink_get_caps (GstBaseSink * bsink,
|
|
|
|
GstCaps * filter);
|
2011-11-02 09:02:11 +00:00
|
|
|
static gboolean gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
|
|
|
|
static gboolean gst_wayland_sink_preroll (GstBaseSink * bsink,
|
|
|
|
GstBuffer * buffer);
|
2012-08-08 14:10:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query);
|
2011-11-02 09:02:11 +00:00
|
|
|
static gboolean gst_wayland_sink_render (GstBaseSink * bsink,
|
|
|
|
GstBuffer * buffer);
|
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
/* VideoOverlay interface */
|
|
|
|
static void gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface *
|
|
|
|
iface);
|
|
|
|
static void gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay,
|
|
|
|
guintptr handle);
|
|
|
|
static void gst_wayland_sink_expose (GstVideoOverlay * overlay);
|
|
|
|
|
|
|
|
/* WaylandVideo interface */
|
|
|
|
static void gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface *
|
|
|
|
iface);
|
|
|
|
static void gst_wayland_sink_set_surface_size (GstWaylandVideo * video,
|
|
|
|
gint w, gint h);
|
|
|
|
static void gst_wayland_sink_pause_rendering (GstWaylandVideo * video);
|
|
|
|
static void gst_wayland_sink_resume_rendering (GstWaylandVideo * video);
|
|
|
|
|
|
|
|
#define gst_wayland_sink_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstWaylandSink, gst_wayland_sink, GST_TYPE_VIDEO_SINK,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_OVERLAY,
|
|
|
|
gst_wayland_sink_videooverlay_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_WAYLAND_VIDEO,
|
|
|
|
gst_wayland_sink_waylandvideo_init));
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
static void
|
2011-11-02 11:51:13 +00:00
|
|
|
gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2012-05-23 10:07:14 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2011-11-02 09:02:11 +00:00
|
|
|
GstBaseSinkClass *gstbasesink_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2012-05-23 10:07:14 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2011-11-02 09:02:11 +00:00
|
|
|
gstbasesink_class = (GstBaseSinkClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_wayland_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_wayland_sink_get_property;
|
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wayland_sink_finalize);
|
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&sink_template));
|
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2012-05-23 10:07:14 +00:00
|
|
|
"wayland video sink", "Sink/Video",
|
|
|
|
"Output to wayland surface",
|
|
|
|
"Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
|
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_wayland_sink_change_state);
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_get_caps);
|
|
|
|
gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_set_caps);
|
|
|
|
gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_wayland_sink_preroll);
|
2012-08-08 14:10:28 +00:00
|
|
|
gstbasesink_class->propose_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_wayland_sink_propose_allocation);
|
2011-11-02 09:02:11 +00:00
|
|
|
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_wayland_sink_render);
|
|
|
|
|
2014-02-26 12:56:21 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DISPLAY,
|
|
|
|
g_param_spec_string ("display", "Wayland Display name", "Wayland "
|
|
|
|
"display name to connect to, if not supplied with GstVideoOverlay",
|
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-23 10:07:14 +00:00
|
|
|
gst_wayland_sink_init (GstWaylandSink * sink)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
2014-02-28 09:48:30 +00:00
|
|
|
g_cond_init (&sink->render_cond);
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (object);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2014-02-26 12:56:21 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_string (value, sink->display_name);
|
2011-11-02 09:02:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (object);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2014-02-26 12:56:21 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
sink->display_name = g_value_dup_string (value);
|
2011-11-02 09:02:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_finalize (GObject * object)
|
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (object);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2011-11-02 11:51:13 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "Finalizing the sink..");
|
|
|
|
|
2014-03-11 15:45:05 +00:00
|
|
|
if (sink->last_buffer)
|
|
|
|
gst_buffer_unref (sink->last_buffer);
|
2014-03-07 14:16:30 +00:00
|
|
|
if (sink->display) {
|
|
|
|
/* see comment about this call in gst_wayland_sink_change_state() */
|
2014-03-12 11:54:44 +00:00
|
|
|
if (sink->pool) {
|
|
|
|
gst_wayland_compositor_release_all_buffers (GST_WAYLAND_BUFFER_POOL
|
|
|
|
(sink->pool));
|
|
|
|
}
|
2014-03-07 14:16:30 +00:00
|
|
|
g_object_unref (sink->display);
|
|
|
|
}
|
2012-03-07 23:48:56 +00:00
|
|
|
if (sink->window)
|
2014-02-13 10:59:45 +00:00
|
|
|
g_object_unref (sink->window);
|
2014-02-26 14:20:41 +00:00
|
|
|
if (sink->pool)
|
|
|
|
gst_object_unref (sink->pool);
|
|
|
|
|
2014-02-26 12:56:21 +00:00
|
|
|
if (sink->display_name)
|
|
|
|
g_free (sink->display_name);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
g_cond_clear (&sink->render_cond);
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_wayland_sink_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (element);
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
if (!sink->window)
|
|
|
|
gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (sink));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
if (gst_wl_window_is_toplevel (sink->window)) {
|
2014-03-07 14:16:30 +00:00
|
|
|
/* Force all buffers to return to the pool, regardless of
|
|
|
|
* whether the compositor has released them or not. We are
|
|
|
|
* going to kill the display, so we need to return all buffers
|
|
|
|
* to be destroyed before this happens.
|
|
|
|
* Note that this is done here instead of the pool destructor
|
|
|
|
* because the buffers hold a reference to the pool. Also,
|
|
|
|
* the buffers can only be unref'ed from the display's event loop
|
|
|
|
* and the pool holds a reference to the display. If we drop
|
|
|
|
* our references here, when the compositor releases the buffers,
|
|
|
|
* they will be unref'ed from the event loop thread, which will
|
|
|
|
* unref the pool and therefore the display, which will try to
|
|
|
|
* stop the thread from within itself and cause a deadlock.
|
|
|
|
*/
|
2014-03-12 11:54:44 +00:00
|
|
|
if (sink->pool) {
|
|
|
|
gst_wayland_compositor_release_all_buffers (GST_WAYLAND_BUFFER_POOL
|
|
|
|
(sink->pool));
|
|
|
|
}
|
2014-03-11 15:45:05 +00:00
|
|
|
gst_buffer_replace (&sink->last_buffer, NULL);
|
2014-02-28 09:48:30 +00:00
|
|
|
g_clear_object (&sink->window);
|
|
|
|
g_clear_object (&sink->display);
|
|
|
|
g_clear_object (&sink->pool);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static GstCaps *
|
2012-05-23 10:07:14 +00:00
|
|
|
gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
2012-08-08 14:10:28 +00:00
|
|
|
GstWaylandSink *sink;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
sink = GST_WAYLAND_SINK (bsink);
|
|
|
|
|
|
|
|
caps = gst_pad_get_pad_template_caps (GST_VIDEO_SINK_PAD (sink));
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
if (filter) {
|
|
|
|
GstCaps *intersection;
|
|
|
|
|
|
|
|
intersection =
|
|
|
|
gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = intersection;
|
|
|
|
}
|
|
|
|
return caps;
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
|
|
|
{
|
2014-04-14 05:56:16 +00:00
|
|
|
GstWaylandSink *sink;
|
2014-02-14 16:20:42 +00:00
|
|
|
GstBufferPool *newpool;
|
2012-08-08 14:10:28 +00:00
|
|
|
GstVideoInfo info;
|
2014-02-28 09:48:30 +00:00
|
|
|
GError *error = NULL;
|
2014-02-26 16:35:29 +00:00
|
|
|
enum wl_shm_format format;
|
|
|
|
GArray *formats;
|
|
|
|
gint i;
|
2012-08-08 14:10:28 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
static GstAllocationParams params = { 0, 0, 0, 15, };
|
|
|
|
|
|
|
|
sink = GST_WAYLAND_SINK (bsink);
|
2014-02-28 09:48:30 +00:00
|
|
|
GST_OBJECT_LOCK (sink);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-26 16:35:29 +00:00
|
|
|
/* extract info from caps */
|
2012-08-08 14:10:28 +00:00
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_format;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-26 16:35:29 +00:00
|
|
|
format = gst_video_format_to_wayland_format (GST_VIDEO_INFO_FORMAT (&info));
|
|
|
|
if (format == -1)
|
2013-06-18 11:47:54 +00:00
|
|
|
goto invalid_format;
|
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
/* store the video size */
|
|
|
|
sink->video_width = info.width;
|
|
|
|
sink->video_height = info.height;
|
|
|
|
|
|
|
|
/* create the output window if needed */
|
2014-03-11 11:14:00 +00:00
|
|
|
if (!sink->window) {
|
2014-02-28 09:48:30 +00:00
|
|
|
if (!sink->display)
|
|
|
|
sink->display = gst_wl_display_new (sink->display_name, &error);
|
|
|
|
|
|
|
|
if (sink->display == NULL)
|
|
|
|
goto display_failed;
|
|
|
|
|
|
|
|
sink->window = gst_wl_window_new_toplevel (sink->display, sink->video_width,
|
|
|
|
sink->video_height);
|
|
|
|
}
|
|
|
|
|
2014-02-26 16:35:29 +00:00
|
|
|
/* verify we support the requested format */
|
|
|
|
formats = sink->display->formats;
|
|
|
|
for (i = 0; i < formats->len; i++) {
|
|
|
|
if (g_array_index (formats, uint32_t, i) == format)
|
|
|
|
break;
|
2013-06-18 11:47:54 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 16:35:29 +00:00
|
|
|
if (i >= formats->len)
|
|
|
|
goto unsupported_format;
|
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
/* create a new pool for the new configuration */
|
2014-02-26 14:11:29 +00:00
|
|
|
newpool = gst_wayland_buffer_pool_new (sink->display);
|
2014-02-28 09:48:30 +00:00
|
|
|
if (!newpool)
|
|
|
|
goto pool_failed;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
structure = gst_buffer_pool_get_config (newpool);
|
2014-02-26 16:35:29 +00:00
|
|
|
gst_buffer_pool_config_set_params (structure, caps, info.size, 2, 0);
|
2012-08-08 14:10:28 +00:00
|
|
|
gst_buffer_pool_config_set_allocator (structure, NULL, ¶ms);
|
|
|
|
if (!gst_buffer_pool_set_config (newpool, structure))
|
|
|
|
goto config_failed;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-14 16:20:42 +00:00
|
|
|
gst_object_replace ((GstObject **) & sink->pool, (GstObject *) newpool);
|
|
|
|
gst_object_unref (newpool);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2012-08-08 14:10:28 +00:00
|
|
|
return TRUE;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
invalid_format:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (sink,
|
|
|
|
"Could not locate image format from caps %" GST_PTR_FORMAT, caps);
|
2014-02-28 09:48:30 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
display_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ_WRITE,
|
|
|
|
("Could not initialise Wayland output"),
|
|
|
|
("Failed to create GstWlDisplay: '%s'", error->message));
|
|
|
|
g_error_free (error);
|
|
|
|
goto failure;
|
2012-08-08 14:10:28 +00:00
|
|
|
}
|
2014-02-26 16:35:29 +00:00
|
|
|
unsupported_format:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (sink, "Format %s is not available on the display",
|
|
|
|
gst_wayland_format_to_string (format));
|
2014-02-28 09:48:30 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
pool_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (sink, "Failed to create new pool");
|
|
|
|
goto failure;
|
2014-02-26 16:35:29 +00:00
|
|
|
}
|
2012-08-08 14:10:28 +00:00
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (bsink, "failed setting config");
|
2014-02-28 09:48:30 +00:00
|
|
|
goto failure;
|
2012-08-08 14:10:28 +00:00
|
|
|
}
|
2014-02-28 09:48:30 +00:00
|
|
|
failure:
|
|
|
|
{
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2012-09-13 00:07:46 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-08-08 14:10:28 +00:00
|
|
|
gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
|
2014-02-14 16:20:42 +00:00
|
|
|
GstBufferPool *pool = NULL;
|
2012-08-08 14:10:28 +00:00
|
|
|
GstStructure *config;
|
|
|
|
GstCaps *caps;
|
|
|
|
guint size;
|
|
|
|
gboolean need_pool;
|
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, &need_pool);
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
2014-02-14 16:20:42 +00:00
|
|
|
if (sink->pool)
|
|
|
|
pool = gst_object_ref (sink->pool);
|
2012-08-08 14:10:28 +00:00
|
|
|
|
|
|
|
if (pool != NULL) {
|
|
|
|
GstCaps *pcaps;
|
|
|
|
|
|
|
|
/* we had a pool, check caps */
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
|
|
|
|
|
|
|
|
if (!gst_caps_is_equal (caps, pcaps)) {
|
|
|
|
/* different caps, we can't use this pool */
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = NULL;
|
|
|
|
}
|
|
|
|
gst_structure_free (config);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool == NULL && need_pool) {
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
if (!gst_video_info_from_caps (&info, caps))
|
|
|
|
goto invalid_caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (sink, "create new pool");
|
2014-02-26 14:11:29 +00:00
|
|
|
pool = gst_wayland_buffer_pool_new (sink->display);
|
2012-08-08 14:10:28 +00:00
|
|
|
|
|
|
|
/* the normal size of a frame */
|
|
|
|
size = info.size;
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, size, 2, 0);
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config))
|
|
|
|
goto config_failed;
|
|
|
|
}
|
|
|
|
if (pool) {
|
|
|
|
gst_query_add_allocation_pool (query, pool, size, 2, 0);
|
|
|
|
gst_object_unref (pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (bsink, "no caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_caps:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (bsink, "invalid caps specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
config_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (bsink, "failed setting config");
|
|
|
|
gst_object_unref (pool);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
|
|
|
|
{
|
2012-05-23 10:07:14 +00:00
|
|
|
GST_DEBUG_OBJECT (bsink, "preroll buffer %p", buffer);
|
2011-11-02 09:02:11 +00:00
|
|
|
return gst_wayland_sink_render (bsink, buffer);
|
|
|
|
}
|
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
static void
|
|
|
|
frame_redraw_callback (void *data, struct wl_callback *callback, uint32_t time)
|
|
|
|
{
|
2014-03-07 15:25:00 +00:00
|
|
|
GstWaylandSink *sink = data;
|
|
|
|
|
2014-02-12 10:28:40 +00:00
|
|
|
GST_LOG ("frame_redraw_cb");
|
2014-03-07 15:25:00 +00:00
|
|
|
|
|
|
|
g_atomic_int_set (&sink->redraw_pending, FALSE);
|
2012-08-08 14:10:28 +00:00
|
|
|
wl_callback_destroy (callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_callback_listener = {
|
|
|
|
frame_redraw_callback
|
|
|
|
};
|
|
|
|
|
2014-03-11 15:45:05 +00:00
|
|
|
/* must be called with the object lock */
|
|
|
|
static void
|
|
|
|
render_last_buffer (GstWaylandSink * sink)
|
|
|
|
{
|
|
|
|
GstWlMeta *meta;
|
|
|
|
struct wl_surface *surface;
|
|
|
|
struct wl_callback *callback;
|
|
|
|
GstVideoRectangle src, dst, res;
|
|
|
|
|
|
|
|
meta = gst_buffer_get_wl_meta (sink->last_buffer);
|
|
|
|
surface = gst_wl_window_get_wl_surface (sink->window);
|
|
|
|
|
|
|
|
g_atomic_int_set (&sink->redraw_pending, TRUE);
|
|
|
|
callback = wl_surface_frame (surface);
|
|
|
|
wl_callback_add_listener (callback, &frame_callback_listener, sink);
|
|
|
|
|
|
|
|
/* Here we essentially add a reference to the buffer. This represents
|
|
|
|
* the fact that the compositor is using the buffer and it should
|
|
|
|
* not return back to the pool and be reused until the compositor
|
|
|
|
* releases it. The release is handled internally in the pool */
|
|
|
|
gst_wayland_compositor_acquire_buffer (meta->pool, sink->last_buffer);
|
|
|
|
|
|
|
|
src.w = sink->video_width;
|
|
|
|
src.h = sink->video_height;
|
|
|
|
dst.w = sink->window->width;
|
|
|
|
dst.h = sink->window->height;
|
|
|
|
gst_video_sink_center_rect (src, dst, &res, FALSE);
|
|
|
|
|
|
|
|
wl_viewport_set (sink->window->viewport, wl_fixed_from_int (0),
|
|
|
|
wl_fixed_from_int (0), wl_fixed_from_int (src.w),
|
|
|
|
wl_fixed_from_int (src.h), res.w, res.h);
|
|
|
|
|
|
|
|
wl_surface_attach (surface, meta->wbuffer, 0, 0);
|
|
|
|
wl_surface_damage (surface, 0, 0, res.w, res.h);
|
|
|
|
|
|
|
|
wl_surface_commit (surface);
|
|
|
|
wl_display_flush (sink->display->display);
|
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
|
2012-05-23 10:07:14 +00:00
|
|
|
GstBuffer *to_render;
|
|
|
|
GstWlMeta *meta;
|
2014-02-28 09:48:30 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
|
2012-07-15 11:27:12 +00:00
|
|
|
GST_LOG_OBJECT (sink, "render buffer %p", buffer);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
|
|
|
/* surface is resizing - drop buffers until finished */
|
2014-03-11 11:14:00 +00:00
|
|
|
if (sink->drawing_frozen)
|
2014-02-28 09:48:30 +00:00
|
|
|
goto done;
|
2012-08-08 14:10:28 +00:00
|
|
|
|
2014-03-07 15:25:00 +00:00
|
|
|
/* drop buffers until we get a frame callback */
|
|
|
|
if (g_atomic_int_get (&sink->redraw_pending) == TRUE)
|
|
|
|
goto done;
|
|
|
|
|
2012-10-20 11:55:41 +00:00
|
|
|
meta = gst_buffer_get_wl_meta (buffer);
|
|
|
|
|
2014-03-07 14:16:30 +00:00
|
|
|
if (meta && meta->pool->display == sink->display) {
|
2012-05-23 10:07:14 +00:00
|
|
|
GST_LOG_OBJECT (sink, "buffer %p from our pool, writing directly", buffer);
|
|
|
|
to_render = buffer;
|
|
|
|
} else {
|
|
|
|
GstMapInfo src;
|
|
|
|
GST_LOG_OBJECT (sink, "buffer %p not from our pool, copying", buffer);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
if (!sink->pool)
|
|
|
|
goto no_pool;
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_set_active (sink->pool, TRUE))
|
|
|
|
goto activate_failed;
|
|
|
|
|
|
|
|
ret = gst_buffer_pool_acquire_buffer (sink->pool, &to_render, NULL);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto no_buffer;
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
gst_buffer_map (buffer, &src, GST_MAP_READ);
|
|
|
|
gst_buffer_fill (to_render, 0, src.data, src.size);
|
|
|
|
gst_buffer_unmap (buffer, &src);
|
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-03-11 15:45:05 +00:00
|
|
|
gst_buffer_replace (&sink->last_buffer, to_render);
|
|
|
|
render_last_buffer (sink);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
/* notify _resume_rendering() in case it's waiting */
|
2014-03-11 15:48:46 +00:00
|
|
|
sink->rendered = TRUE;
|
2014-02-28 09:48:30 +00:00
|
|
|
g_cond_broadcast (&sink->render_cond);
|
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
if (buffer != to_render)
|
|
|
|
gst_buffer_unref (to_render);
|
2014-02-28 09:48:30 +00:00
|
|
|
goto done;
|
2012-05-23 10:07:14 +00:00
|
|
|
|
2012-08-08 14:10:28 +00:00
|
|
|
no_buffer:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (sink, "could not create image");
|
2014-02-28 09:48:30 +00:00
|
|
|
goto done;
|
2012-08-08 14:10:28 +00:00
|
|
|
}
|
|
|
|
no_pool:
|
2012-05-23 10:07:14 +00:00
|
|
|
{
|
2012-08-08 14:10:28 +00:00
|
|
|
GST_ELEMENT_ERROR (sink, RESOURCE, WRITE,
|
|
|
|
("Internal error: can't allocate images"),
|
|
|
|
("We don't have a bufferpool negotiated"));
|
2014-02-28 09:48:30 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
2012-08-08 14:10:28 +00:00
|
|
|
}
|
|
|
|
activate_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (sink, "failed to activate bufferpool.");
|
|
|
|
ret = GST_FLOW_ERROR;
|
2014-02-28 09:48:30 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
{
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2012-08-08 14:10:28 +00:00
|
|
|
return ret;
|
2012-05-23 10:07:14 +00:00
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
static void
|
|
|
|
gst_wayland_sink_videooverlay_init (GstVideoOverlayInterface * iface)
|
|
|
|
{
|
|
|
|
iface->set_window_handle = gst_wayland_sink_set_window_handle;
|
|
|
|
iface->expose = gst_wayland_sink_expose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
|
|
|
|
{
|
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
|
2014-02-28 09:48:30 +00:00
|
|
|
GstWaylandWindowHandle *whandle = (GstWaylandWindowHandle *) handle;
|
|
|
|
GError *error = NULL;
|
|
|
|
GstPad *peer;
|
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
g_return_if_fail (sink != NULL);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (sink, "Setting window handle %" GST_PTR_FORMAT,
|
|
|
|
(void *) handle);
|
|
|
|
|
|
|
|
if (GST_STATE (sink) > GST_STATE_READY)
|
|
|
|
gst_wayland_sink_pause_rendering (GST_WAYLAND_VIDEO (sink));
|
|
|
|
|
|
|
|
g_clear_object (&sink->window);
|
|
|
|
g_clear_object (&sink->display);
|
|
|
|
|
|
|
|
if (handle) {
|
|
|
|
sink->display =
|
|
|
|
gst_wl_display_new_existing (whandle->display, FALSE, &error);
|
|
|
|
if (error) {
|
|
|
|
GST_ELEMENT_WARNING (sink, RESOURCE, OPEN_READ_WRITE,
|
|
|
|
("Could not set window handle"),
|
|
|
|
("Failed to use the external wayland display: '%s'", error->message));
|
|
|
|
g_error_free (error);
|
|
|
|
} else {
|
2014-03-10 11:50:06 +00:00
|
|
|
wl_proxy_set_queue ((struct wl_proxy *) whandle->surface,
|
|
|
|
sink->display->queue);
|
2014-02-28 09:48:30 +00:00
|
|
|
sink->window = gst_wl_window_new_from_surface (sink->display,
|
|
|
|
whandle->surface, whandle->width, whandle->height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* reconfigure to force creation of new window in set_caps */
|
|
|
|
sink->negotiated = FALSE;
|
|
|
|
peer = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink));
|
|
|
|
if (peer) {
|
|
|
|
gst_pad_send_event (peer, gst_event_new_reconfigure ());
|
|
|
|
gst_object_unref (peer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_STATE (sink) > GST_STATE_READY)
|
|
|
|
gst_wayland_sink_resume_rendering (GST_WAYLAND_VIDEO (sink));
|
2014-02-14 15:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_expose (GstVideoOverlay * overlay)
|
|
|
|
{
|
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (overlay);
|
2014-03-11 15:45:05 +00:00
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
g_return_if_fail (sink != NULL);
|
2014-03-11 15:45:05 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (sink, "expose");
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
if (sink->last_buffer && g_atomic_int_get (&sink->redraw_pending) == FALSE) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "redrawing last buffer");
|
|
|
|
render_last_buffer (sink);
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2014-02-14 15:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_waylandvideo_init (GstWaylandVideoInterface * iface)
|
|
|
|
{
|
|
|
|
iface->set_surface_size = gst_wayland_sink_set_surface_size;
|
|
|
|
iface->pause_rendering = gst_wayland_sink_pause_rendering;
|
|
|
|
iface->resume_rendering = gst_wayland_sink_resume_rendering;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_set_surface_size (GstWaylandVideo * video, gint w, gint h)
|
|
|
|
{
|
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (video);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2014-02-14 15:08:56 +00:00
|
|
|
g_return_if_fail (sink != NULL);
|
2014-02-28 09:48:30 +00:00
|
|
|
g_return_if_fail (sink->window != NULL);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
if (!sink->window) {
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
GST_WARNING_OBJECT (sink,
|
|
|
|
"set_surface_size called without window, ignoring");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-11 16:45:23 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "changing window size to %d x %d", w, h);
|
2014-02-28 09:48:30 +00:00
|
|
|
gst_wl_window_set_size (sink->window, w, h);
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2014-02-14 15:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_pause_rendering (GstWaylandVideo * video)
|
|
|
|
{
|
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (video);
|
|
|
|
g_return_if_fail (sink != NULL);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
sink->drawing_frozen = TRUE;
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2014-02-14 15:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wayland_sink_resume_rendering (GstWaylandVideo * video)
|
|
|
|
{
|
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (video);
|
|
|
|
g_return_if_fail (sink != NULL);
|
2014-02-28 09:48:30 +00:00
|
|
|
|
2014-03-11 16:45:23 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "resuming rendering");
|
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
sink->drawing_frozen = FALSE;
|
2014-03-11 15:45:05 +00:00
|
|
|
|
2014-03-11 15:48:46 +00:00
|
|
|
if (GST_STATE (sink) == GST_STATE_PLAYING) {
|
|
|
|
sink->rendered = FALSE;
|
|
|
|
while (sink->rendered == FALSE)
|
|
|
|
g_cond_wait (&sink->render_cond, GST_OBJECT_GET_LOCK (sink));
|
2014-03-11 16:45:23 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "synchronized with render()");
|
2014-03-11 15:48:46 +00:00
|
|
|
} else if (sink->window && sink->last_buffer &&
|
|
|
|
g_atomic_int_get (&sink->redraw_pending) == FALSE) {
|
2014-03-11 15:45:05 +00:00
|
|
|
render_last_buffer (sink);
|
2014-03-11 16:45:23 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "last buffer redrawn");
|
2014-03-11 15:48:46 +00:00
|
|
|
}
|
2014-03-11 15:45:05 +00:00
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2014-02-14 15:08:56 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gstwayland_debug, "waylandsink", 0,
|
|
|
|
" wayland video sink");
|
|
|
|
|
|
|
|
return gst_element_register (plugin, "waylandsink", GST_RANK_MARGINAL,
|
|
|
|
GST_TYPE_WAYLAND_SINK);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 16:02:56 +00:00
|
|
|
waylandsink,
|
2012-03-07 23:48:56 +00:00
|
|
|
"Wayland Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
|
|
|
|
GST_PACKAGE_ORIGIN)
|