mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-11 01:53:43 +00:00
janus: non-tc358743 devices for acap suppurted
An alternative implementation of pikvm/ustreamer#304. Thanks for the idea.
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include <janus/config.h>
|
#include <janus/config.h>
|
||||||
#include <janus/plugins/plugin.h>
|
#include <janus/plugins/plugin.h>
|
||||||
|
|
||||||
|
#include "uslibs/types.h"
|
||||||
#include "uslibs/tools.h"
|
#include "uslibs/tools.h"
|
||||||
|
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
@@ -35,6 +36,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static char *_get_value(janus_config *jcfg, const char *section, const char *option);
|
static char *_get_value(janus_config *jcfg, const char *section, const char *option);
|
||||||
|
static uint _get_uint(janus_config *jcfg, const char *section, const char *option, uint def);
|
||||||
// static bool _get_bool(janus_config *jcfg, const char *section, const char *option, bool def);
|
// static bool _get_bool(janus_config *jcfg, const char *section, const char *option, bool def);
|
||||||
|
|
||||||
|
|
||||||
@@ -60,8 +62,10 @@ us_config_s *us_config_init(const char *config_dir_path) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if ((config->acap_dev_name = _get_value(jcfg, "acap", "device")) != NULL) {
|
if ((config->acap_dev_name = _get_value(jcfg, "acap", "device")) != NULL) {
|
||||||
if ((config->tc358743_dev_path = _get_value(jcfg, "acap", "tc358743")) == NULL) {
|
config->acap_hz = _get_uint(jcfg, "acap", "sampling_rate", 0);
|
||||||
US_JLOG_INFO("config", "Missing config value: acap.tc358743");
|
config->tc358743_dev_path = _get_value(jcfg, "acap", "tc358743");
|
||||||
|
if (config->acap_hz == 0 && config->tc358743_dev_path == NULL) {
|
||||||
|
US_JLOG_ERROR("config", "Either acap.sampling_rate or acap.tc358743 required");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
config->aplay_dev_name = _get_value(jcfg, "aplay", "device");
|
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
|
|||||||
return us_strdup(option_obj->value);
|
return us_strdup(option_obj->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint _get_uint(janus_config *jcfg, const char *section, const char *option, uint def) {
|
||||||
|
char *const tmp = _get_value(jcfg, section, option);
|
||||||
|
uint value = def;
|
||||||
|
if (tmp != NULL) {
|
||||||
|
errno = 0;
|
||||||
|
value = (uint)strtoul(tmp, NULL, 10);
|
||||||
|
if (errno != 0) {
|
||||||
|
value = def;
|
||||||
|
}
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/*static bool _get_bool(janus_config *jcfg, const char *section, const char *option, bool def) {
|
/*static bool _get_bool(janus_config *jcfg, const char *section, const char *option, bool def) {
|
||||||
char *const tmp = _get_value(jcfg, section, option);
|
char *const tmp = _get_value(jcfg, section, option);
|
||||||
bool value = def;
|
bool value = def;
|
||||||
|
|||||||
@@ -23,10 +23,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "uslibs/types.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *video_sink_name;
|
char *video_sink_name;
|
||||||
|
|
||||||
char *acap_dev_name;
|
char *acap_dev_name;
|
||||||
|
uint acap_hz;
|
||||||
char *tc358743_dev_path;
|
char *tc358743_dev_path;
|
||||||
|
|
||||||
char *aplay_dev_name;
|
char *aplay_dev_name;
|
||||||
|
|||||||
@@ -214,7 +214,15 @@ static void *_video_sink_thread(void *arg) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _check_tc358743_acap(uint *hz) {
|
static int _get_acap_hz(uint *hz) {
|
||||||
|
if (_g_config->acap_hz != 0) {
|
||||||
|
*hz = _g_config->acap_hz;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (_g_config->tc358743_dev_path == NULL) {
|
||||||
|
US_JLOG_ERROR("acap", "No configured sampling rate");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
int fd;
|
int fd;
|
||||||
if ((fd = open(_g_config->tc358743_dev_path, O_RDWR)) < 0) {
|
if ((fd = open(_g_config->tc358743_dev_path, O_RDWR)) < 0) {
|
||||||
US_JLOG_PERROR("acap", "Can't open TC358743 V4L2 device");
|
US_JLOG_PERROR("acap", "Can't open TC358743 V4L2 device");
|
||||||
@@ -236,7 +244,6 @@ static void *_acap_thread(void *arg) {
|
|||||||
atomic_store(&_g_acap_tid_created, true);
|
atomic_store(&_g_acap_tid_created, true);
|
||||||
|
|
||||||
assert(_g_config->acap_dev_name != NULL);
|
assert(_g_config->acap_dev_name != NULL);
|
||||||
assert(_g_config->tc358743_dev_path != NULL);
|
|
||||||
assert(_g_rtpa != NULL);
|
assert(_g_rtpa != NULL);
|
||||||
|
|
||||||
int once = 0;
|
int once = 0;
|
||||||
@@ -254,7 +261,7 @@ static void *_acap_thread(void *arg) {
|
|||||||
US_ONCE({ US_JLOG_ERROR("acap", "No PCM capture device"); });
|
US_ONCE({ US_JLOG_ERROR("acap", "No PCM capture device"); });
|
||||||
goto close_acap;
|
goto close_acap;
|
||||||
}
|
}
|
||||||
if (_check_tc358743_acap(&hz) < 0) {
|
if (_get_acap_hz(&hz) < 0) {
|
||||||
goto close_acap;
|
goto close_acap;
|
||||||
}
|
}
|
||||||
if (hz == 0) {
|
if (hz == 0) {
|
||||||
@@ -269,7 +276,7 @@ static void *_acap_thread(void *arg) {
|
|||||||
once = 0;
|
once = 0;
|
||||||
|
|
||||||
while (!_STOP && _HAS_WATCHERS && _HAS_LISTENERS) {
|
while (!_STOP && _HAS_WATCHERS && _HAS_LISTENERS) {
|
||||||
if (_check_tc358743_acap(&hz) < 0 || acap->pcm_hz != hz) {
|
if (_get_acap_hz(&hz) < 0 || acap->pcm_hz != hz) {
|
||||||
goto close_acap;
|
goto close_acap;
|
||||||
}
|
}
|
||||||
uz size = US_RTP_DATAGRAM_SIZE - US_RTP_HEADER_SIZE;
|
uz size = US_RTP_DATAGRAM_SIZE - US_RTP_HEADER_SIZE;
|
||||||
|
|||||||
Reference in New Issue
Block a user