Browse code

vf_deshake: reduce stack usage.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>

Reimar Döffinger authored on 2014/09/02 06:36:29
Showing 2 changed files
... ...
@@ -71,8 +71,11 @@ typedef struct {
71 71
 
72 72
 #endif
73 73
 
74
+#define MAX_R 64
75
+
74 76
 typedef struct {
75 77
     const AVClass *class;
78
+    int counts[2*MAX_R+1][2*MAX_R+1]; /// < Scratch buffer for motion search
76 79
     AVFrame *ref;              ///< Previous frame
77 80
     int rx;                    ///< Maximum horizontal shift
78 81
     int ry;                    ///< Maximum vertical shift
... ...
@@ -67,8 +67,6 @@
67 67
 #define OFFSET(x) offsetof(DeshakeContext, x)
68 68
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
69 69
 
70
-#define MAX_R 64
71
-
72 70
 static const AVOption deshake_options[] = {
73 71
     { "x", "set x for the rectangular search area",      OFFSET(cx), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
74 72
     { "y", "set y for the rectangular search area",      OFFSET(cy), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
... ...
@@ -242,7 +240,6 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
242 242
 {
243 243
     int x, y;
244 244
     IntMotionVector mv = {0, 0};
245
-    int counts[2*MAX_R+1][2*MAX_R+1];
246 245
     int count_max_value = 0;
247 246
     int contrast;
248 247
 
... ...
@@ -254,7 +251,7 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
254 254
     // Reset counts to zero
255 255
     for (x = 0; x < deshake->rx * 2 + 1; x++) {
256 256
         for (y = 0; y < deshake->ry * 2 + 1; y++) {
257
-            counts[x][y] = 0;
257
+            deshake->counts[x][y] = 0;
258 258
         }
259 259
     }
260 260
 
... ...
@@ -270,7 +267,7 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
270 270
                 //av_log(NULL, AV_LOG_ERROR, "%d\n", contrast);
271 271
                 find_block_motion(deshake, src1, src2, x, y, stride, &mv);
272 272
                 if (mv.x != -1 && mv.y != -1) {
273
-                    counts[mv.x + deshake->rx][mv.y + deshake->ry] += 1;
273
+                    deshake->counts[mv.x + deshake->rx][mv.y + deshake->ry] += 1;
274 274
                     if (x > deshake->rx && y > deshake->ry)
275 275
                         angles[pos++] = block_angle(x, y, 0, 0, &mv);
276 276
 
... ...
@@ -294,11 +291,11 @@ static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2,
294 294
     // Find the most common motion vector in the frame and use it as the gmv
295 295
     for (y = deshake->ry * 2; y >= 0; y--) {
296 296
         for (x = 0; x < deshake->rx * 2 + 1; x++) {
297
-            //av_log(NULL, AV_LOG_ERROR, "%5d ", counts[x][y]);
298
-            if (counts[x][y] > count_max_value) {
297
+            //av_log(NULL, AV_LOG_ERROR, "%5d ", deshake->counts[x][y]);
298
+            if (deshake->counts[x][y] > count_max_value) {
299 299
                 t->vector.x = x - deshake->rx;
300 300
                 t->vector.y = y - deshake->ry;
301
-                count_max_value = counts[x][y];
301
+                count_max_value = deshake->counts[x][y];
302 302
             }
303 303
         }
304 304
         //av_log(NULL, AV_LOG_ERROR, "\n");