[vlc-commits] aout: unlock time_get, play, pause and flush
Rémi Denis-Courmont
git at videolan.org
Sat May 5 11:32:21 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat May 5 12:05:55 2018 +0300| [fc5679c3b83d9dd246101bd237628f09bb210804] | committer: Rémi Denis-Courmont
aout: unlock time_get, play, pause and flush
This allows those callbacks to run without the output lock.
All existing audio outputs appeared to handle this correctly
except amem (which was fixed in the previous changeset).
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fc5679c3b83d9dd246101bd237628f09bb210804
---
src/audio_output/aout_internal.h | 4 ---
src/audio_output/dec.c | 26 ++++++++++-----
src/audio_output/output.c | 68 ----------------------------------------
3 files changed, 18 insertions(+), 80 deletions(-)
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 19ad579247..54cbf5ee09 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -129,10 +129,6 @@ void aout_Destroy (audio_output_t *);
int aout_OutputNew(audio_output_t *, audio_sample_format_t *,
aout_filters_cfg_t *filters_cfg);
-int aout_OutputTimeGet(audio_output_t *, mtime_t *);
-void aout_OutputPlay(audio_output_t *, block_t *block, mtime_t date);
-void aout_OutputPause( audio_output_t * p_aout, bool, mtime_t );
-void aout_OutputFlush( audio_output_t * p_aout, bool );
void aout_OutputDelete( audio_output_t * p_aout );
void aout_OutputLock(audio_output_t *);
void aout_OutputUnlock(audio_output_t *);
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 135768381a..3bf66253f4 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -221,7 +221,7 @@ static void aout_DecSilence (audio_output_t *aout, mtime_t length, mtime_t pts)
block->i_pts = pts;
block->i_dts = pts;
block->i_length = length;
- aout_OutputPlay(aout, block, pts);
+ aout->play(aout, block, pts);
}
static void aout_DecSynchronize(audio_output_t *aout, mtime_t dec_pts)
@@ -230,6 +230,9 @@ static void aout_DecSynchronize(audio_output_t *aout, mtime_t dec_pts)
const float rate = owner->sync.rate;
mtime_t drift;
+ if (unlikely(aout->time_get == NULL))
+ return;
+
/**
* Depending on the drift between the actual and intended playback times,
* the audio core may ignore the drift, trigger upsampling or downsampling,
@@ -246,7 +249,7 @@ static void aout_DecSynchronize(audio_output_t *aout, mtime_t dec_pts)
* all samples in the buffer will have been played. Then:
* pts = mdate() + delay
*/
- if (aout_OutputTimeGet (aout, &drift) != 0)
+ if (aout->time_get(aout, &drift) != 0)
return; /* nothing can be done if timing is unknown */
drift += mdate () - dec_pts;
@@ -265,14 +268,14 @@ static void aout_DecSynchronize(audio_output_t *aout, mtime_t dec_pts)
else
msg_Dbg (aout, "playback too late (%"PRId64"): "
"flushing buffers", drift);
- aout_OutputFlush (aout, false);
+ aout->flush(aout, false);
aout_StopResampling (aout);
owner->sync.end = VLC_TS_INVALID;
owner->sync.discontinuity = true;
/* Now the output might be too early... Recheck. */
- if (aout_OutputTimeGet (aout, &drift) != 0)
+ if (aout->time_get(aout, &drift) != 0)
return; /* nothing can be done if timing is unknown */
drift += mdate () - dec_pts;
}
@@ -396,7 +399,7 @@ int aout_DecPlay(audio_output_t *aout, block_t *block)
/* Output */
owner->sync.end = block->i_pts + block->i_length + 1;
owner->sync.discontinuity = false;
- aout_OutputPlay(aout, block, block->i_pts);
+ aout->play(aout, block, block->i_pts);
atomic_fetch_add_explicit(&owner->buffers_played, 1, memory_order_relaxed);
return ret;
drop:
@@ -429,8 +432,14 @@ void aout_DecChangePause (audio_output_t *aout, bool paused, mtime_t date)
else
owner->sync.end += date;
}
+
if (owner->mixer_format.i_format)
- aout_OutputPause (aout, paused, date);
+ {
+ if (aout->pause != NULL)
+ aout->pause(aout, paused, date);
+ else if (paused)
+ aout->flush(aout, false);
+ }
}
void aout_DecChangeRate(audio_output_t *aout, float rate)
@@ -451,10 +460,11 @@ void aout_DecFlush (audio_output_t *aout, bool wait)
{
block_t *block = aout_FiltersDrain (owner->filters);
if (block)
- aout_OutputPlay(aout, block, block->i_pts);
+ aout->play(aout, block, block->i_pts);
}
else
aout_FiltersFlush (owner->filters);
- aout_OutputFlush (aout, wait);
+
+ aout->flush(aout, wait);
}
}
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 6939b08301..536a208403 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -609,74 +609,6 @@ void aout_OutputDelete (audio_output_t *aout)
aout_OutputUnlock(aout);
}
-int aout_OutputTimeGet (audio_output_t *aout, mtime_t *delay)
-{
- int ret;
-
- if (aout->time_get == NULL)
- return -1;
-
- aout_OutputLock(aout);
- ret = aout->time_get (aout, delay);
- aout_OutputUnlock(aout);
- return ret;
-}
-
-/**
- * Plays a decoded audio buffer.
- * \note This can only be called after a successful aout_OutputNew().
- * \warning The caller must NOT hold the audio output lock.
- */
-void aout_OutputPlay(audio_output_t *aout, block_t *block, mtime_t date)
-{
-#ifndef NDEBUG
- aout_owner_t *owner = aout_owner (aout);
- assert (owner->mixer_format.i_frame_length > 0);
- assert (block->i_buffer == 0 || block->i_buffer / block->i_nb_samples ==
- owner->mixer_format.i_bytes_per_frame /
- owner->mixer_format.i_frame_length);
-#endif
- aout_OutputLock(aout);
- aout->play(aout, block, date);
- aout_OutputUnlock(aout);
-}
-
-static void PauseDefault (audio_output_t *aout, bool pause, mtime_t date)
-{
- if (pause)
- aout->flush(aout, false);
- (void) date;
-}
-
-/**
- * Notifies the audio output (if any) of pause/resume events.
- * This enables the output to expedite pause, instead of waiting for its
- * buffers to drain.
- * \note This can only be called after a successful aout_OutputNew().
- * \warning The caller must NOT hold the audio output lock.
- */
-void aout_OutputPause( audio_output_t *aout, bool pause, mtime_t date )
-{
- aout_OutputLock(aout);
- ((aout->pause != NULL) ? aout->pause : PauseDefault) (aout, pause, date);
- aout_OutputUnlock(aout);
-}
-
-/**
- * Flushes or drains the audio output buffers.
- * This enables the output to expedite seek and stop.
- * \param wait if true, wait for buffer playback (i.e. drain),
- * if false, discard the buffers immediately (i.e. flush)
- * \note This can only be called after a successful aout_OutputNew().
- * \warning The caller must NOT hold the audio output lock.
- */
-void aout_OutputFlush( audio_output_t *aout, bool wait )
-{
- aout_OutputLock(aout);
- aout->flush (aout, wait);
- aout_OutputUnlock(aout);
-}
-
static int aout_OutputVolumeSet (audio_output_t *aout, float vol)
{
aout_OutputAssertLocked (aout);
More information about the vlc-commits
mailing list