Skip to content

Commit 0349beb

Browse files
committed
vdisp/dummy: add discard parameter
1 parent 0dad02e commit 0349beb

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/video_display/dummy.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "config_win32.h"
4141

4242
#include <assert.h>
43+
#include <stdbool.h>
4344
#include <stdlib.h>
4445
#include <string.h>
4546

@@ -79,6 +80,7 @@ struct dummy_display_state {
7980

8081
size_t dump_bytes;
8182
_Bool dump_to_file;
83+
bool discard; ///< do not recycle frame
8284
_Bool oneshot;
8385
_Bool raw;
8486
int dump_to_file_skip_frames;
@@ -137,6 +139,8 @@ static _Bool dummy_parse_opts(struct dummy_display_state *s, char *fmt) {
137139
s->oneshot = 1;
138140
} else if (strcmp(item, "raw") == 0) {
139141
s->raw = 1;
142+
} else if (strcmp(item, "discard") == 0) {
143+
s->discard = true;
140144
} else {
141145
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unrecognized option: %s\n", item);
142146
return 0;
@@ -161,6 +165,7 @@ static void *display_dummy_init(struct module *parent, const char *cfg, unsigned
161165
{ "rgb_shift=<r>,<g>,<b>", "if using output codec RGBA, use specified shifts instead of default (" TOSTRING(DEFAULT_R_SHIFT) ", " TOSTRING(DEFAULT_G_SHIFT) ", " TOSTRING(DEFAULT_B_SHIFT) ")" },
162166
{ "dump[:skip=<n>][:oneshot][:raw]", "dump first frame to file dummy.<ext> (optionally skip <n> first frames); 'oneshot' - exit after dumping the picture; 'raw' - dump raw data" },
163167
{ "hexdump[=<n>]", "dump first n (default " TOSTRING(DEFAULT_DUMP_LEN) ") bytes of every frame in hexadecimal format" },
168+
{ "discard", "realloc every frame (do not recycle)" },
164169
{ NULL, NULL }
165170
};
166171
print_module_usage("-d dummy", options, NULL, 0);
@@ -197,7 +202,11 @@ static void display_dummy_done(void *state)
197202

198203
static struct video_frame *display_dummy_getf(void *state)
199204
{
200-
return ((struct dummy_display_state *) state)->f;
205+
struct dummy_display_state *s = state;
206+
if (s->discard) {
207+
return vf_alloc_desc_data(video_desc_from_frame(s->f));
208+
}
209+
return s->f;
201210
}
202211

203212
static void dump_buf(unsigned char *buf, size_t len, int block_size) {
@@ -213,10 +222,13 @@ static void dump_buf(unsigned char *buf, size_t len, int block_size) {
213222

214223
static bool display_dummy_putf(void *state, struct video_frame *frame, long long flags)
215224
{
225+
struct dummy_display_state *s = state;
216226
if (flags == PUTF_DISCARD || frame == NULL) {
227+
if (s->discard) {
228+
vf_free(frame);
229+
}
217230
return true;
218231
}
219-
struct dummy_display_state *s = state;
220232
if (s->dump_bytes > 0) {
221233
dump_buf((unsigned char *)(frame->tiles[0].data), MIN(frame->tiles[0].data_len, s->dump_bytes), get_pf_block_bytes(frame->color_spec));
222234
}
@@ -234,6 +246,9 @@ static bool display_dummy_putf(void *state, struct video_frame *frame, long long
234246
}
235247
}
236248
}
249+
if (s->discard) {
250+
vf_free(frame);
251+
}
237252

238253
return true;
239254
}

0 commit comments

Comments
 (0)