[vlc-commits] player: Add support for "ask to resume"

Hugo Beauzée-Luyssen git at videolan.org
Thu Jan 23 10:05:21 CET 2020


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Nov 28 15:33:44 2019 +0100| [41fe2ebbe2694e85fe55008555ad9d68b858fa28] | committer: Hugo Beauzée-Luyssen

player: Add support for "ask to resume"

And allow states to be restored independently of the position

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=41fe2ebbe2694e85fe55008555ad9d68b858fa28
---

 include/vlc_player.h  |  7 +++++++
 src/libvlc-module.c   | 12 ++++++++++++
 src/player/input.c    | 15 +++++++++------
 src/player/medialib.c | 19 +++++++++++++++++--
 src/player/player.h   |  4 +++-
 5 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index 5dec3c8132..d0f9f0d973 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -373,6 +373,13 @@ enum vlc_player_abloop
 /** Player teletext key: Index */
 #define VLC_PLAYER_TELETEXT_KEY_INDEX ('i' << 16)
 
+enum vlc_player_restore_playback_pos
+{
+    VLC_PLAYER_RESTORE_PLAYBACK_POS_NEVER,
+    VLC_PLAYER_RESTORE_PLAYBACK_POS_ASK,
+    VLC_PLAYER_RESTORE_PLAYBACK_POS_ALWAYS,
+};
+
 /**
  * Set the current media
  *
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index c6dd9a29b1..86fc1b1f1b 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -43,6 +43,7 @@
 #include "vlc_meta.h"
 #include <vlc_aout.h>
 #include <vlc_vout.h>
+#include <vlc_player.h>
 
 #include "clock/clock.h"
 
@@ -707,6 +708,12 @@ static const char *const ppsz_prefres[] = {
     "the form \"{name=bookmark-name,time=optional-time-offset," \
     "bytes=optional-byte-offset},{...}\"")
 
+#define RESTORE_PLAYBACK_POS_TEXT N_("Continue playback?")
+
+#define RESTORE_PLAYBACK_STATE_TEXT N_("Resume last playback states")
+#define RESTORE_PLAYBACK_STATE_LONGTEXT N_("This will resume the last playback " \
+    "state, such as the selected tracks, rate, aspect-ratio, ..." )
+
 #define INPUT_RECORD_PATH_TEXT N_("Record directory")
 #define INPUT_RECORD_PATH_LONGTEXT N_( \
     "Directory where the records will be stored" )
@@ -1891,6 +1898,11 @@ vlc_module_begin ()
                  BOOKMARKS_TEXT, BOOKMARKS_LONGTEXT, true )
         change_safe ()
 
+    add_integer( "restore-playback-pos", VLC_PLAYER_RESTORE_PLAYBACK_POS_ASK,
+                 RESTORE_PLAYBACK_POS_TEXT, RESTORE_PLAYBACK_POS_TEXT, false )
+    add_bool( "restore-playback-states", false,
+                 RESTORE_PLAYBACK_STATE_TEXT, RESTORE_PLAYBACK_STATE_LONGTEXT, false )
+
     set_section( N_( "Default devices") , NULL )
 
     add_loadfile("dvd", DVD_DEVICE, DVD_DEV_TEXT, DVD_DEV_LONGTEXT)
diff --git a/src/player/input.c b/src/player/input.c
index 26e669007b..69328924b9 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -444,19 +444,22 @@ vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
                      * insertion. The initialization of the default track when
                      * we don't have a value will be done when the first track
                      * gets selected */
-                    if (input->ml.states.current_video_track != -2 &&
+                    if (input->ml.restore_states &&
+                        input->ml.states.current_video_track != -2 &&
                         input->ml.states.current_video_track == ev->fmt->i_id)
                         vlc_player_SelectTrack(input->player, &trackpriv->t,
                                                VLC_PLAYER_SELECT_EXCLUSIVE);
                     break;
                 case AUDIO_ES:
-                    if (input->ml.states.current_audio_track != -2 &&
+                    if (input->ml.restore_states &&
+                        input->ml.states.current_audio_track != -2 &&
                         input->ml.states.current_audio_track == ev->fmt->i_id)
                         vlc_player_SelectTrack(input->player, &trackpriv->t,
                                                VLC_PLAYER_SELECT_EXCLUSIVE);
                     break;
                 case SPU_ES:
-                    if (input->ml.states.current_subtitle_track != -2 &&
+                    if (input->ml.restore_states &&
+                        input->ml.states.current_subtitle_track != -2 &&
                         input->ml.states.current_subtitle_track == ev->fmt->i_id)
                         vlc_player_SelectTrack(input->player, &trackpriv->t,
                                                VLC_PLAYER_SELECT_EXCLUSIVE);
@@ -879,7 +882,8 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
         input->ml.default_video_track = input->ml.default_audio_track =
         input->ml.default_subtitle_track = -2;
     input->ml.states.progress = -1.f;
-    input->ml.restore = VLC_RESTOREPOINT_TITLE;
+    input->ml.restore = VLC_RESTOREPOINT_NONE;
+    input->ml.restore_states = false;
 
     input->thread = input_Create(player, input_thread_Events, input, item,
                                  player->resource, player->renderer);
@@ -888,8 +892,7 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
         free(input);
         return NULL;
     }
-
-    vlc_player_input_RestoreMlStates(input);
+    vlc_player_input_RestoreMlStates(input, false);
 
     /* Initial sub/audio delay */
     const vlc_tick_t cat_delays[DATA_ES] = {
diff --git a/src/player/medialib.c b/src/player/medialib.c
index 722f27bcd8..e0c0b0f6f4 100644
--- a/src/player/medialib.c
+++ b/src/player/medialib.c
@@ -27,11 +27,18 @@
 #include "misc/variables.h"
 
 void
-vlc_player_input_RestoreMlStates(struct vlc_player_input* input)
+vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
 {
     vlc_player_t* player = input->player;
     vlc_player_assert_locked(player);
 
+    int restore_pos;
+    if (force_pos)
+        restore_pos = VLC_PLAYER_RESTORE_PLAYBACK_POS_ALWAYS;
+    else
+        restore_pos = var_InheritInteger(player, "restore-playback-pos");
+    bool restore_states = var_InheritBool(player, "restore-playback-states");
+
     vlc_medialibrary_t* ml = vlc_ml_instance_get(input->player);
     if (!ml)
         return;
@@ -41,12 +48,20 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input)
         return;
     if (vlc_ml_media_get_all_playback_pref(ml, media->i_id, &input->ml.states) != VLC_SUCCESS)
         return;
+    input->ml.restore = (restore_pos == VLC_PLAYER_RESTORE_PLAYBACK_POS_ALWAYS) ?
+                            VLC_RESTOREPOINT_TITLE : VLC_RESTOREPOINT_NONE;
+    input->ml.restore_states = restore_states;
     /* If we are aiming at a specific title, wait for it to be added, and
      * only then select it & set the position.
      * If we're not aiming at a specific title, just set the position now.
      */
-    if (input->ml.states.current_title == -1 && input->ml.states.progress > .0f)
+    if (restore_pos == VLC_PLAYER_RESTORE_PLAYBACK_POS_ALWAYS &&
+            input->ml.states.current_title == -1 &&
+            input->ml.states.progress > .0f)
         input_SetPosition(input->thread, input->ml.states.progress, false);
+
+    if (!restore_states)
+        return;
     if (input->ml.states.rate != .0f)
         vlc_player_ChangeRate(player, input->ml.states.rate);
 
diff --git a/src/player/player.h b/src/player/player.h
index 386fed1c5b..d7e499a84e 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -115,6 +115,8 @@ struct vlc_player_input
             VLC_RESTOREPOINT_POSITION,
             VLC_RESTOREPOINT_NONE,
         } restore;
+        bool restore_states;
+        bool delay_restore;
     } ml;
 };
 
@@ -491,7 +493,7 @@ vlc_player_osd_Program(vlc_player_t *player, const char *name);
  */
 
 void
-vlc_player_input_RestoreMlStates(struct vlc_player_input* input);
+vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos);
 
 void
 vlc_player_UpdateMLStates(vlc_player_t *player, struct vlc_player_input* input);



More information about the vlc-commits mailing list