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.
This commit is contained in:
wm4 2017-02-02 18:24:27 +01:00
parent e13a62fc34
commit fb9a32977d
19 changed files with 47 additions and 50 deletions

View File

@ -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.

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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 {

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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";

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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 },
};

View File

@ -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;
}

View File

@ -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");
}

View File

@ -30,7 +30,6 @@
static int
mf_stream_open (stream_t *stream)
{
stream->type = STREAMTYPE_MF;
stream->demuxer = "mf";
stream->allow_caching = false;

View File

@ -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;