2003-04-22 14:55:12 +00:00
|
|
|
/* GStreamer divx decoder plugin
|
|
|
|
* Copyright (C) 2003 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "gstdivxdec.h"
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-divx, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"divxversion = (int) [ 3, 5 ], "
|
|
|
|
"width = (int) [ 16, 4096 ], "
|
2005-12-19 14:40:22 +00:00
|
|
|
"height = (int) [ 16, 4096 ], " "framerate = (fraction) [0/1, MAX]")
|
2004-03-14 20:47:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YUY2, YV12, UYVY }")
|
2004-03-15 19:32:27 +00:00
|
|
|
/* FIXME: 15/16/24/32bpp RGB */
|
2004-03-14 20:47:18 +00:00
|
|
|
)
|
|
|
|
);
|
2003-04-22 14:55:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* DivxDec signals and args */
|
2004-03-14 20:47:18 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-04-22 14:55:12 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-04-22 14:55:12 +00:00
|
|
|
ARG_0
|
2004-03-14 20:47:18 +00:00
|
|
|
/* FILL ME */
|
2003-04-22 14:55:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
static void gst_divxdec_base_init (GstDivxDecClass * klass);
|
|
|
|
static void gst_divxdec_class_init (GstDivxDecClass * klass);
|
|
|
|
static void gst_divxdec_init (GstDivxDec * divxdec);
|
|
|
|
static void gst_divxdec_dispose (GObject * object);
|
2005-12-19 14:40:22 +00:00
|
|
|
static GstFlowReturn gst_divxdec_chain (GstPad * pad, GstBuffer * buf);
|
|
|
|
static gboolean gst_divxdec_connect (GstPad * pad, GstCaps * vscapslist);
|
|
|
|
static gboolean gst_divxdec_negotiate (GstDivxDec * divxdec);
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_divxdec_change_state (GstElement * element, GstStateChange transition);
|
2003-04-22 14:55:12 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 20:47:18 +00:00
|
|
|
|
2003-04-22 14:55:12 +00:00
|
|
|
/* static guint gst_divxdec_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
|
2010-03-25 21:48:09 +00:00
|
|
|
static const gchar *
|
2003-05-30 21:44:53 +00:00
|
|
|
gst_divxdec_error (int errorcode)
|
|
|
|
{
|
2010-03-25 21:48:09 +00:00
|
|
|
const gchar *error;
|
2003-05-30 21:44:53 +00:00
|
|
|
|
|
|
|
switch (errorcode) {
|
|
|
|
case DEC_OK:
|
|
|
|
error = "No error";
|
|
|
|
break;
|
|
|
|
case DEC_MEMORY:
|
|
|
|
error = "Invalid memory";
|
|
|
|
break;
|
|
|
|
case DEC_BAD_FORMAT:
|
|
|
|
error = "Invalid format";
|
|
|
|
break;
|
|
|
|
case DEC_INVALID_ARGUMENT:
|
|
|
|
error = "Invalid argument";
|
|
|
|
break;
|
|
|
|
case DEC_NOT_IMPLEMENTED:
|
|
|
|
error = "Not implemented";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = "Unknown error";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2003-04-22 14:55:12 +00:00
|
|
|
GType
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_get_type (void)
|
2003-04-22 14:55:12 +00:00
|
|
|
{
|
|
|
|
static GType divxdec_type = 0;
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
if (!divxdec_type) {
|
2003-04-22 14:55:12 +00:00
|
|
|
static const GTypeInfo divxdec_info = {
|
2004-03-14 20:47:18 +00:00
|
|
|
sizeof (GstDivxDecClass),
|
2003-11-02 20:37:50 +00:00
|
|
|
(GBaseInitFunc) gst_divxdec_base_init,
|
2003-04-22 14:55:12 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_divxdec_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 20:47:18 +00:00
|
|
|
sizeof (GstDivxDec),
|
2003-04-22 14:55:12 +00:00
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_divxdec_init,
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
divxdec_type = g_type_register_static (GST_TYPE_ELEMENT,
|
2004-03-15 19:32:27 +00:00
|
|
|
"GstDivxDec", &divxdec_info, 0);
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
|
|
|
return divxdec_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-02 20:37:50 +00:00
|
|
|
static void
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_base_init (GstDivxDecClass * klass)
|
2003-11-02 20:37:50 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_static_pad_template_get (&sink_template));
|
2003-11-02 20:37:50 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_static_pad_template_get (&src_template));
|
2003-11-02 20:37:50 +00:00
|
|
|
|
2010-03-18 16:30:26 +00:00
|
|
|
gst_element_class_set_details_simple (element_class,
|
|
|
|
"Divx4linux video decoder", "Codec/Decoder/Video",
|
|
|
|
"Divx decoder based on divxdecore",
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
2003-11-02 20:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-22 14:55:12 +00:00
|
|
|
static void
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_class_init (GstDivxDecClass * klass)
|
2003-04-22 14:55:12 +00:00
|
|
|
{
|
2005-12-19 14:40:22 +00:00
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
2003-04-22 14:55:12 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
|
2006-04-08 21:48:01 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2003-04-22 14:55:12 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
gstelement_class->change_state = gst_divxdec_change_state;
|
2003-04-22 14:55:12 +00:00
|
|
|
gobject_class->dispose = gst_divxdec_dispose;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_init (GstDivxDec * divxdec)
|
2003-04-22 14:55:12 +00:00
|
|
|
{
|
|
|
|
/* create the sink pad */
|
2007-06-22 10:46:33 +00:00
|
|
|
divxdec->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (divxdec), divxdec->sinkpad);
|
|
|
|
gst_pad_set_chain_function (divxdec->sinkpad, gst_divxdec_chain);
|
2005-12-19 14:40:22 +00:00
|
|
|
gst_pad_set_setcaps_function (divxdec->sinkpad, gst_divxdec_connect);
|
2003-04-22 14:55:12 +00:00
|
|
|
|
|
|
|
/* create the src pad */
|
2007-06-22 10:46:33 +00:00
|
|
|
divxdec->srcpad = gst_pad_new_from_static_template (&src_template, "src");
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (divxdec), divxdec->srcpad);
|
2005-12-19 14:40:22 +00:00
|
|
|
gst_pad_use_fixed_caps (divxdec->srcpad);
|
2003-04-22 14:55:12 +00:00
|
|
|
|
|
|
|
/* bitrate, etc. */
|
2003-05-30 21:44:53 +00:00
|
|
|
divxdec->width = divxdec->height = divxdec->csp = divxdec->bitcnt = -1;
|
2004-01-23 10:56:57 +00:00
|
|
|
divxdec->version = 0;
|
2003-04-22 14:55:12 +00:00
|
|
|
|
|
|
|
/* set divx handle to NULL */
|
|
|
|
divxdec->handle = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_unset (GstDivxDec * divxdec)
|
2003-04-22 14:55:12 +00:00
|
|
|
{
|
|
|
|
if (divxdec->handle) {
|
|
|
|
/* unref this instance */
|
2004-03-14 20:47:18 +00:00
|
|
|
decore (divxdec->handle, DEC_OPT_RELEASE, NULL, NULL);
|
2003-04-22 14:55:12 +00:00
|
|
|
divxdec->handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_setup (GstDivxDec * divxdec)
|
2003-04-22 14:55:12 +00:00
|
|
|
{
|
2003-05-30 21:44:53 +00:00
|
|
|
void *handle;
|
|
|
|
DEC_INIT xinit;
|
|
|
|
DivXBitmapInfoHeader output;
|
2003-04-22 14:55:12 +00:00
|
|
|
int ret;
|
|
|
|
|
2003-05-30 21:44:53 +00:00
|
|
|
/* initialize the handle */
|
2004-03-14 20:47:18 +00:00
|
|
|
memset (&xinit, 0, sizeof (DEC_INIT));
|
2003-09-30 20:10:05 +00:00
|
|
|
xinit.smooth_playback = 0;
|
2004-01-23 10:56:57 +00:00
|
|
|
switch (divxdec->version) {
|
|
|
|
case 3:
|
|
|
|
xinit.codec_version = 311;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
xinit.codec_version = 400;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
xinit.codec_version = 500;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
xinit.codec_version = 0;
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 20:47:18 +00:00
|
|
|
if ((ret = decore (&handle, DEC_OPT_INIT, &xinit, NULL)) != 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (divxdec, LIBRARY, INIT, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("divx library error: %s (%d)", gst_divxdec_error (ret), ret));
|
2003-04-22 14:55:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-05-30 21:44:53 +00:00
|
|
|
/* we've got a handle now */
|
|
|
|
divxdec->handle = handle;
|
2003-04-22 14:55:12 +00:00
|
|
|
|
2003-05-30 21:44:53 +00:00
|
|
|
/* initialise parameters, see divx documentation */
|
2004-03-14 20:47:18 +00:00
|
|
|
memset (&output, 0, sizeof (DivXBitmapInfoHeader));
|
|
|
|
output.biSize = sizeof (DivXBitmapInfoHeader);
|
2003-05-30 21:44:53 +00:00
|
|
|
output.biWidth = divxdec->width;
|
|
|
|
output.biHeight = divxdec->height;
|
|
|
|
output.biBitCount = divxdec->bitcnt;
|
|
|
|
output.biCompression = divxdec->csp;
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
if ((ret = decore (divxdec->handle, DEC_OPT_SETOUT, &output, NULL)) != 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (divxdec, LIBRARY, SETTINGS, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
("error setting output: %s (%d)", gst_divxdec_error (ret), ret));
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_unset (divxdec);
|
2003-04-22 14:55:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_dispose (GObject * object)
|
2003-04-22 14:55:12 +00:00
|
|
|
{
|
2004-03-14 20:47:18 +00:00
|
|
|
GstDivxDec *divxdec = GST_DIVXDEC (object);
|
2003-04-22 14:55:12 +00:00
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_unset (divxdec);
|
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
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_divxdec_chain (GstPad * pad, GstBuffer * buf)
|
2003-04-22 14:55:12 +00:00
|
|
|
{
|
|
|
|
GstDivxDec *divxdec;
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
DEC_FRAME xframe;
|
2005-12-19 14:40:22 +00:00
|
|
|
int res;
|
|
|
|
GstFlowReturn ret;
|
2003-04-22 14:55:12 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
divxdec = GST_DIVXDEC (gst_pad_get_parent (pad));
|
2003-04-22 14:55:12 +00:00
|
|
|
if (!divxdec->handle) {
|
2004-03-14 20:47:18 +00:00
|
|
|
if (gst_divxdec_negotiate (divxdec) <= 0) {
|
2005-12-19 14:40:22 +00:00
|
|
|
goto not_negotiated;
|
2003-07-06 20:49:52 +00:00
|
|
|
}
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
outbuf = gst_buffer_new_and_alloc (divxdec->width *
|
|
|
|
divxdec->height * divxdec->bpp / 8);
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
GST_BUFFER_SIZE (outbuf) = divxdec->width *
|
|
|
|
divxdec->height * divxdec->bpp / 8;
|
2003-04-22 14:55:12 +00:00
|
|
|
|
|
|
|
/* encode and so ... */
|
2004-03-14 20:47:18 +00:00
|
|
|
xframe.bitstream = (void *) GST_BUFFER_DATA (buf);
|
|
|
|
xframe.bmp = (void *) GST_BUFFER_DATA (outbuf);
|
|
|
|
xframe.length = GST_BUFFER_SIZE (buf);
|
2003-05-30 21:44:53 +00:00
|
|
|
xframe.stride = 0;
|
2003-04-22 14:55:12 +00:00
|
|
|
xframe.render_flag = 1;
|
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
if ((res = decore (divxdec->handle, DEC_OPT_FRAME, &xframe, NULL))) {
|
|
|
|
goto not_decoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (divxdec->srcpad));
|
|
|
|
ret = gst_pad_push (divxdec->srcpad, outbuf);
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
not_negotiated:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (divxdec, CORE, TOO_LAZY, (NULL),
|
|
|
|
("No format set - aborting"));
|
|
|
|
ret = GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
not_decoding:
|
|
|
|
{
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (divxdec, STREAM, DECODE, (NULL),
|
2005-12-19 14:40:22 +00:00
|
|
|
("Error decoding divx frame: %s (%d)", gst_divxdec_error (res), res));
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto cleanup;
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
cleanup:
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_buffer_unref (buf);
|
2005-12-19 14:40:22 +00:00
|
|
|
gst_object_unref (divxdec);
|
|
|
|
return ret;
|
|
|
|
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
/* FIXME: moved all the bits out here that are broken so the syntax
|
|
|
|
* stays clear */
|
|
|
|
|
|
|
|
/*
|
2005-12-19 14:40:22 +00:00
|
|
|
{
|
2004-03-14 20:47:18 +00:00
|
|
|
GST_MAKE_FOURCC ('R', 'G', 'B', ' '), 32, 32,
|
2005-12-19 14:40:22 +00:00
|
|
|
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
|
|
|
|
GST_MAKE_FOURCC ('A', 'B', 'G', 'R'), 32}
|
2004-03-14 20:47:18 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
,
|
|
|
|
#else
|
|
|
|
0, 32}
|
2004-03-14 20:47:18 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
,
|
|
|
|
#endif
|
|
|
|
{
|
2004-03-14 20:47:18 +00:00
|
|
|
GST_MAKE_FOURCC ('R', 'G', 'B', ' '), 24, 24,
|
2005-12-19 14:40:22 +00:00
|
|
|
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
|
|
|
|
GST_MAKE_FOURCC ('A', 'B', 'G', 'R'), 24}
|
2004-03-14 20:47:18 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
,
|
|
|
|
#else
|
|
|
|
0, 24}
|
2004-03-14 20:47:18 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
,
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
GST_MAKE_FOURCC ('R', 'G', 'B', ' '), 16, 16, 3, 16}
|
2004-03-14 20:47:18 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
, {
|
|
|
|
GST_MAKE_FOURCC ('R', 'G', 'B', ' '), 15, 16, 0, 16}
|
2004-03-14 20:47:18 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
,
|
|
|
|
#endif
|
|
|
|
if (fmt_list[i].fourcc == GST_MAKE_FOURCC ('R', 'G', 'B', ' ')) {
|
2004-03-14 20:47:18 +00:00
|
|
|
guint32 r_mask = 0, b_mask = 0, g_mask = 0;
|
|
|
|
gint endianness = 0;
|
|
|
|
|
|
|
|
switch (fmt_list[i].depth) {
|
2005-12-19 14:40:22 +00:00
|
|
|
case 15:
|
|
|
|
endianness = G_BYTE_ORDER;
|
|
|
|
r_mask = 0xf800;
|
|
|
|
g_mask = 0x07c0;
|
|
|
|
b_mask = 0x003e;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
endianness = G_BYTE_ORDER;
|
|
|
|
r_mask = 0xf800;
|
|
|
|
g_mask = 0x07e0;
|
|
|
|
b_mask = 0x001f;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
endianness = G_BIG_ENDIAN;
|
|
|
|
r_mask = GST_VIDEO_BYTE1_MASK_24_INT;
|
|
|
|
g_mask = GST_VIDEO_BYTE2_MASK_24_INT;
|
|
|
|
b_mask = GST_VIDEO_BYTE3_MASK_24_INT break;
|
|
|
|
case 32:
|
|
|
|
endianness = G_BIG_ENDIAN;
|
|
|
|
r_mask = GST_VIDEO_BYTE1_MASK_32_INT;
|
|
|
|
g_mask = GST_VIDEO_BYTE2_MASK_32_INT;
|
|
|
|
b_mask = GST_VIDEO_BYTE3_MASK_32_INT break;
|
2004-03-14 20:47:18 +00:00
|
|
|
}
|
|
|
|
caps = GST_CAPS_NEW ("divxdec_src_pad_rgb",
|
2005-12-19 14:40:22 +00:00
|
|
|
"video/x-raw-rgb",
|
|
|
|
"width", GST_PROPS_INT (divxdec->width),
|
|
|
|
"height", GST_PROPS_INT (divxdec->height),
|
|
|
|
"framerate", GST_PROPS_FLOAT (divxdec->fps),
|
|
|
|
"depth", GST_PROPS_INT (fmt_list[i].depth),
|
|
|
|
"bpp", GST_PROPS_INT (fmt_list[i].bpp),
|
|
|
|
"endianness", GST_PROPS_INT (endianness),
|
|
|
|
"red_mask", GST_PROPS_INT (r_mask),
|
|
|
|
"green_mask", GST_PROPS_INT (g_mask),
|
|
|
|
"blue_mask", GST_PROPS_INT (b_mask));
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2004-03-14 20:47:18 +00:00
|
|
|
*/
|
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
static gboolean
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_negotiate (GstDivxDec * divxdec)
|
|
|
|
{
|
2005-12-19 14:40:22 +00:00
|
|
|
GstCaps *caps = NULL;
|
|
|
|
gint i;
|
|
|
|
gint par_num, par_den;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
guint32 fourcc;
|
|
|
|
gint depth, bpp;
|
|
|
|
guint32 csp;
|
|
|
|
gint bitcnt;
|
2004-03-15 19:32:27 +00:00
|
|
|
}
|
2005-12-19 14:40:22 +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
|
|
|
fmt_list[] = {
|
2004-03-14 20:47:18 +00:00
|
|
|
{
|
|
|
|
GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'), 16, 16,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'), 0}
|
|
|
|
, {
|
2004-03-14 20:47:18 +00:00
|
|
|
GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'), 16, 16,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'), 0}
|
|
|
|
, {
|
2004-03-14 20:47:18 +00:00
|
|
|
GST_MAKE_FOURCC ('I', '4', '2', '0'), 12, 12,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_MAKE_FOURCC ('I', '4', '2', '0'), 0}
|
|
|
|
, {
|
2004-03-14 20:47:18 +00:00
|
|
|
GST_MAKE_FOURCC ('Y', 'V', '1', '2'), 12, 12,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_MAKE_FOURCC ('Y', 'V', '1', '2'), 0}
|
|
|
|
, {
|
2004-03-14 20:47:18 +00:00
|
|
|
0, 0, 0, 0, 0}
|
2003-04-22 14:55:12 +00:00
|
|
|
};
|
2005-12-19 14:40:22 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (divxdec, "fps %d/%d, PAR %d/%d",
|
|
|
|
divxdec->fps_n, divxdec->fps_d, divxdec->par_n, divxdec->par_d);
|
|
|
|
|
|
|
|
/* calculate par
|
|
|
|
* the info.aspect_* values reflect PAR;
|
|
|
|
* 0:0 is allowed and can be interpreted as 1:1, so correct for it */
|
|
|
|
par_num = divxdec->par_n;
|
|
|
|
par_den = divxdec->par_d;
|
|
|
|
if (par_num == 0 && par_den == 0) {
|
|
|
|
par_num = par_den = 1;
|
|
|
|
}
|
2003-04-22 14:55:12 +00:00
|
|
|
|
|
|
|
for (i = 0; fmt_list[i].fourcc != 0; i++) {
|
|
|
|
divxdec->csp = fmt_list[i].csp;
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
caps = gst_caps_new_simple ("video/x-raw-yuv",
|
2004-03-15 19:32:27 +00:00
|
|
|
"width", G_TYPE_INT, divxdec->width,
|
|
|
|
"height", G_TYPE_INT, divxdec->height,
|
2005-12-19 14:40:22 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION, divxdec->fps_n, divxdec->fps_d,
|
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_num, par_den,
|
2004-03-15 19:32:27 +00:00
|
|
|
"format", GST_TYPE_FOURCC, fmt_list[i].fourcc, NULL);
|
2004-03-14 20:47:18 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
if (caps) {
|
|
|
|
|
|
|
|
if (gst_divxdec_setup (divxdec) &&
|
|
|
|
gst_pad_set_caps (divxdec->srcpad, caps)) {
|
|
|
|
divxdec->csp = fmt_list[i].csp;
|
|
|
|
divxdec->bpp = fmt_list[i].bpp;
|
|
|
|
divxdec->bitcnt = fmt_list[i].bitcnt;
|
|
|
|
ret = TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = NULL;
|
|
|
|
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
2005-12-19 14:40:22 +00:00
|
|
|
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we got here - it's not good */
|
2005-12-19 14:40:22 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
if (caps) {
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
static gboolean
|
|
|
|
gst_divxdec_connect (GstPad * pad, GstCaps * caps)
|
2003-07-06 20:49:52 +00:00
|
|
|
{
|
|
|
|
GstDivxDec *divxdec;
|
2005-12-19 14:40:22 +00:00
|
|
|
const GValue *par;
|
|
|
|
const GValue *fps;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
2003-07-06 20:49:52 +00:00
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
divxdec = GST_DIVXDEC (gst_pad_get_parent (pad));
|
2003-07-06 20:49:52 +00:00
|
|
|
|
|
|
|
/* if there's something old around, remove it */
|
|
|
|
if (divxdec->handle) {
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_divxdec_unset (divxdec);
|
2003-07-06 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we get here, we know the input is divx. we
|
|
|
|
* only need to bother with the output colorspace */
|
2004-03-14 20:47:18 +00:00
|
|
|
gst_structure_get_int (structure, "width", &divxdec->width);
|
|
|
|
gst_structure_get_int (structure, "height", &divxdec->height);
|
|
|
|
gst_structure_get_int (structure, "divxversion", &divxdec->version);
|
2003-07-06 20:49:52 +00:00
|
|
|
|
2005-12-19 14:40:22 +00:00
|
|
|
/* get pixel aspect ratio if it's set */
|
|
|
|
par = gst_structure_get_value (structure, "pixel-aspect-ratio");
|
|
|
|
if (par) {
|
|
|
|
divxdec->par_n = gst_value_get_fraction_numerator (par),
|
|
|
|
divxdec->par_d = gst_value_get_fraction_denominator (par);
|
|
|
|
}
|
|
|
|
|
|
|
|
fps = gst_structure_get_value (structure, "framerate");
|
|
|
|
if (fps != NULL) {
|
|
|
|
divxdec->fps_n = gst_value_get_fraction_numerator (fps);
|
|
|
|
divxdec->fps_d = gst_value_get_fraction_denominator (fps);
|
|
|
|
} else {
|
|
|
|
divxdec->fps_n = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_divxdec_negotiate (divxdec);
|
|
|
|
gst_object_unref (divxdec);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_divxdec_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = parent_class->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2003-07-06 20:49:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-22 14:55:12 +00:00
|
|
|
static gboolean
|
2004-03-14 20:47:18 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2003-04-22 14:55:12 +00:00
|
|
|
{
|
2003-05-30 21:44:53 +00:00
|
|
|
int lib_version;
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
lib_version = decore (NULL, DEC_OPT_VERSION, 0, 0);
|
2003-05-30 21:44:53 +00:00
|
|
|
if (lib_version != DECORE_VERSION) {
|
2004-03-14 20:47:18 +00:00
|
|
|
g_warning ("Version mismatch! This plugin was compiled for "
|
2004-03-15 19:32:27 +00:00
|
|
|
"DivX version %d, while your library has version %d!",
|
|
|
|
DECORE_VERSION, lib_version);
|
2003-11-02 20:37:50 +00:00
|
|
|
return FALSE;
|
2003-05-30 21:44:53 +00:00
|
|
|
}
|
2003-04-22 14:55:12 +00:00
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
return gst_element_register (plugin, "divxdec",
|
|
|
|
GST_RANK_SECONDARY, GST_TYPE_DIVXDEC);
|
2003-04-22 14:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-14 20:47:18 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"divxdec",
|
|
|
|
"DivX decoder",
|
|
|
|
plugin_init,
|
|
|
|
"5.03", GST_LICENSE_UNKNOWN, "divx4linux", "http://www.divx.com/");
|