[vlc-commits] [Git][videolan/vlc][master] 9 commits: player: rework media_provider.get_next handling
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Mar 9 22:16:45 UTC 2024
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
67d14d92 by Thomas Guillem at 2024-03-09T21:20:40+00:00
player: rework media_provider.get_next handling
The next media can now be set anytime while the current media is
playing, via vlc_player_SetNextMedia().
Related to #28524
- - - - -
2311c60a by Thomas Guillem at 2024-03-09T21:20:40+00:00
player: also open the next media from Start
- - - - -
0a84d74c by Thomas Guillem at 2024-03-09T21:20:40+00:00
player: document SetCurrentMedia() and SetNextMedia()
- - - - -
dbf20a17 by Thomas Guillem at 2024-03-09T21:20:40+00:00
playlist: rework next_media handling
Update the next_media directly instead of invalidating it.
- - - - -
382e4dad by Thomas Guillem at 2024-03-09T21:20:40+00:00
player: unexport vlc_player_InvalidateNextMedia
- - - - -
0b221c2e by Thomas Guillem at 2024-03-09T21:20:40+00:00
test: player: add player_create_mock_media
- - - - -
87d240f7 by Thomas Guillem at 2024-03-09T21:20:40+00:00
test: player: rework set_next_mock_media
Call vlc_player_SetNextMedia() instead of vlc_player_SetCurrentMedia()
for the first media (then medias are added in a vector).
That way, the on_current_media_changed event won't be called directly,
allowing the user to finish to fill the vector or next medias.
- - - - -
b504ce71 by Thomas Guillem at 2024-03-09T21:20:40+00:00
test: player: check SetNextMedia() can be overridden
- - - - -
7b631e09 by Thomas Guillem at 2024-03-09T21:20:40+00:00
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.
- - - - -
17 changed files:
- include/vlc_player.h
- lib/media_player.c
- modules/misc/fingerprinter.c
- src/input/vlm.c
- src/libvlccore.sym
- src/player/input.c
- src/player/player.c
- src/player/player.h
- src/playlist/content.c
- src/playlist/control.c
- src/playlist/control.h
- src/playlist/player.c
- src/playlist/playlist.h
- test/modules/stream_out/transcode.c
- test/src/input/decoder/input_decoder.c
- test/src/player/player.c
- test/src/video_output/video_output.c
Changes:
=====================================
include/vlc_player.h
=====================================
@@ -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
- *
- * @note The returned media must be already held with input_item_Hold()
- *
- * @param player locked player instance
- * @param data opaque pointer set from vlc_player_New()
- * @return the next media to play, held by the callee with input_item_Hold()
- */
- input_item_t *(*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
@@ -365,6 +339,9 @@ enum vlc_player_restore_playback_pos
* blocking. If a media is currently being played, this media will be stopped
* and the requested media will be set after.
*
+ * @note The function will open the media, without starting it, allowing the
+ * user to send controls (like seek requests) before Starting the player.
+ *
* @warning This function is either synchronous (if the player state is
* STOPPED) or asynchronous. In the later case, vlc_player_GetCurrentMedia()
* will return the old media, even after this call, and until the
@@ -377,6 +354,25 @@ enum vlc_player_restore_playback_pos
VLC_API int
vlc_player_SetCurrentMedia(vlc_player_t *player, input_item_t *media);
+/**
+ * Set the next media
+ *
+ * This function replaces the next media to be played.
+ * The user should set the next media from the
+ * 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
+ * current media, the next media will be opened from vlc_player_Start(). If
+ * there is a current playing media, the next media will be opened and played
+ * automatically.
+ *
+ * @param player locked player instance
+ * @param media next media to play (will be held by the player)
+ */
+VLC_API void
+vlc_player_SetNextMedia(vlc_player_t *player, input_item_t *media);
+
/**
* Get the current played media.
*
@@ -388,6 +384,17 @@ vlc_player_SetCurrentMedia(vlc_player_t *player, input_item_t *media);
VLC_API input_item_t *
vlc_player_GetCurrentMedia(vlc_player_t *player);
+/**
+ * Get the next played media.
+ *
+ * This function return the media set by vlc_player_SetNextMedia()
+ *
+ * @param player locked player instance
+ * @return a valid media or NULL (if no next media is set)
+ */
+VLC_API input_item_t *
+vlc_player_GetNextMedia(vlc_player_t *player);
+
/**
* Helper that hold the current media
*/
@@ -398,21 +405,6 @@ vlc_player_HoldCurrentMedia(vlc_player_t *player)
return item ? input_item_Hold(item) : NULL;
}
-/**
- * Invalidate the next media.
- *
- * This function can be used to invalidate the media returned by the
- * vlc_player_media_provider.get_next callback. This can be used when the next
- * item from a playlist was changed by the user.
- *
- * Calling this function will trigger the
- * vlc_player_media_provider.get_next callback to be called again.
- *
- * @param player locked player instance
- */
-VLC_API void
-vlc_player_InvalidateNextMedia(vlc_player_t *player);
-
/**
* Start the playback of the current media.
*
@@ -2754,8 +2746,10 @@ 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()
- * @see vlc_player_InvalidateNextMedia()
*
* @param player locked player instance
* @param new_media new media currently played or NULL (when there is no
=====================================
lib/media_player.c
=====================================
@@ -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);
=====================================
modules/misc/fingerprinter.c
=====================================
@@ -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);
=====================================
src/input/vlm.c
=====================================
@@ -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;
=====================================
src/libvlccore.sym
=====================================
@@ -861,6 +861,7 @@ vlc_player_GetCapabilities
vlc_player_GetCategoryDelay
vlc_player_GetCategoryLanguage
vlc_player_GetCurrentMedia
+vlc_player_GetNextMedia
vlc_player_GetError
vlc_player_GetEsIdDelay
vlc_player_GetEsIdFromVout
@@ -887,7 +888,6 @@ vlc_player_GetTrackCount
vlc_player_GetV4l2Object
vlc_player_HasTeletextMenu
vlc_player_IncrementRate
-vlc_player_InvalidateNextMedia
vlc_player_IsRecording
vlc_player_IsTeletextEnabled
vlc_player_IsTeletextTransparent
@@ -930,6 +930,7 @@ vlc_player_SetAssociatedSubsFPS
vlc_player_SetAtoBLoop
vlc_player_SetCategoryDelay
vlc_player_SetCurrentMedia
+vlc_player_SetNextMedia
vlc_player_SetEsIdDelay
vlc_player_SetRecordingEnabled
vlc_player_SetRenderer
=====================================
src/player/input.c
=====================================
@@ -276,12 +276,8 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
if (input == player->input)
player->input = NULL;
- if (player->started)
- {
- vlc_player_PrepareNextMedia(player);
- if (!player->next_media)
- player->started = false;
- }
+ if (player->started && !player->next_media)
+ player->started = false;
send_event = !player->started;
break;
case VLC_PLAYER_STATE_PLAYING:
@@ -289,7 +285,7 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
vlc_player_UpdateTimerState(player, NULL,
VLC_PLAYER_TIMER_STATE_PLAYING,
input->pause_date);
- /* fallthrough */
+ /* fall through */
case VLC_PLAYER_STATE_STARTED:
if (player->started &&
player->global_state == VLC_PLAYER_STATE_PLAYING)
=====================================
src/player/player.c
=====================================
@@ -51,28 +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->next_media =
- 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);
@@ -1002,6 +985,17 @@ vlc_player_RemoveListener(vlc_player_t *player,
free(id);
}
+static void
+vlc_player_InvalidateNextMedia(vlc_player_t *player)
+{
+ vlc_player_assert_locked(player);
+ if (player->next_media)
+ {
+ input_item_Release(player->next_media);
+ player->next_media = NULL;
+ }
+}
+
int
vlc_player_SetCurrentMedia(vlc_player_t *player, input_item_t *media)
{
@@ -1016,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;
@@ -1045,6 +1037,28 @@ vlc_player_SetCurrentMedia(vlc_player_t *player, input_item_t *media)
return vlc_player_OpenNextMedia(player);
}
+void
+vlc_player_SetNextMedia(vlc_player_t *player, input_item_t *media)
+{
+ vlc_player_assert_locked(player);
+
+ /* Order is important, hold the new media before releasing the old one */
+ input_item_t *next_media = media != NULL ? input_item_Hold(media) : NULL;
+
+ if (player->next_media != NULL)
+ input_item_Release(player->next_media);
+
+ player->next_media = next_media;
+}
+
+input_item_t *
+vlc_player_GetNextMedia(vlc_player_t *player)
+{
+ vlc_player_assert_locked(player);
+
+ return player->next_media;
+}
+
input_item_t *
vlc_player_GetCurrentMedia(vlc_player_t *player)
{
@@ -1125,19 +1139,6 @@ vlc_player_GetAssociatedSubsFPS(vlc_player_t *player)
return var_GetFloat(player, "sub-fps");
}
-void
-vlc_player_InvalidateNextMedia(vlc_player_t *player)
-{
- vlc_player_assert_locked(player);
- if (player->next_media)
- {
- input_item_Release(player->next_media);
- player->next_media = NULL;
- }
- player->next_media_requested = false;
-
-}
-
int
vlc_player_Start(vlc_player_t *player)
{
@@ -1163,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
@@ -1171,7 +1171,18 @@ vlc_player_Start(vlc_player_t *player)
}
if (!player->media)
- return VLC_EGENERIC;
+ {
+ if (player->next_media != NULL)
+ {
+ /* The user called only SetNextMedia() and not SetCurrentMedia(),
+ * so open the next media directly from here. */
+ int ret = vlc_player_OpenNextMedia(player);
+ if (ret != VLC_SUCCESS)
+ return ret;
+ }
+ else
+ return VLC_EGENERIC;
+ }
if (!player->input)
{
@@ -1891,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);
@@ -1913,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;
@@ -1924,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 =
=====================================
src/player/player.h
=====================================
@@ -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);
=====================================
src/playlist/content.c
=====================================
@@ -283,7 +283,7 @@ vlc_playlist_Insert(vlc_playlist_t *playlist, size_t index,
}
vlc_playlist_ItemsInserted(playlist, index, count);
- vlc_player_InvalidateNextMedia(playlist->player);
+ vlc_playlist_UpdateNextMedia(playlist);
return VLC_SUCCESS;
}
@@ -299,7 +299,7 @@ vlc_playlist_Move(vlc_playlist_t *playlist, size_t index, size_t count,
vlc_vector_move_slice(&playlist->items, index, count, target);
vlc_playlist_ItemsMoved(playlist, index, count, target);
- vlc_player_InvalidateNextMedia(playlist->player);
+ vlc_playlist_UpdateNextMedia(playlist);
}
void
@@ -320,7 +320,7 @@ vlc_playlist_Remove(vlc_playlist_t *playlist, size_t index, size_t count)
if (current_media_changed)
vlc_playlist_SetCurrentMedia(playlist, playlist->current);
else
- vlc_player_InvalidateNextMedia(playlist->player);
+ vlc_playlist_UpdateNextMedia(playlist);
}
static int
@@ -385,7 +385,7 @@ vlc_playlist_Expand(vlc_playlist_t *playlist, size_t index,
if ((ssize_t) index == playlist->current)
vlc_playlist_SetCurrentMedia(playlist, playlist->current);
else
- vlc_player_InvalidateNextMedia(playlist->player);
+ vlc_playlist_UpdateNextMedia(playlist);
}
return VLC_SUCCESS;
=====================================
src/playlist/control.c
=====================================
@@ -429,17 +429,29 @@ vlc_playlist_GetNextMediaIndex(vlc_playlist_t *playlist)
return (ssize_t)vlc_playlist_GetNextIndex(playlist);
}
-input_item_t *
-vlc_playlist_GetNextMedia(vlc_playlist_t *playlist)
+void
+vlc_playlist_UpdateNextMedia(vlc_playlist_t *playlist)
{
/* the playlist and the player share the lock */
vlc_playlist_AssertLocked(playlist);
+ input_item_t *media = NULL;
- ssize_t index = vlc_playlist_GetNextMediaIndex(playlist);
- if (index == -1)
- return NULL;
+ switch (playlist->stopped_action)
+ {
+ case VLC_PLAYLIST_MEDIA_STOPPED_CONTINUE:
+ case VLC_PLAYLIST_MEDIA_STOPPED_PAUSE:
+ case VLC_PLAYLIST_MEDIA_STOPPED_EXIT:
+ {
+ ssize_t index = vlc_playlist_GetNextMediaIndex(playlist);
+ if (index != -1)
+ media = playlist->items.data[index]->media;
+ /* fall through */
+ }
+ case VLC_PLAYLIST_MEDIA_STOPPED_STOP:
+ break;
+ default:
+ vlc_assert_unreachable();
+ }
- input_item_t *media = playlist->items.data[index]->media;
- input_item_Hold(media);
- return media;
+ vlc_player_SetNextMedia(playlist->player, media);
}
=====================================
src/playlist/control.h
=====================================
@@ -34,7 +34,7 @@ vlc_playlist_ComputeHasNext(vlc_playlist_t *playlist);
int
vlc_playlist_SetCurrentMedia(vlc_playlist_t *playlist, ssize_t index);
-input_item_t *
-vlc_playlist_GetNextMedia(vlc_playlist_t *playlist);
+void
+vlc_playlist_UpdateNextMedia(vlc_playlist_t *playlist);
#endif
=====================================
src/playlist/player.c
=====================================
@@ -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,28 +130,6 @@ on_player_media_subitems_changed(vlc_player_t *player, input_item_t *media,
vlc_playlist_ExpandItemFromNode(playlist, subitems);
}
-static input_item_t *
-player_get_next_media(vlc_player_t *player, void *userdata)
-{
- VLC_UNUSED(player);
- vlc_playlist_t *playlist = userdata;
- switch (playlist->stopped_action)
- {
- case VLC_PLAYLIST_MEDIA_STOPPED_CONTINUE:
- case VLC_PLAYLIST_MEDIA_STOPPED_PAUSE:
- case VLC_PLAYLIST_MEDIA_STOPPED_EXIT:
- return vlc_playlist_GetNextMedia(playlist);
- case VLC_PLAYLIST_MEDIA_STOPPED_STOP:
- return NULL;
- default:
- vlc_assert_unreachable();
- }
-}
-
-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,
@@ -159,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;
@@ -227,6 +208,6 @@ vlc_playlist_SetMediaStoppedAction(vlc_playlist_t *playlist,
playlist->stopped_action = action;
var_SetBool(playlist->player, "play-and-pause",
action == VLC_PLAYLIST_MEDIA_STOPPED_PAUSE);
- vlc_player_InvalidateNextMedia(playlist->player);
+ vlc_playlist_UpdateNextMedia(playlist);
vlc_playlist_Notify(playlist, on_media_stopped_action_changed, action);
}
=====================================
src/playlist/playlist.h
=====================================
@@ -31,15 +31,14 @@ 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)
# define vlc_player_AddListener(a,b,c) (VLC_UNUSED(b), malloc(1))
# define vlc_player_RemoveListener(a,b) free(b)
# define vlc_player_SetCurrentMedia(a,b) (VLC_UNUSED(b), VLC_SUCCESS)
-# define vlc_player_InvalidateNextMedia(p) VLC_UNUSED(p)
+# define vlc_player_SetNextMedia(a,b) (VLC_UNUSED(b), VLC_SUCCESS)
# define vlc_player_osd_Message(p, fmt...) VLC_UNUSED(p)
#endif /* TEST_PLAYLIST */
=====================================
test/modules/stream_out/transcode.c
=====================================
@@ -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 = {
=====================================
test/src/input/decoder/input_decoder.c
=====================================
@@ -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;
=====================================
test/src/player/player.c
=====================================
@@ -272,27 +272,6 @@ get_ctx(vlc_player_t *player, void *data)
return ctx;
}
-static input_item_t *
-player_get_next(vlc_player_t *player, void *data)
-{
- struct ctx *ctx = get_ctx(player, data);
- input_item_t *next_media;
- if (ctx->next_medias.size > 0)
- {
- next_media = ctx->next_medias.data[0];
- vlc_vector_remove(&ctx->next_medias, 0);
-
- input_item_Hold(next_media);
- bool success = vlc_vector_push(&ctx->added_medias, next_media);
- assert(success);
- success = vlc_vector_push(&ctx->played_medias, next_media);
- assert(success);
- }
- else
- next_media = NULL;
- return next_media;
-}
-
#define VEC_PUSH(vec, item) do { \
bool success = vlc_vector_push(&ctx->report.vec, item); \
assert(success); \
@@ -307,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
@@ -809,24 +800,30 @@ create_mock_media(const char *name, const struct media_params *params)
return item;
}
+static input_item_t *
+player_create_mock_media(struct ctx *ctx, const char *name,
+ const struct media_params *params)
+{
+ assert(params);
+
+ input_item_t *media = create_mock_media(name, params);
+ assert(media != NULL);
+
+ ctx->params = *params;
+ if (ctx->params.chapter_count > 0 && ctx->params.title_count == 0)
+ ctx->params.title_count = 1;
+ if (ctx->params.program_count == 0)
+ ctx->params.program_count = 1;
+ return media;
+}
+
static void
player_set_current_mock_media(struct ctx *ctx, const char *name,
const struct media_params *params, bool ignored)
{
input_item_t *media;
if (name)
- {
- assert(params);
-
- media = create_mock_media(name, params);
- assert(media);
-
- ctx->params = *params;
- if (ctx->params.chapter_count > 0 && ctx->params.title_count == 0)
- ctx->params.title_count = 1;
- if (ctx->params.program_count == 0)
- ctx->params.program_count = 1;
- }
+ media = player_create_mock_media(ctx, name, params);
else
media = NULL;
int ret = vlc_player_SetCurrentMedia(ctx->player, media);
@@ -846,10 +843,15 @@ static void
player_set_next_mock_media(struct ctx *ctx, const char *name,
const struct media_params *params)
{
- if (vlc_player_GetCurrentMedia(ctx->player) == NULL)
+ assert(name != NULL);
+ if (ctx->added_medias.size == 0)
{
- assert(ctx->added_medias.size == 0);
- player_set_current_mock_media(ctx, name, params, false);
+ input_item_t *media = player_create_mock_media(ctx, name, params);
+ vlc_player_SetNextMedia(ctx->player, media);
+ bool success = vlc_vector_push(&ctx->added_medias, media);
+ assert(success);
+ success = vlc_vector_push(&ctx->played_medias, media);
+ assert(success);
}
else
{
@@ -1473,7 +1475,7 @@ test_tracks_ids(struct ctx *ctx)
const size_t track_count = params.track_count[VIDEO_ES] +
params.track_count[AUDIO_ES] +
params.track_count[SPU_ES];
- player_set_next_mock_media(ctx, "media1", ¶ms);
+ player_set_current_mock_media(ctx, "media1", ¶ms, false);
/*
* Test that tracks can be set before the player is started
@@ -1908,7 +1910,7 @@ test_seeks(struct ctx *ctx)
vlc_player_t *player = ctx->player;
struct media_params params = DEFAULT_MEDIA_PARAMS(VLC_TICK_FROM_SEC(10));
- player_set_next_mock_media(ctx, "media1", ¶ms);
+ player_set_current_mock_media(ctx, "media1", ¶ms, false);
/* only the last one will be taken into account before start */
vlc_player_SetTimeFast(player, 0);
@@ -1965,6 +1967,17 @@ test_next_media(struct ctx *ctx)
struct media_params params = DEFAULT_MEDIA_PARAMS(VLC_TICK_FROM_MS(100));
+ /* This media should be overiden by the first call of
+ * player_set_next_mock_media() and no events should be sent regarding this
+ * media. */
+ input_item_t *media = create_mock_media("ignored", ¶ms);
+ assert(media);
+ vlc_player_SetNextMedia(ctx->player, media);
+
+ /* Check vlc_player_GetNextMedia() */
+ assert(vlc_player_GetNextMedia(ctx->player) == media);
+ input_item_Release(media);
+
for (size_t i = 0; i < media_count; ++i)
player_set_next_mock_media(ctx, media_names[i], ¶ms);
player_set_rate(ctx, 4.f);
@@ -2095,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);
@@ -2232,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
@@ -2259,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);
=====================================
test/src/video_output/video_output.c
=====================================
@@ -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);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e896a2fc5525407df7db7035e38990ba398a9e1b...7b631e09542737bb3d494e5e09d3ba0902bc47e8
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e896a2fc5525407df7db7035e38990ba398a9e1b...7b631e09542737bb3d494e5e09d3ba0902bc47e8
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list