[vlc-commits] stream: create access in stream_AccessNew()
Rémi Denis-Courmont
git at videolan.org
Tue Aug 25 20:33:17 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 26 16:36:35 2015 +0300| [96244c3d84b93d61facb4043a9fc4b44d0f3544c] | committer: Rémi Denis-Courmont
stream: create access in stream_AccessNew()
This simplifies the code a little, and removes the need for the
stream_CommonDelete() hack due to inverted stream/access parentage.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=96244c3d84b93d61facb4043a9fc4b44d0f3544c
---
src/input/access.c | 98 +++++++++++++++++++--------------------------
src/input/access.h | 5 +--
src/input/input.c | 25 +++++-------
src/input/stream.c | 10 ++---
src/input/stream.h | 4 +-
src/input/stream_access.c | 31 +++++++-------
6 files changed, 74 insertions(+), 99 deletions(-)
diff --git a/src/input/access.c b/src/input/access.c
index cd5e960..e6774e3 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -28,7 +28,6 @@
#include <assert.h>
#include "access.h"
-#include "input_internal.h"
#include <libvlc.h>
#include <vlc_url.h>
#include <vlc_modules.h>
@@ -49,72 +48,59 @@ char *get_path(const char *location)
return path;
}
-#undef access_New
/*****************************************************************************
* access_New:
*****************************************************************************/
-access_t *access_New( vlc_object_t *p_obj, input_thread_t *p_parent_input,
- const char *psz_access, const char *psz_location )
+access_t *access_New(vlc_object_t *parent, input_thread_t *input,
+ const char *mrl)
{
- access_t *p_access = vlc_custom_create( p_obj, sizeof (*p_access),
- "access" );
-
- if( p_access == NULL )
+ const char *p = strstr(mrl, "://");
+ if (p == NULL)
return NULL;
- /* */
-
- p_access->p_input = p_parent_input;
-
- p_access->psz_access = strdup( psz_access );
- p_access->psz_location = strdup( psz_location );
- p_access->psz_filepath = get_path( psz_location );
- if( p_access->psz_access == NULL || p_access->psz_location == NULL )
- goto error;
-
- msg_Dbg( p_obj, "creating access '%s' location='%s', path='%s'",
- psz_access, psz_location,
- p_access->psz_filepath ? p_access->psz_filepath : "(null)" );
-
- p_access->pf_read = NULL;
- p_access->pf_block = NULL;
- p_access->pf_readdir = NULL;
- p_access->pf_seek = NULL;
- p_access->pf_control = NULL;
- p_access->p_sys = NULL;
-
- access_InitFields( p_access );
-
- p_access->p_module = module_need( p_access, "access", psz_access, true );
- if( p_access->p_module == NULL )
- goto error;
-
- assert( p_access->pf_control != NULL );
+ access_t *access = vlc_custom_create(parent, sizeof (*access), "access");
+ char *scheme = strndup(mrl, p - mrl);
+ char *location = strdup(p + 3);
- return p_access;
-
-error:
- free( p_access->psz_access );
- free( p_access->psz_location );
- free( p_access->psz_filepath );
- vlc_object_release( p_access );
- return NULL;
+ if (unlikely(access == NULL || scheme == NULL || location == NULL))
+ {
+ free(location);
+ free(scheme);
+ vlc_object_release(access);
+ return NULL;
+ }
+
+ access->p_input = input;
+ access->psz_access = scheme;
+ access->psz_location = location;
+ access->psz_filepath = get_path(location);
+ access->pf_read = NULL;
+ access->pf_block = NULL;
+ access->pf_readdir = NULL;
+ access->pf_seek = NULL;
+ access->pf_control = NULL;
+ access->p_sys = NULL;
+ access_InitFields(access);
+
+ msg_Dbg(access, "creating access '%s' location='%s', path='%s'", scheme,
+ location, access->psz_filepath ? access->psz_filepath : "(null)");
+
+ access->p_module = module_need(access, "access", scheme, true);
+ if (access->p_module == NULL)
+ {
+ free(access->psz_filepath);
+ free(access->psz_location);
+ free(access->psz_access);
+ vlc_object_release(access);
+ access = NULL;
+ }
+ assert(access == NULL || access->pf_control != NULL);
+ return access;
}
access_t *vlc_access_NewMRL(vlc_object_t *parent, const char *mrl)
{
- char *buf = strdup(mrl);
- if (unlikely(buf == NULL))
- return NULL;
-
- const char *access, *demux, *location, *anchor;
- input_SplitMRL(&access, &demux, &location, &anchor, buf);
-
- /* Both demux and anchor are ignored, since they are of no use here. */
- access_t *obj = access_New(parent, NULL, access, location);
-
- free(buf);
- return obj;
+ return access_New(parent, NULL, mrl);
}
void vlc_access_Delete(access_t *access)
diff --git a/src/input/access.h b/src/input/access.h
index 88b8951..5f069c3 100644
--- a/src/input/access.h
+++ b/src/input/access.h
@@ -28,10 +28,7 @@
#include <vlc_common.h>
#include <vlc_access.h>
-access_t *access_New( vlc_object_t *p_obj, input_thread_t *p_input,
- const char *psz_access, const char *psz_path );
-#define access_New( a, b, c, d ) access_New(VLC_OBJECT(a), b, c, d )
-
+access_t *access_New(vlc_object_t *, input_thread_t *, const char *);
char *get_path(const char *location);
#endif
diff --git a/src/input/input.c b/src/input/input.c
index 9731ab3..a227b57 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -2284,10 +2284,16 @@ static int InputSourceInit( input_thread_t *p_input,
TAB_CLEAN( count, tab );
}
- /* */
- access_t *p_access = access_New( p_input, p_input,
- psz_access, psz_path );
- if( p_access == NULL )
+ /* Create the stream_t */
+ stream_t *p_stream = NULL;
+ char *url;
+
+ if( likely(asprintf( &url, "%s://%s", psz_access, psz_path) >= 0) )
+ {
+ p_stream = stream_AccessNew( VLC_OBJECT(p_input), p_input, url );
+ free( url );
+ }
+ if( p_stream == NULL )
{
msg_Err( p_input, "open of `%s' failed", psz_mrl );
if( !b_in_can_fail && !input_Stopped( p_input ) )
@@ -2297,17 +2303,6 @@ static int InputSourceInit( input_thread_t *p_input,
goto error;
}
- /* Access-forced demuxer (PARENTAL ADVISORY: EXPLICIT HACK) */
-#warning FIXME: parse content type
-
- /* Create the stream_t */
- stream_t *p_stream = stream_AccessNew( p_access );
- if( p_stream == NULL )
- {
- msg_Warn( p_input, "cannot create a stream_t from access" );
- goto error;
- }
-
/* Add stream filters */
p_stream = stream_FilterAutoNew( p_stream );
diff --git a/src/input/stream.c b/src/input/stream.c
index de32be3..a9d5ac2 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -101,14 +101,10 @@ stream_t *stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
if( !psz_url )
return NULL;
- access_t *p_access = vlc_access_NewMRL( p_parent, psz_url );
- if( p_access == NULL )
- {
+ stream_t *s = stream_AccessNew( p_parent, NULL, psz_url );
+ if( s == NULL )
msg_Err( p_parent, "no suitable access module for `%s'", psz_url );
- return NULL;
- }
-
- return stream_AccessNew( p_access );
+ return s;
}
/**
diff --git a/src/input/stream.h b/src/input/stream.h
index 6602186..6588337 100644
--- a/src/input/stream.h
+++ b/src/input/stream.h
@@ -33,9 +33,9 @@ stream_t *stream_CommonNew( vlc_object_t * );
void stream_CommonDelete( stream_t * );
/**
- * This function creates a stream_t from a provided access_t.
+ * This function creates a stream_t with an access_t back-end.
*/
-stream_t *stream_AccessNew( access_t *p_access );
+stream_t *stream_AccessNew(vlc_object_t *, input_thread_t *, const char *);
/**
* This function creates a new stream_t filter.
diff --git a/src/input/stream_access.c b/src/input/stream_access.c
index 4679d60..4cba97b 100644
--- a/src/input/stream_access.c
+++ b/src/input/stream_access.c
@@ -33,6 +33,7 @@
#include <vlc_interrupt.h>
#include <libvlc.h>
+#include "access.h"
#include "stream.h"
#include "input_internal.h"
@@ -236,32 +237,28 @@ static void AStreamDestroy(stream_t *s)
free(sys);
}
-stream_t *stream_AccessNew(access_t *access)
+stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input,
+ const char *url)
{
- stream_t *s = stream_CommonNew(VLC_OBJECT(access));
+ stream_t *s = stream_CommonNew(parent);
if (unlikely(s == NULL))
return NULL;
- s->p_input = access->p_input;
- if (asprintf(&s->psz_url, "%s://%s", access->psz_access,
- access->psz_location) == -1)
- s->psz_url = NULL;
+ s->p_input = input;
+ s->psz_url = strdup(url);
stream_sys_t *sys = malloc(sizeof (*sys));
-
if (unlikely(s->psz_url == NULL || sys == NULL))
- {
- free(sys);
- stream_CommonDelete(s);
- vlc_access_Delete(access);
- return NULL;
- }
+ goto error;
+
+ sys->access = access_New(VLC_OBJECT(s), input, url);
+ if (sys->access == NULL)
+ goto error;
- sys->access = access;
sys->block = NULL;
s->p_sys = sys;
- if (access->pf_block != NULL)
+ if (sys->access->pf_block != NULL)
s->pf_read = AStreamReadBlock;
else
s->pf_read = AStreamReadStream;
@@ -270,4 +267,8 @@ stream_t *stream_AccessNew(access_t *access)
s->pf_destroy = AStreamDestroy;
return s;
+error:
+ free(sys);
+ stream_CommonDelete(s);
+ return NULL;
}
More information about the vlc-commits
mailing list