<html><head></head><body>It would be far simpler to just add a flag to seek functions.<br><br><div class="gmail_quote">Le 14 juin 2018 14:00:10 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/libvlc_media_player.h | 17 ++++++++++++++---<br> include/vlc_input.h               |  9 +++++++++<br> lib/media_player.c                | 17 +++++++++++++++--<br> src/input/input.c                 | 25 ++++++++++++++++++++++---<br> src/input/var.c                   |  3 +++<br> 5 files changed, 63 insertions(+), 8 deletions(-)<br><br>diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h<br>index 9ef1dde..eb4d0ab 100644<br>--- a/include/vlc/libvlc_media_player.h<br>+++ b/include/vlc/libvlc_media_player.h<br>@@ -780,14 +780,22 @@ LIBVLC_API libvlc_time_t libvlc_media_player_get_length( libvlc_media_player_t *<br>  */<br> LIBVLC_API libvlc_time_t libvlc_media_player_get_time( libvlc_media_player_t *p_mi );<br> <br>+typedef enum libvlc_media_player_seek_mode_t {<br>+    libvlc_seek_mode_auto = 0,<br>+    libvlc_seek_mode_precise,<br>+    libvlc_seek_mode_fast<br>+} libvlc_media_player_seek_mode_t;<br>+<br> /**<br>  * Set the movie time (in ms). This has no effect if no media is being played.<br>- * Not all formats and protocols support this.<br>+ * Not all formats and protocols support this. i_seek_mode is only a hint.<br>  *<br>  * \param p_mi the Media Player<br>+ * \param i_seek_mode values of libvlc_media_player_seek_mode_t<br>  * \param i_time the movie time (in ms).<br>  */<br>-LIBVLC_API void libvlc_media_player_set_time( libvlc_media_player_t *p_mi, libvlc_time_t i_time );<br>+LIBVLC_API void libvlc_media_player_set_time( libvlc_media_player_t *p_mi,<br>+                                              libvlc_time_t i_time, int i_seek_mode );<br> <br> /**<br>  * Get movie position as percentage between 0.0 and 1.0.<br>@@ -801,11 +809,14 @@ LIBVLC_API float libvlc_media_player_get_position( libvlc_media_player_t *p_mi )<br>  * Set movie position as percentage between 0.0 and 1.0.<br>  * This has no effect if playback is not enabled.<br>  * This might not work depending on the underlying input format and protocol.<br>+ * i_seek_mode is only a hint.<br>  *<br>  * \param p_mi the Media Player<br>+ * \param i_seek_mode values of libvlc_media_player_seek_mode_t<br>  * \param f_pos the position<br>  */<br>-LIBVLC_API void libvlc_media_player_set_position( libvlc_media_player_t *p_mi, float f_pos );<br>+LIBVLC_API void libvlc_media_player_set_position( libvlc_media_player_t *p_mi,<br>+                                                  float f_pos, int i_seek_mode );<br> <br> /**<br>  * Set movie chapter (if applicable).<br>diff --git a/include/vlc_input.h b/include/vlc_input.h<br>index 16c566a..ed1f542 100644<br>--- a/include/vlc_input.h<br>+++ b/include/vlc_input.h<br>@@ -490,6 +490,15 @@ enum input_query_e<br>     INPUT_MODIFY_PCR_SYSTEM,/* arg1=int absolute, arg2=mtime_t      res=can fail */<br> };<br> <br>+/**<br>+ * Input seek mode<br>+ */<br>+enum input_seek_mode_e {<br>+    INPUT_SEEK_MODE_AUTO = 0,<br>+    INPUT_SEEK_MODE_PRECISE,<br>+    INPUT_SEEK_MODE_FAST<br>+};<br>+<br> /** @}*/<br> <br> /*****************************************************************************<br>diff --git a/lib/media_player.c b/lib/media_player.c<br>index cd9d3ee..3bd8f07 100644<br>--- a/lib/media_player.c<br>+++ b/lib/media_player.c<br>@@ -1325,8 +1325,14 @@ libvlc_time_t libvlc_media_player_get_time( libvlc_media_player_t *p_mi )<br>     return i_time;<br> }<br> <br>+static_assert(libvlc_seek_mode_auto == (int)INPUT_SEEK_MODE_AUTO &&<br>+        libvlc_seek_mode_precise == (int)INPUT_SEEK_MODE_PRECISE &&<br>+        libvlc_seek_mode_fast == (int)INPUT_SEEK_MODE_FAST,<br>+        "Mismatch between libvlc_media_player_seek_mode_t and input_seek_mode_e");<br>+<br> void libvlc_media_player_set_time( libvlc_media_player_t *p_mi,<br>-                                   libvlc_time_t i_time )<br>+                                   libvlc_time_t i_time,<br>+                                   int i_seek_mode )<br> {<br>     input_thread_t *p_input_thread;<br> <br>@@ -1334,12 +1340,16 @@ void libvlc_media_player_set_time( libvlc_media_player_t *p_mi,<br>     if( !p_input_thread )<br>         return;<br> <br>+    assert(i_seek_mode >= libvlc_seek_mode_auto &&<br>+           i_seek_mode <= libvlc_seek_mode_fast);<br>+    var_SetInteger( p_input_thread, "seek-mode", i_seek_mode );<br>     var_SetInteger( p_input_thread, "time", to_mtime(i_time) );<br>     vlc_object_release( p_input_thread );<br> }<br> <br> void libvlc_media_player_set_position( libvlc_media_player_t *p_mi,<br>-                                       float position )<br>+                                       float position,<br>+                                       int i_seek_mode )<br> {<br>     input_thread_t *p_input_thread;<br> <br>@@ -1347,6 +1357,9 @@ void libvlc_media_player_set_position( libvlc_media_player_t *p_mi,<br>     if( !p_input_thread )<br>         return;<br> <br>+    assert(i_seek_mode >= libvlc_seek_mode_auto &&<br>+           i_seek_mode <= libvlc_seek_mode_fast);<br>+    var_SetInteger( p_input_thread, "seek-mode", i_seek_mode );<br>     var_SetFloat( p_input_thread, "position", position );<br>     vlc_object_release( p_input_thread );<br> }<br>diff --git a/src/input/input.c b/src/input/input.c<br>index a413683..e075be4 100644<br>--- a/src/input/input.c<br>+++ b/src/input/input.c<br>@@ -1854,10 +1854,20 @@ static bool Control( input_thread_t *p_input,<br>                 f_pos = 0.f;<br>             else if( f_pos > 1.f )<br>                 f_pos = 1.f;<br>+<br>+            bool b_precise;<br>+            int seek_mode = var_GetInteger( p_input, "seek-mode" );<br>+            if( seek_mode == INPUT_SEEK_MODE_PRECISE )<br>+                b_precise = true;<br>+            else if( seek_mode == INPUT_SEEK_MODE_FAST )<br>+                b_precise = false;<br>+            else<br>+                b_precise = !input_priv(p_input)->b_fast_seek;<br>+<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, b_precise ) )<br>             {<br>                 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION "<br>                          "%2.1f%% failed", (double)(f_pos * 100.f) );<br>@@ -1888,12 +1898,21 @@ static bool Control( input_thread_t *p_input,<br>             if( i_time < 0 )<br>                 i_time = 0;<br> <br>+            bool b_precise;<br>+            int seek_mode = var_GetInteger( p_input, "seek-mode" );<br>+            if( seek_mode == INPUT_SEEK_MODE_PRECISE )<br>+                b_precise = true;<br>+            else if( seek_mode == INPUT_SEEK_MODE_FAST )<br>+                b_precise = false;<br>+            else<br>+                b_precise = !input_priv(p_input)->b_fast_seek;<br>+<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> <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>+                                   b_precise );<br>             if( i_ret )<br>             {<br>                 int64_t i_length;<br>@@ -1905,7 +1924,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>+                                            b_precise );<br>                 }<br>             }<br>             if( i_ret )<br>diff --git a/src/input/var.c b/src/input/var.c<br>index 04c8cb0..ea6a961 100644<br>--- a/src/input/var.c<br>+++ b/src/input/var.c<br>@@ -147,6 +147,9 @@ void input_ControlVarInit ( input_thread_t *p_input )<br>     var_Create( p_input, "time", VLC_VAR_INTEGER );<br>     var_Create( p_input, "time-offset", VLC_VAR_INTEGER );    /* relative */<br> <br>+    var_Create( p_input, "seek-mode", VLC_VAR_INTEGER );<br>+    var_SetInteger( p_input, "seek-mode", INPUT_SEEK_MODE_AUTO );<br>+<br>     /* Bookmark */<br>     var_Create( p_input, "bookmark", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );<br>     var_Change( p_input, "bookmark", VLC_VAR_SETTEXT, _("Bookmark") );</pre></blockquote></div><br>
-- <br>
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>