Commit f6803667 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

stream: privatize the destruction callback

parent 5d096c30
......@@ -61,9 +61,6 @@ struct stream_t
int (*pf_seek)(stream_t *, uint64_t);
int (*pf_control)( stream_t *, int i_query, va_list );
/* */
void (*pf_destroy)( stream_t *);
/* Private data for module */
stream_sys_t *p_sys;
......
......@@ -348,7 +348,7 @@ static void AStreamDestroy(stream_t *s)
stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input,
const char *url)
{
stream_t *s = stream_CommonNew(parent);
stream_t *s = stream_CommonNew(parent, AStreamDestroy);
if (unlikely(s == NULL))
return NULL;
......@@ -391,7 +391,6 @@ stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input,
s->pf_seek = AStreamSeek;
s->pf_control = AStreamControl;
s->pf_destroy = AStreamDestroy;
s->p_sys = sys;
if (cachename != NULL)
......@@ -399,6 +398,6 @@ stream_t *stream_AccessNew(vlc_object_t *parent, input_thread_t *input,
return s;
error:
free(sys);
stream_Delete(s);
stream_CommonDelete(s);
return NULL;
}
......@@ -44,6 +44,7 @@
typedef struct stream_priv_t
{
stream_t stream;
void (*destroy)(stream_t *);
block_t *peek;
uint64_t offset;
......@@ -58,7 +59,7 @@ typedef struct stream_priv_t
/**
* Allocates a VLC stream object
*/
stream_t *stream_CommonNew(vlc_object_t *parent)
stream_t *stream_CommonNew(vlc_object_t *parent, void (*destroy)(stream_t *))
{
stream_priv_t *priv = vlc_custom_create(parent, sizeof (*priv), "stream");
if (unlikely(priv == NULL))
......@@ -72,8 +73,9 @@ stream_t *stream_CommonNew(vlc_object_t *parent)
s->pf_read = NULL;
s->pf_readdir = NULL;
s->pf_control = NULL;
s->pf_destroy = NULL;
s->p_input = NULL;
assert(destroy != NULL);
priv->destroy = destroy;
priv->peek = NULL;
priv->offset = 0;
......@@ -85,16 +87,10 @@ stream_t *stream_CommonNew(vlc_object_t *parent)
return s;
}
/**
* Destroy a stream
*/
void stream_Delete(stream_t *s)
void stream_CommonDelete(stream_t *s)
{
stream_priv_t *priv = (stream_priv_t *)s;
if (s->pf_destroy != NULL)
s->pf_destroy(s);
if (priv->text.conv != (vlc_iconv_t)(-1))
vlc_iconv_close(priv->text.conv);
......@@ -105,6 +101,17 @@ void stream_Delete(stream_t *s)
vlc_object_release(s);
}
/**
* Destroy a stream
*/
void stream_Delete(stream_t *s)
{
stream_priv_t *priv = (stream_priv_t *)s;
priv->destroy(s);
stream_CommonDelete(s);
}
#undef stream_UrlNew
/****************************************************************************
* stream_UrlNew: create a stream from a access
......
......@@ -29,7 +29,8 @@
#include <vlc_stream.h>
/* */
stream_t *stream_CommonNew( vlc_object_t * );
stream_t *stream_CommonNew( vlc_object_t *, void (*destroy)(stream_t *) );
void stream_CommonDelete( stream_t *s );
/**
* This function creates a stream_t with an access_t back-end.
......
......@@ -68,21 +68,17 @@ stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *ou
stream_t *s;
stream_sys_t *p_sys;
s = stream_CommonNew( p_obj );
s = stream_CommonNew( p_obj, DStreamDelete );
if( s == NULL )
return NULL;
s->p_input = p_demux->p_input;
s->pf_read = DStreamRead;
s->pf_seek = NULL;
s->pf_control= DStreamControl;
s->pf_destroy= DStreamDelete;
s->p_sys = p_sys = malloc( sizeof( *p_sys) );
if( !s->p_sys )
{
stream_Delete( s );
return NULL;
}
if( unlikely(p_sys == NULL) )
goto error;
p_sys->out = out;
p_sys->p_block = NULL;
......@@ -94,10 +90,8 @@ stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *ou
/* decoder fifo */
if( ( p_sys->p_fifo = block_FifoNew() ) == NULL )
{
stream_Delete( s );
free( p_sys->psz_name );
free( p_sys );
return NULL;
goto error;
}
atomic_init( &p_sys->active, true );
......@@ -107,13 +101,15 @@ stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *ou
{
vlc_mutex_destroy( &p_sys->lock );
block_FifoRelease( p_sys->p_fifo );
stream_Delete( s );
free( p_sys->psz_name );
free( p_sys );
return NULL;
goto error;
}
return s;
error:
free( p_sys );
stream_CommonDelete( s );
return NULL;
}
void stream_DemuxSend( stream_t *s, block_t *p_block )
......
......@@ -42,7 +42,7 @@ stream_t *stream_FilterNew( stream_t *p_source,
stream_t *s;
assert( p_source != NULL );
s = stream_CommonNew( p_source->p_parent );
s = stream_CommonNew( p_source->p_parent, StreamDelete );
if( s == NULL )
return NULL;
......@@ -52,25 +52,19 @@ stream_t *stream_FilterNew( stream_t *p_source,
{
s->psz_url = strdup( p_source->psz_url );
if( unlikely(s->psz_url == NULL) )
{
stream_Delete( s );
return NULL;
}
goto error;
}
s->p_source = p_source;
/* */
s->p_module = module_need( s, "stream_filter", psz_stream_filter, true );
if( !s->p_module )
{
stream_Delete( s );
return NULL;
}
s->pf_destroy = StreamDelete;
if( s->p_module == NULL )
goto error;
return s;
error:
stream_CommonDelete( s );
return NULL;
}
/* Add automatic stream filter */
......
......@@ -54,7 +54,7 @@ static void Delete ( stream_t * );
stream_t *stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
uint64_t i_size, bool i_preserve_memory )
{
stream_t *s = stream_CommonNew( p_this );
stream_t *s = stream_CommonNew( p_this, Delete );
stream_sys_t *p_sys;
if( !s )
......@@ -63,7 +63,7 @@ stream_t *stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) );
if( !s->p_sys )
{
stream_Delete( s );
stream_CommonDelete( s );
return NULL;
}
p_sys->i_pos = 0;
......@@ -74,7 +74,6 @@ stream_t *stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
s->pf_read = Read;
s->pf_seek = Seek;
s->pf_control = Control;
s->pf_destroy = Delete;
s->p_input = NULL;
return s;
......
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