2011-11-02 09:02:11 +00:00
|
|
|
/*
|
|
|
|
* GStreamer Wayland video sink
|
|
|
|
*
|
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>
|
|
|
|
*
|
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
|
|
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
/* signals */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
SIGNAL_FRAME_READY,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_WAYLAND_DISPLAY
|
|
|
|
};
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (gstwayland_debug);
|
|
|
|
#define GST_CAT_DEFAULT gstwayland_debug
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-05-23 10:07:14 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-raw, "
|
|
|
|
"format = (string) BGRA, "
|
2011-11-02 09:02:11 +00:00
|
|
|
"framerate = (fraction) [ 0, MAX ], "
|
|
|
|
"width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ] "));
|
2012-03-07 23:48:56 +00:00
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
/*Fixme: Add more interfaces */
|
2012-05-23 10:07:14 +00:00
|
|
|
#define gst_wayland_sink_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstWaylandSink, gst_wayland_sink, GST_TYPE_VIDEO_SINK);
|
|
|
|
|
|
|
|
/* wl metadata */
|
|
|
|
GType
|
|
|
|
gst_wl_meta_api_get_type (void)
|
|
|
|
{
|
|
|
|
static volatile GType type;
|
|
|
|
static const gchar *tags[] =
|
|
|
|
{ "memory", "size", "colorspace", "orientation", NULL };
|
|
|
|
|
|
|
|
if (g_once_init_enter (&type)) {
|
|
|
|
GType _type = gst_meta_api_type_register ("GstWlMetaAPI", tags);
|
|
|
|
g_once_init_leave (&type, _type);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
static void
|
|
|
|
gst_wl_meta_free (GstWlMeta * meta, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gst_object_unref (meta->sink);
|
|
|
|
munmap (meta->data, meta->size);
|
|
|
|
wl_buffer_destroy (meta->wbuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
const GstMetaInfo *
|
|
|
|
gst_wl_meta_get_info (void)
|
|
|
|
{
|
|
|
|
static const GstMetaInfo *wl_meta_info = NULL;
|
|
|
|
|
|
|
|
if (wl_meta_info == NULL) {
|
|
|
|
wl_meta_info =
|
|
|
|
gst_meta_register (GST_WL_META_API_TYPE, "GstWlMeta",
|
|
|
|
sizeof (GstWlMeta), (GstMetaInitFunction) NULL,
|
|
|
|
(GstMetaFreeFunction) gst_wl_meta_free,
|
|
|
|
(GstMetaTransformFunction) NULL);
|
|
|
|
}
|
|
|
|
return wl_meta_info;
|
|
|
|
}
|
2011-11-02 11:51:13 +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);
|
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_start (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_wayland_sink_stop (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_wayland_sink_preroll (GstBaseSink * bsink,
|
|
|
|
GstBuffer * buffer);
|
|
|
|
static gboolean gst_wayland_sink_render (GstBaseSink * bsink,
|
|
|
|
GstBuffer * buffer);
|
|
|
|
|
|
|
|
static int event_mask_update (uint32_t mask, void *data);
|
|
|
|
static struct display *create_display (void);
|
|
|
|
static void display_handle_global (struct wl_display *display, uint32_t id,
|
|
|
|
const char *interface, uint32_t version, void *data);
|
2011-11-02 14:23:02 +00:00
|
|
|
static void redraw (void *data, struct wl_callback *callback, uint32_t time);
|
2012-03-07 23:48:56 +00:00
|
|
|
static void create_window (GstWaylandSink * sink, struct display *display,
|
|
|
|
int width, int height);
|
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));
|
|
|
|
|
|
|
|
gst_element_class_set_details_simple (gstelement_class,
|
|
|
|
"wayland video sink", "Sink/Video",
|
|
|
|
"Output to wayland surface",
|
|
|
|
"Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
|
|
|
|
|
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->start = GST_DEBUG_FUNCPTR (gst_wayland_sink_start);
|
|
|
|
gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_wayland_sink_stop);
|
|
|
|
gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_wayland_sink_preroll);
|
|
|
|
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_wayland_sink_render);
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_WAYLAND_DISPLAY,
|
2011-11-02 11:51:13 +00:00
|
|
|
g_param_spec_pointer ("wayland-display", "Wayland Display",
|
2012-03-07 23:48:56 +00:00
|
|
|
"Wayland Display handle created by the application ",
|
|
|
|
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
|
|
|
{
|
2012-05-23 10:07:14 +00:00
|
|
|
sink->render_busy = FALSE;
|
2012-02-16 20:27:23 +00:00
|
|
|
sink->display = NULL;
|
|
|
|
sink->window = NULL;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
g_mutex_init (&sink->wayland_lock);
|
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) {
|
|
|
|
case PROP_WAYLAND_DISPLAY:
|
|
|
|
g_value_set_pointer (value, sink->display);
|
|
|
|
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) {
|
|
|
|
case PROP_WAYLAND_DISPLAY:
|
|
|
|
sink->display = g_value_get_pointer (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 20:27:23 +00:00
|
|
|
static void
|
|
|
|
destroy_display (struct display *display)
|
|
|
|
{
|
|
|
|
if (display->shm)
|
|
|
|
wl_shm_destroy (display->shm);
|
|
|
|
|
|
|
|
if (display->shell)
|
|
|
|
wl_shell_destroy (display->shell);
|
|
|
|
|
|
|
|
if (display->compositor)
|
|
|
|
wl_compositor_destroy (display->compositor);
|
|
|
|
|
|
|
|
wl_display_flush (display->display);
|
|
|
|
wl_display_destroy (display->display);
|
|
|
|
free (display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_window (struct window *window)
|
|
|
|
{
|
2012-03-07 23:48:56 +00:00
|
|
|
if (window->shell_surface)
|
|
|
|
wl_shell_surface_destroy (window->shell_surface);
|
|
|
|
if (window->surface)
|
|
|
|
wl_surface_destroy (window->surface);
|
2012-02-16 20:27:23 +00:00
|
|
|
free (window);
|
|
|
|
}
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
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..");
|
|
|
|
|
2012-03-07 23:48:56 +00:00
|
|
|
if (sink->window)
|
|
|
|
destroy_window (sink->window);
|
|
|
|
if (sink->display)
|
|
|
|
destroy_display (sink->display);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
g_mutex_clear (&sink->wayland_lock);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-23 10:07:14 +00:00
|
|
|
return gst_static_pad_template_get_caps (&sink_template);
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
event_mask_update (uint32_t mask, void *data)
|
|
|
|
{
|
|
|
|
struct display *d = data;
|
|
|
|
|
|
|
|
d->mask = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 20:27:23 +00:00
|
|
|
static void
|
|
|
|
shm_format (void *data, struct wl_shm *wl_shm, uint32_t format)
|
|
|
|
{
|
|
|
|
struct display *d = data;
|
|
|
|
|
|
|
|
d->formats |= (1 << format);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_shm_listener shm_listenter = {
|
|
|
|
shm_format
|
|
|
|
};
|
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
static void
|
|
|
|
display_handle_global (struct wl_display *display, uint32_t id,
|
|
|
|
const char *interface, uint32_t version, void *data)
|
|
|
|
{
|
|
|
|
struct display *d = data;
|
|
|
|
|
|
|
|
if (strcmp (interface, "wl_compositor") == 0) {
|
2011-11-02 14:23:02 +00:00
|
|
|
d->compositor = wl_display_bind (display, id, &wl_compositor_interface);
|
2011-11-02 09:02:11 +00:00
|
|
|
} else if (strcmp (interface, "wl_shell") == 0) {
|
2011-11-02 14:23:02 +00:00
|
|
|
d->shell = wl_display_bind (display, id, &wl_shell_interface);
|
2011-11-02 09:02:11 +00:00
|
|
|
} else if (strcmp (interface, "wl_shm") == 0) {
|
2011-11-02 14:23:02 +00:00
|
|
|
d->shm = wl_display_bind (display, id, &wl_shm_interface);
|
2012-02-16 20:27:23 +00:00
|
|
|
wl_shm_add_listener (d->shm, &shm_listenter, d);
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct display *
|
|
|
|
create_display (void)
|
|
|
|
{
|
|
|
|
struct display *display;
|
|
|
|
|
|
|
|
display = malloc (sizeof *display);
|
|
|
|
display->display = wl_display_connect (NULL);
|
2011-11-02 14:23:02 +00:00
|
|
|
assert (display->display);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
wl_display_add_global_listener (display->display,
|
|
|
|
display_handle_global, display);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
wl_display_iterate (display->display, WL_DISPLAY_READABLE);
|
2012-02-16 20:27:23 +00:00
|
|
|
wl_display_roundtrip (display->display);
|
|
|
|
|
|
|
|
if (!(display->formats & (1 << WL_SHM_FORMAT_XRGB8888))) {
|
|
|
|
GST_ERROR ("WL_SHM_FORMAT_XRGB32 not available");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
wl_display_get_fd (display->display, event_mask_update, display);
|
|
|
|
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
static GstBuffer *
|
2011-11-02 11:51:13 +00:00
|
|
|
wayland_buffer_create (GstWaylandSink * sink)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
char filename[1024];
|
|
|
|
int fd, size, stride;
|
2011-11-02 09:02:11 +00:00
|
|
|
static void *data;
|
2011-11-02 11:51:13 +00:00
|
|
|
static int init = 0;
|
2012-05-23 10:07:14 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
GstWlMeta *wmeta;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (sink, "Creating wayland-shm buffers");
|
|
|
|
|
2012-02-16 20:27:23 +00:00
|
|
|
snprintf (filename, 256, "%s-%d-%s", "/tmp/wayland-shm", init++, "XXXXXX");
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
fd = mkstemp (filename);
|
|
|
|
if (fd < 0) {
|
2011-11-02 11:51:13 +00:00
|
|
|
GST_ERROR_OBJECT (sink, "open %s failed:", filename);
|
2012-05-23 10:07:14 +00:00
|
|
|
return NULL;
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 11:51:13 +00:00
|
|
|
stride = sink->video_width * 4;
|
|
|
|
size = stride * sink->video_height;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
if (ftruncate (fd, size) < 0) {
|
2011-11-02 11:51:13 +00:00
|
|
|
GST_ERROR_OBJECT (sink, "ftruncate failed:");
|
2011-11-02 09:02:11 +00:00
|
|
|
close (fd);
|
2012-05-23 10:07:14 +00:00
|
|
|
return NULL;
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
unlink (filename);
|
|
|
|
if (data == MAP_FAILED) {
|
2012-03-07 23:48:56 +00:00
|
|
|
GST_ELEMENT_ERROR (sink, LIBRARY, SHUTDOWN, (NULL),
|
|
|
|
("mmap() failed: %s", strerror (errno)));
|
2011-11-02 09:02:11 +00:00
|
|
|
close (fd);
|
2012-05-23 10:07:14 +00:00
|
|
|
return NULL;
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
|
|
|
|
wmeta = (GstWlMeta *) gst_buffer_add_meta (buffer, GST_WL_META_INFO, NULL);
|
|
|
|
wmeta->sink = gst_object_ref (sink);
|
|
|
|
wmeta->wbuffer = wl_shm_create_buffer (sink->display->shm, fd,
|
2012-02-16 20:27:23 +00:00
|
|
|
sink->video_width, sink->video_height, stride, WL_SHM_FORMAT_XRGB8888);
|
2012-05-23 10:07:14 +00:00
|
|
|
wmeta->data = data;
|
|
|
|
wmeta->size = size;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
close (fd);
|
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
gst_buffer_append_memory (buffer,
|
|
|
|
gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, data,
|
|
|
|
size, 0, size, NULL, NULL));
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
return buffer;
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
|
2011-11-02 09:02:11 +00:00
|
|
|
const GstStructure *structure;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2011-11-02 11:51:13 +00:00
|
|
|
ret &= gst_structure_get_int (structure, "width", &sink->video_width);
|
|
|
|
ret &= gst_structure_get_int (structure, "height", &sink->video_height);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-11-02 14:23:02 +00:00
|
|
|
static const struct wl_callback_listener frame_listener;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
static void
|
2011-11-02 14:23:02 +00:00
|
|
|
redraw (void *data, struct wl_callback *callback, uint32_t time)
|
2011-11-02 09:02:11 +00:00
|
|
|
{
|
|
|
|
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = (GstWaylandSink *) data;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
sink->render_busy = FALSE;
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 20:27:23 +00:00
|
|
|
static void
|
2011-11-02 11:51:13 +00:00
|
|
|
create_window (GstWaylandSink * sink, struct display *display, int width,
|
2011-11-02 09:02:11 +00:00
|
|
|
int height)
|
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
|
2012-02-16 20:27:23 +00:00
|
|
|
if (sink->window)
|
|
|
|
return;
|
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
g_mutex_lock (&sink->wayland_lock);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
window = malloc (sizeof *window);
|
|
|
|
window->display = display;
|
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
|
|
|
window->surface = wl_compositor_create_surface (display->compositor);
|
|
|
|
|
2012-02-16 20:27:23 +00:00
|
|
|
window->shell_surface = wl_shell_get_shell_surface (display->shell,
|
|
|
|
window->surface);
|
2012-03-07 23:48:56 +00:00
|
|
|
/* wl_shell_surface_set_toplevel (window->shell_surface); */
|
2012-05-23 10:07:14 +00:00
|
|
|
#ifdef WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT
|
2012-02-28 19:00:24 +00:00
|
|
|
wl_shell_surface_set_fullscreen (window->shell_surface,
|
|
|
|
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, NULL);
|
2012-05-23 10:07:14 +00:00
|
|
|
#endif
|
2012-02-16 20:27:23 +00:00
|
|
|
|
|
|
|
sink->window = window;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
g_mutex_unlock (&sink->wayland_lock);
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_wayland_sink_start (GstBaseSink * bsink)
|
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = (GstWaylandSink *) bsink;
|
2011-11-02 09:02:11 +00:00
|
|
|
gboolean result = TRUE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (sink, "start");
|
|
|
|
|
|
|
|
if (!sink->display)
|
|
|
|
sink->display = create_display ();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_wayland_sink_stop (GstBaseSink * bsink)
|
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = (GstWaylandSink *) bsink;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (sink, "stop");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
|
|
|
{
|
2011-11-02 11:51:13 +00:00
|
|
|
GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
|
|
|
|
GstVideoRectangle src, dst, res;
|
2012-05-23 10:07:14 +00:00
|
|
|
GstBuffer *to_render;
|
|
|
|
GstWlMeta *meta;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
GST_LOG_OBJECT (sink, "render buffer %p" GST_TIME_FORMAT, buffer);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-02-16 20:27:23 +00:00
|
|
|
if (!sink->window)
|
|
|
|
create_window (sink, sink->display, sink->video_width, sink->video_height);
|
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
if (sink->render_busy)
|
|
|
|
goto was_busy;
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
meta = gst_buffer_get_wl_meta (buffer);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
if (meta && meta->sink == sink) {
|
|
|
|
GST_LOG_OBJECT (sink, "buffer %p from our pool, writing directly", buffer);
|
|
|
|
to_render = buffer;
|
|
|
|
} else {
|
|
|
|
GstMapInfo src;
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
GST_LOG_OBJECT (sink, "buffer %p not from our pool, copying", buffer);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
to_render = wayland_buffer_create (sink);
|
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 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
meta = gst_buffer_get_wl_meta (to_render);
|
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
src.w = sink->video_width;
|
|
|
|
src.h = sink->video_height;
|
|
|
|
dst.w = sink->window->width;
|
|
|
|
dst.h = sink->window->height;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
gst_video_sink_center_rect (src, dst, &res, FALSE);
|
2011-11-02 11:51:13 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
sink->render_busy = TRUE;
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
wl_buffer_damage (meta->wbuffer, 0, 0, res.w, res.h);
|
|
|
|
wl_surface_attach (sink->window->surface, meta->wbuffer, 0, 0);
|
|
|
|
wl_surface_damage (sink->window->surface, 0, 0, res.w, res.h);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
if (sink->callback)
|
|
|
|
wl_callback_destroy (sink->callback);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
sink->callback = wl_surface_frame (sink->window->surface);
|
|
|
|
wl_callback_add_listener (sink->callback, &frame_listener, sink);
|
|
|
|
wl_display_iterate (sink->display->display, sink->display->mask);
|
2011-11-02 09:02:11 +00:00
|
|
|
|
2012-05-23 10:07:14 +00:00
|
|
|
if (buffer != to_render)
|
|
|
|
gst_buffer_unref (to_render);
|
2012-02-16 20:27:23 +00:00
|
|
|
|
2011-11-02 09:02:11 +00:00
|
|
|
return GST_FLOW_OK;
|
2012-05-23 10:07:14 +00:00
|
|
|
|
|
|
|
was_busy:
|
|
|
|
{
|
|
|
|
GST_LOG_OBJECT (sink,
|
|
|
|
"Waiting to get the signal from compositor to render the next frame..");
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2011-11-02 09:02:11 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 14:23:02 +00:00
|
|
|
static const struct wl_callback_listener frame_listener = {
|
|
|
|
redraw
|
|
|
|
};
|
|
|
|
|
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)
|