mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-07-17 17:21:55 +00:00
refactoring
This commit is contained in:
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
@@ -63,7 +62,7 @@ us_acap_s *us_acap_init(const char *name, uint pcm_hz) {
|
|||||||
US_LOG_PERROR_ALSA(err, "Can't open PCM capture");
|
US_LOG_PERROR_ALSA(err, "Can't open PCM capture");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
assert(!snd_pcm_hw_params_malloc(&acap->dev_params));
|
US_A(!snd_pcm_hw_params_malloc(&acap->dev_params));
|
||||||
|
|
||||||
# define SET_PARAM(_msg, _func, ...) { \
|
# define SET_PARAM(_msg, _func, ...) { \
|
||||||
if ((err = _func(acap->dev, acap->dev_params, ##__VA_ARGS__)) < 0) { \
|
if ((err = _func(acap->dev, acap->dev_params, ##__VA_ARGS__)) < 0) { \
|
||||||
@@ -101,12 +100,12 @@ us_acap_s *us_acap_init(const char *name, uint pcm_hz) {
|
|||||||
{
|
{
|
||||||
// OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY
|
// OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY
|
||||||
acap->enc = opus_encoder_create(US_RTP_OPUS_HZ, US_RTP_OPUS_CH, OPUS_APPLICATION_AUDIO, &err);
|
acap->enc = opus_encoder_create(US_RTP_OPUS_HZ, US_RTP_OPUS_CH, OPUS_APPLICATION_AUDIO, &err);
|
||||||
assert(err == 0);
|
US_A(err == 0);
|
||||||
// https://github.com/meetecho/janus-gateway/blob/3cdd6ff/src/plugins/janus_audiobridge.c#L2272
|
// https://github.com/meetecho/janus-gateway/blob/3cdd6ff/src/plugins/janus_audiobridge.c#L2272
|
||||||
// https://datatracker.ietf.org/doc/html/rfc7587#section-3.1.1
|
// https://datatracker.ietf.org/doc/html/rfc7587#section-3.1.1
|
||||||
assert(!opus_encoder_ctl(acap->enc, OPUS_SET_BITRATE(128000)));
|
US_A(!opus_encoder_ctl(acap->enc, OPUS_SET_BITRATE(128000)));
|
||||||
assert(!opus_encoder_ctl(acap->enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)));
|
US_A(!opus_encoder_ctl(acap->enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)));
|
||||||
assert(!opus_encoder_ctl(acap->enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)));
|
US_A(!opus_encoder_ctl(acap->enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)));
|
||||||
// OPUS_SET_INBAND_FEC(1), OPUS_SET_PACKET_LOSS_PERC(10): see rtpa.c
|
// OPUS_SET_INBAND_FEC(1), OPUS_SET_PACKET_LOSS_PERC(10): see rtpa.c
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,13 +204,13 @@ static void *_encoder_thread(void *v_acap) {
|
|||||||
|
|
||||||
s16 *in_ptr;
|
s16 *in_ptr;
|
||||||
if (acap->res != NULL) {
|
if (acap->res != NULL) {
|
||||||
assert(acap->pcm_hz != US_RTP_OPUS_HZ);
|
US_A(acap->pcm_hz != US_RTP_OPUS_HZ);
|
||||||
u32 in_count = acap->pcm_frames;
|
u32 in_count = acap->pcm_frames;
|
||||||
u32 out_count = US_AU_HZ_TO_FRAMES(US_RTP_OPUS_HZ);
|
u32 out_count = US_AU_HZ_TO_FRAMES(US_RTP_OPUS_HZ);
|
||||||
speex_resampler_process_interleaved_int(acap->res, in->data, &in_count, in_res, &out_count);
|
speex_resampler_process_interleaved_int(acap->res, in->data, &in_count, in_res, &out_count);
|
||||||
in_ptr = in_res;
|
in_ptr = in_res;
|
||||||
} else {
|
} else {
|
||||||
assert(acap->pcm_hz == US_RTP_OPUS_HZ);
|
US_A(acap->pcm_hz == US_RTP_OPUS_HZ);
|
||||||
in_ptr = in->data;
|
in_ptr = in->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <janus/plugins/plugin.h>
|
#include <janus/plugins/plugin.h>
|
||||||
@@ -169,7 +168,7 @@ static void *_acap_thread(void *v_client) {
|
|||||||
static void *_video_or_acap_thread(void *v_client, bool video) {
|
static void *_video_or_acap_thread(void *v_client, bool video) {
|
||||||
us_janus_client_s *const client = v_client;
|
us_janus_client_s *const client = v_client;
|
||||||
us_ring_s *const ring = (video ? client->video_ring : client->acap_ring);
|
us_ring_s *const ring = (video ? client->video_ring : client->acap_ring);
|
||||||
assert(ring != NULL);
|
US_A(ring != NULL);
|
||||||
|
|
||||||
while (!atomic_load(&client->stop)) {
|
while (!atomic_load(&client->stop)) {
|
||||||
const int ri = us_ring_consumer_acquire(ring, 0.1);
|
const int ri = us_ring_consumer_acquire(ring, 0.1);
|
||||||
@@ -242,7 +241,7 @@ static void *_aplay_thread(void *v_client) {
|
|||||||
|
|
||||||
int err;
|
int err;
|
||||||
OpusDecoder *dec = opus_decoder_create(US_RTP_OPUS_HZ, US_RTP_OPUS_CH, &err);
|
OpusDecoder *dec = opus_decoder_create(US_RTP_OPUS_HZ, US_RTP_OPUS_CH, &err);
|
||||||
assert(err == 0);
|
US_A(err == 0);
|
||||||
|
|
||||||
while (!atomic_load(&client->stop)) {
|
while (!atomic_load(&client->stop)) {
|
||||||
const int in_ri = us_ring_consumer_acquire(client->aplay_enc_ring, 0.1);
|
const int in_ri = us_ring_consumer_acquire(client->aplay_enc_ring, 0.1);
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -191,8 +190,8 @@ static void *_acap_thread(void *arg) {
|
|||||||
US_THREAD_SETTLE("us_p_acap");
|
US_THREAD_SETTLE("us_p_acap");
|
||||||
atomic_store(&_g_acap_tid_created, true);
|
atomic_store(&_g_acap_tid_created, true);
|
||||||
|
|
||||||
assert(_g_config->acap_dev_name != NULL);
|
US_A(_g_config->acap_dev_name != NULL);
|
||||||
assert(_g_rtpa != NULL);
|
US_A(_g_rtpa != NULL);
|
||||||
|
|
||||||
int once = 0;
|
int once = 0;
|
||||||
|
|
||||||
@@ -266,7 +265,7 @@ static void *_aplay_thread(void *arg) {
|
|||||||
US_THREAD_SETTLE("us_p_aplay");
|
US_THREAD_SETTLE("us_p_aplay");
|
||||||
atomic_store(&_g_aplay_tid_created, true);
|
atomic_store(&_g_aplay_tid_created, true);
|
||||||
|
|
||||||
assert(_g_config->aplay_dev_name != NULL);
|
US_A(_g_config->aplay_dev_name != NULL);
|
||||||
|
|
||||||
int once = 0;
|
int once = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user