[FFmpeg-devel] [PATCH 3/3] Deprecate url_exist() and replace all its uses, use url_check() instead.
Stefano Sabatini
stefano.sabatini-lala
Thu Sep 30 17:46:12 CEST 2010
The problem with url_exist() is that it tries to open a file in RDONLY
mode. If the file is a FIFO and there is a reading client, the open()
call will hang, and the ffmpeg process will get stuck.
Using url_check() with no access mode of ~0 check if the file simply
exists without attempting to open it, thus avoiding locks.
Fix issue #1663.
---
ffmpeg.c | 2 +-
ffserver.c | 4 ++--
libavformat/avformat.h | 3 +++
libavformat/avio.c | 2 ++
libavformat/avio.h | 3 +++
libavformat/img2.c | 6 +++---
6 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index d9812be..23cf46c 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3763,7 +3763,7 @@ static void opt_output_file(const char *filename)
(strchr(filename, ':') == NULL ||
filename[1] == ':' ||
av_strstart(filename, "file:", NULL))) {
- if (url_exist(filename)) {
+ if (url_check(filename, 0) != AVERROR(ENOENT)) {
if (!using_stdin) {
fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
fflush(stderr);
diff --git a/ffserver.c b/ffserver.c
index d5d8417..c59c746 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -3669,7 +3669,7 @@ static void build_feed_streams(void)
for(feed = first_feed; feed != NULL; feed = feed->next_feed) {
int fd;
- if (url_exist(feed->feed_filename)) {
+ if (url_check(feed->feed_filename, URL_RDONLY) > 0) {
/* See if it matches */
AVFormatContext *s;
int matches = 0;
@@ -3742,7 +3742,7 @@ static void build_feed_streams(void)
unlink(feed->feed_filename);
}
}
- if (!url_exist(feed->feed_filename)) {
+ if (url_check(feed->feed_filename, URL_RDONLY) <= 0) {
AVFormatContext s1 = {0}, *s = &s1;
if (feed->readonly) {
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 0520530..581e6c6 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -54,6 +54,9 @@
#ifndef FF_API_REGISTER_PROTOCOL
#define FF_API_REGISTER_PROTOCOL (LIBAVFORMAT_VERSION_MAJOR < 53)
#endif
+#ifndef FF_API_URL_EXIST
+#define FF_API_URL_EXIST (LIBAVFORMAT_VERSION_MAJOR < 53)
+#endif
/**
* I return the LIBAVFORMAT_VERSION_INT constant. You got
diff --git a/libavformat/avio.c b/libavformat/avio.c
index ac23d59..befff21 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -276,6 +276,7 @@ int url_close(URLContext *h)
return ret;
}
+#if FF_API_URL_EXIST
int url_exist(const char *filename)
{
URLContext *h;
@@ -284,6 +285,7 @@ int url_exist(const char *filename)
url_close(h);
return 1;
}
+#endif
int url_check(const char *url, int flags)
{
diff --git a/libavformat/avio.h b/libavformat/avio.h
index db5f081..2a4d12e 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -159,11 +159,14 @@ int64_t url_seek(URLContext *h, int64_t pos, int whence);
*/
int url_close(URLContext *h);
+#if FF_API_URL_EXIST
/**
* Return a non-zero value if the resource indicated by url
* exists, 0 otherwise.
*/
+attribute_deprecated
int url_exist(const char *url);
+#endif
/**
* Return a positive value if the resource indicated by url can be
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 7c152cb..8ef70d8 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -129,11 +129,11 @@ static int find_image_range(int *pfirst_index, int *plast_index,
if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
*pfirst_index =
*plast_index = 1;
- if(url_exist(buf))
+ if (url_check(buf, URL_RDONLY) != AVERROR(ENOENT))
return 0;
return -1;
}
- if (url_exist(buf))
+ if (url_check(buf, URL_RDONLY) != AVERROR(ENOENT))
break;
}
if (first_index == 5)
@@ -151,7 +151,7 @@ static int find_image_range(int *pfirst_index, int *plast_index,
if (av_get_frame_filename(buf, sizeof(buf), path,
last_index + range1) < 0)
goto fail;
- if (!url_exist(buf))
+ if (url_check(buf, URL_RDONLY) == AVERROR(ENOENT))
break;
range = range1;
/* just in case... */
--
1.7.1
More information about the ffmpeg-devel
mailing list