2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:27:17 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-03-19 04:10:06 +00:00
|
|
|
/*#define DEBUG_ENABLED */
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:27:17 +00:00
|
|
|
#include <gstvideoscale.h>
|
2003-04-22 07:32:50 +00:00
|
|
|
#include <videoscale.h>
|
2001-12-22 23:27:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* elementfactory information */
|
2003-11-02 20:48:33 +00:00
|
|
|
static GstElementDetails videoscale_details = GST_ELEMENT_DETAILS (
|
2001-12-22 23:27:17 +00:00
|
|
|
"Video scaler",
|
2003-11-16 22:02:21 +00:00
|
|
|
"Filter/Effect/Video",
|
2001-12-22 23:27:17 +00:00
|
|
|
"Resizes video",
|
2003-11-02 20:48:33 +00:00
|
|
|
"Wim Taymans <wim.taymans@chello.be>"
|
|
|
|
);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
|
|
|
/* GstVideoscale signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_METHOD,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_TYPE_VIDEOSCALE_METHOD (gst_videoscale_method_get_type())
|
|
|
|
static GType
|
|
|
|
gst_videoscale_method_get_type (void)
|
|
|
|
{
|
|
|
|
static GType videoscale_method_type = 0;
|
|
|
|
static GEnumValue videoscale_methods[] = {
|
|
|
|
{ GST_VIDEOSCALE_POINT_SAMPLE, "0", "Point Sample" },
|
|
|
|
{ GST_VIDEOSCALE_NEAREST, "1", "Nearest" },
|
|
|
|
{ GST_VIDEOSCALE_BILINEAR, "2", "Bilinear" },
|
|
|
|
{ GST_VIDEOSCALE_BICUBIC, "3", "Bicubic" },
|
|
|
|
{ 0, NULL, NULL },
|
|
|
|
};
|
|
|
|
if (!videoscale_method_type) {
|
|
|
|
videoscale_method_type = g_enum_register_static ("GstVideoscaleMethod", videoscale_methods);
|
|
|
|
}
|
|
|
|
return videoscale_method_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_videoscale_get_capslist(void)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2003-11-02 20:48:33 +00:00
|
|
|
static GstCaps *capslist = NULL;
|
|
|
|
GstCaps *caps;
|
|
|
|
int i;
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
if (capslist){
|
|
|
|
gst_caps_ref(capslist);
|
|
|
|
return capslist;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
for(i=0;i<videoscale_n_formats;i++){
|
|
|
|
caps = videoscale_get_caps(videoscale_formats + i);
|
|
|
|
capslist = gst_caps_append(capslist, caps);
|
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
gst_caps_ref(capslist);
|
|
|
|
return capslist;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
static GstPadTemplate *
|
|
|
|
gst_videoscale_src_template_factory(void)
|
|
|
|
{
|
|
|
|
static GstPadTemplate *templ = NULL;
|
|
|
|
|
|
|
|
if(!templ){
|
2003-07-06 20:49:52 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstCaps *caps1 = GST_CAPS_NEW("src","video/x-raw-yuv",
|
2003-04-22 07:32:50 +00:00
|
|
|
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
2003-07-06 20:49:52 +00:00
|
|
|
"height", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
|
|
|
|
GstCaps *caps2 = GST_CAPS_NEW("src","video/x-raw-rgb",
|
|
|
|
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
caps = gst_caps_intersect(caps1, gst_videoscale_get_capslist ());
|
|
|
|
gst_caps_unref (caps1);
|
|
|
|
caps1 = caps;
|
|
|
|
caps = gst_caps_intersect(caps2, gst_videoscale_get_capslist ());
|
|
|
|
gst_caps_unref (caps2);
|
|
|
|
caps2 = caps;
|
|
|
|
caps = gst_caps_append(caps1, caps2);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
|
|
|
templ = GST_PAD_TEMPLATE_NEW("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
|
|
|
|
}
|
|
|
|
return templ;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadTemplate *
|
|
|
|
gst_videoscale_sink_template_factory(void)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2003-04-22 07:32:50 +00:00
|
|
|
static GstPadTemplate *templ = NULL;
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
if(!templ){
|
2003-07-06 20:49:52 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstCaps *caps1 = GST_CAPS_NEW("src","video/x-raw-yuv",
|
|
|
|
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
|
|
|
|
GstCaps *caps2 = GST_CAPS_NEW("src","video/x-raw-rgb",
|
2003-04-22 07:32:50 +00:00
|
|
|
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
2003-07-06 20:49:52 +00:00
|
|
|
"height", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-07-06 20:49:52 +00:00
|
|
|
caps = gst_caps_intersect(caps1, gst_videoscale_get_capslist ());
|
|
|
|
gst_caps_unref (caps1);
|
|
|
|
caps1 = caps;
|
|
|
|
caps = gst_caps_intersect(caps2, gst_videoscale_get_capslist ());
|
|
|
|
gst_caps_unref (caps2);
|
|
|
|
caps2 = caps;
|
|
|
|
caps = gst_caps_append(caps1, caps2);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
templ = GST_PAD_TEMPLATE_NEW("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
return templ;
|
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
static void gst_videoscale_base_init (gpointer g_class);
|
|
|
|
static void gst_videoscale_class_init (GstVideoscaleClass *klass);
|
|
|
|
static void gst_videoscale_init (GstVideoscale *videoscale);
|
|
|
|
|
|
|
|
static void gst_videoscale_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_videoscale_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gst_videoscale_chain (GstPad *pad, GstData *_data);
|
|
|
|
static GstCaps * gst_videoscale_get_capslist(void);
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
/*static guint gst_videoscale_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_videoscale_get_type (void)
|
2003-04-22 07:32:50 +00:00
|
|
|
{
|
2003-11-02 20:48:33 +00:00
|
|
|
static GType videoscale_type = 0;
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
if (!videoscale_type) {
|
|
|
|
static const GTypeInfo videoscale_info = {
|
|
|
|
sizeof(GstVideoscaleClass),
|
|
|
|
gst_videoscale_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_videoscale_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstVideoscale),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_videoscale_init,
|
|
|
|
};
|
|
|
|
videoscale_type = g_type_register_static(GST_TYPE_ELEMENT, "GstVideoscale", &videoscale_info, 0);
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
2003-11-02 20:48:33 +00:00
|
|
|
return videoscale_type;
|
|
|
|
}
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
static void
|
|
|
|
gst_videoscale_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &videoscale_details);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class, GST_PAD_TEMPLATE_GET (gst_videoscale_sink_template_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class, GST_PAD_TEMPLATE_GET (gst_videoscale_src_template_factory));
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
gst_videoscale_class_init (GstVideoscaleClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_METHOD,
|
|
|
|
g_param_spec_enum("method","method","method",
|
|
|
|
GST_TYPE_VIDEOSCALE_METHOD,0,G_PARAM_READWRITE)); /* CHECKME! */
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_videoscale_set_property;
|
|
|
|
gobject_class->get_property = gst_videoscale_get_property;
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_videoscale_getcaps (GstPad *pad, GstCaps *caps)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2003-04-22 07:32:50 +00:00
|
|
|
GstVideoscale *videoscale;
|
2003-11-11 05:35:31 +00:00
|
|
|
//GstCaps *capslist = NULL;
|
2003-04-22 07:32:50 +00:00
|
|
|
GstCaps *peercaps;
|
2003-11-11 05:35:31 +00:00
|
|
|
//GstCaps *sizecaps1, *sizecaps2;
|
|
|
|
//GstCaps *sizecaps;
|
|
|
|
GstCaps *handled_caps;
|
|
|
|
GstCaps *icaps;
|
|
|
|
GstPad *otherpad;
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG ("gst_videoscale_getcaps");
|
2003-04-22 07:32:50 +00:00
|
|
|
videoscale = GST_VIDEOSCALE (gst_pad_get_parent (pad));
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
/* get list of peer's caps */
|
|
|
|
if(pad == videoscale->srcpad){
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG("getting caps of srcpad");
|
|
|
|
otherpad = videoscale->sinkpad;
|
2003-04-22 07:32:50 +00:00
|
|
|
}else{
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG("getting caps of sinkpad");
|
|
|
|
otherpad = videoscale->srcpad;
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
2003-11-11 05:35:31 +00:00
|
|
|
if (!GST_PAD_IS_LINKED (otherpad)){
|
|
|
|
GST_DEBUG ("otherpad not linked");
|
|
|
|
return GST_PAD_LINK_DELAYED;
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
2003-11-11 05:35:31 +00:00
|
|
|
peercaps = gst_pad_get_allowed_caps (GST_PAD_PEER(otherpad));
|
|
|
|
|
|
|
|
GST_DEBUG("othercaps are %s", gst_caps_to_string(peercaps));
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps1 = GST_CAPS_NEW("src","video/x-raw-yuv",
|
2003-04-22 07:32:50 +00:00
|
|
|
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
2003-07-06 20:49:52 +00:00
|
|
|
"height", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
|
2003-11-11 05:35:31 +00:00
|
|
|
GstCaps *caps2 = GST_CAPS_NEW("src","video/x-raw-rgb",
|
2003-07-06 20:49:52 +00:00
|
|
|
"width", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (0, G_MAXINT),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
|
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
caps = gst_caps_intersect(caps1, gst_videoscale_get_capslist ());
|
|
|
|
gst_caps_unref (caps1);
|
|
|
|
caps1 = caps;
|
|
|
|
caps = gst_caps_intersect(caps2, gst_videoscale_get_capslist ());
|
|
|
|
gst_caps_unref (caps2);
|
|
|
|
caps2 = caps;
|
|
|
|
handled_caps = gst_caps_append(caps1, caps2);
|
|
|
|
}
|
|
|
|
|
|
|
|
icaps = gst_caps_intersect (handled_caps, gst_caps_copy(peercaps));
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG("returning caps %s", gst_caps_to_string (icaps));
|
|
|
|
|
|
|
|
return icaps;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2003-11-11 05:35:31 +00:00
|
|
|
gst_videoscale_link (GstPad *pad, GstCaps *caps)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
|
|
|
GstVideoscale *videoscale;
|
2003-04-22 07:32:50 +00:00
|
|
|
GstPadLinkReturn ret;
|
2003-11-11 05:35:31 +00:00
|
|
|
GstCaps *othercaps;
|
|
|
|
GstPad *otherpad;
|
|
|
|
GstCaps *icaps;
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG ("gst_videoscale_link");
|
2001-12-22 23:27:17 +00:00
|
|
|
videoscale = GST_VIDEOSCALE (gst_pad_get_parent (pad));
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
if (pad == videoscale->srcpad) {
|
|
|
|
otherpad = videoscale->sinkpad;
|
|
|
|
} else {
|
|
|
|
otherpad = videoscale->srcpad;
|
|
|
|
}
|
|
|
|
if (otherpad == NULL) {
|
|
|
|
return GST_PAD_LINK_DELAYED;
|
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
othercaps = GST_PAD_CAPS (otherpad);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
if (othercaps) {
|
|
|
|
GstCaps *othercaps_wh;
|
2003-09-14 11:25:48 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG ("otherpad caps are already set");
|
|
|
|
GST_DEBUG ("otherpad caps are %s", gst_caps_to_string(othercaps));
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
othercaps_wh = gst_caps_copy (othercaps);
|
|
|
|
gst_caps_set(othercaps_wh, "width", GST_PROPS_INT_RANGE (1, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (1, G_MAXINT), NULL);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
#if 1
|
|
|
|
icaps = othercaps;
|
|
|
|
#else
|
|
|
|
/* FIXME this is disabled because videotestsrc ! videoscale ! ximagesink
|
|
|
|
* doesn't negotiate caps correctly the first time, so we pretend it's
|
|
|
|
* still ok here. */
|
|
|
|
icaps = gst_caps_intersect (othercaps_wh, caps);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG ("intersected caps are %s", gst_caps_to_string(icaps));
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
if (icaps == NULL) {
|
|
|
|
/* the new caps are not compatible with the existing, set caps */
|
|
|
|
/* currently, we don't force renegotiation */
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
|
|
|
#endif
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
if (!GST_CAPS_IS_FIXED (icaps)) {
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
/* ok, we have a candidate caps */
|
|
|
|
} else {
|
|
|
|
GstCaps *othercaps_wh;
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG ("otherpad caps are unset");
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
othercaps = gst_pad_get_allowed_caps (pad);
|
2003-06-30 05:21:09 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
othercaps_wh = gst_caps_copy (othercaps);
|
|
|
|
gst_caps_set(othercaps_wh, "width", GST_PROPS_INT_RANGE (1, G_MAXINT),
|
|
|
|
"height", GST_PROPS_INT_RANGE (1, G_MAXINT), NULL);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
icaps = gst_caps_intersect (othercaps_wh, caps);
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
GST_DEBUG ("intersected caps are %s", gst_caps_to_string(icaps));
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
if (icaps == NULL) {
|
|
|
|
/* the new caps are not compatible with the existing, set caps */
|
|
|
|
/* currently, we don't force renegotiation */
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
if (!GST_CAPS_IS_FIXED (icaps)) {
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
/* ok, we have a candidate caps */
|
|
|
|
ret = gst_pad_try_set_caps (otherpad, gst_caps_copy(icaps));
|
|
|
|
if (ret == GST_PAD_LINK_DELAYED || ret == GST_PAD_LINK_REFUSED) {
|
|
|
|
return ret;
|
|
|
|
}
|
2003-09-14 11:25:48 +00:00
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
if (pad == videoscale->srcpad) {
|
|
|
|
gst_caps_get_int (icaps, "width", &videoscale->from_width);
|
|
|
|
gst_caps_get_int (icaps, "height", &videoscale->from_height);
|
|
|
|
gst_caps_get_int (caps, "width", &videoscale->to_width);
|
|
|
|
gst_caps_get_int (caps, "height", &videoscale->to_height);
|
|
|
|
} else {
|
|
|
|
gst_caps_get_int (icaps, "width", &videoscale->to_width);
|
|
|
|
gst_caps_get_int (icaps, "height", &videoscale->to_height);
|
|
|
|
gst_caps_get_int (caps, "width", &videoscale->from_width);
|
|
|
|
gst_caps_get_int (caps, "height", &videoscale->from_height);
|
2003-04-22 07:32:50 +00:00
|
|
|
}
|
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
videoscale->format = videoscale_find_by_caps (caps);
|
2003-09-14 11:25:48 +00:00
|
|
|
gst_videoscale_setup(videoscale);
|
|
|
|
|
2003-11-11 05:35:31 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_videoscale_init (GstVideoscale *videoscale)
|
|
|
|
{
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_videoscale_init");
|
2001-12-22 23:27:17 +00:00
|
|
|
videoscale->sinkpad = gst_pad_new_from_template (
|
2003-04-22 07:32:50 +00:00
|
|
|
GST_PAD_TEMPLATE_GET (gst_videoscale_sink_template_factory),
|
|
|
|
"sink");
|
2001-12-22 23:27:17 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(videoscale),videoscale->sinkpad);
|
|
|
|
gst_pad_set_chain_function(videoscale->sinkpad,gst_videoscale_chain);
|
2003-11-11 05:35:31 +00:00
|
|
|
gst_pad_set_link_function(videoscale->sinkpad,gst_videoscale_link);
|
2003-04-22 07:32:50 +00:00
|
|
|
gst_pad_set_getcaps_function(videoscale->sinkpad,gst_videoscale_getcaps);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
|
|
|
videoscale->srcpad = gst_pad_new_from_template (
|
2003-04-22 07:32:50 +00:00
|
|
|
GST_PAD_TEMPLATE_GET (gst_videoscale_src_template_factory),
|
|
|
|
"src");
|
2001-12-22 23:27:17 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(videoscale),videoscale->srcpad);
|
2003-11-11 05:35:31 +00:00
|
|
|
gst_pad_set_link_function(videoscale->srcpad,gst_videoscale_link);
|
2003-04-22 07:32:50 +00:00
|
|
|
gst_pad_set_getcaps_function(videoscale->srcpad,gst_videoscale_getcaps);
|
|
|
|
|
|
|
|
videoscale->inited = FALSE;
|
2001-12-22 23:27:17 +00:00
|
|
|
|
|
|
|
videoscale->method = GST_VIDEOSCALE_NEAREST;
|
2002-03-19 04:10:06 +00:00
|
|
|
/*videoscale->method = GST_VIDEOSCALE_BILINEAR; */
|
|
|
|
/*videoscale->method = GST_VIDEOSCALE_POINT_SAMPLE; */
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-10-08 16:08:22 +00:00
|
|
|
gst_videoscale_chain (GstPad *pad, GstData *_data)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2003-10-08 16:08:22 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-22 23:27:17 +00:00
|
|
|
GstVideoscale *videoscale;
|
|
|
|
guchar *data;
|
|
|
|
gulong size;
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_videoscale_chain");
|
2001-12-22 23:27:17 +00:00
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
|
|
|
videoscale = GST_VIDEOSCALE (gst_pad_get_parent (pad));
|
2003-04-22 07:32:50 +00:00
|
|
|
g_return_if_fail (videoscale->inited);
|
|
|
|
|
2001-12-22 23:27:17 +00:00
|
|
|
data = GST_BUFFER_DATA(buf);
|
|
|
|
size = GST_BUFFER_SIZE(buf);
|
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
if(videoscale->passthru){
|
2003-10-08 16:08:22 +00:00
|
|
|
gst_pad_push(videoscale->srcpad, GST_DATA (buf));
|
2003-04-22 07:32:50 +00:00
|
|
|
return;
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
2003-04-22 07:32:50 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_videoscale_chain: got buffer of %ld bytes in '%s'",size,
|
2001-12-22 23:27:17 +00:00
|
|
|
GST_OBJECT_NAME (videoscale));
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("size=%ld from=%dx%d to=%dx%d fromsize=%ld (should be %d) tosize=%d",
|
2001-12-22 23:27:17 +00:00
|
|
|
size,
|
2003-04-22 07:32:50 +00:00
|
|
|
videoscale->from_width, videoscale->from_height,
|
|
|
|
videoscale->to_width, videoscale->to_height,
|
|
|
|
size, videoscale->from_buf_size,
|
|
|
|
videoscale->to_buf_size);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
g_return_if_fail (size == videoscale->from_buf_size);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
outbuf = gst_buffer_new();
|
|
|
|
/* FIXME: handle bufferpools */
|
|
|
|
GST_BUFFER_SIZE(outbuf) = videoscale->to_buf_size;
|
|
|
|
GST_BUFFER_DATA(outbuf) = g_malloc (videoscale->to_buf_size);
|
|
|
|
GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(buf);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
g_return_if_fail(videoscale->format);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("format %s",videoscale->format->fourcc);
|
2003-04-22 07:32:50 +00:00
|
|
|
g_return_if_fail(videoscale->format->scale);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-04-22 07:32:50 +00:00
|
|
|
videoscale->format->scale(videoscale, GST_BUFFER_DATA(outbuf), data);
|
2001-12-22 23:27:17 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_videoscale_chain: pushing buffer of %d bytes in '%s'",GST_BUFFER_SIZE(outbuf),
|
2003-04-22 07:32:50 +00:00
|
|
|
GST_OBJECT_NAME (videoscale));
|
|
|
|
|
2003-10-08 16:08:22 +00:00
|
|
|
gst_pad_push(videoscale->srcpad, GST_DATA (outbuf));
|
2003-04-22 07:32:50 +00:00
|
|
|
|
|
|
|
gst_buffer_unref(buf);
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_videoscale_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstVideoscale *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_VIDEOSCALE(object));
|
|
|
|
src = GST_VIDEOSCALE(object);
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_videoscale_set_property");
|
2001-12-22 23:27:17 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_METHOD:
|
2002-04-14 10:22:24 +00:00
|
|
|
src->method = g_value_get_enum (value);
|
2001-12-22 23:27:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_videoscale_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstVideoscale *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_VIDEOSCALE(object));
|
|
|
|
src = GST_VIDEOSCALE(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_METHOD:
|
2002-04-14 10:22:24 +00:00
|
|
|
g_value_set_enum (value, src->method);
|
2001-12-22 23:27:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2003-11-02 20:48:33 +00:00
|
|
|
plugin_init (GstPlugin *plugin)
|
2001-12-22 23:27:17 +00:00
|
|
|
{
|
2003-11-02 20:48:33 +00:00
|
|
|
return gst_element_register (plugin, "videoscale", GST_RANK_NONE, GST_TYPE_VIDEOSCALE);
|
2001-12-22 23:27:17 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 20:48:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (
|
2001-12-22 23:27:17 +00:00
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"videoscale",
|
2003-11-02 20:48:33 +00:00
|
|
|
"Resizes video",
|
|
|
|
plugin_init,
|
|
|
|
VERSION,
|
|
|
|
GST_LICENSE,
|
|
|
|
GST_PACKAGE,
|
|
|
|
GST_ORIGIN
|
|
|
|
)
|