Commit 96244c3d authored by Rémi Denis-Courmont's avatar 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.
parent 3a3f44fd
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <assert.h> #include <assert.h>
#include "access.h" #include "access.h"
#include "input_internal.h"
#include <libvlc.h> #include <libvlc.h>
#include <vlc_url.h> #include <vlc_url.h>
#include <vlc_modules.h> #include <vlc_modules.h>
...@@ -49,72 +48,59 @@ char *get_path(const char *location) ...@@ -49,72 +48,59 @@ char *get_path(const char *location)
return path; return path;
} }
#undef access_New
/***************************************************************************** /*****************************************************************************
* access_New: * access_New:
*****************************************************************************/ *****************************************************************************/
access_t *access_New( vlc_object_t *p_obj, input_thread_t *p_parent_input, access_t *access_New(vlc_object_t *parent, input_thread_t *input,
const char *psz_access, const char *psz_location ) const char *mrl)
{ {
access_t *p_access = vlc_custom_create( p_obj, sizeof (*p_access), const char *p = strstr(mrl, "://");
"access" ); if (p == NULL)
if( p_access == NULL )
return NULL; return NULL;
/* */ access_t *access = vlc_custom_create(parent, sizeof (*access), "access");
char *scheme = strndup(mrl, p - mrl);
p_access->p_input = p_parent_input; char *location = strdup(p + 3);
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 );
return p_access; if (unlikely(access == NULL || scheme == NULL || location == NULL))
{
error: free(location);
free( p_access->psz_access ); free(scheme);
free( p_access->psz_location ); vlc_object_release(access);
free( p_access->psz_filepath ); return NULL;
vlc_object_release( p_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) access_t *vlc_access_NewMRL(vlc_object_t *parent, const char *mrl)
{ {
char *buf = strdup(mrl); return access_New(parent, NULL, 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;
} }
void vlc_access_Delete(access_t *access) void vlc_access_Delete(access_t *access)
......
...@@ -28,10 +28,7 @@ ...@@ -28,10 +28,7 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_access.h> #include <vlc_access.h>
access_t *access_New( vlc_object_t *p_obj, input_thread_t *p_input, access_t *access_New(vlc_object_t *, input_thread_t *, const char *);
const char *psz_access, const char *psz_path );
#define access_New( a, b, c, d ) access_New(VLC_OBJECT(a), b, c, d )
char *get_path(const char *location); char *get_path(const char *location);
#endif #endif
......
...@@ -2284,10 +2284,16 @@ static int InputSourceInit( input_thread_t *p_input, ...@@ -2284,10 +2284,16 @@ static int InputSourceInit( input_thread_t *p_input,
TAB_CLEAN( count, tab ); TAB_CLEAN( count, tab );
} }
/* */ /* Create the stream_t */
access_t *p_access = access_New( p_input, p_input, stream_t *p_stream = NULL;
psz_access, psz_path ); char *url;
if( p_access == NULL )
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 ); msg_Err( p_input, "open of `%s' failed", psz_mrl );
if( !b_in_can_fail && !input_Stopped( p_input ) ) if( !b_in_can_fail && !input_Stopped( p_input ) )
...@@ -2297,17 +2303,6 @@ static int InputSourceInit( input_thread_t *p_input, ...@@ -2297,17 +2303,6 @@ static int InputSourceInit( input_thread_t *p_input,
goto error; 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 */ /* Add stream filters */
p_stream = stream_FilterAutoNew( p_stream ); p_stream = stream_FilterAutoNew( p_stream );
......
...@@ -101,14 +101,10 @@ stream_t *stream_UrlNew( vlc_object_t *p_parent, const char *psz_url ) ...@@ -101,14 +101,10 @@ stream_t *stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
if( !psz_url ) if( !psz_url )
return NULL; return NULL;
access_t *p_access = vlc_access_NewMRL( p_parent, psz_url ); stream_t *s = stream_AccessNew( p_parent, NULL, psz_url );
if( p_access == NULL ) if( s == NULL )
{
msg_Err( p_parent, "no suitable access module for `%s'", psz_url ); msg_Err( p_parent, "no suitable access module for `%s'", psz_url );
return NULL; return s;
}
return stream_AccessNew( p_access );
} }
/** /**
......
...@@ -33,9 +33,9 @@ stream_t *stream_CommonNew( vlc_object_t * ); ...@@ -33,9 +33,9 @@ stream_t *stream_CommonNew( vlc_object_t * );
void stream_CommonDelete( stream_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. * This function creates a new stream_t filter.
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <vlc_interrupt.h> #include <vlc_interrupt.h>
#include <libvlc.h> #include <libvlc.h>
#include "access.h"
#include "stream.h" #include "stream.h"
#include "input_internal.h" #include "input_internal.h"
...@@ -236,32 +237,28 @@ static void AStreamDestroy(stream_t *s) ...@@ -236,32 +237,28 @@ static void AStreamDestroy(stream_t *s)
free(sys); 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)) if (unlikely(s == NULL))
return NULL; return NULL;
s->p_input = access->p_input; s->p_input = input;
if (asprintf(&s->psz_url, "%s://%s", access->psz_access, s->psz_url = strdup(url);
access->psz_location) == -1)
s->psz_url = NULL;
stream_sys_t *sys = malloc(sizeof (*sys)); stream_sys_t *sys = malloc(sizeof (*sys));
if (unlikely(s->psz_url == NULL || sys == NULL)) if (unlikely(s->psz_url == NULL || sys == NULL))
{ goto error;
free(sys);
stream_CommonDelete(s); sys->access = access_New(VLC_OBJECT(s), input, url);
vlc_access_Delete(access); if (sys->access == NULL)
return NULL; goto error;
}
sys->access = access;
sys->block = NULL; sys->block = NULL;
s->p_sys = sys; s->p_sys = sys;
if (access->pf_block != NULL) if (sys->access->pf_block != NULL)
s->pf_read = AStreamReadBlock; s->pf_read = AStreamReadBlock;
else else
s->pf_read = AStreamReadStream; s->pf_read = AStreamReadStream;
...@@ -270,4 +267,8 @@ stream_t *stream_AccessNew(access_t *access) ...@@ -270,4 +267,8 @@ stream_t *stream_AccessNew(access_t *access)
s->pf_destroy = AStreamDestroy; s->pf_destroy = AStreamDestroy;
return s; return s;
error:
free(sys);
stream_CommonDelete(s);
return NULL;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment