From e40885d963f8b60d83aa5ea8104985dd20af262f Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 19 Jun 2019 16:48:46 +0200 Subject: stream: create memory streams in more straightforward way Instead of having to rely on the protocol matching, make a function that creates a stream from a stream_info_t directly. Instead of going through a weird indirection with STREAM_CTRL, add a direct argument for non-text arguments to the open callback. Instead of creating a weird dummy mpv_global, just pass an existing one from all callers. (The latter one is just an artifact from the past, where mpv_global wasn't available everywhere.) Actually I just wanted a function that creates a stream without any of that bullshit. This goal was slightly missed, since you still need this heavy "constructor" just to setup a shitty struct with some shitty callbacks. --- stream/stream.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'stream/stream.h') diff --git a/stream/stream.h b/stream/stream.h index 8bd8ecfc01..4bd6a7b713 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -37,6 +37,7 @@ // flags for stream_open_ext (this includes STREAM_READ and STREAM_WRITE) #define STREAM_SAFE_ONLY 4 #define STREAM_NETWORK_ONLY 8 +#define STREAM_SILENT 16 #define STREAM_UNSAFE -3 #define STREAM_NO_MATCH -2 @@ -47,9 +48,6 @@ enum stream_ctrl { STREAM_CTRL_GET_SIZE = 1, - // stream_memory.c - STREAM_CTRL_SET_CONTENTS, - // Certain network protocols STREAM_CTRL_AVSEEK, STREAM_CTRL_HAS_AVSEEK, @@ -72,6 +70,8 @@ typedef struct stream_info_st { const char *name; // opts is set from ->opts int (*open)(struct stream *st); + // Alternative to open(). Only either open() or open2() can be set. + int (*open2)(struct stream *st, void *arg); const char *const *protocols; bool can_write; // correctly checks for READ/WRITE modes bool is_safe; // opening is no security issue, even with remote provided URLs @@ -165,15 +165,20 @@ struct bstr stream_read_file(const char *filename, void *talloc_ctx, struct mpv_global *global, int max_size); int stream_control(stream_t *s, int cmd, void *arg); void free_stream(stream_t *s); +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); struct stream *stream_create(const char *url, int flags, struct mp_cancel *c, struct mpv_global *global); struct stream *stream_open(const char *filename, struct mpv_global *global); stream_t *open_output_stream(const char *filename, struct mpv_global *global); -stream_t *open_memory_stream(void *data, int len); void mp_url_unescape_inplace(char *buf); char *mp_url_escape(void *talloc_ctx, const char *s, const char *ok); +// stream_memory.c +struct stream *stream_memory_open(struct mpv_global *global, void *data, int len); + // stream_file.c char *mp_file_url_to_filename(void *talloc_ctx, bstr url); char *mp_file_get_path(void *talloc_ctx, bstr url); -- cgit v1.2.3