Skip to content

Commit 206f691

Browse files
committed
janus: non-tc358743 devices for acap suppurted
1 parent 9a5cce3 commit 206f691

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

janus/src/config.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
#include <janus/config.h>
2929
#include <janus/plugins/plugin.h>
3030

31+
#include "uslibs/types.h"
3132
#include "uslibs/tools.h"
3233

3334
#include "const.h"
3435
#include "logging.h"
3536

3637

3738
static char *_get_value(janus_config *jcfg, const char *section, const char *option);
39+
static uint _get_uint(janus_config *jcfg, const char *section, const char *option, uint def);
3840
// static bool _get_bool(janus_config *jcfg, const char *section, const char *option, bool def);
3941

4042

@@ -60,8 +62,10 @@ us_config_s *us_config_init(const char *config_dir_path) {
6062
goto error;
6163
}
6264
if ((config->acap_dev_name = _get_value(jcfg, "acap", "device")) != NULL) {
63-
if ((config->tc358743_dev_path = _get_value(jcfg, "acap", "tc358743")) == NULL) {
64-
US_JLOG_INFO("config", "Missing config value: acap.tc358743");
65+
config->acap_hz = _get_uint(jcfg, "acap", "sampling_rate", 0);
66+
config->tc358743_dev_path = _get_value(jcfg, "acap", "tc358743");
67+
if (config->acap_hz == 0 && config->tc358743_dev_path == NULL) {
68+
US_JLOG_ERROR("config", "Either acap.sampling_rate or acap.tc358743 required");
6569
goto error;
6670
}
6771
config->aplay_dev_name = _get_value(jcfg, "aplay", "device");
@@ -95,6 +99,20 @@ static char *_get_value(janus_config *jcfg, const char *section, const char *opt
9599
return us_strdup(option_obj->value);
96100
}
97101

102+
static uint _get_uint(janus_config *jcfg, const char *section, const char *option, uint def) {
103+
char *const tmp = _get_value(jcfg, section, option);
104+
uint value = def;
105+
if (tmp != NULL) {
106+
errno = 0;
107+
value = (uint)strtoul(tmp, NULL, 10);
108+
if (errno != 0) {
109+
value = def;
110+
}
111+
free(tmp);
112+
}
113+
return value;
114+
}
115+
98116
/*static bool _get_bool(janus_config *jcfg, const char *section, const char *option, bool def) {
99117
char *const tmp = _get_value(jcfg, section, option);
100118
bool value = def;

janus/src/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
#pragma once
2424

2525

26+
#include "uslibs/types.h"
27+
28+
2629
typedef struct {
2730
char *video_sink_name;
2831

2932
char *acap_dev_name;
33+
uint acap_hz;
3034
char *tc358743_dev_path;
3135

3236
char *aplay_dev_name;

janus/src/plugin.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,15 @@ static void *_video_sink_thread(void *arg) {
214214
return NULL;
215215
}
216216

217-
static int _check_tc358743_acap(uint *hz) {
217+
static int _get_acap_hz(uint *hz) {
218+
if (_g_config->acap_hz != 0) {
219+
*hz = _g_config->acap_hz;
220+
return 0;
221+
}
222+
if (_g_config->tc358743_dev_path == NULL) {
223+
US_JLOG_ERROR("acap", "No configured sampling rate");
224+
return -1;
225+
}
218226
int fd;
219227
if ((fd = open(_g_config->tc358743_dev_path, O_RDWR)) < 0) {
220228
US_JLOG_PERROR("acap", "Can't open TC358743 V4L2 device");
@@ -254,7 +262,7 @@ static void *_acap_thread(void *arg) {
254262
US_ONCE({ US_JLOG_ERROR("acap", "No PCM capture device"); });
255263
goto close_acap;
256264
}
257-
if (_check_tc358743_acap(&hz) < 0) {
265+
if (_get_acap_hz(&hz) < 0) {
258266
goto close_acap;
259267
}
260268
if (hz == 0) {
@@ -269,7 +277,7 @@ static void *_acap_thread(void *arg) {
269277
once = 0;
270278

271279
while (!_STOP && _HAS_WATCHERS && _HAS_LISTENERS) {
272-
if (_check_tc358743_acap(&hz) < 0 || acap->pcm_hz != hz) {
280+
if (_get_acap_hz(&hz) < 0 || acap->pcm_hz != hz) {
273281
goto close_acap;
274282
}
275283
uz size = US_RTP_DATAGRAM_SIZE - US_RTP_HEADER_SIZE;

0 commit comments

Comments
 (0)