Skip to content

Commit

Permalink
vpp/delay: limit nr of frames
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MartinPulec committed Feb 1, 2024
1 parent 69906a2 commit 75fb28c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/vo_postprocess/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
*/

#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -92,6 +91,10 @@ usage()
static void *
delay_init(const char *config)
{
enum {
MAX_VAL_FRM = 2000,
MAX_VAL_SEC = 60,
};
if (!IS_KEY_PREFIX(config, "seconds") &&
!IS_KEY_PREFIX(config, "frames")) {
usage();
Expand All @@ -100,7 +103,8 @@ delay_init(const char *config)

const char *val_s = strchr(config, '=') + 1;
double val = strtod(val_s, NULL);
if (val <= 0 || val > INT_MAX) {
if (val <= 0 || val > MAX_VAL_FRM ||
(IS_KEY_PREFIX(config, "seconds") && val > MAX_VAL_SEC)) {
MSG(ERROR, "Wrong delay value: %s\n", val_s);
return NULL;
}
Expand All @@ -117,6 +121,8 @@ delay_init(const char *config)
} else {
s->delay_frames = (int) val;
}
MSG(INFO, "Delay set to %g %s.\n", val,
s->delay_sec ? "seconds" : "frames");
s->cached_frames = simple_linked_list_init();

return s;
Expand Down

0 comments on commit 75fb28c

Please sign in to comment.