summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2014-10-18 15:19:58 +0200
committerWim Taymans <wtaymans@redhat.com>2014-10-24 11:28:00 +0200
commit2bc9382de16cfa54a41b1298f73ce0fe99232c4b (patch)
treeec22ad8826b75ac2d6bb98112b8e565773c3f7ec
parentc71e63efc3b59c1537510c34a632cf89a0738798 (diff)
video-converter: plug memory leaks
-rw-r--r--gst-libs/gst/video/video-converter.c146
-rw-r--r--gst/videoscale/gstvideoscale.c2
2 files changed, 80 insertions, 68 deletions
diff --git a/gst-libs/gst/video/video-converter.c b/gst-libs/gst/video/video-converter.c
index 697c39c7f..9b1157696 100644
--- a/gst-libs/gst/video/video-converter.c
+++ b/gst-libs/gst/video/video-converter.c
@@ -143,6 +143,8 @@ gst_line_cache_new ()
static void
gst_line_cache_clear (GstLineCache * cache)
{
+ g_return_if_fail (cache != NULL);
+
if (cache->free_line) {
gint i;
for (i = 0; i < cache->lines->len; i++)
@@ -154,6 +156,14 @@ gst_line_cache_clear (GstLineCache * cache)
}
static void
+gst_line_cache_free (GstLineCache * cache)
+{
+ gst_line_cache_clear (cache);
+ g_ptr_array_unref (cache->lines);
+ g_slice_free (GstLineCache, cache);
+}
+
+static void
gst_line_cache_set_need_line_func (GstLineCache * cache,
GstLineCacheNeedLineFunc need_line, gpointer user_data,
GDestroyNotify notify)
@@ -225,8 +235,8 @@ static void video_converter_matrix8 (GstVideoConverter * convert,
static void video_converter_matrix16 (GstVideoConverter * convert,
gpointer pixels);
static gboolean video_converter_lookup_fastpath (GstVideoConverter * convert);
-static gboolean video_converter_compute_matrix (GstVideoConverter * convert);
-static gboolean video_converter_compute_resample (GstVideoConverter * convert);
+static void video_converter_compute_matrix (GstVideoConverter * convert);
+static void video_converter_compute_resample (GstVideoConverter * convert);
static gboolean do_unpack_lines (GstLineCache * cache, gint line,
GstVideoConverter * convert);
@@ -373,7 +383,7 @@ gst_video_converter_new (GstVideoInfo * in_info, GstVideoInfo * out_info,
g_return_val_if_fail (in_info->interlace_mode == out_info->interlace_mode,
NULL);
- convert = g_malloc0 (sizeof (GstVideoConverter));
+ convert = g_slice_new0 (GstVideoConverter);
convert->in_info = *in_info;
convert->out_info = *out_info;
@@ -383,22 +393,36 @@ gst_video_converter_new (GstVideoInfo * in_info, GstVideoInfo * out_info,
convert->out_width = GST_VIDEO_INFO_WIDTH (out_info);
convert->out_height = GST_VIDEO_INFO_HEIGHT (out_info);
- if (!video_converter_lookup_fastpath (convert)) {
- convert->convert = video_converter_generic;
- if (!video_converter_compute_matrix (convert))
- goto no_convert;
+ /* default config */
+ convert->config = gst_structure_new ("GstVideoConverter",
+ "dither", GST_TYPE_VIDEO_DITHER_METHOD, GST_VIDEO_DITHER_NONE, NULL);
+ if (config)
+ gst_video_converter_set_config (convert, config);
+
+ if (video_converter_lookup_fastpath (convert))
+ goto done;
+
+ if (in_info->finfo->unpack_func == NULL)
+ goto no_unpack_func;
+
+ if (out_info->finfo->pack_func == NULL)
+ goto no_pack_func;
+
+ convert->convert = video_converter_generic;
- if (!video_converter_compute_resample (convert))
- goto no_convert;
- }
s2 = convert->in_width * convert->out_height;
s3 = convert->out_width * convert->in_height;
convert->v_scale_width = convert->in_width;
+ video_converter_compute_matrix (convert);
+ video_converter_compute_resample (convert);
+
/* unpack */
need_line = (GstLineCacheNeedLineFunc) do_unpack_lines;
+
/* upsample chroma */
- need_line = chain_upsample (convert, need_line);
+ if (convert->upsample)
+ need_line = chain_upsample (convert, need_line);
if (s3 <= s2) {
/* horizontal scaling first produces less pixels */
@@ -434,7 +458,8 @@ gst_video_converter_new (GstVideoInfo * in_info, GstVideoInfo * out_info,
}
}
/* downsample chroma */
- need_line = chain_downsample (convert, need_line);
+ if (convert->downsample)
+ need_line = chain_downsample (convert, need_line);
/* pack into final format */
need_line = chain_pack (convert, need_line);
@@ -444,18 +469,21 @@ gst_video_converter_new (GstVideoInfo * in_info, GstVideoInfo * out_info,
/* FIXME */
alloc_tmplines (convert, 64, width);
- /* default config */
- convert->config = gst_structure_new ("GstVideoConverter",
- "dither", GST_TYPE_VIDEO_DITHER_METHOD, GST_VIDEO_DITHER_NONE, NULL);
-
- if (config)
- gst_video_converter_set_config (convert, config);
-
+done:
return convert;
/* ERRORS */
-no_convert:
+no_unpack_func:
{
+ GST_ERROR ("no unpack_func for format %s",
+ gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (in_info)));
+ gst_video_converter_free (convert);
+ return NULL;
+ }
+no_pack_func:
+ {
+ GST_ERROR ("no pack_func for format %s",
+ gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (out_info)));
gst_video_converter_free (convert);
return NULL;
}
@@ -480,6 +508,23 @@ gst_video_converter_free (GstVideoConverter * convert)
gst_video_chroma_resample_free (convert->upsample);
if (convert->downsample)
gst_video_chroma_resample_free (convert->downsample);
+ if (convert->v_scaler)
+ gst_video_scaler_free (convert->v_scaler);
+ if (convert->h_scaler)
+ gst_video_scaler_free (convert->h_scaler);
+
+ if (convert->upsample_lines)
+ gst_line_cache_free (convert->upsample_lines);
+ if (convert->hscale_lines)
+ gst_line_cache_free (convert->hscale_lines);
+ if (convert->vscale_lines)
+ gst_line_cache_free (convert->vscale_lines);
+ if (convert->convert_lines)
+ gst_line_cache_free (convert->convert_lines);
+ if (convert->downsample_lines)
+ gst_line_cache_free (convert->downsample_lines);
+ if (convert->pack_lines)
+ gst_line_cache_free (convert->pack_lines);
for (i = 0; i < convert->n_tmplines; i++)
g_free (convert->tmplines[i]);
@@ -489,7 +534,7 @@ gst_video_converter_free (GstVideoConverter * convert)
if (convert->config)
gst_structure_free (convert->config);
- g_free (convert);
+ g_slice_free (GstVideoConverter, convert);
}
static void
@@ -813,7 +858,7 @@ color_matrix_RGB_to_YCbCr (ColorMatrix * m, double Kr, double Kb)
color_matrix_multiply (m, &k, m);
}
-static gboolean
+static void
video_converter_compute_matrix (GstVideoConverter * convert)
{
GstVideoInfo *in_info, *out_info;
@@ -830,12 +875,6 @@ video_converter_compute_matrix (GstVideoConverter * convert)
sfinfo = in_info->finfo;
dfinfo = out_info->finfo;
- if (sfinfo->unpack_func == NULL)
- goto no_unpack_func;
-
- if (dfinfo->pack_func == NULL)
- goto no_pack_func;
-
suinfo = gst_video_format_get_info (sfinfo->unpack_format);
duinfo = gst_video_format_get_info (dfinfo->unpack_format);
@@ -848,7 +887,7 @@ video_converter_compute_matrix (GstVideoConverter * convert)
in_info->colorimetry.matrix == out_info->colorimetry.matrix) {
GST_DEBUG ("using identity color transform");
convert->matrix = NULL;
- return TRUE;
+ return;
}
/* calculate intermediate format for the matrix. When unpacking, we expand
@@ -934,25 +973,9 @@ video_converter_compute_matrix (GstVideoConverter * convert)
convert->orc_p3 = (((guint64) (guint16) convert->cmatrix[2][2]) << 48) |
(((guint64) (guint16) convert->cmatrix[1][2]) << 32) |
(((guint64) (guint16) convert->cmatrix[0][2]) << 16);
-
- return TRUE;
-
- /* ERRORS */
-no_unpack_func:
- {
- GST_ERROR ("no unpack_func for format %s",
- gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (in_info)));
- return FALSE;
- }
-no_pack_func:
- {
- GST_ERROR ("no pack_func for format %s",
- gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (out_info)));
- return FALSE;
- }
}
-static gboolean
+static void
video_converter_compute_resample (GstVideoConverter * convert)
{
GstVideoInfo *in_info, *out_info;
@@ -1002,9 +1025,6 @@ video_converter_compute_resample (GstVideoConverter * convert)
GST_DEBUG ("downsample: %p, site: %d, offset %d, n_lines %d",
convert->downsample, out_info->chroma_site, convert->down_offset,
convert->down_n_lines);
-
-
- return TRUE;
}
#define TO_16(x) (((x)<<8) | (x))
@@ -1116,10 +1136,9 @@ do_upsample_lines (GstLineCache * cache, gint line, GstVideoConverter * convert)
lines =
gst_line_cache_get_lines (convert->upsample_lines, start_line, n_lines);
- if (convert->upsample) {
- GST_DEBUG ("doing upsample %d-%d", start_line, start_line + n_lines - 1);
- gst_video_chroma_resample (convert->upsample, lines, convert->in_width);
- }
+ GST_DEBUG ("doing upsample %d-%d", start_line, start_line + n_lines - 1);
+ gst_video_chroma_resample (convert->upsample, lines, convert->in_width);
+
for (i = 0; i < n_lines; i++)
gst_line_cache_add_line (cache, start_line + i, lines[i]);
@@ -1140,6 +1159,7 @@ do_hscale_lines (GstLineCache * cache, gint line, GstVideoConverter * convert)
GST_VIDEO_COLOR_RANGE_0_255, lines[0], destline, 0, convert->out_width);
gst_line_cache_add_line (cache, line, destline);
+
return TRUE;
}
@@ -1213,11 +1233,10 @@ do_downsample_lines (GstLineCache * cache, gint line,
lines =
gst_line_cache_get_lines (convert->downsample_lines, start_line, n_lines);
- if (convert->downsample) {
- GST_DEBUG ("downsample line %d %d-%d", line, start_line,
- start_line + n_lines - 1);
- gst_video_chroma_resample (convert->downsample, lines, convert->out_width);
- }
+ GST_DEBUG ("downsample line %d %d-%d", line, start_line,
+ start_line + n_lines - 1);
+ gst_video_chroma_resample (convert->downsample, lines, convert->out_width);
+
for (i = 0; i < n_lines; i++)
gst_line_cache_add_line (cache, start_line + i, lines[i]);
@@ -2089,8 +2108,6 @@ video_converter_lookup_fastpath (GstVideoConverter * convert)
gboolean interlaced;
gint width, height;
- return FALSE;
-
width = GST_VIDEO_INFO_WIDTH (&convert->in_info);
height = GST_VIDEO_INFO_HEIGHT (&convert->in_info);
@@ -2117,8 +2134,7 @@ video_converter_lookup_fastpath (GstVideoConverter * convert)
(transforms[i].height_align & height) == 0) {
GST_DEBUG ("using fastpath");
if (transforms[i].needs_color_matrix)
- if (!video_converter_compute_matrix (convert))
- goto no_convert;
+ video_converter_compute_matrix (convert);
convert->convert = transforms[i].convert;
alloc_tmplines (convert, 1, GST_VIDEO_INFO_WIDTH (&convert->in_info));
return TRUE;
@@ -2126,10 +2142,4 @@ video_converter_lookup_fastpath (GstVideoConverter * convert)
}
GST_DEBUG ("no fastpath found");
return FALSE;
-
-no_convert:
- {
- GST_DEBUG ("can't create matrix");
- return FALSE;
- }
}
diff --git a/gst/videoscale/gstvideoscale.c b/gst/videoscale/gstvideoscale.c
index 3914c866b..4fb9e9376 100644
--- a/gst/videoscale/gstvideoscale.c
+++ b/gst/videoscale/gstvideoscale.c
@@ -499,6 +499,8 @@ gst_video_scale_set_info (GstVideoFilter * filter, GstCaps * in,
GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, filter, "setup videoscaling");
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (filter), FALSE);
+ if (videoscale->convert)
+ gst_video_converter_free (videoscale->convert);
videoscale->convert = gst_video_converter_new (in_info, out_info, NULL);
}