remove copyright field from plugins
[platform/upstream/gst-plugins-good.git] / gst / median / gstmedian.c
index f0e836a..b4d4166 100644 (file)
@@ -1,4 +1,4 @@
-/* Gnome-Streamer
+/* GStreamer
  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
  *
  * This library is free software; you can redistribute it and/or
  * Boston, MA 02111-1307, USA.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include <string.h>
 #include <gstmedian.h>
+#include <gst/video/video.h>
 
-
+/* elementfactory information */
 static GstElementDetails median_details = {
   "Median effect",
-  "Filter/Effect",
-  "apply a median filter to an image",
-  VERSION,
-  "Wim Taymans <wim.taymans@chello.be>",
-  "(C) 2000",
+  "Filter/Effect/Video",
+  "Apply a median filter to an image",
+  "Wim Taymans <wim.taymans@chello.be>"
 };
 
-GST_PADTEMPLATE_FACTORY (median_src_factory,
+GST_PAD_TEMPLATE_FACTORY (median_src_factory,
   "src",
   GST_PAD_SRC,
   GST_PAD_ALWAYS,
-  GST_CAPS_NEW (
+  gst_caps_new (
    "median_src",
-   "video/raw",
-     "format",   GST_PROPS_FOURCC (GST_STR_FOURCC ("I420"))
+   "video/x-raw-yuv",
+    GST_VIDEO_YUV_PAD_TEMPLATE_PROPS (
+      GST_PROPS_FOURCC (GST_STR_FOURCC ("I420"))
+    )
   )
 )
 
-GST_PADTEMPLATE_FACTORY (median_sink_factory,
+GST_PAD_TEMPLATE_FACTORY (median_sink_factory,
   "sink",
   GST_PAD_SINK,
   GST_PAD_ALWAYS,
-  GST_CAPS_NEW (
-   "median_src",
-   "video/raw",
-     "format",   GST_PROPS_FOURCC (GST_STR_FOURCC ("I420"))
+  gst_caps_new (
+    "median_src",
+    "video/x-raw-yuv",
+    GST_VIDEO_YUV_PAD_TEMPLATE_PROPS (
+      GST_PROPS_FOURCC (GST_STR_FOURCC ("I420"))
+    )
   )
 )
 
@@ -68,39 +74,18 @@ enum {
 
 static GType   gst_median_get_type     (void);
 static void    gst_median_class_init   (GstMedianClass *klass);
+static void    gst_median_base_init    (GstMedianClass *klass);
 static void    gst_median_init         (GstMedian *median);
 
 static void    median_5                (unsigned char *src, unsigned char *dest, int height, int width);
 static void    median_9                (unsigned char *src, unsigned char *dest, int height, int width);
-static void    gst_median_chain        (GstPad *pad, GstBuffer *buf);
+static void    gst_median_chain        (GstPad *pad, GstData *_data);
 
 static void    gst_median_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 static void    gst_median_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
 
 static GstElementClass *parent_class = NULL;
-//static guint gst_median_signals[LAST_SIGNAL] = { 0 };
-
-static GstPadNegotiateReturn
-median_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data)
-{
-  GstMedian* filter = GST_MEDIAN (gst_pad_get_parent (pad));
-
-  if (*caps==NULL)
-    return GST_PAD_NEGOTIATE_FAIL;
-
-  return gst_pad_negotiate_proxy (pad, filter->sinkpad, caps);
-}
-
-static GstPadNegotiateReturn
-median_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data)
-{
-  GstMedian* filter = GST_MEDIAN (gst_pad_get_parent (pad));
-
-  if (*caps==NULL)
-    return GST_PAD_NEGOTIATE_FAIL;
-
-  return gst_pad_negotiate_proxy (pad, filter->srcpad, caps);
-}
+/*static guint gst_median_signals[LAST_SIGNAL] = { 0 }; */
 
 GType
 gst_median_get_type (void)
@@ -109,7 +94,10 @@ gst_median_get_type (void)
 
   if (!median_type) {
     static const GTypeInfo median_info = {
-      sizeof(GstMedianClass),      NULL,      NULL,      (GClassInitFunc)gst_median_class_init,
+      sizeof(GstMedianClass),
+      (GBaseInitFunc)gst_median_base_init,
+      NULL,
+      (GClassInitFunc)gst_median_class_init,
       NULL,
       NULL,
       sizeof(GstMedian),
@@ -122,6 +110,18 @@ gst_median_get_type (void)
 }
 
 static void
+gst_median_base_init (GstMedianClass *klass)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+  gst_element_class_add_pad_template (element_class,
+       GST_PAD_TEMPLATE_GET (median_sink_factory));
+  gst_element_class_add_pad_template (element_class,
+       GST_PAD_TEMPLATE_GET (median_src_factory));
+  gst_element_class_set_details (element_class, &median_details);
+}
+
+static void
 gst_median_class_init (GstMedianClass *klass)
 {
   GObjectClass *gobject_class;
@@ -134,41 +134,45 @@ gst_median_class_init (GstMedianClass *klass)
 
   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_ACTIVE,
     g_param_spec_boolean("active","active","active",
-                         TRUE,G_PARAM_READWRITE)); // CHECKME
+                         TRUE,G_PARAM_READWRITE)); /* CHECKME */
   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FILTERSIZE,
     g_param_spec_int("filtersize","filtersize","filtersize",
-                     G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); // CHECKME
+                     G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LUM_ONLY,
     g_param_spec_boolean("lum_only","lum_only","lum_only",
-                         TRUE,G_PARAM_READWRITE)); // CHECKME
+                         TRUE,G_PARAM_READWRITE)); /* CHECKME */
 
   gobject_class->set_property = gst_median_set_property;
   gobject_class->get_property = gst_median_get_property;
 }
 
-static void
-gst_median_newcaps (GstPad *pad, GstCaps *caps)
+static gboolean
+gst_median_sinkconnect (GstPad *pad, GstCaps *caps)
 {
   GstMedian *filter;
 
   filter = GST_MEDIAN (gst_pad_get_parent (pad));
 
-  filter->width = gst_caps_get_int (caps, "width");
-  filter->height = gst_caps_get_int (caps, "height");
+  if (!GST_CAPS_IS_FIXED (caps))
+    return GST_PAD_LINK_DELAYED;
+
+  gst_caps_get_int (caps, "width", &filter->width);
+  gst_caps_get_int (caps, "height", &filter->height);
+
+  /* forward to the next plugin */
+  return gst_pad_try_set_caps(filter->srcpad, gst_caps_copy_1(caps));
 }
 
 void gst_median_init (GstMedian *median)
 {
   median->sinkpad = gst_pad_new_from_template (
-                 GST_PADTEMPLATE_GET (median_sink_factory), "sink");
-  gst_pad_set_negotiate_function (median->sinkpad, median_negotiate_sink);
-  gst_pad_set_newcaps_function (median->sinkpad, gst_median_newcaps);
+                 GST_PAD_TEMPLATE_GET (median_sink_factory), "sink");
+  gst_pad_set_link_function (median->sinkpad, gst_median_sinkconnect);
   gst_pad_set_chain_function (median->sinkpad, gst_median_chain);
   gst_element_add_pad (GST_ELEMENT (median), median->sinkpad);
 
   median->srcpad = gst_pad_new_from_template (
-                 GST_PADTEMPLATE_GET (median_src_factory), "src");
-  gst_pad_set_negotiate_function (median->srcpad, median_negotiate_src);
+                 GST_PAD_TEMPLATE_GET (median_src_factory), "src");
   gst_element_add_pad (GST_ELEMENT (median), median->srcpad);
 
   median->filtersize = 5;
@@ -190,7 +194,7 @@ median_5 (unsigned char *src, unsigned char *dest, int width, int height)
   nLastCol = width - 1;
   nLastRow = height - 1;
 
-  //copy the top and bottom rows into the result array
+  /*copy the top and bottom rows into the result array */
   for (i=0; i<width; i++) {
     dest[i] = src[i];
     dest[nLastRow * width + i] = src[nLastRow * width + i];
@@ -214,10 +218,13 @@ median_5 (unsigned char *src, unsigned char *dest, int width, int height)
       PIX_SORT(p[1],p[2]) ;
       dest[i] = p[2];
     }
-    dest[i] = src[i++];
-    dest[i] = src[i++];
+    dest[i] = src[i];
+    i++;
+    dest[i] = src[i];
+    i++;
   }
-  dest[i] = src[i++];
+  dest[i] = src[i];
+  i++;
 }
 
 static void
@@ -231,7 +238,7 @@ median_9 (unsigned char *src, unsigned char *dest, int width, int height)
   nLastCol = width - 1;
   nLastRow = height - 1;
 
-  //copy the top and bottom rows into the result array
+  /*copy the top and bottom rows into the result array */
   for (i=0; i<width; i++) {
     dest[i] = src[i];
     dest[nLastRow * width + i] = src[nLastRow * width + i];
@@ -263,20 +270,24 @@ median_9 (unsigned char *src, unsigned char *dest, int width, int height)
       PIX_SORT(p[4], p[2]) ;
       dest[i] = p[4];
     }
-    dest[i] = src[i++];
-    dest[i] = src[i++];
+    dest[i] = src[i];
+    i++;
+    dest[i] = src[i];
+    i++;
   }
-  dest[i] = src[i++];
+  dest[i] = src[i];
+  i++;
 }
 
 static void
-gst_median_chain (GstPad *pad, GstBuffer *buf)
+gst_median_chain (GstPad *pad, GstData *_data)
 {
+  GstBuffer *buf = GST_BUFFER (_data);
   GstMedian *median;
   guchar *data;
   gulong size;
   GstBuffer *outbuf;
-//  GstMeta *meta;
+/*  GstMeta *meta; */
   int lumsize, chromsize;
 
   g_return_if_fail(pad != NULL);
@@ -286,14 +297,14 @@ gst_median_chain (GstPad *pad, GstBuffer *buf)
   median = GST_MEDIAN (GST_OBJECT_PARENT (pad));
 
   if (!median->active) {
-    gst_pad_push(median->srcpad,buf);
+    gst_pad_push(median->srcpad,GST_DATA (buf));
     return;
   }
 
   data = GST_BUFFER_DATA(buf);
   size = GST_BUFFER_SIZE(buf);
 
-  GST_DEBUG (0,"median: have buffer of %d\n", GST_BUFFER_SIZE(buf));
+  GST_DEBUG ("median: have buffer of %d", GST_BUFFER_SIZE(buf));
 
   outbuf = gst_buffer_new();
   GST_BUFFER_DATA(outbuf) = g_malloc(GST_BUFFER_SIZE(buf));
@@ -326,7 +337,7 @@ gst_median_chain (GstPad *pad, GstBuffer *buf)
 
   gst_buffer_unref(buf);
 
-  gst_pad_push(median->srcpad,outbuf);
+  gst_pad_push(median->srcpad,GST_DATA (outbuf));
 }
 
 static void
@@ -387,26 +398,20 @@ gst_median_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
 
 
 static gboolean
-plugin_init (GModule *module, GstPlugin *plugin)
+plugin_init (GstPlugin *plugin)
 {
-  GstElementFactory *factory;
-
-  factory = gst_elementfactory_new("median",GST_TYPE_MEDIAN,
-                                   &median_details);
-  g_return_val_if_fail(factory != NULL, FALSE);
-
-  gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (median_sink_factory));
-  gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (median_src_factory));
-
-  gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
-
-  return TRUE;
+  return gst_element_register (plugin, "median",
+                              GST_RANK_NONE, GST_TYPE_MEDIAN);
 }
 
-GstPluginDesc plugin_desc = {
+GST_PLUGIN_DEFINE (
   GST_VERSION_MAJOR,
   GST_VERSION_MINOR,
   "median",
-  plugin_init
-};
-
+  "Video median filter",
+  plugin_init,
+  VERSION,
+  GST_LICENSE,
+  GST_PACKAGE,
+  GST_ORIGIN
+)