Created
December 12, 2017 15:03
-
-
Save tguillem/1052ee54937b4bdd24eae666ea271b6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From b1bb5eabd61b35f7566e763e15ca537228bb9139 Mon Sep 17 00:00:00 2001 | |
From: Thomas Guillem <thomas@gllm.fr> | |
Date: Tue, 12 Dec 2017 15:57:01 +0100 | |
Subject: [PATCH] wip | |
--- | |
modules/audio_output/coreaudio_common.c | 20 +++++++++++++++++--- | |
modules/audio_output/coreaudio_common.h | 1 + | |
2 files changed, 18 insertions(+), 3 deletions(-) | |
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c | |
index d113975432..12d037e9b8 100644 | |
--- a/modules/audio_output/coreaudio_common.c | |
+++ b/modules/audio_output/coreaudio_common.c | |
@@ -50,6 +50,7 @@ ca_Open(audio_output_t *p_aout) | |
atomic_init(&p_sys->i_underrun_size, 0); | |
atomic_init(&p_sys->b_paused, false); | |
atomic_init(&p_sys->b_do_flush, false); | |
+ p_sys->b_alive = false; | |
vlc_sem_init(&p_sys->flush_sem, 0); | |
vlc_mutex_init(&p_sys->lock); | |
@@ -136,11 +137,14 @@ ca_Flush(audio_output_t *p_aout, bool wait) | |
while (TPCircularBufferTail(&p_sys->circular_buffer, &i_bytes) != NULL) | |
{ | |
- if (atomic_load(&p_sys->b_paused)) | |
+ vlc_mutex_lock(&p_sys->lock); | |
+ if (!p_sys->b_alive) | |
{ | |
+ vlc_mutex_unlock(&p_sys->lock); | |
TPCircularBufferClear(&p_sys->circular_buffer); | |
return; | |
} | |
+ vlc_mutex_unlock(&p_sys->lock); | |
/* Calculate the duration of the circular buffer, in order to wait | |
* for the render thread to play it all */ | |
@@ -160,7 +164,7 @@ ca_Flush(audio_output_t *p_aout, bool wait) | |
vlc_mutex_lock(&p_sys->lock); | |
assert(!atomic_load(&p_sys->b_do_flush)); | |
- if (atomic_load(&p_sys->b_paused)) | |
+ if (!p_sys->b_alive) | |
{ | |
vlc_mutex_unlock(&p_sys->lock); | |
TPCircularBufferClear(&p_sys->circular_buffer); | |
@@ -204,6 +208,14 @@ ca_Play(audio_output_t * p_aout, block_t * p_block) | |
break; | |
} | |
+ vlc_mutex_lock(&p_sys->lock); | |
+ if (!p_sys->b_alive) | |
+ { | |
+ vlc_mutex_unlock(&p_sys->lock); | |
+ return; | |
+ } | |
+ vlc_mutex_unlock(&p_sys->lock); | |
+ | |
/* Try to play what we can */ | |
int32_t i_avalaible_bytes; | |
TPCircularBufferHead(&p_sys->circular_buffer, &i_avalaible_bytes); | |
@@ -274,6 +286,8 @@ ca_Initialize(audio_output_t *p_aout, const audio_sample_format_t *fmt, | |
if (!TPCircularBufferInit(&p_sys->circular_buffer, i_audiobuffer_size)) | |
return VLC_EGENERIC; | |
+ ca_SetAliveState(p_aout, true); | |
+ | |
return VLC_SUCCESS; | |
} | |
@@ -291,7 +305,7 @@ ca_SetAliveState(audio_output_t *p_aout, bool alive) | |
struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys; | |
vlc_mutex_lock(&p_sys->lock); | |
- atomic_store(&p_sys->b_paused, !alive); | |
+ p_sys->b_alive = alive; | |
bool expected = true; | |
if (!alive && atomic_compare_exchange_strong(&p_sys->b_do_flush, &expected, false)) | |
diff --git a/modules/audio_output/coreaudio_common.h b/modules/audio_output/coreaudio_common.h | |
index 75b50a53d0..b387d3ae2f 100644 | |
--- a/modules/audio_output/coreaudio_common.h | |
+++ b/modules/audio_output/coreaudio_common.h | |
@@ -57,6 +57,7 @@ struct aout_sys_common | |
atomic_bool b_do_flush; | |
vlc_sem_t flush_sem; | |
vlc_mutex_t lock; | |
+ bool b_alive; | |
int i_rate; | |
unsigned int i_bytes_per_frame; | |
unsigned int i_frame_length; | |
-- | |
2.11.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment