[vlc-devel] [PATCH v2 12/24] transcode: simplify the picture queue tail handling

Steve Lhomme robux4 at ycbcr.xyz
Fri Sep 18 16:45:18 CEST 2020


Rather than a pointer on the last picture pointer, we use either NULL (no
tail/chain empty) or a pointer to the last picture in the chain.

Make sure that the pictures we queue don't have a p_next otherwise it would
screw the computation of the last. (the issue existed before this patch)
---
 modules/stream_out/transcode/transcode.h |  2 +-
 modules/stream_out/transcode/video.c     | 12 ++++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/modules/stream_out/transcode/transcode.h b/modules/stream_out/transcode/transcode.h
index 0ca725d46bd..315c5173a0d 100644
--- a/modules/stream_out/transcode/transcode.h
+++ b/modules/stream_out/transcode/transcode.h
@@ -89,7 +89,7 @@ struct sout_stream_id_sys_t
         {
             struct {
                 picture_t *first;
-                picture_t **last;
+                picture_t *tail;
             } pic;
             struct {
                 subpicture_t *first;
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index ed004363497..1bcbfb9d389 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -150,8 +150,12 @@ static void decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
     sout_stream_id_sys_t *id = p_owner->id;
 
     vlc_mutex_lock(&id->fifo.lock);
-    *id->fifo.pic.last = p_pic;
-    id->fifo.pic.last = &p_pic->p_next;
+    if (id->fifo.pic.first == NULL)
+        id->fifo.pic.first = p_pic;
+    else
+        id->fifo.pic.tail->p_next = p_pic;
+    id->fifo.pic.tail = p_pic;
+    assert(p_pic->p_next == NULL);
     vlc_mutex_unlock(&id->fifo.lock);
 }
 
@@ -160,7 +164,7 @@ static picture_t *transcode_dequeue_all_pics( sout_stream_id_sys_t *id )
     vlc_mutex_lock(&id->fifo.lock);
     picture_t *p_pics = id->fifo.pic.first;
     id->fifo.pic.first = NULL;
-    id->fifo.pic.last = &id->fifo.pic.first;
+    id->fifo.pic.tail  = NULL;
     vlc_mutex_unlock(&id->fifo.lock);
 
     return p_pics;
@@ -174,7 +178,7 @@ int transcode_video_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
              (char*)&p_fmt->i_codec, (char*)&id->p_enccfg->i_codec );
 
     id->fifo.pic.first = NULL;
-    id->fifo.pic.last = &id->fifo.pic.first;
+    id->fifo.pic.tail  = NULL;
     id->b_transcode = true;
     es_format_Init( &id->decoder_out, VIDEO_ES, 0 );
 
-- 
2.26.2



More information about the vlc-devel mailing list