Skip to content

Commit 3ea13e3

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 602c174 commit 3ea13e3

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
@@ -244,16 +244,18 @@ static void *_acap_thread(void *arg) {
244244
continue;
245245
}
246246

247-
uint hz = 0;
247+
uint hz = _g_config->acap_sampling_rate;
248248
us_acap_s *acap = NULL;
249249

250-
if (_check_tc358743_acap(&hz) < 0) {
250+
US_ONCE({ US_JLOG_INFO("acap", "Configured acap_sampling_rate : %d", _g_config->acap_sampling_rate); });
251+
if (hz == 0 && _check_tc358743_acap(&hz) < 0) {
251252
goto close_acap;
252253
}
253254
if (hz == 0) {
254255
US_ONCE({ US_JLOG_INFO("acap", "No audio presented from the host"); });
255256
goto close_acap;
256257
}
258+
257259
US_ONCE({ US_JLOG_INFO("acap", "Detected host audio"); });
258260
if ((acap = us_acap_init(_g_config->acap_dev_name, hz)) == NULL) {
259261
goto close_acap;
@@ -262,7 +264,7 @@ static void *_acap_thread(void *arg) {
262264
once = 0;
263265

264266
while (!_STOP && _HAS_WATCHERS && _HAS_LISTENERS) {
265-
if (_check_tc358743_acap(&hz) < 0 || acap->pcm_hz != hz) {
267+
if (_g_config->acap_sampling_rate == 0 && (_check_tc358743_acap(&hz) < 0 || acap->pcm_hz != hz)) {
266268
goto close_acap;
267269
}
268270
uz size = US_RTP_DATAGRAM_SIZE - US_RTP_HEADER_SIZE;

0 commit comments

Comments
 (0)