]> git.sesse.net Git - vlc/blobdiff - modules/access/cdda.c
Remove stdlib.h
[vlc] / modules / access / cdda.c
index a09ebd8960adf847df937dc17953a6b3bf5bd65c..e49654d42acbd1a2e4d1af34005bf82a064e820d 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
+#define _GNU_SOURCE
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
+#include <vlc_input.h>
+#include <vlc_access.h>
 
-#include "codecs.h"
+#include <vlc_codecs.h> /* For WAVEHEADER */
 #include "vcd/cdrom.h"
 
 #include <vlc_playlist.h>
@@ -139,10 +140,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 )
@@ -177,36 +174,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_thread_t *)p_access->p_parent)->input.p_item )
-            p_item = p_playlist->status.p_item;
-        else
-        {
-            input_item_t *p_current = ( (input_thread_t*)p_access->p_parent)->
-                                         input.p_item;
-            p_item = playlist_LockItemGetByInput( p_playlist, p_current );
+        /* 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
     {
@@ -259,7 +258,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;
 }
 
@@ -414,13 +412,11 @@ static int GetTracks( access_t *p_access,
         return VLC_EGENERIC;
     }
 
-    p_item_in_category = playlist_LockItemToNode( p_playlist, p_parent );
-    psz_name = strdup( "Audio CD" );
+    p_item_in_category = playlist_ItemToNode( p_playlist, p_parent, VLC_FALSE );
     vlc_mutex_lock( &p_playlist->object_lock );
-    playlist_ItemSetName( p_parent, psz_name );
+    playlist_ItemSetName( p_parent, "Audio CD" );
     vlc_mutex_unlock( &p_playlist->object_lock );
     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 );
@@ -428,13 +424,12 @@ 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 ) );
+            const char *psz_name = cddb_disc_get_title( p_sys->p_disc );
             vlc_mutex_lock( &p_playlist->object_lock );
             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
@@ -477,7 +472,7 @@ static int GetTracks( access_t *p_access,
         /* If we have CDDB info, change the name */
         if( p_sys->p_disc )
         {
-            char *psz_result;
+            const char *psz_result;
             cddb_track_t *t = cddb_disc_get_track( p_sys->p_disc, i );
             if( t!= NULL )
             {
@@ -485,23 +480,23 @@ 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 );
                 }
             }
         }
 #endif
-        playlist_AddWhereverNeeded( p_playlist, p_input_item, p_parent,
-                               p_item_in_category, VLC_FALSE, PLAYLIST_APPEND );
+        playlist_BothAddInput( p_playlist, p_input_item, p_item_in_category,
+                               PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL,
+                               VLC_FALSE );
         free( psz_uri ); free( psz_opt ); free( psz_name );
         free( psz_first ); free( psz_last );
     }