]> git.sesse.net Git - vlc/blobdiff - src/control/media_list_player.c
Merge commit 'origin/1.0-bugfix'
[vlc] / src / control / media_list_player.c
index c5f04511cdfbdca0ec95ff72be555a8502945a50..1ed1af0b324b10fb3d79127718a99877066d19ef 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-#include "libvlc_internal.h"
+
 #include <vlc/libvlc.h>
+#include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_list.h>
+#include <vlc/libvlc_media_player.h>
+#include <vlc/libvlc_media_list_player.h>
+#include <vlc/libvlc_events.h>
+
+#include "libvlc_internal.h"
+
+#include "media_internal.h" // Abuse, could and should be removed
 #include "media_list_path.h"
 
+
+struct libvlc_media_list_player_t
+{
+    libvlc_event_manager_t *    p_event_manager;
+    libvlc_instance_t *         p_libvlc_instance;
+    int                         i_refcount;
+    vlc_mutex_t                 object_lock;
+    libvlc_media_list_path_t    current_playing_item_path;
+    libvlc_media_t *            p_current_playing_item;
+    libvlc_media_list_t *       p_mlist;
+    libvlc_media_player_t *     p_mi;
+};
+
 /*
  * Private functions
  */
@@ -64,23 +86,23 @@ get_next_path( libvlc_media_list_player_t * p_mlp )
                             p_mlp->p_mlist,
                             p_mlp->current_playing_item_path );
 
-    int deepness = libvlc_media_list_path_deepness( p_mlp->current_playing_item_path );
-    if( deepness < 1 || !p_parent_of_playing_item )
+    int depth = libvlc_media_list_path_depth( p_mlp->current_playing_item_path );
+    if( depth < 1 || !p_parent_of_playing_item )
         return NULL;
 
     ret = libvlc_media_list_path_copy( p_mlp->current_playing_item_path );
 
-    while( ret[deepness-1] >= libvlc_media_list_count( p_parent_of_playing_item, NULL ) )
+    while( ret[depth-1] >= libvlc_media_list_count( p_parent_of_playing_item, NULL ) )
     {
-        deepness--;
-        if( deepness <= 0 )
+        depth--;
+        if( depth <= 0 )
         {
             free( ret );
             libvlc_media_list_release( p_parent_of_playing_item );
             return NULL;
         }
-        ret[deepness] = -1;
-        ret[deepness-1]++;
+        ret[depth] = -1;
+        ret[depth-1]++;
         p_parent_of_playing_item  = libvlc_media_list_parentlist_at_path(
                                         p_mlp->p_mlist,
                                         ret );
@@ -264,10 +286,13 @@ libvlc_media_list_player_new( libvlc_instance_t * p_instance,
     if( !p_mlp )
         return NULL;
 
+    libvlc_retain( p_instance );
+    p_mlp->p_libvlc_instance = p_instance;
+    p_mlp->i_refcount = 0;
+    vlc_mutex_init( &p_mlp->object_lock );
     p_mlp->current_playing_item_path = NULL;
-    p_mlp->p_mi = NULL;
     p_mlp->p_mlist = NULL;
-    vlc_mutex_init( &p_mlp->object_lock );
+    p_mlp->p_mi = NULL;
     p_mlp->p_event_manager = libvlc_event_manager_new( p_mlp,
                                                        p_instance,
                                                        p_e );
@@ -282,7 +307,32 @@ libvlc_media_list_player_new( libvlc_instance_t * p_instance,
  **************************************************************************/
 void libvlc_media_list_player_release( libvlc_media_list_player_t * p_mlp )
 {
-    free(p_mlp);
+    if( !p_mlp )
+        return;
+
+    vlc_mutex_lock( &p_mlp->object_lock );
+
+    p_mlp->i_refcount--;
+    if( p_mlp->i_refcount > 0 )
+    {
+        vlc_mutex_unlock( &p_mlp->object_lock );
+        return;
+    }
+    vlc_mutex_unlock( &p_mlp->object_lock );
+    vlc_mutex_destroy( &p_mlp->object_lock );
+
+    libvlc_event_manager_release( p_mlp->p_event_manager );
+    libvlc_media_player_release( p_mlp->p_mi );
+
+    if( p_mlp->p_mlist )
+    {
+        uninstall_playlist_observer( p_mlp );
+        libvlc_media_list_release( p_mlp->p_mlist );
+    }
+
+    free( p_mlp->current_playing_item_path );
+    libvlc_release( p_mlp->p_libvlc_instance );
+    free( p_mlp );
 }
 
 /**************************************************************************
@@ -376,7 +426,6 @@ libvlc_media_list_player_is_playing( libvlc_media_list_player_t * p_mlp,
 {
     libvlc_state_t state = libvlc_media_player_get_state( p_mlp->p_mi, p_e );
     return (state == libvlc_Opening) || (state == libvlc_Buffering) ||
-           (state == libvlc_Forward) || (state == libvlc_Backward) ||
            (state == libvlc_Playing);
 }