diff mbox series

[FFmpeg-devel,29/35] fftools/ffmpeg_mux: return errors from submit_packet()

Message ID 20220616195534.5278-29-anton@khirnov.net
State Accepted
Commit 279214dd517f6c58e43a4d6e8beb09accbaf3d4b
Headers show
Series [FFmpeg-devel,01/35] fftools/ffmpeg_mux: add private muxer context | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov June 16, 2022, 7:55 p.m. UTC
Do not call exit_program(), as that would conflict with moving this code
into a separate thread.
---
 fftools/ffmpeg_mux.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
diff mbox series

Patch

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;
         }
     }