mirror of
https://github.com/pikvm/ustreamer.git
synced 2025-12-24 03:00:01 +00:00
block signals in threads
This commit is contained in:
parent
c8dc5119fe
commit
98b5e52a68
@ -195,7 +195,7 @@ static _enc_buffer_s *_enc_buffer_init(void) {
|
||||
}
|
||||
|
||||
static void *_pcm_thread(void *v_audio) {
|
||||
US_THREAD_RENAME("us_a_pcm");
|
||||
US_THREAD_SETTLE("us_a_pcm");
|
||||
|
||||
us_audio_s *const audio = (us_audio_s *)v_audio;
|
||||
uint8_t in[_MAX_BUF8];
|
||||
@ -225,7 +225,7 @@ static void *_pcm_thread(void *v_audio) {
|
||||
}
|
||||
|
||||
static void *_encoder_thread(void *v_audio) {
|
||||
US_THREAD_RENAME("us_a_enc");
|
||||
US_THREAD_SETTLE("us_a_enc");
|
||||
|
||||
us_audio_s *const audio = (us_audio_s *)v_audio;
|
||||
int16_t in_res[_MAX_BUF16];
|
||||
|
||||
@ -93,10 +93,12 @@ void us_janus_client_send(us_janus_client_s *client, const us_rtp_s *rtp) {
|
||||
}
|
||||
|
||||
static void *_video_thread(void *v_client) {
|
||||
US_THREAD_SETTLE("us_c_video");
|
||||
return _common_thread(v_client, true);
|
||||
}
|
||||
|
||||
static void *_audio_thread(void *v_client) {
|
||||
US_THREAD_SETTLE("us_c_audio");
|
||||
return _common_thread(v_client, false);
|
||||
}
|
||||
|
||||
|
||||
@ -100,8 +100,7 @@ janus_plugin *create(void);
|
||||
|
||||
static void *_video_rtp_thread(void *arg) {
|
||||
(void)arg;
|
||||
|
||||
US_THREAD_RENAME("us_video_rtp");
|
||||
US_THREAD_SETTLE("us_video_rtp");
|
||||
atomic_store(&_g_video_rtp_tid_created, true);
|
||||
|
||||
while (!_STOP) {
|
||||
@ -120,8 +119,7 @@ static void *_video_rtp_thread(void *arg) {
|
||||
|
||||
static void *_video_sink_thread(void *arg) {
|
||||
(void)arg;
|
||||
|
||||
US_THREAD_RENAME("us_video_sink");
|
||||
US_THREAD_SETTLE("us_video_sink");
|
||||
atomic_store(&_g_video_sink_tid_created, true);
|
||||
|
||||
us_frame_s *drop = us_frame_init();
|
||||
@ -185,15 +183,16 @@ static void *_video_sink_thread(void *arg) {
|
||||
US_JLOG_INFO("video", "Memsink closed");
|
||||
sleep(1); // error_delay
|
||||
}
|
||||
|
||||
us_frame_destroy(drop);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *_audio_thread(void *arg) {
|
||||
(void)arg;
|
||||
|
||||
US_THREAD_RENAME("us_audio");
|
||||
US_THREAD_SETTLE("us_audio");
|
||||
atomic_store(&_g_audio_tid_created, true);
|
||||
|
||||
assert(_g_config->audio_dev_name != NULL);
|
||||
assert(_g_config->tc358743_dev_path != NULL);
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <sys/syscall.h>
|
||||
@ -56,9 +57,14 @@
|
||||
us_thread_set_name(m_new_tname_buf); \
|
||||
}
|
||||
#else
|
||||
# define US_THREAD_RENAME(_fmt, ...)
|
||||
# define US_THREAD_RENAME(x_fmt, ...)
|
||||
#endif
|
||||
|
||||
#define US_THREAD_SETTLE(x_fmt, ...) { \
|
||||
US_THREAD_RENAME((x_fmt), ##__VA_ARGS__); \
|
||||
us_thread_block_signals(); \
|
||||
}
|
||||
|
||||
#define US_MUTEX_INIT(x_mutex) assert(!pthread_mutex_init(&(x_mutex), NULL))
|
||||
#define US_MUTEX_DESTROY(x_mutex) assert(!pthread_mutex_destroy(&(x_mutex)))
|
||||
#define US_MUTEX_LOCK(x_mutex) assert(!pthread_mutex_lock(&(x_mutex)))
|
||||
@ -124,3 +130,11 @@ INLINE void us_thread_get_name(char *name) { // Always required for logging
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
INLINE void us_thread_block_signals(void) {
|
||||
sigset_t mask;
|
||||
assert(!sigemptyset(&mask));
|
||||
assert(!sigaddset(&mask, SIGINT));
|
||||
assert(!sigaddset(&mask, SIGTERM));
|
||||
assert(!pthread_sigmask(SIG_BLOCK, &mask, NULL));
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ static void _block_thread_signals(void) {
|
||||
|
||||
static void *_stream_loop_thread(void *arg) {
|
||||
(void)arg;
|
||||
US_THREAD_RENAME("stream");
|
||||
US_THREAD_SETTLE("stream");
|
||||
_block_thread_signals();
|
||||
us_stream_loop(_g_stream);
|
||||
return NULL;
|
||||
@ -62,7 +62,7 @@ static void *_stream_loop_thread(void *arg) {
|
||||
|
||||
static void *_server_loop_thread(void *arg) {
|
||||
(void)arg;
|
||||
US_THREAD_RENAME("http");
|
||||
US_THREAD_SETTLE("http");
|
||||
_block_thread_signals();
|
||||
us_server_loop(_g_server);
|
||||
return NULL;
|
||||
|
||||
@ -279,6 +279,7 @@ void _stream_set_capture_state(us_stream_s *stream, uint width, uint height, boo
|
||||
}
|
||||
|
||||
static void *_releaser_thread(void *v_ctx) {
|
||||
US_THREAD_SETTLE("str_rel")
|
||||
_releaser_context_s *ctx = v_ctx;
|
||||
|
||||
while (!atomic_load(ctx->stop)) {
|
||||
@ -308,6 +309,7 @@ done:
|
||||
}
|
||||
|
||||
static void *_jpeg_thread(void *v_ctx) {
|
||||
US_THREAD_SETTLE("str_jpeg")
|
||||
_jpeg_context_s *ctx = v_ctx;
|
||||
us_stream_s *stream = ctx->stream;
|
||||
|
||||
@ -372,6 +374,7 @@ static void *_jpeg_thread(void *v_ctx) {
|
||||
}
|
||||
|
||||
static void *_h264_thread(void *v_ctx) {
|
||||
US_THREAD_SETTLE("str_h264");
|
||||
_h264_context_s *ctx = v_ctx;
|
||||
|
||||
ldf last_encode_ts = us_get_now_monotonic();
|
||||
|
||||
@ -178,7 +178,7 @@ long double us_workers_pool_get_fluency_delay(us_workers_pool_s *pool, const us_
|
||||
static void *_worker_thread(void *v_worker) {
|
||||
us_worker_s *wr = (us_worker_s *)v_worker;
|
||||
|
||||
US_THREAD_RENAME("%s", wr->name);
|
||||
US_THREAD_SETTLE("%s", wr->name);
|
||||
US_LOG_DEBUG("Hello! I am a worker %s ^_^", wr->name);
|
||||
|
||||
while (!atomic_load(&wr->pool->stop)) {
|
||||
|
||||
@ -227,11 +227,10 @@ static void _main_loop(void) {
|
||||
}
|
||||
|
||||
static void *_follower_thread(void *v_unix_follow) {
|
||||
US_THREAD_SETTLE("follower");
|
||||
const char *path = v_unix_follow;
|
||||
assert(path != NULL);
|
||||
|
||||
US_THREAD_RENAME("follower");
|
||||
|
||||
while (!atomic_load(&_g_stop)) {
|
||||
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
assert(fd >= 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user