[vlc-devel] [RFC PATCH 10/13] FIXUP: add a vlc_tick_t system_now to vlc_clock_ConvertToSystem
Thomas Guillem
thomas at gllm.fr
Wed Jun 27 14:41:32 CEST 2018
And always set the system time as a first argument.
---
include/vlc_aout.h | 2 +-
include/vlc_codec.h | 7 ++---
modules/codec/avcodec/video.c | 2 +-
modules/codec/synchro.c | 14 +++++-----
src/audio_output/aout_internal.h | 4 +--
src/audio_output/dec.c | 45 ++++++++++++++++----------------
src/audio_output/output.c | 6 ++---
src/clock/clock.c | 38 ++++++++++++++-------------
src/clock/clock.h | 10 +++----
src/input/decoder.c | 5 ++--
src/video_output/video_output.c | 14 ++++++----
11 files changed, 77 insertions(+), 70 deletions(-)
diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 0cdbc6183d..78e1b6508c 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -112,7 +112,7 @@
#include <vlc_block.h>
struct vlc_audio_output_events {
- void (*timing_report)(audio_output_t *, vlc_tick_t, vlc_tick_t);
+ void (*timing_report)(audio_output_t *, vlc_tick_t system_now, vlc_tick_t pts);
void (*volume_report)(audio_output_t *, float);
void (*mute_report)(audio_output_t *, bool);
void (*policy_report)(audio_output_t *, bool);
diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index 9d5c8de25c..21f52ce7e9 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -61,7 +61,7 @@ struct decoder_owner_callbacks
/* Display date
* cf. decoder_GetDisplayDate */
- vlc_tick_t (*get_display_date)( decoder_t *, vlc_tick_t );
+ vlc_tick_t (*get_display_date)( decoder_t *, vlc_tick_t, vlc_tick_t );
/* Display rate
* cf. decoder_GetDisplayRate */
float (*get_display_rate)( decoder_t * );
@@ -434,13 +434,14 @@ static inline int decoder_GetInputAttachments( decoder_t *dec,
* You MUST use it *only* for gathering statistics about speed.
*/
VLC_USED
-static inline vlc_tick_t decoder_GetDisplayDate( decoder_t *dec, vlc_tick_t i_ts )
+static inline vlc_tick_t decoder_GetDisplayDate( decoder_t *dec, vlc_tick_t system_now,
+ vlc_tick_t i_ts )
{
assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
if( !dec->cbs->video.get_display_date )
return VLC_TS_INVALID;
- return dec->cbs->video.get_display_date( dec, i_ts );
+ return dec->cbs->video.get_display_date( dec,system_now, i_ts );
}
/**
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 7bf12eba6b..f0087df299 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -762,7 +762,7 @@ static void update_late_frame_count( decoder_t *p_dec, block_t *p_block,
/* Update frame late count (except when doing preroll) */
vlc_tick_t i_display_date = VLC_TS_INVALID;
if( !p_block || !(p_block->i_flags & BLOCK_FLAG_PREROLL) )
- i_display_date = decoder_GetDisplayDate( p_dec, i_pts );
+ i_display_date = decoder_GetDisplayDate( p_dec, current_time, i_pts );
if( i_display_date != VLC_TS_INVALID && i_display_date <= current_time )
{
diff --git a/modules/codec/synchro.c b/modules/codec/synchro.c
index 8285d8c00b..69a45e6fc3 100644
--- a/modules/codec/synchro.c
+++ b/modules/codec/synchro.c
@@ -234,11 +234,11 @@ bool decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_type,
case I_CODING_TYPE:
if( b_low_delay )
{
- pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts );
+ pts = decoder_GetDisplayDate( p_synchro->p_dec, now, S.current_pts );
}
else if( S.backward_pts )
{
- pts = decoder_GetDisplayDate( p_synchro->p_dec, S.backward_pts );
+ pts = decoder_GetDisplayDate( p_synchro->p_dec, now, S.backward_pts );
}
else
{
@@ -247,7 +247,7 @@ bool decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_type,
* | +- current picture
* +- current PTS
*/
- pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts ) + period * (S.i_n_b + 2);
+ pts = decoder_GetDisplayDate( p_synchro->p_dec, now, S.current_pts ) + period * (S.i_n_b + 2);
}
if( (1 + S.i_n_p * (S.i_n_b + 1)) * period > S.p_tau[I_CODING_TYPE] )
@@ -271,15 +271,15 @@ bool decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_type,
case P_CODING_TYPE:
if( b_low_delay )
{
- pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts );
+ pts = decoder_GetDisplayDate( p_synchro->p_dec, now, S.current_pts );
}
else if( S.backward_pts )
{
- pts = decoder_GetDisplayDate( p_synchro->p_dec, S.backward_pts );
+ pts = decoder_GetDisplayDate( p_synchro->p_dec, now, S.backward_pts );
}
else
{
- pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts + period * (S.i_n_b + 1) );
+ pts = decoder_GetDisplayDate( p_synchro->p_dec, now, S.current_pts + period * (S.i_n_b + 1) );
}
if( p_synchro->i_nb_ref < 1 )
@@ -314,7 +314,7 @@ bool decoder_SynchroChoose( decoder_synchro_t * p_synchro, int i_coding_type,
break;
case B_CODING_TYPE:
- pts = decoder_GetDisplayDate( p_synchro->p_dec, S.current_pts );
+ pts = decoder_GetDisplayDate( p_synchro->p_dec, now, S.current_pts );
if( p_synchro->i_nb_ref < 2 )
{
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index b1f658b9eb..55fab1a7e9 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -154,8 +154,8 @@ void aout_DecChangeRate(audio_output_t *aout, float rate);
void aout_DecChangeDelay(audio_output_t *aout, vlc_tick_t delay);
void aout_DecFlush(audio_output_t *, bool wait);
void aout_RequestRestart (audio_output_t *, unsigned);
-void aout_RequestRetiming(audio_output_t *aout, vlc_tick_t audio_ts,
- vlc_tick_t system_ts);
+void aout_RequestRetiming(audio_output_t *aout, vlc_tick_t system_ts,
+ vlc_tick_t audio_ts);
static inline void aout_InputRequestRestart(audio_output_t *aout)
{
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 59a1c065c3..523682e619 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -226,24 +226,12 @@ static void aout_DecSilence (audio_output_t *aout, vlc_tick_t length, vlc_tick_t
block->i_dts = pts;
block->i_length = length;
aout->play(aout, block,
- vlc_clock_ConvertToSystem(owner->sync.clock, pts));
+ vlc_clock_ConvertToSystem(owner->sync.clock, vlc_tick_now(), pts));
}
-static void aout_DecSynchronize(audio_output_t *aout, vlc_tick_t dec_pts)
+static void aout_DecSynchronize(audio_output_t *aout, vlc_tick_t system_now,
+ vlc_tick_t dec_pts)
{
- aout_owner_t *owner = aout_owner (aout);
-
- if (owner->sync.request_delay != owner->sync.delay)
- {
- owner->sync.delay = owner->sync.request_delay;
- vlc_tick_t delta = vlc_clock_SetDelay(owner->sync.clock, owner->sync.delay);
- if (delta > 0)
- aout_DecSilence (aout, delta, dec_pts);
- }
-
- vlc_tick_t now = vlc_tick_now();
- vlc_tick_t delay;
-
/**
* Depending on the drift between the actual and intended playback times,
* the audio core may ignore the drift, trigger upsampling or downsampling,
@@ -260,18 +248,19 @@ static void aout_DecSynchronize(audio_output_t *aout, vlc_tick_t dec_pts)
* all samples in the buffer will have been played. Then:
* pts = vlc_tick_now() + delay
*/
+ vlc_tick_t delay;
if (aout->time_get(aout, &delay) != 0)
return; /* nothing can be done if timing is unknown */
- aout_RequestRetiming(aout, dec_pts - delay, now);
+ aout_RequestRetiming(aout, system_now, dec_pts - delay);
}
-void aout_RequestRetiming(audio_output_t *aout, vlc_tick_t audio_ts,
- vlc_tick_t system_ts)
+void aout_RequestRetiming(audio_output_t *aout, vlc_tick_t system_ts,
+ vlc_tick_t audio_ts)
{
aout_owner_t *owner = aout_owner (aout);
const float rate = owner->sync.rate;
- vlc_tick_t drift = -vlc_clock_Update(owner->sync.clock, audio_ts, system_ts,
+ vlc_tick_t drift = -vlc_clock_Update(owner->sync.clock, system_ts, audio_ts,
owner->sync.rate);
/* Late audio output.
@@ -398,8 +387,18 @@ int aout_DecPlay(audio_output_t *aout, block_t *block)
/* Software volume */
aout_volume_Amplify (owner->volume, block);
+ /* Update delay */
+ if (owner->sync.request_delay != owner->sync.delay)
+ {
+ owner->sync.delay = owner->sync.request_delay;
+ vlc_tick_t delta = vlc_clock_SetDelay(owner->sync.clock, owner->sync.delay);
+ if (delta > 0)
+ aout_DecSilence (aout, delta, block->i_pts);
+ }
+
/* Drift correction */
- aout_DecSynchronize(aout, block->i_pts);
+ vlc_tick_t system_now = vlc_tick_now();
+ aout_DecSynchronize(aout, system_now, block->i_pts);
if (owner->sync.delay != 0)
{
@@ -410,7 +409,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->play(aout, block, vlc_clock_ConvertToSystem(owner->sync.clock,
+ aout->play(aout, block, vlc_clock_ConvertToSystem(owner->sync.clock, system_now,
block->i_pts));
atomic_fetch_add_explicit(&owner->buffers_played, 1, memory_order_relaxed);
return ret;
@@ -453,7 +452,7 @@ void aout_DecChangePause (audio_output_t *aout, bool paused, vlc_tick_t date)
aout->flush(aout, false);
}
- vlc_clock_ChangePause(owner->sync.clock, paused, date);
+ vlc_clock_ChangePause(owner->sync.clock, date, paused);
}
void aout_DecChangeRate(audio_output_t *aout, float rate)
@@ -483,7 +482,7 @@ void aout_DecFlush (audio_output_t *aout, bool wait)
if (block)
{
vlc_tick_t date = vlc_clock_ConvertToSystem(owner->sync.clock,
- block->i_pts);
+ vlc_tick_now(), block->i_pts);
aout->play(aout, block, date);
}
}
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index e96d9031f8..16c7d7e10e 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -71,10 +71,10 @@ static int var_CopyDevice (vlc_object_t *src, const char *name,
return var_Set (dst, "audio-device", value);
}
-static void aout_TimingNotify(audio_output_t *aout, vlc_tick_t audio_ts,
- vlc_tick_t system_ts)
+static void aout_TimingNotify(audio_output_t *aout, vlc_tick_t system_ts,
+ vlc_tick_t audio_ts)
{
- aout_RequestRetiming(aout, audio_ts, system_ts);
+ aout_RequestRetiming(aout, system_ts, audio_ts);
}
/**
diff --git a/src/clock/clock.c b/src/clock/clock.c
index cbba4bca09..c977375a8c 100644
--- a/src/clock/clock.c
+++ b/src/clock/clock.c
@@ -58,13 +58,14 @@ struct vlc_clock_main_t
struct vlc_clock_t
{
- vlc_tick_t (*update)(vlc_clock_t * clock, vlc_tick_t timestamp,
- vlc_tick_t system_now, float rate);
+ vlc_tick_t (*update)(vlc_clock_t * clock, vlc_tick_t system_now, vlc_tick_t pts,
+ float rate);
void (*reset)(vlc_clock_t * clock);
- void (*pause)(vlc_clock_t * clock, bool paused, vlc_tick_t now);
+ void (*pause)(vlc_clock_t * clock, vlc_tick_t system_now, bool paused);
vlc_tick_t (*set_delay)(vlc_clock_t * clock, vlc_tick_t delay);
void (*set_dejitter)(vlc_clock_t * clock, vlc_tick_t delay, int cr_avg);
- vlc_tick_t (*to_system_locked)(vlc_clock_t * clock, vlc_tick_t now, vlc_tick_t pts);
+ vlc_tick_t (*to_system_locked)(vlc_clock_t * clock, vlc_tick_t system_now,
+ vlc_tick_t pts);
vlc_clock_main_t * owner;
vlc_tick_t delay;
@@ -98,8 +99,8 @@ static void vlc_clock_main_reset(vlc_clock_main_t * main_clock)
vlc_cond_broadcast(&main_clock->cond);
}
-static vlc_tick_t vlc_clock_master_update(vlc_clock_t * clock, vlc_tick_t pts,
- vlc_tick_t system_now, float rate)
+static vlc_tick_t vlc_clock_master_update(vlc_clock_t * clock, vlc_tick_t system_now,
+ vlc_tick_t pts, float rate)
{
vlc_clock_main_t * main_clock = clock->owner;
@@ -156,7 +157,7 @@ static void vlc_clock_master_reset(vlc_clock_t * clock)
vlc_mutex_unlock(&main_clock->lock);
}
-static void vlc_clock_master_pause(vlc_clock_t * clock, bool paused, vlc_tick_t now)
+static void vlc_clock_master_pause(vlc_clock_t * clock, vlc_tick_t now, bool paused)
{
vlc_clock_main_t * main_clock = clock->owner;
vlc_mutex_lock(&main_clock->lock);
@@ -292,13 +293,13 @@ static vlc_tick_t vlc_clock_master_to_system_locked(vlc_clock_t * clock, vlc_tic
return vlc_clock_main_to_system_locked(main_clock, now, pts);
}
-static vlc_tick_t vlc_clock_slave_update(vlc_clock_t * clock, vlc_tick_t timestamp,
- vlc_tick_t system_now, float rate)
+static vlc_tick_t vlc_clock_slave_update(vlc_clock_t * clock, vlc_tick_t system_now,
+ vlc_tick_t pts, float rate)
{
VLC_UNUSED(rate);
vlc_clock_main_t * main_clock = clock->owner;
vlc_mutex_lock(&main_clock->lock);
- vlc_tick_t computed = clock->to_system_locked(clock, system_now, timestamp);
+ 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;
}
@@ -311,7 +312,7 @@ static void vlc_clock_slave_reset(vlc_clock_t * clock)
vlc_mutex_unlock(&main_clock->lock);
}
-static void vlc_clock_slave_pause(vlc_clock_t * clock, bool paused, vlc_tick_t now)
+static void vlc_clock_slave_pause(vlc_clock_t * clock, vlc_tick_t now, bool paused)
{
VLC_UNUSED(clock);
VLC_UNUSED(paused);
@@ -423,10 +424,10 @@ void vlc_clock_main_Delete(vlc_clock_main_t * main_clock)
free(main_clock);
}
-vlc_tick_t vlc_clock_Update(vlc_clock_t * clock, vlc_tick_t timestamp,
- vlc_tick_t system_now, float rate)
+vlc_tick_t vlc_clock_Update(vlc_clock_t * clock, vlc_tick_t system_now, vlc_tick_t pts,
+ float rate)
{
- return clock->update(clock, timestamp, system_now, rate);
+ return clock->update(clock, system_now, pts, rate);
}
void vlc_clock_Reset(vlc_clock_t * clock)
@@ -434,9 +435,9 @@ void vlc_clock_Reset(vlc_clock_t * clock)
clock->reset(clock);
}
-void vlc_clock_ChangePause(vlc_clock_t * clock, bool paused, vlc_tick_t system_now)
+void vlc_clock_ChangePause(vlc_clock_t * clock, vlc_tick_t system_now, bool paused)
{
- clock->pause(clock, paused, system_now);
+ clock->pause(clock, system_now, paused);
}
vlc_tick_t vlc_clock_SetDelay(vlc_clock_t * clock, vlc_tick_t delay)
@@ -449,11 +450,12 @@ float vlc_clock_GetRate(vlc_clock_t * clock)
return vlc_clock_get_rate(clock);
}
-vlc_tick_t vlc_clock_ConvertToSystem(vlc_clock_t * clock, vlc_tick_t pts)
+vlc_tick_t vlc_clock_ConvertToSystem(vlc_clock_t * clock, vlc_tick_t system_now,
+ vlc_tick_t pts)
{
vlc_clock_main_t * main_clock = clock->owner;
vlc_mutex_lock(&main_clock->lock);
- vlc_tick_t system = clock->to_system_locked(clock, vlc_tick_now(), pts);
+ vlc_tick_t system = clock->to_system_locked(clock, system_now, pts);
vlc_mutex_unlock(&main_clock->lock);
return system;
}
diff --git a/src/clock/clock.h b/src/clock/clock.h
index 41469a9274..ff55ed17fb 100644
--- a/src/clock/clock.h
+++ b/src/clock/clock.h
@@ -77,8 +77,8 @@ void vlc_clock_Delete(vlc_clock_t * clock);
/**
* This function will update the clock drift and returns the drift
*/
-vlc_tick_t vlc_clock_Update(vlc_clock_t * clock, vlc_tick_t pts,
- vlc_tick_t system_now, float rate);
+vlc_tick_t vlc_clock_Update(vlc_clock_t * clock, vlc_tick_t system_now,
+ vlc_tick_t pts, float rate);
/**
* This function resets the clock drift
@@ -88,8 +88,7 @@ void vlc_clock_Reset(vlc_clock_t * clock);
/**
* This function allows changing the pause status.
*/
-void vlc_clock_ChangePause(vlc_clock_t * clock, bool paused,
- vlc_tick_t sysem_now);
+void vlc_clock_ChangePause(vlc_clock_t * clock, vlc_tick_t system_now, bool paused);
/**
* This functions change the clock delay.
@@ -111,7 +110,8 @@ int vlc_clock_Wait(vlc_clock_t * clock, vlc_tick_t pts, vlc_tick_t max_duration)
/**
* This function converts a timestamp from stream to system
*/
-vlc_tick_t vlc_clock_ConvertToSystem(vlc_clock_t * clock, vlc_tick_t pts);
+vlc_tick_t vlc_clock_ConvertToSystem(vlc_clock_t * clock, vlc_tick_t system_now,
+ vlc_tick_t pts);
void vlc_clock_ConvertArrayToSystem(vlc_clock_t * clock, vlc_tick_t system_now,
vlc_tick_t *pts_array, size_t pts_count);
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 2597431997..142b3a3e33 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -620,7 +620,8 @@ static int DecoderGetInputAttachments( decoder_t *p_dec,
ppp_attachment, pi_attachment );
}
-static vlc_tick_t DecoderGetDisplayDate( decoder_t *p_dec, vlc_tick_t i_ts )
+static vlc_tick_t DecoderGetDisplayDate( decoder_t *p_dec, vlc_tick_t system_now,
+ vlc_tick_t i_ts )
{
struct decoder_owner *p_owner = dec_get_owner( p_dec );
@@ -632,7 +633,7 @@ static vlc_tick_t DecoderGetDisplayDate( decoder_t *p_dec, vlc_tick_t i_ts )
if( !p_owner->p_clock || i_ts == VLC_TS_INVALID )
return i_ts;
- return vlc_clock_ConvertToSystem( p_owner->p_clock, i_ts );
+ return vlc_clock_ConvertToSystem( p_owner->p_clock, system_now, i_ts );
}
static float DecoderGetDisplayRate( decoder_t *p_dec )
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index adc3240eb2..a2cb70e9f0 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -890,7 +890,8 @@ static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool fra
if (is_late_dropped && !decoded->b_force) {
const vlc_tick_t date = vlc_tick_now();
const vlc_tick_t system_pts =
- vlc_clock_ConvertToSystem(vout->p->clock, decoded->date);
+ vlc_clock_ConvertToSystem(vout->p->clock, date,
+ decoded->date);
const vlc_tick_t late = date - system_pts;
vlc_tick_t late_threshold;
if (decoded->format.i_frame_rate && decoded->format.i_frame_rate_base)
@@ -1170,7 +1171,9 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
return VLC_EGENERIC;
}
- vlc_tick_t system_pts = vlc_clock_ConvertToSystem(vout->p->clock, todisplay->date);
+ system_now = vlc_tick_now(); /* XXX update it or use last one ? */
+ vlc_tick_t system_pts = vlc_clock_ConvertToSystem(vout->p->clock, system_now,
+ todisplay->date);
if (sys->display.use_dr) {
vout_display_Prepare(vd, todisplay, subpic, system_pts);
@@ -1210,7 +1213,7 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
vout_display_Display(vd, todisplay, subpic);
const vlc_tick_t now = vlc_tick_now();
- const vlc_tick_t drift = vlc_clock_Update(vout->p->clock, todisplay->date, now,
+ const vlc_tick_t drift = vlc_clock_Update(vout->p->clock, now, todisplay->date,
vout->p->rate);
vout->p->displayed.date = now + (drift != VLC_TS_INVALID ? drift : 0);
@@ -1244,7 +1247,8 @@ static int ThreadDisplayPicture(vout_thread_t *vout, vlc_tick_t *deadline)
if (!paused && vout->p->displayed.next) {
const vlc_tick_t next_system_pts =
- vlc_clock_ConvertToSystem(vout->p->clock, vout->p->displayed.next->date);
+ vlc_clock_ConvertToSystem(vout->p->clock, date,
+ vout->p->displayed.next->date);
date_next = next_system_pts - render_delay;
if (date_next <= date)
@@ -1348,7 +1352,7 @@ static void ThreadChangePause(vout_thread_t *vout, bool is_paused, vlc_tick_t da
vout_window_SetInhibition(window, !is_paused);
if (vout->p->clock)
- vlc_clock_ChangePause(vout->p->clock, is_paused, date);
+ vlc_clock_ChangePause(vout->p->clock, date, is_paused);
}
static void ThreadChangeDelay(vout_thread_t *vout, vlc_tick_t delay)
--
2.18.0
More information about the vlc-devel
mailing list