[FFmpeg-cvslog] fftools/ffmpeg_mux: return errors from submit_packet()

Anton Khirnov git at videolan.org
Sat Jul 23 13:07:55 EEST 2022


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Apr  1 10:03:46 2022 +0200| [279214dd517f6c58e43a4d6e8beb09accbaf3d4b] | committer: Anton Khirnov

fftools/ffmpeg_mux: return errors from submit_packet()

Do not call exit_program(), as that would conflict with moving this code
into a separate thread.

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

 fftools/ffmpeg_mux.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 490e0e54eb..98d3adaeac 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -200,7 +200,7 @@ static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
     }
 }
 
-static void submit_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
+static int submit_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
 {
     if (ost->sq_idx_mux >= 0) {
         int ret = sq_send(of->sq_mux, ost->sq_idx_mux, SQPKT(pkt));
@@ -209,17 +209,17 @@ static void submit_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
                 av_packet_unref(pkt);
             if (ret == AVERROR_EOF) {
                 ost->finished |= MUXER_FINISHED;
-                return;
+                return 0;
             } else
-                exit_program(1);
+                return ret;
         }
 
         while (1) {
             ret = sq_receive(of->sq_mux, -1, SQPKT(of->mux->sq_pkt));
             if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
-                return;
+                return 0;
             else if (ret < 0)
-                exit_program(1);
+                return ret;
 
             write_packet(of, output_streams[of->ost_index + ret],
                          of->mux->sq_pkt);
@@ -230,6 +230,8 @@ static void submit_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
         else
             ost->finished |= MUXER_FINISHED;
     }
+
+    return 0;
 }
 
 int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
@@ -237,7 +239,7 @@ int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
     int ret;
 
     if (of->mux->header_written) {
-        submit_packet(of, ost, pkt);
+        return submit_packet(of, ost, pkt);
     } else {
         /* the muxer is not initialized yet, buffer the packet */
         ret = queue_packet(of, ost, pkt);
@@ -348,11 +350,13 @@ int of_check_init(OutputFile *of)
             ost->mux_timebase = ost->st->time_base;
 
         while (av_fifo_read(ms->muxing_queue, &pkt, 1) >= 0) {
-            submit_packet(of, ost, pkt);
+            ret = submit_packet(of, ost, pkt);
             if (pkt) {
                 ms->muxing_queue_data_size -= pkt->size;
                 av_packet_free(&pkt);
             }
+            if (ret < 0)
+                return ret;
         }
     }
 



More information about the ffmpeg-cvslog mailing list