summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-02-02 18:24:27 +0100
committerwm4 <wm4@nowhere>2017-02-02 18:26:58 +0100
commitfb9a32977d6abf4c83a92d993af58e393819c062 (patch)
treedaa8fac391c393560588ce8653943a8259f59815
parente13a62fc346867450cd41d02cffbdaf477a3fec4 (diff)
downloadmpv-fb9a32977d6abf4c83a92d993af58e393819c062.tar.bz2
mpv-fb9a32977d6abf4c83a92d993af58e393819c062.tar.xz
stream: get rid of streamtype enum
Because it's kind of dumb. (But not sure if it was worth the trouble.) For stream_file.c, we add new explicit fields. The rest are rather special uses and can be killed by comparing the stream impl. name. The changes to DVD/BD/CD/TV are entirely untested.
-rw-r--r--demux/demux_disc.c28
-rw-r--r--demux/demux_edl.c8
-rw-r--r--demux/demux_lavf.c7
-rw-r--r--demux/demux_mf.c5
-rw-r--r--demux/demux_mkv_timeline.c2
-rw-r--r--demux/demux_playlist.c2
-rw-r--r--demux/demux_tv.c5
-rw-r--r--stream/stream.c5
-rw-r--r--stream/stream.h18
-rw-r--r--stream/stream_avdevice.c2
-rw-r--r--stream/stream_bluray.c1
-rw-r--r--stream/stream_cdda.c1
-rw-r--r--stream/stream_dvb.c1
-rw-r--r--stream/stream_dvd.c1
-rw-r--r--stream/stream_dvdnav.c3
-rw-r--r--stream/stream_edl.c2
-rw-r--r--stream/stream_file.c4
-rw-r--r--stream/stream_mf.c1
-rw-r--r--stream/stream_tv.c1
19 files changed, 47 insertions, 50 deletions
diff --git a/demux/demux_disc.c b/demux/demux_disc.c
index 805ba4ccff..ad54db8c19 100644
--- a/demux/demux_disc.c
+++ b/demux/demux_disc.c
@@ -43,6 +43,8 @@ struct priv {
double base_dts; // packet DTS that maps to base_time
double last_dts; // DTS of previously demuxed packet
bool seek_reinit; // needs reinit after seek
+
+ bool is_dvd, is_cdda;
};
// If the timestamp difference between subsequent packets is this big, assume
@@ -65,7 +67,7 @@ static void reselect_streams(demuxer_t *demuxer)
static void get_disc_lang(struct stream *stream, struct sh_stream *sh)
{
struct stream_lang_req req = {.type = sh->type, .id = sh->demuxer_id};
- if (stream->uncached_type == STREAMTYPE_DVD && sh->type == STREAM_SUB)
+ if (sh->type == STREAM_SUB)
req.id = req.id & 0x1F; // mpeg ID to index
stream_control(stream, STREAM_CTRL_GET_LANG, &req);
if (req.name[0])
@@ -76,7 +78,7 @@ static void add_dvd_streams(demuxer_t *demuxer)
{
struct priv *p = demuxer->priv;
struct stream *stream = demuxer->stream;
- if (stream->uncached_type != STREAMTYPE_DVD)
+ if (!p->is_dvd)
return;
struct stream_dvd_info_req info;
if (stream_control(stream, STREAM_CTRL_GET_DVD_INFO, &info) > 0) {
@@ -162,7 +164,7 @@ static void d_seek(demuxer_t *demuxer, double seek_pts, int flags)
{
struct priv *p = demuxer->priv;
- if (demuxer->stream->uncached_type == STREAMTYPE_CDDA) {
+ if (p->is_cdda) {
demux_seek(p->slave, seek_pts, flags);
return;
}
@@ -222,7 +224,7 @@ static int d_fill_buffer(demuxer_t *demuxer)
return 1;
}
- if (demuxer->stream->uncached_type == STREAMTYPE_CDDA) {
+ if (p->is_cdda) {
demux_add_packet(sh, pkt);
return 1;
}
@@ -285,7 +287,21 @@ static int d_open(demuxer_t *demuxer, enum demux_check check)
struct demuxer_params params = {.force_format = "+lavf"};
- if (demuxer->stream->uncached_type == STREAMTYPE_CDDA)
+ struct stream *cur = demuxer->stream;
+ const char *sname = "";
+ while (cur) {
+ if (cur->info)
+ sname = cur->info->name;
+ cur = cur->underlying; // down the caching chain
+ }
+
+ p->is_cdda = strcmp(sname, "cdda") == 0;
+ p->is_dvd = strcmp(sname, "dvd") == 0 ||
+ strcmp(sname, "ifo") == 0 ||
+ strcmp(sname, "dvdnav") == 0 ||
+ strcmp(sname, "ifo_dvdnav") == 0;
+
+ if (p->is_cdda)
params.force_format = "+rawaudio";
char *t = NULL;
@@ -311,7 +327,7 @@ static int d_open(demuxer_t *demuxer, enum demux_check check)
// (actually libavformat/mpegts.c) to seek sometimes when reading a packet.
// It does this to seek back a bit in case the current file position points
// into the middle of a packet.
- if (demuxer->stream->uncached_type != STREAMTYPE_CDDA) {
+ if (!p->is_cdda) {
demuxer->stream->seekable = false;
// Can be seekable even if the stream isn't.
diff --git a/demux/demux_edl.c b/demux/demux_edl.c
index 623cae35b3..240c224ab7 100644
--- a/demux/demux_edl.c
+++ b/demux/demux_edl.c
@@ -50,6 +50,7 @@ struct tl_parts {
struct priv {
bstr data;
+ bool allow_any;
};
// Parse a time (absolute file time or duration). Currently equivalent to a
@@ -286,8 +287,7 @@ static void build_mpv_edl_timeline(struct timeline *tl)
return;
}
MP_TARRAY_APPEND(tl, tl->sources, tl->num_sources, tl->demuxer);
- // Source is .edl and not edl:// => don't allow arbitrary paths
- if (tl->demuxer->stream->uncached_type != STREAMTYPE_EDL)
+ if (!p->allow_any)
fix_filenames(parts, tl->demuxer->filename);
build_timeline(tl, parts);
talloc_free(parts);
@@ -303,8 +303,10 @@ static int try_open_file(struct demuxer *demuxer, enum demux_check check)
demuxer->fully_read = true;
struct stream *s = demuxer->stream;
- if (s->uncached_type == STREAMTYPE_EDL) {
+ if (s->info && strcmp(s->info->name, "edl") == 0) {
p->data = bstr0(s->path);
+ // Source is edl:// and not .edl => allow arbitrary paths
+ p->allow_any = true;
return 0;
}
if (check >= DEMUX_CHECK_UNSAFE) {
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index 124956378c..50391a29da 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -338,7 +338,7 @@ static int lavf_check_file(demuxer_t *demuxer, enum demux_check check)
priv->filename = remove_prefix(s->url, prefixes);
char *avdevice_format = NULL;
- if (s->uncached_type == STREAMTYPE_AVDEVICE) {
+ if (s->info && strcmp(s->info->name, "avdevice") == 0) {
// always require filename in the form "format:filename"
char *sep = strchr(priv->filename, ':');
if (!sep) {
@@ -808,10 +808,7 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
AVDictionary *dopts = NULL;
- if ((priv->avif_flags & AVFMT_NOFILE) ||
- priv->stream->type == STREAMTYPE_AVDEVICE ||
- priv->format_hack.no_stream)
- {
+ if ((priv->avif_flags & AVFMT_NOFILE) || priv->format_hack.no_stream) {
mp_setup_av_network_options(&dopts, demuxer->global, demuxer->log);
// This might be incorrect.
demuxer->seekable = true;
diff --git a/demux/demux_mf.c b/demux/demux_mf.c
index 4abd394317..50afd355b7 100644
--- a/demux/demux_mf.c
+++ b/demux/demux_mf.c
@@ -294,9 +294,10 @@ static int demux_open_mf(demuxer_t *demuxer, enum demux_check check)
mf_t *mf;
if (strncmp(demuxer->stream->url, "mf://", 5) == 0 &&
- demuxer->stream->type == STREAMTYPE_MF)
+ demuxer->stream->info && strcmp(demuxer->stream->info->name, "mf") == 0)
+ {
mf = open_mf_pattern(demuxer, demuxer->log, demuxer->stream->url + 5);
- else {
+ } else {
mf = open_mf_single(demuxer, demuxer->log, demuxer->stream->url);
int bog = 0;
MP_TARRAY_APPEND(mf, mf->streams, bog, demuxer->stream);
diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c
index 476551c58b..de7b2e0853 100644
--- a/demux/demux_mkv_timeline.c
+++ b/demux/demux_mkv_timeline.c
@@ -267,7 +267,7 @@ static void find_ordered_chapter_sources(struct tl_ctx *ctx)
talloc_steal(tmp, pl);
for (struct playlist_entry *e = pl ? pl->first : NULL; e; e = e->next)
MP_TARRAY_APPEND(tmp, filenames, num_filenames, e->filename);
- } else if (ctx->demuxer->stream->uncached_type != STREAMTYPE_FILE) {
+ } else if (!ctx->demuxer->stream->is_local_file) {
MP_WARN(ctx, "Playback source is not a "
"normal disk file. Will not search for related files.\n");
} else {
diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c
index 0f2ebedd76..d79edfca40 100644
--- a/demux/demux_playlist.c
+++ b/demux/demux_playlist.c
@@ -277,7 +277,7 @@ static int cmp_filename(const void *a, const void *b)
static int parse_dir(struct pl_parser *p)
{
- if (p->real_stream->type != STREAMTYPE_DIR)
+ if (!p->real_stream->is_directory)
return -1;
if (p->probing)
return 0;
diff --git a/demux/demux_tv.c b/demux/demux_tv.c
index 42b0ce5ff3..4a8e0c70fa 100644
--- a/demux/demux_tv.c
+++ b/demux/demux_tv.c
@@ -22,7 +22,10 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
tvi_handle_t *tvh;
const tvi_functions_t *funcs;
- if (check > DEMUX_CHECK_REQUEST || demuxer->stream->type != STREAMTYPE_TV)
+ if (check > DEMUX_CHECK_REQUEST)
+ return -1;
+
+ if (!demuxer->stream->info || strcmp(demuxer->stream->info->name, "tv") != 0)
return -1;
tv_param_t *params = mp_get_config_group(demuxer, demuxer->global,
diff --git a/stream/stream.c b/stream/stream.c
index 79a51a777f..94b9c44bc4 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -258,8 +258,6 @@ static int open_internal(const stream_info_t *sinfo, const char *url, int flags,
assert(s->seekable == !!s->seek);
- s->uncached_type = s->type;
-
if (s->mime_type)
MP_VERBOSE(s, "Mime-type: '%s'\n", s->mime_type);
@@ -635,7 +633,6 @@ stream_t *open_memory_stream(void *data, int len)
static stream_t *open_cache(stream_t *orig, const char *name)
{
stream_t *cache = new_stream();
- cache->uncached_type = orig->uncached_type;
cache->underlying = orig;
cache->caching = true;
cache->seekable = true;
@@ -648,6 +645,8 @@ static stream_t *open_cache(stream_t *orig, const char *name)
cache->lavf_type = talloc_strdup(cache, orig->lavf_type);
cache->streaming = orig->streaming,
cache->is_network = orig->is_network;
+ cache->is_local_file = orig->is_local_file;
+ cache->is_directory = orig->is_directory;
cache->cancel = orig->cancel;
cache->global = orig->global;
diff --git a/stream/stream.h b/stream/stream.h
index b6fcc3a6fa..cc47184ea6 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -28,20 +28,6 @@
#include "misc/bstr.h"
-enum streamtype {
- STREAMTYPE_GENERIC = 0,
- STREAMTYPE_FILE,
- STREAMTYPE_DIR,
- STREAMTYPE_DVB,
- STREAMTYPE_DVD,
- STREAMTYPE_BLURAY,
- STREAMTYPE_TV,
- STREAMTYPE_MF,
- STREAMTYPE_EDL,
- STREAMTYPE_AVDEVICE,
- STREAMTYPE_CDDA,
-};
-
#define STREAM_BUFFER_SIZE 2048
#define STREAM_MAX_SECTOR_SIZE (8 * 1024)
@@ -178,8 +164,6 @@ typedef struct stream {
// Close
void (*close)(struct stream *s);
- enum streamtype type; // see STREAMTYPE_*
- enum streamtype uncached_type; // if stream is cache, type of wrapped str.
int sector_size; // sector size (seek will be aligned on this size if non 0)
int read_chunk; // maximum amount of data to read at once to limit latency
unsigned int buf_pos, buf_len;
@@ -198,6 +182,8 @@ typedef struct stream {
bool is_network : 1; // original stream_info_t.is_network flag
bool allow_caching : 1; // stream cache makes sense
bool caching : 1; // is a cache, or accesses a cache
+ bool is_local_file : 1; // from the filesystem
+ bool is_directory : 1; // directory on the filesystem
bool access_references : 1; // open other streams
struct mp_log *log;
struct mpv_global *global;
diff --git a/stream/stream_avdevice.c b/stream/stream_avdevice.c
index 9734b7b6f5..2b132cd1a9 100644
--- a/stream/stream_avdevice.c
+++ b/stream/stream_avdevice.c
@@ -21,8 +21,8 @@
static int open_f(stream_t *stream)
{
- stream->type = STREAMTYPE_AVDEVICE;
stream->demuxer = "lavf";
+ stream->allow_caching = false;
return STREAM_OK;
}
diff --git a/stream/stream_bluray.c b/stream/stream_bluray.c
index e648337b93..07dcc7f69e 100644
--- a/stream/stream_bluray.c
+++ b/stream/stream_bluray.c
@@ -450,7 +450,6 @@ static int bluray_stream_open_internal(stream_t *s)
s->fill_buffer = bluray_stream_fill_buffer;
s->close = bluray_stream_close;
s->control = bluray_stream_control;
- s->type = STREAMTYPE_BLURAY;
s->sector_size = BLURAY_SECTOR_SIZE;
s->priv = b;
s->demuxer = "+disc";
diff --git a/stream/stream_cdda.c b/stream/stream_cdda.c
index df7862cd8f..2a8eb7553f 100644
--- a/stream/stream_cdda.c
+++ b/stream/stream_cdda.c
@@ -383,7 +383,6 @@ static int open_cdda(stream_t *st)
st->streaming = true;
- st->type = STREAMTYPE_CDDA;
st->demuxer = "+disc";
print_cdtext(st, 0);
diff --git a/stream/stream_dvb.c b/stream/stream_dvb.c
index 6e55d8c156..4cdbacc681 100644
--- a/stream/stream_dvb.c
+++ b/stream/stream_dvb.c
@@ -990,7 +990,6 @@ static int dvb_open(stream_t *stream)
return STREAM_ERROR;
}
- stream->type = STREAMTYPE_DVB;
stream->fill_buffer = dvb_streaming_read;
stream->close = dvbin_close;
stream->control = dvbin_stream_control;
diff --git a/stream/stream_dvd.c b/stream/stream_dvd.c
index 338c23633c..fe5796d30d 100644
--- a/stream/stream_dvd.c
+++ b/stream/stream_dvd.c
@@ -904,7 +904,6 @@ static int open_s_internal(stream_t *stream)
// ... (unimplemented)
// return NULL;
- stream->type = STREAMTYPE_DVD;
stream->demuxer = "+disc";
stream->lavf_type = "mpeg";
stream->sector_size = 2048;
diff --git a/stream/stream_dvdnav.c b/stream/stream_dvdnav.c
index 1178f50857..21827b6898 100644
--- a/stream/stream_dvdnav.c
+++ b/stream/stream_dvdnav.c
@@ -507,7 +507,6 @@ static int open_s_internal(stream_t *stream)
stream->fill_buffer = fill_buffer;
stream->control = control;
stream->close = stream_dvdnav_close;
- stream->type = STREAMTYPE_DVD;
stream->demuxer = "+disc";
stream->lavf_type = "mpeg";
stream->allow_caching = false;
@@ -596,7 +595,7 @@ unsupported:
}
const stream_info_t stream_info_ifo_dvdnav = {
- .name = "ifo/dvdnav",
+ .name = "ifo_dvdnav",
.open = ifo_dvdnav_stream_open,
.protocols = (const char*const[]){ "file", "", NULL },
};
diff --git a/stream/stream_edl.c b/stream/stream_edl.c
index 4873047cc2..11c149b3ab 100644
--- a/stream/stream_edl.c
+++ b/stream/stream_edl.c
@@ -5,8 +5,8 @@
static int s_open (struct stream *stream)
{
- stream->type = STREAMTYPE_EDL;
stream->demuxer = "edl";
+ stream->allow_caching = false;
return STREAM_OK;
}
diff --git a/stream/stream_file.c b/stream/stream_file.c
index 5d5925ac7c..bfe40429cb 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -234,7 +234,7 @@ static int open_f(stream_t *stream)
.fd = -1
};
stream->priv = p;
- stream->type = STREAMTYPE_FILE;
+ stream->is_local_file = true;
bool write = stream->mode == STREAM_WRITE;
int m = O_CLOEXEC | (write ? O_RDWR | O_CREAT | O_TRUNC : O_RDONLY);
@@ -281,7 +281,7 @@ static int open_f(stream_t *stream)
if (fstat(p->fd, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
p->use_poll = false;
- stream->type = STREAMTYPE_DIR;
+ stream->is_directory = true;
stream->allow_caching = false;
MP_INFO(stream, "This is a directory - adding to playlist.\n");
}
diff --git a/stream/stream_mf.c b/stream/stream_mf.c
index a027e8b79c..ca6ab6ae88 100644
--- a/stream/stream_mf.c
+++ b/stream/stream_mf.c
@@ -30,7 +30,6 @@
static int
mf_stream_open (stream_t *stream)
{
- stream->type = STREAMTYPE_MF;
stream->demuxer = "mf";
stream->allow_caching = false;
diff --git a/stream/stream_tv.c b/stream/stream_tv.c
index 435e3e7b54..d9acbe4cf4 100644
--- a/stream/stream_tv.c
+++ b/stream/stream_tv.c
@@ -39,7 +39,6 @@ static int
tv_stream_open (stream_t *stream)
{
- stream->type = STREAMTYPE_TV;
stream->close=tv_stream_close;
stream->demuxer = "tv";
stream->allow_caching = false;