[FFmpeg-cvslog] avio: add avio_check()

Stefano Sabatini git at videolan.org
Thu Apr 14 03:24:36 CEST 2011


ffmpeg | branch: master | Stefano Sabatini <stefano.sabatini-lala at poste.it> | Fri Apr  8 18:32:25 2011 +0200| [175389c85487822f1ee180ee01cc770df896557f] | committer: Anton Khirnov

avio: add avio_check()

The new function is more flexible than url_exist(), as it allows to
specify which access flags to check, and does not require an explicit
open of the checked resource.

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

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=175389c85487822f1ee180ee01cc770df896557f
---

 libavformat/avio.c |   19 +++++++++++++++++++
 libavformat/avio.h |   18 ++++++++++++++++++
 libavformat/url.h  |    1 +
 3 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index ad1f1b4..18b2ee6 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -374,6 +374,25 @@ int url_exist(const char *filename)
     return 1;
 }
 
+int avio_check(const char *url, int flags)
+{
+    URLContext *h;
+    int ret = ffurl_alloc(&h, url, flags);
+    if (ret)
+        return ret;
+
+    if (h->prot->url_check) {
+        ret = h->prot->url_check(h, flags);
+    } else {
+        ret = ffurl_connect(h);
+        if (ret >= 0)
+            ret = flags;
+    }
+
+    ffurl_close(h);
+    return ret;
+}
+
 int64_t ffurl_size(URLContext *h)
 {
     int64_t pos, size;
diff --git a/libavformat/avio.h b/libavformat/avio.h
index a4109a2..14aa599 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -134,6 +134,7 @@ typedef struct URLProtocol {
     int priv_data_size;
     const AVClass *priv_data_class;
     int flags;
+    int (*url_check)(URLContext *h, int mask);
 } URLProtocol;
 
 typedef struct URLPollEntry {
@@ -347,6 +348,23 @@ attribute_deprecated int url_close_buf(AVIOContext *s);
 int url_exist(const char *url);
 
 /**
+ * Return AVIO_* access flags corresponding to the access permissions
+ * of the resource in url, or a negative value corresponding to an
+ * AVERROR code in case of failure. The returned access flags are
+ * masked by the value in flags.
+ *
+ * @note This function is intrinsically unsafe, in the sense that the
+ * checked resource may change its existence or permission status from
+ * one call to another. Thus you should not trust the returned value,
+ * unless you are sure that no other processes are accessing the
+ * checked resource.
+ *
+ * @note This function is slightly broken until next major bump
+ *       because of AVIO_RDONLY == 0. Don't use it until then.
+ */
+int avio_check(const char *url, int flags);
+
+/**
  * The callback is called in blocking functions to test regulary if
  * asynchronous interruption is needed. AVERROR_EXIT is returned
  * in this case by the interrupted function. 'NULL' means no interrupt
diff --git a/libavformat/url.h b/libavformat/url.h
index bde06d9..c5732c6 100644
--- a/libavformat/url.h
+++ b/libavformat/url.h
@@ -59,6 +59,7 @@ typedef struct URLProtocol {
     int priv_data_size;
     const AVClass *priv_data_class;
     int flags;
+    int (*url_check)(URLContext *h, int mask);
 } URLProtocol;
 #endif
 



More information about the ffmpeg-cvslog mailing list