[vlc-devel] [V2 11/16] input: Manage attachment through the item

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Nov 13 11:27:27 CET 2020


---
 include/vlc_input_item.h            |  4 +++
 src/input/access.c                  |  3 +-
 src/input/es_out.c                  |  4 +--
 src/input/input.c                   | 47 -----------------------------
 src/input/input_internal.h          |  4 ---
 src/input/item.c                    | 43 ++++++++++++++++++++++++++
 src/input/meta.c                    |  2 +-
 src/video_output/vout_subpictures.c |  3 +-
 8 files changed, 54 insertions(+), 56 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 3f51b00d76..b48d9a1755 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -338,6 +338,9 @@ VLC_API int input_item_DelInfo( input_item_t *p_i, const char *psz_cat, const ch
 VLC_API void input_item_ReplaceInfos( input_item_t *, info_category_t * );
 VLC_API void input_item_MergeInfos( input_item_t *, info_category_t * );
 
+int input_item_GetAttachments(input_item_t *item, input_attachment_t ***attachments);
+input_attachment_t *input_item_GetAttachment(input_item_t *item, const char *name);
+
 /**
  * This function creates a new input_item_t with the provided information.
  *
@@ -591,4 +594,5 @@ VLC_API int vlc_readdir_helper_additem(struct vlc_readdir_helper *p_rdh,
                                        const char *psz_filename,
                                        int i_type, int i_net);
 
+
 #endif
diff --git a/src/input/access.c b/src/input/access.c
index b5a5ae010d..6db7f337da 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -80,7 +80,8 @@ static stream_t *accessNewAttachment(vlc_object_t *parent,
     if (!input)
         return NULL;
 
-    input_attachment_t *attachment = input_GetAttachment(input, mrl + 13);
+    input_thread_private_t *priv = input_priv(input);
+    input_attachment_t *attachment = input_item_GetAttachment(priv->p_item, mrl + 13);
     if (!attachment)
         return NULL;
     stream_t *stream = vlc_stream_AttachmentNew(parent, attachment);
diff --git a/src/input/es_out.c b/src/input/es_out.c
index ab3134ab9f..deb81a9b06 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -410,8 +410,8 @@ decoder_get_attachments(vlc_input_decoder_t *decoder,
 
     if (!p_sys->p_input)
         return -1;
-
-    return input_GetAttachments(p_sys->p_input, ppp_attachment);
+    input_thread_private_t *priv = input_priv(p_sys->p_input);
+    return input_item_GetAttachments(priv->p_item, ppp_attachment);
 }
 
 static const struct vlc_input_decoder_callbacks decoder_cbs = {
diff --git a/src/input/input.c b/src/input/input.c
index df315cf010..0160879c39 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -3450,50 +3450,3 @@ static char *input_SubtitleFile2Uri( input_thread_t *p_input,
     free( psz_idxpath );
     return psz_uri;
 }
-
-int input_GetAttachments(input_thread_t *input,
-                         input_attachment_t ***attachments)
-{
-    input_thread_private_t *priv = input_priv(input);
-
-    vlc_mutex_lock(&priv->p_item->lock);
-    int attachments_count = priv->p_item->i_attachment;
-    if (attachments_count <= 0)
-    {
-        vlc_mutex_unlock(&priv->p_item->lock);
-        *attachments = NULL;
-        return 0;
-    }
-
-    *attachments = vlc_alloc(attachments_count, sizeof(input_attachment_t*));
-    if (!*attachments)
-    {
-        vlc_mutex_unlock(&priv->p_item->lock);
-        return -1;
-    }
-
-    for (int i = 0; i < attachments_count; i++)
-        (*attachments)[i] = vlc_input_attachment_Hold(priv->p_item->attachment[i]);
-
-    vlc_mutex_unlock(&priv->p_item->lock);
-    return attachments_count;
-}
-
-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->p_item->i_attachment; i++)
-    {
-        if (!strcmp( priv->p_item->attachment[i]->psz_name, name))
-        {
-            input_attachment_t *attachment =
-                vlc_input_attachment_Hold(priv->p_item->attachment[i] );
-            vlc_mutex_unlock( &priv->p_item->lock );
-            return attachment;
-        }
-    }
-    vlc_mutex_unlock( &priv->p_item->lock );
-    return NULL;
-}
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 106bacc6e3..005194df65 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -640,10 +640,6 @@ void input_SetEsCatIds(input_thread_t *, enum es_format_category_e cat,
 
 bool input_Stopped( input_thread_t * );
 
-int input_GetAttachments(input_thread_t *input, input_attachment_t ***attachments);
-
-input_attachment_t *input_GetAttachment(input_thread_t *input, const char *name);
-
 /**
  * Hold the input_source_t
  */
diff --git a/src/input/item.c b/src/input/item.c
index 28498f12d7..1ffcd11589 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -1903,3 +1903,46 @@ int vlc_readdir_helper_additem(struct vlc_readdir_helper *p_rdh,
         p_rdh_slave->p_node = p_node;
     return VLC_SUCCESS;
 }
+
+int input_item_GetAttachments(input_item_t *item,
+                              input_attachment_t ***attachments)
+{
+    vlc_mutex_lock(&item->lock);
+    int attachments_count = item->i_attachment;
+    if (attachments_count <= 0)
+    {
+        vlc_mutex_unlock(&item->lock);
+        *attachments = NULL;
+        return 0;
+    }
+
+    *attachments = vlc_alloc(attachments_count, sizeof(input_attachment_t*));
+    if (!*attachments)
+    {
+        vlc_mutex_unlock(&item->lock);
+        return -1;
+    }
+
+    for (int i = 0; i < attachments_count; i++)
+        (*attachments)[i] = vlc_input_attachment_Hold(item->attachment[i]);
+
+    vlc_mutex_unlock(&item->lock);
+    return attachments_count;
+}
+
+input_attachment_t *input_item_GetAttachment(input_item_t *item, const char *name)
+{
+    vlc_mutex_lock(&item->lock);
+    for (int i = 0; i < item->i_attachment; i++)
+    {
+        if (!strcmp( item->attachment[i]->psz_name, name))
+        {
+            input_attachment_t *attachment =
+                vlc_input_attachment_Hold(item->attachment[i] );
+            vlc_mutex_unlock( &item->lock );
+            return attachment;
+        }
+    }
+    vlc_mutex_unlock( &item->lock );
+    return NULL;
+}
diff --git a/src/input/meta.c b/src/input/meta.c
index 9ef43cad83..c27ea11502 100644
--- a/src/input/meta.c
+++ b/src/input/meta.c
@@ -215,7 +215,7 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input,
     }
 
     /* */
-    input_attachment_t *p_attachment = input_GetAttachment( p_input, name );
+    input_attachment_t *p_attachment = input_item_GetAttachment( p_item, name );
     if( !p_attachment )
     {
         msg_Warn( p_input, "art attachment %s not found", name );
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index f60c6f5797..484017c1ae 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -240,7 +240,8 @@ static int spu_get_attachments(filter_t *filter,
 
     if (spu->p->input)
     {
-        int count = input_GetAttachments(spu->p->input, attachment_ptr);
+        int count = input_item_GetAttachments(input_priv(spu->p->input)->p_item,
+                                              attachment_ptr);
         if (count <= 0)
             return VLC_EGENERIC;
         *attachment_count = count;
-- 
2.29.2



More information about the vlc-devel mailing list