[FFmpeg-cvslog] fftools/ffmpeg_demux: move preparing DemuxMsg to separate function

Anton Khirnov git at videolan.org
Mon May 15 15:16:15 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Apr 26 14:23:42 2023 +0200| [abf9532bdad9d62b586b0fb5e4005a9fad2064e5] | committer: Anton Khirnov

fftools/ffmpeg_demux: move preparing DemuxMsg to separate function

Will be useful in following commits, which will move more code into this
function.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=abf9532bdad9d62b586b0fb5e4005a9fad2064e5
---

 fftools/ffmpeg_demux.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 1872e87d57..b16a20a87b 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -257,6 +257,26 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
     SHOW_TS_DEBUG("demuxer+tsfixup");
 }
 
+// process an input packet into a message to send to the consumer thread
+// src is always cleared by this function
+static int input_packet_process(Demuxer *d, DemuxMsg *msg, AVPacket *src)
+{
+    AVPacket *pkt;
+
+    pkt = av_packet_alloc();
+    if (!pkt) {
+        av_packet_unref(src);
+        return AVERROR(ENOMEM);
+    }
+    av_packet_move_ref(pkt, src);
+
+    ts_fixup(d, pkt, &msg->repeat_pict);
+
+    msg->pkt = pkt;
+
+    return 0;
+}
+
 static void thread_set_name(InputFile *f)
 {
     char name[16];
@@ -336,15 +356,10 @@ static void *input_thread(void *arg)
             }
         }
 
-        ts_fixup(d, pkt, &msg.repeat_pict);
-
-        msg.pkt = av_packet_alloc();
-        if (!msg.pkt) {
-            av_packet_unref(pkt);
-            ret = AVERROR(ENOMEM);
+        ret = input_packet_process(d, &msg, pkt);
+        if (ret < 0)
             break;
-        }
-        av_packet_move_ref(msg.pkt, pkt);
+
         ret = av_thread_message_queue_send(d->in_thread_queue, &msg, flags);
         if (flags && ret == AVERROR(EAGAIN)) {
             flags = 0;



More information about the ffmpeg-cvslog mailing list