]> git.sesse.net Git - vlc/blobdiff - modules/access/cdda.c
Input access locking, part 3 (final).
[vlc] / modules / access / cdda.c
index 589e0d7c9aaf1e22fd064fd7f7d2a08ba42b697f..b246ad67c781a4dcbec171c16d4aa503f42b3a5b 100644 (file)
@@ -31,8 +31,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#define _GNU_SOURCE
-#include <stdlib.h>
 
 #include <vlc/vlc.h>
 #include <vlc_input.h>
@@ -141,10 +139,6 @@ static int Open( vlc_object_t *p_this )
     vcddev_t *vcddev;
     char *psz_name;
     int i_mrl_tracknum = -1;
-
-    input_thread_t *p_input;
-    playlist_item_t *p_item = NULL;
-    playlist_t *p_playlist  = NULL;
     int i_ret;
 
     if( !p_access->psz_path || !*p_access->psz_path )
@@ -179,36 +173,38 @@ static int Open( vlc_object_t *p_this )
     STANDARD_BLOCK_ACCESS_INIT
     p_sys->vcddev = vcddev;
 
-    /* We only do separate items if the whole disc is requested -
-     *  Dirty hack we access some private data ! */
-    p_input = (input_thread_t *)( p_access->p_parent );
-
    /* Do we play a single track ? */
    p_sys->i_track = var_CreateGetInteger( p_access, "cdda-track" );
 
    if( p_sys->i_track < 0 && i_mrl_tracknum <= 0 )
    {
-        p_playlist = pl_Yield( p_access );
-        if( p_playlist->status.p_item->p_input ==
-             input_GetItem( (input_thread_t *)p_access->p_parent))
-            p_item = p_playlist->status.p_item;
-        else
-        {
-            input_item_t *p_current = input_GetItem(
-                                        (input_thread_t*)p_access->p_parent);
-            p_item = playlist_ItemGetByInput( p_playlist, p_current, VLC_FALSE );
+        /* We only do separate items if the whole disc is requested */
+        playlist_t *p_playlist = pl_Yield( p_access );
 
-            if( !p_item )
+        i_ret = -1;
+        if( p_playlist )
+        {
+            input_thread_t *p_input = (input_thread_t*)vlc_object_find( p_access, VLC_OBJECT_INPUT, FIND_PARENT );
+            if( p_input )
             {
-                msg_Dbg( p_playlist, "unable to find item in playlist");
-                return -1;
+                input_item_t *p_current = input_GetItem( p_input );
+                playlist_item_t *p_item;
+
+                if( p_playlist->status.p_item->p_input == p_current )
+                    p_item = p_playlist->status.p_item;
+                else
+                    p_item = playlist_ItemGetByInput( p_playlist, p_current, VLC_FALSE );
+
+                if( p_item )
+                    i_ret = GetTracks( p_access, p_playlist, p_item );
+                else
+                    msg_Dbg( p_playlist, "unable to find item in playlist");
+                vlc_object_release( p_input );
             }
+            vlc_object_release( p_playlist );
         }
-
-        i_ret = GetTracks( p_access, p_playlist, p_item );
-
-        if( p_playlist ) vlc_object_release( p_playlist );
-        if( i_ret < 0 ) goto error;
+        if( i_ret < 0 )
+            goto error;
     }
     else
     {
@@ -261,7 +257,6 @@ static int Open( vlc_object_t *p_this )
 error:
     ioctl_Close( VLC_OBJECT(p_access), p_sys->vcddev );
     free( p_sys );
-    if( p_playlist ) vlc_object_release( p_playlist );
     return VLC_EGENERIC;
 }
 
@@ -417,12 +412,8 @@ static int GetTracks( access_t *p_access,
     }
 
     p_item_in_category = playlist_ItemToNode( p_playlist, p_parent, VLC_FALSE );
-    psz_name = strdup( "Audio CD" );
-    vlc_mutex_lock( &p_playlist->object_lock );
-    playlist_ItemSetName( p_parent, psz_name );
-    vlc_mutex_unlock( &p_playlist->object_lock );
+    playlist_ItemSetName( p_parent, "Audio CD" );
     var_SetInteger( p_playlist, "item-change", p_parent->p_input->i_id );
-    free( psz_name );
 
 #ifdef HAVE_LIBCDDB
     GetCDDBInfo( p_access, i_titles, p_sys->p_sectors );
@@ -430,13 +421,10 @@ static int GetTracks( access_t *p_access,
     {
         if( cddb_disc_get_title( p_sys->p_disc ) )
         {
-            asprintf( &psz_name, "%s", cddb_disc_get_title( p_sys->p_disc ) );
-            vlc_mutex_lock( &p_playlist->object_lock );
+            const char *psz_name = cddb_disc_get_title( p_sys->p_disc );
             playlist_ItemSetName( p_parent, psz_name );
-            vlc_mutex_unlock( &p_playlist->object_lock );
             var_SetInteger( p_playlist, "item-change",
                             p_parent->p_input->i_id );
-            free( psz_name );
         }
     }
 #endif
@@ -487,17 +475,16 @@ static int GetTracks( access_t *p_access,
                 {
                     input_ItemAddInfo( p_input_item, _(VLC_META_INFO_CAT),
                                             _(VLC_META_TITLE),
-                                            cddb_track_get_title( t ) );
+                                            "%s", cddb_track_get_title( t ) );
                     if( p_input_item->psz_name )
                         free( p_input_item->psz_name );
-                    asprintf( &p_input_item->psz_name, "%s",
-                              cddb_track_get_title( t ) );
+                    p_input_item->psz_name = strdup( cddb_track_get_title( t ) );
                 }
                 psz_result = cddb_track_get_artist( t );
                 if( psz_result )
                 {
                     input_ItemAddInfo( p_input_item, _(VLC_META_INFO_CAT),
-                                            _(VLC_META_ARTIST), psz_result );
+                                       _(VLC_META_ARTIST), "%s", psz_result );
                 }
             }
         }