[vlc-devel] [PATCH 22/22] picture_chain: add append version that takes care of the chain init

Steve Lhomme robux4 at ycbcr.xyz
Thu Sep 17 17:33:44 CEST 2020


---
 include/vlc_picture.h                | 17 +++++++++++++++++
 modules/hw/mmal/converter.c          | 11 +----------
 modules/hw/mmal/deinterlace.c        |  8 +-------
 modules/stream_out/mosaic_bridge.c   |  9 +--------
 modules/stream_out/transcode/video.c |  8 +-------
 modules/video_filter/fps.c           |  2 +-
 src/misc/picture_fifo.c              | 10 +---------
 7 files changed, 23 insertions(+), 42 deletions(-)

diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index a16d82a94f6..6db41801608 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -223,6 +223,23 @@ static inline picture_t * picture_chain_append(picture_t *chain, picture_t *tail
     return tail;
 }
 
+/**
+ * Append a picture in a picture chain that may not be initialized.
+ *
+ * \return the new tail of the picture chain
+ */
+static inline picture_t * picture_chain_append_empty(picture_t **chain, picture_t *tail,
+                                                     picture_t *pic)
+{
+    if (*chain == NULL)
+        *chain = pic;
+    else
+        tail->p_next = pic;
+
+    pic->p_next = NULL; // we're appending a picture, not a chain
+    return pic;
+}
+
 /**
  * Add a picture at the front of a picture chain.
  *
diff --git a/modules/hw/mmal/converter.c b/modules/hw/mmal/converter.c
index d85f8a122e1..b3f8181dad1 100644
--- a/modules/hw/mmal/converter.c
+++ b/modules/hw/mmal/converter.c
@@ -142,16 +142,7 @@ static void pic_fifo_init(pic_fifo_t * const pf)
 
 static void pic_fifo_put(pic_fifo_t * const pf, picture_t * pic)
 {
-    if (pf->head == NULL)
-    {
-        pic->p_next = NULL;
-        pf->head = pic;
-        pf->tail = pic;
-    }
-    else
-    {
-        pf->tail = picture_chain_append( pf->tail, pic  );
-    }
+    pf->tail = picture_chain_append_empty( &pf->head, pf->tail, pic  );
 }
 
 #define SUBS_MAX 3
diff --git a/modules/hw/mmal/deinterlace.c b/modules/hw/mmal/deinterlace.c
index 2512095b4ca..6f637e3357e 100644
--- a/modules/hw/mmal/deinterlace.c
+++ b/modules/hw/mmal/deinterlace.c
@@ -289,13 +289,7 @@ static picture_t *deinterlace(filter_t * p_filter, picture_t * p_pic)
             }
             out_buf = NULL;  // Now attached to pic or recycled
 
-            if (ret_pics == NULL)
-            {
-                ret_pics = out_pic;
-                chain_tail = out_pic;
-            }
-            else
-                chain_tail = picture_chain_append( chain_tail, out_pic );
+            chain_tail = picture_chain_append_empty( &ret_pics, chain_tail, out_pic );
 
             // Ignore 0 seqs
             // Don't think these should actually happen
diff --git a/modules/stream_out/mosaic_bridge.c b/modules/stream_out/mosaic_bridge.c
index 53a370cec84..98d289e4870 100644
--- a/modules/stream_out/mosaic_bridge.c
+++ b/modules/stream_out/mosaic_bridge.c
@@ -570,14 +570,7 @@ static void decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
     /* push the picture in the mosaic-struct structure */
     bridged_es_t *p_es = p_sys->p_es;
     vlc_global_lock( VLC_MOSAIC_MUTEX );
-    if (p_es->p_picture == NULL)
-    {
-        p_es->p_picture = p_new_pic;
-        p_es->tail      = p_new_pic;
-        p_new_pic->p_next = NULL;
-    }
-    else
-        p_es->tail = picture_chain_append( p_es->tail, p_new_pic );
+    p_es->tail = picture_chain_append_empty( &p_es->p_picture, p_es->tail, p_new_pic );
     vlc_global_unlock( VLC_MOSAIC_MUTEX );
 }
 
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index edbd8e44f38..ae8d1dddac5 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -151,13 +151,7 @@ static void decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
 
     assert(picture_chain_empty(p_pic));
     vlc_mutex_lock(&id->fifo.lock);
-    if (id->fifo.pic.first == NULL)
-    {
-        id->fifo.pic.first = p_pic;
-        id->fifo.pic.tail = p_pic;
-    }
-    else
-        id->fifo.pic.tail = picture_chain_append( id->fifo.pic.tail, p_pic );
+    id->fifo.pic.tail = picture_chain_append_empty( &id->fifo.pic.first, id->fifo.pic.tail, p_pic );
     vlc_mutex_unlock(&id->fifo.lock);
 }
 
diff --git a/modules/video_filter/fps.c b/modules/video_filter/fps.c
index 92cc3a0874a..329cd647957 100644
--- a/modules/video_filter/fps.c
+++ b/modules/video_filter/fps.c
@@ -122,7 +122,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_picture)
         picture_Copy( p_tmp, p_sys->p_previous_pic);
         p_tmp->date = date_Get( &p_sys->next_output_pts );
 
-        last_pic = picture_chain_append( last_pic, p_tmp );
+        last_pic = picture_chain_append_empty( &p_sys->p_previous_pic, last_pic, p_tmp );
         date_Increment( &p_sys->next_output_pts, 1 );
     }
 
diff --git a/src/misc/picture_fifo.c b/src/misc/picture_fifo.c
index f67202c31b7..08805cfc94c 100644
--- a/src/misc/picture_fifo.c
+++ b/src/misc/picture_fifo.c
@@ -50,15 +50,7 @@ static void PictureFifoReset(picture_fifo_t *fifo)
 static void PictureFifoPush(picture_fifo_t *fifo, picture_t *picture)
 {
     assert(picture_chain_empty(picture));
-    if (fifo->first == NULL)
-    {
-        fifo->first = picture;
-        fifo->tail  = picture;
-    }
-    else
-    {
-        fifo->tail = picture_chain_append( fifo->tail, picture );
-    }
+    fifo->tail = picture_chain_append_empty( &fifo->first, fifo->tail, picture );
 }
 static picture_t *PictureFifoPop(picture_fifo_t *fifo)
 {
-- 
2.26.2



More information about the vlc-devel mailing list