Skip to content

Commit b329b18

Browse files
committed
vidcap testcard: allow setting key shortcuts
1 parent b5cd530 commit b329b18

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/utils/macros.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,10 @@
104104
#define OPTIMIZED_FOR for
105105
#endif
106106

107+
/// expands to true value if <k> from tok in format <k>=<v> is prefix of key
108+
#define IS_KEY_PREFIX(tok, key) \
109+
(strchr((tok), '=') != 0 && \
110+
strncmp(key, tok, strchr((tok), '=') - (tok)) == 0)
111+
107112
#endif // !defined UTILS_MACROS_H_1982D373_8862_4453_ADFB_33AECC853E48
108113

src/video_capture/testcard.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@
6060
#include "config_win32.h"
6161

6262
#include <stdint.h>
63+
#include <stdio.h>
64+
#include <stdlib.h>
6365

66+
#include "audio/types.h"
6467
#include "debug.h"
6568
#include "host.h"
6669
#include "lib_common.h"
6770
#include "tv.h"
6871
#include "types.h"
69-
#include "video.h"
70-
#include "video_capture.h"
7172
#include "utils/color_out.h"
7273
#include "utils/macros.h"
7374
#include "utils/misc.h"
75+
#include "utils/pam.h"
7476
#include "utils/string.h"
7577
#include "utils/vf_split.h"
76-
#include "utils/pam.h"
77-
#include "utils/y4m.h"
78-
#include <stdio.h>
79-
#include <stdlib.h>
80-
#include "audio/types.h"
8178
#include "utils/video_pattern_generator.h"
79+
#include "utils/y4m.h"
80+
#include "video.h"
81+
#include "video_capture.h"
8282
#include "video_capture/testcard_common.h"
8383

8484
enum {
@@ -133,6 +133,7 @@ static void configure_fallback_audio(struct testcard_state *s) {
133133

134134
for (int i = 0; i < AUDIO_BUFFER_SIZE(s->audio.ch_count) / AUDIO_BPS; i += 1) {
135135
*((int16_t*)(void *)(&s->audio_data[i * AUDIO_BPS])) = round(sin(((double) i / ((double) AUDIO_SAMPLE_RATE / s->audio_frequency)) * M_PI * 2. ) * ((1U << (AUDIO_BPS * 8U - 1)) - 1) * scale);
136+
136137
}
137138
}
138139

@@ -426,7 +427,7 @@ static void show_help(bool full) {
426427
color_printf("Examples:\n");
427428
color_printf(TBOLD("\t%s -t testcard:file=picture.pam\n"), uv_argv[0]);
428429
color_printf(TBOLD("\t%s -t testcard:mode=VGA\n"), uv_argv[0]);
429-
color_printf(TBOLD("\t%s -t testcard:size=1920x1080:fps=59.94i\n"), uv_argv[0]);
430+
color_printf(TBOLD("\t%s -t testcard:s=1920x1080:f=59.94i\n"), uv_argv[0]);
430431
color_printf("\n");
431432
color_printf("Default mode: %s\n", video_desc_to_string(DEFAULT_FORMAT));
432433
color_printf(TBOLD("Note:") " only certain codec and generator combinations produce full-depth samples (not up-sampled 8-bit), use " TBOLD("pattern=help") " for details.\n");
@@ -471,8 +472,6 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
471472
while (tmp) {
472473
if (strcmp(tmp, "p") == 0) {
473474
s->pan = 48;
474-
} else if (strstr(tmp, "file=") == tmp || strstr(tmp, "filename=") == tmp) {
475-
filename = strchr(tmp, '=') + 1;
476475
} else if (strncmp(tmp, "s=", 2) == 0) {
477476
strip_fmt = tmp;
478477
} else if (strcmp(tmp, "i") == 0) {
@@ -483,20 +482,20 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
483482
log_msg(LOG_LEVEL_WARNING, "[testcard] Deprecated 'sf' option. Use format testcard:1920:1080:25sf:UYVY instead!\n");
484483
} else if (strcmp(tmp, "still") == 0) {
485484
s->still_image = true;
486-
} else if (strncmp(tmp, "pattern=", strlen("pattern=")) == 0) {
485+
} else if (IS_KEY_PREFIX(tmp, "pattern")) {
487486
const char *pattern = tmp + strlen("pattern=");
488487
strncpy(s->pattern, pattern, sizeof s->pattern - 1);
489-
} else if (strstr(tmp, "codec=") == tmp) {
488+
} else if (IS_KEY_PREFIX(tmp, "codec")) {
490489
desc.color_spec = get_codec_from_name(strchr(tmp, '=') + 1);
491490
if (desc.color_spec == VIDEO_CODEC_NONE) {
492491
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Wrong color spec: %s\n", strchr(tmp, '=') + 1);
493492
goto error;
494493
}
495-
} else if (strstr(tmp, "mode=") == tmp) {
494+
} else if (IS_KEY_PREFIX(tmp, "mode")) {
496495
codec_t saved_codec = desc.color_spec;
497496
desc = get_video_desc_from_string(strchr(tmp, '=') + 1);
498497
desc.color_spec = saved_codec;
499-
} else if (strstr(tmp, "size=") == tmp) {
498+
} else if (IS_KEY_PREFIX(tmp, "size")) {
500499
tmp = strchr(tmp, '=') + 1;
501500
if (isdigit(tmp[0]) && strchr(tmp, 'x') != NULL) {
502501
desc.width = atoi(tmp);
@@ -507,10 +506,12 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
507506
desc.width = size_dsc.width;
508507
desc.height = size_dsc.height;
509508
}
510-
} else if (strstr(tmp, "fps=") == tmp) {
509+
} else if (IS_KEY_PREFIX(tmp, "fps")) {
511510
if (!parse_fps(strchr(tmp, '=') + 1, &desc)) {
512511
goto error;
513512
}
513+
} else if (IS_KEY_PREFIX(tmp, "file")) {
514+
filename = strchr(tmp, '=') + 1;
514515
} else if (strstr(tmp, "afrequency=") == tmp) {
515516
s->audio_frequency = atoi(strchr(tmp, '=') + 1);
516517
} else {

0 commit comments

Comments
 (0)