Merge branch 'master' into 0.11
[platform/upstream/gst-plugins-good.git] / gst / effectv / gstradioac.c
index 15be676..a84f2ef 100644 (file)
@@ -55,8 +55,6 @@
 #include "gstradioac.h"
 #include "gsteffectv.h"
 
-#include <gst/controller/gstcontroller.h>
-
 enum
 {
   RADIOAC_NORMAL = 0,
@@ -133,14 +131,15 @@ enum
 #define RATIO 0.95
 
 static guint32 palettes[COLORS * PATTERN];
+static gint swap_tab[] = { 2, 1, 0, 3 };
 
 #define gst_radioactv_parent_class parent_class
 G_DEFINE_TYPE (GstRadioacTV, gst_radioactv, GST_TYPE_VIDEO_FILTER);
 
 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define CAPS_STR GST_VIDEO_CAPS_MAKE ("RGBx")
+#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ RGBx, BGRx }")
 #else
-#define CAPS_STR GST_VIDEO_CAPS_MAKE ("xBGR")
+#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }")
 #endif
 
 static GstStaticPadTemplate gst_radioactv_src_template =
@@ -164,18 +163,20 @@ makePalette (void)
 
 #define DELTA (255/(COLORS/2-1))
 
+  /* red, gree, blue */
   for (i = 0; i < COLORS / 2; i++) {
     palettes[i] = i * DELTA;
     palettes[COLORS + i] = (i * DELTA) << 8;
     palettes[COLORS * 2 + i] = (i * DELTA) << 16;
   }
   for (i = 0; i < COLORS / 2; i++) {
-    palettes[+i + COLORS / 2] = 255 | (i * DELTA) << 16 | (i * DELTA) << 8;
+    palettes[i + COLORS / 2] = 255 | (i * DELTA) << 16 | (i * DELTA) << 8;
     palettes[COLORS + i + COLORS / 2] =
         (255 << 8) | (i * DELTA) << 16 | i * DELTA;
     palettes[COLORS * 2 + i + COLORS / 2] =
         (255 << 16) | (i * DELTA) << 8 | i * DELTA;
   }
+  /* white */
   for (i = 0; i < COLORS; i++) {
     palettes[COLORS * 3 + i] = (255 * i / COLORS) * 0x10101;
   }
@@ -232,9 +233,12 @@ blur (GstRadioacTV * filter)
   gint width;
   guint8 *p, *q;
   guint8 v;
+  GstVideoInfo *info;
+
+  info = &GST_VIDEO_FILTER (filter)->in_info;
 
   width = filter->buf_width;
-  p = filter->blurzoombuf + GST_VIDEO_INFO_WIDTH (&filter->info) + 1;
+  p = filter->blurzoombuf + GST_VIDEO_INFO_WIDTH (info) + 1;
   q = p + filter->buf_area;
 
   for (y = filter->buf_height - 2; y > 0; y--) {
@@ -314,42 +318,48 @@ image_bgsubtract_update_y (guint32 * src, gint16 * background, guint8 * diff,
 }
 
 static GstFlowReturn
-gst_radioactv_transform (GstBaseTransform * trans, GstBuffer * in,
-    GstBuffer * out)
+gst_radioactv_transform_frame (GstVideoFilter * vfilter,
+    GstVideoFrame * in_frame, GstVideoFrame * out_frame)
 {
-  GstRadioacTV *filter = GST_RADIOACTV (trans);
+  GstRadioacTV *filter = GST_RADIOACTV (vfilter);
   guint32 *src, *dest;
-  GstVideoFrame in_frame, out_frame;
   GstClockTime timestamp, stream_time;
   gint x, y, width, height;
   guint32 a, b;
   guint8 *diff, *p;
   guint32 *palette;
 
-  timestamp = GST_BUFFER_TIMESTAMP (in);
+  timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
   stream_time =
-      gst_segment_to_stream_time (&trans->segment, GST_FORMAT_TIME, timestamp);
+      gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment,
+      GST_FORMAT_TIME, timestamp);
 
   GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
       GST_TIME_ARGS (timestamp));
 
   if (GST_CLOCK_TIME_IS_VALID (stream_time))
-    gst_object_sync_values (G_OBJECT (filter), stream_time);
+    gst_object_sync_values (GST_OBJECT (filter), stream_time);
 
-  if (!gst_video_frame_map (&in_frame, &filter->info, in, GST_MAP_READ))
-    goto invalid_in;
+  src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
+  dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
 
-  if (!gst_video_frame_map (&out_frame, &filter->info, out, GST_MAP_WRITE))
-    goto invalid_out;
-
-  src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
-  dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
-
-  width = GST_VIDEO_FRAME_WIDTH (&in_frame);
-  height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
+  width = GST_VIDEO_FRAME_WIDTH (in_frame);
+  height = GST_VIDEO_FRAME_HEIGHT (in_frame);
 
   GST_OBJECT_LOCK (filter);
-  palette = &palettes[COLORS * filter->color];
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+  if (GST_VIDEO_FRAME_FORMAT (in_frame) == GST_VIDEO_FORMAT_RGBx) {
+    palette = &palettes[COLORS * filter->color];
+  } else {
+    palette = &palettes[COLORS * swap_tab[filter->color]];
+  }
+#else
+  if (GST_VIDEO_FRAME_FORMAT (in_frame) == GST_VIDEO_FORMAT_xBGR) {
+    palette = &palettes[COLORS * filter->color];
+  } else {
+    palette = &palettes[COLORS * swap_tab[filter->color]];
+  }
+#endif
   diff = filter->diff;
 
   if (filter->mode == 3 && filter->trigger)
@@ -405,40 +415,18 @@ gst_radioactv_transform (GstBaseTransform * trans, GstBuffer * in,
   }
   GST_OBJECT_UNLOCK (filter);
 
-  gst_video_frame_unmap (&in_frame);
-  gst_video_frame_unmap (&out_frame);
-
   return GST_FLOW_OK;
-
-  /* ERRORS */
-invalid_in:
-  {
-    GST_DEBUG_OBJECT (filter, "invalid input frame");
-    return GST_FLOW_ERROR;
-  }
-invalid_out:
-  {
-    GST_DEBUG_OBJECT (filter, "invalid output frame");
-    gst_video_frame_unmap (&in_frame);
-    return GST_FLOW_ERROR;
-  }
 }
 
 static gboolean
-gst_radioactv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
-    GstCaps * outcaps)
+gst_radioactv_set_info (GstVideoFilter * vfilter, GstCaps * incaps,
+    GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
 {
-  GstRadioacTV *filter = GST_RADIOACTV (btrans);
-  GstVideoInfo info;
+  GstRadioacTV *filter = GST_RADIOACTV (vfilter);
   gint width, height;
 
-  if (!gst_video_info_from_caps (&info, incaps))
-    goto invalid_caps;
-
-  filter->info = info;
-
-  width = GST_VIDEO_INFO_WIDTH (&info);
-  height = GST_VIDEO_INFO_HEIGHT (&info);
+  width = GST_VIDEO_INFO_WIDTH (in_info);
+  height = GST_VIDEO_INFO_HEIGHT (in_info);
 
   filter->buf_width_blocks = width / 32;
   if (filter->buf_width_blocks > 255)
@@ -480,11 +468,6 @@ gst_radioactv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
   return TRUE;
 
   /* ERRORS */
-invalid_caps:
-  {
-    GST_DEBUG_OBJECT (filter, "invalid caps received");
-    return FALSE;
-  }
 too_wide:
   {
     GST_DEBUG_OBJECT (filter, "frame too wide");
@@ -594,6 +577,7 @@ gst_radioactv_class_init (GstRadioacTVClass * klass)
   GObjectClass *gobject_class = (GObjectClass *) klass;
   GstElementClass *gstelement_class = (GstElementClass *) klass;
   GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
+  GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
 
   gobject_class->set_property = gst_radioactv_set_property;
   gobject_class->get_property = gst_radioactv_get_property;
@@ -631,10 +615,12 @@ gst_radioactv_class_init (GstRadioacTVClass * klass)
   gst_element_class_add_pad_template (gstelement_class,
       gst_static_pad_template_get (&gst_radioactv_src_template));
 
-  trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_radioactv_set_caps);
-  trans_class->transform = GST_DEBUG_FUNCPTR (gst_radioactv_transform);
   trans_class->start = GST_DEBUG_FUNCPTR (gst_radioactv_start);
 
+  vfilter_class->set_info = GST_DEBUG_FUNCPTR (gst_radioactv_set_info);
+  vfilter_class->transform_frame =
+      GST_DEBUG_FUNCPTR (gst_radioactv_transform_frame);
+
   makePalette ();
 }
 
@@ -645,7 +631,4 @@ gst_radioactv_init (GstRadioacTV * filter)
   filter->color = DEFAULT_COLOR;
   filter->interval = DEFAULT_INTERVAL;
   filter->trigger = DEFAULT_TRIGGER;
-
-  gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (filter));
-  gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (filter));
 }