Merge remote-tracking branch 'origin/master' into 0.11
[platform/upstream/gstreamer.git] / gst / effectv / gstwarp.c
index c460217..80161a7 100644 (file)
@@ -54,6 +54,8 @@
 #include <math.h>
 
 #include "gstwarp.h"
+#include <gst/video/gstvideometa.h>
+#include <gst/video/gstvideopool.h>
 
 #ifndef M_PI
 #define M_PI    3.14159265358979323846
@@ -63,7 +65,6 @@
 G_DEFINE_TYPE (GstWarpTV, gst_warptv, GST_TYPE_VIDEO_FILTER);
 
 static void initSinTable ();
-static void initOffsTable (GstWarpTV * filter, gint width, gint height);
 static void initDistTable (GstWarpTV * filter, gint width, gint height);
 
 static GstStaticPadTemplate gst_warptv_src_template =
@@ -97,10 +98,7 @@ gst_warptv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
   height = GST_VIDEO_INFO_HEIGHT (&info);
 
   g_free (filter->disttable);
-  g_free (filter->offstable);
-  filter->offstable = g_malloc (height * sizeof (guint32));
   filter->disttable = g_malloc (width * height * sizeof (guint32));
-  initOffsTable (filter, width, height);
   initDistTable (filter, width, height);
 
   return TRUE;
@@ -131,25 +129,11 @@ initSinTable (void)
 }
 
 static void
-initOffsTable (GstWarpTV * filter, gint width, gint height)
-{
-  gint y;
-
-  for (y = 0; y < height; y++) {
-    filter->offstable[y] = y * width;
-  }
-}
-
-static void
 initDistTable (GstWarpTV * filter, gint width, gint height)
 {
   gint32 halfw, halfh, *distptr;
   gint x, y;
-#ifdef PS2
-  float m;
-#else
   float m;
-#endif
 
   halfw = width >> 1;
   halfh = height >> 1;
@@ -174,9 +158,10 @@ gst_warptv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
   gint width, height;
   gint xw, yw, cw;
   gint32 c, i, x, y, dx, dy, maxx, maxy;
-  gint32 skip, *ctptr, *distptr;
+  gint32 *ctptr, *distptr;
   gint32 *ctable;
   guint32 *src, *dest;
+  gint sstride, dstride;
   GstVideoFrame in_frame, out_frame;
 
   gst_video_frame_map (&in_frame, &warptv->info, in, GST_MAP_READ);
@@ -185,6 +170,9 @@ gst_warptv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
   src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
   dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
 
+  sstride = GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, 0) / 4;
+  dstride = GST_VIDEO_FRAME_PLANE_STRIDE (&out_frame, 0) / 4;
+
   width = GST_VIDEO_FRAME_WIDTH (&in_frame);
   height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
 
@@ -199,7 +187,6 @@ gst_warptv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
   distptr = warptv->disttable;
   ctable = warptv->ctable;
 
-  skip = 0;                     /* video_width*sizeof(RGB32)/4 - video_width;; */
   c = 0;
 
   for (x = 0; x < 512; x++) {
@@ -226,9 +213,10 @@ gst_warptv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out)
         dy = 0;
       else if (dy > maxy)
         dy = maxy;
-      *dest++ = src[warptv->offstable[dy] + dx];
+
+      dest[x] = src[dy * sstride + dx];
     }
-    dest += skip;
+    dest += dstride;
   }
 
   warptv->tval = (warptv->tval + 1) & 511;
@@ -250,13 +238,31 @@ gst_warptv_start (GstBaseTransform * trans)
   return TRUE;
 }
 
+static gboolean
+gst_wraptv_decide_allocation (GstBaseTransform * trans, GstQuery * query)
+{
+  GstBufferPool *pool = NULL;
+  guint size, min, max, prefix, alignment;
+
+  gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
+      &alignment, &pool);
+
+  if (pool) {
+    GstStructure *config;
+
+    config = gst_buffer_pool_get_config (pool);
+    gst_buffer_pool_config_add_option (config,
+        GST_BUFFER_POOL_OPTION_VIDEO_META);
+    gst_buffer_pool_set_config (pool, config);
+  }
+  return TRUE;
+}
+
 static void
 gst_warptv_finalize (GObject * object)
 {
   GstWarpTV *warptv = GST_WARPTV (object);
 
-  g_free (warptv->offstable);
-  warptv->offstable = NULL;
   g_free (warptv->disttable);
   warptv->disttable = NULL;
 
@@ -284,6 +290,8 @@ gst_warptv_class_init (GstWarpTVClass * klass)
 
   trans_class->start = GST_DEBUG_FUNCPTR (gst_warptv_start);
   trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_warptv_set_caps);
+  trans_class->decide_allocation =
+      GST_DEBUG_FUNCPTR (gst_wraptv_decide_allocation);
   trans_class->transform = GST_DEBUG_FUNCPTR (gst_warptv_transform);
 
   initSinTable ();
@@ -292,6 +300,5 @@ gst_warptv_class_init (GstWarpTVClass * klass)
 static void
 gst_warptv_init (GstWarpTV * warptv)
 {
-  gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (warptv));
-  gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (warptv));
+  /* nothing to do */
 }