stream_dvd, stream_dvdnav: remove weird option parsing stuff

Same deal as with stream_bluray.

Untested because I don't give a fuck about your shitty DVDs.
This commit is contained in:
wm4 2016-09-08 21:46:48 +02:00
parent 35e8b6c1e6
commit 5e30e7a041
7 changed files with 120 additions and 77 deletions

View File

@ -212,6 +212,22 @@ const struct m_sub_options vo_sub_opts = {
}, },
}; };
#undef OPT_BASE_STRUCT
#define OPT_BASE_STRUCT struct dvd_opts
const struct m_sub_options dvd_conf = {
.opts = (const struct m_option[]){
OPT_STRING("dvd-device", device, M_OPT_FILE),
OPT_INT("dvd-speed", speed, 0),
OPT_INTRANGE("dvd-angle", angle, 0, 1, 99),
{0}
},
.size = sizeof(struct dvd_opts),
.defaults = &(const struct dvd_opts){
.angle = 1,
},
};
#undef OPT_BASE_STRUCT #undef OPT_BASE_STRUCT
#define OPT_BASE_STRUCT struct MPOpts #define OPT_BASE_STRUCT struct MPOpts
@ -275,9 +291,7 @@ const m_option_t mp_opts[] = {
OPT_SUBSTRUCT("", stream_cache, stream_cache_conf, 0), OPT_SUBSTRUCT("", stream_cache, stream_cache_conf, 0),
#if HAVE_DVDREAD || HAVE_DVDNAV #if HAVE_DVDREAD || HAVE_DVDNAV
OPT_STRING("dvd-device", dvd_device, M_OPT_FILE), OPT_SUBSTRUCT("", dvd_opts, dvd_conf, 0),
OPT_INT("dvd-speed", dvd_speed, 0),
OPT_INTRANGE("dvd-angle", dvd_angle, 0, 1, 99),
#endif /* HAVE_DVDREAD */ #endif /* HAVE_DVDREAD */
OPT_INTPAIR("chapter", chapterrange, 0), OPT_INTPAIR("chapter", chapterrange, 0),
OPT_CHOICE_OR_INT("edition", edition_id, 0, 0, 8190, OPT_CHOICE_OR_INT("edition", edition_id, 0, 0, 8190,
@ -855,8 +869,6 @@ const struct MPOpts mp_default_opts = {
.index_mode = 1, .index_mode = 1,
.dvd_angle = 1,
.mf_fps = 1.0, .mf_fps = 1.0,
.display_tags = (char **)(const char*[]){ .display_tags = (char **)(const char*[]){

View File

@ -290,10 +290,6 @@ typedef struct MPOpts {
struct stream_lavf_params *stream_lavf_opts; struct stream_lavf_params *stream_lavf_opts;
char *cdrom_device; char *cdrom_device;
int dvd_title;
int dvd_angle;
int dvd_speed;
char *dvd_device;
char *bluray_device; char *bluray_device;
double mf_fps; double mf_fps;
@ -318,11 +314,19 @@ typedef struct MPOpts {
char *input_file; char *input_file;
struct gl_video_opts *gl_video_opts; struct gl_video_opts *gl_video_opts;
struct dvd_opts *dvd_opts;
} MPOpts; } MPOpts;
struct dvd_opts {
int angle;
int speed;
char *device;
};
extern const m_option_t mp_opts[]; extern const m_option_t mp_opts[];
extern const struct MPOpts mp_default_opts; extern const struct MPOpts mp_default_opts;
extern const struct m_sub_options vo_sub_opts; extern const struct m_sub_options vo_sub_opts;
extern const struct m_sub_options stream_cache_conf; extern const struct m_sub_options stream_cache_conf;
extern const struct m_sub_options dvd_conf;
#endif #endif

View File

@ -180,8 +180,8 @@ static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
realpath = mp_path_join(tmp, cwd, fname); realpath = mp_path_join(tmp, cwd, fname);
} }
} }
if (bstr_startswith0(bfname, "dvd://") && opts->dvd_device) if (bstr_startswith0(bfname, "dvd://") && opts->dvd_opts->device)
realpath = talloc_asprintf(tmp, "%s - %s", realpath, opts->dvd_device); realpath = talloc_asprintf(tmp, "%s - %s", realpath, opts->dvd_opts->device);
if ((bstr_startswith0(bfname, "br://") || bstr_startswith0(bfname, "bd://") || if ((bstr_startswith0(bfname, "br://") || bstr_startswith0(bfname, "bd://") ||
bstr_startswith0(bfname, "bluray://")) && opts->bluray_device) bstr_startswith0(bfname, "bluray://")) && opts->bluray_device)
realpath = talloc_asprintf(tmp, "%s - %s", realpath, opts->bluray_device); realpath = talloc_asprintf(tmp, "%s - %s", realpath, opts->bluray_device);

View File

@ -207,18 +207,22 @@ static bstr split_next(bstr *s, char end, const char *delim)
// Parse the stream URL, syntax: // Parse the stream URL, syntax:
// proto:// [<username>@]<hostname>[:<port>][/<filename>] // proto:// [<username>@]<hostname>[:<port>][/<filename>]
// (the proto:// part is already removed from s->path) // (the proto:// part is assumed to be already removed from s)
// This code originates from times when http code used this, but now it's // This code originates from times when http code used this, but now it's
// just relict from other stream implementations reusing this code. // just relict from other stream implementations reusing this code.
void mp_parse_legacy_url(bstr s, bstr c[4])
{
c[0] = split_next(&s, '@', "@:/");
c[1] = split_next(&s, 0, ":/");
c[2] = bstr_eatstart0(&s, ":") ? split_next(&s, 0, "/") : (bstr){0};
c[3] = bstr_eatstart0(&s, "/") ? s : (bstr){0};
}
static bool parse_url(struct stream *st, struct m_config *config) static bool parse_url(struct stream *st, struct m_config *config)
{ {
bstr s = bstr0(st->path);
const char *f_names[4] = {"username", "hostname", "port", "filename"};
bstr f[4]; bstr f[4];
f[0] = split_next(&s, '@', "@:/"); mp_parse_legacy_url(bstr0(st->path), f);
f[1] = split_next(&s, 0, ":/"); const char *f_names[4] = {"username", "hostname", "port", "filename"};
f[2] = bstr_eatstart0(&s, ":") ? split_next(&s, 0, "/") : (bstr){0};
f[3] = bstr_eatstart0(&s, "/") ? s : (bstr){0};
for (int n = 0; n < 4; n++) { for (int n = 0; n < 4; n++) {
if (f[n].len) { if (f[n].len) {
const char *opt = find_url_opt(st, f_names[n]); const char *opt = find_url_opt(st, f_names[n]);

View File

@ -296,6 +296,13 @@ void mp_setup_av_network_options(struct AVDictionary **dict,
struct mpv_global *global, struct mpv_global *global,
struct mp_log *log); struct mp_log *log);
// sort-of legacy handling of options-in-stream-URL
#define URL_USERNAME 0
#define URL_HOSTNAME 1
#define URL_PORT 2
#define URL_FILENAME 3
void mp_parse_legacy_url(bstr url, bstr components[4]);
void stream_print_proto_list(struct mp_log *log); void stream_print_proto_list(struct mp_log *log);
char **stream_get_proto_list(void); char **stream_get_proto_list(void);
bool stream_has_proto(const char *proto); bool stream_has_proto(const char *proto);

View File

@ -45,7 +45,7 @@
#define FIRST_PCM_AID 160 #define FIRST_PCM_AID 160
#include "stream.h" #include "stream.h"
#include "options/m_option.h" #include "options/m_config.h"
#include "options/options.h" #include "options/options.h"
#include "options/path.h" #include "options/path.h"
@ -109,18 +109,6 @@ typedef struct {
char *cfg_device; char *cfg_device;
} dvd_priv_t; } dvd_priv_t;
static const dvd_priv_t stream_priv_dflts = {
.cfg_title = 0,
};
#define OPT_BASE_STRUCT dvd_priv_t
/// URL definition
static const m_option_t stream_opts_fields[] = {
OPT_INTRANGE("title", cfg_title, 0, 0, 99),
OPT_STRING("device", cfg_device, 0),
{0}
};
static int dvd_lang_from_aid(stream_t *stream, int id) { static int dvd_lang_from_aid(stream_t *stream, int id) {
dvd_priv_t *d; dvd_priv_t *d;
int i; int i;
@ -657,12 +645,15 @@ static int control(stream_t *stream,int cmd,void* arg)
} }
static int open_s(stream_t *stream) static int open_s_internal(stream_t *stream)
{ {
int k; int k;
dvd_priv_t *d = stream->priv; dvd_priv_t *d = stream->priv;
d->dvd_angle = stream->opts->dvd_angle; struct dvd_opts *opts =
mp_get_config_group(stream, stream->global, &dvd_conf);
d->dvd_angle = opts->angle;
MP_VERBOSE(stream, "URL: %s\n", stream->url); MP_VERBOSE(stream, "URL: %s\n", stream->url);
d->dvd_title = d->cfg_title + 1; d->dvd_title = d->cfg_title + 1;
@ -680,11 +671,11 @@ static int open_s(stream_t *stream)
*/ */
if(d->cfg_device && d->cfg_device[0]) if(d->cfg_device && d->cfg_device[0])
d->dvd_device_current = d->cfg_device; d->dvd_device_current = d->cfg_device;
else if(stream->opts->dvd_device && stream->opts->dvd_device[0]) else if(opts->device && opts->device[0])
d->dvd_device_current = talloc_strdup(stream, stream->opts->dvd_device); d->dvd_device_current = talloc_strdup(stream, opts->device);
else else
d->dvd_device_current = DEFAULT_DVD_DEVICE; d->dvd_device_current = DEFAULT_DVD_DEVICE;
d->dvd_speed = stream->opts->dvd_speed; d->dvd_speed = opts->speed;
dvd_set_speed(stream,d->dvd_device_current, d->dvd_speed); dvd_set_speed(stream,d->dvd_device_current, d->dvd_speed);
#if defined(__APPLE__) || defined(__DARWIN__) #if defined(__APPLE__) || defined(__DARWIN__)
/* Dynamic DVD drive selection on Darwin */ /* Dynamic DVD drive selection on Darwin */
@ -933,11 +924,32 @@ fail:
return STREAM_UNSUPPORTED; return STREAM_UNSUPPORTED;
} }
static int open_s(stream_t *stream)
{
dvd_priv_t *d = talloc_zero(stream, dvd_priv_t);
stream->priv = d;
bstr title, bdevice;
bstr_split_tok(bstr0(stream->path), "/", &title, &bdevice);
if (title.len) {
bstr rest;
d->cfg_title = bstrtoll(title, &rest, 10);
if (rest.len) {
MP_ERR(stream, "number expected: '%.*s'\n", BSTR_P(rest));
return STREAM_ERROR;
}
}
d->cfg_device = bstrto0(d, bdevice);
return open_s_internal(stream);
}
static int ifo_stream_open(stream_t *stream) static int ifo_stream_open(stream_t *stream)
{ {
dvd_priv_t *priv = talloc_ptrtype(stream, priv); dvd_priv_t *priv = talloc_zero(stream, dvd_priv_t);
stream->priv = priv; stream->priv = priv;
*priv = stream_priv_dflts;
char *path = mp_file_get_path(priv, bstr0(stream->url)); char *path = mp_file_get_path(priv, bstr0(stream->url));
if (!path) if (!path)
@ -958,7 +970,7 @@ static int ifo_stream_open(stream_t *stream)
priv->cfg_device = bstrto0(priv, mp_dirname(path)); priv->cfg_device = bstrto0(priv, mp_dirname(path));
MP_INFO(stream, ".IFO detected. Redirecting to dvdread://\n"); MP_INFO(stream, ".IFO detected. Redirecting to dvdread://\n");
return open_s(stream); return open_s_internal(stream);
unsupported: unsupported:
talloc_free(priv); talloc_free(priv);
@ -970,14 +982,6 @@ const stream_info_t stream_info_dvd = {
.name = "dvd", .name = "dvd",
.open = open_s, .open = open_s,
.protocols = (const char*const[]){ "dvdread", NULL }, .protocols = (const char*const[]){ "dvdread", NULL },
.priv_size = sizeof(dvd_priv_t),
.priv_defaults = &stream_priv_dflts,
.options = stream_opts_fields,
.url_options = (const char*const[]){
"hostname=title",
"filename=device",
NULL
},
}; };
const stream_info_t stream_info_ifo = { const stream_info_t stream_info_ifo = {

View File

@ -34,7 +34,7 @@
#include "options/options.h" #include "options/options.h"
#include "common/msg.h" #include "common/msg.h"
#include "input/input.h" #include "input/input.h"
#include "options/m_option.h" #include "options/m_config.h"
#include "options/path.h" #include "options/path.h"
#include "osdep/timer.h" #include "osdep/timer.h"
#include "stream.h" #include "stream.h"
@ -59,19 +59,8 @@ struct priv {
int track; int track;
char *device; char *device;
};
static const struct priv stream_priv_dflts = { struct dvd_opts *opts;
.track = TITLE_LONGEST,
};
#define OPT_BASE_STRUCT struct priv
static const m_option_t stream_opts_fields[] = {
OPT_CHOICE_OR_INT("title", track, 0, 0, 99,
({"menu", TITLE_MENU},
{"longest", TITLE_LONGEST})),
OPT_STRING("device", device, 0),
{0}
}; };
#define DNE(e) [e] = # e #define DNE(e) [e] = # e
@ -437,7 +426,7 @@ static struct priv *new_dvdnav_stream(stream_t *stream, char *filename)
if (!(priv->filename = strdup(filename))) if (!(priv->filename = strdup(filename)))
return NULL; return NULL;
priv->dvd_speed = stream->opts->dvd_speed; priv->dvd_speed = priv->opts->speed;
dvd_set_speed(stream, priv->filename, priv->dvd_speed); dvd_set_speed(stream, priv->filename, priv->dvd_speed);
if (dvdnav_open(&(priv->dvdnav), priv->filename) != DVDNAV_STATUS_OK) { if (dvdnav_open(&(priv->dvdnav), priv->filename) != DVDNAV_STATUS_OK) {
@ -458,16 +447,18 @@ static struct priv *new_dvdnav_stream(stream_t *stream, char *filename)
return priv; return priv;
} }
static int open_s(stream_t *stream) static int open_s_internal(stream_t *stream)
{ {
struct priv *priv, *p; struct priv *priv, *p;
priv = p = stream->priv; priv = p = stream->priv;
char *filename; char *filename;
p->opts = mp_get_config_group(stream, stream->global, &dvd_conf);
if (p->device && p->device[0]) if (p->device && p->device[0])
filename = p->device; filename = p->device;
else if (stream->opts->dvd_device && stream->opts->dvd_device[0]) else if (p->opts->device && p->opts->device[0])
filename = stream->opts->dvd_device; filename = p->opts->device;
else else
filename = DEFAULT_DVD_DEVICE; filename = DEFAULT_DVD_DEVICE;
if (!new_dvdnav_stream(stream, filename)) { if (!new_dvdnav_stream(stream, filename)) {
@ -509,8 +500,8 @@ static int open_s(stream_t *stream)
MP_FATAL(stream, "DVD menu support has been removed.\n"); MP_FATAL(stream, "DVD menu support has been removed.\n");
return STREAM_ERROR; return STREAM_ERROR;
} }
if (stream->opts->dvd_angle > 1) if (p->opts->angle > 1)
dvdnav_angle_change(priv->dvdnav, stream->opts->dvd_angle); dvdnav_angle_change(priv->dvdnav, p->opts->angle);
stream->sector_size = 2048; stream->sector_size = 2048;
stream->fill_buffer = fill_buffer; stream->fill_buffer = fill_buffer;
@ -524,18 +515,38 @@ static int open_s(stream_t *stream)
return STREAM_OK; return STREAM_OK;
} }
static int open_s(stream_t *stream)
{
struct priv *priv = talloc_zero(stream, struct priv);
stream->priv = priv;
bstr title, bdevice;
bstr_split_tok(bstr0(stream->path), "/", &title, &bdevice);
priv->track = TITLE_LONGEST;
if (bstr_equals0(title, "longest") || bstr_equals0(title, "first")) {
priv->track = TITLE_LONGEST;
} else if (bstr_equals0(title, "menu")) {
priv->track = TITLE_MENU;
} else if (title.len) {
bstr rest;
priv->title = bstrtoll(title, &rest, 10);
if (rest.len) {
MP_ERR(stream, "number expected: '%.*s'\n", BSTR_P(rest));
return STREAM_ERROR;
}
}
priv->device = bstrto0(priv, bdevice);
return open_s_internal(stream);
}
const stream_info_t stream_info_dvdnav = { const stream_info_t stream_info_dvdnav = {
.name = "dvdnav", .name = "dvdnav",
.open = open_s, .open = open_s,
.protocols = (const char*const[]){ "dvd", "dvdnav", NULL }, .protocols = (const char*const[]){ "dvd", "dvdnav", NULL },
.priv_size = sizeof(struct priv),
.priv_defaults = &stream_priv_dflts,
.options = stream_opts_fields,
.url_options = (const char*const[]){
"hostname=title",
"filename=device",
NULL
},
}; };
static bool check_ifo(const char *path) static bool check_ifo(const char *path)
@ -548,9 +559,10 @@ static bool check_ifo(const char *path)
static int ifo_dvdnav_stream_open(stream_t *stream) static int ifo_dvdnav_stream_open(stream_t *stream)
{ {
struct priv *priv = talloc_ptrtype(stream, priv); struct priv *priv = talloc_zero(stream, struct priv);
stream->priv = priv; stream->priv = priv;
*priv = stream_priv_dflts;
priv->track = TITLE_LONGEST;
char *path = mp_file_get_path(priv, bstr0(stream->url)); char *path = mp_file_get_path(priv, bstr0(stream->url));
if (!path) if (!path)
@ -572,7 +584,7 @@ static int ifo_dvdnav_stream_open(stream_t *stream)
priv->device = bstrto0(priv, mp_dirname(path)); priv->device = bstrto0(priv, mp_dirname(path));
MP_INFO(stream, ".IFO detected. Redirecting to dvd://\n"); MP_INFO(stream, ".IFO detected. Redirecting to dvd://\n");
return open_s(stream); return open_s_internal(stream);
unsupported: unsupported:
talloc_free(priv); talloc_free(priv);