Browse Source

player: expose media stopping reason via on_stopping_current_media

Add an enum to expose whether media is stopping due to user request,
reaching EOS or encountering an error.
pull/192/head
Ayush Dey 9 months ago
committed by Thomas Guillem
parent
commit
fe65b13db0
  1. 21
      include/vlc_player.h
  2. 4
      lib/media_player.c
  3. 9
      src/player/input.c
  4. 1
      src/player/player.c
  5. 1
      src/player/player.h

21
include/vlc_player.h

@ -302,6 +302,19 @@ enum vlc_player_abloop
VLC_PLAYER_ABLOOP_B,
};
/**
* Reason why the current media is stopping
*/
enum vlc_player_media_stopping_reason
{
/** The media is stopping because of an error (default) */
VLC_PLAYER_MEDIA_STOPPING_ERROR,
/** The media reached the end of stream */
VLC_PLAYER_MEDIA_STOPPING_EOS,
/** The media is stopping because of a user request */
VLC_PLAYER_MEDIA_STOPPING_USER,
};
/** Player capability: can seek */
#define VLC_PLAYER_CAP_SEEK (1<<0)
/** Player capability: can pause */
@ -3279,11 +3292,13 @@ struct vlc_player_cbs
* @see vlc_player_Stop()
*
* @param player locked player instance
* @param prev_media media currently stopping
* @param current_media media currently stopping
* @param stopping_reason reason why the media is stopping
* @param data opaque pointer set by vlc_player_AddListener()
*/
void (*on_stopping_current_media)(vlc_player_t *player,
input_item_t *current_media, void *data);
void (*on_stopping_current_media)(vlc_player_t *player, input_item_t *current_media,
enum vlc_player_media_stopping_reason stopping_reason,
void *data);
};
/**

4
lib/media_player.c

@ -79,10 +79,12 @@ on_current_media_changed(vlc_player_t *player, input_item_t *new_media,
static void
on_stopping_current_media(vlc_player_t *player, input_item_t *media,
void *data)
enum vlc_player_media_stopping_reason stopping_reason,
void *data)
{
assert(media != NULL);
(void) player;
(void) stopping_reason;
libvlc_media_player_t *mp = data;

9
src/player/input.c

@ -276,7 +276,8 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
by the player lock. User can hold the input_item, if they want
to use it beyond the callback scope. */
input_item_t *media = input_GetItem(input->thread);
vlc_player_SendEvent(player, on_stopping_current_media, media);
vlc_player_SendEvent(player, on_stopping_current_media,
media, input->stopping_reason);
vlc_player_UpdateTimerEvent(player, NULL,
VLC_PLAYER_TIMER_EVENT_DISCONTINUITY,
@ -347,6 +348,7 @@ vlc_player_input_HandleStateEvent(struct vlc_player_input *input,
break;
case END_S:
input->playing = false;
input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_EOS;
vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
VLC_TICK_INVALID);
vlc_player_destructor_AddStoppingInput(input->player, input);
@ -364,6 +366,7 @@ vlc_player_input_HandleStateEvent(struct vlc_player_input *input,
* the input thread and we won't reach END_S. */
if (!input->playing)
{
input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_ERROR;
vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
VLC_TICK_INVALID);
vlc_player_destructor_AddStoppingInput(input->player, input);
@ -1042,8 +1045,11 @@ input_thread_Events(input_thread_t *input_thread,
break;
case INPUT_EVENT_DEAD:
if (input->started) /* Can happen with early input_thread fails */
{
input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_ERROR;
vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
VLC_TICK_INVALID);
}
vlc_player_destructor_AddJoinableInput(player, input);
break;
case INPUT_EVENT_VBI_PAGE:
@ -1130,6 +1136,7 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
input->state = VLC_PLAYER_STATE_STOPPED;
input->error = VLC_PLAYER_ERROR_NONE;
input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_ERROR;
input->rate = 1.f;
input->capabilities = 0;
input->length = input->time = VLC_TICK_INVALID;

1
src/player/player.c

@ -203,6 +203,7 @@ vlc_player_destructor_Thread(void *data)
vlc_list_foreach(input, &player->destructor.inputs, node)
{
input_Stop(input->thread);
input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_USER;
vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
VLC_TICK_INVALID);
vlc_player_destructor_AddStoppingInput(player, input);

1
src/player/player.h

@ -65,6 +65,7 @@ struct vlc_player_input
enum vlc_player_state state;
enum vlc_player_error error;
enum vlc_player_media_stopping_reason stopping_reason;
float rate;
int capabilities;
vlc_tick_t length;

Loading…
Cancel
Save