summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 8361cd8748..43a7f51a60 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -30,6 +30,7 @@
#include "common/common.h"
#include "common/global.h"
+#include "demux/demux.h"
#include "misc/bstr.h"
#include "misc/thread_tools.h"
#include "common/msg.h"
@@ -51,6 +52,7 @@ extern const stream_info_t stream_info_ffmpeg;
extern const stream_info_t stream_info_ffmpeg_unsafe;
extern const stream_info_t stream_info_avdevice;
extern const stream_info_t stream_info_file;
+extern const stream_info_t stream_info_slice;
extern const stream_info_t stream_info_fd;
extern const stream_info_t stream_info_ifo_dvdnav;
extern const stream_info_t stream_info_dvdnav;
@@ -88,9 +90,9 @@ static const stream_info_t *const stream_list[] = {
&stream_info_mf,
&stream_info_edl,
&stream_info_file,
+ &stream_info_slice,
&stream_info_fd,
&stream_info_cb,
- NULL
};
// Because of guarantees documented on STREAM_BUFFER_SIZE.
@@ -102,7 +104,7 @@ static const stream_info_t *const stream_list[] = {
struct stream_opts {
int64_t buffer_size;
- int load_unsafe_playlists;
+ bool load_unsafe_playlists;
};
#define OPT_BASE_STRUCT struct stream_opts
@@ -111,7 +113,7 @@ const struct m_sub_options stream_conf = {
.opts = (const struct m_option[]){
{"stream-buffer-size", OPT_BYTE_SIZE(buffer_size),
M_RANGE(STREAM_MIN_BUFFER_SIZE, STREAM_MAX_BUFFER_SIZE)},
- {"load-unsafe-playlists", OPT_FLAG(load_unsafe_playlists)},
+ {"load-unsafe-playlists", OPT_BOOL(load_unsafe_playlists)},
{0}
},
.size = sizeof(struct stream_opts),
@@ -352,9 +354,9 @@ static int stream_create_instance(const stream_info_t *sinfo,
if (flags & STREAM_LESS_NOISE)
mp_msg_set_max_level(s->log, MSGL_WARN);
- int opt;
- mp_read_option_raw(s->global, "access-references", &m_option_type_flag, &opt);
- s->access_references = opt;
+ struct demux_opts *demux_opts = mp_get_config_group(s, s->global, &demux_conf);
+ s->access_references = demux_opts->access_references;
+ talloc_free(demux_opts);
MP_VERBOSE(s, "Opening %s\n", url);
@@ -421,7 +423,7 @@ int stream_create_with_args(struct stream_open_args *args, struct stream **ret)
if (args->sinfo) {
r = stream_create_instance(args->sinfo, args, ret);
} else {
- for (int i = 0; stream_list[i]; i++) {
+ for (int i = 0; i < MP_ARRAY_SIZE(stream_list); i++) {
r = stream_create_instance(stream_list[i], args, ret);
if (r == STREAM_OK)
break;
@@ -439,8 +441,7 @@ int stream_create_with_args(struct stream_open_args *args, struct stream **ret)
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");
+ "Use 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 "
@@ -611,11 +612,19 @@ int stream_read(stream_t *s, void *mem, int total)
return total;
}
+// Read ahead so that at least forward_size bytes are readable ahead. Returns
+// the actual forward amount available (restricted by EOF or buffer limits).
+int stream_peek(stream_t *s, int forward_size)
+{
+ while (stream_read_more(s, forward_size)) {}
+ return s->buf_end - s->buf_cur;
+}
+
// Like stream_read(), but do not advance the current position. This may resize
// the buffer to satisfy the read request.
int stream_read_peek(stream_t *s, void *buf, int buf_size)
{
- while (stream_read_more(s, buf_size)) {}
+ stream_peek(s, buf_size);
return ring_copy(s, buf, buf_size, s->buf_cur);
}
@@ -794,7 +803,7 @@ int stream_skip_bom(struct stream *s)
struct bstr stream_read_complete(struct stream *s, void *talloc_ctx,
int max_size)
{
- if (max_size > 1000000000)
+ if (max_size <= 0 || max_size > STREAM_MAX_READ_SIZE)
abort();
int bufsize;
@@ -843,7 +852,7 @@ char **stream_get_proto_list(void)
{
char **list = NULL;
int num = 0;
- for (int i = 0; stream_list[i]; i++) {
+ for (int i = 0; i < MP_ARRAY_SIZE(stream_list); i++) {
const stream_info_t *stream_info = stream_list[i];
if (!stream_info->protocols)
@@ -878,7 +887,7 @@ void stream_print_proto_list(struct mp_log *log)
bool stream_has_proto(const char *proto)
{
- for (int i = 0; stream_list[i]; i++) {
+ for (int i = 0; i < MP_ARRAY_SIZE(stream_list); i++) {
const stream_info_t *stream_info = stream_list[i];
for (int j = 0; stream_info->protocols && stream_info->protocols[j]; j++) {