2002-03-20 21:45:04 +00:00
|
|
|
/* GStreamer
|
2001-12-23 14:25:32 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-23 14:25:32 +00:00
|
|
|
#include <gst/gst.h>
|
2003-07-06 20:49:52 +00:00
|
|
|
#include <gst/video/video.h>
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
#include "gstcolorspace.h"
|
|
|
|
#include "yuv2rgb.h"
|
2002-06-21 18:29:13 +00:00
|
|
|
#include "yuv2yuv.h"
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstElementDetails colorspace_details = {
|
|
|
|
"Colorspace converter",
|
2003-07-19 23:25:25 +00:00
|
|
|
"Filter/Convert",
|
2002-04-20 21:42:51 +00:00
|
|
|
"Converts video from one colorspace to another using libhermes",
|
2001-12-23 14:25:32 +00:00
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Stereo signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_SOURCE,
|
|
|
|
ARG_DEST,
|
|
|
|
};
|
|
|
|
|
2003-11-01 16:42:12 +00:00
|
|
|
static void gst_colorspace_base_init (gpointer g_class);
|
2001-12-23 14:25:32 +00:00
|
|
|
static void gst_colorspace_class_init (GstColorspaceClass *klass);
|
|
|
|
static void gst_colorspace_init (GstColorspace *space);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
static void gst_colorspace_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_colorspace_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_colorspace_sinkconnect (GstPad *pad, GstCaps *caps);
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_colorspace_srcconnect (GstPad *pad, GstCaps *caps);
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_colorspace_srcconnect_func (GstPad *pad, GstCaps *caps, gboolean newcaps);
|
2003-10-08 16:08:19 +00:00
|
|
|
static void gst_colorspace_chain (GstPad *pad, GstData *_data);
|
2002-01-13 22:27:25 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_colorspace_change_state (GstElement *element);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-03-19 04:10:06 +00:00
|
|
|
/* FIXME */
|
2002-01-13 22:27:25 +00:00
|
|
|
extern void gst_colorspace_rgb32_to_i420 (unsigned char *src, unsigned char *dest,
|
|
|
|
guint width, guint height);
|
|
|
|
extern void gst_colorspace_rgb32_to_yv12 (unsigned char *src, unsigned char *dest,
|
|
|
|
guint width, guint height);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
static GstPadTemplate *srctempl, *sinktempl;
|
2001-12-23 14:25:32 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-03-19 04:10:06 +00:00
|
|
|
/*static guint gst_colorspace_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
static GstBufferPool*
|
|
|
|
colorspace_get_bufferpool (GstPad *pad)
|
|
|
|
{
|
|
|
|
GstColorspace *space;
|
|
|
|
|
|
|
|
space = GST_COLORSPACE (gst_pad_get_parent (pad));
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (space->type == GST_COLORSPACE_NONE && !space->disabled)
|
2001-12-23 14:25:32 +00:00
|
|
|
return gst_pad_get_bufferpool (space->srcpad);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2002-01-13 22:27:25 +00:00
|
|
|
colorspace_setup_converter (GstColorspace *space, GstCaps *from_caps, GstCaps *to_caps)
|
2001-12-23 14:25:32 +00:00
|
|
|
{
|
2002-03-30 17:06:26 +00:00
|
|
|
guint32 from_space, to_space;
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (to_caps != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (from_caps != NULL, FALSE);
|
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
if (gst_caps_has_property (from_caps, "format"))
|
|
|
|
gst_caps_get_fourcc_int (from_caps, "format", &from_space);
|
|
|
|
else
|
|
|
|
from_space = GST_MAKE_FOURCC ('R','G','B',' ');
|
|
|
|
|
|
|
|
if (gst_caps_has_property (to_caps, "format"))
|
|
|
|
gst_caps_get_fourcc_int (to_caps, "format", &to_space);
|
|
|
|
else
|
|
|
|
to_space = GST_MAKE_FOURCC ('R','G','B',' ');
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
GST_INFO ("set up converter for " GST_FOURCC_FORMAT
|
|
|
|
" (%08x) to " GST_FOURCC_FORMAT " (%08x)",
|
|
|
|
GST_FOURCC_ARGS (from_space), from_space,
|
|
|
|
GST_FOURCC_ARGS (to_space), to_space);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
switch (from_space) {
|
|
|
|
case GST_MAKE_FOURCC ('R','G','B',' '):
|
2002-01-13 22:27:25 +00:00
|
|
|
{
|
2002-03-30 17:06:26 +00:00
|
|
|
gint from_bpp;
|
|
|
|
|
|
|
|
gst_caps_get_int (from_caps, "bpp", &from_bpp);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2001-12-23 14:25:32 +00:00
|
|
|
switch (to_space) {
|
|
|
|
case GST_MAKE_FOURCC ('R','G','B',' '):
|
2002-01-13 22:27:25 +00:00
|
|
|
#ifdef HAVE_HERMES
|
2001-12-23 14:25:32 +00:00
|
|
|
{
|
2002-03-30 17:06:26 +00:00
|
|
|
gint to_bpp;
|
|
|
|
|
|
|
|
gst_caps_get_int (to_caps, "bpp", &to_bpp);
|
|
|
|
|
|
|
|
gst_caps_get_int (from_caps, "red_mask", &space->source.r);
|
|
|
|
gst_caps_get_int (from_caps, "green_mask", &space->source.g);
|
|
|
|
gst_caps_get_int (from_caps, "blue_mask", &space->source.b);
|
2001-12-23 14:25:32 +00:00
|
|
|
space->source.a = 0;
|
2002-01-13 22:27:25 +00:00
|
|
|
space->srcbpp = space->source.bits = from_bpp;
|
2001-12-23 14:25:32 +00:00
|
|
|
space->source.indexed = 0;
|
|
|
|
space->source.has_colorkey = 0;
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "source red mask %08x", space->source.r);
|
|
|
|
GST_INFO ( "source green mask %08x", space->source.g);
|
|
|
|
GST_INFO ( "source blue mask %08x", space->source.b);
|
|
|
|
GST_INFO ( "source bpp %08x", space->srcbpp);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
gst_caps_get_int (to_caps, "red_mask", &space->dest.r);
|
|
|
|
gst_caps_get_int (to_caps, "green_mask", &space->dest.g);
|
|
|
|
gst_caps_get_int (to_caps, "blue_mask", &space->dest.b);
|
2001-12-23 14:25:32 +00:00
|
|
|
space->dest.a = 0;
|
2002-03-30 17:06:26 +00:00
|
|
|
space->destbpp = space->dest.bits = to_bpp;
|
2001-12-23 14:25:32 +00:00
|
|
|
space->dest.indexed = 0;
|
|
|
|
space->dest.has_colorkey = 0;
|
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "dest red mask %08x", space->dest.r);
|
|
|
|
GST_INFO ( "dest green mask %08x", space->dest.g);
|
|
|
|
GST_INFO ( "dest blue mask %08x", space->dest.b);
|
|
|
|
GST_INFO ( "dest bpp %08x", space->destbpp);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
if (!Hermes_ConverterRequest (space->h_handle, &space->source, &space->dest)) {
|
2002-01-13 22:27:25 +00:00
|
|
|
g_warning ("Hermes: could not get converter\n");
|
2001-12-23 14:25:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "converter set up");
|
2001-12-23 14:25:32 +00:00
|
|
|
space->type = GST_COLORSPACE_HERMES;
|
2002-01-13 22:27:25 +00:00
|
|
|
return TRUE;
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
#else
|
|
|
|
g_warning ("colorspace: compiled without hermes!");
|
|
|
|
return FALSE;
|
2001-12-23 14:25:32 +00:00
|
|
|
#endif
|
2002-01-13 22:27:25 +00:00
|
|
|
case GST_MAKE_FOURCC ('Y','V','1','2'):
|
|
|
|
if (from_bpp == 32) {
|
|
|
|
space->type = GST_COLORSPACE_RGB32_YV12;
|
|
|
|
space->destbpp = 12;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-12-23 14:25:32 +00:00
|
|
|
case GST_MAKE_FOURCC ('I','4','2','0'):
|
2002-01-13 22:27:25 +00:00
|
|
|
if (from_bpp == 32) {
|
|
|
|
space->type = GST_COLORSPACE_RGB32_I420;
|
|
|
|
space->destbpp = 12;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case GST_MAKE_FOURCC ('Y','U','Y','2'):
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "colorspace: RGB to YUV with bpp %d not implemented!!", from_bpp);
|
2002-01-13 22:27:25 +00:00
|
|
|
return FALSE;
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
2001-12-23 14:25:32 +00:00
|
|
|
case GST_MAKE_FOURCC ('I','4','2','0'):
|
|
|
|
switch (to_space) {
|
|
|
|
case GST_MAKE_FOURCC ('R','G','B',' '):
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "colorspace: YUV to RGB");
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
gst_caps_get_int (to_caps, "bpp", &space->destbpp);
|
2001-12-23 14:25:32 +00:00
|
|
|
space->converter = gst_colorspace_yuv2rgb_get_converter (from_caps, to_caps);
|
|
|
|
space->type = GST_COLORSPACE_YUV_RGB;
|
2002-01-13 22:27:25 +00:00
|
|
|
return TRUE;
|
|
|
|
case GST_MAKE_FOURCC ('I','4','2','0'):
|
|
|
|
space->type = GST_COLORSPACE_NONE;
|
|
|
|
space->destbpp = 12;
|
|
|
|
return TRUE;
|
2002-06-21 18:29:13 +00:00
|
|
|
case GST_MAKE_FOURCC ('Y','V','1','2'):
|
|
|
|
space->type = GST_COLORSPACE_420_SWAP;
|
|
|
|
space->destbpp = 12;
|
|
|
|
return TRUE;
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_MAKE_FOURCC ('Y','U','Y','2'):
|
|
|
|
switch (to_space) {
|
2001-12-23 14:25:32 +00:00
|
|
|
case GST_MAKE_FOURCC ('I','4','2','0'):
|
|
|
|
space->type = GST_COLORSPACE_YUY2_I420;
|
|
|
|
space->destbpp = 12;
|
2002-01-13 22:27:25 +00:00
|
|
|
return TRUE;
|
|
|
|
case GST_MAKE_FOURCC ('Y','U','Y','2'):
|
|
|
|
space->type = GST_COLORSPACE_NONE;
|
|
|
|
space->destbpp = 16;
|
|
|
|
return TRUE;
|
2002-06-21 18:29:13 +00:00
|
|
|
case GST_MAKE_FOURCC ('R','G','B',' '):
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "colorspace: YUY2 to RGB not implemented!!");
|
2002-06-21 18:29:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_MAKE_FOURCC ('Y','V','1','2'):
|
|
|
|
switch (to_space) {
|
2002-07-11 15:48:58 +00:00
|
|
|
case GST_MAKE_FOURCC ('R','G','B',' '):
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "colorspace: YV12 to RGB");
|
2002-07-11 15:48:58 +00:00
|
|
|
|
|
|
|
gst_caps_get_int (to_caps, "bpp", &space->destbpp);
|
|
|
|
space->converter = gst_colorspace_yuv2rgb_get_converter (from_caps, to_caps);
|
|
|
|
space->type = GST_COLORSPACE_YUV_RGB;
|
|
|
|
return TRUE;
|
2002-06-21 18:29:13 +00:00
|
|
|
case GST_MAKE_FOURCC ('I','4','2','0'):
|
|
|
|
space->type = GST_COLORSPACE_420_SWAP;
|
|
|
|
space->destbpp = 12;
|
|
|
|
return TRUE;
|
2002-07-11 15:48:58 +00:00
|
|
|
case GST_MAKE_FOURCC ('Y','V','1','2'):
|
|
|
|
space->type = GST_COLORSPACE_NONE;
|
|
|
|
space->destbpp = 12;
|
|
|
|
return TRUE;
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
return FALSE;
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
static GstCaps*
|
|
|
|
gst_colorspace_getcaps (GstPad *pad, GstCaps *caps)
|
2001-12-23 14:25:32 +00:00
|
|
|
{
|
2002-01-13 22:27:25 +00:00
|
|
|
GstColorspace *space;
|
|
|
|
GstCaps *result;
|
|
|
|
GstCaps *peercaps;
|
2003-02-02 20:00:19 +00:00
|
|
|
GstCaps *ourcaps, *temp;
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
space = GST_COLORSPACE (gst_pad_get_parent (pad));
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* we can do everything our peer can... */
|
2003-02-02 20:00:19 +00:00
|
|
|
temp = gst_pad_get_allowed_caps (space->srcpad);
|
|
|
|
peercaps = gst_caps_copy (temp);
|
|
|
|
gst_caps_unref (temp);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* and our own template of course */
|
2003-02-02 20:00:19 +00:00
|
|
|
temp = gst_pad_get_pad_template_caps (pad);
|
|
|
|
ourcaps = gst_caps_copy (temp);
|
|
|
|
gst_caps_unref (temp);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* merge them together, we prefer the peercaps first */
|
|
|
|
result = gst_caps_prepend (ourcaps, peercaps);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_colorspace_sinkconnect (GstPad *pad, GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstColorspace *space;
|
|
|
|
GstPad *peer;
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
space = GST_COLORSPACE (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (!GST_CAPS_IS_FIXED (caps)) {
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
gst_caps_get_int (caps, "width", &space->width);
|
|
|
|
gst_caps_get_int (caps, "height", &space->height);
|
2003-07-06 20:49:52 +00:00
|
|
|
gst_caps_get_float (caps, "framerate", &space->fps);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "size: %dx%d", space->width, space->height);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2003-02-02 20:00:19 +00:00
|
|
|
gst_caps_replace_sink (&space->sinkcaps, caps);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
peer = gst_pad_get_peer (pad);
|
|
|
|
if (peer) {
|
2003-02-02 20:00:19 +00:00
|
|
|
GstCaps *allowed = gst_pad_get_allowed_caps (space->srcpad);
|
|
|
|
if (gst_colorspace_srcconnect_func (pad, allowed, FALSE) < 1) {
|
2002-01-13 22:27:25 +00:00
|
|
|
space->sinkcaps = NULL;
|
2003-02-02 20:00:19 +00:00
|
|
|
gst_caps_unref (allowed);
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
2003-02-02 20:00:19 +00:00
|
|
|
gst_caps_unref (allowed);
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_colorspace_srcconnect (GstPad *pad, GstCaps *caps)
|
2001-12-23 14:25:32 +00:00
|
|
|
{
|
2002-01-13 22:27:25 +00:00
|
|
|
return gst_colorspace_srcconnect_func (pad, caps, TRUE);
|
|
|
|
}
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_colorspace_srcconnect_func (GstPad *pad, GstCaps *caps, gboolean newcaps)
|
|
|
|
{
|
|
|
|
GstColorspace *space;
|
|
|
|
GstCaps *peercaps;
|
2003-02-02 20:00:19 +00:00
|
|
|
GstCaps *ourcaps, *to_intersect, *try_peercaps;
|
2003-05-24 10:20:31 +00:00
|
|
|
GstPadLinkReturn res = GST_PAD_LINK_REFUSED;
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
space = GST_COLORSPACE (gst_pad_get_parent (pad));
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* we cannot operate if we didn't get src caps */
|
|
|
|
ourcaps = space->sinkcaps;
|
|
|
|
if (!ourcaps) {
|
|
|
|
if (newcaps)
|
|
|
|
gst_pad_recalc_allowed_caps (space->sinkpad);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* first see if we can do the format natively by filtering the peer caps
|
|
|
|
* with our incomming caps */
|
|
|
|
peercaps = gst_caps_intersect (caps, ourcaps);
|
|
|
|
if (peercaps) {
|
2003-07-23 07:26:58 +00:00
|
|
|
GstCaps *trycaps;
|
|
|
|
|
|
|
|
trycaps = peercaps;
|
|
|
|
while(trycaps){
|
|
|
|
GstCaps *caps1 = gst_caps_copy_1(trycaps);
|
|
|
|
|
|
|
|
/* see if the peer likes it too, it should as the caps say so.. */
|
|
|
|
if (gst_pad_try_set_caps (space->srcpad, caps1) > 0) {
|
|
|
|
space->type = GST_COLORSPACE_NONE;
|
|
|
|
space->disabled = FALSE;
|
|
|
|
gst_caps_unref (peercaps);
|
|
|
|
peercaps = caps1;
|
|
|
|
res = GST_PAD_LINK_DONE;
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
trycaps = trycaps->next;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
2003-02-02 20:00:19 +00:00
|
|
|
gst_caps_unref (peercaps);
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
2003-02-02 20:00:19 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
to_intersect = gst_caps_append (
|
|
|
|
GST_CAPS_NEW (
|
2002-01-13 22:27:25 +00:00
|
|
|
"colorspace_filter",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-yuv",
|
|
|
|
"width", GST_PROPS_INT (space->width),
|
|
|
|
"height", GST_PROPS_INT (space->height),
|
|
|
|
"framerate", GST_PROPS_FLOAT (space->fps)
|
|
|
|
), GST_CAPS_NEW (
|
|
|
|
"colorspace_filter",
|
|
|
|
"video/x-raw-rgb",
|
|
|
|
"width", GST_PROPS_INT (space->width),
|
|
|
|
"height", GST_PROPS_INT (space->height),
|
|
|
|
"framerate", GST_PROPS_FLOAT (space->fps)
|
|
|
|
));
|
2003-02-02 20:00:19 +00:00
|
|
|
|
|
|
|
/* then see what the peer has that matches the size */
|
|
|
|
peercaps = gst_caps_intersect (caps, to_intersect);
|
|
|
|
gst_caps_unref (to_intersect);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
/* we are looping over the caps, so we have to get rid of the lists */
|
2003-02-02 20:00:19 +00:00
|
|
|
try_peercaps = gst_caps_normalize (peercaps);
|
|
|
|
gst_caps_unref (peercaps);
|
|
|
|
peercaps = try_peercaps;
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
/* loop over all possibilities and select the first one we can convert and
|
|
|
|
* is accepted by the peer */
|
|
|
|
while (peercaps) {
|
2003-07-23 07:26:58 +00:00
|
|
|
GstCaps *peer1 = gst_caps_copy_1(peercaps);
|
|
|
|
|
|
|
|
if (colorspace_setup_converter (space, ourcaps, peer1)) {
|
|
|
|
if (gst_pad_try_set_caps (space->srcpad, peer1) > 0) {
|
2002-01-13 22:27:25 +00:00
|
|
|
space->disabled = FALSE;
|
2003-02-02 20:00:19 +00:00
|
|
|
gst_caps_unref (try_peercaps);
|
2003-05-24 10:20:31 +00:00
|
|
|
res = GST_PAD_LINK_DONE;
|
|
|
|
goto success;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
peercaps = peercaps->next;
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
2003-02-02 20:00:19 +00:00
|
|
|
gst_caps_unref (try_peercaps);
|
2003-05-24 10:20:31 +00:00
|
|
|
|
|
|
|
if (gst_pad_recover_caps_error (space->srcpad, NULL)) {
|
|
|
|
res = GST_PAD_LINK_DONE;
|
|
|
|
goto success;
|
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
/* we disable ourself here */
|
|
|
|
space->disabled = TRUE;
|
2003-05-24 10:20:31 +00:00
|
|
|
goto done;
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2003-05-24 10:20:31 +00:00
|
|
|
success:
|
|
|
|
done:
|
|
|
|
|
|
|
|
return res;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_colorspace_get_type (void)
|
|
|
|
{
|
|
|
|
static GType colorspace_type = 0;
|
|
|
|
|
|
|
|
if (!colorspace_type) {
|
|
|
|
static const GTypeInfo colorspace_info = {
|
2002-03-30 17:06:26 +00:00
|
|
|
sizeof(GstColorspaceClass),
|
2003-11-01 16:42:12 +00:00
|
|
|
gst_colorspace_base_init,
|
2001-12-23 14:25:32 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_colorspace_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstColorspace),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_colorspace_init,
|
|
|
|
};
|
|
|
|
colorspace_type = g_type_register_static(GST_TYPE_ELEMENT, "GstColorspace", &colorspace_info, 0);
|
|
|
|
}
|
|
|
|
return colorspace_type;
|
|
|
|
}
|
|
|
|
|
2003-11-01 16:42:12 +00:00
|
|
|
static void
|
|
|
|
gst_colorspace_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
/* create caps for templates */
|
|
|
|
caps = gst_caps_new ("csp_templ_yuv",
|
|
|
|
"video/x-raw-yuv",
|
|
|
|
GST_VIDEO_YUV_PAD_TEMPLATE_PROPS (
|
|
|
|
GST_PROPS_LIST (
|
|
|
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
|
|
|
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("YV12")),
|
|
|
|
GST_PROPS_FOURCC (GST_STR_FOURCC ("YUY2")))));
|
|
|
|
caps = gst_caps_append (caps,
|
|
|
|
gst_caps_new ("csp_templ_rgb24_32",
|
|
|
|
"video/x-raw-rgb",
|
|
|
|
GST_VIDEO_RGB_PAD_TEMPLATE_PROPS_24_32));
|
|
|
|
caps = gst_caps_append (caps,
|
|
|
|
gst_caps_new ("csp_templ_rgb15",
|
|
|
|
"video/x-raw-rgb",
|
|
|
|
GST_VIDEO_RGB_PAD_TEMPLATE_PROPS_15));
|
|
|
|
caps = gst_caps_append (caps,
|
|
|
|
gst_caps_new ("csp_templ_rgb16",
|
|
|
|
"video/x-raw-rgb",
|
|
|
|
GST_VIDEO_RGB_PAD_TEMPLATE_PROPS_16));
|
|
|
|
|
|
|
|
/* build templates */
|
|
|
|
srctempl = gst_pad_template_new ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
caps, NULL);
|
|
|
|
gst_caps_ref (caps);
|
|
|
|
sinktempl = gst_pad_template_new ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
caps, NULL);
|
|
|
|
gst_element_class_add_pad_template (element_class, srctempl);
|
|
|
|
gst_element_class_add_pad_template (element_class, sinktempl);
|
|
|
|
gst_element_class_set_details (element_class, &colorspace_details);
|
|
|
|
}
|
|
|
|
|
2001-12-23 14:25:32 +00:00
|
|
|
static void
|
|
|
|
gst_colorspace_class_init (GstColorspaceClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_colorspace_set_property;
|
|
|
|
gobject_class->get_property = gst_colorspace_get_property;
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_colorspace_change_state;
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_colorspace_init (GstColorspace *space)
|
|
|
|
{
|
2003-07-06 20:49:52 +00:00
|
|
|
space->sinkpad = gst_pad_new_from_template (sinktempl, "sink");
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (space->sinkpad, gst_colorspace_sinkconnect);
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_pad_set_getcaps_function (space->sinkpad, gst_colorspace_getcaps);
|
2001-12-23 14:25:32 +00:00
|
|
|
gst_pad_set_bufferpool_function (space->sinkpad, colorspace_get_bufferpool);
|
|
|
|
gst_pad_set_chain_function(space->sinkpad,gst_colorspace_chain);
|
|
|
|
gst_element_add_pad(GST_ELEMENT(space),space->sinkpad);
|
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
space->srcpad = gst_pad_new_from_template (srctempl, "src");
|
2001-12-23 14:25:32 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(space),space->srcpad);
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (space->srcpad, gst_colorspace_srcconnect);
|
2001-12-23 14:25:32 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
#ifdef HAVE_HERMES
|
2001-12-23 14:25:32 +00:00
|
|
|
space->h_handle = Hermes_ConverterInstance (0);
|
|
|
|
#endif
|
|
|
|
space->pool = NULL;
|
|
|
|
space->converter = NULL;
|
2002-01-13 22:27:25 +00:00
|
|
|
space->disabled = TRUE;
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-08 16:08:19 +00:00
|
|
|
gst_colorspace_chain (GstPad *pad,GstData *_data)
|
2001-12-23 14:25:32 +00:00
|
|
|
{
|
2003-10-08 16:08:19 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-23 14:25:32 +00:00
|
|
|
GstColorspace *space;
|
|
|
|
gint size;
|
|
|
|
GstBuffer *outbuf = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
|
|
|
space = GST_COLORSPACE (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
g_return_if_fail (space != NULL);
|
|
|
|
g_return_if_fail (GST_IS_COLORSPACE (space));
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (space->disabled) {
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-23 14:25:32 +00:00
|
|
|
if (space->type == GST_COLORSPACE_NONE) {
|
|
|
|
outbuf = buf;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gint dest_bytes, src_bytes;
|
|
|
|
|
|
|
|
size = space->width * space->height;
|
|
|
|
dest_bytes = ((space->destbpp+7)/8);
|
|
|
|
src_bytes = ((space->srcbpp+7)/8);
|
|
|
|
|
2003-07-23 08:20:24 +00:00
|
|
|
if (!space->pool)
|
|
|
|
space->pool = gst_pad_get_bufferpool (space->srcpad);
|
|
|
|
|
2001-12-23 14:25:32 +00:00
|
|
|
if (space->pool) {
|
|
|
|
outbuf = gst_buffer_new_from_pool (space->pool, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!outbuf) {
|
|
|
|
outbuf = gst_buffer_new ();
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE (outbuf) = (size * space->destbpp)/8;
|
|
|
|
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (space->type == GST_COLORSPACE_YUV_RGB) {
|
|
|
|
gst_colorspace_convert (space->converter, GST_BUFFER_DATA (buf), GST_BUFFER_DATA (outbuf));
|
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
#ifdef HAVE_HERMES
|
2001-12-23 14:25:32 +00:00
|
|
|
else if (space->type == GST_COLORSPACE_HERMES) {
|
|
|
|
Hermes_ConverterCopy (space->h_handle,
|
|
|
|
GST_BUFFER_DATA (buf), 0, 0, space->width, space->height, space->width * src_bytes,
|
|
|
|
GST_BUFFER_DATA (outbuf), 0, 0, space->width, space->height, space->width * dest_bytes);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (space->type == GST_COLORSPACE_YUY2_I420) {
|
|
|
|
gst_colorspace_yuy2_to_i420 (GST_BUFFER_DATA (buf),
|
|
|
|
GST_BUFFER_DATA (outbuf),
|
|
|
|
space->width,
|
|
|
|
space->height);
|
|
|
|
}
|
2002-06-21 18:29:13 +00:00
|
|
|
else if (space->type == GST_COLORSPACE_420_SWAP) {
|
|
|
|
gst_colorspace_i420_to_yv12 (GST_BUFFER_DATA (buf),
|
|
|
|
GST_BUFFER_DATA (outbuf),
|
|
|
|
space->width,
|
|
|
|
space->height);
|
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
else if (space->type == GST_COLORSPACE_RGB32_I420) {
|
|
|
|
gst_colorspace_rgb32_to_i420 (GST_BUFFER_DATA (buf),
|
|
|
|
GST_BUFFER_DATA (outbuf),
|
|
|
|
space->width,
|
|
|
|
space->height);
|
|
|
|
}
|
|
|
|
else if (space->type == GST_COLORSPACE_RGB32_YV12) {
|
|
|
|
gst_colorspace_rgb32_to_yv12 (GST_BUFFER_DATA (buf),
|
|
|
|
GST_BUFFER_DATA (outbuf),
|
|
|
|
space->width,
|
|
|
|
space->height);
|
|
|
|
}
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
2003-10-08 16:08:19 +00:00
|
|
|
gst_pad_push (space->srcpad, GST_DATA (outbuf));
|
2001-12-23 14:25:32 +00:00
|
|
|
}
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_colorspace_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstColorspace *space;
|
|
|
|
|
|
|
|
space = GST_COLORSPACE (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
2003-01-12 21:31:16 +00:00
|
|
|
if (space->pool)
|
|
|
|
gst_buffer_pool_unref (space->pool);
|
2002-01-13 22:27:25 +00:00
|
|
|
space->pool = NULL;
|
|
|
|
break;
|
2002-09-12 20:57:09 +00:00
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
gst_colorspace_converter_destroy (space->converter);
|
|
|
|
space->converter = NULL;
|
|
|
|
space->disabled = TRUE;
|
|
|
|
space->type = GST_COLORSPACE_NONE;
|
2003-02-02 20:00:19 +00:00
|
|
|
gst_caps_replace (&space->sinkcaps, NULL);
|
2002-09-12 20:57:09 +00:00
|
|
|
break;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
|
|
|
|
2003-05-24 10:20:31 +00:00
|
|
|
return parent_class->change_state (element);
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-23 14:25:32 +00:00
|
|
|
static void
|
|
|
|
gst_colorspace_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstColorspace *space;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_COLORSPACE(object));
|
|
|
|
space = GST_COLORSPACE(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_colorspace_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstColorspace *space;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_COLORSPACE(object));
|
|
|
|
space = GST_COLORSPACE(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-11-01 16:42:12 +00:00
|
|
|
plugin_init (GstPlugin *plugin)
|
2001-12-23 14:25:32 +00:00
|
|
|
{
|
2002-01-13 22:27:25 +00:00
|
|
|
#ifdef HAVE_HERMES
|
2001-12-23 14:25:32 +00:00
|
|
|
gint hermes_res;
|
|
|
|
|
|
|
|
hermes_res = Hermes_Init();
|
|
|
|
g_return_val_if_fail (hermes_res != 0, FALSE);
|
|
|
|
#endif
|
|
|
|
|
2003-11-01 16:42:12 +00:00
|
|
|
if (!gst_element_register (plugin, "colorspace", GST_RANK_PRIMARY, GST_TYPE_COLORSPACE))
|
|
|
|
return FALSE;
|
2001-12-23 14:25:32 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-01 16:42:12 +00:00
|
|
|
GST_PLUGIN_DEFINE (
|
2001-12-23 14:25:32 +00:00
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"colorspace",
|
2003-11-01 16:42:12 +00:00
|
|
|
"Hermes colorspace converter",
|
|
|
|
plugin_init,
|
|
|
|
VERSION,
|
|
|
|
"LGPL",
|
|
|
|
GST_COPYRIGHT,
|
|
|
|
GST_PACKAGE,
|
|
|
|
GST_ORIGIN)
|
2001-12-23 14:25:32 +00:00
|
|
|
|