[vlc-devel] [PATCH] core: access: change attachment handling

Thomas Guillem thomas at gllm.fr
Wed Jul 18 14:24:53 CEST 2018


And remove one more reference to the input_thread_t from accesses.
---
 include/vlc_stream.h        |  9 +++++++++
 modules/access/attachment.c | 32 +++++---------------------------
 src/input/access.c          | 10 ++++++++++
 3 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index ff894280a0..007c8232e6 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -54,6 +54,15 @@ struct stream_t
     bool         b_preparsing; /**< True if this access is used to preparse */
 
     union {
+        /**
+         * Input attachement
+         *
+         * Depending on the module capability:
+         * - "stream filter" or "demux": a NULL pointer
+         * - "access": a valid pointer or NULL
+         * - "demux_filter": undefined
+         */
+        input_attachment_t *attachment;
         /**
          * Input stream
          *
diff --git a/modules/access/attachment.c b/modules/access/attachment.c
index cb63bb3aa5..8a57c6c40f 100644
--- a/modules/access/attachment.c
+++ b/modules/access/attachment.c
@@ -38,7 +38,6 @@
  * Module descriptor
  *****************************************************************************/
 static int  Open (vlc_object_t *);
-static void Close(vlc_object_t *);
 
 vlc_module_begin()
     set_shortname(N_("Attachment"))
@@ -48,7 +47,7 @@ vlc_module_begin()
 
     set_capability("access", 0)
     add_shortcut("attachment")
-    set_callbacks(Open, Close)
+    set_callbacks(Open, NULL)
 vlc_module_end()
 
 /*****************************************************************************
@@ -60,7 +59,6 @@ static int     Control(stream_t *, int, va_list);
 
 typedef struct
 {
-    input_attachment_t *attachment;
     size_t offset;
 } access_sys_t;
 
@@ -69,24 +67,13 @@ static int Open(vlc_object_t *object)
 {
     stream_t     *access = (stream_t *)object;
 
-    input_thread_t *input = access->p_input;
-    if (!input)
+    if (access->attachment == NULL)
         return VLC_EGENERIC;
 
     access_sys_t *sys = vlc_obj_malloc(object, sizeof (*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
 
-    if (input_Control(input, INPUT_GET_ATTACHMENT, &sys->attachment,
-                      access->psz_location))
-        sys->attachment = NULL;
-
-    if (sys->attachment == NULL) {
-        msg_Err(access, "Failed to find the attachment '%s'",
-                access->psz_location);
-        return VLC_EGENERIC;
-    }
-
     sys->offset = 0;
 
     /* */
@@ -98,20 +85,11 @@ static int Open(vlc_object_t *object)
     return VLC_SUCCESS;
 }
 
-/* */
-static void Close(vlc_object_t *object)
-{
-    stream_t     *access = (stream_t *)object;
-    access_sys_t *sys = access->p_sys;
-
-    vlc_input_attachment_Delete(sys->attachment);
-}
-
 /* */
 static ssize_t Read(stream_t *access, void *buffer, size_t size)
 {
     access_sys_t *sys = access->p_sys;
-    input_attachment_t *a = sys->attachment;
+    input_attachment_t *a = access->attachment;
 
     if (sys->offset >= (uint64_t)a->i_data)
         return 0;
@@ -126,7 +104,7 @@ static ssize_t Read(stream_t *access, void *buffer, size_t size)
 static int Seek(stream_t *access, uint64_t position)
 {
     access_sys_t *sys = access->p_sys;
-    input_attachment_t *a = sys->attachment;
+    input_attachment_t *a = access->attachment;
 
     if (position > a->i_data)
         position = a->i_data;
@@ -149,7 +127,7 @@ static int Control(stream_t *access, int query, va_list args)
         *va_arg(args, bool *) = true;
         break;
     case STREAM_GET_SIZE:
-        *va_arg(args, uint64_t *) = sys->attachment->i_data;
+        *va_arg(args, uint64_t *) = access->attachment->i_data;
         break;
     case STREAM_GET_PTS_DELAY:
         *va_arg(args, vlc_tick_t *) = DEFAULT_PTS_DELAY;
diff --git a/src/input/access.c b/src/input/access.c
index 732837e28b..e0ff90a273 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -66,6 +66,8 @@ static void vlc_access_Destroy(stream_t *access)
     module_unneed(access, priv->module);
     free(access->psz_filepath);
     free(access->psz_name);
+    if (access->attachment)
+        vlc_input_attachment_Delete(access->attachment);
 }
 
 #define MAX_REDIR 5
@@ -114,6 +116,11 @@ static stream_t *access_New(vlc_object_t *parent, input_thread_t *input,
         if (access->psz_filepath != NULL)
             msg_Dbg(access, " (path: %s)", access->psz_filepath);
 
+        if (strcmp(access->psz_name, "attachment") != 0 || input == NULL
+         || input_Control(input, INPUT_GET_ATTACHMENT, &access->attachment,
+                          access->psz_location) != VLC_SUCCESS)
+            access->attachment = NULL;
+
         priv->module = module_need(access, "access", access->psz_name, true);
         if (priv->module != NULL) /* success */
         {
@@ -124,6 +131,9 @@ static stream_t *access_New(vlc_object_t *parent, input_thread_t *input,
             return access;
         }
 
+        if (access->attachment)
+            vlc_input_attachment_Delete(access->attachment);
+
         if (access->psz_url == url) /* failure (no redirection) */
             goto error;
 
-- 
2.18.0



More information about the vlc-devel mailing list