waylandsink: Fix warnings, proper structuring, dead code removal, adding doc section.

This commit is contained in:
Sreerenj Balachandran 2012-03-08 01:48:56 +02:00 committed by Stefan Sauer
parent 4e7edb2778
commit 689bf4d392
2 changed files with 64 additions and 103 deletions

View file

@ -1,8 +1,8 @@
/* /*
* GStreamer Wayland video sink * GStreamer Wayland video sink
* *
* Copyright: Intel Corporation * Copyright (C) 2011 Intel Corporation
* Copyright: Sreerenj Balachandran <sreerenj.balachandran@intel.com> * Copyright (C) 2011 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -19,30 +19,28 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/**
/* The waylandsink is creating its own window and render the decoded video frames to that.*/ * 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.
* The current implementaion is based on weston compositor.
*
* <refsect2>
* <title>Example pipelines</title>
* |[
* gst-launch -v videotestsrc ! waylandsink
* ]| test the video rendering in wayland
* </refsect2>
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include "gstwaylandsink.h" #include "gstwaylandsink.h"
#include <wayland-client.h>
/* signals */ /* signals */
enum enum
{ {
@ -52,7 +50,6 @@ enum
}; };
/* Properties */ /* Properties */
/*Fixme: Not yet implemented */
enum enum
{ {
PROP_0, PROP_0,
@ -72,28 +69,27 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
"green_mask = (int) 16711680, " "green_mask = (int) 16711680, "
"blue_mask = (int) -16777216," "blue_mask = (int) -16777216,"
"width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ] ")); "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ] "));
GType gst_wlbuffer_get_type (void);
G_DEFINE_TYPE (GstWlBuffer, gst_wlbuffer, GST_TYPE_BUFFER);
/*Fixme: Add more interfaces */ /*Fixme: Add more interfaces */
GST_BOILERPLATE (GstWaylandSink, gst_wayland_sink, GstVideoSink, GST_BOILERPLATE (GstWaylandSink, gst_wayland_sink, GstVideoSink,
GST_TYPE_VIDEO_SINK); GST_TYPE_VIDEO_SINK);
static void gst_wlbuffer_finalize (GstWlBuffer * wbuffer); static void gst_wlbuffer_finalize (GstWlBuffer * wbuffer);
static GstBufferClass *wlbuffer_parent_class = NULL;
static void gst_wayland_sink_get_property (GObject * object, static void gst_wayland_sink_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec); guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_wayland_sink_set_property (GObject * object, static void gst_wayland_sink_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec); guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_wayland_sink_dispose (GObject * object);
static void gst_wayland_sink_finalize (GObject * object); static void gst_wayland_sink_finalize (GObject * object);
static GstCaps *gst_wayland_sink_get_caps (GstBaseSink * bsink); static GstCaps *gst_wayland_sink_get_caps (GstBaseSink * bsink);
static gboolean gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps); static gboolean gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps);
static gboolean gst_wayland_sink_start (GstBaseSink * bsink); static gboolean gst_wayland_sink_start (GstBaseSink * bsink);
static gboolean gst_wayland_sink_stop (GstBaseSink * bsink); static gboolean gst_wayland_sink_stop (GstBaseSink * bsink);
static GstFlowReturn static GstFlowReturn
gst_wayland_sink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size, gst_wayland_sink_buffer_alloc (GstBaseSink * bsink, guint64 offset,
GstCaps * caps, GstBuffer ** buf); guint size, GstCaps * caps, GstBuffer ** buf);
static gboolean gst_wayland_sink_preroll (GstBaseSink * bsink, static gboolean gst_wayland_sink_preroll (GstBaseSink * bsink,
GstBuffer * buffer); GstBuffer * buffer);
static gboolean gst_wayland_sink_render (GstBaseSink * bsink, static gboolean gst_wayland_sink_render (GstBaseSink * bsink,
@ -107,51 +103,25 @@ static struct display *create_display (void);
static void display_handle_global (struct wl_display *display, uint32_t id, static void display_handle_global (struct wl_display *display, uint32_t id,
const char *interface, uint32_t version, void *data); const char *interface, uint32_t version, void *data);
static void redraw (void *data, struct wl_callback *callback, uint32_t time); static void redraw (void *data, struct wl_callback *callback, uint32_t time);
static void create_window (GstWaylandSink * sink, static void create_window (GstWaylandSink * sink, struct display *display,
struct display *display, int width, int height); int width, int height);
static void static void
gst_wlbuffer_init (GstWlBuffer * buffer, gpointer g_class) gst_wlbuffer_init (GstWlBuffer * buffer)
{ {
buffer->wbuffer = NULL; buffer->wbuffer = NULL;
buffer->wlsink = NULL; buffer->wlsink = NULL;
} }
static void static void
gst_wlbuffer_class_init (gpointer g_class, gpointer class_data) gst_wlbuffer_class_init (GstWlBufferClass * klass)
{ {
GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class); GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (klass);
wlbuffer_parent_class = g_type_class_peek_parent (g_class);
mini_object_class->finalize = (GstMiniObjectFinalizeFunction) mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
gst_wlbuffer_finalize; gst_wlbuffer_finalize;
} }
GType
gst_wlbuffer_get_type (void)
{
static GType _gst_wlbuffer_type;
if (G_UNLIKELY (_gst_wlbuffer_type == 0)) {
static const GTypeInfo wlbuffer_info = {
sizeof (GstBufferClass),
NULL,
NULL,
gst_wlbuffer_class_init,
NULL,
NULL,
sizeof (GstWlBuffer),
0,
(GInstanceInitFunc) gst_wlbuffer_init,
NULL
};
_gst_wlbuffer_type = g_type_register_static (GST_TYPE_BUFFER,
"GstWlBuffer", &wlbuffer_info, 0);
}
return _gst_wlbuffer_type;
}
static void static void
gst_wlbuffer_finalize (GstWlBuffer * wbuffer) gst_wlbuffer_finalize (GstWlBuffer * wbuffer)
{ {
@ -189,7 +159,7 @@ gst_wayland_sink_base_init (gpointer gclass)
gst_element_class_set_details_simple (element_class, gst_element_class_set_details_simple (element_class,
"wayland video sink", "Sink/Video", "wayland video sink", "Sink/Video",
"Output to wayland surface", "Output to wayland surface",
"Sreerenj Balachandran <sreerenj.balachandran@intel.com>,"); "Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
} }
static void static void
@ -203,7 +173,6 @@ gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
gobject_class->set_property = gst_wayland_sink_set_property; gobject_class->set_property = gst_wayland_sink_set_property;
gobject_class->get_property = gst_wayland_sink_get_property; gobject_class->get_property = gst_wayland_sink_get_property;
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_wayland_sink_dispose);
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wayland_sink_finalize); gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_wayland_sink_finalize);
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_get_caps); gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_wayland_sink_get_caps);
@ -217,8 +186,8 @@ gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
g_object_class_install_property (gobject_class, PROP_WAYLAND_DISPLAY, g_object_class_install_property (gobject_class, PROP_WAYLAND_DISPLAY,
g_param_spec_pointer ("wayland-display", "Wayland Display", g_param_spec_pointer ("wayland-display", "Wayland Display",
"Wayland Display id created by the application ", "Wayland Display handle created by the application ",
G_PARAM_READWRITE)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
} }
@ -291,27 +260,24 @@ destroy_display (struct display *display)
static void static void
destroy_window (struct window *window) destroy_window (struct window *window)
{ {
wl_shell_surface_destroy (window->shell_surface); if (window->shell_surface)
wl_surface_destroy (window->surface); wl_shell_surface_destroy (window->shell_surface);
if (window->surface)
wl_surface_destroy (window->surface);
free (window); free (window);
} }
static void
gst_wayland_sink_dispose (GObject * object)
{
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void static void
gst_wayland_sink_finalize (GObject * object) gst_wayland_sink_finalize (GObject * object)
{ {
GstWaylandSink *sink = GST_WAYLAND_SINK (object); GstWaylandSink *sink = GST_WAYLAND_SINK (object);
GST_DEBUG_OBJECT (sink, "Finalizing the sink.."); GST_DEBUG_OBJECT (sink, "Finalizing the sink..");
gst_caps_replace (&sink->caps, NULL);
free (sink->display); if (sink->window)
free (sink->window); destroy_window (sink->window);
if (sink->display)
destroy_display (sink->display);
if (sink->pool_lock) { if (sink->pool_lock) {
g_mutex_free (sink->pool_lock); g_mutex_free (sink->pool_lock);
@ -327,7 +293,6 @@ gst_wayland_sink_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
static GstCaps * static GstCaps *
gst_wayland_sink_get_caps (GstBaseSink * bsink) gst_wayland_sink_get_caps (GstBaseSink * bsink)
{ {
@ -432,7 +397,8 @@ wayland_buffer_create (GstWaylandSink * sink)
data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
unlink (filename); unlink (filename);
if (data == MAP_FAILED) { if (data == MAP_FAILED) {
fprintf (stderr, "mmap failed: %m\n"); GST_ELEMENT_ERROR (sink, LIBRARY, SHUTDOWN, (NULL),
("mmap() failed: %s", strerror (errno)));
close (fd); close (fd);
exit (0); exit (0);
} }
@ -446,7 +412,6 @@ wayland_buffer_create (GstWaylandSink * sink)
GST_BUFFER_SIZE (wbuffer) = size; GST_BUFFER_SIZE (wbuffer) = size;
return wbuffer; return wbuffer;
} }
static void static void
@ -457,7 +422,7 @@ gst_wayland_buffer_destroy (GstWaylandSink * sink, GstWlBuffer * buffer)
gst_object_unref (sink); gst_object_unref (sink);
} }
GST_MINI_OBJECT_CLASS (wlbuffer_parent_class)->finalize (GST_MINI_OBJECT GST_MINI_OBJECT_CLASS (gst_wlbuffer_parent_class)->finalize (GST_MINI_OBJECT
(buffer)); (buffer));
} }
@ -521,7 +486,6 @@ gst_wayland_sink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
gst_caps_unref (desired_caps); gst_caps_unref (desired_caps);
return ret; return ret;
} }
static gboolean static gboolean
@ -531,22 +495,13 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
const GstStructure *structure; const GstStructure *structure;
GstCaps *allowed_caps; GstCaps *allowed_caps;
gboolean ret = TRUE; gboolean ret = TRUE;
GstCaps *intersection;
GST_LOG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps); GST_LOG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
structure = gst_caps_get_structure (caps, 0);
allowed_caps = gst_pad_get_caps (GST_BASE_SINK_PAD (bsink)); allowed_caps = gst_pad_get_caps (GST_BASE_SINK_PAD (bsink));
/* We intersect those caps with our template to make sure they are correct */ if (!gst_caps_can_intersect (allowed_caps, caps))
intersection = gst_caps_intersect (allowed_caps, caps);
gst_caps_unref (allowed_caps);
if (gst_caps_is_empty (intersection)) {
gst_caps_unref (intersection);
return FALSE; return FALSE;
}
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
@ -558,8 +513,6 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
gst_caps_replace (&sink->caps, caps); gst_caps_replace (&sink->caps, caps);
gst_caps_unref (intersection);
return TRUE; return TRUE;
} }
@ -593,7 +546,7 @@ create_window (GstWaylandSink * sink, struct display *display, int width,
window->shell_surface = wl_shell_get_shell_surface (display->shell, window->shell_surface = wl_shell_get_shell_surface (display->shell,
window->surface); window->surface);
// wl_shell_surface_set_toplevel (window->shell_surface); /* wl_shell_surface_set_toplevel (window->shell_surface); */
wl_shell_surface_set_fullscreen (window->shell_surface, wl_shell_surface_set_fullscreen (window->shell_surface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, NULL); WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, NULL);
@ -602,7 +555,6 @@ create_window (GstWaylandSink * sink, struct display *display, int width,
g_mutex_unlock (sink->wayland_lock); g_mutex_unlock (sink->wayland_lock);
} }
static gboolean static gboolean
gst_wayland_sink_start (GstBaseSink * bsink) gst_wayland_sink_start (GstBaseSink * bsink)
{ {
@ -635,7 +587,6 @@ gst_wayland_sink_preroll (GstBaseSink * bsink, GstBuffer * buffer)
return gst_wayland_sink_render (bsink, buffer); return gst_wayland_sink_render (bsink, buffer);
} }
static GstFlowReturn static GstFlowReturn
gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer) gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
{ {
@ -674,15 +625,6 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
if (mem_cpy) { if (mem_cpy) {
GstWlBuffer *wlbuf = wayland_buffer_create (sink); GstWlBuffer *wlbuf = wayland_buffer_create (sink);
/*Fixme: remove the memcpy and add memory allocation stuffs to buff_alloc */
/*guint8 *src = GST_BUFFER_DATA (buffer);
guint len = GST_BUFFER_SIZE (buffer) / sink->height;
for (i = 0; i < sink->height; i++) {
memcpy (data, src, len);
src += len;
data += len;
} */
memcpy (GST_BUFFER_DATA (wlbuf), GST_BUFFER_DATA (buffer), memcpy (GST_BUFFER_DATA (wlbuf), GST_BUFFER_DATA (buffer),
GST_BUFFER_SIZE (buffer)); GST_BUFFER_SIZE (buffer));
@ -735,4 +677,5 @@ plugin_init (GstPlugin * plugin)
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR, GST_VERSION_MINOR,
"waylandsink", "waylandsink",
"Wayland Video Sink", plugin_init, VERSION, "LGPL", "gst-wayland", "") "Wayland Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME,
GST_PACKAGE_ORIGIN)

View file

@ -21,6 +21,19 @@
#ifndef __GST_WAYLAND_VIDEO_SINK_H__ #ifndef __GST_WAYLAND_VIDEO_SINK_H__
#define __GST_WAYLAND_VIDEO_SINK_H__ #define __GST_WAYLAND_VIDEO_SINK_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h> #include <gst/video/video.h>
#include <gst/video/gstvideosink.h> #include <gst/video/gstvideosink.h>
@ -67,6 +80,7 @@ typedef struct _GstWaylandSinkClass GstWaylandSinkClass;
#define GST_WLBUFFER (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WLBUFFER, GstWlBuffer)) #define GST_WLBUFFER (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WLBUFFER, GstWlBuffer))
typedef struct _GstWlBuffer GstWlBuffer; typedef struct _GstWlBuffer GstWlBuffer;
typedef struct _GstWlBufferClass GstWlBufferClass;
struct _GstWlBuffer { struct _GstWlBuffer {
GstBuffer buffer; /* Extending GstBuffer */ GstBuffer buffer; /* Extending GstBuffer */
@ -76,6 +90,11 @@ struct _GstWlBuffer {
GstWaylandSink *wlsink; GstWaylandSink *wlsink;
}; };
struct _GstWlBufferClass
{
GstBufferClass parent_class;
};
struct _GstWaylandSink struct _GstWaylandSink
{ {
@ -103,11 +122,10 @@ struct _GstWaylandSink
struct _GstWaylandSinkClass struct _GstWaylandSinkClass
{ {
GstVideoSinkClass parent; GstVideoSinkClass parent;
}; };
GType gst_wayland_sink_get_type (void) G_GNUC_CONST; GType gst_wayland_sink_get_type (void) G_GNUC_CONST;
GType gst_dfbsurface_get_type (void); GType gst_wlbuffer_get_type (void);
G_END_DECLS G_END_DECLS
#endif /* __GST_WAYLAND_VIDEO_SINK_H__ */ #endif /* __GST_WAYLAND_VIDEO_SINK_H__ */