Browse code

avio: Add AVIOInterruptCB

This is a better io interrupt callback function, which has an
opaque parameter, which is given to the interrupt callback.

This allows callers to precisely cancel IO for one single
AVFormatContext, without interrupt other ones in the same
process.

Note, it's not needed in AVIOContext, at the moment.

Signed-off-by: Anton Khirnov <anton@khirnov.net>

Martin Storsjö authored on 2011/11/06 21:10:16
Showing 3 changed files
... ...
@@ -994,6 +994,17 @@ typedef struct AVFormatContext {
994 994
      */
995 995
     int error_recognition;
996 996
 
997
+    /**
998
+     * Custom interrupt callbacks for the I/O layer.
999
+     *
1000
+     * decoding: set by the user before avformat_open_input().
1001
+     * encoding: set by the user before avformat_write_header()
1002
+     * (mainly useful for AVFMT_NOFILE formats). The callback
1003
+     * should also be passed to avio_open2() if it's used to
1004
+     * open the file.
1005
+     */
1006
+    AVIOInterruptCB interrupt_callback;
1007
+
997 1008
     /*****************************************************************
998 1009
      * All fields below this line are not part of the public API. They
999 1010
      * may not be used outside of libavformat and can be changed and
... ...
@@ -36,6 +36,22 @@
36 36
 #define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
37 37
 
38 38
 /**
39
+ * Callback for checking whether to abort blocking functions.
40
+ * AVERROR_EXIT is returned in this case by the interrupted
41
+ * function. During blocking operations, callback is called with
42
+ * opaque as parameter. If the callback returns 1, the
43
+ * blocking operation will be aborted.
44
+ *
45
+ * No members can be added to this struct without a major bump, if
46
+ * new elements have been added after this struct in AVFormatContext
47
+ * or AVIOContext.
48
+ */
49
+typedef struct {
50
+    int (*callback)(void*);
51
+    void *opaque;
52
+} AVIOInterruptCB;
53
+
54
+/**
39 55
  * Bytestream IO Context.
40 56
  * New fields can be added to the end with minor version bumps.
41 57
  * Removal, reordering and changes to existing fields require a major
... ...
@@ -109,6 +125,7 @@ typedef struct URLContext {
109 109
     void *priv_data;
110 110
     char *filename; /**< specified URL */
111 111
     int is_connected;
112
+    AVIOInterruptCB interrupt_callback;
112 113
 } URLContext;
113 114
 
114 115
 #define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
... ...
@@ -42,6 +42,7 @@ typedef struct URLContext {
42 42
     int max_packet_size;        /**< if non zero, the stream is packetized with this max packet size */
43 43
     int is_streamed;            /**< true if streamed (no seek possible), default = false */
44 44
     int is_connected;
45
+    AVIOInterruptCB interrupt_callback;
45 46
 } URLContext;
46 47
 
47 48
 typedef struct URLProtocol {