diff options
author | Diogo Franco (Kovensky) <diogomfranco@gmail.com> | 2014-02-15 19:44:58 -0300 |
---|---|---|
committer | Diogo Franco (Kovensky) <diogomfranco@gmail.com> | 2014-02-15 19:44:58 -0300 |
commit | 317a02bdd43ee4d650e4faea340c610fdfa82ff5 (patch) | |
tree | 97713668edc7117395f6a5a25e0c554786898b11 | |
parent | 4a66fce7d336e96847acf5f54e7c0aa30f31ff3b (diff) | |
parent | 792c1750ecb7af83b52feaee387728d48772b34b (diff) | |
download | mpv-317a02bdd43ee4d650e4faea340c610fdfa82ff5.tar.bz2 mpv-317a02bdd43ee4d650e4faea340c610fdfa82ff5.tar.xz |
Merge branch 'master' of git://github.com/mpv-player/mpv
* 'master' of git://github.com/mpv-player/mpv:
win32: restore support for exe directory as config directory
crosscompile-mingw: improve instructions for MXE
sd_lavc: handle subtitles with no subtitle resolution set
options: make --no-config block all auto-loaded configuration files
lua: auto-load scripts from ~/.mpv/lua/
lua: make register_event() not overwrite previous event handler
-rw-r--r-- | DOCS/crosscompile-mingw.md | 2 | ||||
-rw-r--r-- | DOCS/man/en/lua.rst | 4 | ||||
-rw-r--r-- | DOCS/man/en/mpv.rst | 5 | ||||
-rw-r--r-- | DOCS/man/en/options.rst | 6 | ||||
-rw-r--r-- | options/path.c | 11 | ||||
-rw-r--r-- | osdep/path-win.c | 6 | ||||
-rw-r--r-- | player/lua.c | 51 | ||||
-rw-r--r-- | player/lua/defaults.lua | 15 | ||||
-rw-r--r-- | player/lua/osc.lua | 2 | ||||
-rw-r--r-- | sub/sd_lavc.c | 4 |
10 files changed, 93 insertions, 13 deletions
diff --git a/DOCS/crosscompile-mingw.md b/DOCS/crosscompile-mingw.md index 42b89036d7..7d5d02f644 100644 --- a/DOCS/crosscompile-mingw.md +++ b/DOCS/crosscompile-mingw.md @@ -12,6 +12,8 @@ Using mingw-w64-cmake to setup a MinGW-w64 environment is recommended (this will also build mpv and its dependencies): https://github.com/lachs0r/mingw-w64-cmake Alternatively, use MXE: http://mxe.cc +With MXE, you have to modify the file settings.mk to target MinGW-w64 (even if +you compile to 32 bit). Warning: the original MinGW (http://www.mingw.org) is unsupported. diff --git a/DOCS/man/en/lua.rst b/DOCS/man/en/lua.rst index 02e7ca8ea9..54b05d9ea5 100644 --- a/DOCS/man/en/lua.rst +++ b/DOCS/man/en/lua.rst @@ -100,6 +100,10 @@ The ``mp`` module is preloaded, although it can be loaded manually with associated, the ``error`` field is set to a string describing the error, on success it's not set. + If multiple functions are registered for the same event, they are run in + registration order, which the first registered function running before all + the other ones. + Returns true if such an event exists, false otherwise. See `Events`_ and `List of events`_ for details. diff --git a/DOCS/man/en/mpv.rst b/DOCS/man/en/mpv.rst index 4109fdabe4..21ef068e0e 100644 --- a/DOCS/man/en/mpv.rst +++ b/DOCS/man/en/mpv.rst @@ -603,6 +603,11 @@ FILES ``~/.mpv/input.conf`` input bindings (see ``--input-keylist`` for the full list) +``~/.mpv/lua/`` + All files in this directly are loaded as if they were passed to the + ``--lua`` option. They are loaded in alphabetical order, and sub-directories + and files with no ``.lua`` extension are ignored. + EXAMPLES OF MPV USAGE ===================== diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index ce3b730387..da67544d3f 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1412,10 +1412,8 @@ OPTIONS ``--no-config`` Do not load default configuration files. This prevents loading of ``~/.mpv/config`` and ``~/.mpv/input.conf``, as well as loading the - same files from system wide configuration directories. - - Loading of some configuration files is not affected by this option, such - as configuration files for DVB code and fontconfig. + same files from system wide configuration directories. Other configuration + files are blocked as well, such as resume playback files. .. note:: diff --git a/options/path.c b/options/path.c index 94b599803e..5fb20010cf 100644 --- a/options/path.c +++ b/options/path.c @@ -32,9 +32,12 @@ #include <sys/stat.h> #include <unistd.h> #include <errno.h> + #include "config.h" + #include "common/global.h" #include "common/msg.h" +#include "options/options.h" #include "options/path.h" #include "talloc.h" #include "osdep/io.h" @@ -53,6 +56,10 @@ static const lookup_fun config_lookup_functions[] = { char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global, const char *filename) { + struct MPOpts *opts = global->opts; + if (!opts->load_config) + return NULL; + for (int i = 0; config_lookup_functions[i] != NULL; i++) { char *path = config_lookup_functions[i](talloc_ctx, global, filename); if (!path) continue; @@ -68,6 +75,10 @@ char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global, char *mp_find_user_config_file(void *talloc_ctx, struct mpv_global *global, const char *filename) { + struct MPOpts *opts = global->opts; + if (!opts->load_config) + return NULL; + char *homedir = getenv("MPV_HOME"); char *configdir = NULL; char *result = NULL; diff --git a/osdep/path-win.c b/osdep/path-win.c index d89adc755e..2b1e8b5144 100644 --- a/osdep/path-win.c +++ b/osdep/path-win.c @@ -59,7 +59,11 @@ char *mp_get_win_config_path(const char *filename) res = mp_path_join(NULL, bstr0(temp), bstr0(filename)); if (!mp_path_exists(res) || mp_path_isdir(res)) { talloc_free(res); - res = NULL; + res = mp_path_join(NULL, bstr0(dir), bstr0(filename)); + if (!mp_path_exists(res) || mp_path_isdir(res)) { + talloc_free(res); + res = NULL; + } } } diff --git a/player/lua.c b/player/lua.c index 60cf4d2fcf..c7f43e0870 100644 --- a/player/lua.c +++ b/player/lua.c @@ -1,5 +1,9 @@ #include <assert.h> #include <string.h> +#include <sys/types.h> +#include <dirent.h> + +#include "osdep/io.h" #include <lua.h> #include <lualib.h> @@ -87,9 +91,9 @@ static int mp_cpcall(lua_State *L, lua_CFunction fn, int args) static void report_error(lua_State *L) { - struct MPContext *mpctx = get_mpctx(L); + struct script_ctx *ctx = get_ctx(L); const char *err = lua_tostring(L, -1); - MP_WARN(mpctx, "Error: %s\n", err ? err : "[unknown]"); + MP_WARN(ctx, "Error: %s\n", err ? err : "[unknown]"); lua_pop(L, 1); } @@ -144,6 +148,7 @@ static int load_file(struct script_ctx *ctx, const char *fname) int r = 0; lua_State *L = ctx->state; char *res_name = mp_get_user_path(NULL, ctx->mpctx->global, fname); + MP_VERBOSE(ctx, "loading file %s\n", res_name); if (luaL_loadfile(L, res_name) || lua_pcall(L, 0, 0, 0)) { report_error(L); r = -1; @@ -170,8 +175,10 @@ static int load_builtin(lua_State *L) // Execute "require " .. name static bool require(lua_State *L, const char *name) { - char buf[80]; + struct script_ctx *ctx = get_ctx(L); + MP_VERBOSE(ctx, "loading %s\n", name); // Lazy, but better than calling the "require" function manually + char buf[80]; snprintf(buf, sizeof(buf), "require '%s'", name); if (luaL_loadstring(L, buf) || lua_pcall(L, 0, 0, 0)) { report_error(L); @@ -260,6 +267,7 @@ static void *lua_thread(void *p) report_error(L); error_out: + MP_VERBOSE(ctx, "exiting.\n"); if (ctx->suspended) mpv_resume(ctx->client); if (ctx->state) @@ -783,6 +791,34 @@ static void add_functions(struct script_ctx *ctx) lua_setfield(L, -2, "get_property_osd"); } +static int compare_filename(const void *pa, const void *pb) +{ + char *a = (char *)pa; + char *b = (char *)pb; + return strcmp(a, b); +} + +static char **list_lua_files(void *talloc_ctx, char *path) +{ + char **files = NULL; + int count = 0; + DIR *dp = opendir(path); + if (!dp) + return NULL; + struct dirent *ep; + while ((ep = readdir(dp))) { + char *ext = mp_splitext(ep->d_name, NULL); + if (!ext || strcasecmp(ext, "lua") != 0) + continue; + char *fname = mp_path_join(talloc_ctx, bstr0(path), bstr0(ep->d_name)); + MP_TARRAY_APPEND(talloc_ctx, files, count, fname); + } + closedir(dp); + qsort(files, count, sizeof(char *), compare_filename); + MP_TARRAY_APPEND(talloc_ctx, files, count, NULL); + return files; +} + void mp_lua_init(struct MPContext *mpctx) { // Load scripts from options @@ -793,4 +829,13 @@ void mp_lua_init(struct MPContext *mpctx) if (files[n][0]) mp_lua_load_script(mpctx, files[n]); } + // Load ~/.mpv/lua/* + void *tmp = talloc_new(NULL); + char *lua_path = mp_find_user_config_file(tmp, mpctx->global, "lua"); + if (lua_path) { + files = list_lua_files(tmp, lua_path); + for (int n = 0; files && files[n]; n++) + mp_lua_load_script(mpctx, files[n]); + } + talloc_free(tmp); } diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 1ab1c4264a..8efa8d6315 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -135,7 +135,12 @@ mp.keep_running = true local event_handlers = {} function mp.register_event(name, cb) - event_handlers[name] = cb + local list = event_handlers[name] + if not list then + list = {} + event_handlers[name] = list + end + list[#list + 1] = cb return mp.request_event(name, true) end @@ -180,9 +185,11 @@ _G.mp_event_loop = function() mp.suspend() more_events = (e.event ~= "none") if more_events then - local handler = event_handlers[e.event] - if handler then - handler(e) + local handlers = event_handlers[e.event] + if handlers then + for _, handler in ipairs(handlers) do + handler(e) + end end end end diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 5bf150274d..033f2c0d7e 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -121,7 +121,7 @@ function read_config(options, identifier) local conffilename = "plugin_" .. identifier .. ".conf" local conffile = mp.find_config_file(conffilename) - local f = io.open(conffile,"r") + local f = conffile and io.open(conffile,"r") if f == nil then -- config not found else diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 0252a37207..c46e52cb70 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -91,6 +91,10 @@ static void get_resolution(struct sd *sd, int wh[2]) struct sd_lavc_priv *priv = sd->priv; wh[0] = priv->avctx->width; wh[1] = priv->avctx->height; + if (wh[0] <= 0 || wh[1] <= 0) { + wh[0] = priv->video_params.w; + wh[1] = priv->video_params.h; + } guess_resolution(priv->avctx->codec_id, &wh[0], &wh[1]); } |