summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/playlist.c17
-rw-r--r--demux/demux.c20
-rw-r--r--demux/demux.h7
-rw-r--r--demux/demux_edl.c23
-rw-r--r--demux/demux_mkv_timeline.c51
-rw-r--r--options/parse_commandline.c3
-rw-r--r--player/loadfile.c12
7 files changed, 55 insertions, 78 deletions
diff --git a/common/playlist.c b/common/playlist.c
index 70206b1cfe..0f6767a3ce 100644
--- a/common/playlist.c
+++ b/common/playlist.c
@@ -270,22 +270,19 @@ struct playlist *playlist_parse_file(const char *file, struct mpv_global *global
struct mp_log *log = mp_log_new(NULL, global->log, "!playlist_parser");
mp_verbose(log, "Parsing playlist file %s...\n", file);
- struct playlist *ret = NULL;
- stream_t *stream = stream_open(file, global);
- if(!stream) {
- mp_err(log, "Error while opening playlist file %s\n", file);
+ struct demuxer_params p = {.force_format = "playlist"};
+ struct demuxer *d = demux_open_url(file, &p, NULL, global);
+ if (!d) {
talloc_free(log);
return NULL;
}
- struct demuxer_params p = {.force_format = "playlist"};
- struct demuxer *pl_demux = demux_open(stream, &p, global);
- if (pl_demux && pl_demux->playlist) {
+ struct playlist *ret = NULL;
+ if (d && d->playlist) {
ret = talloc_zero(NULL, struct playlist);
- playlist_transfer_entries(ret, pl_demux->playlist);
+ playlist_transfer_entries(ret, d->playlist);
}
- free_demuxer(pl_demux);
- free_stream(stream);
+ free_demuxer_and_stream(d);
if (ret) {
mp_verbose(log, "Playlist successfully parsed\n");
diff --git a/demux/demux.c b/demux/demux.c
index a08f633289..21898e3156 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -1039,6 +1039,26 @@ done:
return demuxer;
}
+// Convenience function: open the stream, enable the cache (according to params
+// and global opts.), open the demuxer.
+// (use free_demuxer_and_stream() to free the underlying stream too)
+struct demuxer *demux_open_url(const char *url,
+ struct demuxer_params *params,
+ struct mp_cancel *cancel,
+ struct mpv_global *global)
+{
+ struct MPOpts *opts = global->opts;
+ struct stream *s = stream_create(url, STREAM_READ, cancel, global);
+ if (!s)
+ return NULL;
+ if (!(params && params->disable_cache))
+ stream_enable_cache(&s, &opts->stream_cache);
+ struct demuxer *d = demux_open(s, params, global);
+ if (!d)
+ free_stream(s);
+ return d;
+}
+
static void flush_locked(demuxer_t *demuxer)
{
for (int n = 0; n < demuxer->num_streams; n++)
diff --git a/demux/demux.h b/demux/demux.h
index b76fb8fedc..b6aa4af517 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -172,6 +172,7 @@ struct demuxer_params {
int matroska_wanted_segment;
bool *matroska_was_valid;
bool expect_subtitle;
+ bool disable_cache; // demux_open_url() only
};
typedef struct demuxer {
@@ -259,6 +260,12 @@ struct sh_stream *new_sh_stream(struct demuxer *demuxer, enum stream_type type);
struct demuxer *demux_open(struct stream *stream, struct demuxer_params *params,
struct mpv_global *global);
+struct mp_cancel;
+struct demuxer *demux_open_url(const char *url,
+ struct demuxer_params *params,
+ struct mp_cancel *cancel,
+ struct mpv_global *global);
+
void demux_start_thread(struct demuxer *demuxer);
void demux_stop_thread(struct demuxer *demuxer);
void demux_set_wakeup_cb(struct demuxer *demuxer, void (*cb)(void *ctx), void *ctx);
diff --git a/demux/demux_edl.c b/demux/demux_edl.c
index ba88e6a3d5..7986489397 100644
--- a/demux/demux_edl.c
+++ b/demux/demux_edl.c
@@ -134,22 +134,6 @@ error:
return NULL;
}
-static struct demuxer *open_file(char *filename, struct timeline *tl)
-{
- struct MPOpts *opts = tl->global->opts;
- struct demuxer *d = NULL;
- struct stream *s = stream_open(filename, tl->global);
- if (s) {
- stream_enable_cache(&s, &opts->stream_cache);
- d = demux_open(s, NULL, tl->global);
- }
- if (!d) {
- MP_ERR(tl, "EDL: Could not open source file '%s'.\n", filename);
- free_stream(s);
- }
- return d;
-}
-
static struct demuxer *open_source(struct timeline *tl, char *filename)
{
for (int n = 0; n < tl->num_sources; n++) {
@@ -157,9 +141,12 @@ static struct demuxer *open_source(struct timeline *tl, char *filename)
if (strcmp(d->stream->url, filename) == 0)
return d;
}
- struct demuxer *d = open_file(filename, tl);
- if (d)
+ struct demuxer *d = demux_open_url(filename, NULL, NULL, tl->global);
+ if (d) {
MP_TARRAY_APPEND(tl, tl->sources, tl->num_sources, d);
+ } else {
+ MP_ERR(tl, "EDL: Could not open source file '%s'.\n", filename);
+ }
return d;
}
diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c
index 64d4583979..71f5b16031 100644
--- a/demux/demux_mkv_timeline.c
+++ b/demux/demux_mkv_timeline.c
@@ -148,36 +148,6 @@ static char **find_files(const char *original_file)
return results;
}
-static int enable_cache(struct mpv_global *global, struct stream **stream,
- struct demuxer **demuxer, struct demuxer_params *params)
-{
- struct MPOpts *opts = global->opts;
-
- if (!stream_wants_cache(*stream, &opts->stream_cache))
- return 0;
-
- char *filename = talloc_strdup(NULL, (*demuxer)->filename);
-
- free_demuxer_and_stream(*demuxer);
- *stream = stream_open(filename, global);
- if (!*stream) {
- talloc_free(filename);
- return -1;
- }
-
- stream_enable_cache(stream, &opts->stream_cache);
-
- *demuxer = demux_open(*stream, params, global);
- if (!*demuxer) {
- talloc_free(filename);
- free_stream(*stream);
- return -1;
- }
-
- talloc_free(filename);
- return 1;
-}
-
static bool has_source_request(struct matroska_segment_uid *uids,
int num_sources,
struct matroska_segment_uid *new_uid)
@@ -202,16 +172,11 @@ static bool check_file_seg(struct tl_ctx *ctx, struct demuxer ***sources,
.matroska_wanted_uids = *uids,
.matroska_wanted_segment = segment,
.matroska_was_valid = &was_valid,
+ .disable_cache = true,
};
- struct stream *s = stream_open(filename, ctx->global);
- if (!s)
+ struct demuxer *d = demux_open_url(filename, &params, NULL, ctx->global);
+ if (!d)
return false;
- struct demuxer *d = demux_open(s, &params, ctx->global);
-
- if (!d) {
- free_stream(s);
- return was_valid;
- }
struct matroska_data *m = &d->matroska_data;
@@ -243,8 +208,14 @@ static bool check_file_seg(struct tl_ctx *ctx, struct demuxer ***sources,
MP_TARRAY_APPEND(NULL, *sources, *num_sources, NULL);
}
- if (enable_cache(ctx->global, &s, &d, &params) < 0)
- continue;
+ if (stream_wants_cache(d->stream, &ctx->global->opts->stream_cache))
+ {
+ free_demuxer_and_stream(d);
+ params.disable_cache = false;
+ d = demux_open_url(filename, &params, NULL, ctx->global);
+ if (!d)
+ continue;
+ }
(*sources)[i] = d;
return true;
diff --git a/options/parse_commandline.c b/options/parse_commandline.c
index 424b8fc0c3..90675c7e01 100644
--- a/options/parse_commandline.c
+++ b/options/parse_commandline.c
@@ -209,7 +209,8 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
struct playlist *pl = playlist_parse_file(param0, global);
talloc_free(param0);
if (!pl) {
- MP_FATAL(config, "Error reading playlist '%.*s'", BSTR_P(p.param));
+ MP_FATAL(config, "Error reading playlist '%.*s'\n",
+ BSTR_P(p.param));
goto err_out;
}
playlist_transfer_entries(files, pl);
diff --git a/player/loadfile.c b/player/loadfile.c
index 66f114b606..b16f1026aa 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -684,11 +684,6 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
if (strncmp(disp_filename, "memory://", 9) == 0)
disp_filename = "memory://"; // avoid noise
- struct stream *stream = stream_open(filename, mpctx->global);
- if (!stream)
- goto err_out;
- stream_enable_cache(&stream, &opts->stream_cache);
-
struct demuxer_params params = {
.expect_subtitle = filter == STREAM_SUB,
};
@@ -702,11 +697,10 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
break;
}
- struct demuxer *demuxer = demux_open(stream, &params, mpctx->global);
- if (!demuxer) {
- free_stream(stream);
+ struct demuxer *demuxer =
+ demux_open_url(filename, &params, mpctx->playback_abort, mpctx->global);
+ if (!demuxer)
goto err_out;
- }
struct track *first = NULL;
for (int n = 0; n < demuxer->num_streams; n++) {