Skip to content

Commit

Permalink
vidcap testcard: check audio frequency
Browse files Browse the repository at this point in the history
* moved (some of) checking to separate function
* fixes CID 417257
  • Loading branch information
MartinPulec committed Sep 26, 2023
1 parent 4f362ac commit 09e447b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/video_capture/testcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,24 @@ static void show_help(bool full) {
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");
}

static bool
validate_settings(struct testcard_state *s, struct video_desc desc)
{
if (desc.width <= 0 || desc.height <= 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Wrong video size, given: %dx%d\n",
desc.width, desc.height);
return false;
}
if (s->audio_frequency <= 0) {
log_msg(LOG_LEVEL_ERROR,
MOD_NAME
"Audio frequency must be positive, given: %d\n",
s->audio_frequency);
return false;
}
return true;
}

static int vidcap_testcard_init(struct vidcap_params *params, void **state)
{
struct testcard_state *s = NULL;
Expand Down Expand Up @@ -483,9 +501,6 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
desc.fps = 0;
if (strlen(ptr) > 0 && isdigit(ptr[0])) {
desc = parse_format(&ptr, &save_ptr);
if (!desc.width) {
goto error;
}
}

tmp = strtok_r(ptr, ":", &save_ptr);
Expand Down Expand Up @@ -548,8 +563,7 @@ static int vidcap_testcard_init(struct vidcap_params *params, void **state)
tmp = strtok_r(NULL, ":", &save_ptr);
}

if (desc.width <= 0 || desc.height <= 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Wrong video format: %s\n", video_desc_to_string(desc));;
if (!validate_settings(s, desc)) {
goto error;
}

Expand Down

0 comments on commit 09e447b

Please sign in to comment.