[vlc-commits] aout: pass rate change separately from play

Rémi Denis-Courmont git at videolan.org
Fri May 4 11:14:52 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri May  4 12:06:15 2018 +0300| [60a64a53c87d90105ee61ddfa77985fe358388c9] | committer: Rémi Denis-Courmont

aout: pass rate change separately from play

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=60a64a53c87d90105ee61ddfa77985fe358388c9
---

 src/audio_output/aout_internal.h |  4 +++-
 src/audio_output/dec.c           | 22 ++++++++++++++++++----
 src/input/decoder.c              |  4 +++-
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 850500428e..563c775168 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -79,6 +79,7 @@ typedef struct
     struct
     {
         mtime_t end; /**< Last seen PTS */
+        float rate; /**< Play-out speed rate */
         unsigned resamp_start_drift; /**< Resampler drift absolute value */
         int resamp_type; /**< Resampler mode (FIXME: redundant / resampling) */
         bool discontinuity;
@@ -154,9 +155,10 @@ bool aout_ChangeFilterString( vlc_object_t *manager, vlc_object_t *aout,
 int aout_DecNew(audio_output_t *, const audio_sample_format_t *,
                 const audio_replay_gain_t *, const aout_request_vout_t *);
 void aout_DecDelete(audio_output_t *);
-int aout_DecPlay(audio_output_t *, block_t *, int i_input_rate);
+int aout_DecPlay(audio_output_t *aout, block_t *block);
 void aout_DecGetResetStats(audio_output_t *, unsigned *, unsigned *);
 void aout_DecChangePause(audio_output_t *, bool b_paused, mtime_t i_date);
+void aout_DecChangeRate(audio_output_t *aout, float rate);
 void aout_DecFlush(audio_output_t *, bool wait);
 void aout_RequestRestart (audio_output_t *, unsigned);
 
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 99740027a0..8bd3ded8fa 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -30,6 +30,8 @@
 
 #include <assert.h>
 
+#include <math.h>
+
 #include <vlc_common.h>
 #include <vlc_aout.h>
 #include <vlc_input.h>
@@ -351,13 +353,12 @@ static void aout_DecSynchronize (audio_output_t *aout, mtime_t dec_pts,
 /*****************************************************************************
  * aout_DecPlay : filter & mix the decoded buffer
  *****************************************************************************/
-int aout_DecPlay (audio_output_t *aout, block_t *block, int input_rate)
+int aout_DecPlay(audio_output_t *aout, block_t *block)
 {
     aout_owner_t *owner = aout_owner (aout);
+    int input_rate;
 
-    assert (input_rate >= INPUT_RATE_DEFAULT / AOUT_MAX_INPUT_RATE);
-    assert (input_rate <= INPUT_RATE_DEFAULT * AOUT_MAX_INPUT_RATE);
-    assert (block->i_pts >= VLC_TS_0);
+    assert (block->i_pts != VLC_TS_INVALID);
 
     block->i_length = CLOCK_FREQ * block->i_nb_samples
                                  / owner->input_format.i_rate;
@@ -391,6 +392,10 @@ int aout_DecPlay (audio_output_t *aout, block_t *block, int input_rate)
         vlc_mutex_unlock (&owner->vp.lock);
     }
 
+    input_rate = lroundf(owner->sync.rate * 1000.f);
+    assert(input_rate >= INPUT_RATE_DEFAULT / AOUT_MAX_INPUT_RATE);
+    assert(input_rate <= INPUT_RATE_DEFAULT * AOUT_MAX_INPUT_RATE);
+
     block = aout_FiltersPlay (owner->filters, block, input_rate);
     if (block == NULL)
         goto lost;
@@ -443,6 +448,15 @@ void aout_DecChangePause (audio_output_t *aout, bool paused, mtime_t date)
     aout_OutputUnlock (aout);
 }
 
+void aout_DecChangeRate(audio_output_t *aout, float rate)
+{
+    aout_owner_t *owner = aout_owner(aout);
+
+    aout_OutputLock(aout);
+    owner->sync.rate = rate;
+    aout_OutputUnlock(aout);
+}
+
 void aout_DecFlush (audio_output_t *aout, bool wait)
 {
     aout_owner_t *owner = aout_owner (aout);
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 3024648f37..50d3d779cd 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1186,7 +1186,9 @@ static int DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
      && i_rate <= INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE
      && !DecoderTimedWait( p_dec, p_audio->i_pts - AOUT_MAX_PREPARE_TIME ) )
     {
-        int status = aout_DecPlay( p_aout, p_audio, i_rate );
+        aout_DecChangeRate( p_aout, ((float)i_rate) / 1000.f );
+
+        int status = aout_DecPlay( p_aout, p_audio );
         if( status == AOUT_DEC_CHANGED )
         {
             /* Only reload the decoder */



More information about the vlc-commits mailing list