[FFmpeg-cvslog] fftools/ffmpeg_mux: return errors from of_submit_packet()
Anton Khirnov
git at videolan.org
Sat Jul 23 13:07:53 EEST 2022
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Apr 1 10:03:46 2022 +0200| [52bc8a842e037214e1644f61962982c73a175eca] | committer: Anton Khirnov
fftools/ffmpeg_mux: return errors from of_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=52bc8a842e037214e1644f61962982c73a175eca
---
fftools/ffmpeg.c | 54 ++++++++++++++++++++++++++++++++++++----------------
fftools/ffmpeg.h | 2 +-
fftools/ffmpeg_mux.c | 6 ++++--
3 files changed, 43 insertions(+), 19 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index cee5b1cbcf..90e14aba25 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -713,6 +713,7 @@ static void close_output_stream(OutputStream *ost)
static void output_packet(OutputFile *of, AVPacket *pkt,
OutputStream *ost, int eof)
{
+ const char *err_msg;
int ret = 0;
if (!eof && pkt->dts != AV_NOPTS_VALUE)
@@ -720,28 +721,49 @@ static void output_packet(OutputFile *of, AVPacket *pkt,
/* apply the output bitstream filters */
if (ost->bsf_ctx) {
+ int bsf_eof = 0;
+
ret = av_bsf_send_packet(ost->bsf_ctx, eof ? NULL : pkt);
+ if (ret < 0) {
+ err_msg = "submitting a packet for bitstream filtering";
+ goto fail;
+ }
+
+ while (!bsf_eof) {
+ ret = av_bsf_receive_packet(ost->bsf_ctx, pkt);
+ if (ret == AVERROR(EAGAIN))
+ return;
+ else if (ret == AVERROR_EOF)
+ bsf_eof = 1;
+ else if (ret < 0) {
+ err_msg = "applying bitstream filters to a packet";
+ goto fail;
+ }
+
+ ret = of_submit_packet(of, bsf_eof ? NULL : pkt, ost);
+ if (ret < 0)
+ goto mux_fail;
+ }
+ } else {
+ ret = of_submit_packet(of, eof ? NULL : pkt, ost);
if (ret < 0)
- goto finish;
- while ((ret = av_bsf_receive_packet(ost->bsf_ctx, pkt)) >= 0)
- of_submit_packet(of, pkt, ost);
- if (ret == AVERROR_EOF)
- of_submit_packet(of, NULL, ost);
- if (ret == AVERROR(EAGAIN))
- ret = 0;
- } else
- of_submit_packet(of, eof ? NULL : pkt, ost);
+ goto mux_fail;
+ }
if (eof)
ost->finished |= MUXER_FINISHED;
-finish:
- if (ret < 0 && ret != AVERROR_EOF) {
- av_log(NULL, AV_LOG_ERROR, "Error applying bitstream filters to an output "
- "packet for stream #%d:%d.\n", ost->file_index, ost->index);
- if(exit_on_error)
- exit_program(1);
- }
+ return;
+
+mux_fail:
+ err_msg = "submitting a packet to the muxer";
+
+fail:
+ av_log(NULL, AV_LOG_ERROR, "Error %s for output stream #%d:%d.\n",
+ err_msg, ost->file_index, ost->index);
+ if (exit_on_error)
+ exit_program(1);
+
}
static int check_recording_time(OutputStream *ost)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 48ecf26f74..8b42a0502e 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -707,7 +707,7 @@ int of_check_init(OutputFile *of);
int of_write_trailer(OutputFile *of);
void of_close(OutputFile **pof);
-void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost);
+int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost);
int of_finished(OutputFile *of);
int64_t of_filesize(OutputFile *of);
AVChapter * const *
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index c44ff0f1df..490e0e54eb 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -232,7 +232,7 @@ static void submit_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt)
}
}
-void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
+int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
{
int ret;
@@ -243,9 +243,11 @@ void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
ret = queue_packet(of, ost, pkt);
if (ret < 0) {
av_packet_unref(pkt);
- exit_program(1);
+ return ret;
}
}
+
+ return 0;
}
static int print_sdp(void)
More information about the ffmpeg-cvslog
mailing list