added a stream_UrlNew to open a general purpos stream_t from a url.

added a pf_destroy to stream_t, changed all various stream_FooDestroy to
stream_Delete
parent 5af605ef
......@@ -65,6 +65,7 @@ struct stream_t
int (*pf_read) ( stream_t *, void *p_read, int i_read );
int (*pf_peek) ( stream_t *, uint8_t **pp_peek, int i_peek );
int (*pf_control)( stream_t *, int i_query, va_list );
void (*pf_destroy)( stream_t *);
stream_sys_t *p_sys;
};
......@@ -104,6 +105,15 @@ static inline int stream_vaControl( stream_t *s, int i_query, va_list args )
{
return s->pf_control( s, i_query, args );
}
/**
* Destroy a stream
*/
static inline void stream_Delete( stream_t *s )
{
s->pf_destroy( s );
}
static inline int stream_Control( stream_t *s, int i_query, ... )
{
va_list args;
......@@ -114,12 +124,20 @@ static inline int stream_Control( stream_t *s, int i_query, ... )
va_end( args );
return i_result;
}
/**
* Get the current position in a stream
*/
static inline int64_t stream_Tell( stream_t *s )
{
int64_t i_pos;
stream_Control( s, STREAM_GET_POSITION, &i_pos );
return i_pos;
}
/**
* Get the size of the stream.
*/
static inline int64_t stream_Size( stream_t *s )
{
int64_t i_pos;
......@@ -176,9 +194,13 @@ VLC_EXPORT( char *, stream_ReadLine, ( stream_t * ) );
VLC_EXPORT( stream_t *,__stream_DemuxNew, ( vlc_object_t *p_obj, char *psz_demux, es_out_t *out ) );
VLC_EXPORT( void, stream_DemuxSend, ( stream_t *s, block_t *p_block ) );
VLC_EXPORT( void, stream_DemuxDelete,( stream_t *s ) );
#define stream_MemoryNew( a, b, c ) __stream_MemoryNew( VLC_OBJECT(a), b, c )
VLC_EXPORT( stream_t *,__stream_MemoryNew, (vlc_object_t *p_obj, uint8_t *p_buffer, int64_t i_size ) );
VLC_EXPORT( void, stream_MemoryDelete,( stream_t *s, vlc_bool_t b_free_buffer ) );
#define stream_MemoryNew( a, b, c, d ) __stream_MemoryNew( VLC_OBJECT(a), b, c, d )
VLC_EXPORT( stream_t *,__stream_MemoryNew, (vlc_object_t *p_obj, uint8_t *p_buffer, int64_t i_size, vlc_bool_t i_preserve_memory ) );
#define stream_UrlNew( a, b ) __stream_UrlNew( VLC_OBJECT(a), b )
VLC_EXPORT( stream_t *,__stream_UrlNew, (vlc_object_t *p_this, char *psz_url ) );
/**
* @}
*/
......
......@@ -1334,7 +1334,8 @@ bool matroska_segment_t::Select( mtime_t i_start_time )
MP4_Box_t *p_box = (MP4_Box_t*)malloc( sizeof( MP4_Box_t ) );
stream_t *p_mp4_stream = stream_MemoryNew( VLC_OBJECT(&sys.demuxer),
tk->p_extra_data,
tk->i_extra_data );
tk->i_extra_data,
VLC_FALSE );
MP4_ReadBoxCommon( p_mp4_stream, p_box );
MP4_ReadBox_sample_vide( p_mp4_stream, p_box );
tk->fmt.i_codec = p_box->i_type;
......@@ -1344,7 +1345,7 @@ bool matroska_segment_t::Select( mtime_t i_start_time )
tk->fmt.p_extra = malloc( tk->fmt.i_extra );
memcpy( tk->fmt.p_extra, p_box->data.p_sample_vide->p_qt_image_description, tk->fmt.i_extra );
MP4_FreeBox_sample_vide( p_box );
stream_MemoryDelete( p_mp4_stream, VLC_TRUE );
stream_Delete( p_mp4_stream );
}
else if( !strcmp( tk->psz_codec, "A_MS/ACM" ) )
{
......
......@@ -1852,12 +1852,12 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
/* now create a memory stream */
p_stream_memory =
stream_MemoryNew( VLC_OBJECT(p_stream), p_cmvd->data.p_cmvd->p_data,
p_cmvd->data.p_cmvd->i_uncompressed_size );
p_cmvd->data.p_cmvd->i_uncompressed_size, VLC_TRUE );
/* and read uncompressd moov */
p_box->data.p_cmov->p_moov = MP4_ReadBox( p_stream_memory, NULL );
stream_MemoryDelete( p_stream_memory, VLC_FALSE );
stream_Delete( p_stream_memory );
#ifdef MP4_VERBOSE
msg_Dbg( p_stream, "read box: \"cmov\" compressed movie header completed");
......
......@@ -62,7 +62,6 @@ static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );
static void ParseOption( input_thread_t *p_input, const char *psz_option );
static void DecodeUrl( char * );
static void MRLSplit( input_thread_t *, char *, char **, char **, char ** );
static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
static input_source_t *InputSourceNew( input_thread_t *);
......@@ -2114,7 +2113,7 @@ error:
demux2_Delete( in->p_demux );
if( in->p_stream )
stream_AccessDelete( in->p_stream );
stream_Delete( in->p_stream );
if( in->p_access )
access2_Delete( in->p_access );
......@@ -2132,7 +2131,7 @@ static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
demux2_Delete( in->p_demux );
if( in->p_stream )
stream_AccessDelete( in->p_stream );
stream_Delete( in->p_stream );
if( in->p_access )
access2_Delete( in->p_access );
......@@ -2393,8 +2392,8 @@ static void ParseOption( input_thread_t *p_input, const char *psz_option )
* MRLSplit: parse the access, demux and url part of the
* Media Resource Locator.
*****************************************************************************/
static void MRLSplit( input_thread_t *p_input, char *psz_dup,
char **ppsz_access, char **ppsz_demux, char **ppsz_path )
void MRLSplit( vlc_object_t *p_input, char *psz_dup,
char **ppsz_access, char **ppsz_demux, char **ppsz_path )
{
char *psz_access = NULL;
char *psz_demux = NULL;
......
......@@ -152,5 +152,6 @@ mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t );
/* Subtitles */
char **subtitles_Detect( input_thread_t *, char* path, char *fname );
void MRLSplit( vlc_object_t *, char *, char **, char **, char ** );
#endif
......@@ -29,21 +29,29 @@
struct stream_sys_t
{
vlc_bool_t i_preserve_memory;
int64_t i_pos; /* Current reading offset */
int64_t i_size;
uint8_t *p_buffer;
};
static int AStreamReadMem( stream_t *, void *p_read, int i_read );
static int AStreamPeekMem( stream_t *, uint8_t **pp_peek, int i_read );
static int AStreamControl( stream_t *, int i_query, va_list );
static int Read ( stream_t *, void *p_read, int i_read );
static int Peek ( stream_t *, uint8_t **pp_peek, int i_read );
static int Control( stream_t *, int i_query, va_list );
static void Delete ( stream_t * );
/****************************************************************************
* stream_MemoryNew: create a stream from a buffer
****************************************************************************/
/**
* Create a stream from a memory buffer
*
* \param p_this the calling vlc_object
* \param p_buffer the memory buffer for the stream
* \param i_buffer the size of the buffer
* \param i_preserve_memory if this is set to VLC_FALSE the memory buffer
* pointed to by p_buffer is freed on stream_Destroy
*/
stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
int64_t i_size )
int64_t i_size, vlc_bool_t i_preserve_memory )
{
stream_t *s = vlc_object_create( p_this, VLC_OBJECT_STREAM );
stream_sys_t *p_sys;
......@@ -54,19 +62,21 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
p_sys->i_pos = 0;
p_sys->i_size = i_size;
p_sys->p_buffer = p_buffer;
p_sys->i_preserve_memory = i_preserve_memory;
s->pf_block = NULL;
s->pf_read = AStreamReadMem; /* Set up later */
s->pf_peek = AStreamPeekMem;
s->pf_control = AStreamControl;
s->pf_read = Read;
s->pf_peek = Peek;
s->pf_control = Control;
s->pf_destroy = Delete;
vlc_object_attach( s, p_this );
return s;
}
void stream_MemoryDelete( stream_t *s, vlc_bool_t b_free_buffer )
static void Delete( stream_t *s )
{
if( b_free_buffer ) free( s->p_sys->p_buffer );
if( !s->p_sys->i_preserve_memory ) free( s->p_sys->p_buffer );
free( s->p_sys );
vlc_object_detach( s );
vlc_object_destroy( s );
......@@ -75,7 +85,7 @@ void stream_MemoryDelete( stream_t *s, vlc_bool_t b_free_buffer )
/****************************************************************************
* AStreamControl:
****************************************************************************/
static int AStreamControl( stream_t *s, int i_query, va_list args )
static int Control( stream_t *s, int i_query, va_list args )
{
stream_sys_t *p_sys = s->p_sys;
......@@ -128,7 +138,7 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
return VLC_SUCCESS;
}
static int AStreamReadMem( stream_t *s, void *p_read, int i_read )
static int Read( stream_t *s, void *p_read, int i_read )
{
stream_sys_t *p_sys = s->p_sys;
int i_res = __MIN( i_read, p_sys->i_size - p_sys->i_pos );
......@@ -137,7 +147,7 @@ static int AStreamReadMem( stream_t *s, void *p_read, int i_read )
return i_res;
}
static int AStreamPeekMem( stream_t *s, uint8_t **pp_peek, int i_read )
static int Peek( stream_t *s, uint8_t **pp_peek, int i_read )
{
stream_sys_t *p_sys = s->p_sys;
int i_res = __MIN( i_read, p_sys->i_size - p_sys->i_pos );
......
......@@ -180,12 +180,43 @@ static int AReadStream( stream_t *s, void *p_read, int i_read );
/* Common */
static int AStreamControl( stream_t *s, int i_query, va_list );
static void AStreamDestroy( stream_t *s );
static void UStreamDestroy( stream_t *s );
static int ASeek( stream_t *s, int64_t i_pos );
/****************************************************************************
* stream_AccessNew: create a stream from a access
****************************************************************************/
stream_t *__stream_UrlNew( vlc_object_t *p_parent, char *psz_url )
{
char *psz_access, *psz_demux, *psz_path;
access_t *p_access;
stream_t *p_res;
MRLSplit( p_parent, psz_url, &psz_access, &psz_demux, &psz_path );
/* Now try a real access */
p_access = access2_New( p_parent, psz_access, NULL,
psz_path, VLC_TRUE );
if( p_access == NULL )
{
msg_Err( p_parent, "no suitable access module for `%s'", psz_url );
return NULL;
}
p_res = stream_AccessNew( p_access, VLC_TRUE );
if( p_res )
{
p_res->pf_destroy = UStreamDestroy;
return p_res;
}
else
{
access2_Delete( p_access );
}
}
stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick )
{
stream_t *s = vlc_object_create( p_access, VLC_OBJECT_STREAM );
......@@ -201,6 +232,7 @@ stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick )
s->pf_read = NULL; /* Set up later */
s->pf_peek = NULL;
s->pf_control= AStreamControl;
s->pf_destroy = AStreamDestroy;
s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) );
......@@ -354,9 +386,9 @@ error:
}
/****************************************************************************
* stream_AccessDelete:
* AStreamDestroy:
****************************************************************************/
void stream_AccessDelete( stream_t *s )
static void AStreamDestroy( stream_t *s )
{
stream_sys_t *p_sys = s->p_sys;
......@@ -381,6 +413,13 @@ void stream_AccessDelete( stream_t *s )
vlc_object_destroy( s );
}
static void UStreamDestroy( stream_t *s )
{
access_t *p_access = (access_t*)vlc_object_find( s, VLC_OBJECT_ACCESS, FIND_PARENT );
AStreamDestroy( s );
access2_Delete( p_access );
}
/****************************************************************************
* stream_AccessReset:
****************************************************************************/
......
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