refactoring

This commit is contained in:
Maxim Devaev
2022-06-06 17:39:03 +03:00
parent c21d0aef7e
commit 53873e9ddb
2 changed files with 8 additions and 8 deletions

View File

@@ -64,7 +64,7 @@ audio_s *audio_init(const char *name) {
audio->pcm_hz = 48000;
audio->pcm_queue = queue_init(8);
audio->enc_queue = queue_init(8);
atomic_init(&audio->run, true);
atomic_init(&audio->working, true);
int err;
@@ -134,7 +134,7 @@ audio_s *audio_init(const char *name) {
void audio_destroy(audio_s *audio) {
if (audio->tids_created) {
atomic_store(&audio->run, false);
atomic_store(&audio->working, false);
A_THREAD_JOIN(audio->pcm_tid);
A_THREAD_JOIN(audio->enc_tid);
}
@@ -168,7 +168,7 @@ void audio_destroy(audio_s *audio) {
}
int audio_get_encoded(audio_s *audio, uint8_t *data, size_t *size, uint64_t *pts) {
if (!atomic_load(&audio->run)) {
if (!atomic_load(&audio->working)) {
return -1;
}
_enc_buffer_s *buf;
@@ -192,7 +192,7 @@ static void *_pcm_thread(void *v_audio) {
audio_s *audio = (audio_s *)v_audio;
uint8_t in[MAX_BUF8];
while (atomic_load(&audio->run)) {
while (atomic_load(&audio->working)) {
int frames = snd_pcm_readi(audio->pcm, in, audio->pcm_frames);
if (frames < 0) {
JLOG_PERROR_ALSA(frames, "audio", "Can't capture PCM frames; breaking audio ...");
@@ -212,7 +212,7 @@ static void *_pcm_thread(void *v_audio) {
}
}
atomic_store(&audio->run, false);
atomic_store(&audio->working, false);
return NULL;
}
@@ -222,7 +222,7 @@ static void *_encoder_thread(void *v_audio) {
audio_s *audio = (audio_s *)v_audio;
int16_t in_res[MAX_BUF16];
while (atomic_load(&audio->run)) {
while (atomic_load(&audio->working)) {
_pcm_buffer_s *in;
if (!queue_get(audio->pcm_queue, (void **)&in, 1)) {
int16_t *in_ptr;
@@ -260,6 +260,6 @@ static void *_encoder_thread(void *v_audio) {
}
}
atomic_store(&audio->run, false);
atomic_store(&audio->working, false);
return NULL;
}

View File

@@ -61,7 +61,7 @@ typedef struct {
pthread_t pcm_tid;
pthread_t enc_tid;
bool tids_created;
atomic_bool run;
atomic_bool working;
} audio_s;