[FFmpeg-devel] [PATCH v2 04/11] avformat/muxers: Add non-blocking mode support for av_write_trailer
sebechlebskyjan at gmail.com
sebechlebskyjan at gmail.com
Thu Aug 11 15:38:29 EEST 2016
From: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
This makes av_write_trailer not to free the resources if write_trailer
call returns AVERROR(EAGAIN) allowing repeated calls of write_trailer of
non-blocking muxer.
Signed-off-by: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
---
Changes since the last version of the patch:
- Added assert to the part of the code dealing with flushing
interleaved packets which should not be entered if
muxer in non-blocking mode is used.
(also there is assert for the same condition added into
av_interleaved_write_packet in one of the following
patches).
libavformat/avformat.h | 6 +++++-
libavformat/mux.c | 10 ++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index d8a6cf3..2cc3156 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2510,8 +2510,12 @@ int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index);
*
* May only be called after a successful call to avformat_write_header.
*
+ * If AVFMT_FLAG_NONBLOCK is set, this call may return AVERROR(EAGAIN)
+ * meaning the operation is pending and the call should be repeated.
+ *
* @param s media file handle
- * @return 0 if OK, AVERROR_xxx on error
+ * @return 0 if OK, AVERROR(EAGAIN) in case call should be repeated,
+ * other AVERROR on error
*/
int av_write_trailer(AVFormatContext *s);
diff --git a/libavformat/mux.c b/libavformat/mux.c
index e9973ed..3ae924c 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1204,11 +1204,14 @@ int av_write_trailer(AVFormatContext *s)
for (;; ) {
AVPacket pkt;
ret = interleave_packet(s, &pkt, NULL, 1);
- if (ret < 0)
- goto fail;
if (!ret)
break;
+ av_assert0(!(s->flags & AVFMT_FLAG_NONBLOCK));
+
+ if (ret < 0)
+ goto fail;
+
ret = write_packet(s, &pkt);
if (ret >= 0)
s->streams[pkt.stream_index]->nb_frames++;
@@ -1238,6 +1241,9 @@ fail:
}
}
+ if (ret == AVERROR(EAGAIN))
+ return ret;
+
if (s->oformat->deinit)
s->oformat->deinit(s);
--
1.9.1
More information about the ffmpeg-devel
mailing list