[FFmpeg-devel] [PATCH 1/5] Special case for ff_check_interrupt

Andrey Utkin andrey.krieger.utkin at gmail.com
Wed Jul 10 23:19:04 CEST 2013


If AVIOInterruptCB.callback == INTERRUPT_CHECK_INT, don't call any
function, but read value of int variable pointed by AVIOInterruptCB.opaque.

Based on proposal of Michael Niedermayer
---
 libavformat/avio.c | 8 +++++---
 libavformat/avio.h | 5 +++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index 5916e46..be79c1c 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -429,8 +429,10 @@ int ffurl_shutdown(URLContext *h, int flags)
 
 int ff_check_interrupt(AVIOInterruptCB *cb)
 {
-    int ret;
-    if (cb && cb->callback && (ret = cb->callback(cb->opaque)))
-        return ret;
+    if (cb && cb->callback) {
+        if (cb->callback == INTERRUPT_CHECK_INT)
+            return *(int*)cb->opaque;
+        return cb->callback(cb->opaque);
+    }
     return 0;
 }
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 5bdbc62..caa908e 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -37,12 +37,17 @@
 
 #define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
 
+#define INTERRUPT_CHECK_INT (void*)1 /**< Special value for AVIOInterruptCB.callback */
+
 /**
  * Callback for checking whether to abort blocking functions.
  * AVERROR_EXIT is returned in this case by the interrupted
  * function. During blocking operations, callback is called with
  * opaque as parameter. If the callback returns 1, the
  * blocking operation will be aborted.
+ * Setting `callback` to INTERRUPT_CHECK_INT activates different behaviour:
+ * `opaque` is treated as a pointer to int, blocking operation is interrupted
+ * if *(int*)opaque != 0
  *
  * No members can be added to this struct without a major bump, if
  * new elements have been added after this struct in AVFormatContext
-- 
1.8.1.5



More information about the ffmpeg-devel mailing list