refactoring

This commit is contained in:
Maxim Devaev
2022-07-20 06:05:05 +03:00
parent cbee3adb2e
commit 5c747a5b5d
12 changed files with 33 additions and 61 deletions

View File

@@ -134,20 +134,12 @@ void us_audio_destroy(us_audio_s *audio) {
US_THREAD_JOIN(audio->pcm_tid);
US_THREAD_JOIN(audio->enc_tid);
}
if (audio->enc) {
opus_encoder_destroy(audio->enc);
}
if (audio->res) {
speex_resampler_destroy(audio->res);
}
if (audio->pcm) {
snd_pcm_close(audio->pcm);
}
if (audio->pcm_params) {
snd_pcm_hw_params_free(audio->pcm_params);
}
US_QUEUE_FREE_ITEMS_AND_DESTROY(audio->enc_queue, free);
US_QUEUE_FREE_ITEMS_AND_DESTROY(audio->pcm_queue, free);
US_DELETE(audio->enc, opus_encoder_destroy);
US_DELETE(audio->res, speex_resampler_destroy);
US_DELETE(audio->pcm, snd_pcm_close);
US_DELETE(audio->pcm_params, snd_pcm_hw_params_free);
US_QUEUE_DELETE_WITH_ITEMS(audio->enc_queue, free);
US_QUEUE_DELETE_WITH_ITEMS(audio->pcm_queue, free);
if (audio->tids_created) {
US_JLOG_INFO("audio", "Pipeline closed");
}

View File

@@ -55,10 +55,10 @@ void us_janus_client_destroy(us_janus_client_s *client) {
}
US_THREAD_JOIN(client->video_tid);
US_QUEUE_FREE_ITEMS_AND_DESTROY(client->video_queue, us_rtp_destroy);
US_QUEUE_DELETE_WITH_ITEMS(client->video_queue, us_rtp_destroy);
if (client->audio_queue != NULL) {
US_THREAD_JOIN(client->audio_tid);
US_QUEUE_FREE_ITEMS_AND_DESTROY(client->audio_queue, us_rtp_destroy);
US_QUEUE_DELETE_WITH_ITEMS(client->audio_queue, us_rtp_destroy);
}
free(client);
}

View File

@@ -231,9 +231,7 @@ static void *_audio_thread(UNUSED void *arg) {
}
close_audio:
if (audio != NULL) {
us_audio_destroy(audio);
}
US_DELETE(audio, us_audio_destroy);
sleep(1); // error_delay
}
return NULL;
@@ -288,7 +286,7 @@ static void _plugin_destroy(void) {
us_janus_client_destroy(client);
});
US_QUEUE_FREE_ITEMS_AND_DESTROY(_g_video_queue, us_frame_destroy);
US_QUEUE_DELETE_WITH_ITEMS(_g_video_queue, us_frame_destroy);
US_DELETE(_g_rtpa, us_rtpa_destroy);
US_DELETE(_g_rtpv, us_rtpv_destroy);

View File

@@ -47,13 +47,12 @@ typedef struct {
} us_queue_s;
#define US_QUEUE_FREE_ITEMS_AND_DESTROY(x_queue, x_free_item) { \
#define US_QUEUE_DELETE_WITH_ITEMS(x_queue, x_free_item) { \
if (x_queue) { \
while (!us_queue_get_free(x_queue)) { \
void *m_ptr; \
assert(!us_queue_get(x_queue, &m_ptr, 0.1)); \
if (m_ptr != NULL) { \
x_free_item(m_ptr); \
if (!us_queue_get(x_queue, &m_ptr, 0)) { \
US_DELETE(m_ptr, x_free_item); \
} \
} \
us_queue_destroy(x_queue); \