[vlc-commits] stream_fifo: simplify using vlc_stream_Private()

Rémi Denis-Courmont git at videolan.org
Fri Apr 6 20:05:13 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Apr  6 20:54:21 2018 +0300| [267635346d777c0052a4f4e486e134b0de6caf4e] | committer: Rémi Denis-Courmont

stream_fifo: simplify using vlc_stream_Private()

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

 src/input/stream_fifo.c | 44 ++++++++++++++++----------------------------
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/src/input/stream_fifo.c b/src/input/stream_fifo.c
index eb7b0ba8d6..fd82dfb92c 100644
--- a/src/input/stream_fifo.c
+++ b/src/input/stream_fifo.c
@@ -33,7 +33,7 @@
 
 #include "stream.h"
 
-struct stream_sys_t
+struct vlc_stream_fifo_private
 {
     vlc_fifo_t *fifo;
     bool eof;
@@ -41,7 +41,7 @@ struct stream_sys_t
 
 static void vlc_stream_fifo_Destroy(stream_t *s)
 {
-    stream_sys_t *sys = s->p_sys;
+    struct vlc_stream_fifo_private *sys = vlc_stream_Private(s);
     vlc_fifo_t *fifo = sys->fifo;
     block_t *block;
     bool closed;
@@ -54,16 +54,13 @@ static void vlc_stream_fifo_Destroy(stream_t *s)
 
     block_ChainRelease(block);
 
-    if (closed)
-    {   /* Destroy shared state if write end is already closed */
+    if (closed) /* Destroy shared state if write end is already closed */
         block_FifoRelease(fifo);
-        free(sys);
-    }
 }
 
 static block_t *vlc_stream_fifo_Block(stream_t *s, bool *restrict eof)
 {
-    stream_sys_t *sys = s->p_sys;
+    struct vlc_stream_fifo_private *sys = vlc_stream_Private(s);
     vlc_fifo_t *fifo = sys->fifo;
     block_t *block;
 
@@ -108,37 +105,31 @@ static int vlc_stream_fifo_Control(stream_t *s, int query, va_list ap)
 
 stream_t *vlc_stream_fifo_New(vlc_object_t *parent)
 {
-    stream_sys_t *sys = malloc(sizeof (*sys));
-    if (unlikely(sys == NULL))
+    vlc_fifo_t *fifo = block_FifoNew();
+    if (unlikely(fifo == NULL))
         return NULL;
 
-    sys->fifo = block_FifoNew();
-    if (unlikely(sys->fifo == NULL))
-    {
-        free(sys);
-        return NULL;
-    }
-
-    sys->eof = false;
-
-    stream_t *s = vlc_stream_CommonNew(parent, vlc_stream_fifo_Destroy);
+    struct vlc_stream_fifo_private *sys;
+    stream_t *s = vlc_stream_CustomNew(parent, vlc_stream_fifo_Destroy,
+                                       sizeof (*sys), "stream");
     if (unlikely(s == NULL))
     {
-        block_FifoRelease(sys->fifo);
-        free(sys);
+        block_FifoRelease(fifo);
         return NULL;
     }
 
+    sys = vlc_stream_Private(s);
+    sys->fifo = fifo;
+    sys->eof = false;
     s->pf_block = vlc_stream_fifo_Block;
     s->pf_seek = NULL;
     s->pf_control = vlc_stream_fifo_Control;
-    s->p_sys = sys;
     return vlc_object_hold(s);
 }
 
 int vlc_stream_fifo_Queue(stream_t *s, block_t *block)
 {
-    stream_sys_t *sys = s->p_sys;
+    struct vlc_stream_fifo_private *sys = vlc_stream_Private(s);
     vlc_fifo_t *fifo = sys->fifo;
 
     vlc_fifo_Lock(fifo);
@@ -170,7 +161,7 @@ ssize_t vlc_stream_fifo_Write(stream_t *s, const void *buf, size_t len)
 
 void vlc_stream_fifo_Close(stream_t *s)
 {
-    stream_sys_t *sys = s->p_sys;
+    struct vlc_stream_fifo_private *sys = vlc_stream_Private(s);
     vlc_fifo_t *fifo = sys->fifo;
     bool closed;
 
@@ -180,11 +171,8 @@ void vlc_stream_fifo_Close(stream_t *s)
     vlc_fifo_Signal(fifo);
     vlc_fifo_Unlock(fifo);
 
-    if (closed)
-    {   /* Destroy shared state if read end is already closed */
+    if (closed) /* Destroy shared state if read end is already closed */
         block_FifoRelease(fifo);
-        free(sys);
-    }
 
     vlc_object_release(s);
 }



More information about the vlc-commits mailing list