<html><head></head><body>Can't input controls be extended so we don't need a malloc and a new union here?<br><br><div class="gmail_quote">Le 19 juin 2018 15:58:30 GMT+03:00, Zhao Zhili <quinkblack@foxmail.com> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">---<br> include/vlc_input.h | 4 ++<br> src/input/input.c | 93 +++++++++++++++++++++++++++++++++++-----------<br> src/input/input_internal.h | 1 -<br> src/input/var.c | 8 ++--<br> src/libvlccore.sym | 2 +<br> 5 files changed, 81 insertions(+), 27 deletions(-)<br><br>diff --git a/include/vlc_input.h b/include/vlc_input.h<br>index 16c566a..1d24fd1 100644<br>--- a/include/vlc_input.h<br>+++ b/include/vlc_input.h<br>@@ -514,6 +514,10 @@ VLC_API int input_Control( input_thread_t *, int i_query, ... );<br> <br> VLC_API void input_Close( input_thread_t * );<br> <br>+VLC_API int input_SetTime( input_thread_t *, mtime_t i_time, bool b_fast );<br>+<br>+VLC_API int input_SetPosition( input_thread_t *, float f_position, bool b_fast );<br>+<br> /**<br> * Create a new input_thread_t and start it.<br> *<br>diff --git a/src/input/input.c b/src/input/input.c<br>index a413683..a8ae021 100644<br>--- a/src/input/input.c<br>+++ b/src/input/input.c<br>@@ -227,6 +227,46 @@ void input_Close( input_thread_t *p_input )<br> vlc_object_release( p_input );<br> }<br> <br>+typedef struct input_seek_params_t {<br>+ bool b_fast;<br>+ union {<br>+ mtime_t i_time;<br>+ float f_position;<br>+ };<br>+} input_seek_params_t;<br>+<br>+int input_SetTime( input_thread_t *p_input, mtime_t i_time, bool b_fast )<br>+{<br>+ vlc_value_t val;<br>+ input_seek_params_t *param;<br>+<br>+ param = malloc( sizeof(*param) );<br>+ if( unlikely(param == NULL) )<br>+ return VLC_ENOMEM;<br>+<br>+ param->b_fast = b_fast;<br>+ param->i_time = i_time;<br>+ val.p_address = param;<br>+ input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );<br>+ return VLC_SUCCESS;<br>+}<br>+<br>+int input_SetPosition( input_thread_t *p_input, float f_position, bool b_fast )<br>+{<br>+ vlc_value_t val;<br>+ input_seek_params_t *param;<br>+<br>+ param = malloc( sizeof(*param) );<br>+ if( unlikely(param == NULL) )<br>+ return VLC_ENOMEM;<br>+<br>+ param->b_fast = b_fast;<br>+ param->f_position = f_position;<br>+ val.p_address = param;<br>+ input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );<br>+ return VLC_SUCCESS;<br>+}<br>+<br> /**<br> * Input destructor (called when the object's refcount reaches 0).<br> */<br>@@ -616,30 +656,28 @@ static int MainLoopTryRepeat( input_thread_t *p_input )<br> var_SetInteger( p_input, "input-repeat", i_repeat );<br> }<br> <br>+ input_thread_private_t *priv = input_priv(p_input);<br> /* Seek to start title/seekpoint */<br>- val.i_int = input_priv(p_input)->master->i_title_start -<br>- input_priv(p_input)->master->i_title_offset;<br>- if( val.i_int < 0 || val.i_int >= input_priv(p_input)->master->i_title )<br>+ val.i_int = priv->master->i_title_start - priv->master->i_title_offset;<br>+ if( val.i_int < 0 || val.i_int >= priv->master->i_title )<br> val.i_int = 0;<br> input_ControlPush( p_input,<br> INPUT_CONTROL_SET_TITLE, &val );<br> <br>- val.i_int = input_priv(p_input)->master->i_seekpoint_start -<br>- input_priv(p_input)->master->i_seekpoint_offset;<br>+ val.i_int = priv->master->i_seekpoint_start -<br>+ priv->master->i_seekpoint_offset;<br> if( val.i_int > 0 /* TODO: check upper boundary */ )<br> input_ControlPush( p_input,<br> INPUT_CONTROL_SET_SEEKPOINT, &val );<br> <br> /* Seek to start position */<br>- if( input_priv(p_input)->i_start > 0 )<br>+ if( priv->i_start > 0 )<br> {<br>- val.i_int = input_priv(p_input)->i_start;<br>- input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );<br>+ input_SetTime( p_input, priv->i_start, false );<br> }<br> else<br> {<br>- val.f_float = 0.f;<br>- input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );<br>+ input_SetPosition( p_input, 0.0f, false );<br> }<br> <br> return VLC_SUCCESS;<br>@@ -916,20 +954,16 @@ static void StartTitle( input_thread_t * p_input )<br> <br> if( priv->i_start > 0 )<br> {<br>- vlc_value_t s;<br>-<br> msg_Dbg( p_input, "starting at time: %"PRId64"s",<br> priv->i_start / CLOCK_FREQ );<br> <br>- s.i_int = priv->i_start;<br>- input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );<br>+ input_SetTime( p_input, priv->i_start, false );<br> }<br> if( priv->i_stop > 0 && priv->i_stop <= priv->i_start )<br> {<br> msg_Warn( p_input, "invalid stop-time ignored" );<br> priv->i_stop = 0;<br> }<br>- priv->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );<br> }<br> <br> static int SlaveCompare(const void *a, const void *b)<br>@@ -1627,6 +1661,8 @@ static void ControlRelease( int i_type, vlc_value_t val )<br> case INPUT_CONTROL_SET_VIEWPOINT:<br> case INPUT_CONTROL_SET_INITIAL_VIEWPOINT:<br> case INPUT_CONTROL_UPDATE_VIEWPOINT:<br>+ case INPUT_CONTROL_SET_TIME:<br>+ case INPUT_CONTROL_SET_POSITION:<br> free( val.p_address );<br> break;<br> case INPUT_CONTROL_SET_RENDERER:<br>@@ -1849,7 +1885,8 @@ static bool Control( input_thread_t *p_input,<br> break;<br> }<br> <br>- float f_pos = val.f_float;<br>+ input_seek_params_t *param = val.p_address;<br>+ float f_pos = param->f_position;<br> if( f_pos < 0.f )<br> f_pos = 0.f;<br> else if( f_pos > 1.f )<br>@@ -1857,7 +1894,7 @@ static bool Control( input_thread_t *p_input,<br> /* Reset the decoders states and clock sync (before calling the demuxer */<br> es_out_Control( input_priv(p_input)->p_es_out, ES_OUT_RESET_PCR );<br> if( demux_Control( input_priv(p_input)->master->p_demux, DEMUX_SET_POSITION,<br>- (double) f_pos, !input_priv(p_input)->b_fast_seek ) )<br>+ (double) f_pos, !param->b_fast ) )<br> {<br> msg_Err( p_input, "INPUT_CONTROL_SET_POSITION "<br> "%2.1f%% failed", (double)(f_pos * 100.f) );<br>@@ -1877,6 +1914,7 @@ static bool Control( input_thread_t *p_input,<br> {<br> int64_t i_time;<br> int i_ret;<br>+ input_seek_params_t *param;<br> <br> if( input_priv(p_input)->b_recording )<br> {<br>@@ -1884,7 +1922,8 @@ static bool Control( input_thread_t *p_input,<br> break;<br> }<br> <br>- i_time = val.i_int;<br>+ param = val.p_address;<br>+ i_time = param->i_time;<br> if( i_time < 0 )<br> i_time = 0;<br> <br>@@ -1893,7 +1932,7 @@ static bool Control( input_thread_t *p_input,<br> <br> i_ret = demux_Control( input_priv(p_input)->master->p_demux,<br> DEMUX_SET_TIME, i_time,<br>- !input_priv(p_input)->b_fast_seek );<br>+ !param->b_fast );<br> if( i_ret )<br> {<br> int64_t i_length;<br>@@ -1905,7 +1944,7 @@ static bool Control( input_thread_t *p_input,<br> double f_pos = (double)i_time / (double)i_length;<br> i_ret = demux_Control( input_priv(p_input)->master->p_demux,<br> DEMUX_SET_POSITION, f_pos,<br>- !input_priv(p_input)->b_fast_seek );<br>+ !param->b_fast );<br> }<br> }<br> if( i_ret )<br>@@ -2236,8 +2275,18 @@ static bool Control( input_thread_t *p_input,<br> break;<br> }<br> <br>- val.i_int = time_offset;<br>- b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );<br>+ vlc_value_t seek_val;<br>+ input_seek_params_t *param;<br>+<br>+ param = malloc( sizeof(*param) );<br>+ if( unlikely(param == NULL) )<br>+ break;<br>+<br>+ param->b_fast = false;<br>+ param->i_time = time_offset;<br>+ seek_val.p_address = param;<br>+<br>+ b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, seek_val );<br> break;<br> }<br> case INPUT_CONTROL_SET_RENDERER:<br>diff --git a/src/input/input_internal.h b/src/input/input_internal.h<br>index c0b8ae4..bc38a09 100644<br>--- a/src/input/input_internal.h<br>+++ b/src/input/input_internal.h<br>@@ -106,7 +106,6 @@ typedef struct input_thread_private_t<br> mtime_t i_start; /* :start-time,0 by default */<br> mtime_t i_stop; /* :stop-time, 0 if none */<br> mtime_t i_time; /* Current time */<br>- bool b_fast_seek;/* :input-fast-seek */<br> <br> /* Output */<br> bool b_out_pace_control; /* XXX Move it ot es_sout ? */<br>diff --git a/src/input/var.c b/src/input/var.c<br>index 04c8cb0..717ae74 100644<br>--- a/src/input/var.c<br>+++ b/src/input/var.c<br>@@ -593,8 +593,8 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,<br> var_Change( p_input, "time", VLC_VAR_SETVALUE, val );<br> }<br> <br>- input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );<br>- return VLC_SUCCESS;<br>+ return input_SetPosition( p_input, newval.f_float,<br>+ var_GetBool( p_input, "input-fast-seek" ) );<br> }<br> <br> static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,<br>@@ -618,8 +618,8 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,<br> var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );<br> }<br> <br>- input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );<br>- return VLC_SUCCESS;<br>+ return input_SetTime( p_input, newval.i_int,<br>+ var_GetBool( p_input, "input-fast-seek" ) );<br> }<br> <br> static int TimeOffsetCallback( vlc_object_t *obj, char const *varname,<br>diff --git a/src/libvlccore.sym b/src/libvlccore.sym<br>index e32a686..15a8af2 100644<br>--- a/src/libvlccore.sym<br>+++ b/src/libvlccore.sym<br>@@ -205,6 +205,8 @@ input_resource_ResetAout<br> input_Start<br> input_Stop<br> input_vaControl<br>+input_SetTime<br>+input_SetPosition<br> vlc_readdir_helper_init<br> vlc_readdir_helper_finish<br> vlc_readdir_helper_additem</pre></blockquote></div><br>
-- <br>
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>