video-scaler: fix temp line allocation
authorWim Taymans <wtaymans@redhat.com>
Tue, 4 Nov 2014 10:03:50 +0000 (11:03 +0100)
committerWim Taymans <wtaymans@redhat.com>
Tue, 4 Nov 2014 16:38:11 +0000 (17:38 +0100)
We need to allocate the templine with the amount of pixels we are going
to handle, which we only know for the vertical resampler when we are
asked to resample.

gst-libs/gst/video/video-scaler.c

index bfc4d6c..372e3d8 100644 (file)
@@ -62,6 +62,7 @@ struct _GstVideoScaler
   /* for ORC */
   gint inc;
 
+  gint tmpwidth;
   guint32 *tmpline1;
   guint32 *tmpline2;
 };
@@ -106,6 +107,16 @@ resampler_zip (GstVideoResampler * resampler, const GstVideoResampler * r1,
   }
 }
 
+static void
+realloc_tmplines (GstVideoScaler * scale, gint width)
+{
+  scale->tmpline1 =
+      g_realloc (scale->tmpline1,
+      sizeof (gint32) * width * 4 * scale->resampler.max_taps);
+  scale->tmpline2 = g_realloc (scale->tmpline2, sizeof (gint32) * width * 4);
+  scale->tmpwidth = width;
+}
+
 /**
  * gst_video_scaler_new:
  * @method: a #GstVideoResamplerMethod
@@ -164,10 +175,6 @@ gst_video_scaler_new (GstVideoResamplerMethod method, GstVideoScalerFlags flags,
   else
     scale->inc = ((in_size - 1) << 16) / (out_size - 1) - 1;
 
-  scale->tmpline1 =
-      g_malloc (sizeof (gint32) * out_size * 4 * scale->resampler.max_taps);
-  scale->tmpline2 = g_malloc (sizeof (gint32) * out_size * 4);
-
   return scale;
 }
 
@@ -727,6 +734,9 @@ gst_video_scaler_horizontal (GstVideoScaler * scale, GstVideoFormat format,
   pstride = finfo->pixel_stride[0];
   g_return_if_fail (pstride == 4 || pstride == 8);
 
+  if (scale->tmpwidth < width)
+    realloc_tmplines (scale, width);
+
   switch (pstride) {
     case 4:
       switch (scale->resampler.max_taps) {
@@ -797,6 +807,9 @@ gst_video_scaler_vertical (GstVideoScaler * scale, GstVideoFormat format,
   pstride = finfo->pixel_stride[0];
   g_return_if_fail (pstride == 4 || pstride == 8);
 
+  if (scale->tmpwidth < width)
+    realloc_tmplines (scale, width);
+
   switch (pstride) {
     case 4:
       switch (scale->resampler.max_taps) {