[vlc-devel] [vlc-commits] playlist: remove item parameter of playlist_NodeCreate()
Steve Lhomme
robux4 at gmail.com
Thu Nov 17 08:57:17 CET 2016
On Wed, Nov 16, 2016 at 9:11 PM, Rémi Denis-Courmont <git at videolan.org> wrote:
> vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Nov 16 22:03:05 2016 +0200| [50c44e464eed62a5a8ddb4721df582c35aa9a801] | committer: Rémi Denis-Courmont
>
> playlist: remove item parameter of playlist_NodeCreate()
>
> Nodes are not supposed to have real input items. The parameter was
> always NULL, except when copying another node, in which case it did not
> matter whether it was or was not NULL.
>
>> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=50c44e464eed62a5a8ddb4721df582c35aa9a801
> ---
>
> include/vlc_playlist.h | 2 +-
> .../gui/qt/components/playlist/playlist_model.cpp | 2 +-
> modules/gui/qt/recents.cpp | 2 +-
> src/playlist/engine.c | 7 ++---
> src/playlist/item.c | 32 ++++++++++++++--------
> src/playlist/services_discovery.c | 9 ++----
> src/playlist/tree.c | 15 ++++------
> 7 files changed, 36 insertions(+), 33 deletions(-)
>
> diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
> index a53f4d7..748e5d2 100644
> --- a/include/vlc_playlist.h
> +++ b/include/vlc_playlist.h
> @@ -351,7 +351,7 @@ VLC_API int playlist_LiveSearchUpdate(playlist_t *, playlist_item_t *, const cha
> * Tree management
> ********************************************************/
> /* Node management */
> -VLC_API playlist_item_t * playlist_NodeCreate( playlist_t *, const char *, playlist_item_t * p_parent, int i_pos, int i_flags, input_item_t * );
> +VLC_API playlist_item_t * playlist_NodeCreate( playlist_t *, const char *, playlist_item_t * p_parent, int i_pos, int i_flags );
> VLC_API playlist_item_t * playlist_ChildSearchName(playlist_item_t*, const char* ) VLC_USED;
> VLC_API void playlist_NodeDelete( playlist_t *, playlist_item_t *, bool );
>
> diff --git a/modules/gui/qt/components/playlist/playlist_model.cpp b/modules/gui/qt/components/playlist/playlist_model.cpp
> index 29f439f..9788699 100644
> --- a/modules/gui/qt/components/playlist/playlist_model.cpp
> +++ b/modules/gui/qt/components/playlist/playlist_model.cpp
> @@ -896,7 +896,7 @@ void PLModel::createNode( QModelIndex index, QString name )
> if ( !index.isValid() ) index = rootIndex();
> playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
> if( p_item )
> - playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
> + playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0 );
> }
>
> void PLModel::renameNode( QModelIndex index, QString name )
> diff --git a/modules/gui/qt/recents.cpp b/modules/gui/qt/recents.cpp
> index 3139adc..8d2fe6f 100644
> --- a/modules/gui/qt/recents.cpp
> +++ b/modules/gui/qt/recents.cpp
> @@ -159,7 +159,7 @@ void RecentsMRL::save()
> playlist_item_t *RecentsMRL::toPlaylist(int length)
> {
> playlist_Lock(THEPL);
> - playlist_item_t *p_node_recent = playlist_NodeCreate(THEPL, _("Recently Played"), THEPL->p_root, PLAYLIST_END, PLAYLIST_RO_FLAG, NULL);
> + playlist_item_t *p_node_recent = playlist_NodeCreate(THEPL, _("Recently Played"), THEPL->p_root, PLAYLIST_END, PLAYLIST_RO_FLAG);
> playlist_Unlock(THEPL);
>
> if ( p_node_recent == NULL ) return NULL;
> diff --git a/src/playlist/engine.c b/src/playlist/engine.c
> index cb49472..feda7ad 100644
> --- a/src/playlist/engine.c
> +++ b/src/playlist/engine.c
> @@ -234,13 +234,12 @@ playlist_t *playlist_Create( vlc_object_t *p_parent )
> playlist_item_t *root, *playing, *ml;
>
> PL_LOCK;
> - root = playlist_NodeCreate( p_playlist, NULL, NULL,
> - PLAYLIST_END, 0, NULL );
> + root = playlist_NodeCreate( p_playlist, NULL, NULL, PLAYLIST_END, 0 );
> playing = playlist_NodeCreate( p_playlist, _( "Playlist" ), root,
> - PLAYLIST_END, PLAYLIST_RO_FLAG | PLAYLIST_NO_INHERIT_FLAG, NULL );
> + PLAYLIST_END, PLAYLIST_RO_FLAG | PLAYLIST_NO_INHERIT_FLAG );
> if( var_InheritBool( p_parent, "media-library") )
> ml = playlist_NodeCreate( p_playlist, _( "Media Library" ), root,
> - PLAYLIST_END, PLAYLIST_RO_FLAG | PLAYLIST_NO_INHERIT_FLAG, NULL );
> + PLAYLIST_END, PLAYLIST_RO_FLAG | PLAYLIST_NO_INHERIT_FLAG );
> else
> ml = NULL;
> PL_UNLOCK;
> diff --git a/src/playlist/item.c b/src/playlist/item.c
> index 6538e2b..de7c5a5 100644
> --- a/src/playlist/item.c
> +++ b/src/playlist/item.c
> @@ -873,21 +873,31 @@ static int RecursiveInsertCopy (
>
> input_item_t *p_input = p_item->p_input;
>
> - if( !(p_item->i_children != -1 && b_flat) )
> + if( p_item->i_children == -1 || !b_flat )
> {
> - input_item_t *p_new_input = input_item_Copy( p_input );
> - if( !p_new_input ) return i_pos;
> -
> playlist_item_t *p_new_item = NULL;
> +
> if( p_item->i_children == -1 )
> - p_new_item = playlist_NodeAddInput( p_playlist, p_new_input,
> - p_parent, PLAYLIST_INSERT, i_pos,
> - pl_Locked );
> + {
> + input_item_t *p_new_input = input_item_Copy( p_input );
> +
> + if( likely(p_new_input != NULL) )
> + {
> + p_new_item = playlist_NodeAddInput( p_playlist, p_new_input,
> + p_parent, PLAYLIST_INSERT,
> + i_pos, pl_Locked );
> + vlc_gc_decref( p_new_input );
> + }
> + }
> else
> - p_new_item = playlist_NodeCreate( p_playlist, NULL,
> - p_parent, i_pos, 0, p_new_input );
> - vlc_gc_decref( p_new_input );
> - if( !p_new_item ) return i_pos;
> + {
> + vlc_mutex_lock( &p_input->lock );
> + p_new_item = playlist_NodeCreate( p_playlist, p_input->psz_name,
> + p_parent, i_pos, 0 );
> + vlc_mutex_unlock( &p_input->lock );
> + }
> + if( unlikely(p_new_item == NULL) )
> + return i_pos;
>
> i_pos++;
>
> diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c
> index c072a66..d4fdf10 100644
> --- a/src/playlist/services_discovery.c
> +++ b/src/playlist/services_discovery.c
> @@ -165,8 +165,7 @@ static void playlist_sd_item_added(services_discovery_t *sd,
> if (sds->node == NULL)
> sds->node = playlist_NodeCreate(playlist, longname, playlist->p_root,
> PLAYLIST_END,
> - PLAYLIST_RO_FLAG|PLAYLIST_SKIP_FLAG,
> - NULL);
> + PLAYLIST_RO_FLAG|PLAYLIST_SKIP_FLAG);
>
> /* If p_parent is in root category (this is clearly a hack) and we have a cat */
> if (psz_cat == NULL)
> @@ -177,8 +176,7 @@ static void playlist_sd_item_added(services_discovery_t *sd,
> if (parent == NULL)
> parent = playlist_NodeCreate(playlist, psz_cat, sds->node,
> PLAYLIST_END,
> - PLAYLIST_RO_FLAG | PLAYLIST_SKIP_FLAG,
> - NULL);
> + PLAYLIST_RO_FLAG|PLAYLIST_SKIP_FLAG);
> }
>
> playlist_NodeAddInput(playlist, p_input, parent,
> @@ -241,8 +239,7 @@ int playlist_ServicesDiscoveryAdd(playlist_t *playlist, const char *chain)
> if (sds->node == NULL && sds->sd->description != NULL)
> sds->node = playlist_NodeCreate(playlist, sds->sd->description,
> playlist->p_root, PLAYLIST_END,
> - PLAYLIST_RO_FLAG|PLAYLIST_SKIP_FLAG,
> - NULL);
> + PLAYLIST_RO_FLAG|PLAYLIST_SKIP_FLAG);
>
> TAB_APPEND(pl_priv(playlist)->i_sds, pl_priv(playlist)->pp_sds, sds);
> playlist_Unlock(playlist);
> diff --git a/src/playlist/tree.c b/src/playlist/tree.c
> index 44078c2..b1e2232 100644
> --- a/src/playlist/tree.c
> +++ b/src/playlist/tree.c
> @@ -58,21 +58,18 @@ playlist_item_t *GetPrevItem( playlist_t *p_playlist,
> playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist,
> const char *psz_name,
> playlist_item_t *p_parent, int i_pos,
> - int i_flags, input_item_t *p_input )
> + int i_flags )
> {
> - input_item_t *p_new_input = NULL;
> + input_item_t *p_new_input;
> playlist_item_t *p_item;
>
> PL_ASSERT_LOCKED;
> if( !psz_name ) psz_name = _("Undefined");
>
> - if( !p_input )
> - p_new_input = input_item_NewExt( NULL, psz_name, -1, ITEM_TYPE_NODE,
> - ITEM_NET_UNKNOWN );
> - p_item = playlist_ItemNewFromInput( p_playlist,
> - p_input ? p_input : p_new_input );
> - if( p_new_input )
> - vlc_gc_decref( p_new_input );
> + p_new_input = input_item_NewExt( NULL, psz_name, -1, ITEM_TYPE_NODE,
> + ITEM_NET_UNKNOWN );
> + p_item = playlist_ItemNewFromInput( p_playlist, p_new_input );
> + vlc_gc_decref( p_new_input );
input_item_NewExt() can return NULL so the test on p_new_input should remain.
> if( p_item == NULL ) return NULL;
> p_item->i_children = 0;
>
> _______________________________________________
> vlc-commits mailing list
> vlc-commits at videolan.org
> https://mailman.videolan.org/listinfo/vlc-commits
More information about the vlc-devel
mailing list