Skip to content

Commit 3ae6252

Browse files
committed
vcap/screen_avf: set device d=100 if unspec
Otherwise d=0 would be initialized implicitly, which isn't screen cap device but rather FaceTime HD Camera or so.
1 parent 74c47c5 commit 3ae6252

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

src/video_capture/screen_avf.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,51 @@ vidcap_screen_avf_probe(struct device_info **available_cards, int *count,
7979
}
8080
}
8181

82+
/// @returns whether the config string contains device spec (d=/uid=/name=)
83+
static bool
84+
contains_dev_spec(const char *fmt)
85+
{
86+
char *cpy = strdup(fmt);
87+
char *tmp = cpy;
88+
char *saveptr = nullptr;
89+
char *item = nullptr;
90+
while ((item = strtok_r(tmp, ":", &saveptr)) != nullptr) {
91+
tmp = nullptr;
92+
char *delim = strchr(item, '=');
93+
if (!delim) {
94+
continue;
95+
}
96+
*delim = '\0';
97+
if (strstr(item, "device") == item ||
98+
strstr(item, "uid") == item ||
99+
strstr(item, "name") == item) {
100+
return true;
101+
}
102+
}
103+
return false;
104+
}
105+
82106
static int
83107
vidcap_screen_avf_init(struct vidcap_params *params, void **state)
84108
{
85-
if (avfoundation_usage(vidcap_params_get_fmt(params), true)) {
109+
const char *fmt = vidcap_params_get_fmt(params);
110+
111+
if (avfoundation_usage(fmt, true)) {
86112
return VIDCAP_INIT_NOERR; // help shown
87113
}
114+
115+
if (contains_dev_spec(fmt)) {
116+
return vidcap_avfoundation_info.init(params, state);
117+
}
118+
119+
// add "d=100" to initialize first screen cap av foundation device
120+
const size_t orig_len = strlen(fmt);
121+
const size_t new_len = orig_len + 50;
122+
char *new_fmt = malloc(new_len);
123+
(void) snprintf(new_fmt, new_len, "%s%sd=%u", fmt,
124+
orig_len == 0 ? "" : ":", AVF_SCR_CAP_OFF);
125+
vidcap_params_replace_fmt(params, new_fmt);
126+
free(new_fmt);
88127
return vidcap_avfoundation_info.init(params, state);
89128
}
90129

src/video_capture_params.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @ingroup vidcap
66
*/
77
/*
8-
* Copyright (c) 2013-2025 CESNET, zájmové sdružení právnických osob
8+
* Copyright (c) 2013-2026 CESNET, zájmové sdružení právnických osob
99
* All rights reserved.
1010
*
1111
* Redistribution and use in source and binary forms, with or without
@@ -280,6 +280,13 @@ struct vidcap_params *vidcap_params_copy(const struct vidcap_params *params)
280280
return ret;
281281
}
282282

283+
void
284+
vidcap_params_replace_fmt(struct vidcap_params *params, const char *new_fmt)
285+
{
286+
free(params->fmt);
287+
params->fmt = strdup(new_fmt);
288+
}
289+
283290
/**
284291
* Frees all members of the given structure as well as its members.
285292
*

src/video_capture_params.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* individual devices' parameters (namely per-device capture filter).
1111
*/
1212
/**
13-
* Copyright (c) 2013-2025 CESNET, zájmové sdružení právnických osob
13+
* Copyright (c) 2013-2026 CESNET, zájmové sdružení právnických osob
1414
* All rights reserved.
1515
*
1616
* Redistribution and use in source and binary forms, with or without
@@ -81,6 +81,8 @@ void vidcap_params_add_capture_filter(struct vidcap_params *par
8181
const char *vidcap_params_get_capture_filter(const struct vidcap_params *params);
8282
void vidcap_params_set_flags(struct vidcap_params *params, unsigned int flags);
8383
void vidcap_params_add_flags(struct vidcap_params *params, unsigned int flags);
84+
void vidcap_params_replace_fmt(struct vidcap_params *params,
85+
const char *new_fmt);
8486
/// @}
8587

8688
#ifdef __cplusplus

0 commit comments

Comments
 (0)