[vlc-devel] [PATCH] player: use states for restoration steps
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Tue Dec 3 13:22:18 CET 2019
Hi,
On Mon, Dec 2, 2019, at 3:04 PM, Francois Cartegnie wrote:
> ---
> src/player/input.c | 16 ++++++++++------
> src/player/player.h | 6 ++++++
> 2 files changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/src/player/input.c b/src/player/input.c
> index 18d2646663..a4d8407e24 100644
> --- a/src/player/input.c
> +++ b/src/player/input.c
> @@ -554,12 +554,14 @@ vlc_player_input_HandleTitleEvent(struct
> vlc_player_input *input,
> {
> vlc_player_SendEvent(player,
> on_title_selection_changed,
> &input->titles->array[0], 0);
> - if (input->ml.states.current_title >= 0 &&
> + if (input->ml.restore == VLC_RESTOREPOINT_TITLE &&
> (size_t)input->ml.states.current_title <
> ev->list.count)
> {
> vlc_player_SelectTitleIdx(player,
> input->ml.states.current_title);
> }
> + input->ml.restore = VLC_RESTOREPOINT_POSITION;
> }
> + else input->ml.restore = VLC_RESTOREPOINT_NONE;
> break;
> }
> case VLC_INPUT_TITLE_SELECTED:
> @@ -570,16 +572,17 @@ vlc_player_input_HandleTitleEvent(struct
> vlc_player_input *input,
> vlc_player_SendEvent(player, on_title_selection_changed,
>
> &input->titles->array[input->title_selected],
> input->title_selected);
> - if (input->ml.states.current_title >= 0 &&
> + if (input->ml.restore == VLC_RESTOREPOINT_POSITION &&
> + input->ml.states.current_title >= 0 &&
> (size_t)input->ml.states.current_title ==
> ev->selected_idx &&
> input->ml.states.progress > .0f)
> {
> input_SetPosition(input->thread,
> input->ml.states.progress, false);
> - /* Reset the wanted title to avoid forcing it or the
> position
> - * again during the next title change
> - */
> - input->ml.states.current_title = 0;
> }
> + /* Reset the wanted title to avoid forcing it or the
> position
> + * again during the next title change
> + */
> + input->ml.restore = VLC_RESTOREPOINT_NONE;
> break;
> default:
> vlc_assert_unreachable();
> @@ -876,6 +879,7 @@ 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;
Shouldn't this be done (when needed) by vlc_player_input_RestoreMlStates instead?
This would prevent you from having to restore it to VLC_RESTOREPOINT_NONE when no restoration is needed or after it's been handled.
Also, as far as I can see, you could use this logic to handle all position restorations, and not just those in the default title.
So basically something like
diff --git a/src/player/medialib.c b/src/player/medialib.c
index c079870ab1..253f6f1a3f 100644
--- a/src/player/medialib.c
+++ b/src/player/medialib.c
@@ -45,8 +45,8 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input,
* 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)
- input_SetPosition(input->thread, input->ml.states.progress, false);
+ if (input->ml.states.current_title != -1 || input->ml.states.progress > .0f)
+ input->ml.restore = VLC_RESTOREPOINT_TITLE;
if (input->ml.states.rate != .0f)
vlc_player_ChangeRate(player, input->ml.states.rate);
>
> input->thread = input_Create(player, input_thread_Events, input, item,
> player->resource, player->renderer);
> diff --git a/src/player/player.h b/src/player/player.h
> index aea4337e0a..2bdda0c926 100644
> --- a/src/player/player.h
> +++ b/src/player/player.h
> @@ -109,6 +109,12 @@ struct vlc_player_input
> int default_video_track;
> int default_audio_track;
> int default_subtitle_track;
> + enum
> + {
> + VLC_RESTOREPOINT_TITLE,
> + VLC_RESTOREPOINT_POSITION,
> + VLC_RESTOREPOINT_NONE,
> + } restore;
> } ml;
> };
>
> --
> 2.21.0
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
--
Hugo Beauzée-Luyssen
hugo at beauzee.fr
More information about the vlc-devel
mailing list