Skip to content

Commit 75fb28c

Browse files
committed
vpp/delay: limit nr of frames
added a limit to number of frames/seconds that can be cached The user may enter some huge value by mistake and since FHD UYVY frame takes 4M, it can exhaust the memory quite quickly. So the limit is set to 2000 frames or 60 sec, which is in the case of 30p video up to 8 GB of memory. \+ print the user selection to console
1 parent 69906a2 commit 75fb28c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/vo_postprocess/delay.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
*/
3737

3838
#include <assert.h>
39-
#include <limits.h>
4039
#include <math.h>
4140
#include <stdlib.h>
4241
#include <string.h>
@@ -92,6 +91,10 @@ usage()
9291
static void *
9392
delay_init(const char *config)
9493
{
94+
enum {
95+
MAX_VAL_FRM = 2000,
96+
MAX_VAL_SEC = 60,
97+
};
9598
if (!IS_KEY_PREFIX(config, "seconds") &&
9699
!IS_KEY_PREFIX(config, "frames")) {
97100
usage();
@@ -100,7 +103,8 @@ delay_init(const char *config)
100103

101104
const char *val_s = strchr(config, '=') + 1;
102105
double val = strtod(val_s, NULL);
103-
if (val <= 0 || val > INT_MAX) {
106+
if (val <= 0 || val > MAX_VAL_FRM ||
107+
(IS_KEY_PREFIX(config, "seconds") && val > MAX_VAL_SEC)) {
104108
MSG(ERROR, "Wrong delay value: %s\n", val_s);
105109
return NULL;
106110
}
@@ -117,6 +121,8 @@ delay_init(const char *config)
117121
} else {
118122
s->delay_frames = (int) val;
119123
}
124+
MSG(INFO, "Delay set to %g %s.\n", val,
125+
s->delay_sec ? "seconds" : "frames");
120126
s->cached_frames = simple_linked_list_init();
121127

122128
return s;

0 commit comments

Comments
 (0)