summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-09-29 00:45:41 +0200
committerwm4 <wm4@nowhere>2019-09-29 00:46:54 +0200
commit2bb5ab07b7ee09fb7ae0e90a74c1e8e5adcc3d59 (patch)
treece765b9b553e40890faba658243191542b8f5068 /stream/stream.c
parenta7158ceec00f14e680a885722cfe23761b4662d3 (diff)
downloadmpv-2bb5ab07b7ee09fb7ae0e90a74c1e8e5adcc3d59.tar.bz2
mpv-2bb5ab07b7ee09fb7ae0e90a74c1e8e5adcc3d59.tar.xz
stream: rearrange open functions
Add yet another variant of the stream open function. This time, make it so that it's possible to add new open parameters in an extendable way, which should put an end to having to change this every other year. Effectively get rid of the overly special stream_create_instance() function and use the new one instead, which requires changes in stream_concat.c and stream_memory.c. The function is still in private in stream.c, but I preferred to make the mentioned users go through the new function for orthogonality. The error handling (mostly logging) was adjusted accordingly. This should not have any functional changes. (To preempt any excuses, I didn't actually test stream_concat and stream_memory.)
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c101
1 files changed, 59 insertions, 42 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 61dbf8ce6c..36b08803b3 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -213,10 +213,13 @@ static void stream_resize_buffer(struct stream *s, int new)
}
}
-int stream_create_instance(const stream_info_t *sinfo, const char *url, int flags,
- struct mp_cancel *c, struct mpv_global *global,
- void *arg, struct stream **ret)
+static int stream_create_instance(const stream_info_t *sinfo,
+ struct stream_open_args *args,
+ struct stream **ret)
{
+ const char *url = args->url;
+ int flags = args->flags;
+
*ret = NULL;
if (!sinfo->is_safe && (flags & STREAM_SAFE_ONLY))
@@ -235,21 +238,21 @@ int stream_create_instance(const stream_info_t *sinfo, const char *url, int flag
return STREAM_NO_MATCH;
stream_t *s = talloc_zero(NULL, stream_t);
+ s->global = args->global;
if (flags & STREAM_SILENT) {
s->log = mp_null_log;
} else {
- s->log = mp_log_new(s, global->log, sinfo->name);
+ s->log = mp_log_new(s, s->global->log, sinfo->name);
}
s->info = sinfo;
- s->cancel = c;
- s->global = global;
+ s->cancel = args->cancel;
s->url = talloc_strdup(s, url);
s->path = talloc_strdup(s, path);
s->is_network = sinfo->is_network;
s->mode = flags & (STREAM_READ | STREAM_WRITE);
int opt;
- mp_read_option_raw(global, "access-references", &m_option_type_flag, &opt);
+ mp_read_option_raw(s->global, "access-references", &m_option_type_flag, &opt);
s->access_references = opt;
MP_VERBOSE(s, "Opening %s\n", url);
@@ -268,8 +271,8 @@ int stream_create_instance(const stream_info_t *sinfo, const char *url, int flag
int r = STREAM_UNSUPPORTED;
if (sinfo->open2) {
- r = sinfo->open2(s, arg);
- } else if (!arg) {
+ r = sinfo->open2(s, args);
+ } else if (!args->special_arg) {
r = (sinfo->open)(s);
}
if (r != STREAM_OK) {
@@ -294,49 +297,63 @@ int stream_create_instance(const stream_info_t *sinfo, const char *url, int flag
return STREAM_OK;
}
-struct stream *stream_create(const char *url, int flags,
- struct mp_cancel *c, struct mpv_global *global)
+int stream_create_with_args(struct stream_open_args *args, struct stream **ret)
+
{
- struct mp_log *log = mp_log_new(NULL, global->log, "!stream");
- struct stream *s = NULL;
- assert(url);
+ assert(args->url);
+
+ int r = STREAM_NO_MATCH;
+ *ret = NULL;
// Open stream proper
- bool unsafe = false;
- for (int i = 0; stream_list[i]; i++) {
- int r = stream_create_instance(stream_list[i], url, flags, c, global,
- NULL, &s);
- if (r == STREAM_OK)
+ if (args->sinfo) {
+ r = stream_create_instance(args->sinfo, args, ret);
+ } else {
+ for (int i = 0; stream_list[i]; i++) {
+ r = stream_create_instance(stream_list[i], args, ret);
+ if (r == STREAM_OK)
+ break;
+ if (r == STREAM_NO_MATCH || r == STREAM_UNSUPPORTED)
+ continue;
+ if (r == STREAM_UNSAFE)
+ continue;
break;
- if (r == STREAM_NO_MATCH || r == STREAM_UNSUPPORTED)
- continue;
- if (r == STREAM_UNSAFE) {
- unsafe = true;
- continue;
- }
- if (r != STREAM_OK) {
- if (!mp_cancel_test(c))
- mp_err(log, "Failed to open %s.\n", url);
- goto done;
}
}
- if (!s && unsafe) {
- mp_err(log, "\nRefusing to load potentially unsafe URL from a playlist.\n"
- "Use --playlist=file or the --load-unsafe-playlists option to "
- "load it anyway.\n\n");
- goto done;
- }
+ if (!*ret && !(args->flags & STREAM_SILENT) && !mp_cancel_test(args->cancel))
+ {
+ struct mp_log *log = mp_log_new(NULL, args->global->log, "!stream");
+
+ if (r == STREAM_UNSAFE) {
+ mp_err(log, "\nRefusing to load potentially unsafe URL from a playlist.\n"
+ "Use --playlist=file or the --load-unsafe-playlists option to "
+ "load it anyway.\n\n");
+ } else if (r == STREAM_NO_MATCH || r == STREAM_UNSUPPORTED) {
+ mp_err(log, "No protocol handler found to open URL %s\n", args->url);
+ mp_err(log, "The protocol is either unsupported, or was disabled "
+ "at compile-time.\n");
+ } else {
+ mp_err(log, "Failed to open %s.\n", args->url);
+ }
- if (!s) {
- mp_err(log, "No protocol handler found to open URL %s\n", url);
- mp_err(log, "The protocol is either unsupported, or was disabled "
- "at compile-time.\n");
- goto done;
+ talloc_free(log);
}
-done:
- talloc_free(log);
+ return r;
+}
+
+struct stream *stream_create(const char *url, int flags,
+ struct mp_cancel *c, struct mpv_global *global)
+{
+ struct stream_open_args args = {
+ .global = global,
+ .cancel = c,
+ .flags = flags,
+ .url = url,
+ };
+ struct stream *s;
+ stream_create_with_args(&args, &s);
return s;
}