[vlc-devel] [RFC PATCH 4/4] fixup! player: add the timer API
Thomas Guillem
thomas at gllm.fr
Tue Sep 10 18:33:07 CEST 2019
Use the npt from the input.
---
src/player/input.c | 4 ++++
src/player/player.h | 4 ++++
src/player/timer.c | 17 ++++++++++++++---
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/player/input.c b/src/player/input.c
index 81b47844a5..0222874105 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -678,6 +678,10 @@ input_thread_Events(input_thread_t *input_thread,
vlc_player_SendEvent(player, on_length_changed, input->length);
changed = true;
}
+
+ if (event->times.npt != VLC_TICK_INVALID)
+ vlc_player_UpdateTimerNPT(player, event->times.npt);
+
if (changed)
{
const struct vlc_player_timer_point point = {
diff --git a/src/player/player.h b/src/player/player.h
index c87878bab0..3b892cf331 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -168,6 +168,7 @@ struct vlc_player_timer
{
vlc_mutex_t lock;
vlc_tick_t input_length;
+ vlc_tick_t input_npt;
float input_position;
struct vlc_player_timer_source sources[VLC_PLAYER_TIMER_TYPE_COUNT];
#define best_source sources[VLC_PLAYER_TIMER_TYPE_BEST]
@@ -389,6 +390,9 @@ vlc_player_UpdateTimerState(vlc_player_t *player, vlc_es_id_t *es_source,
enum vlc_player_timer_state state,
vlc_tick_t interpolate_date, vlc_tick_t system_date);
+void
+vlc_player_UpdateTimerNPT(vlc_player_t *player, vlc_tick_t npt);
+
void
vlc_player_UpdateTimer(vlc_player_t *player, vlc_es_id_t *es_source,
bool es_source_is_master,
diff --git a/src/player/timer.c b/src/player/timer.c
index 827d9ec120..e18cfdef58 100644
--- a/src/player/timer.c
+++ b/src/player/timer.c
@@ -31,6 +31,7 @@ vlc_player_Reset(vlc_player_t *player)
{
player->timer.smpte_source.smpte.last_ts = VLC_TICK_INVALID;
player->timer.input_length = VLC_TICK_INVALID;
+ player->timer.input_npt = VLC_TICK_0;
player->timer.input_position = 0.f;
}
@@ -69,6 +70,7 @@ vlc_player_SendSmpteTimerSourceUpdates(vlc_player_t *player,
source->smpte.last_ts = point->ts;
+ const vlc_tick_t ts = point->ts - player->timer.input_npt;
struct vlc_player_timer_smpte_timecode tc;
long framenum;
unsigned frame_rate;
@@ -83,7 +85,7 @@ vlc_player_SendSmpteTimerSourceUpdates(vlc_player_t *player,
frame_rate_base = 1001;
/* Convert the ts to a frame number */
- framenum = round((point->ts - VLC_TICK_0) * frame_rate
+ framenum = round(ts * frame_rate
/ (double) frame_rate_base / VLC_TICK_FROM_SEC(1));
/* Drop 2 or 4 frames every minutes except every 10 minutes in order to
@@ -108,7 +110,7 @@ vlc_player_SendSmpteTimerSourceUpdates(vlc_player_t *player,
frame_rate_base = source->smpte.frame_rate_base;
/* Convert the ts to a frame number */
- framenum = round((point->ts - VLC_TICK_0) * frame_rate
+ framenum = round(ts * frame_rate
/ (double) frame_rate_base / VLC_TICK_FROM_SEC(1));
tc.drop_frame = false;
@@ -223,6 +225,14 @@ vlc_player_UpdateTimerState(vlc_player_t *player, vlc_es_id_t *es_source,
vlc_mutex_unlock(&player->timer.lock);
}
+void
+vlc_player_UpdateTimerNPT(vlc_player_t *player, vlc_tick_t npt)
+{
+ vlc_mutex_lock(&player->timer.lock);
+ player->timer.input_npt = npt;
+ vlc_mutex_unlock(&player->timer.lock);
+}
+
static void
vlc_player_UpdateTimerSource(vlc_player_t *player,
struct vlc_player_timer_source *source,
@@ -230,12 +240,13 @@ vlc_player_UpdateTimerSource(vlc_player_t *player,
bool *force_update)
{
assert(ts != VLC_TICK_INVALID && ts >= VLC_TICK_0);
+ assert(player->timer.input_npt >= VLC_TICK_0);
*force_update = source->point.rate != rate
|| source->point.length != player->timer.input_length;
source->point.rate = rate;
- source->point.ts = ts;
+ source->point.ts = ts - player->timer.input_npt;
source->point.system_date = system_date;
source->point.length = player->timer.input_length;
--
2.20.1
More information about the vlc-devel
mailing list