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

Steve Lhomme robux4 at ycbcr.xyz
Fri Sep 18 16:45:30 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 +---------
 7 files changed, 13 insertions(+), 44 deletions(-)

diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index 44fcf6f3cec..984f56f6f75 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -234,13 +234,18 @@ static inline void picture_chain_append_chain(picture_t *chain, picture_t *tail)
  * 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
  */
-static inline picture_t * picture_chain_append(picture_t *chain, picture_t *pic) VLC_USED
+static inline picture_t * picture_chain_append(picture_t **chain, picture_t *tail,
+                                               picture_t *pic) VLC_USED
 {
-    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 d85f8a122e1..4d2931ffb02 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( &pf->head, pf->tail, pic  );
 }
 
 #define SUBS_MAX 3
diff --git a/modules/hw/mmal/deinterlace.c b/modules/hw/mmal/deinterlace.c
index 41ea253c918..9d3353ac2e8 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 = picture_chain_append( chain_tail, out_pic );
+        chain_tail = 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 53a370cec84..2b270944f03 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( &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 4961a6dc527..c8497ed4807 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_has_chained_pics(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( &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 df537872929..ccaa1b48da1 100644
--- a/modules/video_filter/fps.c
+++ b/modules/video_filter/fps.c
@@ -125,7 +125,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( &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 966a4d5c30a..9580e5063e8 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_has_chained_pics(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( &fifo->first, fifo->tail, picture );
 }
 static picture_t *PictureFifoPop(picture_fifo_t *fifo)
 {
-- 
2.26.2



More information about the vlc-devel mailing list