[vlc-commits] stream: privatize the destruction callback

Rémi Denis-Courmont git at videolan.org
Wed Sep 2 21:54:14 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Sep  2 20:49:40 2015 +0300| [f68036675747ad5181ca78e2cfcff520dab6a451] | committer: Rémi Denis-Courmont

stream: privatize the destruction callback

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f68036675747ad5181ca78e2cfcff520dab6a451
---

 include/vlc_stream.h      |    3 ---
 src/input/access.c        |    5 ++---
 src/input/stream.c        |   25 ++++++++++++++++---------
 src/input/stream.h        |    3 ++-
 src/input/stream_demux.c  |   22 +++++++++-------------
 src/input/stream_filter.c |   20 +++++++-------------
 src/input/stream_memory.c |    5 ++---
 7 files changed, 38 insertions(+), 45 deletions(-)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index d3715d2..cbdd2fa 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -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;
 
diff --git a/src/input/access.c b/src/input/access.c
index 2b83a2d..e04e30b 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -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;
 }
diff --git a/src/input/stream.c b/src/input/stream.c
index 309e66f..244143c 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -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
diff --git a/src/input/stream.h b/src/input/stream.h
index b80ccd3..4031c7a 100644
--- a/src/input/stream.h
+++ b/src/input/stream.h
@@ -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.
diff --git a/src/input/stream_demux.c b/src/input/stream_demux.c
index a571b9f..e25814c 100644
--- a/src/input/stream_demux.c
+++ b/src/input/stream_demux.c
@@ -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 )
diff --git a/src/input/stream_filter.c b/src/input/stream_filter.c
index 0027c9f..3c05d2b 100644
--- a/src/input/stream_filter.c
+++ b/src/input/stream_filter.c
@@ -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 */
diff --git a/src/input/stream_memory.c b/src/input/stream_memory.c
index f0814db..3fc23a9 100644
--- a/src/input/stream_memory.c
+++ b/src/input/stream_memory.c
@@ -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;



More information about the vlc-commits mailing list