janus: camera basics

This commit is contained in:
Maxim Devaev
2026-05-31 18:28:53 +03:00
parent 8b76b59393
commit 52dfa38a8f
5 changed files with 22 additions and 27 deletions

View File

@@ -70,6 +70,7 @@ us_config_s *us_config_init(const char *config_dir_path) {
} }
} }
config->aplay_dev_name = _get_value(jcfg, "aplay", "device"); config->aplay_dev_name = _get_value(jcfg, "aplay", "device");
config->vplay_sink_name = _get_value(jcfg, "vplay", "sink");
goto ok; goto ok;
@@ -87,6 +88,7 @@ void us_config_destroy(us_config_s *config) {
US_DELETE(config->acap_dev_name, free); US_DELETE(config->acap_dev_name, free);
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);
free(config); free(config);
} }

View File

@@ -34,6 +34,7 @@ typedef struct {
char *tc358743_dev_path; char *tc358743_dev_path;
char *aplay_dev_name; char *aplay_dev_name;
char *vplay_sink_name;
} us_config_s; } us_config_s;

View File

@@ -612,21 +612,20 @@ static struct janus_plugin_result *_plugin_handle_message(
uint video_orient = 0; uint video_orient = 0;
bool with_acap = false; bool with_acap = false;
bool with_aplay = false; bool with_aplay = false;
bool with_vplay = false;
{ {
json_t *const params = json_object_get(msg, "params"); json_t *const params = json_object_get(msg, "params");
if (params != NULL) { if (params != NULL) {
{ # define READ_BOOL(x_target, x_key, x_cond) { \
json_t *const obj = json_object_get(params, "audio"); json_t *const m_obj = json_object_get(params, x_key); \
if (obj != NULL && json_is_boolean(obj)) { if (m_obj != NULL && json_is_boolean(m_obj)) { \
with_acap = (us_au_probe(_g_config->acap_dev_name) && json_boolean_value(obj)); x_target = (json_boolean_value(m_obj) && (x_cond)); \
} } \
}
{
json_t *const obj = json_object_get(params, "mic");
if (obj != NULL && json_is_boolean(obj)) {
with_aplay = (us_au_probe(_g_config->aplay_dev_name) && json_boolean_value(obj));
}
} }
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_vplay, "camera", (_g_config->vplay_sink_name != NULL));
# undef READ_BOOL
{ {
json_t *const obj = json_object_get(params, "orientation"); json_t *const obj = json_object_get(params, "orientation");
if (obj != NULL && json_is_integer(obj)) { if (obj != NULL && json_is_integer(obj)) {
@@ -642,29 +641,21 @@ static struct janus_plugin_result *_plugin_handle_message(
{ {
_LOCK_ALL; _LOCK_ALL;
bool has_listeners = false;
bool has_speakers = false;
US_LIST_ITERATE(_g_clients, client, { US_LIST_ITERATE(_g_clients, client, {
if (client->session == session) { if (client->session == session) {
char *const sdp = us_sdp_create( char *const sdp = us_sdp_create(
client->video_ssrc, client->video_ssrc,
client->audio_ssrc, client->audio_ssrc,
with_acap, with_acap,
with_aplay); with_aplay,
with_vplay);
json_t *const offer_jsep = json_pack("{ssss}", "type", "offer", "sdp", sdp); json_t *const offer_jsep = json_pack("{ssss}", "type", "offer", "sdp", sdp);
PUSH_STATUS("started", NULL, offer_jsep); PUSH_STATUS("started", NULL, offer_jsep);
json_decref(offer_jsep); json_decref(offer_jsep);
free(sdp); free(sdp);
break;
}
});
_UNLOCK_ALL;
}
{
_LOCK_ALL;
bool has_listeners = false;
bool has_speakers = false;
US_LIST_ITERATE(_g_clients, client, {
if (client->session == session) {
atomic_store(&client->transmit_acap, with_acap); atomic_store(&client->transmit_acap, with_acap);
atomic_store(&client->transmit_aplay, with_aplay); atomic_store(&client->transmit_aplay, with_aplay);
atomic_store(&client->video_orient, video_orient); atomic_store(&client->video_orient, video_orient);

View File

@@ -34,7 +34,7 @@
#include "rtpa.h" #include "rtpa.h"
char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay) { char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay, bool vplay) {
char *video_sdp; char *video_sdp;
{ {
// https://tools.ietf.org/html/rfc6184 // https://tools.ietf.org/html/rfc6184
@@ -56,9 +56,10 @@ char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay) {
"a=extmap:1/sendonly urn:3gpp:video-orientation" RN "a=extmap:1/sendonly urn:3gpp:video-orientation" RN
"a=extmap:2/sendonly http://www.webrtc.org/experiments/rtp-hdrext/playout-delay" RN "a=extmap:2/sendonly http://www.webrtc.org/experiments/rtp-hdrext/playout-delay" RN
"a=extmap:3/sendonly http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time" RN "a=extmap:3/sendonly http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time" RN
"a=sendonly" RN, "a=%s" RN,
pl, pl, pl, pl, pl, pl, pl, pl, pl, pl, pl, pl, pl, pl,
video_ssrc); video_ssrc,
(vplay ? "sendrecv" : "sendonly"));
} }
char *audio_sdp; char *audio_sdp;

View File

@@ -25,4 +25,4 @@
#include "uslibs/types.h" #include "uslibs/types.h"
char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay); char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay, bool vplay);