janus: webcam: check the device state

This commit is contained in:
Maxim Devaev
2026-07-17 19:40:39 +03:00
parent e1542dd617
commit 35fa72ba73
3 changed files with 16 additions and 2 deletions

View File

@@ -77,6 +77,7 @@ us_config_s *us_config_init(const char *config_dir_path) {
config->vplay_sink_name = _get_value(jcfg, "vplay", "sink"); config->vplay_sink_name = _get_value(jcfg, "vplay", "sink");
config->vplay_sink_mode = _get_uint(jcfg, "vplay", "sink_mode", 0660, 8); config->vplay_sink_mode = _get_uint(jcfg, "vplay", "sink_mode", 0660, 8);
config->vplay_dev_path = _get_value(jcfg, "vplay", "device");
goto ok; goto ok;
@@ -95,6 +96,7 @@ void us_config_destroy(us_config_s *config) {
US_DELETE(config->tc358743_dev_path, free); US_DELETE(config->tc358743_dev_path, free);
US_DELETE(config->aplay_dev_name, free); US_DELETE(config->aplay_dev_name, free);
US_DELETE(config->vplay_sink_name, free); US_DELETE(config->vplay_sink_name, free);
US_DELETE(config->vplay_dev_path, free);
free(config); free(config);
} }

View File

@@ -37,6 +37,7 @@ typedef struct {
char *vplay_sink_name; char *vplay_sink_name;
uint vplay_sink_mode; uint vplay_sink_mode;
char *vplay_dev_path;
} us_config_s; } us_config_s;

View File

@@ -386,6 +386,7 @@ static void *_aplay_thread(void *arg) {
return NULL; return NULL;
} }
static bool _is_camera_enabled(void);
static void _camera_set_active(uint width, uint height, uint fps); static void _camera_set_active(uint width, uint height, uint fps);
static void _camera_set_inactive(); static void _camera_set_inactive();
@@ -615,6 +616,16 @@ static void _push_camera_event(us_janus_client_s *client, bool requested) {
json_decref(event); json_decref(event);
} }
static bool _is_camera_enabled(void) {
bool enabled = us_str_is_ok(_g_config->vplay_sink_name);
if (enabled && us_str_is_ok(_g_config->vplay_dev_path)) {
if (access(_g_config->vplay_dev_path, F_OK) != 0) {
enabled = false;
}
}
return enabled;
}
static void _camera_set_active(uint width, uint height, uint fps) { static void _camera_set_active(uint width, uint height, uint fps) {
_LOCK_VPLAY; _LOCK_VPLAY;
US_A(!_g_camera.active); US_A(!_g_camera.active);
@@ -787,7 +798,7 @@ static struct janus_plugin_result *_plugin_handle_message(
} }
READ_BOOL(with_acap, "audio", us_au_probe(_g_config->acap_dev_name)); READ_BOOL(with_acap, "audio", us_au_probe(_g_config->acap_dev_name));
READ_BOOL(with_aplay, "mic", us_au_probe(_g_config->aplay_dev_name)); READ_BOOL(with_aplay, "mic", us_au_probe(_g_config->aplay_dev_name));
READ_BOOL(with_vplay, "camera", us_str_is_ok(_g_config->vplay_sink_name)); READ_BOOL(with_vplay, "camera", _is_camera_enabled());
# undef READ_BOOL # undef READ_BOOL
{ {
json_t *const obj = json_object_get(params, "orientation"); json_t *const obj = json_object_get(params, "orientation");
@@ -858,7 +869,7 @@ static struct janus_plugin_result *_plugin_handle_message(
"audio", us_au_probe(_g_config->acap_dev_name), "audio", us_au_probe(_g_config->acap_dev_name),
"mic", us_au_probe(_g_config->aplay_dev_name), "mic", us_au_probe(_g_config->aplay_dev_name),
"camera", "camera",
"enabled", us_str_is_ok(_g_config->vplay_sink_name), "enabled", _is_camera_enabled(),
"request", camera_req, "request", camera_req,
"ice", "ice",
"url", (ice_url != NULL ? ice_url : _g_default_ice_url) "url", (ice_url != NULL ? ice_url : _g_default_ice_url)