[FFmpeg-devel] [PATCH v2 06/11] avformat: add avformat_write_abort() function
sebechlebskyjan at gmail.com
sebechlebskyjan at gmail.com
Thu Aug 4 15:54:53 EEST 2016
From: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
Signed-off-by: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
---
Changes from last version of patch:
- removed AVFMT_FLAG_NONBLOCK check and modified comment
so it states how function behaves with both blocking / non-blocking muxer
libavformat/avformat.h | 15 +++++++++++++++
libavformat/mux.c | 13 +++++++++++++
2 files changed, 28 insertions(+)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 578f99f..3f6a6eb 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2512,6 +2512,8 @@ int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index);
*
* If AVFMT_FLAG_NONBLOCK is set, this call may return AVERROR(EAGAIN)
* meaning the operation is pending and the call should be repeated.
+ * If caller decides to abort operation (after too many calls have returned
+ * AVERROR(EAGAIN)), it can be done by calling @ref avformat_write_abort().
*
* @param s media file handle
* @return 0 if OK, AVERROR(EAGAIN) in case call should be repeated,
@@ -2520,6 +2522,19 @@ int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index);
int av_write_trailer(AVFormatContext *s);
/**
+ * Abort muxer operation and free private data.
+ * For muxer operating in blocking mode, this is equivalent to calling
+ * av_write_trailer. For muxer operating in non-blocking mode, this will
+ * call deinitialize routine even if there is operation pending
+ * and @ref av_write_trailer() keeps returning AVERROR(EAGAIN).
+ * May only be called after a successful call to avformat_write_header.
+ *
+ * @param s Media file handle
+ * return >= 0 on success, negative AVERROR on error
+ */
+int avformat_write_abort(AVFormatContext *s);
+
+/**
* Return the output format in the list of registered output formats
* which best matches the provided parameters, or return NULL if
* there is no match.
diff --git a/libavformat/mux.c b/libavformat/mux.c
index bc9c98f..a3c1d8a 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1267,6 +1267,19 @@ fail:
return ret;
}
+int avformat_write_abort(AVFormatContext *s)
+{
+ int ret;
+
+ ret = av_write_trailer(s);
+ if (ret == AVERROR(EAGAIN)) {
+ deinit_muxer(s);
+ ret = 0;
+ }
+
+ return ret;
+}
+
int av_get_output_timestamp(struct AVFormatContext *s, int stream,
int64_t *dts, int64_t *wall)
{
--
1.9.1
More information about the ffmpeg-devel
mailing list