[vlc-devel] [RFC V2 1/2] input: add input_SetTime and input_SetPosition
Zhao Zhili
quinkblack at foxmail.com
Tue Jun 19 10:31:40 CEST 2018
On 2018年06月19日 15:14, Thomas Guillem wrote:
> I think this patches goes to the right direction (getting ride of variable callback to control the input).
> One question, should the "input-fast-seek" var should be fetched only one time when the input is created ?
Good point. I should not remove
- bool b_fast_seek;/* :input-fast-seek */
By the way, I think the libvlc API is incomplete without a
SeekComplete event like in Android MediaPlayer API. The GUI
doesn't know whether it should update the slider position (during
playback) or not (during seeking). The workaround in TimeCallback
related to intf behavior is error prone. Since Control() and
input_SendEventPosition() are serial, a Seeking event is a good
indicator to the GUI:
1. During seeking, move the slider to the new position and don't
update the slider position according to libvlc_MediaPlayerTimeChanged
2. After receving the Seeking event, update the slider position
according to libvlc_MediaPlayerTimeChanged
>
> On Fri, Jun 15, 2018, at 14:57, Zhao Zhili wrote:
>> ---
>> include/vlc_input.h | 4 +++
>> src/input/input.c | 83 +++++++++++++++++++++++++++++++++++++---------
>> src/input/input_internal.h | 1 -
>> src/input/var.c | 8 ++---
>> src/libvlccore.sym | 2 ++
>> 5 files changed, 77 insertions(+), 21 deletions(-)
>>
>> diff --git a/include/vlc_input.h b/include/vlc_input.h
>> index 16c566a..7e04713 100644
>> --- a/include/vlc_input.h
>> +++ b/include/vlc_input.h
>> @@ -512,6 +512,10 @@ VLC_API int input_vaControl( input_thread_t *, int
>> i_query, va_list );
>>
>> VLC_API int input_Control( input_thread_t *, int i_query, ... );
>>
>> +VLC_API int input_SetTime( input_thread_t *, mtime_t i_time, bool
>> b_fast );
>> +
>> +VLC_API int input_SetPosition( input_thread_t *, float f_position, bool
>> b_fast );
>> +
>> VLC_API void input_Close( input_thread_t * );
>>
>> /**
>> diff --git a/src/input/input.c b/src/input/input.c
>> index a413683..9003d61 100644
>> --- a/src/input/input.c
>> +++ b/src/input/input.c
>> @@ -227,6 +227,46 @@ void input_Close( input_thread_t *p_input )
>> vlc_object_release( p_input );
>> }
>>
>> +typedef struct input_seek_params_t {
>> + bool b_fast;
>> + union {
>> + mtime_t i_time;
>> + float f_position;
>> + };
>> +} input_seek_params_t;
>> +
>> +int input_SetTime( input_thread_t *p_input, mtime_t i_time, bool b_fast )
>> +{
>> + vlc_value_t val;
>> + input_seek_params_t *param;
>> +
>> + param = malloc( sizeof(*param) );
>> + if( unlikely(param == NULL) )
>> + return VLC_ENOMEM;
>> +
>> + param->b_fast = b_fast;
>> + param->i_time = i_time;
>> + val.p_address = param;
>> + input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );
>> + return VLC_SUCCESS;
>> +}
>> +
>> +int input_SetPosition( input_thread_t *p_input, float f_position, bool b_fast )
>> +{
>> + vlc_value_t val;
>> + input_seek_params_t *param;
>> +
>> + param = malloc( sizeof(*param) );
>> + if( unlikely(param == NULL) )
>> + return VLC_ENOMEM;
>> +
>> + param->b_fast = b_fast;
>> + param->f_position = f_position;
>> + val.p_address = param;
>> + input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );
>> + return VLC_SUCCESS;
>> +}
>> +
>> /**
>> * Input destructor (called when the object's refcount reaches 0).
>> */
>> @@ -630,16 +670,15 @@ static int MainLoopTryRepeat( input_thread_t *p_input )
>> input_ControlPush( p_input,
>> INPUT_CONTROL_SET_SEEKPOINT, &val );
>>
>> + bool b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
>> /* Seek to start position */
>> if( input_priv(p_input)->i_start > 0 )
>> {
>> - val.i_int = input_priv(p_input)->i_start;
>> - input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );
>> + input_SetTime( p_input, input_priv(p_input)->i_start, b_fast_seek );
>> }
>> else
>> {
>> - val.f_float = 0.f;
>> - input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );
>> + input_SetPosition( p_input, 0.0f, b_fast_seek );
>> }
>>
>> return VLC_SUCCESS;
>> @@ -916,20 +955,17 @@ static void StartTitle( input_thread_t * p_input )
>>
>> if( priv->i_start > 0 )
>> {
>> - vlc_value_t s;
>> -
>> msg_Dbg( p_input, "starting at time: %"PRId64"s",
>> priv->i_start / CLOCK_FREQ );
>>
>> - s.i_int = priv->i_start;
>> - input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
>> + bool b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
>> + input_SetTime( p_input, priv->i_start, b_fast_seek );
>> }
>> if( priv->i_stop > 0 && priv->i_stop <= priv->i_start )
>> {
>> msg_Warn( p_input, "invalid stop-time ignored" );
>> priv->i_stop = 0;
>> }
>> - priv->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
>> }
>>
>> static int SlaveCompare(const void *a, const void *b)
>> @@ -1627,6 +1663,8 @@ static void ControlRelease( int i_type, vlc_value_t val )
>> case INPUT_CONTROL_SET_VIEWPOINT:
>> case INPUT_CONTROL_SET_INITIAL_VIEWPOINT:
>> case INPUT_CONTROL_UPDATE_VIEWPOINT:
>> + case INPUT_CONTROL_SET_TIME:
>> + case INPUT_CONTROL_SET_POSITION:
>> free( val.p_address );
>> break;
>> case INPUT_CONTROL_SET_RENDERER:
>> @@ -1849,7 +1887,8 @@ static bool Control( input_thread_t *p_input,
>> break;
>> }
>>
>> - float f_pos = val.f_float;
>> + input_seek_params_t *param = val.p_address;
>> + float f_pos = param->f_position;
>> if( f_pos < 0.f )
>> f_pos = 0.f;
>> else if( f_pos > 1.f )
>> @@ -1857,7 +1896,7 @@ static bool Control( input_thread_t *p_input,
>> /* Reset the decoders states and clock sync (before calling
>> the demuxer */
>> es_out_Control( input_priv(p_input)->p_es_out,
>> ES_OUT_RESET_PCR );
>> if( demux_Control( input_priv(p_input)->master->p_demux,
>> DEMUX_SET_POSITION,
>> - (double) f_pos, !input_priv(p_input)-
>>> b_fast_seek ) )
>> + (double) f_pos, !param->b_fast ) )
>> {
>> msg_Err( p_input, "INPUT_CONTROL_SET_POSITION "
>> "%2.1f%% failed", (double)(f_pos * 100.f) );
>> @@ -1877,6 +1916,7 @@ static bool Control( input_thread_t *p_input,
>> {
>> int64_t i_time;
>> int i_ret;
>> + input_seek_params_t *param;
>>
>> if( input_priv(p_input)->b_recording )
>> {
>> @@ -1884,7 +1924,8 @@ static bool Control( input_thread_t *p_input,
>> break;
>> }
>>
>> - i_time = val.i_int;
>> + param = val.p_address;
>> + i_time = param->i_time;
>> if( i_time < 0 )
>> i_time = 0;
>>
>> @@ -1893,7 +1934,7 @@ static bool Control( input_thread_t *p_input,
>>
>> i_ret = demux_Control( input_priv(p_input)->master-
>>> p_demux,
>> DEMUX_SET_TIME, i_time,
>> - !input_priv(p_input)->b_fast_seek );
>> + !param->b_fast );
>> if( i_ret )
>> {
>> int64_t i_length;
>> @@ -1905,7 +1946,7 @@ static bool Control( input_thread_t *p_input,
>> double f_pos = (double)i_time / (double)i_length;
>> i_ret = demux_Control( input_priv(p_input)->master-
>>> p_demux,
>> DEMUX_SET_POSITION, f_pos,
>> - !input_priv(p_input)-
>>> b_fast_seek );
>> + !param->b_fast );
>> }
>> }
>> if( i_ret )
>> @@ -2236,8 +2277,18 @@ static bool Control( input_thread_t *p_input,
>> break;
>> }
>>
>> - val.i_int = time_offset;
>> - b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME,
>> val );
>> + vlc_value_t seek_val;
>> + input_seek_params_t *param;
>> +
>> + param = malloc( sizeof(*param) );
>> + if( unlikely(param == NULL) )
>> + break;
>> +
>> + param->b_fast = var_GetBool( p_input, "input-fast-seek" );
>> + param->i_time = time_offset;
>> + seek_val.p_address = param;
>> +
>> + b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME,
>> seek_val );
>> break;
>> }
>> case INPUT_CONTROL_SET_RENDERER:
>> diff --git a/src/input/input_internal.h b/src/input/input_internal.h
>> index c0b8ae4..bc38a09 100644
>> --- a/src/input/input_internal.h
>> +++ b/src/input/input_internal.h
>> @@ -106,7 +106,6 @@ typedef struct input_thread_private_t
>> mtime_t i_start; /* :start-time,0 by default */
>> mtime_t i_stop; /* :stop-time, 0 if none */
>> mtime_t i_time; /* Current time */
>> - bool b_fast_seek;/* :input-fast-seek */
>>
>> /* Output */
>> bool b_out_pace_control; /* XXX Move it ot es_sout ? */
>> diff --git a/src/input/var.c b/src/input/var.c
>> index 04c8cb0..717ae74 100644
>> --- a/src/input/var.c
>> +++ b/src/input/var.c
>> @@ -593,8 +593,8 @@ static int PositionCallback( vlc_object_t *p_this,
>> char const *psz_cmd,
>> var_Change( p_input, "time", VLC_VAR_SETVALUE, val );
>> }
>>
>> - input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
>> - return VLC_SUCCESS;
>> + return input_SetPosition( p_input, newval.f_float,
>> + var_GetBool( p_input, "input-fast-seek" ) );
>> }
>>
>> static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
>> @@ -618,8 +618,8 @@ static int TimeCallback( vlc_object_t *p_this, char
>> const *psz_cmd,
>> var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
>> }
>>
>> - input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
>> - return VLC_SUCCESS;
>> + return input_SetTime( p_input, newval.i_int,
>> + var_GetBool( p_input, "input-fast-seek" ) );
>> }
>>
>> static int TimeOffsetCallback( vlc_object_t *obj, char const *varname,
>> diff --git a/src/libvlccore.sym b/src/libvlccore.sym
>> index e32a686..f9418b1 100644
>> --- a/src/libvlccore.sym
>> +++ b/src/libvlccore.sym
>> @@ -202,6 +202,8 @@ input_resource_GetAout
>> input_resource_HoldAout
>> input_resource_PutAout
>> input_resource_ResetAout
>> +input_SetPosition
>> +input_SetTime
>> input_Start
>> input_Stop
>> input_vaControl
>> --
>> 2.9.5
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list