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
|
2003-11-07 12:47:02 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
#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
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
#include <gst/interfaces/xoverlay.h>
|
2003-10-28 09:08:32 +00:00
|
|
|
|
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",
|
|
|
|
"An SDL-based videosink",
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>",
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_sdlvideosink_base_init (gpointer g_class);
|
|
|
|
static void gst_sdlvideosink_class_init (GstSDLVideoSinkClass * klass);
|
|
|
|
static void gst_sdlvideosink_init (GstSDLVideoSink * sdl);
|
2003-10-28 09:08:32 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_sdlvideosink_interface_init (GstImplementsInterfaceClass *
|
|
|
|
klass);
|
|
|
|
static gboolean gst_sdlvideosink_supported (GstImplementsInterface * iface,
|
|
|
|
GType type);
|
2003-10-28 09:08:32 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_sdlvideosink_xoverlay_init (GstXOverlayClass * klass);
|
|
|
|
static void gst_sdlvideosink_xoverlay_set_xwindow_id
|
|
|
|
(GstXOverlay * overlay, unsigned long parent);
|
2003-10-28 09:08:32 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean gst_sdlvideosink_lock (GstSDLVideoSink * sdl);
|
|
|
|
static void gst_sdlvideosink_unlock (GstSDLVideoSink * sdl);
|
2003-10-28 09:08:32 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean gst_sdlvideosink_initsdl (GstSDLVideoSink * sdl);
|
|
|
|
static void gst_sdlvideosink_deinitsdl (GstSDLVideoSink * sdl);
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean gst_sdlvideosink_create (GstSDLVideoSink * sdl);
|
|
|
|
static void gst_sdlvideosink_destroy (GstSDLVideoSink * sdl);
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
static gboolean gst_sdlvideosink_setcaps (GstBaseSink * bsink, GstCaps * caps);
|
|
|
|
|
|
|
|
#if 0
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstCaps *gst_sdlvideosink_fixate (GstPad * pad, const GstCaps * caps);
|
2005-09-19 21:47:54 +00:00
|
|
|
#endif
|
|
|
|
static GstFlowReturn gst_sdlvideosink_show_frame (GstBaseSink * bsink,
|
|
|
|
GstBuffer * buff);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
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);
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_sdlvideosink_change_state (GstElement * element, GstStateChange transition);
|
2002-01-10 09:58:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
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-11-02 01:27:21 +00:00
|
|
|
sizeof (GstSDLVideoSinkClass),
|
|
|
|
gst_sdlvideosink_base_init,
|
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,
|
|
|
|
};
|
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
sdlvideosink_type = g_type_register_static (GST_TYPE_VIDEO_SINK,
|
2004-03-15 19:32:27 +00:00
|
|
|
"GstSDLVideoSink", &sdlvideosink_info, 0);
|
2004-03-14 22:34:33 +00:00
|
|
|
g_type_add_interface_static (sdlvideosink_type,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_IMPLEMENTS_INTERFACE, &iface_info);
|
2004-03-14 22:34:33 +00:00
|
|
|
g_type_add_interface_static (sdlvideosink_type, GST_TYPE_X_OVERLAY,
|
2004-03-15 19:32:27 +00:00
|
|
|
&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-11-02 01:27:21 +00:00
|
|
|
static void
|
|
|
|
gst_sdlvideosink_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
2003-12-22 01:47:09 +00:00
|
|
|
GstCaps *capslist;
|
2003-11-02 01:27:21 +00:00
|
|
|
gint i;
|
2004-03-14 22:34:33 +00:00
|
|
|
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')
|
|
|
|
};
|
2003-11-02 01:27:21 +00:00
|
|
|
|
|
|
|
/* make a list of all available caps */
|
2004-03-14 22:34:33 +00:00
|
|
|
capslist = gst_caps_new_empty ();
|
2003-11-02 01:27:21 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_caps_append_structure (capslist,
|
2004-03-15 19:32:27 +00:00
|
|
|
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,
|
2004-08-09 20:07:10 +00:00
|
|
|
"framerate", GST_TYPE_DOUBLE_RANGE, 1.0, 100.0, NULL));
|
2003-11-02 01:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sink_template = gst_pad_template_new ("sink",
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PAD_SINK, GST_PAD_ALWAYS, capslist);
|
|
|
|
|
2003-11-02 01:27:21 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, sink_template);
|
|
|
|
gst_element_class_set_details (element_class, &gst_sdlvideosink_details);
|
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
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)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
|
|
|
g_mutex_free (GST_SDLVIDEOSINK (obj)->lock);
|
|
|
|
|
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
|
|
|
if (((GObjectClass *) parent_class)->finalize)
|
|
|
|
((GObjectClass *) parent_class)->finalize (obj);
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_class_init (GstSDLVideoSinkClass * klass)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2005-09-19 21:47:54 +00:00
|
|
|
GstBaseSinkClass *gstvs_class;
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2005-09-19 21:47:54 +00:00
|
|
|
gstvs_class = (GstBaseSinkClass *) klass;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
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;
|
2005-09-19 21:47:54 +00:00
|
|
|
|
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;
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_sdlvideosink_change_state);
|
|
|
|
|
|
|
|
gstvs_class->set_caps = GST_DEBUG_FUNCPTR (gst_sdlvideosink_setcaps);
|
|
|
|
gstvs_class->preroll = GST_DEBUG_FUNCPTR (gst_sdlvideosink_show_frame);
|
|
|
|
gstvs_class->render = GST_DEBUG_FUNCPTR (gst_sdlvideosink_show_frame);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-09-14 21:09:41 +00:00
|
|
|
/*gstvs_class->set_video_out = gst_sdlvideosink_set_video_out;
|
2004-03-14 22:34:33 +00:00
|
|
|
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-12-22 01:47:09 +00:00
|
|
|
#if 0
|
|
|
|
/* FIXME */
|
2003-10-28 09:08:32 +00:00
|
|
|
static GstBuffer *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_buffer_new (GstBufferPool * pool,
|
|
|
|
gint64 location, guint size, gpointer user_data)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (user_data);
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
if (!sdlvideosink->overlay)
|
|
|
|
return NULL;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_sdlvideosink_lock (sdlvideosink)) {
|
2003-10-28 09:08:32 +00:00
|
|
|
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) =
|
2004-03-15 19:32:27 +00:00
|
|
|
sdlvideosink->width * sdlvideosink->height * 3 / 2;
|
2003-10-28 09:08:32 +00:00
|
|
|
} else {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_SIZE (buffer) = sdlvideosink->width * sdlvideosink->height * 2;
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
|
|
|
GST_BUFFER_MAXSIZE (buffer) = GST_BUFFER_SIZE (buffer);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_buffer_free (GstBufferPool * pool,
|
|
|
|
GstBuffer * buffer, gpointer user_data)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (user_data);
|
|
|
|
|
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_unlock (sdlvideosink);
|
2003-10-28 09:08:32 +00:00
|
|
|
|
|
|
|
gst_buffer_default_free (buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstBufferPool *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_get_bufferpool (GstPad * pad)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (sdlvideosink->overlay)
|
|
|
|
return sdlvideosink->bufferpool;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-12-22 01:47:09 +00:00
|
|
|
#endif
|
2003-10-28 09:08:32 +00:00
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_init (GstSDLVideoSink * sdlvideosink)
|
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
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
//sdlvideosink->capslist = capslist;
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
sdlvideosink->init = FALSE;
|
|
|
|
|
|
|
|
sdlvideosink->lock = g_mutex_new ();
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
#if 0
|
2004-03-15 19:32:27 +00:00
|
|
|
sdlvideosink->bufferpool = gst_buffer_pool_new (NULL, /* free */
|
|
|
|
NULL, /* copy */
|
|
|
|
(GstBufferPoolBufferNewFunction) gst_sdlvideosink_buffer_new, NULL, /* buffer copy, the default is fine */
|
2004-03-14 22:34:33 +00:00
|
|
|
(GstBufferPoolBufferFreeFunction) gst_sdlvideosink_buffer_free,
|
|
|
|
sdlvideosink);
|
2003-12-22 01:47:09 +00:00
|
|
|
#endif
|
2003-10-28 09:08:32 +00:00
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_interface_init (GstImplementsInterfaceClass * klass)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
2003-12-07 12:11:30 +00:00
|
|
|
klass->supported = gst_sdlvideosink_supported;
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_supported (GstImplementsInterface * interface,
|
|
|
|
GType iface_type)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_xoverlay_init (GstXOverlayClass * klass)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
|
|
|
klass->set_xwindow_id = gst_sdlvideosink_xoverlay_set_xwindow_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_xoverlay_set_xwindow_id (GstXOverlay * overlay,
|
2004-03-13 00:19:26 +00:00
|
|
|
unsigned long parent)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_get_sdl_from_fourcc (GstSDLVideoSink * sdlvideosink,
|
|
|
|
guint32 code)
|
2002-01-10 09:58:15 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (code) {
|
|
|
|
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
2002-01-10 09:58:15 +00:00
|
|
|
return SDL_IYUV_OVERLAY;
|
2004-03-14 22:34:33 +00:00
|
|
|
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
|
2002-01-10 09:58:15 +00:00
|
|
|
return SDL_YV12_OVERLAY;
|
2004-03-14 22:34:33 +00:00
|
|
|
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
|
2002-01-10 09:58:15 +00:00
|
|
|
return SDL_YUY2_OVERLAY;
|
2004-03-14 22:34:33 +00:00
|
|
|
case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
|
2002-01-10 09:58:15 +00:00
|
|
|
return SDL_UYVY_OVERLAY;
|
2004-03-14 22:34:33 +00:00
|
|
|
case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
|
2002-01-10 09:58:15 +00:00
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_lock (GstSDLVideoSink * sdlvideosink)
|
2002-02-04 19:36:21 +00:00
|
|
|
{
|
2003-10-28 09:08:32 +00:00
|
|
|
/* assure that we've got a screen */
|
|
|
|
if (!sdlvideosink->screen || !sdlvideosink->overlay) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("Tried to lock screen without being set-up"));
|
2003-10-28 09:08:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-02-04 19:36:21 +00:00
|
|
|
/* Lock SDL/yuv-overlay */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (SDL_MUSTLOCK (sdlvideosink->screen)) {
|
|
|
|
if (SDL_LockSurface (sdlvideosink->screen) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("SDL: couldn't lock the SDL video window: %s", SDL_GetError ()));
|
2002-02-04 19:36:21 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
if (SDL_LockYUVOverlay (sdlvideosink->overlay) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_unlock (GstSDLVideoSink * sdlvideosink)
|
2002-02-04 19:36:21 +00:00
|
|
|
{
|
2003-10-28 09:08:32 +00:00
|
|
|
/* Unlock SDL_overlay */
|
2004-03-14 22:34:33 +00:00
|
|
|
SDL_UnlockYUVOverlay (sdlvideosink->overlay);
|
|
|
|
if (SDL_MUSTLOCK (sdlvideosink->screen))
|
|
|
|
SDL_UnlockSurface (sdlvideosink->screen);
|
2002-02-04 19:36:21 +00:00
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_deinitsdl (GstSDLVideoSink * sdlvideosink)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
2004-11-10 22:01:20 +00:00
|
|
|
g_mutex_lock (sdlvideosink->lock);
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
if (sdlvideosink->init) {
|
|
|
|
SDL_Quit ();
|
|
|
|
sdlvideosink->init = FALSE;
|
|
|
|
}
|
2004-11-10 22:01:20 +00:00
|
|
|
|
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
2002-02-04 19:36:21 +00:00
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +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);
|
|
|
|
|
2004-11-10 22:01:20 +00:00
|
|
|
g_mutex_lock (sdlvideosink->lock);
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
if (!sdlvideosink->xwindow_id) {
|
2004-03-14 22:34:33 +00:00
|
|
|
unsetenv ("SDL_WINDOWID");
|
2003-10-28 09:08:32 +00:00
|
|
|
} else {
|
|
|
|
char SDL_hack[32];
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
sprintf (SDL_hack, "%lu", sdlvideosink->xwindow_id);
|
|
|
|
setenv ("SDL_WINDOWID", SDL_hack, 1);
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the SDL library */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, INIT, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("Couldn't initialize SDL: %s", SDL_GetError ()));
|
2004-11-10 22:01:20 +00:00
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
2003-10-28 09:08:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-11-10 22:01:20 +00:00
|
|
|
sdlvideosink->init = TRUE;
|
|
|
|
|
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_destroy (GstSDLVideoSink * sdlvideosink)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
2004-11-10 22:01:20 +00:00
|
|
|
g_mutex_lock (sdlvideosink->lock);
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
if (sdlvideosink->overlay) {
|
2004-03-14 22:34:33 +00:00
|
|
|
SDL_FreeYUVOverlay (sdlvideosink->overlay);
|
2003-10-28 09:08:32 +00:00
|
|
|
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;
|
|
|
|
}
|
2004-11-10 22:01:20 +00:00
|
|
|
|
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_create (GstSDLVideoSink * sdlvideosink)
|
2003-10-28 09:08:32 +00:00
|
|
|
{
|
2005-09-19 21:47:54 +00:00
|
|
|
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;
|
2003-10-28 09:08:32 +00:00
|
|
|
|
|
|
|
gst_sdlvideosink_destroy (sdlvideosink);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2004-11-10 22:01:20 +00:00
|
|
|
g_mutex_lock (sdlvideosink->lock);
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
/* create a SDL window of the size requested by the user */
|
2005-09-19 21:47:54 +00:00
|
|
|
sdlvideosink->screen = SDL_SetVideoMode (GST_VIDEO_SINK_WIDTH (sdlvideosink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (sdlvideosink), 0, SDL_HWSURFACE | SDL_RESIZABLE);
|
2004-03-14 22:34:33 +00:00
|
|
|
if (sdlvideosink->screen == NULL) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
|
2005-09-19 21:47:54 +00:00
|
|
|
("SDL: Couldn't set %dx%d: %s", GST_VIDEO_SINK_WIDTH (sdlvideosink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (sdlvideosink), SDL_GetError ()));
|
2004-11-10 22:01:20 +00:00
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
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 */
|
2004-03-14 22:34:33 +00:00
|
|
|
sdlvideosink->overlay = SDL_CreateYUVOverlay (sdlvideosink->width,
|
|
|
|
sdlvideosink->height, sdlvideosink->format, sdlvideosink->screen);
|
|
|
|
if (sdlvideosink->overlay == NULL) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (sdlvideosink, LIBRARY, TOO_LAZY, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("SDL: Couldn't create SDL YUV overlay (%dx%d \'" GST_FOURCC_FORMAT
|
|
|
|
"\'): %s", sdlvideosink->width, sdlvideosink->height,
|
|
|
|
GST_FOURCC_ARGS (sdlvideosink->format), SDL_GetError ()));
|
2004-11-10 22:01:20 +00:00
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
2002-01-15 15:52:09 +00:00
|
|
|
return FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG ("Using a %dx%d %dbpp SDL screen with a %dx%d \'"
|
2005-09-19 21:47:54 +00:00
|
|
|
GST_FOURCC_FORMAT "\' YUV overlay", GST_VIDEO_SINK_WIDTH (sdlvideosink),
|
|
|
|
GST_VIDEO_SINK_HEIGHT (sdlvideosink),
|
2004-03-15 19:32:27 +00:00
|
|
|
sdlvideosink->screen->format->BitsPerPixel, sdlvideosink->width,
|
|
|
|
sdlvideosink->height, GST_FOURCC_ARGS (sdlvideosink->format));
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sdlvideosink->rect.x = 0;
|
|
|
|
sdlvideosink->rect.y = 0;
|
2005-09-19 21:47:54 +00:00
|
|
|
sdlvideosink->rect.w = GST_VIDEO_SINK_WIDTH (sdlvideosink);
|
|
|
|
sdlvideosink->rect.h = GST_VIDEO_SINK_HEIGHT (sdlvideosink);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2004-11-10 22:01:20 +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 ")",
|
2004-03-14 22:34:33 +00:00
|
|
|
sdlvideosink->format, GST_FOURCC_ARGS (sdlvideosink->format));
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2004-11-10 22:01:20 +00:00
|
|
|
g_mutex_unlock (sdlvideosink->lock);
|
|
|
|
|
2002-01-15 15:52:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
#if 0
|
2004-03-06 04:51:15 +00:00
|
|
|
static GstCaps *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_fixate (GstPad * pad, const GstCaps * caps)
|
2004-03-06 04:51:15 +00:00
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
GstCaps *newcaps;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (gst_caps_get_size (caps) > 1)
|
|
|
|
return NULL;
|
2004-03-06 04:51:15 +00:00
|
|
|
|
|
|
|
newcaps = gst_caps_copy (caps);
|
|
|
|
structure = gst_caps_get_structure (newcaps, 0);
|
|
|
|
|
|
|
|
if (gst_caps_structure_fixate_field_nearest_int (structure, "width", 320)) {
|
|
|
|
return newcaps;
|
|
|
|
}
|
|
|
|
if (gst_caps_structure_fixate_field_nearest_int (structure, "height", 240)) {
|
|
|
|
return newcaps;
|
|
|
|
}
|
|
|
|
if (gst_caps_structure_fixate_field_nearest_double (structure, "framerate",
|
2004-03-15 19:32:27 +00:00
|
|
|
30.0)) {
|
2004-03-06 04:51:15 +00:00
|
|
|
return newcaps;
|
|
|
|
}
|
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
gst_caps_unref (newcaps);
|
2004-03-06 04:51:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-09-19 21:47:54 +00:00
|
|
|
#endif
|
2004-03-06 04:51:15 +00:00
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
static gboolean
|
|
|
|
gst_sdlvideosink_setcaps (GstBaseSink * bsink, GstCaps * vscapslist)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
2002-01-10 09:58:15 +00:00
|
|
|
GstSDLVideoSink *sdlvideosink;
|
2003-12-22 01:47:09 +00:00
|
|
|
guint32 format;
|
|
|
|
GstStructure *structure;
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK (bsink);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (vscapslist, 0);
|
|
|
|
gst_structure_get_fourcc (structure, "format", &format);
|
|
|
|
sdlvideosink->format =
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_get_sdl_from_fourcc (sdlvideosink, format);
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_get_int (structure, "width", &sdlvideosink->width);
|
|
|
|
gst_structure_get_int (structure, "height", &sdlvideosink->height);
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!sdlvideosink->format || !gst_sdlvideosink_create (sdlvideosink))
|
2005-09-19 21:47:54 +00:00
|
|
|
return FALSE;
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2004-11-10 22:01:20 +00:00
|
|
|
gst_x_overlay_got_desired_size (GST_X_OVERLAY (sdlvideosink),
|
|
|
|
sdlvideosink->width, sdlvideosink->height);
|
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
return TRUE;
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
2002-01-10 09:58:15 +00:00
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_sdlvideosink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
2005-09-19 21:47:54 +00:00
|
|
|
|
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
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK (bsink);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2004-11-10 22:01:20 +00:00
|
|
|
if (!sdlvideosink->init ||
|
|
|
|
!sdlvideosink->overlay || !sdlvideosink->overlay->pixels) {
|
2005-09-19 21:47:54 +00:00
|
|
|
g_print ("Not Init!\n");
|
|
|
|
return GST_FLOW_ERROR;
|
2004-11-10 22:01:20 +00:00
|
|
|
}
|
|
|
|
|
2003-10-28 09:08:32 +00:00
|
|
|
if (GST_BUFFER_DATA (buf) != sdlvideosink->overlay->pixels[0]) {
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_sdlvideosink_lock (sdlvideosink)) {
|
2005-09-19 21:47:54 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
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 ||
|
2004-03-15 19:32:27 +00:00
|
|
|
sdlvideosink->format == SDL_YV12_OVERLAY) {
|
2003-10-28 09:08:32 +00:00
|
|
|
memcpy (sdlvideosink->overlay->pixels[0], GST_BUFFER_DATA (buf),
|
2004-03-15 19:32:27 +00:00
|
|
|
sdlvideosink->width * sdlvideosink->height);
|
2003-10-28 09:08:32 +00:00
|
|
|
memcpy (sdlvideosink->overlay->pixels[1],
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_DATA (buf) + sdlvideosink->width * sdlvideosink->height,
|
|
|
|
sdlvideosink->width * sdlvideosink->height / 4);
|
2003-10-28 09:08:32 +00:00
|
|
|
memcpy (sdlvideosink->overlay->pixels[2],
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_DATA (buf) +
|
|
|
|
sdlvideosink->width * sdlvideosink->height * 5 / 4,
|
|
|
|
sdlvideosink->width * sdlvideosink->height / 4);
|
2003-10-28 09:08:32 +00:00
|
|
|
} else {
|
|
|
|
memcpy (sdlvideosink->overlay->pixels[0], GST_BUFFER_DATA (buf),
|
2004-03-15 19:32:27 +00:00
|
|
|
sdlvideosink->width * sdlvideosink->height * 2);
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_unlock (sdlvideosink);
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
2001-12-20 23:21:15 +00:00
|
|
|
|
|
|
|
/* Show, baby, show! */
|
2004-03-14 22:34:33 +00:00
|
|
|
SDL_DisplayYUVOverlay (sdlvideosink->overlay, &(sdlvideosink->rect));
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
while (SDL_PollEvent (&sdl_event)) {
|
|
|
|
switch (sdl_event.type) {
|
2003-10-28 09:08:32 +00:00
|
|
|
case SDL_VIDEORESIZE:
|
2004-03-15 19:32:27 +00:00
|
|
|
/* create a SDL window of the size requested by the user */
|
2005-09-19 21:47:54 +00:00
|
|
|
GST_VIDEO_SINK_WIDTH (sdlvideosink) = sdl_event.resize.w;
|
|
|
|
GST_VIDEO_SINK_HEIGHT (sdlvideosink) = sdl_event.resize.h;
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_sdlvideosink_create (sdlvideosink);
|
|
|
|
break;
|
2003-10-28 09:08:32 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-10 22:01:20 +00:00
|
|
|
|
2005-09-19 21:47:54 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_SDLVIDEOSINK (object));
|
2004-03-14 22:34:33 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK (object);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2004-03-14 22:34:33 +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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_sdlvideosink_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
|
|
|
GstSDLVideoSink *sdlvideosink;
|
|
|
|
|
2002-01-10 10:03:33 +00:00
|
|
|
g_return_if_fail (GST_IS_SDLVIDEOSINK (object));
|
2004-03-14 22:34:33 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK (object);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_sdlvideosink_change_state (GstElement * element, GstStateChange transition)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
2002-01-10 09:58:15 +00:00
|
|
|
GstSDLVideoSink *sdlvideosink;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
g_return_val_if_fail (GST_IS_SDLVIDEOSINK (element),
|
|
|
|
GST_STATE_CHANGE_FAILURE);
|
2004-03-14 22:34:33 +00:00
|
|
|
sdlvideosink = GST_SDLVIDEOSINK (element);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2003-10-28 09:08:32 +00:00
|
|
|
if (!gst_sdlvideosink_initsdl (sdlvideosink))
|
2005-09-05 17:20:29 +00:00
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
2002-01-10 09:58:15 +00:00
|
|
|
GST_FLAG_SET (sdlvideosink, GST_SDLVIDEOSINK_OPEN);
|
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2003-10-28 09:08:32 +00:00
|
|
|
gst_sdlvideosink_destroy (sdlvideosink);
|
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_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;
|
2004-03-15 19:32:27 +00:00
|
|
|
default: /* do nothing */
|
2002-01-10 09:58:15 +00:00
|
|
|
break;
|
2001-12-20 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
2005-09-05 17:20:29 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2001-12-20 23:21:15 +00:00
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
return GST_STATE_CHANGE_SUCCESS;
|
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 gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-20 23:21:15 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!gst_element_register (plugin, "sdlvideosink", GST_RANK_NONE,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_SDLVIDEOSINK))
|
2003-11-02 01:27:21 +00:00
|
|
|
return FALSE;
|
2001-12-20 23:21:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"sdlvideosink",
|
|
|
|
"SDL Video Sink", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|