[vlc-devel] [PATCH 19/21] access/cdda: use stream-fragments for track selection

Filip Roséen filip at atch.se
Sun Jul 31 22:42:28 CEST 2016


Given that the variables affected by this patch does not retain their
value across runs, having the relevant information be part of the MRL
for each entry is a better solution.

This commit removes the unnecessary (and rather cumbersome) variables
and replaces them with parsing the appropriate fragment associated
with the stream (if any).
---
 modules/access/cdda.c | 74 ++++++++++++++++++++++++---------------------------
 1 file changed, 35 insertions(+), 39 deletions(-)

diff --git a/modules/access/cdda.c b/modules/access/cdda.c
index 0e57c26..779bcef 100644
--- a/modules/access/cdda.c
+++ b/modules/access/cdda.c
@@ -41,6 +41,7 @@
 #include <vlc_plugin.h>
 #include <vlc_input.h>
 #include <vlc_access.h>
+#include <vlc_stream.h>
 #include <vlc_meta.h>
 #include <vlc_charset.h> /* ToLocaleDup */
 
@@ -76,6 +77,8 @@ static void Close( vlc_object_t * );
 # endif
 #endif
 
+#define CDDA_FRAGMENT_FMT "%d_%d-%d"
+
 vlc_module_begin ()
     set_shortname( N_("Audio CD") )
     set_description( N_("Audio CD input") )
@@ -87,13 +90,7 @@ vlc_module_begin ()
     add_loadfile( "cd-audio", CD_DEVICE, CDAUDIO_DEV_TEXT,
                   CDAUDIO_DEV_LONGTEXT, false )
 
-    add_usage_hint( N_("[cdda:][device][@[track]]") )
-    add_integer( "cdda-track", 0 , NULL, NULL, true )
-        change_volatile ()
-    add_integer( "cdda-first-sector", -1, NULL, NULL, true )
-        change_volatile ()
-    add_integer( "cdda-last-sector", -1, NULL, NULL, true )
-        change_volatile ()
+    add_usage_hint( N_("[cdda:][device][#[track][_[first-sector]-[last-sector]]") )
 
 #ifdef HAVE_LIBCDDB
     add_string( "cddb-server", "freedb.videolan.org", N_( "CDDB Server" ),
@@ -185,10 +182,7 @@ static int Open( vlc_object_t *p_this )
 
     p_sys->vcddev = vcddev;
 
-    /* Do we play a single track ? */
-    p_sys->i_track = var_InheritInteger( p_access, "cdda-track" ) - 1;
-
-    if( p_sys->i_track < 0 )
+    if( vlc_stream_PeekFragment( p_access ) == NULL )
     {
         /* We only do separate items if the whole disc is requested */
         input_thread_t *p_input = p_access->p_input;
@@ -205,6 +199,23 @@ static int Open( vlc_object_t *p_this )
     }
     else
     {
+        /* try to seek to requested track */
+
+        switch( sscanf( vlc_stream_PeekFragment( p_access ), CDDA_FRAGMENT_FMT,
+            &p_sys->i_track, &p_sys->i_first_sector, &p_sys->i_last_sector ) )
+        {
+            case 1:
+                p_sys->i_first_sector = -1;
+                p_sys->i_last_sector  = -1;
+
+            case 3:
+                free( vlc_stream_PopFragment( p_access ) );
+                break;
+
+            default:
+                goto error;
+        }
+
         /* Build a WAV header for the output data */
         memset( &p_sys->waveheader, 0, sizeof(WAVEHEADER) );
         SetWLE( &p_sys->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
@@ -223,10 +234,6 @@ static int Open( vlc_object_t *p_this )
         p_sys->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
         p_sys->waveheader.DataLength = 0;           /* we just don't know */
 
-        p_sys->i_first_sector = var_InheritInteger( p_access,
-                                                    "cdda-first-sector" );
-        p_sys->i_last_sector  = var_InheritInteger( p_access,
-                                                    "cdda-last-sector" );
         /* Tracknumber in MRL */
         if( p_sys->i_first_sector < 0 || p_sys->i_last_sector < 0 )
         {
@@ -237,6 +244,7 @@ static int Open( vlc_object_t *p_this )
                 msg_Err( p_access, "invalid track number" );
                 goto error;
             }
+
             p_sys->i_first_sector = p_sys->p_sectors[p_sys->i_track];
             p_sys->i_last_sector = p_sys->p_sectors[p_sys->i_track+1];
         }
@@ -492,9 +500,15 @@ static int GetTracks( access_t *p_access, input_item_t *p_current )
     /* Build title table */
     for( int i = 0; i < i_titles; i++ )
     {
-        char *psz_opt, *psz_name;
+        char track_id[64];
+        char *psz_name, *psz_mrl;
 
-        msg_Dbg( p_access, "track[%d] start=%d", i, p_sys->p_sectors[i] );
+        /* create track MRL */
+        snprintf( track_id, sizeof( track_id ), CDDA_FRAGMENT_FMT, i,
+                  p_sys->p_sectors[i], p_sys->p_sectors[i+1] );
+
+        if( !( psz_mrl = vlc_stream_CreateFragmentedMRL( p_access, track_id ) ) )
+            continue;
 
         /* Define a "default name" */
         if( asprintf( &psz_name, _("Audio CD - Track %02i"), (i+1) ) == -1 )
@@ -504,34 +518,16 @@ static int GetTracks( access_t *p_access, input_item_t *p_current )
         const mtime_t i_duration = (int64_t)( p_sys->p_sectors[i+1] - p_sys->p_sectors[i] ) *
                                    CDDA_DATA_SIZE * 1000000 / 44100 / 2 / 2;
 
-        input_item_t *p_item = input_item_NewDisc( p_access->psz_url,
-                                                   psz_name, i_duration );
-        if( likely(psz_name != p_access->psz_url) )
-            free( psz_name );
+
+        input_item_t *p_item = input_item_NewDisc( psz_mrl, psz_name, i_duration );
+
+        free( psz_mrl );
 
         if( unlikely(p_item == NULL) )
             continue;
 
         input_item_CopyOptions( p_item, p_current );
 
-        if( likely(asprintf( &psz_opt, "cdda-track=%i", i+1 ) != -1) )
-        {
-            input_item_AddOption( p_item, psz_opt, VLC_INPUT_OPTION_TRUSTED );
-            free( psz_opt );
-        }
-        if( likely(asprintf( &psz_opt, "cdda-first-sector=%i",
-                             p_sys->p_sectors[i] ) != -1) )
-        {
-            input_item_AddOption( p_item, psz_opt, VLC_INPUT_OPTION_TRUSTED );
-            free( psz_opt );
-        }
-        if( likely(asprintf( &psz_opt, "cdda-last-sector=%i",
-                             p_sys->p_sectors[i+1] ) != -1) )
-        {
-            input_item_AddOption( p_item, psz_opt, VLC_INPUT_OPTION_TRUSTED );
-            free( psz_opt );
-        }
-
         const char *psz_track_title = NULL;
         const char *psz_track_artist = NULL;
         const char *psz_track_genre = NULL;
-- 
2.9.2



More information about the vlc-devel mailing list