[FFmpeg-cvslog] ffmpeg: handle errors in print_sdp()
Anton Khirnov
git at videolan.org
Tue Dec 7 12:29:29 EET 2021
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Dec 4 18:38:54 2021 +0100| [9f717ca92f77d94e9ac3e5676e5622c6ba847dc4] | committer: Anton Khirnov
ffmpeg: handle errors in print_sdp()
Do not continue as if nothing happened.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9f717ca92f77d94e9ac3e5676e5622c6ba847dc4
---
fftools/ffmpeg.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 1a415d396b..0f1834cdbe 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2761,17 +2761,17 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
return !eof_reached;
}
-static void print_sdp(void)
+static int print_sdp(void)
{
char sdp[16384];
int i;
- int j;
+ int j, ret;
AVIOContext *sdp_pb;
AVFormatContext **avc;
for (i = 0; i < nb_output_files; i++) {
if (!output_files[i]->header_written)
- return;
+ return 0;
}
avc = av_malloc_array(nb_output_files, sizeof(*avc));
@@ -2784,26 +2784,34 @@ static void print_sdp(void)
}
}
- if (!j)
+ if (!j) {
+ av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n");
+ ret = AVERROR(EINVAL);
goto fail;
+ }
- av_sdp_create(avc, j, sdp, sizeof(sdp));
+ ret = av_sdp_create(avc, j, sdp, sizeof(sdp));
+ if (ret < 0)
+ goto fail;
if (!sdp_filename) {
printf("SDP:\n%s\n", sdp);
fflush(stdout);
} else {
- if (avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL) < 0) {
+ ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL);
+ if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename);
- } else {
- avio_print(sdp_pb, sdp);
- avio_closep(&sdp_pb);
- av_freep(&sdp_filename);
+ goto fail;
}
+
+ avio_print(sdp_pb, sdp);
+ avio_closep(&sdp_pb);
+ av_freep(&sdp_filename);
}
fail:
av_freep(&avc);
+ return ret;
}
static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
@@ -2959,8 +2967,13 @@ static int check_init_output_file(OutputFile *of, int file_index)
av_dump_format(of->ctx, file_index, of->ctx->url, 1);
nb_output_dumped++;
- if (sdp_filename || want_sdp)
- print_sdp();
+ if (sdp_filename || want_sdp) {
+ ret = print_sdp();
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error writing the SDP.\n");
+ return ret;
+ }
+ }
/* flush the muxing queues */
for (i = 0; i < of->ctx->nb_streams; i++) {
More information about the ffmpeg-cvslog
mailing list