From bbe53b4f49eb0ce537409643ba1b431053aaf1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 19 Nov 2016 13:19:06 +0200 Subject: [PATCH] interface: clean up intf_InsertItem() - Handle and report errors. - Fix and improve documentation. --- src/interface/interface.c | 27 ++++++++++++++++++++++----- src/libvlc.h | 4 ++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/interface/interface.c b/src/interface/interface.c index f71790bcd6..568215f7ce 100644 --- a/src/interface/interface.c +++ b/src/interface/interface.c @@ -154,15 +154,32 @@ static playlist_t *intf_GetPlaylist(libvlc_int_t *libvlc) } /** - * Inserts an item in the playlist used by interfaces. + * Inserts an item in the playlist. + * + * This function is used during initialization. Unlike playlist_Add() and + * variants, it inserts an item to the beginning of the playlist. That is + * meant to compensate for the reverse parsing order of the command line. + * * @note This function may not be called at the same time as * intf_DestroyAll(). */ -void intf_InsertItem(libvlc_int_t *libvlc, const char *mrl, unsigned optc, - const char *const *optv, unsigned flags) +int intf_InsertItem(libvlc_int_t *libvlc, const char *mrl, unsigned optc, + const char *const *optv, unsigned flags) { - playlist_AddExt(intf_GetPlaylist(libvlc), mrl, NULL, 0, - 0, optc, optv, flags, true); + playlist_t *playlist = intf_GetPlaylist(libvlc); + input_item_t *item = input_item_New(mrl, NULL); + + if (unlikely(item == NULL)) + return -1; + + int ret = -1; + + if (input_item_AddOptions(item, optc, optv, flags) == VLC_SUCCESS + && playlist_AddInput(playlist, item, 0, 0, true) == VLC_SUCCESS) + ret = 0; + + input_item_Release(item); + return ret; } void libvlc_InternalPlay(libvlc_int_t *libvlc) diff --git a/src/libvlc.h b/src/libvlc.h index 63d8b5444c..eef1d0a01c 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -161,8 +161,8 @@ static inline libvlc_priv_t *libvlc_priv (libvlc_int_t *libvlc) return (libvlc_priv_t *)libvlc; } -void intf_InsertItem(libvlc_int_t *, const char *mrl, unsigned optc, - const char * const *optv, unsigned flags); +int intf_InsertItem(libvlc_int_t *, const char *mrl, unsigned optc, + const char * const *optv, unsigned flags); void intf_DestroyAll( libvlc_int_t * ); #define libvlc_stats( o ) (libvlc_priv((VLC_OBJECT(o))->obj.libvlc)->b_stats)