[FFmpeg-devel,v3,06/11] avformat: add avformat_write_abort() function

Submitted by sebechlebskyjan@gmail.com on Aug. 11, 2016, 12:42 p.m.

Details

Message ID 1470919324-3702-1-git-send-email-sebechlebskyjan@gmail.com
State New
Headers show

Commit Message

sebechlebskyjan@gmail.com Aug. 11, 2016, 12:42 p.m.
From: Jan Sebechlebsky <sebechlebskyjan@gmail.com>

Signed-off-by: Jan Sebechlebsky <sebechlebskyjan@gmail.com>
---
 No changes since the last version of the patch, just rebased
 because of the changes in previous patches.

 libavformat/avformat.h | 15 +++++++++++++++
 libavformat/mux.c      | 13 +++++++++++++
 2 files changed, 28 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 2cc3156..83903b5 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 45f1401..0f002a3 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1270,6 +1270,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)
 {