[vlc-devel] [PATCH] input: De-duplicate titles

Hugo Beauzée-Luyssen hugo at beauzee.fr
Sun Sep 3 15:19:48 CEST 2017


Store them in the input source
---
 src/input/control.c        | 12 ++++++------
 src/input/input.c          | 12 +++---------
 src/input/input_internal.h |  4 ----
 src/input/var.c            | 31 ++++++++++++++++---------------
 4 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/src/input/control.c b/src/input/control.c
index 1401e0893d..e9d85690f7 100644
--- a/src/input/control.c
+++ b/src/input/control.c
@@ -327,9 +327,9 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             if ( *pi_req_title_offset < 0 ) /* return current title if -1 */
                 *pi_req_title_offset = i_current_title;
 
-            if( priv->i_title && priv->i_title > *pi_req_title_offset )
+            if( priv->master->i_title && priv->master->i_title > *pi_req_title_offset )
             {
-                *p_title = vlc_input_title_Duplicate( priv->title[*pi_req_title_offset] );
+                *p_title = vlc_input_title_Duplicate( priv->master->title[*pi_req_title_offset] );
                 vlc_mutex_unlock( &priv->p_item->lock );
                 return VLC_SUCCESS;
             }
@@ -343,7 +343,7 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
         case INPUT_GET_FULL_TITLE_INFO:
         {
             vlc_mutex_lock( &priv->p_item->lock );
-            unsigned count = priv->i_title;
+            unsigned count = priv->master->i_title;
             input_title_t **array = malloc( count * sizeof (*array) );
 
             if( count > 0 && unlikely(array == NULL) )
@@ -353,7 +353,7 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             }
 
             for( unsigned i = 0; i < count; i++ )
-                array[i] = vlc_input_title_Duplicate( priv->title[i] );
+                array[i] = vlc_input_title_Duplicate( priv->master->title[i] );
 
             vlc_mutex_unlock( &priv->p_item->lock );
 
@@ -372,13 +372,13 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             if ( *pi_title_to_fetch < 0 ) /* query current title if -1 */
                 *pi_title_to_fetch = var_GetInteger( p_input, "title" );
 
-            if( priv->i_title == 0 || priv->i_title <= *pi_title_to_fetch )
+            if( priv->master->i_title == 0 || priv->master->i_title <= *pi_title_to_fetch )
             {
                 vlc_mutex_unlock( &priv->p_item->lock );
                 return VLC_EGENERIC;
             }
 
-            const input_title_t *p_title = priv->title[*pi_title_to_fetch];
+            const input_title_t *p_title = priv->master->title[*pi_title_to_fetch];
 
             /* set arg2 to the number of seekpoints we found */
             const int i_chapters = p_title->i_seekpoint;
diff --git a/src/input/input.c b/src/input/input.c
index 8e529b3274..f03584262b 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -306,8 +306,6 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     priv->i_start = 0;
     priv->i_time  = 0;
     priv->i_stop  = 0;
-    priv->i_title = 0;
-    priv->title = NULL;
     priv->i_title_offset = input_priv(p_input)->i_seekpoint_offset = 0;
     priv->i_state = INIT_S;
     priv->is_running = false;
@@ -875,11 +873,9 @@ static void InitTitle( input_thread_t * p_input )
 
     vlc_mutex_lock( &priv->p_item->lock );
     /* Create global title (from master) */
-    priv->i_title = p_master->i_title;
-    priv->title   = p_master->title;
     priv->i_title_offset = p_master->i_title_offset;
     priv->i_seekpoint_offset = p_master->i_seekpoint_offset;
-    if( priv->i_title > 0 )
+    if( p_master->i_title > 0 )
     {
         /* Setup variables */
         input_ControlVarNavigation( p_input );
@@ -1448,8 +1444,6 @@ static void End( input_thread_t * p_input )
 
     /* Clean up master */
     InputSourceDestroy( priv->master );
-    priv->i_title = 0;
-    priv->title = NULL;
     priv->i_title_offset = 0;
     priv->i_seekpoint_offset = 0;
 
@@ -2278,8 +2272,8 @@ static void UpdateTitleListfromDemux( input_thread_t *p_input )
         for( int i = 0; i < in->i_title; i++ )
             vlc_input_title_Delete( in->title[i] );
         TAB_CLEAN( in->i_title, in->title );
-        priv->i_title = 0;
-        priv->title = NULL;
+        in->i_title = 0;
+        in->title = NULL;
         in->b_title_demux = false;
     }
 
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 3606f575f1..536a8fdad6 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -113,10 +113,6 @@ typedef struct input_thread_private_t
     vlc_viewpoint_t viewpoint;
     bool            viewpoint_changed;
 
-    /* Title infos FIXME multi-input (not easy) ? */
-    int          i_title;
-    const input_title_t **title;
-
     int i_title_offset;
     int i_seekpoint_offset;
 
diff --git a/src/input/var.c b/src/input/var.c
index f41dac5e9e..b8868da51a 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -239,10 +239,10 @@ void input_ControlVarStop( input_thread_t *p_input )
     if( !input_priv(p_input)->b_preparsing )
         InputDelCallbacks( p_input, p_input_callbacks );
 
-    if( input_priv(p_input)->i_title > 1 )
+    if( input_priv(p_input)->master->i_title > 1 )
         InputDelCallbacks( p_input, p_input_title_navigation_callbacks );
 
-    for( int i = 0; i < input_priv(p_input)->i_title; i++ )
+    for( int i = 0; i < input_priv(p_input)->master->i_title; i++ )
     {
         char name[sizeof("title ") + 3 * sizeof (int)];
 
@@ -252,7 +252,7 @@ void input_ControlVarStop( input_thread_t *p_input )
 
     if( !demux_Control( p_demux, DEMUX_GET_TITLE, &i_cur_title ) )
     {
-        const input_title_t* t = input_priv(p_input)->title[ i_cur_title ];
+        const input_title_t* t = input_priv(p_input)->master->title[ i_cur_title ];
 
         if( t->i_seekpoint > 1 )
             InputDelCallbacks( p_input, p_input_seekpoint_navigation_callbacks );
@@ -268,7 +268,7 @@ void input_ControlVarNavigation( input_thread_t *p_input )
     vlc_value_t text;
 
     /* Create more command variables */
-    if( input_priv(p_input)->i_title > 1 )
+    if( input_priv(p_input)->master->i_title > 1 )
     {
         if( var_Type( p_input, "next-title" ) == 0 ) {
             var_Create( p_input, "next-title", VLC_VAR_VOID );
@@ -302,7 +302,7 @@ void input_ControlVarNavigation( input_thread_t *p_input )
     /* Create titles and chapters */
     var_Change( p_input, "title", VLC_VAR_CLEARCHOICES, NULL, NULL );
 
-    for( int i = 0; i < input_priv(p_input)->i_title; i++ )
+    for( int i = 0; i < input_priv(p_input)->master->i_title; i++ )
     {
         vlc_value_t val2, text2;
         char title[sizeof("title ") + 3 * sizeof (int)];
@@ -315,17 +315,18 @@ void input_ControlVarNavigation( input_thread_t *p_input )
                          NavigationCallback, (void *)(intptr_t)i );
 
         char psz_length[MSTRTIME_MAX_SIZE + sizeof(" []")];
-        if( input_priv(p_input)->title[i]->i_length > 0 )
+        if( input_priv(p_input)->master->title[i]->i_length > 0 )
         {
             strcpy( psz_length, " [" );
-            secstotimestr( &psz_length[2], input_priv(p_input)->title[i]->i_length / CLOCK_FREQ );
+            secstotimestr( &psz_length[2],
+                    input_priv(p_input)->master->title[i]->i_length / CLOCK_FREQ );
             strcat( psz_length, "]" );
         }
         else
             psz_length[0] = '\0';
 
-        if( input_priv(p_input)->title[i]->psz_name == NULL ||
-            *input_priv(p_input)->title[i]->psz_name == '\0' )
+        if( input_priv(p_input)->master->title[i]->psz_name == NULL ||
+            *input_priv(p_input)->master->title[i]->psz_name == '\0' )
         {
             if( asprintf( &text.psz_string, _("Title %i%s"),
                           i + input_priv(p_input)->i_title_offset, psz_length ) == -1 )
@@ -334,7 +335,7 @@ void input_ControlVarNavigation( input_thread_t *p_input )
         else
         {
             if( asprintf( &text.psz_string, "%s%s",
-                          input_priv(p_input)->title[i]->psz_name, psz_length ) == -1 )
+                          input_priv(p_input)->master->title[i]->psz_name, psz_length ) == -1 )
                 continue;
         }
 
@@ -344,12 +345,12 @@ void input_ControlVarNavigation( input_thread_t *p_input )
 
         free( text.psz_string );
 
-        for( int j = 0; j < input_priv(p_input)->title[i]->i_seekpoint; j++ )
+        for( int j = 0; j < input_priv(p_input)->master->title[i]->i_seekpoint; j++ )
         {
             val2.i_int = j;
 
-            if( input_priv(p_input)->title[i]->seekpoint[j]->psz_name == NULL ||
-                *input_priv(p_input)->title[i]->seekpoint[j]->psz_name == '\0' )
+            if( input_priv(p_input)->master->title[i]->seekpoint[j]->psz_name == NULL ||
+                *input_priv(p_input)->master->title[i]->seekpoint[j]->psz_name == '\0' )
             {
                 /* Default value */
                 if( asprintf( &text2.psz_string, _("Chapter %i"),
@@ -359,7 +360,7 @@ void input_ControlVarNavigation( input_thread_t *p_input )
             else
             {
                 text2.psz_string =
-                    strdup( input_priv(p_input)->title[i]->seekpoint[j]->psz_name );
+                    strdup( input_priv(p_input)->master->title[i]->seekpoint[j]->psz_name );
             }
 
             var_Change( p_input, title, VLC_VAR_ADDCHOICE, &val2, &text2 );
@@ -375,7 +376,7 @@ void input_ControlVarNavigation( input_thread_t *p_input )
  *****************************************************************************/
 void input_ControlVarTitle( input_thread_t *p_input, int i_title )
 {
-    const input_title_t *t = input_priv(p_input)->title[i_title];
+    const input_title_t *t = input_priv(p_input)->master->title[i_title];
     vlc_value_t text;
     int  i;
 
-- 
2.11.0



More information about the vlc-devel mailing list