From fb9a32977d6abf4c83a92d993af58e393819c062 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 2 Feb 2017 18:24:27 +0100 Subject: 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. --- demux/demux_disc.c | 28 ++++++++++++++++++++++------ demux/demux_edl.c | 8 +++++--- demux/demux_lavf.c | 7 ++----- demux/demux_mf.c | 5 +++-- demux/demux_mkv_timeline.c | 2 +- demux/demux_playlist.c | 2 +- demux/demux_tv.c | 5 ++++- 7 files changed, 38 insertions(+), 19 deletions(-) (limited to 'demux') 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, -- cgit v1.2.3