[vlc-devel] [PATCH v4 24/24] picture_chain: modify the append to take care of the chain init

Steve Lhomme robux4 at ycbcr.xyz
Mon Sep 21 13:48:22 CEST 2020


By default p_next is always set to NULL in a picture. We can always use it as
a proper picture chain.

When a chain becomes empty p_next goes back to zero and the "known tail" is
invalid. But we only use the tail when the front is not empty, so there is no
problem.
---
 include/vlc_picture.h                |  9 +++++++--
 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 +---------
 src/video_output/snapshot.c          | 10 +---------
 8 files changed, 14 insertions(+), 53 deletions(-)

diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index ef86ed41ea1..dc9e12e81c3 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -194,14 +194,19 @@ static inline picture_t * vlc_picture_chain_PopFront(picture_t **chain)
  * Append a picture to a picture chain.
  *
  * \param chain the picture chain pointer
+ * \param tail the known tail of the picture chain
  * \param pic the picture to append to the chain
  *
  * \return the new tail of the picture chain
  */
 VLC_USED
-static inline picture_t * vlc_picture_chain_Append(picture_t *chain, picture_t *pic)
+static inline picture_t * vlc_picture_chain_Append(picture_t **chain, picture_t *tail,
+                                                   picture_t *pic)
 {
-    chain->p_next = 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;
 }
diff --git a/modules/hw/mmal/converter.c b/modules/hw/mmal/converter.c
index 974840f4bbe..f62f21e0876 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 = vlc_picture_chain_Append( pf->tail, pic  );
-    }
+    pf->tail = vlc_picture_chain_Append( &pf->head, pf->tail, pic  );
 }
 
 #define SUBS_MAX 3
diff --git a/modules/hw/mmal/deinterlace.c b/modules/hw/mmal/deinterlace.c
index d3cc0cc6031..2709a1f1730 100644
--- a/modules/hw/mmal/deinterlace.c
+++ b/modules/hw/mmal/deinterlace.c
@@ -284,13 +284,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 = vlc_picture_chain_Append( chain_tail, out_pic );
+        chain_tail = vlc_picture_chain_Append( &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 daa7ee4ddf5..eda165b00c2 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 = vlc_picture_chain_Append( p_es->tail, p_new_pic );
+    p_es->tail = vlc_picture_chain_Append( &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 d1ffb567b3e..dc07278e11b 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_HasChainedPics(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 = vlc_picture_chain_Append( id->fifo.pic.tail, p_pic );
+    id->fifo.pic.tail = vlc_picture_chain_Append( &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 ab78610a992..4e6a59dfd66 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 = vlc_picture_chain_Append( last_pic, p_tmp );
+        last_pic = vlc_picture_chain_Append( &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 2e6c227e794..c2f2df8734d 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_HasChainedPics(picture));
-    if (fifo->first == NULL)
-    {
-        fifo->first = picture;
-        fifo->tail  = picture;
-    }
-    else
-    {
-        fifo->tail = vlc_picture_chain_Append( fifo->tail, picture );
-    }
+    fifo->tail = vlc_picture_chain_Append( &fifo->first, fifo->tail, picture );
 }
 static picture_t *PictureFifoPop(picture_fifo_t *fifo)
 {
diff --git a/src/video_output/snapshot.c b/src/video_output/snapshot.c
index 01eed7e275c..aaa658c851e 100644
--- a/src/video_output/snapshot.c
+++ b/src/video_output/snapshot.c
@@ -151,15 +151,7 @@ void vout_snapshot_Set(vout_snapshot_t *snap,
 
         video_format_CopyCrop( &dup->format, fmt );
 
-        if (snap->picture == NULL)
-        {
-            snap->picture = dup;
-            snap->tail = dup;
-        }
-        else
-        {
-            snap->tail = vlc_picture_chain_Append( snap->tail, dup );
-        }
+        snap->tail = vlc_picture_chain_Append( &snap->picture, snap->tail, dup );
         snap->request_count--;
     }
     vlc_cond_broadcast(&snap->wait);
-- 
2.26.2



More information about the vlc-devel mailing list