gstreamer/ext/sdl/sdlvideosink.c

722 lines
20 KiB
C
Raw Normal View History

/* GStreamer SDL plugin
* Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
*
* 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 ;-) */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <signal.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
#include <gst/interfaces/xoverlay.h>
#include "sdlvideosink.h"
/* elementfactory information */
static GstElementDetails gst_sdlvideosink_details = {
"Video sink",
"Sink/Video",
"An SDL-based videosink",
"Ronald Bultje <rbultje@ronald.bitfreak.net>",
};
static void gst_sdlvideosink_base_init (gpointer g_class);
static void gst_sdlvideosink_class_init (GstSDLVideoSinkClass * klass);
static void gst_sdlvideosink_init (GstSDLVideoSink * sdl);
static void gst_sdlvideosink_interface_init (GstImplementsInterfaceClass *
klass);
static gboolean gst_sdlvideosink_supported (GstImplementsInterface * iface,
GType type);
static void gst_sdlvideosink_xoverlay_init (GstXOverlayClass * klass);
static void gst_sdlvideosink_xoverlay_set_xwindow_id
(GstXOverlay * overlay, unsigned long 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);
static gboolean gst_sdlvideosink_create (GstSDLVideoSink * sdl);
static void gst_sdlvideosink_destroy (GstSDLVideoSink * sdl);
static gboolean gst_sdlvideosink_setcaps (GstBaseSink * bsink, GstCaps * caps);
static GstFlowReturn gst_sdlvideosink_show_frame (GstBaseSink * bsink,
GstBuffer * buff);
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 GstStateChangeReturn
gst_sdlvideosink_change_state (GstElement * element, GstStateChange transition);
static GstPadTemplate *sink_template;
static GstElementClass *parent_class = NULL;
GType
gst_sdlvideosink_get_type (void)
{
static GType sdlvideosink_type = 0;
if (!sdlvideosink_type) {
static const GTypeInfo sdlvideosink_info = {
sizeof (GstSDLVideoSinkClass),
gst_sdlvideosink_base_init,
NULL,
(GClassInitFunc) gst_sdlvideosink_class_init,
NULL,
NULL,
sizeof (GstSDLVideoSink),
0,
(GInstanceInitFunc) gst_sdlvideosink_init,
};
static const GInterfaceInfo iface_info = {
(GInterfaceInitFunc) gst_sdlvideosink_interface_init,
NULL,
NULL,
};
static const GInterfaceInfo xoverlay_info = {
(GInterfaceInitFunc) gst_sdlvideosink_xoverlay_init,
NULL,
NULL,
};
sdlvideosink_type = g_type_register_static (GST_TYPE_VIDEO_SINK,
"GstSDLVideoSink", &sdlvideosink_info, 0);
g_type_add_interface_static (sdlvideosink_type,
GST_TYPE_IMPLEMENTS_INTERFACE, &iface_info);
g_type_add_interface_static (sdlvideosink_type, GST_TYPE_X_OVERLAY,
&xoverlay_info);
}
return sdlvideosink_type;
}
static void
gst_sdlvideosink_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GstCaps *capslist;
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')
};
/* make a list of all available caps */
capslist = gst_caps_new_empty ();
for (i = 0; i < 5; i++) {
gst_caps_append_structure (capslist,
gst_structure_new ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, format[i],
"width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
"framerate", GST_TYPE_DOUBLE_RANGE, 1.0, 100.0, NULL));
}
sink_template = gst_pad_template_new ("sink",
GST_PAD_SINK, GST_PAD_ALWAYS, capslist);
gst_element_class_add_pad_template (element_class, sink_template);
gst_element_class_set_details (element_class, &gst_sdlvideosink_details);
}
static void
Fixes a bunch of problems with finalize and dispose functions, either assumptions that dispose is only called once, o... Original commit message from CVS: * ext/alsa/gstalsa.c: (gst_alsa_class_init), (gst_alsa_dispose), (gst_alsa_finalize): * ext/cdaudio/gstcdaudio.c: (gst_cdaudio_class_init), (gst_cdaudio_finalize): * ext/cdparanoia/gstcdparanoia.c: (cdparanoia_class_init), (cdparanoia_finalize): * ext/divx/gstdivxdec.c: (gst_divxdec_dispose): * ext/divx/gstdivxenc.c: (gst_divxenc_dispose): * ext/dvdread/dvdreadsrc.c: (dvdreadsrc_class_init), (dvdreadsrc_finalize): * ext/flac/gstflacdec.c: (gst_flacdec_class_init), (gst_flacdec_finalize): * ext/flac/gstflacenc.c: (gst_flacenc_class_init), (gst_flacenc_finalize): * ext/gnomevfs/gstgnomevfssink.c: (gst_gnomevfssink_class_init), (gst_gnomevfssink_finalize): * ext/gnomevfs/gstgnomevfssrc.c: (gst_gnomevfssrc_class_init), (gst_gnomevfssrc_finalize): * ext/libfame/gstlibfame.c: (gst_fameenc_class_init), (gst_fameenc_finalize): * ext/nas/nassink.c: (gst_nassink_class_init), (gst_nassink_finalize): * ext/sdl/sdlvideosink.c: (gst_sdlvideosink_finalize), (gst_sdlvideosink_class_init): * ext/sndfile/gstsf.c: (gst_sf_dispose): * gst-libs/gst/mixer/mixertrack.c: (gst_mixer_track_dispose): * gst-libs/gst/tuner/tunerchannel.c: (gst_tuner_channel_dispose): * gst-libs/gst/tuner/tunernorm.c: (gst_tuner_norm_dispose): * gst-libs/gst/xwindowlistener/xwindowlistener.c: (gst_x_window_listener_dispose): * gst/audioscale/gstaudioscale.c: * gst/playondemand/gstplayondemand.c: (play_on_demand_class_init), (play_on_demand_finalize): * gst/videofilter/gstvideobalance.c: (gst_videobalance_dispose): * gst/videoscale/gstvideoscale.c: (gst_videoscale_chain): * sys/cdrom/gstcdplayer.c: (cdplayer_class_init), (cdplayer_finalize): * sys/glsink/glimagesink.c: (gst_glimagesink_finalize), (gst_glimagesink_class_init): * sys/oss/gstosselement.c: (gst_osselement_class_init), (gst_osselement_finalize): * sys/oss/gstosssink.c: (gst_osssink_dispose): * sys/oss/gstosssrc.c: (gst_osssrc_dispose): * sys/v4l/gstv4lelement.c: (gst_v4lelement_dispose): Fixes a bunch of problems with finalize and dispose functions, either assumptions that dispose is only called once, or not calling the parent class dispose/finalize function
2004-11-01 14:43:38 +00:00
gst_sdlvideosink_finalize (GObject * obj)
{
g_mutex_free (GST_SDLVIDEOSINK (obj)->lock);
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
static void
gst_sdlvideosink_get_times (GstBaseSink * basesink, GstBuffer * buffer,
GstClockTime * start, GstClockTime * end)
{
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (basesink);
GstClockTime timestamp, duration;
timestamp = GST_BUFFER_TIMESTAMP (buffer);
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
*start = timestamp;
duration = GST_BUFFER_DURATION (buffer);
if (GST_CLOCK_TIME_IS_VALID (duration)) {
*end = timestamp + duration;
} else {
if (sdlvideosink->framerate > 0) {
*end = timestamp + GST_SECOND / sdlvideosink->framerate;
}
}
}
}
static void
gst_sdlvideosink_class_init (GstSDLVideoSinkClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
GstBaseSinkClass *gstvs_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
gstvs_class = (GstBaseSinkClass *) klass;
parent_class = g_type_class_ref (GST_TYPE_BASE_SINK);
gobject_class->set_property = gst_sdlvideosink_set_property;
gobject_class->get_property = gst_sdlvideosink_get_property;
Fixes a bunch of problems with finalize and dispose functions, either assumptions that dispose is only called once, o... Original commit message from CVS: * ext/alsa/gstalsa.c: (gst_alsa_class_init), (gst_alsa_dispose), (gst_alsa_finalize): * ext/cdaudio/gstcdaudio.c: (gst_cdaudio_class_init), (gst_cdaudio_finalize): * ext/cdparanoia/gstcdparanoia.c: (cdparanoia_class_init), (cdparanoia_finalize): * ext/divx/gstdivxdec.c: (gst_divxdec_dispose): * ext/divx/gstdivxenc.c: (gst_divxenc_dispose): * ext/dvdread/dvdreadsrc.c: (dvdreadsrc_class_init), (dvdreadsrc_finalize): * ext/flac/gstflacdec.c: (gst_flacdec_class_init), (gst_flacdec_finalize): * ext/flac/gstflacenc.c: (gst_flacenc_class_init), (gst_flacenc_finalize): * ext/gnomevfs/gstgnomevfssink.c: (gst_gnomevfssink_class_init), (gst_gnomevfssink_finalize): * ext/gnomevfs/gstgnomevfssrc.c: (gst_gnomevfssrc_class_init), (gst_gnomevfssrc_finalize): * ext/libfame/gstlibfame.c: (gst_fameenc_class_init), (gst_fameenc_finalize): * ext/nas/nassink.c: (gst_nassink_class_init), (gst_nassink_finalize): * ext/sdl/sdlvideosink.c: (gst_sdlvideosink_finalize), (gst_sdlvideosink_class_init): * ext/sndfile/gstsf.c: (gst_sf_dispose): * gst-libs/gst/mixer/mixertrack.c: (gst_mixer_track_dispose): * gst-libs/gst/tuner/tunerchannel.c: (gst_tuner_channel_dispose): * gst-libs/gst/tuner/tunernorm.c: (gst_tuner_norm_dispose): * gst-libs/gst/xwindowlistener/xwindowlistener.c: (gst_x_window_listener_dispose): * gst/audioscale/gstaudioscale.c: * gst/playondemand/gstplayondemand.c: (play_on_demand_class_init), (play_on_demand_finalize): * gst/videofilter/gstvideobalance.c: (gst_videobalance_dispose): * gst/videoscale/gstvideoscale.c: (gst_videoscale_chain): * sys/cdrom/gstcdplayer.c: (cdplayer_class_init), (cdplayer_finalize): * sys/glsink/glimagesink.c: (gst_glimagesink_finalize), (gst_glimagesink_class_init): * sys/oss/gstosselement.c: (gst_osselement_class_init), (gst_osselement_finalize): * sys/oss/gstosssink.c: (gst_osssink_dispose): * sys/oss/gstosssrc.c: (gst_osssrc_dispose): * sys/v4l/gstv4lelement.c: (gst_v4lelement_dispose): Fixes a bunch of problems with finalize and dispose functions, either assumptions that dispose is only called once, or not calling the parent class dispose/finalize function
2004-11-01 14:43:38 +00:00
gobject_class->finalize = gst_sdlvideosink_finalize;
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_sdlvideosink_change_state);
gstvs_class->set_caps = GST_DEBUG_FUNCPTR (gst_sdlvideosink_setcaps);
gstvs_class->get_times = GST_DEBUG_FUNCPTR (gst_sdlvideosink_get_times);
gstvs_class->preroll = GST_DEBUG_FUNCPTR (gst_sdlvideosink_show_frame);
gstvs_class->render = GST_DEBUG_FUNCPTR (gst_sdlvideosink_show_frame);
/*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; */
}
#if 0
/* FIXME */
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;
}
#endif
static void
gst_sdlvideosink_init (GstSDLVideoSink * sdlvideosink)
{
sdlvideosink->width = -1;
sdlvideosink->height = -1;
sdlvideosink->framerate = 0;
sdlvideosink->overlay = NULL;
sdlvideosink->screen = NULL;
sdlvideosink->xwindow_id = 0;
//sdlvideosink->capslist = capslist;
sdlvideosink->init = FALSE;
sdlvideosink->lock = g_mutex_new ();
}
static void
gst_sdlvideosink_interface_init (GstImplementsInterfaceClass * klass)
{
klass->supported = gst_sdlvideosink_supported;
}
static gboolean
gst_sdlvideosink_supported (GstImplementsInterface * 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,
unsigned long parent)
{
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (overlay);
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
gst_sdlvideosink_get_sdl_from_fourcc (GstSDLVideoSink * sdlvideosink,
guint32 code)
{
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;
default:
return 0;
}
}
static gboolean
gst_sdlvideosink_lock (GstSDLVideoSink * sdlvideosink)
{
/* assure that we've got a screen */
if (!sdlvideosink->screen || !sdlvideosink->overlay)
goto no_setup;
/* Lock SDL/yuv-overlay */
if (SDL_MUSTLOCK (sdlvideosink->screen)) {
if (SDL_LockSurface (sdlvideosink->screen) < 0)
goto could_not_lock;
}
if (SDL_LockYUVOverlay (sdlvideosink->overlay) < 0)
goto lock_yuv;
sdlvideosink->init = TRUE;
return TRUE;
/* ERRORS */
no_setup:
{
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
("Tried to lock screen without being set-up"));
return FALSE;
}
could_not_lock:
{
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
("SDL: couldn't lock the SDL video window: %s", SDL_GetError ()));
return FALSE;
}
lock_yuv:
{
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
("SDL: couldn\'t lock the SDL YUV overlay: %s", SDL_GetError ()));
return FALSE;
}
}
static void
gst_sdlvideosink_unlock (GstSDLVideoSink * sdlvideosink)
{
/* Unlock SDL_overlay */
SDL_UnlockYUVOverlay (sdlvideosink->overlay);
if (SDL_MUSTLOCK (sdlvideosink->screen))
SDL_UnlockSurface (sdlvideosink->screen);
}
static void
gst_sdlvideosink_deinitsdl (GstSDLVideoSink * sdlvideosink)
{
g_mutex_lock (sdlvideosink->lock);
if (sdlvideosink->init) {
SDL_Quit ();
sdlvideosink->init = FALSE;
}
g_mutex_unlock (sdlvideosink->lock);
}
static gboolean
gst_sdlvideosink_initsdl (GstSDLVideoSink * sdlvideosink)
{
gst_sdlvideosink_deinitsdl (sdlvideosink);
g_mutex_lock (sdlvideosink->lock);
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)
goto init_failed;
sdlvideosink->init = TRUE;
g_mutex_unlock (sdlvideosink->lock);
return TRUE;
/* ERRORS */
init_failed:
{
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, INIT, (NULL),
("Couldn't initialize SDL: %s", SDL_GetError ()));
g_mutex_unlock (sdlvideosink->lock);
return FALSE;
}
}
static void
gst_sdlvideosink_destroy (GstSDLVideoSink * sdlvideosink)
{
g_mutex_lock (sdlvideosink->lock);
if (sdlvideosink->overlay) {
SDL_FreeYUVOverlay (sdlvideosink->overlay);
sdlvideosink->overlay = NULL;
}
if (sdlvideosink->screen) {
SDL_FreeSurface (sdlvideosink->screen);
sdlvideosink->screen = NULL;
}
g_mutex_unlock (sdlvideosink->lock);
}
static gboolean
gst_sdlvideosink_create (GstSDLVideoSink * sdlvideosink)
{
if (GST_VIDEO_SINK_HEIGHT (sdlvideosink) <= 0)
GST_VIDEO_SINK_HEIGHT (sdlvideosink) = sdlvideosink->height;
if (GST_VIDEO_SINK_WIDTH (sdlvideosink) <= 0)
GST_VIDEO_SINK_WIDTH (sdlvideosink) = sdlvideosink->width;
gst_sdlvideosink_destroy (sdlvideosink);
g_mutex_lock (sdlvideosink->lock);
/* create a SDL window of the size requested by the user */
sdlvideosink->screen = SDL_SetVideoMode (GST_VIDEO_SINK_WIDTH (sdlvideosink),
GST_VIDEO_SINK_HEIGHT (sdlvideosink), 0, SDL_HWSURFACE | SDL_RESIZABLE);
if (sdlvideosink->screen == NULL)
goto no_screen;
/* create a new YUV overlay */
sdlvideosink->overlay = SDL_CreateYUVOverlay (sdlvideosink->width,
sdlvideosink->height, sdlvideosink->format, sdlvideosink->screen);
if (sdlvideosink->overlay == NULL)
goto no_overlay;
GST_DEBUG ("Using a %dx%d %dbpp SDL screen with a %dx%d \'"
GST_FOURCC_FORMAT "\' YUV overlay", GST_VIDEO_SINK_WIDTH (sdlvideosink),
GST_VIDEO_SINK_HEIGHT (sdlvideosink),
sdlvideosink->screen->format->BitsPerPixel, sdlvideosink->width,
sdlvideosink->height, GST_FOURCC_ARGS (sdlvideosink->format));
sdlvideosink->rect.x = 0;
sdlvideosink->rect.y = 0;
sdlvideosink->rect.w = GST_VIDEO_SINK_WIDTH (sdlvideosink);
sdlvideosink->rect.h = GST_VIDEO_SINK_HEIGHT (sdlvideosink);
/*SDL_DisplayYUVOverlay (sdlvideosink->overlay, &(sdlvideosink->rect)); */
GST_DEBUG ("sdlvideosink: setting %08x (" GST_FOURCC_FORMAT ")",
sdlvideosink->format, GST_FOURCC_ARGS (sdlvideosink->format));
g_mutex_unlock (sdlvideosink->lock);
return TRUE;
/* ERRORS */
no_screen:
{
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
("SDL: Couldn't set %dx%d: %s", GST_VIDEO_SINK_WIDTH (sdlvideosink),
GST_VIDEO_SINK_HEIGHT (sdlvideosink), SDL_GetError ()));
g_mutex_unlock (sdlvideosink->lock);
return FALSE;
}
no_overlay:
{
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
("SDL: Couldn't create SDL YUV overlay (%dx%d \'" GST_FOURCC_FORMAT
"\'): %s", sdlvideosink->width, sdlvideosink->height,
GST_FOURCC_ARGS (sdlvideosink->format), SDL_GetError ()));
g_mutex_unlock (sdlvideosink->lock);
return FALSE;
}
}
static gboolean
gst_sdlvideosink_setcaps (GstBaseSink * bsink, GstCaps * vscapslist)
{
GstSDLVideoSink *sdlvideosink;
guint32 format;
GstStructure *structure;
sdlvideosink = GST_SDLVIDEOSINK (bsink);
structure = gst_caps_get_structure (vscapslist, 0);
gst_structure_get_fourcc (structure, "format", &format);
sdlvideosink->format =
gst_sdlvideosink_get_sdl_from_fourcc (sdlvideosink, format);
gst_structure_get_int (structure, "width", &sdlvideosink->width);
gst_structure_get_int (structure, "height", &sdlvideosink->height);
gst_structure_get_double (structure, "framerate", &sdlvideosink->framerate);
if (!sdlvideosink->format || !gst_sdlvideosink_create (sdlvideosink))
return FALSE;
gst_x_overlay_got_desired_size (GST_X_OVERLAY (sdlvideosink),
sdlvideosink->width, sdlvideosink->height);
return TRUE;
}
static GstFlowReturn
gst_sdlvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
{
GstSDLVideoSink *sdlvideosink;
SDL_Event sdl_event;
sdlvideosink = GST_SDLVIDEOSINK (bsink);
if (!sdlvideosink->init ||
!sdlvideosink->overlay || !sdlvideosink->overlay->pixels)
goto not_init;
if (GST_BUFFER_DATA (buf) != sdlvideosink->overlay->pixels[0]) {
if (!gst_sdlvideosink_lock (sdlvideosink))
goto cannot_lock;
/* 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);
}
gst_sdlvideosink_unlock (sdlvideosink);
}
/* Show, baby, show! */
SDL_DisplayYUVOverlay (sdlvideosink->overlay, &(sdlvideosink->rect));
while (SDL_PollEvent (&sdl_event)) {
switch (sdl_event.type) {
case SDL_VIDEORESIZE:
/* create a SDL window of the size requested by the user */
GST_VIDEO_SINK_WIDTH (sdlvideosink) = sdl_event.resize.w;
GST_VIDEO_SINK_HEIGHT (sdlvideosink) = sdl_event.resize.h;
gst_sdlvideosink_create (sdlvideosink);
break;
}
}
return GST_FLOW_OK;
/* ERRORS */
not_init:
{
GST_ELEMENT_ERROR (sdlvideosink, CORE, NEGOTIATION, (NULL),
("not negotiated."));
return GST_FLOW_NOT_NEGOTIATED;
}
cannot_lock:
{
/* lock function posted detailed message */
return GST_FLOW_ERROR;
}
}
static void
gst_sdlvideosink_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstSDLVideoSink *sdlvideosink;
sdlvideosink = GST_SDLVIDEOSINK (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_sdlvideosink_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstSDLVideoSink *sdlvideosink;
sdlvideosink = GST_SDLVIDEOSINK (object);
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GstStateChangeReturn
gst_sdlvideosink_change_state (GstElement * element, GstStateChange transition)
{
GstSDLVideoSink *sdlvideosink;
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
g_return_val_if_fail (GST_IS_SDLVIDEOSINK (element),
GST_STATE_CHANGE_FAILURE);
sdlvideosink = GST_SDLVIDEOSINK (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (!gst_sdlvideosink_initsdl (sdlvideosink))
goto init_failed;
renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition Original commit message from CVS: * examples/indexing/indexmpeg.c: (main): * ext/artsd/gstartsdsink.c: (gst_artsdsink_open_audio), (gst_artsdsink_close_audio), (gst_artsdsink_change_state): * ext/artsd/gstartsdsink.h: * ext/audiofile/gstafparse.c: (gst_afparse_open_file), (gst_afparse_close_file): * ext/audiofile/gstafparse.h: * ext/audiofile/gstafsink.c: (gst_afsink_open_file), (gst_afsink_close_file), (gst_afsink_chain), (gst_afsink_change_state): * ext/audiofile/gstafsink.h: * ext/audiofile/gstafsrc.c: (gst_afsrc_open_file), (gst_afsrc_close_file), (gst_afsrc_change_state): * ext/audiofile/gstafsrc.h: * ext/cdaudio/gstcdaudio.c: (gst_cdaudio_init): * ext/directfb/directfbvideosink.c: (gst_directfbvideosink_init): * ext/dts/gstdtsdec.c: (gst_dtsdec_init): * ext/jack/gstjack.h: * ext/jack/gstjackbin.c: (gst_jack_bin_init), (gst_jack_bin_change_state): * ext/musepack/gstmusepackdec.c: (gst_musepackdec_init): * ext/musicbrainz/gsttrm.c: (gst_musicbrainz_init): * ext/nas/nassink.c: (gst_nassink_open_audio), (gst_nassink_close_audio), (gst_nassink_change_state): * ext/nas/nassink.h: * ext/polyp/polypsink.c: (gst_polypsink_init): * ext/sdl/sdlvideosink.c: (gst_sdlvideosink_change_state): * ext/sdl/sdlvideosink.h: * ext/smoothwave/gstsmoothwave.c: (gst_smoothwave_init): * ext/sndfile/gstsf.c: (gst_sf_set_property), (gst_sf_change_state), (gst_sf_release_request_pad), (gst_sf_open_file), (gst_sf_close_file), (gst_sf_loop): * ext/sndfile/gstsf.h: * ext/swfdec/gstswfdec.c: (gst_swfdec_init): * ext/tarkin/gsttarkindec.c: (gst_tarkindec_init): * gst/apetag/apedemux.c: (gst_ape_demux_init): * gst/cdxaparse/gstcdxaparse.c: (gst_cdxaparse_init): * gst/cdxaparse/gstcdxastrip.c: (gst_cdxastrip_init): * gst/festival/gstfestival.c: (gst_festival_change_state): * gst/festival/gstfestival.h: * gst/mpeg2sub/gstmpeg2subt.c: (gst_mpeg2subt_init): * gst/multifilesink/gstmultifilesink.c: (gst_multifilesink_init), (gst_multifilesink_set_location), (gst_multifilesink_open_file), (gst_multifilesink_close_file), (gst_multifilesink_next_file), (gst_multifilesink_pad_query), (gst_multifilesink_handle_event), (gst_multifilesink_chain), (gst_multifilesink_change_state): * gst/multifilesink/gstmultifilesink.h: * gst/videodrop/gstvideodrop.c: (gst_videodrop_init): * sys/cdrom/gstcdplayer.c: (cdplayer_init): * sys/dxr3/dxr3audiosink.c: (dxr3audiosink_init), (dxr3audiosink_open), (dxr3audiosink_close), (dxr3audiosink_chain_pcm), (dxr3audiosink_chain_ac3), (dxr3audiosink_change_state): * sys/dxr3/dxr3audiosink.h: * sys/dxr3/dxr3spusink.c: (dxr3spusink_init), (dxr3spusink_open), (dxr3spusink_close), (dxr3spusink_chain), (dxr3spusink_change_state): * sys/dxr3/dxr3spusink.h: * sys/dxr3/dxr3videosink.c: (dxr3videosink_init), (dxr3videosink_open), (dxr3videosink_close), (dxr3videosink_write_data), (dxr3videosink_change_state): * sys/dxr3/dxr3videosink.h: * sys/glsink/glimagesink.c: (gst_glimagesink_init): * sys/qcam/gstqcamsrc.c: (gst_qcamsrc_change_state), (gst_qcamsrc_open), (gst_qcamsrc_close): * sys/qcam/gstqcamsrc.h: * sys/v4l2/gstv4l2src.c: (gst_v4l2src_init): * sys/vcd/vcdsrc.c: (gst_vcdsrc_set_property), (gst_vcdsrc_get), (gst_vcdsrc_open_file), (gst_vcdsrc_close_file), (gst_vcdsrc_change_state), (gst_vcdsrc_recalculate): * sys/vcd/vcdsrc.h: renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition
2005-10-12 14:29:55 +00:00
GST_OBJECT_FLAG_SET (sdlvideosink, GST_SDLVIDEOSINK_OPEN);
break;
default: /* do nothing */
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY:
sdlvideosink->framerate = 0;
gst_sdlvideosink_destroy (sdlvideosink);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
gst_sdlvideosink_deinitsdl (sdlvideosink);
renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition Original commit message from CVS: * examples/indexing/indexmpeg.c: (main): * ext/artsd/gstartsdsink.c: (gst_artsdsink_open_audio), (gst_artsdsink_close_audio), (gst_artsdsink_change_state): * ext/artsd/gstartsdsink.h: * ext/audiofile/gstafparse.c: (gst_afparse_open_file), (gst_afparse_close_file): * ext/audiofile/gstafparse.h: * ext/audiofile/gstafsink.c: (gst_afsink_open_file), (gst_afsink_close_file), (gst_afsink_chain), (gst_afsink_change_state): * ext/audiofile/gstafsink.h: * ext/audiofile/gstafsrc.c: (gst_afsrc_open_file), (gst_afsrc_close_file), (gst_afsrc_change_state): * ext/audiofile/gstafsrc.h: * ext/cdaudio/gstcdaudio.c: (gst_cdaudio_init): * ext/directfb/directfbvideosink.c: (gst_directfbvideosink_init): * ext/dts/gstdtsdec.c: (gst_dtsdec_init): * ext/jack/gstjack.h: * ext/jack/gstjackbin.c: (gst_jack_bin_init), (gst_jack_bin_change_state): * ext/musepack/gstmusepackdec.c: (gst_musepackdec_init): * ext/musicbrainz/gsttrm.c: (gst_musicbrainz_init): * ext/nas/nassink.c: (gst_nassink_open_audio), (gst_nassink_close_audio), (gst_nassink_change_state): * ext/nas/nassink.h: * ext/polyp/polypsink.c: (gst_polypsink_init): * ext/sdl/sdlvideosink.c: (gst_sdlvideosink_change_state): * ext/sdl/sdlvideosink.h: * ext/smoothwave/gstsmoothwave.c: (gst_smoothwave_init): * ext/sndfile/gstsf.c: (gst_sf_set_property), (gst_sf_change_state), (gst_sf_release_request_pad), (gst_sf_open_file), (gst_sf_close_file), (gst_sf_loop): * ext/sndfile/gstsf.h: * ext/swfdec/gstswfdec.c: (gst_swfdec_init): * ext/tarkin/gsttarkindec.c: (gst_tarkindec_init): * gst/apetag/apedemux.c: (gst_ape_demux_init): * gst/cdxaparse/gstcdxaparse.c: (gst_cdxaparse_init): * gst/cdxaparse/gstcdxastrip.c: (gst_cdxastrip_init): * gst/festival/gstfestival.c: (gst_festival_change_state): * gst/festival/gstfestival.h: * gst/mpeg2sub/gstmpeg2subt.c: (gst_mpeg2subt_init): * gst/multifilesink/gstmultifilesink.c: (gst_multifilesink_init), (gst_multifilesink_set_location), (gst_multifilesink_open_file), (gst_multifilesink_close_file), (gst_multifilesink_next_file), (gst_multifilesink_pad_query), (gst_multifilesink_handle_event), (gst_multifilesink_chain), (gst_multifilesink_change_state): * gst/multifilesink/gstmultifilesink.h: * gst/videodrop/gstvideodrop.c: (gst_videodrop_init): * sys/cdrom/gstcdplayer.c: (cdplayer_init): * sys/dxr3/dxr3audiosink.c: (dxr3audiosink_init), (dxr3audiosink_open), (dxr3audiosink_close), (dxr3audiosink_chain_pcm), (dxr3audiosink_chain_ac3), (dxr3audiosink_change_state): * sys/dxr3/dxr3audiosink.h: * sys/dxr3/dxr3spusink.c: (dxr3spusink_init), (dxr3spusink_open), (dxr3spusink_close), (dxr3spusink_chain), (dxr3spusink_change_state): * sys/dxr3/dxr3spusink.h: * sys/dxr3/dxr3videosink.c: (dxr3videosink_init), (dxr3videosink_open), (dxr3videosink_close), (dxr3videosink_write_data), (dxr3videosink_change_state): * sys/dxr3/dxr3videosink.h: * sys/glsink/glimagesink.c: (gst_glimagesink_init): * sys/qcam/gstqcamsrc.c: (gst_qcamsrc_change_state), (gst_qcamsrc_open), (gst_qcamsrc_close): * sys/qcam/gstqcamsrc.h: * sys/v4l2/gstv4l2src.c: (gst_v4l2src_init): * sys/vcd/vcdsrc.c: (gst_vcdsrc_set_property), (gst_vcdsrc_get), (gst_vcdsrc_open_file), (gst_vcdsrc_close_file), (gst_vcdsrc_change_state), (gst_vcdsrc_recalculate): * sys/vcd/vcdsrc.h: renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition
2005-10-12 14:29:55 +00:00
GST_OBJECT_FLAG_UNSET (sdlvideosink, GST_SDLVIDEOSINK_OPEN);
break;
default: /* do nothing */
break;
}
return ret;
init_failed:
{
/* method posted detailed error message */
GST_DEBUG_OBJECT (sdlvideosink, "init failed");
return GST_STATE_CHANGE_FAILURE;
}
}
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_element_register (plugin, "sdlvideosink", GST_RANK_NONE,
GST_TYPE_SDLVIDEOSINK))
return FALSE;
return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"sdlvideosink",
"SDL Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)