Skip to content

Commit fd9821d

Browse files
committed
dummy disp: allow multiple codecs for "codec" opt
1 parent ffcf7d3 commit fd9821d

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/video_display/dummy.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@
5252
#define DEFAULT_DUMP_LEN 32
5353
#define MOD_NAME "[dummy] "
5454

55-
static const codec_t codecs[] = {I420, UYVY, YUYV, v210, R10k, R12L, RGBA, RGB, BGR, RG48};
55+
static const codec_t default_codecs[] = {I420, UYVY, YUYV, v210, R10k, R12L, RGBA, RGB, BGR, RG48};
5656

5757
struct dummy_display_state {
5858
struct video_frame *f;
59-
codec_t req_codec;
59+
codec_t codecs[VIDEO_CODEC_COUNT];
60+
int codec_count;
6061
int rgb_shift[3];
6162

6263
size_t dump_bytes;
@@ -75,7 +76,7 @@ static void *display_dummy_init(struct module *parent, const char *cfg, unsigned
7576
"Additionally, options " TBOLD("hexdump") " and " TBOLD("dump") " are available for debugging.\n\n";
7677
color_printf("%s", indent_paragraph(desc));
7778
struct key_val options[] = {
78-
{ "codec=<codec>", "force the use of a codec instead of default set" },
79+
{ "codec=<codec>[,<codec2>]", "force the use of a codec instead of default set" },
7980
{ "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) ")" },
8081
{ "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" },
8182
{ "hexdump[=<n>]", "dump first n (default " TOSTRING(DEFAULT_DUMP_LEN) ") bytes of every frame in hexadecimal format" },
@@ -84,7 +85,8 @@ static void *display_dummy_init(struct module *parent, const char *cfg, unsigned
8485
print_module_usage("-d dummy", options, NULL, 0);
8586
return INIT_NOERR;
8687
}
87-
struct dummy_display_state s = { 0 };
88+
struct dummy_display_state s = { .codec_count = sizeof default_codecs / sizeof default_codecs[0] };
89+
memcpy(s.codecs, default_codecs, sizeof default_codecs);
8890
int rgb_shift_init[] = DEFAULT_RGB_SHIFT_INIT;
8991
memcpy(s.rgb_shift, &rgb_shift_init, sizeof s.rgb_shift);
9092
char *ccpy = alloca(strlen(cfg) + 1);
@@ -93,10 +95,17 @@ static void *display_dummy_init(struct module *parent, const char *cfg, unsigned
9395
char *save_ptr = NULL;
9496
while ((item = strtok_r(ccpy, ":", &save_ptr)) != NULL) {
9597
if (strstr(item, "codec=") != NULL) {
96-
s.req_codec = get_codec_from_name(strchr(item, '=') + 1);
97-
if (s.req_codec == VIDEO_CODEC_NONE) {
98-
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Wrong codec spec: %s!\n", strchr(item, '=') + 1);
99-
return NULL;
98+
char *sptr = NULL;
99+
char *tok = NULL;
100+
char *str = strchr(item, '=') + 1;
101+
s.codec_count = 0;
102+
while ((tok = strtok_r(str, ",", &sptr))) {
103+
str = NULL;
104+
s.codecs[s.codec_count++] = get_codec_from_name(tok);
105+
if (s.codecs[s.codec_count - 1] == VIDEO_CODEC_NONE) {
106+
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Wrong codec spec: %s!\n", tok);
107+
return NULL;
108+
}
100109
}
101110
} else if (strstr(item, "dump") != NULL) {
102111
s.dump_to_file = 1;
@@ -190,12 +199,12 @@ static int display_dummy_get_property(void *state, int property, void *val, size
190199
switch (property) {
191200
case DISPLAY_PROPERTY_CODECS:
192201
{
193-
size_t req_len = s->req_codec ? sizeof(codec_t) : sizeof codecs;
202+
size_t req_len = s->codec_count * sizeof(codec_t);
194203
if (req_len > *len) {
195204
return FALSE;
196205
}
197206
*len = req_len;
198-
memcpy(val, s->req_codec ? &s->req_codec : codecs, *len);
207+
memcpy(val, s->codecs, *len);
199208
}
200209
break;
201210
case DISPLAY_PROPERTY_RGB_SHIFT:

0 commit comments

Comments
 (0)