diff mbox series

[FFmpeg-devel,03/10] lavfi: add fs protocol as synonym for file.

Message ID 20210727144813.452917-4-george@nsup.org
State New
Headers show
Series [FFmpeg-devel,01/10] lavu/internal: add hex to int functions. | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Nicolas George July 27, 2021, 2:48 p.m. UTC
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavformat/file.c      | 47 ++++++++++++++++++++++++++++++++++++-----
 libavformat/protocols.c |  1 +
 2 files changed, 43 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/file.c b/libavformat/file.c
index 8303436be0..2fb93c23fd 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -203,17 +203,15 @@  static int file_move(URLContext *h_src, URLContext *h_dst)
     return 0;
 }
 
-#if CONFIG_FILE_PROTOCOL
+#if CONFIG_FILE_PROTOCOL || CONFIG_FS_PROTOCOL
 
-static int file_open(URLContext *h, const char *filename, int flags)
+static int file_open_common(URLContext *h, const char *filename, int flags)
 {
     FileContext *c = h->priv_data;
     int access;
     int fd;
     struct stat st;
 
-    av_strstart(filename, "file:", &filename);
-
     if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) {
         access = O_CREAT | O_RDWR;
         if (c->trunc)
@@ -353,6 +351,16 @@  static int file_close_dir(URLContext *h)
 #endif /* HAVE_LSTAT */
 }
 
+#endif /* CONFIG_FILE_PROTOCOL || CONFIG_FS_PROTOCOL */
+
+#if CONFIG_FILE_PROTOCOL
+
+static int file_open(URLContext *h, const char *filename, int flags)
+{
+    av_strstart(filename, "file:", &filename);
+    return file_open_common(h, filename, flags);
+}
+
 const URLProtocol ff_file_protocol = {
     .name                = "file",
     .url_open            = file_open,
@@ -369,11 +377,40 @@  const URLProtocol ff_file_protocol = {
     .url_open_dir        = file_open_dir,
     .url_read_dir        = file_read_dir,
     .url_close_dir       = file_close_dir,
-    .default_whitelist   = "file,crypto,data"
+    .default_whitelist   = "file,fs,crypto,data"
 };
 
 #endif /* CONFIG_FILE_PROTOCOL */
 
+#if CONFIG_FS_PROTOCOL
+
+static int fs_open(URLContext *h, const char *filename, int flags)
+{
+    av_strstart(filename, "fs:", &filename);
+    return file_open_common(h, filename, flags);
+}
+
+const URLProtocol ff_fs_protocol = {
+    .name                = "fs",
+    .url_open            = fs_open,
+    .url_read            = file_read,
+    .url_write           = file_write,
+    .url_seek            = file_seek,
+    .url_close           = file_close,
+    .url_get_file_handle = file_get_handle,
+    .url_check           = file_check,
+    .url_delete          = file_delete,
+    .url_move            = file_move,
+    .priv_data_size      = sizeof(FileContext),
+    .priv_data_class     = &file_class,
+    .url_open_dir        = file_open_dir,
+    .url_read_dir        = file_read_dir,
+    .url_close_dir       = file_close_dir,
+    .default_whitelist   = "file,fs,crypto,data"
+};
+
+#endif /* CONFIG_FS_PROTOCOL */
+
 #if CONFIG_PIPE_PROTOCOL
 
 static int pipe_open(URLContext *h, const char *filename, int flags)
diff --git a/libavformat/protocols.c b/libavformat/protocols.c
index 7f08f151b6..a0035da590 100644
--- a/libavformat/protocols.c
+++ b/libavformat/protocols.c
@@ -33,6 +33,7 @@  extern const URLProtocol ff_data_protocol;
 extern const URLProtocol ff_ffrtmpcrypt_protocol;
 extern const URLProtocol ff_ffrtmphttp_protocol;
 extern const URLProtocol ff_file_protocol;
+extern const URLProtocol ff_fs_protocol;
 extern const URLProtocol ff_ftp_protocol;
 extern const URLProtocol ff_gopher_protocol;
 extern const URLProtocol ff_gophers_protocol;