[vlc-devel] [RFC PATCH 11/13] FIXUP: slightly improve rate change
Thomas Guillem
thomas at gllm.fr
Wed Jun 27 14:41:33 CEST 2018
From: Denis Charmet <typx at videolan.org>
---
src/audio_output/filters.c | 2 +-
src/clock/clock.c | 14 ++++++++++----
src/input/decoder.c | 2 +-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index 99b3a7648d..a8c3df0296 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -712,7 +712,7 @@ block_t *aout_FiltersPlay(aout_filters_t *filters, block_t *block, float rate)
/* Override input rate */
nominal_rate = rate_filter->fmt_in.audio.i_rate;
- rate_filter->fmt_in.audio.i_rate = lroundf(nominal_rate / rate);
+ rate_filter->fmt_in.audio.i_rate = lroundf(nominal_rate * rate);
}
block = aout_FiltersPipelinePlay (filters->tab, filters->count, block);
diff --git a/src/clock/clock.c b/src/clock/clock.c
index c977375a8c..0a94cc9ce5 100644
--- a/src/clock/clock.c
+++ b/src/clock/clock.c
@@ -117,7 +117,6 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t * clock, vlc_tick_t system
main_clock->reset_date = VLC_TS_INVALID;
vlc_clock_main_reset(main_clock);
}
- main_clock->rate = rate;
if (unlikely(pts == VLC_TS_INVALID || system_now == VLC_TS_INVALID))
{
@@ -130,9 +129,12 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t * clock, vlc_tick_t system
/* We have a reference so we can update coeff */
float instant_coeff =
((float) (system_now - main_clock->last.system))/(pts - main_clock->last.stream);
- AvgUpdate(&main_clock->coeff_avg, instant_coeff);
- main_clock->coeff = AvgGet(&main_clock->coeff_avg);
- /* TODO handle rate change?*/
+ if (rate == main_clock->rate)
+ {
+ instant_coeff *= rate;
+ AvgUpdate(&main_clock->coeff_avg, instant_coeff);
+ main_clock->coeff = AvgGet(&main_clock->coeff_avg);
+ }
}
else
main_clock->wait_sync_ref =
@@ -143,6 +145,7 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t * clock, vlc_tick_t system
if (pts != VLC_TS_INVALID && system_now != VLC_TS_INVALID)
main_clock->last = clock_point_Create(pts, system_now);
+ main_clock->rate = rate;
vlc_cond_broadcast(&main_clock->cond);
vlc_mutex_unlock(&main_clock->lock);
return 0;
@@ -299,6 +302,9 @@ static vlc_tick_t vlc_clock_slave_update(vlc_clock_t * clock, vlc_tick_t system_
VLC_UNUSED(rate);
vlc_clock_main_t * main_clock = clock->owner;
vlc_mutex_lock(&main_clock->lock);
+ if (!main_clock->master && main_clock->rate != rate)
+ main_clock->rate = rate;
+
vlc_tick_t computed = clock->to_system_locked(clock, system_now, pts);
vlc_mutex_unlock(&main_clock->lock);
return (computed != INT64_MAX)?(computed - system_now):VLC_TS_INVALID;
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 142b3a3e33..1601201fbb 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1519,7 +1519,7 @@ static void *DecoderThread( void *p_data )
rate = p_owner->rate;
vlc_fifo_Unlock( p_owner->p_fifo );
- OutputChangeRate( p_dec, rate );
+ OutputChangeRate( p_dec, 1.f /rate );
vlc_restorecancel( canc );
vlc_fifo_Lock( p_owner->p_fifo );
--
2.18.0
More information about the vlc-devel
mailing list