[vlc-commits] commit: core playlist: refactor & fix #3737 (Jakob Leben )
git at videolan.org
git at videolan.org
Sat Jun 12 04:29:44 CEST 2010
vlc | branch: master | Jakob Leben <jleben at videolan.org> | Sat Jun 12 04:24:38 2010 +0200| [4eff56920864b1b4c37ffacc953e50d5940f3cd5] | committer: Jakob Leben
core playlist: refactor & fix #3737
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4eff56920864b1b4c37ffacc953e50d5940f3cd5
---
src/playlist/item.c | 73 +++++++++++++++++++++++++++++---------------------
1 files changed, 42 insertions(+), 31 deletions(-)
diff --git a/src/playlist/item.c b/src/playlist/item.c
index 64d8131..8213308 100644
--- a/src/playlist/item.c
+++ b/src/playlist/item.c
@@ -90,21 +90,22 @@ static void input_item_add_subitem_tree ( const vlc_event_t * p_event,
}
p_up = p_up->p_parent;
}
+
if( b_flat )
- {
playlist_DeleteItem( p_playlist, p_item, true );
- p_item = playlist_InsertInputItemTree( p_playlist, p_parent,
- p_new_root, pos, true );
- }
- else
- p_item = playlist_InsertInputItemTree( p_playlist, p_item,
- p_new_root, PLAYLIST_END, false );
+
+ p_item = playlist_InsertInputItemTree( p_playlist,
+ b_flat ? p_parent : p_item,
+ p_new_root,
+ b_flat ? pos: PLAYLIST_END,
+ b_flat );
if( !b_flat ) var_SetAddress( p_playlist, "leaf-to-parent", p_input );
+ //control playback only if it was the current playing item that got subitems
if( b_current )
{
- if( ( b_stop && !b_flat ) || !b_autostart )
+ if( !p_item || ( b_stop && !b_flat ) || !b_autostart )
{
PL_UNLOCK;
playlist_Stop( p_playlist );
@@ -796,40 +797,50 @@ static int RecursiveAddIntoParent (
input_item_node_t *p_node, int i_pos, bool b_flat,
playlist_item_t **pp_first_leaf )
{
+ *pp_first_leaf = NULL;
+
if( p_parent->i_children == -1 ) ChangeToNode( p_playlist, p_parent );
if( i_pos == PLAYLIST_END ) i_pos = p_parent->i_children;
for( int i = 0; i < p_node->i_children; i++ )
{
- playlist_item_t *p_child = NULL;
- if( b_flat ? p_node->pp_children[i]->i_children == 0 : 1 )
+ input_item_node_t *p_child_node = p_node->pp_children[i];
+
+ playlist_item_t *p_new_item = NULL;
+ bool b_children = p_child_node->i_children > 0;
+
+ //Create the playlist item represented by input node, if allowed.
+ if( !(b_flat && b_children) )
{
- p_child = playlist_NodeAddInput( p_playlist,
- p_node->pp_children[i]->p_item,
- p_parent,
- PLAYLIST_INSERT, i_pos,
- pl_Locked );
+ p_new_item = playlist_NodeAddInput( p_playlist,
+ p_child_node->p_item,
+ p_parent,
+ PLAYLIST_INSERT, i_pos,
+ pl_Locked );
+ if( !p_new_item ) return i_pos;
+
i_pos++;
+
+ //Swap parent for new item, if we will recurse
+ if( b_children ) p_parent = p_new_item;
}
- if( p_node->pp_children[i]->i_children > 0 )
+ //Recurse if any children
+ if( b_children )
{
- if( b_flat )
- {
- i_pos = RecursiveAddIntoParent(
- p_playlist, p_parent,
- p_node->pp_children[i], i_pos, true,
- &p_child );
- }
- else
- {
- RecursiveAddIntoParent( p_playlist, p_child,
- p_node->pp_children[i], 0, false,
- &p_child );
- }
+ //Substitute p_new_item for first child leaf
+ //(If flat, continue counting from current position)
+ int i_last_pos = RecursiveAddIntoParent(
+ p_playlist, p_parent, p_child_node,
+ ( b_flat ? i_pos : 0 ),
+ b_flat,
+ &p_new_item );
+ //If flat, take position after recursion as current position
+ if( b_flat ) i_pos = i_last_pos;
}
- assert( p_child != NULL );
- if( i == 0 ) *pp_first_leaf = p_child;
+
+ assert( p_new_item != NULL );
+ if( i == 0 ) *pp_first_leaf = p_new_item;
}
return i_pos;
}
More information about the vlc-commits
mailing list