mirror of https://code.videolan.org/videolan/vlc
player: remove the media_provider
Move the media_provider.get_next callback to vlc_player_cbs.request_next_media. This callback does not need a special handling since it doesn't wait for a result anymore.
This commit is contained in:
parent
b504ce7193
commit
7b631e0954
|
@ -87,30 +87,6 @@ enum vlc_player_lock_type
|
|||
VLC_PLAYER_LOCK_REENTRANT,
|
||||
};
|
||||
|
||||
/**
|
||||
* Callbacks for the owner of the player.
|
||||
*
|
||||
* These callbacks are needed to control the player flow (via the
|
||||
* vlc_playlist_t as a owner for example). It can only be set when creating the
|
||||
* player via vlc_player_New().
|
||||
*
|
||||
* All callbacks are called with the player locked (cf. vlc_player_Lock()), and
|
||||
* from any thread (even the current one).
|
||||
*/
|
||||
struct vlc_player_media_provider
|
||||
{
|
||||
/**
|
||||
* Called when the player requires a new media
|
||||
*
|
||||
* The user has to set the next media via vlc_player_SetNextMedia() from
|
||||
* the current callback or anytime before the current media is stopped.
|
||||
*
|
||||
* @param player locked player instance
|
||||
* @param data opaque pointer set from vlc_player_New()
|
||||
*/
|
||||
void (*get_next)(vlc_player_t *player, void *data);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new player instance
|
||||
*
|
||||
|
@ -122,9 +98,7 @@ struct vlc_player_media_provider
|
|||
* @return a pointer to a valid player instance or NULL in case of error
|
||||
*/
|
||||
VLC_API vlc_player_t *
|
||||
vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,
|
||||
const struct vlc_player_media_provider *media_provider,
|
||||
void *media_provider_data);
|
||||
vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type);
|
||||
|
||||
/**
|
||||
* Delete a player instance
|
||||
|
@ -385,7 +359,7 @@ vlc_player_SetCurrentMedia(vlc_player_t *player, input_item_t *media);
|
|||
*
|
||||
* This function replaces the next media to be played.
|
||||
* The user should set the next media from the
|
||||
* vlc_player_media_provider.get_next callback or anytime before the current
|
||||
* vlc_player_cbs.current_media_changed callback or anytime before the current
|
||||
* media is stopped.
|
||||
*
|
||||
* @note The media won't be opened directly by this function. If there is no
|
||||
|
@ -2772,6 +2746,9 @@ struct vlc_player_cbs
|
|||
* the next media internally) or from the STOPPED state (from
|
||||
* vlc_player_SetCurrentMedia() or from an internal transition).
|
||||
*
|
||||
* The user could set the next media via vlc_player_SetNextMedia() from
|
||||
* the current callback or anytime before the current media is stopped.
|
||||
|
||||
* @see vlc_player_SetCurrentMedia()
|
||||
*
|
||||
* @param player locked player instance
|
||||
|
|
|
@ -773,8 +773,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
|
|||
mp->p_md = NULL;
|
||||
mp->p_libvlc_instance = instance;
|
||||
/* use a reentrant lock to allow calling libvlc functions from callbacks */
|
||||
mp->player = vlc_player_New(VLC_OBJECT(mp), VLC_PLAYER_LOCK_REENTRANT,
|
||||
NULL, NULL);
|
||||
mp->player = vlc_player_New(VLC_OBJECT(mp), VLC_PLAYER_LOCK_REENTRANT);
|
||||
if (unlikely(!mp->player))
|
||||
goto error1;
|
||||
vlc_cond_init(&mp->wait);
|
||||
|
|
|
@ -229,7 +229,7 @@ static int Open(vlc_object_t *p_this)
|
|||
var_Create(p_fingerprinter, "aout", VLC_VAR_STRING);
|
||||
var_SetString(p_fingerprinter, "aout", "dummy");
|
||||
p_sys->player = vlc_player_New(VLC_OBJECT(p_fingerprinter),
|
||||
VLC_PLAYER_LOCK_NORMAL, NULL, NULL );
|
||||
VLC_PLAYER_LOCK_NORMAL);
|
||||
if (!p_sys->player)
|
||||
{
|
||||
free(p_sys);
|
||||
|
|
|
@ -592,7 +592,7 @@ static vlm_media_instance_sys_t *vlm_MediaInstanceNew( vlm_media_sys_t *p_media,
|
|||
p_instance->i_index = 0;
|
||||
|
||||
p_instance->player = vlc_player_New(VLC_OBJECT(p_media->vlm),
|
||||
VLC_PLAYER_LOCK_NORMAL, NULL, NULL);
|
||||
VLC_PLAYER_LOCK_NORMAL);
|
||||
if (!p_instance->player)
|
||||
goto error;
|
||||
|
||||
|
|
|
@ -285,12 +285,8 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
|
|||
vlc_player_UpdateTimerState(player, NULL,
|
||||
VLC_PLAYER_TIMER_STATE_PLAYING,
|
||||
input->pause_date);
|
||||
if (player->started &&
|
||||
player->global_state == VLC_PLAYER_STATE_PLAYING)
|
||||
send_event = false;
|
||||
break;
|
||||
/* fall through */
|
||||
case VLC_PLAYER_STATE_STARTED:
|
||||
vlc_player_PrepareNextMedia(player);
|
||||
if (player->started &&
|
||||
player->global_state == VLC_PLAYER_STATE_PLAYING)
|
||||
send_event = false;
|
||||
|
|
|
@ -51,27 +51,11 @@ static_assert(VLC_PLAYER_TITLE_MENU == INPUT_TITLE_MENU &&
|
|||
#define vlc_player_foreach_inputs(it) \
|
||||
for (struct vlc_player_input *it = player->input; it != NULL; it = NULL)
|
||||
|
||||
void
|
||||
vlc_player_PrepareNextMedia(vlc_player_t *player)
|
||||
{
|
||||
vlc_player_assert_locked(player);
|
||||
|
||||
if (!player->media_provider
|
||||
|| player->next_media_requested)
|
||||
return;
|
||||
|
||||
assert(player->next_media == NULL);
|
||||
player->media_provider->get_next(player, player->media_provider_data);
|
||||
player->next_media_requested = true;
|
||||
}
|
||||
|
||||
int
|
||||
vlc_player_OpenNextMedia(vlc_player_t *player)
|
||||
{
|
||||
assert(player->input == NULL);
|
||||
|
||||
player->next_media_requested = false;
|
||||
|
||||
/* Tracks string ids are only remembered for one media */
|
||||
free(player->video_string_ids);
|
||||
free(player->audio_string_ids);
|
||||
|
@ -1010,7 +994,6 @@ vlc_player_InvalidateNextMedia(vlc_player_t *player)
|
|||
input_item_Release(player->next_media);
|
||||
player->next_media = NULL;
|
||||
}
|
||||
player->next_media_requested = false;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1027,14 +1010,12 @@ vlc_player_SetCurrentMedia(vlc_player_t *player, input_item_t *media)
|
|||
/* Switch to this new media when the current input is stopped */
|
||||
player->next_media = input_item_Hold(media);
|
||||
player->releasing_media = false;
|
||||
player->next_media_requested = true;
|
||||
}
|
||||
else if (player->media)
|
||||
{
|
||||
/* The current media will be set to NULL once the current input is
|
||||
* stopped */
|
||||
player->releasing_media = true;
|
||||
player->next_media_requested = false;
|
||||
}
|
||||
else
|
||||
return VLC_SUCCESS;
|
||||
|
@ -1068,7 +1049,6 @@ vlc_player_SetNextMedia(vlc_player_t *player, input_item_t *media)
|
|||
input_item_Release(player->next_media);
|
||||
|
||||
player->next_media = next_media;
|
||||
player->next_media_requested = true;
|
||||
}
|
||||
|
||||
input_item_t *
|
||||
|
@ -1184,7 +1164,6 @@ vlc_player_Start(vlc_player_t *player)
|
|||
player->started = true;
|
||||
player->next_media = input_item_Hold(player->media);
|
||||
player->releasing_media = false;
|
||||
player->next_media_requested = true;
|
||||
return VLC_SUCCESS;
|
||||
}
|
||||
else
|
||||
|
@ -1923,17 +1902,13 @@ vlc_player_Delete(vlc_player_t *player)
|
|||
}
|
||||
|
||||
vlc_player_t *
|
||||
vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,
|
||||
const struct vlc_player_media_provider *media_provider,
|
||||
void *media_provider_data)
|
||||
vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type)
|
||||
{
|
||||
audio_output_t *aout = NULL;
|
||||
vlc_player_t *player = vlc_custom_create(parent, sizeof(*player), "player");
|
||||
if (!player)
|
||||
return NULL;
|
||||
|
||||
assert(!media_provider || media_provider->get_next);
|
||||
|
||||
vlc_list_init(&player->listeners);
|
||||
vlc_list_init(&player->metadata_listeners);
|
||||
vlc_list_init(&player->vout_listeners);
|
||||
|
@ -1945,8 +1920,6 @@ vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,
|
|||
player->pause_on_cork = false;
|
||||
player->corked = false;
|
||||
player->renderer = NULL;
|
||||
player->media_provider = media_provider;
|
||||
player->media_provider_data = media_provider_data;
|
||||
player->media = NULL;
|
||||
player->input = NULL;
|
||||
player->global_state = VLC_PLAYER_STATE_STOPPED;
|
||||
|
@ -1956,7 +1929,6 @@ vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,
|
|||
player->eos_burst_count = 0;
|
||||
|
||||
player->releasing_media = false;
|
||||
player->next_media_requested = false;
|
||||
player->next_media = NULL;
|
||||
|
||||
player->video_string_ids = player->audio_string_ids =
|
||||
|
|
|
@ -241,9 +241,6 @@ struct vlc_player_t
|
|||
|
||||
bool start_paused;
|
||||
|
||||
const struct vlc_player_media_provider *media_provider;
|
||||
void *media_provider_data;
|
||||
|
||||
bool pause_on_cork;
|
||||
bool corked;
|
||||
|
||||
|
@ -259,7 +256,6 @@ struct vlc_player_t
|
|||
struct vlc_player_input *input;
|
||||
|
||||
bool releasing_media;
|
||||
bool next_media_requested;
|
||||
input_item_t *next_media;
|
||||
|
||||
char *video_string_ids;
|
||||
|
@ -347,9 +343,6 @@ vlc_player_GetObject(vlc_player_t *player);
|
|||
int
|
||||
vlc_player_OpenNextMedia(vlc_player_t *player);
|
||||
|
||||
void
|
||||
vlc_player_PrepareNextMedia(vlc_player_t *player);
|
||||
|
||||
void
|
||||
vlc_player_destructor_AddStoppingInput(vlc_player_t *player,
|
||||
struct vlc_player_input *input);
|
||||
|
|
|
@ -48,8 +48,10 @@ player_on_current_media_changed(vlc_player_t *player, input_item_t *new_media,
|
|||
? playlist->items.data[playlist->current]->media
|
||||
: NULL;
|
||||
if (new_media == media)
|
||||
/* nothing to do */
|
||||
{
|
||||
vlc_playlist_UpdateNextMedia(playlist);
|
||||
return;
|
||||
}
|
||||
|
||||
ssize_t index;
|
||||
if (new_media)
|
||||
|
@ -73,6 +75,8 @@ player_on_current_media_changed(vlc_player_t *player, input_item_t *new_media,
|
|||
playlist->has_next = vlc_playlist_ComputeHasNext(playlist);
|
||||
|
||||
vlc_playlist_state_NotifyChanges(playlist, &state);
|
||||
|
||||
vlc_playlist_UpdateNextMedia(playlist);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -126,18 +130,6 @@ on_player_media_subitems_changed(vlc_player_t *player, input_item_t *media,
|
|||
vlc_playlist_ExpandItemFromNode(playlist, subitems);
|
||||
}
|
||||
|
||||
static void
|
||||
player_get_next_media(vlc_player_t *player, void *userdata)
|
||||
{
|
||||
VLC_UNUSED(player);
|
||||
vlc_playlist_t *playlist = userdata;
|
||||
vlc_playlist_UpdateNextMedia(playlist);
|
||||
}
|
||||
|
||||
static const struct vlc_player_media_provider player_media_provider = {
|
||||
.get_next = player_get_next_media,
|
||||
};
|
||||
|
||||
static const struct vlc_player_cbs player_callbacks = {
|
||||
.on_current_media_changed = player_on_current_media_changed,
|
||||
.on_state_changed = on_player_state_changed,
|
||||
|
@ -149,8 +141,7 @@ static const struct vlc_player_cbs player_callbacks = {
|
|||
bool
|
||||
vlc_playlist_PlayerInit(vlc_playlist_t *playlist, vlc_object_t *parent)
|
||||
{
|
||||
playlist->player = vlc_player_New(parent, VLC_PLAYER_LOCK_NORMAL,
|
||||
&player_media_provider, playlist);
|
||||
playlist->player = vlc_player_New(parent, VLC_PLAYER_LOCK_NORMAL);
|
||||
if (unlikely(!playlist->player))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ typedef struct input_item_t input_item_t;
|
|||
|
||||
#ifdef TEST_PLAYLIST
|
||||
/* mock the player in tests */
|
||||
# define vlc_player_New(a,b,c,d) (VLC_UNUSED(a), VLC_UNUSED(b), VLC_UNUSED(c), \
|
||||
malloc(1))
|
||||
# define vlc_player_New(a,b) (VLC_UNUSED(a), malloc(1))
|
||||
# define vlc_player_Delete(p) free(p)
|
||||
# define vlc_player_Lock(p) VLC_UNUSED(p)
|
||||
# define vlc_player_Unlock(p) VLC_UNUSED(p)
|
||||
|
|
|
@ -304,7 +304,7 @@ static void play_scenario(intf_thread_t *intf, struct transcode_scenario *scenar
|
|||
var_SetString(intf, "sout-transcode-vcodec", "test");
|
||||
|
||||
vlc_player_t *player = vlc_player_New(&intf->obj,
|
||||
VLC_PLAYER_LOCK_NORMAL, NULL, NULL);
|
||||
VLC_PLAYER_LOCK_NORMAL);
|
||||
assert(player);
|
||||
|
||||
static const struct vlc_player_cbs player_cbs = {
|
||||
|
|
|
@ -365,7 +365,7 @@ static void play_scenario(intf_thread_t *intf, struct input_decoder_scenario *sc
|
|||
input_item_AddOption(media, scenario->item_option, VLC_INPUT_OPTION_TRUSTED);
|
||||
|
||||
vlc_player_t *player = vlc_player_New(&intf->obj,
|
||||
VLC_PLAYER_LOCK_NORMAL, NULL, NULL);
|
||||
VLC_PLAYER_LOCK_NORMAL);
|
||||
assert(player);
|
||||
|
||||
intf->p_sys = (intf_sys_t *)player;
|
||||
|
|
|
@ -272,23 +272,6 @@ get_ctx(vlc_player_t *player, void *data)
|
|||
return ctx;
|
||||
}
|
||||
|
||||
static void
|
||||
player_get_next(vlc_player_t *player, void *data)
|
||||
{
|
||||
struct ctx *ctx = get_ctx(player, data);
|
||||
if (ctx->next_medias.size == 0)
|
||||
return;
|
||||
|
||||
input_item_t *next_media = ctx->next_medias.data[0];
|
||||
vlc_vector_remove(&ctx->next_medias, 0);
|
||||
|
||||
bool success = vlc_vector_push(&ctx->added_medias, next_media);
|
||||
assert(success);
|
||||
success = vlc_vector_push(&ctx->played_medias, next_media);
|
||||
assert(success);
|
||||
vlc_player_SetNextMedia(player, next_media);
|
||||
}
|
||||
|
||||
#define VEC_PUSH(vec, item) do { \
|
||||
bool success = vlc_vector_push(&ctx->report.vec, item); \
|
||||
assert(success); \
|
||||
|
@ -303,6 +286,18 @@ player_on_current_media_changed(vlc_player_t *player,
|
|||
if (new_media)
|
||||
input_item_Hold(new_media);
|
||||
VEC_PUSH(on_current_media_changed, new_media);
|
||||
|
||||
if (ctx->next_medias.size == 0)
|
||||
return;
|
||||
|
||||
input_item_t *next_media = ctx->next_medias.data[0];
|
||||
vlc_vector_remove(&ctx->next_medias, 0);
|
||||
|
||||
bool success = vlc_vector_push(&ctx->added_medias, next_media);
|
||||
assert(success);
|
||||
success = vlc_vector_push(&ctx->played_medias, next_media);
|
||||
assert(success);
|
||||
vlc_player_SetNextMedia(player, next_media);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2113,8 +2108,7 @@ static void
|
|||
test_delete_while_playback(vlc_object_t *obj, bool start)
|
||||
{
|
||||
test_log("delete_while_playback (start: %d)\n", start);
|
||||
vlc_player_t *player = vlc_player_New(obj, VLC_PLAYER_LOCK_NORMAL,
|
||||
NULL, NULL);
|
||||
vlc_player_t *player = vlc_player_New(obj, VLC_PLAYER_LOCK_NORMAL);
|
||||
|
||||
struct media_params params = DEFAULT_MEDIA_PARAMS(VLC_TICK_FROM_SEC(10));
|
||||
input_item_t *media = create_mock_media("media1", ¶ms);
|
||||
|
@ -2250,10 +2244,6 @@ ctx_init(struct ctx *ctx, enum ctx_flags flags)
|
|||
libvlc_instance_t *vlc = libvlc_new(ARRAY_SIZE(argv), argv);
|
||||
assert(vlc);
|
||||
|
||||
static const struct vlc_player_media_provider provider = {
|
||||
.get_next = player_get_next,
|
||||
};
|
||||
|
||||
#define X(type, name) .name = player_##name,
|
||||
static const struct vlc_player_cbs cbs = {
|
||||
REPORT_LIST
|
||||
|
@ -2277,7 +2267,7 @@ REPORT_LIST
|
|||
assert(ret == VLC_SUCCESS);
|
||||
|
||||
ctx->player = vlc_player_New(VLC_OBJECT(vlc->p_libvlc_int),
|
||||
VLC_PLAYER_LOCK_NORMAL, &provider, ctx);
|
||||
VLC_PLAYER_LOCK_NORMAL);
|
||||
assert(ctx->player);
|
||||
|
||||
vlc_player_Lock(ctx->player);
|
||||
|
|
|
@ -211,7 +211,7 @@ static void play_scenario(intf_thread_t *intf, struct vout_scenario *scenario)
|
|||
var_SetString(intf, "window", MODULE_STRING);
|
||||
|
||||
vlc_player_t *player = vlc_player_New(&intf->obj,
|
||||
VLC_PLAYER_LOCK_NORMAL, NULL, NULL);
|
||||
VLC_PLAYER_LOCK_NORMAL);
|
||||
assert(player);
|
||||
|
||||
vlc_player_Lock(player);
|
||||
|
|
Loading…
Reference in New Issue