Browse code

avfilter/vf_vectorscope: less aggressive memory allocation

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2016/03/14 04:07:18
Showing 1 changed files
... ...
@@ -64,7 +64,8 @@ typedef struct VectorscopeContext {
64 64
     int flags;
65 65
     int colorspace;
66 66
     int cs;
67
-    uint8_t peak[4096][4096];
67
+    uint8_t *peak_memory;
68
+    uint8_t **peak;
68 69
 
69 70
     void (*vectorscope)(struct VectorscopeContext *s,
70 71
                         AVFrame *in, AVFrame *out, int pd);
... ...
@@ -252,10 +253,23 @@ static int query_formats(AVFilterContext *ctx)
252 252
 static int config_output(AVFilterLink *outlink)
253 253
 {
254 254
     VectorscopeContext *s = outlink->src->priv;
255
+    int i;
255 256
 
256 257
     s->intensity = s->fintensity * (s->size - 1);
257 258
     outlink->h = outlink->w = s->size;
258 259
     outlink->sample_aspect_ratio = (AVRational){1,1};
260
+
261
+    s->peak_memory = av_calloc(s->size, s->size);
262
+    if (!s->peak_memory)
263
+        return AVERROR(ENOMEM);
264
+
265
+    s->peak = av_calloc(s->size, sizeof(*s->peak));
266
+    if (!s->peak)
267
+        return AVERROR(ENOMEM);
268
+
269
+    for (i = 0; i < s->size; i++)
270
+        s->peak[i] = s->peak_memory + s->size * i;
271
+
259 272
     return 0;
260 273
 }
261 274
 
... ...
@@ -1298,6 +1312,14 @@ static int config_input(AVFilterLink *inlink)
1298 1298
     return 0;
1299 1299
 }
1300 1300
 
1301
+static av_cold void uninit(AVFilterContext *ctx)
1302
+{
1303
+    VectorscopeContext *s = ctx->priv;
1304
+
1305
+    av_freep(&s->peak);
1306
+    av_freep(&s->peak_memory);
1307
+}
1308
+
1301 1309
 static const AVFilterPad inputs[] = {
1302 1310
     {
1303 1311
         .name         = "default",
... ...
@@ -1323,6 +1345,7 @@ AVFilter ff_vf_vectorscope = {
1323 1323
     .priv_size     = sizeof(VectorscopeContext),
1324 1324
     .priv_class    = &vectorscope_class,
1325 1325
     .query_formats = query_formats,
1326
+    .uninit        = uninit,
1326 1327
     .inputs        = inputs,
1327 1328
     .outputs       = outputs,
1328 1329
 };