stream_bluray: remove weird option parsing stuff

Instead, parse manually. This is to get rid of the option API usages,
which seem unnecessary and shoehorned. (Just look at the URL pseudo
parsing and the dumb url_options map. They were pretty much artifacts
from refactoring old mplayer code.)
This commit is contained in:
wm4 2016-09-08 20:49:33 +02:00
parent 7177ef3e1c
commit c8cc1f401b
1 changed files with 45 additions and 51 deletions

View File

@ -41,8 +41,7 @@
#include "mpv_talloc.h"
#include "common/common.h"
#include "common/msg.h"
#include "options/m_option.h"
#include "options/options.h"
#include "options/m_config.h"
#include "options/path.h"
#include "stream.h"
#include "osdep/timer.h"
@ -86,31 +85,6 @@ struct bluray_priv_s {
bool use_nav;
};
static const struct bluray_priv_s bluray_stream_priv_dflts = {
.cfg_title = BLURAY_DEFAULT_TITLE,
};
static const struct bluray_priv_s bdnav_stream_priv_dflts = {
.cfg_title = BLURAY_DEFAULT_TITLE,
.use_nav = true,
};
#define OPT_BASE_STRUCT struct bluray_priv_s
static const m_option_t bluray_stream_opts_fields[] = {
OPT_CHOICE_OR_INT("title", cfg_title, 0, 0, 99999,
({"longest", BLURAY_DEFAULT_TITLE})),
OPT_STRING("device", cfg_device, 0),
{0}
};
static const m_option_t bdnav_stream_opts_fields[] = {
OPT_CHOICE_OR_INT("title", cfg_title, 0, 0, 99999,
({"menu", BLURAY_MENU_TITLE},
{"first", BLURAY_DEFAULT_TITLE})),
OPT_STRING("device", cfg_device, 0),
{0}
};
static void destruct(struct bluray_priv_s *priv)
{
if (priv->title_info)
@ -383,18 +357,20 @@ static void select_initial_title(stream_t *s, int title_guess) {
}
}
static int bluray_stream_open(stream_t *s)
static int bluray_stream_open_internal(stream_t *s)
{
struct bluray_priv_s *b = s->priv;
const char *device = NULL;
char *device = NULL;
/* find the requested device */
if (b->cfg_device && b->cfg_device[0])
if (b->cfg_device && b->cfg_device[0]) {
device = b->cfg_device;
else if (s->opts->bluray_device && s->opts->bluray_device[0])
device = s->opts->bluray_device;
} else {
mp_read_option_raw(s->global, "bluray-device", &m_option_type_string,
&device);
}
if (!device) {
if (!device || !device[0]) {
MP_ERR(s, "No Blu-ray device/location was specified ...\n");
return STREAM_UNSUPPORTED;
}
@ -470,32 +446,48 @@ static int bluray_stream_open(stream_t *s)
return STREAM_OK;
}
const stream_info_t stream_info_bdnav;
static int bluray_stream_open(stream_t *s)
{
struct bluray_priv_s *b = talloc_zero(s, struct bluray_priv_s);
s->priv = b;
b->use_nav = s->info == &stream_info_bdnav;
bstr title, bdevice;
bstr_split_tok(bstr0(s->path), "/", &title, &bdevice);
b->cfg_title = BLURAY_DEFAULT_TITLE;
if (bstr_equals0(title, "longest") || bstr_equals0(title, "first")) {
b->cfg_title = BLURAY_DEFAULT_TITLE;
} else if (bstr_equals0(title, "menu")) {
b->cfg_title = BLURAY_MENU_TITLE;
} else if (title.len) {
bstr rest;
b->cfg_title = bstrtoll(title, &rest, 10);
if (rest.len) {
MP_ERR(s, "number expected: '%.*s'\n", BSTR_P(rest));
return STREAM_ERROR;
}
}
b->cfg_device = bstrto0(b, bdevice);
return bluray_stream_open_internal(s);
}
const stream_info_t stream_info_bluray = {
.name = "bd",
.open = bluray_stream_open,
.protocols = (const char*const[]){ "bd", "br", "bluray", NULL },
.priv_defaults = &bluray_stream_priv_dflts,
.priv_size = sizeof(struct bluray_priv_s),
.options = bluray_stream_opts_fields,
.url_options = (const char*const[]){
"hostname=title",
"filename=device",
NULL
},
};
const stream_info_t stream_info_bdnav = {
.name = "bdnav",
.open = bluray_stream_open,
.protocols = (const char*const[]){ "bdnav", "brnav", "bluraynav", NULL },
.priv_defaults = &bdnav_stream_priv_dflts,
.priv_size = sizeof(struct bluray_priv_s),
.options = bdnav_stream_opts_fields,
.url_options = (const char*const[]){
"hostname=title",
"filename=device",
NULL
},
};
static bool check_bdmv(const char *path)
@ -542,7 +534,9 @@ static int bdmv_dir_stream_open(stream_t *stream)
{
struct bluray_priv_s *priv = talloc_ptrtype(stream, priv);
stream->priv = priv;
*priv = bluray_stream_priv_dflts;
*priv = (struct bluray_priv_s){
.cfg_title = BLURAY_DEFAULT_TITLE,
};
char *path = mp_file_get_path(priv, bstr0(stream->url));
if (!path)
@ -569,7 +563,7 @@ static int bdmv_dir_stream_open(stream_t *stream)
goto unsupported;
MP_INFO(stream, "BDMV detected. Redirecting to bluray://\n");
return bluray_stream_open(stream);
return bluray_stream_open_internal(stream);
unsupported:
talloc_free(priv);