2001-12-20 23:21:15 +00:00
|
|
|
/* GStreamer SDL plugin
|
2002-01-31 22:22:42 +00:00
|
|
|
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2001-12-20 23:21:15 +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., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* let's not forget to mention that all this was based on aasink ;-) */
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-20 23:21:15 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
2002-02-03 20:10:03 +00:00
|
|
|
#include <stdlib.h>
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
#include <gst/xoverlay/xoverlay.h>
|
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
#include "sdlvideosink.h"
|
|
|
|
|
2002-09-18 19:02:52 +00:00
|
|
|
/* elementfactory information */
|
2001-12-20 23:21:15 +00:00
|
|
|
static GstElementDetails gst_sdlvideosink_details = {
|
|
|
|
"Video sink",
|
|
|
|
"Sink/Video",
|
2002-09-18 19:02:52 +00:00
|
|
|
"LGPL",
|
2001-12-20 23:21:15 +00:00
|
|
|
"An SDL-based videosink",
|
|
|
|
VERSION,
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>",
|
|
|
|
"(C) 2001",
|
|
|
|
};
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static void gst_sdlvideosink_class_init (GstSDLVideoSinkClass *klass);
|
|
|
|
static void gst_sdlvideosink_init (GstSDLVideoSink *sdl);
|
|
|
|
|
|
|
|
static void gst_sdlvideosink_interface_init (GstInterfaceClass *klass);
|
|
|
|
static gboolean gst_sdlvideosink_interface_supported (GstInterface *iface,
|
|
|
|
GType type);
|
|
|
|
|
|
|
|
static void gst_sdlvideosink_xoverlay_init (GstXOverlayClass *klass);
|
|
|
|
static void gst_sdlvideosink_xoverlay_set_xwindow_id
|
|
|
|
(GstXOverlay *overlay,
|
|
|
|
XID parent);
|
|
|
|
|
|
|
|
static gboolean gst_sdlvideosink_lock (GstSDLVideoSink *sdl);
|
|
|
|
static void gst_sdlvideosink_unlock (GstSDLVideoSink *sdl);
|
|
|
|
|
|
|
|
static gboolean gst_sdlvideosink_initsdl (GstSDLVideoSink *sdl);
|
|
|
|
static void gst_sdlvideosink_deinitsdl (GstSDLVideoSink *sdl);
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static gboolean gst_sdlvideosink_create (GstSDLVideoSink *sdl);
|
|
|
|
static void gst_sdlvideosink_destroy (GstSDLVideoSink *sdl);
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static GstPadLinkReturn
|
|
|
|
gst_sdlvideosink_sinkconnect (GstPad *pad,
|
|
|
|
GstCaps *caps);
|
|
|
|
static void gst_sdlvideosink_chain (GstPad *pad,
|
|
|
|
GstData *data);
|
|
|
|
|
|
|
|
static void gst_sdlvideosink_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gst_sdlvideosink_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_sdlvideosink_change_state (GstElement *element);
|
2002-01-10 09:58:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstCaps *capslist = NULL;
|
|
|
|
static GstPadTemplate *sink_template;
|
2002-01-15 15:52:09 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
GType
|
|
|
|
gst_sdlvideosink_get_type (void)
|
|
|
|
{
|
|
|
|
static GType sdlvideosink_type = 0;
|
|
|
|
|
|
|
|
if (!sdlvideosink_type) {
|
|
|
|
static const GTypeInfo sdlvideosink_info = {
|
2003-09-14 21:09:41 +00:00
|
|
|
sizeof (GstSDLVideoSinkClass), NULL,
|
2001-12-20 23:21:15 +00:00
|
|
|
NULL,
|
2003-09-14 21:09:41 +00:00
|
|
|
(GClassInitFunc) gst_sdlvideosink_class_init,
|
2001-12-20 23:21:15 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2003-09-14 21:09:41 +00:00
|
|
|
sizeof (GstSDLVideoSink),
|
2001-12-20 23:21:15 +00:00
|
|
|
0,
|
2003-09-14 21:09:41 +00:00
|
|
|
(GInstanceInitFunc) gst_sdlvideosink_init,
|
2001-12-20 23:21:15 +00:00
|
|
|
};
|
2003-10-28 09:08:32 +00:00
|
|
|
static const GInterfaceInfo iface_info = {
|
|
|
|
(GInterfaceInitFunc) gst_sdlvideosink_interface_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
static const GInterfaceInfo xoverlay_info = {
|
|
|
|
(GInterfaceInitFunc) gst_sdlvideosink_xoverlay_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
sdlvideosink_type = g_type_register_static(GST_TYPE_VIDEOSINK,
|
|
|
|
"GstSDLVideoSink",
|
|
|
|
&sdlvideosink_info, 0);
|
2003-10-28 09:08:32 +00:00
|
|
|
g_type_add_interface_static(sdlvideosink_type, GST_TYPE_INTERFACE,
|
|
|
|
&iface_info);
|
|
|
|
g_type_add_interface_static(sdlvideosink_type, GST_TYPE_X_OVERLAY,
|
|
|
|
&xoverlay_info);
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
2003-10-28 09:08:32 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
return sdlvideosink_type;
|
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static void
|
|
|
|
gst_sdlvideosink_dispose (GObject *obj)
|
|
|
|
{
|
|
|
|
g_mutex_free (GST_SDLVIDEOSINK (obj)->lock);
|
|
|
|
|
|
|
|
if (((GObjectClass *) parent_class)->dispose)
|
|
|
|
((GObjectClass *) parent_class)->dispose (obj);
|
|
|
|
}
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
static void
|
|
|
|
gst_sdlvideosink_class_init (GstSDLVideoSinkClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2003-09-14 21:09:41 +00:00
|
|
|
GstVideoSinkClass *gstvs_class;
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
gstelement_class = (GstElementClass*) klass;
|
|
|
|
gstvs_class = (GstVideoSinkClass*) klass;
|
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_sdlvideosink_set_property;
|
|
|
|
gobject_class->get_property = gst_sdlvideosink_get_property;
|
2003-10-28 09:08:32 +00:00
|
|
|
gobject_class->dispose = gst_sdlvideosink_dispose;
|
2001-12-20 23:21:15 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_sdlvideosink_change_state;
|
2002-02-03 20:10:03 +00:00
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
/*gstvs_class->set_video_out = gst_sdlvideosink_set_video_out;
|
|
|
|
gstvs_class->push_ui_event = gst_sdlvideosink_push_ui_event;
|
|
|
|
gstvs_class->set_geometry = gst_sdlvideosink_set_geometry;*/
|
2002-02-03 20:10:03 +00:00
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static GstBuffer *
|
|
|
|
gst_sdlvideosink_buffer_new (GstBufferPool *pool,
|
|
|
|
gint64 location,
|
|
|
|
guint size,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (user_data);
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
if (!sdlvideosink->overlay)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!gst_sdlvideosink_lock(sdlvideosink)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this protects the buffer from being written over multiple times */
|
|
|
|
g_mutex_lock (sdlvideosink->lock);
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_DONTFREE);
|
|
|
|
GST_BUFFER_DATA (buffer) = sdlvideosink->overlay->pixels[0];
|
|
|
|
if (sdlvideosink->format == SDL_YV12_OVERLAY ||
|
|
|
|
sdlvideosink->format == SDL_IYUV_OVERLAY) {
|
|
|
|
GST_BUFFER_SIZE (buffer) =
|
|
|
|
sdlvideosink->width * sdlvideosink->height * 3/2;
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_SIZE (buffer) =
|
|
|
|
sdlvideosink->width * sdlvideosink->height * 2;
|
|
|
|
}
|
|
|
|
GST_BUFFER_MAXSIZE (buffer) = GST_BUFFER_SIZE (buffer);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_sdlvideosink_buffer_free (GstBufferPool *pool,
|
|
|
|
GstBuffer *buffer,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (user_data);
|
|
|
|
|
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
|
|
|
gst_sdlvideosink_unlock(sdlvideosink);
|
|
|
|
|
|
|
|
gst_buffer_default_free (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstBufferPool *
|
|
|
|
gst_sdlvideosink_get_bufferpool (GstPad *pad)
|
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (sdlvideosink->overlay)
|
|
|
|
return sdlvideosink->bufferpool;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
static void
|
|
|
|
gst_sdlvideosink_init (GstSDLVideoSink *sdlvideosink)
|
|
|
|
{
|
2003-09-14 21:09:41 +00:00
|
|
|
GST_VIDEOSINK_PAD (sdlvideosink) = gst_pad_new_from_template (sink_template,
|
|
|
|
"sink");
|
2003-10-28 09:08:32 +00:00
|
|
|
gst_pad_set_bufferpool_function (GST_VIDEOSINK_PAD (sdlvideosink),
|
|
|
|
gst_sdlvideosink_get_bufferpool);
|
2003-09-14 21:09:41 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (sdlvideosink),
|
|
|
|
GST_VIDEOSINK_PAD (sdlvideosink));
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
gst_pad_set_chain_function (GST_VIDEOSINK_PAD (sdlvideosink),
|
|
|
|
gst_sdlvideosink_chain);
|
|
|
|
gst_pad_set_link_function (GST_VIDEOSINK_PAD (sdlvideosink),
|
|
|
|
gst_sdlvideosink_sinkconnect);
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->width = -1;
|
|
|
|
sdlvideosink->height = -1;
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->overlay = NULL;
|
2002-01-10 09:58:15 +00:00
|
|
|
sdlvideosink->screen = NULL;
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->xwindow_id = 0;
|
2002-01-10 09:58:15 +00:00
|
|
|
|
|
|
|
sdlvideosink->capslist = capslist;
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->init = FALSE;
|
|
|
|
|
|
|
|
sdlvideosink->lock = g_mutex_new ();
|
|
|
|
|
|
|
|
sdlvideosink->bufferpool = gst_buffer_pool_new (
|
|
|
|
NULL, /* free */
|
|
|
|
NULL, /* copy */
|
|
|
|
(GstBufferPoolBufferNewFunction) gst_sdlvideosink_buffer_new,
|
|
|
|
NULL, /* buffer copy, the default is fine */
|
|
|
|
(GstBufferPoolBufferFreeFunction) gst_sdlvideosink_buffer_free,
|
|
|
|
sdlvideosink);
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
GST_FLAG_SET(sdlvideosink, GST_ELEMENT_THREAD_SUGGESTED);
|
2002-05-26 21:59:21 +00:00
|
|
|
GST_FLAG_SET(sdlvideosink, GST_ELEMENT_EVENT_AWARE);
|
2002-01-10 09:58:15 +00:00
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static void
|
|
|
|
gst_sdlvideosink_interface_init (GstInterfaceClass *klass)
|
|
|
|
{
|
|
|
|
klass->supported = gst_sdlvideosink_interface_supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_sdlvideosink_interface_supported (GstInterface *interface,
|
|
|
|
GType iface_type)
|
|
|
|
{
|
|
|
|
g_assert (iface_type == GST_TYPE_X_OVERLAY);
|
|
|
|
|
|
|
|
/* FIXME: check SDL for whether it was compiled against X, FB, etc. */
|
|
|
|
return (GST_STATE (interface) != GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_sdlvideosink_xoverlay_init (GstXOverlayClass *klass)
|
|
|
|
{
|
|
|
|
klass->set_xwindow_id = gst_sdlvideosink_xoverlay_set_xwindow_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_sdlvideosink_xoverlay_set_xwindow_id (GstXOverlay *overlay, XID parent)
|
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (overlay);
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->xwindow_id = parent;
|
|
|
|
|
|
|
|
/* are we running yet? */
|
|
|
|
if (sdlvideosink->init) {
|
|
|
|
gboolean negotiated = (sdlvideosink->overlay != NULL);
|
|
|
|
|
|
|
|
if (negotiated)
|
|
|
|
gst_sdlvideosink_destroy (sdlvideosink);
|
|
|
|
|
|
|
|
gst_sdlvideosink_initsdl (sdlvideosink);
|
|
|
|
|
|
|
|
if (negotiated)
|
|
|
|
gst_sdlvideosink_create (sdlvideosink);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static guint32
|
2002-01-10 09:58:15 +00:00
|
|
|
gst_sdlvideosink_get_sdl_from_fourcc (GstSDLVideoSink *sdlvideosink,
|
2003-10-28 09:08:32 +00:00
|
|
|
guint32 code)
|
2002-01-10 09:58:15 +00:00
|
|
|
{
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case GST_MAKE_FOURCC('I','4','2','0'):
|
|
|
|
return SDL_IYUV_OVERLAY;
|
|
|
|
case GST_MAKE_FOURCC('Y','V','1','2'):
|
|
|
|
return SDL_YV12_OVERLAY;
|
|
|
|
case GST_MAKE_FOURCC('Y','U','Y','2'):
|
|
|
|
return SDL_YUY2_OVERLAY;
|
|
|
|
case GST_MAKE_FOURCC('U','Y','V','Y'):
|
|
|
|
return SDL_UYVY_OVERLAY;
|
|
|
|
case GST_MAKE_FOURCC('Y','V','Y','U'):
|
|
|
|
return SDL_YVYU_OVERLAY;
|
2003-10-28 09:08:32 +00:00
|
|
|
default:
|
2002-01-10 09:58:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
static gboolean
|
2002-02-04 19:36:21 +00:00
|
|
|
gst_sdlvideosink_lock (GstSDLVideoSink *sdlvideosink)
|
|
|
|
{
|
2003-10-28 09:08:32 +00:00
|
|
|
/* assure that we've got a screen */
|
|
|
|
if (!sdlvideosink->screen || !sdlvideosink->overlay) {
|
|
|
|
gst_element_error (GST_ELEMENT (sdlvideosink),
|
|
|
|
"Tried to lock screen without being set-up");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-02-04 19:36:21 +00:00
|
|
|
/* Lock SDL/yuv-overlay */
|
|
|
|
if (SDL_MUSTLOCK(sdlvideosink->screen))
|
|
|
|
{
|
|
|
|
if (SDL_LockSurface(sdlvideosink->screen) < 0)
|
|
|
|
{
|
2003-09-16 10:00:00 +00:00
|
|
|
gst_element_error(GST_ELEMENT(sdlvideosink),
|
|
|
|
"SDL: couldn\'t lock the SDL video window: %s", SDL_GetError());
|
2002-02-04 19:36:21 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2003-10-28 09:08:32 +00:00
|
|
|
if (SDL_LockYUVOverlay(sdlvideosink->overlay) < 0)
|
2002-02-04 19:36:21 +00:00
|
|
|
{
|
2003-09-16 10:00:00 +00:00
|
|
|
gst_element_error(GST_ELEMENT(sdlvideosink),
|
|
|
|
"SDL: couldn\'t lock the SDL YUV overlay: %s", SDL_GetError());
|
2002-02-04 19:36:21 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->init = TRUE;
|
|
|
|
|
2002-02-04 19:36:21 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_sdlvideosink_unlock (GstSDLVideoSink *sdlvideosink)
|
|
|
|
{
|
2003-10-28 09:08:32 +00:00
|
|
|
/* Unlock SDL_overlay */
|
|
|
|
SDL_UnlockYUVOverlay(sdlvideosink->overlay);
|
2002-02-04 19:36:21 +00:00
|
|
|
if (SDL_MUSTLOCK(sdlvideosink->screen))
|
|
|
|
SDL_UnlockSurface(sdlvideosink->screen);
|
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static void
|
|
|
|
gst_sdlvideosink_deinitsdl (GstSDLVideoSink *sdlvideosink)
|
|
|
|
{
|
|
|
|
if (sdlvideosink->init) {
|
|
|
|
SDL_Quit ();
|
|
|
|
sdlvideosink->init = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2002-02-04 19:36:21 +00:00
|
|
|
|
|
|
|
static gboolean
|
2003-10-28 09:08:32 +00:00
|
|
|
gst_sdlvideosink_initsdl (GstSDLVideoSink *sdlvideosink)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
2003-10-28 09:08:32 +00:00
|
|
|
gst_sdlvideosink_deinitsdl (sdlvideosink);
|
|
|
|
|
|
|
|
if (!sdlvideosink->xwindow_id) {
|
|
|
|
unsetenv("SDL_WINDOWID");
|
|
|
|
} else {
|
|
|
|
char SDL_hack[32];
|
|
|
|
sprintf(SDL_hack, "%lu", sdlvideosink->xwindow_id);
|
|
|
|
setenv("SDL_WINDOWID", SDL_hack, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the SDL library */
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0 ) {
|
|
|
|
gst_element_error(GST_ELEMENT (sdlvideosink),
|
|
|
|
"Couldn't initialize SDL: %s",
|
|
|
|
SDL_GetError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_sdlvideosink_destroy (GstSDLVideoSink *sdlvideosink)
|
|
|
|
{
|
|
|
|
if (sdlvideosink->overlay) {
|
|
|
|
SDL_FreeYUVOverlay(sdlvideosink->overlay);
|
|
|
|
sdlvideosink->overlay = NULL;
|
|
|
|
}
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
if (sdlvideosink->screen) {
|
|
|
|
SDL_FreeSurface (sdlvideosink->screen);
|
|
|
|
sdlvideosink->screen = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_sdlvideosink_create (GstSDLVideoSink *sdlvideosink)
|
|
|
|
{
|
2003-09-14 21:09:41 +00:00
|
|
|
if (GST_VIDEOSINK_HEIGHT (sdlvideosink) <= 0)
|
2003-10-28 09:08:32 +00:00
|
|
|
GST_VIDEOSINK_HEIGHT (sdlvideosink) = sdlvideosink->height;
|
2003-09-14 21:09:41 +00:00
|
|
|
if (GST_VIDEOSINK_WIDTH (sdlvideosink) <= 0)
|
2003-10-28 09:08:32 +00:00
|
|
|
GST_VIDEOSINK_WIDTH (sdlvideosink) = sdlvideosink->width;
|
|
|
|
|
|
|
|
gst_sdlvideosink_destroy (sdlvideosink);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
/* create a SDL window of the size requested by the user */
|
2003-09-14 21:09:41 +00:00
|
|
|
sdlvideosink->screen = SDL_SetVideoMode(GST_VIDEOSINK_WIDTH (sdlvideosink),
|
2003-10-28 09:08:32 +00:00
|
|
|
GST_VIDEOSINK_HEIGHT (sdlvideosink), 0, SDL_HWSURFACE | SDL_RESIZABLE);
|
|
|
|
if (sdlvideosink->screen == NULL)
|
2002-01-10 09:58:15 +00:00
|
|
|
{
|
2003-09-16 10:00:00 +00:00
|
|
|
gst_element_error(GST_ELEMENT(sdlvideosink),
|
|
|
|
"SDL: Couldn't set %dx%d: %s", GST_VIDEOSINK_WIDTH (sdlvideosink),
|
|
|
|
GST_VIDEOSINK_HEIGHT (sdlvideosink), SDL_GetError());
|
2002-01-15 15:52:09 +00:00
|
|
|
return FALSE;
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
/* create a new YUV overlay */
|
|
|
|
sdlvideosink->overlay = SDL_CreateYUVOverlay(sdlvideosink->width,
|
|
|
|
sdlvideosink->height, sdlvideosink->format, sdlvideosink->screen);
|
|
|
|
if ( sdlvideosink->overlay == NULL )
|
2002-01-10 09:58:15 +00:00
|
|
|
{
|
2003-09-16 10:00:00 +00:00
|
|
|
gst_element_error(GST_ELEMENT(sdlvideosink),
|
2003-10-28 09:08:32 +00:00
|
|
|
"SDL: Couldn't create SDL YUV overlay (%dx%d \'" GST_FOURCC_FORMAT "\'): %s",
|
|
|
|
sdlvideosink->width, sdlvideosink->height,
|
2003-09-16 10:00:00 +00:00
|
|
|
GST_FOURCC_ARGS(sdlvideosink->format), SDL_GetError());
|
2002-01-15 15:52:09 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-10-28 09:08:32 +00:00
|
|
|
GST_DEBUG("Using a %dx%d %dbpp SDL screen with a %dx%d \'" GST_FOURCC_FORMAT "\' YUV overlay",
|
2003-09-14 21:09:41 +00:00
|
|
|
GST_VIDEOSINK_WIDTH (sdlvideosink), GST_VIDEOSINK_HEIGHT (sdlvideosink),
|
2002-01-15 15:52:09 +00:00
|
|
|
sdlvideosink->screen->format->BitsPerPixel,
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->width, sdlvideosink->height,
|
2003-04-07 20:47:30 +00:00
|
|
|
GST_FOURCC_ARGS(sdlvideosink->format));
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sdlvideosink->rect.x = 0;
|
|
|
|
sdlvideosink->rect.y = 0;
|
2003-09-14 21:09:41 +00:00
|
|
|
sdlvideosink->rect.w = GST_VIDEOSINK_WIDTH (sdlvideosink);
|
|
|
|
sdlvideosink->rect.h = GST_VIDEOSINK_HEIGHT (sdlvideosink);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
SDL_DisplayYUVOverlay(sdlvideosink->overlay, &(sdlvideosink->rect));
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
GST_DEBUG ("sdlvideosink: setting %08x (" GST_FOURCC_FORMAT ")",
|
|
|
|
sdlvideosink->format, GST_FOURCC_ARGS(sdlvideosink->format));
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
gst_video_sink_got_video_size (GST_VIDEOSINK (sdlvideosink),
|
|
|
|
GST_VIDEOSINK_WIDTH (sdlvideosink),
|
|
|
|
GST_VIDEOSINK_HEIGHT (sdlvideosink));
|
2002-01-15 15:52:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-15 15:52:09 +00:00
|
|
|
gst_sdlvideosink_sinkconnect (GstPad *pad,
|
|
|
|
GstCaps *vscapslist)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
2002-01-10 09:58:15 +00:00
|
|
|
GstSDLVideoSink *sdlvideosink;
|
2002-01-15 15:52:09 +00:00
|
|
|
GstCaps *caps;
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK (gst_pad_get_parent (pad));
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2002-01-15 23:01:32 +00:00
|
|
|
/* we are not going to act on variable caps */
|
|
|
|
if (!GST_CAPS_IS_FIXED (vscapslist))
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
2002-01-15 23:01:32 +00:00
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
for (caps = vscapslist; caps != NULL; caps = vscapslist = vscapslist->next)
|
2002-01-10 09:58:15 +00:00
|
|
|
{
|
2002-03-30 17:06:26 +00:00
|
|
|
guint32 format;
|
|
|
|
|
|
|
|
gst_caps_get_fourcc_int(caps, "format", &format);
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->format =
|
|
|
|
gst_sdlvideosink_get_sdl_from_fourcc (sdlvideosink, format);
|
|
|
|
gst_caps_get_int(caps, "width", &sdlvideosink->width);
|
|
|
|
gst_caps_get_int(caps, "height", &sdlvideosink->height);
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
/* try it out */
|
|
|
|
if (!sdlvideosink->format ||
|
|
|
|
!gst_sdlvideosink_create(sdlvideosink))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return GST_PAD_LINK_OK;
|
2002-01-10 09:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we got here - it's not good */
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
static void
|
2003-10-08 16:08:19 +00:00
|
|
|
gst_sdlvideosink_chain (GstPad *pad, GstData *_data)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
2003-10-08 16:08:19 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-20 23:21:15 +00:00
|
|
|
GstSDLVideoSink *sdlvideosink;
|
2002-05-26 21:59:21 +00:00
|
|
|
SDL_Event sdl_event;
|
2001-12-20 23:21:15 +00:00
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
|
|
|
sdlvideosink = GST_SDLVIDEOSINK (gst_pad_get_parent (pad));
|
|
|
|
|
2002-05-26 21:59:21 +00:00
|
|
|
if (GST_IS_EVENT (buf)) {
|
|
|
|
GstEvent *event = GST_EVENT (buf);
|
|
|
|
gint64 offset;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
|
|
offset = GST_EVENT_DISCONT_OFFSET (event, 0).value;
|
2003-10-28 09:08:32 +00:00
|
|
|
/*gst_clock_handle_discont (sdlvideosink->clock,
|
|
|
|
(guint64) GST_EVENT_DISCONT_OFFSET (event, 0).value);*/
|
2002-05-26 21:59:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gst_pad_event_default (pad, event);
|
2002-08-02 11:32:37 +00:00
|
|
|
return;
|
2002-05-26 21:59:21 +00:00
|
|
|
}
|
2002-07-08 19:36:32 +00:00
|
|
|
gst_event_unref (event);
|
2002-05-26 21:59:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
if (GST_VIDEOSINK_CLOCK (sdlvideosink)) {
|
|
|
|
GstClockID id = gst_clock_new_single_shot_id (
|
|
|
|
GST_VIDEOSINK_CLOCK (sdlvideosink),
|
|
|
|
GST_BUFFER_TIMESTAMP (buf));
|
2002-12-27 23:00:34 +00:00
|
|
|
|
|
|
|
gst_element_clock_wait (GST_ELEMENT (sdlvideosink), id, NULL);
|
|
|
|
gst_clock_id_free (id);
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
if (GST_BUFFER_DATA (buf) != sdlvideosink->overlay->pixels[0]) {
|
|
|
|
if (!gst_sdlvideosink_lock(sdlvideosink)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
/* buf->yuv - FIXME: bufferpool! */
|
|
|
|
if (sdlvideosink->format == SDL_IYUV_OVERLAY ||
|
|
|
|
sdlvideosink->format == SDL_YV12_OVERLAY)
|
|
|
|
{
|
|
|
|
memcpy (sdlvideosink->overlay->pixels[0], GST_BUFFER_DATA (buf),
|
|
|
|
sdlvideosink->width * sdlvideosink->height);
|
|
|
|
memcpy (sdlvideosink->overlay->pixels[1],
|
|
|
|
GST_BUFFER_DATA (buf) + sdlvideosink->width*sdlvideosink->height,
|
|
|
|
sdlvideosink->width * sdlvideosink->height / 4);
|
|
|
|
memcpy (sdlvideosink->overlay->pixels[2],
|
|
|
|
GST_BUFFER_DATA (buf) + sdlvideosink->width*sdlvideosink->height*5/4,
|
|
|
|
sdlvideosink->width * sdlvideosink->height / 4);
|
|
|
|
} else {
|
|
|
|
memcpy (sdlvideosink->overlay->pixels[0], GST_BUFFER_DATA (buf),
|
|
|
|
sdlvideosink->width * sdlvideosink->height * 2);
|
|
|
|
}
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
gst_sdlvideosink_unlock(sdlvideosink);
|
|
|
|
}
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
gst_buffer_unref(buf);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
|
|
|
/* Show, baby, show! */
|
2003-10-28 09:08:32 +00:00
|
|
|
SDL_DisplayYUVOverlay(sdlvideosink->overlay, &(sdlvideosink->rect));
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
gst_video_sink_frame_displayed (GST_VIDEOSINK (sdlvideosink));
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
while (SDL_PollEvent(&sdl_event))
|
|
|
|
{
|
|
|
|
switch(sdl_event.type)
|
|
|
|
{
|
|
|
|
case SDL_VIDEORESIZE:
|
|
|
|
/* create a SDL window of the size requested by the user */
|
|
|
|
GST_VIDEOSINK_WIDTH (sdlvideosink) = sdl_event.resize.w;
|
|
|
|
GST_VIDEOSINK_HEIGHT (sdlvideosink) = sdl_event.resize.h;
|
|
|
|
gst_sdlvideosink_create(sdlvideosink);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_sdlvideosink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_SDLVIDEOSINK (object));
|
2002-01-10 10:03:33 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK(object);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2002-01-17 12:41:05 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2002-01-10 09:58:15 +00:00
|
|
|
}
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
static void
|
|
|
|
gst_sdlvideosink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2002-01-10 10:03:33 +00:00
|
|
|
g_return_if_fail (GST_IS_SDLVIDEOSINK (object));
|
2001-12-20 23:21:15 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-01-10 09:58:15 +00:00
|
|
|
default:
|
2002-01-17 12:41:05 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-20 23:21:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_sdlvideosink_change_state (GstElement *element)
|
|
|
|
{
|
2002-01-10 09:58:15 +00:00
|
|
|
GstSDLVideoSink *sdlvideosink;
|
2001-12-20 23:21:15 +00:00
|
|
|
g_return_val_if_fail (GST_IS_SDLVIDEOSINK (element), GST_STATE_FAILURE);
|
2002-01-10 09:58:15 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK(element);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element))
|
|
|
|
{
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
2003-10-28 09:08:32 +00:00
|
|
|
if (!gst_sdlvideosink_initsdl (sdlvideosink))
|
2001-12-20 23:21:15 +00:00
|
|
|
return GST_STATE_FAILURE;
|
2002-01-10 09:58:15 +00:00
|
|
|
GST_FLAG_SET (sdlvideosink, GST_SDLVIDEOSINK_OPEN);
|
|
|
|
break;
|
2003-10-28 09:08:32 +00:00
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
gst_sdlvideosink_destroy (sdlvideosink);
|
|
|
|
break;
|
2002-01-15 23:01:32 +00:00
|
|
|
case GST_STATE_READY_TO_NULL:
|
2003-10-28 09:08:32 +00:00
|
|
|
gst_sdlvideosink_deinitsdl (sdlvideosink);
|
2002-01-10 09:58:15 +00:00
|
|
|
GST_FLAG_UNSET (sdlvideosink, GST_SDLVIDEOSINK_OPEN);
|
|
|
|
break;
|
|
|
|
default: /* do nothing */
|
|
|
|
break;
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
2002-01-10 09:58:15 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
gint i;
|
|
|
|
gulong format[6] = { GST_MAKE_FOURCC('I','4','2','0'),
|
|
|
|
GST_MAKE_FOURCC('Y','V','1','2'),
|
|
|
|
GST_MAKE_FOURCC('Y','U','Y','2'),
|
|
|
|
GST_MAKE_FOURCC('Y','V','Y','U'),
|
|
|
|
GST_MAKE_FOURCC('U','Y','V','Y')
|
|
|
|
};
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
/* Loading the library containing GstVideoSink, our parent object */
|
|
|
|
if (!gst_library_load ("gstvideo"))
|
|
|
|
return FALSE;
|
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
/* create an elementfactory for the sdlvideosink element */
|
2002-04-11 20:42:26 +00:00
|
|
|
factory = gst_element_factory_new("sdlvideosink",GST_TYPE_SDLVIDEOSINK,
|
2001-12-20 23:21:15 +00:00
|
|
|
&gst_sdlvideosink_details);
|
|
|
|
g_return_val_if_fail(factory != NULL, FALSE);
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
/* make a list of all available caps */
|
2003-07-06 20:49:52 +00:00
|
|
|
for (i=0;i<5;i++)
|
2002-01-10 09:58:15 +00:00
|
|
|
{
|
|
|
|
caps = gst_caps_new ("sdlvideosink_caps",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-yuv",
|
2002-01-10 09:58:15 +00:00
|
|
|
gst_props_new (
|
|
|
|
"format", GST_PROPS_FOURCC(format[i]),
|
|
|
|
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
2003-07-06 20:49:52 +00:00
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT),
|
2002-01-10 09:58:15 +00:00
|
|
|
NULL )
|
|
|
|
);
|
|
|
|
capslist = gst_caps_append(capslist, caps);
|
|
|
|
}
|
|
|
|
|
2002-04-11 20:42:26 +00:00
|
|
|
sink_template = gst_pad_template_new (
|
2002-01-10 09:58:15 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
capslist, NULL);
|
|
|
|
|
2002-04-11 20:42:26 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, sink_template);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"sdlvideosink",
|
|
|
|
plugin_init
|
|
|
|
};
|