Skip to content

Commit 4f78bc8

Browse files
committed
Allow optional acap property - sampling_rate
This is needed when using audio capture from a device other than tc358743 such as a UAC2 Capture device to have two way audio over USB When sampling_rate is provided, janus plugin don't try to query tc358743
1 parent f2dd9c3 commit 4f78bc8

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

janus/src/config.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "config.h"
2424

25+
#include <errno.h>
2526
#include <stdlib.h>
2627
#include <string.h>
2728
#include <unistd.h>
@@ -36,6 +37,7 @@
3637

3738

3839
static char *_get_value(janus_config *jcfg, const char *section, const char *option);
40+
static uint _get_uint(janus_config *jcfg, const char *section, const char *option, bool def);
3941
// static bool _get_bool(janus_config *jcfg, const char *section, const char *option, bool def);
4042

4143

@@ -65,6 +67,7 @@ us_config_s *us_config_init(const char *config_dir_path) {
6567
US_JLOG_INFO("config", "Missing config value: acap.tc358743");
6668
goto error;
6769
}
70+
config->acap_sampling_rate = _get_uint(jcfg, "acap", "sampling_rate", 0);
6871
if ((config->aplay_dev_name = _get_value(jcfg, "aplay", "device")) != NULL) {
6972
char *path = _get_value(jcfg, "aplay", "check");
7073
if (path != NULL) {
@@ -105,6 +108,20 @@ static char *_get_value(janus_config *jcfg, const char *section, const char *opt
105108
return us_strdup(option_obj->value);
106109
}
107110

111+
static uint _get_uint(janus_config *jcfg, const char *section, const char *option, bool def) {
112+
char *const tmp = _get_value(jcfg, section, option);
113+
uint value = def;
114+
if (tmp != NULL) {
115+
errno = 0;
116+
value = (uint) strtoul(tmp, NULL, 10);
117+
if (errno != 0) {
118+
value = def;
119+
}
120+
free(tmp);
121+
}
122+
return value;
123+
}
124+
108125
/*static bool _get_bool(janus_config *jcfg, const char *section, const char *option, bool def) {
109126
char *const tmp = _get_value(jcfg, section, option);
110127
bool value = def;

janus/src/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ typedef struct {
2727
char *video_sink_name;
2828

2929
char *acap_dev_name;
30+
unsigned int acap_sampling_rate;
3031
char *tc358743_dev_path;
3132

3233
char *aplay_dev_name;
34+
3335
} us_config_s;
3436

3537

janus/src/plugin.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,18 @@ static void *_acap_thread(void *arg) {
247247
continue;
248248
}
249249

250-
uint hz = 0;
250+
uint hz = _g_config->acap_sampling_rate;
251251
us_acap_s *acap = NULL;
252252

253-
if (_check_tc358743_acap(&hz) < 0) {
253+
US_ONCE({ US_JLOG_INFO("acap", "Configured acap_sampling_rate : %d", _g_config->acap_sampling_rate); });
254+
if (hz == 0 && _check_tc358743_acap(&hz) < 0) {
254255
goto close_acap;
255256
}
256257
if (hz == 0) {
257258
US_ONCE({ US_JLOG_INFO("acap", "No audio presented from the host"); });
258259
goto close_acap;
259260
}
261+
260262
US_ONCE({ US_JLOG_INFO("acap", "Detected host audio"); });
261263
if ((acap = us_acap_init(_g_config->acap_dev_name, hz)) == NULL) {
262264
goto close_acap;
@@ -265,7 +267,7 @@ static void *_acap_thread(void *arg) {
265267
once = 0;
266268

267269
while (!_STOP && _HAS_WATCHERS && _HAS_LISTENERS) {
268-
if (_check_tc358743_acap(&hz) < 0 || acap->pcm_hz != hz) {
270+
if (_g_config->acap_sampling_rate == 0 && (_check_tc358743_acap(&hz) < 0 || acap->pcm_hz != hz)) {
269271
goto close_acap;
270272
}
271273
uz size = US_RTP_DATAGRAM_SIZE - US_RTP_HEADER_SIZE;

0 commit comments

Comments
 (0)