[vlc-devel] [RFC PATCH 09/13] input: Move attachment to input_item_t

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Nov 6 10:22:24 CET 2020


---
 include/vlc_input_item.h   |  3 +++
 src/input/input.c          | 33 +++++++++++++--------------------
 src/input/input_internal.h |  4 ----
 src/input/item.c           |  5 +++++
 4 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 9a01a80672..3f51b00d76 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -123,6 +123,9 @@ struct input_item_t
 
     void        *libvlc_owner;       /**< LibVLC private data, can only be set
                                           before events are registered. */
+    /* Input attachment */
+    int i_attachment;
+    input_attachment_t **attachment;
 };
 
 #define INPUT_ITEM_URI_NOP "vlc://nop" /* dummy URI for node/directory items */
diff --git a/src/input/input.c b/src/input/input.c
index e6a1e4a874..47ddb5c72d 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -314,7 +314,6 @@ static input_thread_t *Create( vlc_object_t *p_parent,
     priv->b_recording = false;
     priv->rate = 1.f;
     priv->normal_time = VLC_TICK_0;
-    TAB_INIT( priv->i_attachment, priv->attachment );
     priv->p_sout   = NULL;
     priv->b_out_pace_control = priv->b_thumbnailing;
     priv->p_renderer = p_renderer && priv->b_preparsing == false ?
@@ -1116,9 +1115,9 @@ static void LoadSlaves( input_thread_t *p_input )
     input_attachment_t **pp_attachment = NULL;
 
     vlc_mutex_lock( &input_priv(p_input)->p_item->lock );
-    for( int i = 0; i < input_priv(p_input)->i_attachment; i++ )
+    for( int i = 0; i < input_priv(p_input)->p_item->i_attachment; i++ )
     {
-        const input_attachment_t *a = input_priv(p_input)->attachment[i];
+        const input_attachment_t *a = input_priv(p_input)->p_item->attachment[i];
         if( !strcmp( a->psz_mime, "application/x-srt" ) )
             TAB_APPEND( i_attachment, pp_attachment,
                         vlc_input_attachment_New( a->psz_name, NULL,
@@ -1411,12 +1410,6 @@ static void End( input_thread_t * p_input )
     }
 
     vlc_mutex_lock( &priv->p_item->lock );
-    if( priv->i_attachment > 0 )
-    {
-        for( int i = 0; i < priv->i_attachment; i++ )
-            vlc_input_attachment_Release( priv->attachment[i] );
-        TAB_CLEAN( priv->i_attachment, priv->attachment );
-    }
 
     vlc_mutex_unlock( &input_priv(p_input)->p_item->lock );
 
@@ -3032,24 +3025,24 @@ static void AppendAttachment( input_thread_t *p_input, int i_new,
                               input_attachment_t **pp_new )
 {
     input_thread_private_t *priv = input_priv( p_input );
-    int i_attachment = priv->i_attachment;
+    int i_attachment = priv->p_item->i_attachment;
     int i;
 
     if ( i_attachment + i_new == 0 )
         /* nothing to do */
         return;
 
-    input_attachment_t **pp_att = realloc( priv->attachment,
+    input_attachment_t **pp_att = realloc( priv->p_item->attachment,
                     sizeof(*pp_att) * ( i_attachment + i_new ) );
     if( likely(pp_att) )
     {
-        priv->attachment = pp_att;
+        priv->p_item->attachment = pp_att;
         for( i = 0; i < i_new; i++ )
         {
             pp_att[i_attachment++] = pp_new[i];
         }
         /* */
-        priv->i_attachment = i_attachment;
+        priv->p_item->i_attachment = i_attachment;
         free( pp_new );
         return;
     }
@@ -3086,9 +3079,9 @@ static void InputUpdateMeta( input_thread_t *p_input, demux_t *p_demux )
         for ( int i = 0; i < i_attachment; ++i )
         {
             bool is_new = true;
-            for( int j = 0; j < priv->i_attachment; ++j )
+            for( int j = 0; j < priv->p_item->i_attachment; ++j )
             {
-                if( priv->attachment[j] == attachment[i] )
+                if( priv->p_item->attachment[j] == attachment[i] )
                 {
                     vlc_input_attachment_Release( attachment[i] );
                     is_new = false;
@@ -3464,7 +3457,7 @@ int input_GetAttachments(input_thread_t *input,
     input_thread_private_t *priv = input_priv(input);
 
     vlc_mutex_lock(&priv->p_item->lock);
-    int attachments_count = priv->i_attachment;
+    int attachments_count = priv->p_item->i_attachment;
     if (attachments_count <= 0)
     {
         vlc_mutex_unlock(&priv->p_item->lock);
@@ -3477,7 +3470,7 @@ int input_GetAttachments(input_thread_t *input,
         return -1;
 
     for (int i = 0; i < attachments_count; i++)
-        (*attachments)[i] = vlc_input_attachment_Hold(priv->attachment[i]);
+        (*attachments)[i] = vlc_input_attachment_Hold(priv->p_item->attachment[i]);
 
     vlc_mutex_unlock(&priv->p_item->lock);
     return attachments_count;
@@ -3488,12 +3481,12 @@ input_attachment_t *input_GetAttachment(input_thread_t *input, const char *name)
     input_thread_private_t *priv = input_priv(input);
 
     vlc_mutex_lock(&priv->p_item->lock);
-    for (int i = 0; i < priv->i_attachment; i++)
+    for (int i = 0; i < priv->p_item->i_attachment; i++)
     {
-        if (!strcmp( priv->attachment[i]->psz_name, name))
+        if (!strcmp( priv->p_item->attachment[i]->psz_name, name))
         {
             input_attachment_t *attachment =
-                vlc_input_attachment_Hold(priv->attachment[i] );
+                vlc_input_attachment_Hold(priv->p_item->attachment[i] );
             vlc_mutex_unlock( &priv->p_item->lock );
             return attachment;
         }
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 36b2e8428b..106bacc6e3 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -505,10 +505,6 @@ typedef struct input_thread_private_t
     int i_title_offset;
     int i_seekpoint_offset;
 
-    /* Input attachment */
-    int i_attachment;
-    input_attachment_t **attachment;
-
     /* Main input properties */
 
     /* Input item */
diff --git a/src/input/item.c b/src/input/item.c
index 44db7acb0b..28498f12d7 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -491,6 +491,10 @@ void input_item_Release( input_item_t *p_item )
         input_item_slave_Delete( p_item->pp_slaves[i] );
     TAB_CLEAN( p_item->i_slaves, p_item->pp_slaves );
 
+    for( int i = 0; i < p_item->i_attachment; i++ )
+        vlc_input_attachment_Release( p_item->attachment[i] );
+    TAB_CLEAN( p_item->i_attachment, p_item->attachment );
+
     free( owner );
 }
 
@@ -1067,6 +1071,7 @@ input_item_NewExt( const char *psz_uri, const char *psz_name,
     p_input->p_stats = NULL;
     TAB_INIT( p_input->i_epg, p_input->pp_epg );
     TAB_INIT( p_input->i_slaves, p_input->pp_slaves );
+    TAB_INIT( p_input->i_attachment, p_input->attachment );
 
     vlc_event_manager_init( p_em, p_input );
 
-- 
2.28.0



More information about the vlc-devel mailing list