player: Add support for "ask to resume"

And allow states to be restored independently of the position
This commit is contained in:
Hugo Beauzée-Luyssen 2019-11-28 15:33:44 +01:00
parent 28687fa225
commit 41fe2ebbe2
5 changed files with 48 additions and 9 deletions

View File

@ -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
*

View File

@ -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)

View File

@ -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] = {

View File

@ -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);

View File

@ -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);