summaryrefslogtreecommitdiffstats
path: root/stream/stream_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'stream/stream_file.c')
-rw-r--r--stream/stream_file.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/stream/stream_file.c b/stream/stream_file.c
index ec801cd82f..89e7a2d9f1 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -50,6 +50,7 @@
#ifdef _WIN32
#include <windows.h>
+#include <winioctl.h>
#include <winternl.h>
#include <io.h>
@@ -176,7 +177,7 @@ static bool check_stream_network(int fd)
{
struct statfs fs;
const char *stypes[] = { "afpfs", "nfs", "smbfs", "webdav", "osxfusefs",
- "fuse", "fusefs.sshfs", NULL };
+ "fuse", "fusefs.sshfs", "macfuse", NULL };
if (fstatfs(fd, &fs) == 0)
for (int i=0; stypes[i]; i++)
if (strcmp(stypes[i], fs.f_fstypename) == 0)
@@ -246,7 +247,7 @@ static bool check_stream_network(int fd)
}
#endif
-static int open_f(stream_t *stream)
+static int open_f(stream_t *stream, const struct stream_open_args *args)
{
struct priv *p = talloc_ptrtype(stream, p);
*p = (struct priv) {
@@ -255,18 +256,21 @@ static int open_f(stream_t *stream)
stream->priv = p;
stream->is_local_file = true;
+ bool strict_fs = args->flags & STREAM_LOCAL_FS_ONLY;
bool write = stream->mode == STREAM_WRITE;
int m = O_CLOEXEC | (write ? O_RDWR | O_CREAT | O_TRUNC : O_RDONLY);
- char *filename = mp_file_url_to_filename(stream, bstr0(stream->url));
- if (filename) {
- stream->path = filename;
- } else {
- filename = stream->path;
+ char *filename = stream->path;
+ char *url = "";
+ if (!strict_fs) {
+ char *fn = mp_file_url_to_filename(stream, bstr0(stream->url));
+ if (fn)
+ filename = stream->path = fn;
+ url = stream->url;
}
- bool is_fdclose = strncmp(stream->url, "fdclose://", 10) == 0;
- if (strncmp(stream->url, "fd://", 5) == 0 || is_fdclose) {
+ bool is_fdclose = strncmp(url, "fdclose://", 10) == 0;
+ if (strncmp(url, "fd://", 5) == 0 || is_fdclose) {
char *begin = strstr(stream->url, "://") + 3, *end = NULL;
p->fd = strtol(begin, &end, 0);
if (!end || end == begin || end[0]) {
@@ -275,7 +279,7 @@ static int open_f(stream_t *stream)
}
if (is_fdclose)
p->close = true;
- } else if (!strcmp(filename, "-")) {
+ } else if (!strict_fs && !strcmp(filename, "-")) {
if (!write) {
MP_INFO(stream, "Reading from stdin...\n");
p->fd = 0;
@@ -303,10 +307,12 @@ static int open_f(stream_t *stream)
}
struct stat st;
+ bool is_sock_or_fifo = false;
if (fstat(p->fd, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
stream->is_directory = true;
- MP_INFO(stream, "This is a directory - adding to playlist.\n");
+ if (!(args->flags & STREAM_LESS_NOISE))
+ MP_INFO(stream, "This is a directory - adding to playlist.\n");
} else if (S_ISREG(st.st_mode)) {
p->regular_file = true;
#ifndef __MINGW32__
@@ -315,6 +321,9 @@ static int open_f(stream_t *stream)
fcntl(p->fd, F_SETFL, val);
#endif
} else {
+#ifndef __MINGW32__
+ is_sock_or_fifo = S_ISSOCK(st.st_mode) || S_ISFIFO(st.st_mode);
+#endif
p->use_poll = true;
}
}
@@ -336,8 +345,15 @@ static int open_f(stream_t *stream)
stream->get_size = get_size;
stream->close = s_close;
- if (check_stream_network(p->fd))
+ if (is_sock_or_fifo || check_stream_network(p->fd)) {
stream->streaming = true;
+#if HAVE_COCOA
+ if (fcntl(p->fd, F_RDAHEAD, 0) < 0) {
+ MP_VERBOSE(stream, "Cannot disable read ahead on file '%s': %s\n",
+ filename, mp_strerror(errno));
+ }
+#endif
+ }
p->orig_size = get_size(stream);
@@ -350,9 +366,17 @@ static int open_f(stream_t *stream)
const stream_info_t stream_info_file = {
.name = "file",
- .open = open_f,
- .protocols = (const char*const[]){ "file", "", "fd", "fdclose",
- "appending", NULL },
+ .open2 = open_f,
+ .protocols = (const char*const[]){ "file", "", "appending", NULL },
.can_write = true,
+ .local_fs = true,
.stream_origin = STREAM_ORIGIN_FS,
};
+
+const stream_info_t stream_info_fd = {
+ .name = "fd",
+ .open2 = open_f,
+ .protocols = (const char*const[]){ "fd", "fdclose", NULL },
+ .can_write = true,
+ .stream_origin = STREAM_ORIGIN_UNSAFE,
+};