[vlc-devel] [PATCH 2/2] input: handle relative seek (or jump)
Thomas Guillem
thomas at gllm.fr
Mon Sep 3 17:56:58 CEST 2018
Add relative seek support, via position (float) or by time (tick). This will be
used by the future vlc_player.
---
src/input/input.c | 47 ++++++++++++++++++++++++++++++--------
src/input/input_internal.h | 2 ++
2 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/src/input/input.c b/src/input/input.c
index 17901d4a6c..d87583cdd7 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -237,6 +237,7 @@ void input_SetTime( input_thread_t *p_input, vlc_tick_t i_time, bool b_fast )
param.time.i_val = i_time;
param.time.b_fast_seek = b_fast;
+ param.time.b_absolute = true;
input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, ¶m );
}
@@ -246,6 +247,7 @@ void input_SetPosition( input_thread_t *p_input, float f_position, bool b_fast )
param.pos.f_val = f_position;
param.pos.b_fast_seek = b_fast;
+ param.pos.b_absolute = true;
input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, ¶m );
}
@@ -1835,10 +1837,21 @@ static void ControlInsertDemuxFilter( input_thread_t* p_input, const char* psz_d
msg_Dbg(p_input, "Failed to create demux filter %s", psz_demux_chain);
}
-static int DemuxSetPostion(input_thread_t *p_input, double pos, bool fast)
+static int DemuxSetPostion(input_thread_t *p_input, double pos, bool fast,
+ bool absolute)
{
input_thread_private_t *priv = input_priv(p_input);
+ if (!absolute)
+ {
+ double current_pos;
+ int ret = demux_Control(priv->master->p_demux, DEMUX_GET_POSITION,
+ ¤t_pos);
+ if (ret != VLC_SUCCESS)
+ return ret;
+ pos += current_pos;
+ }
+
if (pos < 0.f )
pos = 0.f;
else if (pos > 1.f)
@@ -1847,10 +1860,21 @@ static int DemuxSetPostion(input_thread_t *p_input, double pos, bool fast)
pos, !fast);
}
-static int DemuxSetTime(input_thread_t *p_input, vlc_tick_t time, bool fast)
+static int DemuxSetTime(input_thread_t *p_input, vlc_tick_t time, bool fast,
+ bool absolute)
{
input_thread_private_t *priv = input_priv(p_input);
+ if (!absolute)
+ {
+ vlc_tick_t current_time;
+ int ret = demux_Control(priv->master->p_demux, DEMUX_GET_TIME,
+ ¤t_time);
+ if (ret != VLC_SUCCESS)
+ return ret;
+ time += current_time;
+ }
+
if (time < 0)
time = 0;
return demux_Control(priv->master->p_demux, DEMUX_SET_TIME, time, !fast);
@@ -1877,10 +1901,12 @@ static bool Control( input_thread_t *p_input,
/* Reset the decoders states and clock sync (before calling the demuxer */
es_out_Control( priv->p_es_out, ES_OUT_RESET_PCR );
if (DemuxSetPostion(p_input, (double) param.pos.f_val,
- param.pos.b_fast_seek))
+ param.pos.b_fast_seek, param.pos.b_absolute))
{
msg_Err( p_input, "INPUT_CONTROL_SET_POSITION "
- "%2.1f%% failed", (double)(param.pos.f_val * 100.f) );
+ "%s%2.1f%% failed",
+ param.pos.b_absolute ? "@" : param.pos.f_val >= 0 ? "+" : "",
+ (double)(param.pos.f_val * 100.f) );
}
else
{
@@ -1905,8 +1931,8 @@ static bool Control( input_thread_t *p_input,
/* Reset the decoders states and clock sync (before calling the demuxer */
es_out_Control( priv->p_es_out, ES_OUT_RESET_PCR );
- i_ret = DemuxSetTime(p_input, param.time.i_val,
- param.time.b_fast_seek);
+ i_ret = DemuxSetTime(p_input, param.time.i_val,
+ param.time.b_fast_seek, param.time.b_absolute);
if( i_ret )
{
int64_t i_length;
@@ -1916,13 +1942,16 @@ static bool Control( input_thread_t *p_input,
DEMUX_GET_LENGTH, &i_length ) && i_length > 0 )
{
double f_pos = (double)param.time.i_val / (double)i_length;
- i_ret = DemuxSetPostion(p_input, f_pos, param.time.b_fast_seek);
+ i_ret = DemuxSetPostion(p_input, f_pos, param.time.b_fast_seek,
+ param.time.b_absolute);
}
}
if( i_ret )
{
- msg_Warn( p_input, "INPUT_CONTROL_SET_TIME %"PRId64
- " failed or not possible", param.time.i_val );
+ msg_Warn( p_input, "INPUT_CONTROL_SET_TIME %s%"PRId64
+ " failed or not possible",
+ param.time.b_absolute ? "@" : param.time.i_val >= 0 ? "+" : "",
+ param.time.i_val );
}
else
{
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 08a3a1d5f1..2818c2c2cd 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -84,10 +84,12 @@ typedef union
vlc_viewpoint_t viewpoint;
struct {
bool b_fast_seek;
+ bool b_absolute;
vlc_tick_t i_val;
} time;
struct {
bool b_fast_seek;
+ bool b_absolute;
float f_val;
} pos;
} input_control_param_t;
--
2.18.0
More information about the vlc-devel
mailing list