diff options
author | Martin Herkt <lachs0r@srsfckn.biz> | 2016-04-11 17:42:55 +0200 |
---|---|---|
committer | Martin Herkt <lachs0r@srsfckn.biz> | 2016-04-11 17:42:55 +0200 |
commit | 0803f4ad21c195519209bae8d18840dd810191f8 (patch) | |
tree | f9a869011ba90c106cf5c05c3e346912a669f63a /player | |
parent | 9d2980dab752280468620df49cabe7f4843f0551 (diff) | |
parent | b968d779afb9114694976792e903b0591a71a816 (diff) | |
download | mpv-0803f4ad21c195519209bae8d18840dd810191f8.tar.bz2 mpv-0803f4ad21c195519209bae8d18840dd810191f8.tar.xz |
Merge branch 'master' into release/current
Diffstat (limited to 'player')
-rw-r--r-- | player/audio.c | 4 | ||||
-rw-r--r-- | player/command.c | 183 | ||||
-rw-r--r-- | player/core.h | 4 | ||||
-rw-r--r-- | player/external_files.c | 1 | ||||
-rw-r--r-- | player/loadfile.c | 2 | ||||
-rw-r--r-- | player/lua.c | 47 | ||||
-rw-r--r-- | player/lua/defaults.lua | 9 | ||||
-rw-r--r-- | player/lua/osc.lua | 39 | ||||
-rw-r--r-- | player/lua/ytdl_hook.lua | 2 | ||||
-rw-r--r-- | player/main.c | 2 | ||||
-rw-r--r-- | player/misc.c | 19 | ||||
-rw-r--r-- | player/osd.c | 14 | ||||
-rw-r--r-- | player/playloop.c | 5 | ||||
-rw-r--r-- | player/sub.c | 43 | ||||
-rw-r--r-- | player/video.c | 24 |
15 files changed, 260 insertions, 138 deletions
diff --git a/player/audio.c b/player/audio.c index f17587a1ca..3a2c60b8ab 100644 --- a/player/audio.c +++ b/player/audio.c @@ -134,6 +134,8 @@ static int recreate_audio_filters(struct MPContext *mpctx) mixer_reinit_audio(mpctx->mixer, mpctx->ao, afs); + mp_notify(mpctx, MPV_EVENT_AUDIO_RECONFIG, NULL); + return 0; fail: @@ -368,6 +370,8 @@ static void reinit_audio_filters_and_output(struct MPContext *mpctx) update_playback_speed(mpctx); + mp_notify(mpctx, MPV_EVENT_AUDIO_RECONFIG, NULL); + return; init_error: diff --git a/player/command.c b/player/command.c index 642330e34f..8a4e9805f1 100644 --- a/player/command.c +++ b/player/command.c @@ -32,6 +32,8 @@ #include "config.h" #include "mpv_talloc.h" #include "client.h" +#include "common/av_common.h" +#include "common/codecs.h" #include "common/msg.h" #include "common/msg_control.h" #include "command.h" @@ -417,6 +419,17 @@ static int mp_property_stream_path(void *ctx, struct m_property *prop, return m_property_strdup_ro(action, arg, stream->url); } +struct change_stream_capture_args { + char *filename; + struct demuxer *demux; +}; + +static void do_change_stream_capture(void *p) +{ + struct change_stream_capture_args *args = p; + stream_set_capture_file(args->demux->stream, args->filename); +} + static int mp_property_stream_capture(void *ctx, struct m_property *prop, int action, void *arg) { @@ -425,10 +438,8 @@ static int mp_property_stream_capture(void *ctx, struct m_property *prop, return M_PROPERTY_UNAVAILABLE; if (action == M_PROPERTY_SET) { - char *filename = *(char **)arg; - demux_pause(mpctx->demuxer); - stream_set_capture_file(mpctx->demuxer->stream, filename); - demux_unpause(mpctx->demuxer); + struct change_stream_capture_args args = {*(char **)arg, mpctx->demuxer}; + demux_run_on_thread(mpctx->demuxer, do_change_stream_capture, &args); // fall through to mp_property_generic_option } return mp_property_generic_option(mpctx, prop, action, arg); @@ -456,24 +467,14 @@ static int mp_property_file_format(void *ctx, struct m_property *prop, return m_property_strdup_ro(action, arg, name); } -/// Position in the stream (RW) static int mp_property_stream_pos(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer; - if (!demuxer) + if (!demuxer || demuxer->filepos < 0) return M_PROPERTY_UNAVAILABLE; - demux_pause(demuxer); - int r; - if (action == M_PROPERTY_SET) { - stream_seek(demuxer->stream, *(int64_t *) arg); - r = M_PROPERTY_OK; - } else { - r = m_property_int64_ro(action, arg, stream_tell(demuxer->stream)); - } - demux_unpause(demuxer); - return r; + return m_property_int64_ro(action, arg, demuxer->filepos); } /// Stream end offset (RO) @@ -1085,11 +1086,12 @@ static int mp_property_angle(void *ctx, struct m_property *prop, if (angle < 0 || angle > angles) return M_PROPERTY_ERROR; - demux_pause(demuxer); demux_flush(demuxer); ris = demux_stream_control(demuxer, STREAM_CTRL_SET_ANGLE, &angle); - demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL); - demux_unpause(demuxer); + if (ris == STREAM_OK) { + demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL); + demux_flush(demuxer); + } reset_audio_state(mpctx); reset_video_state(mpctx); @@ -1368,11 +1370,11 @@ static int mp_property_cache_size(void *ctx, struct m_property *prop, switch (action) { case M_PROPERTY_GET: case M_PROPERTY_PRINT: { - int64_t size = -1; - demux_stream_control(demuxer, STREAM_CTRL_GET_CACHE_SIZE, &size); - if (size <= 0) + struct stream_cache_info info = {0}; + demux_stream_control(demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) break; - return property_int_kb_size(size / 1024, action, arg); + return property_int_kb_size(info.size / 1024, action, arg); } case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){ @@ -1401,11 +1403,11 @@ static int mp_property_cache_used(void *ctx, struct m_property *prop, if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; - int64_t size = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &size); - if (size < 0) + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) return M_PROPERTY_UNAVAILABLE; - return property_int_kb_size(size / 1024, action, arg); + return property_int_kb_size(info.fill / 1024, action, arg); } static int mp_property_cache_free(void *ctx, struct m_property *prop, @@ -1415,29 +1417,43 @@ static int mp_property_cache_free(void *ctx, struct m_property *prop, if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; - int64_t size_used = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &size_used); - if (size_used < 0) + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) return M_PROPERTY_UNAVAILABLE; - int64_t size = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_SIZE, &size); - if (size <= 0) + return property_int_kb_size((info.size - info.fill) / 1024, action, arg); +} + +static int mp_property_cache_speed(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; - return property_int_kb_size((size - size_used) / 1024, action, arg); + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) + return M_PROPERTY_UNAVAILABLE; + + if (action == M_PROPERTY_PRINT) { + *(char **)arg = talloc_strdup_append(format_file_size(info.speed), "/s"); + return M_PROPERTY_OK; + } + return m_property_int64_ro(action, arg, info.speed); } static int mp_property_cache_idle(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - int idle = -1; + struct stream_cache_info info = {0}; if (mpctx->demuxer) - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_IDLE, &idle); - if (idle < 0) + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size <= 0) return M_PROPERTY_UNAVAILABLE; - return m_property_flag_ro(action, arg, !!idle); + return m_property_flag_ro(action, arg, info.idle); } static int mp_property_demuxer_cache_duration(void *ctx, struct m_property *prop, @@ -1944,7 +1960,14 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) struct MPContext *mpctx = ctx; struct track *track = mpctx->tracks[item]; - const char *codec = track->stream ? track->stream->codec->codec : NULL; + struct mp_codec_params p = + track->stream ? *track->stream->codec : (struct mp_codec_params){0}; + + const char *decoder_desc = NULL; + if (track->d_video) + decoder_desc = track->d_video->decoder_desc; + if (track->d_audio) + decoder_desc = track->d_audio->decoder_desc; struct m_sub_property props[] = { {"id", SUB_PROP_INT(track->user_tid)}, @@ -1965,9 +1988,20 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) {"selected", SUB_PROP_FLAG(track->selected)}, {"external-filename", SUB_PROP_STR(track->external_filename), .unavailable = !track->external_filename}, - {"codec", SUB_PROP_STR(codec), - .unavailable = !codec}, {"ff-index", SUB_PROP_INT(track->ff_index)}, + {"decoder-desc", SUB_PROP_STR(decoder_desc), + .unavailable = !decoder_desc}, + {"codec", SUB_PROP_STR(p.codec), + .unavailable = !p.codec}, + {"demux-w", SUB_PROP_INT(p.disp_w), .unavailable = !p.disp_w}, + {"demux-h", SUB_PROP_INT(p.disp_h), .unavailable = !p.disp_h}, + {"demux-channel-count", SUB_PROP_INT(p.channels.num), + .unavailable = !p.channels.num}, + {"demux-channels", SUB_PROP_STR(mp_chmap_to_str(&p.channels)), + .unavailable = !p.channels.num}, + {"demux-samplerate", SUB_PROP_INT(p.samplerate), + .unavailable = !p.samplerate}, + {"demux-fps", SUB_PROP_DOUBLE(p.fps), .unavailable = p.fps <= 0}, {0} }; @@ -2699,7 +2733,7 @@ static int mp_property_osd_w(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_OSD); + struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd); return m_property_int_ro(action, arg, vo_res.w); } @@ -2707,7 +2741,7 @@ static int mp_property_osd_h(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_OSD); + struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd); return m_property_int_ro(action, arg, vo_res.h); } @@ -2715,7 +2749,7 @@ static int mp_property_osd_par(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_OSD); + struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd); return m_property_double_ro(action, arg, vo_res.display_par); } @@ -3272,6 +3306,47 @@ static int mp_property_protocols(void *ctx, struct m_property *prop, return M_PROPERTY_NOT_IMPLEMENTED; } +static int get_decoder_entry(int item, int action, void *arg, void *ctx) +{ + struct mp_decoder_list *codecs = ctx; + struct mp_decoder_entry *c = &codecs->entries[item]; + + struct m_sub_property props[] = { + {"family", SUB_PROP_STR(c->family)}, + {"codec", SUB_PROP_STR(c->codec)}, + {"driver" , SUB_PROP_STR(c->decoder)}, + {"description", SUB_PROP_STR(c->desc)}, + {0} + }; + + return m_property_read_sub(props, action, arg); +} + +static int mp_property_decoders(void *ctx, struct m_property *prop, + int action, void *arg) +{ + struct mp_decoder_list *codecs = talloc_zero(NULL, struct mp_decoder_list); + struct mp_decoder_list *v = talloc_steal(codecs, video_decoder_list()); + struct mp_decoder_list *a = talloc_steal(codecs, audio_decoder_list()); + mp_append_decoders(codecs, v); + mp_append_decoders(codecs, a); + int r = m_property_read_list(action, arg, codecs->num_entries, + get_decoder_entry, codecs); + talloc_free(codecs); + return r; +} + +static int mp_property_encoders(void *ctx, struct m_property *prop, + int action, void *arg) +{ + struct mp_decoder_list *codecs = talloc_zero(NULL, struct mp_decoder_list); + mp_add_lavc_encoders(codecs); + int r = m_property_read_list(action, arg, codecs->num_entries, + get_decoder_entry, codecs); + talloc_free(codecs); + return r; +} + static int mp_property_version(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3284,6 +3359,16 @@ static int mp_property_configuration(void *ctx, struct m_property *prop, return m_property_strdup_ro(action, arg, CONFIGURATION); } +static int mp_property_ffmpeg(void *ctx, struct m_property *prop, + int action, void *arg) +{ +#if HAVE_AV_VERSION_INFO + return m_property_strdup_ro(action, arg, av_version_info()); +#else + return M_PROPERTY_UNAVAILABLE; +#endif +} + static int mp_property_alias(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3535,6 +3620,7 @@ static const struct m_property mp_properties[] = { {"cache-used", mp_property_cache_used}, {"cache-size", mp_property_cache_size}, {"cache-idle", mp_property_cache_idle}, + {"cache-speed", mp_property_cache_speed}, {"demuxer-cache-duration", mp_property_demuxer_cache_duration}, {"demuxer-cache-time", mp_property_demuxer_cache_time}, {"demuxer-cache-idle", mp_property_demuxer_cache_idle}, @@ -3591,6 +3677,7 @@ static const struct m_property mp_properties[] = { {"video-output-levels", mp_property_video_color, .priv = (void *)"output-levels"}, {"panscan", panscan_property_helper}, + {"keepaspect", panscan_property_helper}, {"video-zoom", panscan_property_helper}, {"video-align-x", panscan_property_helper}, {"video-align-y", panscan_property_helper}, @@ -3645,6 +3732,7 @@ static const struct m_property mp_properties[] = { {"af", mp_property_af}, {"video-rotate", video_simple_refresh_property}, + {"video-stereo-mode", video_simple_refresh_property}, {"ab-loop-a", mp_property_ab_loop}, {"ab-loop-b", mp_property_ab_loop}, @@ -3689,9 +3777,12 @@ static const struct m_property mp_properties[] = { {"working-directory", mp_property_cwd}, {"protocol-list", mp_property_protocols}, + {"decoder-list", mp_property_decoders}, + {"encoder-list", mp_property_encoders}, {"mpv-version", mp_property_version}, {"mpv-configuration", mp_property_configuration}, + {"ffmpeg-version", mp_property_ffmpeg}, {"options", mp_property_options}, {"file-local-options", mp_property_local_options}, @@ -3746,7 +3837,7 @@ static const char *const *const mp_event_property_change[] = { E(MPV_EVENT_CHAPTER_CHANGE, "chapter", "chapter-metadata"), E(MP_EVENT_CACHE_UPDATE, "cache", "cache-free", "cache-used", "cache-idle", "demuxer-cache-duration", "demuxer-cache-idle", "paused-for-cache", - "demuxer-cache-time"), + "demuxer-cache-time", "cache-buffering-state", "cache-speed"), E(MP_EVENT_WIN_RESIZE, "window-scale", "osd-width", "osd-height", "osd-par"), E(MP_EVENT_WIN_STATE, "window-minimized", "display-names", "display-fps", "fullscreen"), }; @@ -4753,6 +4844,8 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re struct track *t = find_track_with_url(mpctx, type, cmd->args[0].v.s); if (t) { mp_switch_track(mpctx, t->type, t, FLAG_MARK_SELECTION); + if (mpctx->playback_initialized) + print_track_list(mpctx, "Track switched:"); return 0; } } diff --git a/player/core.h b/player/core.h index f26cacbb51..21129d6ea3 100644 --- a/player/core.h +++ b/player/core.h @@ -147,10 +147,6 @@ struct track { struct vo_chain *vo_c; struct ao_chain *ao_c; struct lavfi_pad *sink; - - // For external subtitles, which are read fully on init. Do not attempt - // to read packets from them. - bool preloaded; }; // Summarizes video filtering and output. diff --git a/player/external_files.c b/player/external_files.c index c1b7d53c3c..dfd1ca6802 100644 --- a/player/external_files.c +++ b/player/external_files.c @@ -20,6 +20,7 @@ static const char *const sub_exts[] = {"utf", "utf8", "utf-8", "idx", "sub", "sr static const char *const audio_exts[] = {"mp3", "aac", "mka", "dts", "flac", "ogg", "m4a", "ac3", "opus", "wav", + "wv", NULL}; static bool test_ext_list(bstr ext, const char *const *list) diff --git a/player/loadfile.c b/player/loadfile.c index b1e9cd2057..5cc1ef5f77 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1027,7 +1027,7 @@ reopen_file: goto terminate_playback; if (opts->stream_dump && opts->stream_dump[0]) { - if (stream_dump(mpctx, mpctx->stream_open_filename) < 0) + if (stream_dump(mpctx, mpctx->stream_open_filename) >= 0) mpctx->error_playing = 1; goto terminate_playback; } diff --git a/player/lua.c b/player/lua.c index 9fe1d0deca..84d7295640 100644 --- a/player/lua.c +++ b/player/lua.c @@ -391,6 +391,7 @@ static int load_lua(struct mpv_handle *client, const char *fname) r = 0; error_out: + osd_set_external(ctx->mpctx->osd, client, 0, 0, NULL); // remove overlay mp_resume_all(client); if (ctx->state) lua_close(ctx->state); @@ -963,31 +964,21 @@ static int script_command_native(lua_State *L) static int script_set_osd_ass(lua_State *L) { - struct MPContext *mpctx = get_mpctx(L); + struct script_ctx *ctx = get_ctx(L); int res_x = luaL_checkinteger(L, 1); int res_y = luaL_checkinteger(L, 2); const char *text = luaL_checkstring(L, 3); if (!text[0]) text = " "; // force external OSD initialization - osd_set_external(mpctx->osd, res_x, res_y, (char *)text); - mp_input_wakeup(mpctx->input); + osd_set_external(ctx->mpctx->osd, ctx->client, res_x, res_y, (char *)text); + mp_input_wakeup(ctx->mpctx->input); return 0; } -static int script_get_osd_resolution(lua_State *L) -{ - struct MPContext *mpctx = get_mpctx(L); - int w, h; - osd_object_get_resolution(mpctx->osd, OSDTYPE_EXTERNAL, &w, &h); - lua_pushnumber(L, w); - lua_pushnumber(L, h); - return 2; -} - -static int script_get_screen_size(lua_State *L) +static int script_get_osd_size(lua_State *L) { struct MPContext *mpctx = get_mpctx(L); - struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_EXTERNAL); + struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd); double aspect = 1.0 * vo_res.w / MPMAX(vo_res.h, 1) / (vo_res.display_par ? vo_res.display_par : 1); lua_pushnumber(L, vo_res.w); @@ -996,10 +987,10 @@ static int script_get_screen_size(lua_State *L) return 3; } -static int script_get_screen_margins(lua_State *L) +static int script_get_osd_margins(lua_State *L) { struct MPContext *mpctx = get_mpctx(L); - struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd, OSDTYPE_EXTERNAL); + struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd); lua_pushnumber(L, vo_res.ml); lua_pushnumber(L, vo_res.mt); lua_pushnumber(L, vo_res.mr); @@ -1012,10 +1003,8 @@ static int script_get_mouse_pos(lua_State *L) struct MPContext *mpctx = get_mpctx(L); int px, py; mp_input_get_mouse_pos(mpctx->input, &px, &py); - double sw, sh; - osd_object_get_scale_factor(mpctx->osd, OSDTYPE_EXTERNAL, &sw, &sh); - lua_pushnumber(L, px * sw); - lua_pushnumber(L, py * sh); + lua_pushnumber(L, px); + lua_pushnumber(L, py); return 2; } @@ -1030,14 +1019,11 @@ static int script_input_set_section_mouse_area(lua_State *L) { struct MPContext *mpctx = get_mpctx(L); - double sw, sh; - osd_object_get_scale_factor(mpctx->osd, OSDTYPE_EXTERNAL, &sw, &sh); - char *section = (char *)luaL_checkstring(L, 1); - int x0 = sw ? luaL_checkinteger(L, 2) / sw : 0; - int y0 = sh ? luaL_checkinteger(L, 3) / sh : 0; - int x1 = sw ? luaL_checkinteger(L, 4) / sw : 0; - int y1 = sh ? luaL_checkinteger(L, 5) / sh : 0; + int x0 = luaL_checkinteger(L, 2); + int y0 = luaL_checkinteger(L, 3); + int x1 = luaL_checkinteger(L, 4); + int y1 = luaL_checkinteger(L, 5); mp_input_set_section_mouse_area(mpctx->input, section, x0, y0, x1, y1); return 0; } @@ -1266,9 +1252,8 @@ static const struct fn_entry main_fns[] = { FN_ENTRY(raw_observe_property), FN_ENTRY(raw_unobserve_property), FN_ENTRY(set_osd_ass), - FN_ENTRY(get_osd_resolution), - FN_ENTRY(get_screen_size), - FN_ENTRY(get_screen_margins), + FN_ENTRY(get_osd_size), + FN_ENTRY(get_osd_margins), FN_ENTRY(get_mouse_pos), FN_ENTRY(get_time), FN_ENTRY(input_set_section_mouse_area), diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index d0ef57cccd..a12e5bd3c3 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -145,7 +145,7 @@ local function update_key_bindings() end local cfg = "" for k, v in pairs(key_bindings) do - if v.forced ~= def then + if v.bind and v.forced ~= def then cfg = cfg .. v.bind .. "\n" end end @@ -161,7 +161,6 @@ local function add_binding(attrs, key, name, fn, rp) fn = name name = reserve_binding() end - local bind = key local repeatable = rp == "repeatable" or rp["repeatable"] if rp["forced"] then attrs.forced = true @@ -205,7 +204,9 @@ local function add_binding(attrs, key, name, fn, rp) end msg_cb = fn end - attrs.bind = bind .. " script-binding " .. mp.script_name .. "/" .. name + if key and #key > 0 then + attrs.bind = key .. " script-binding " .. mp.script_name .. "/" .. name + end attrs.name = name key_bindings[name] = attrs update_key_bindings() @@ -438,7 +439,7 @@ local function call_event_handlers(e) end end -mp.use_suspend = true +mp.use_suspend = false function mp.dispatch_events(allow_wait) local more_events = true diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 24afeef970..23f7cc6d19 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -99,6 +99,27 @@ local state = { -- Helperfunctions -- +-- scale factor for translating between real and virtual ASS coordinates +function get_virt_scale_factor() + local w, h = mp.get_osd_size() + if w <= 0 or h <= 0 then + return 0, 0 + end + return osc_param.playresx / w, osc_param.playresy / h +end + +-- return mouse position in virtual ASS coordinates (playresx/y) +function get_virt_mouse_pos() + local sx, sy = get_virt_scale_factor() + local x, y = mp.get_mouse_pos() + return x * sx, y * sy +end + +function set_virt_mouse_area(x0, y0, x1, y1, name) + local sx, sy = get_virt_scale_factor() + mp.set_mouse_area(x0 / sx, y0 / sy, x1 / sx, y1 / sy, name) +end + function scale_value(x0, x1, y0, y1, val) local m = (y1 - y0) / (x1 - x0) local b = y0 - (m * x0) @@ -141,7 +162,7 @@ function mouse_hit(element) end function mouse_hit_coords(bX1, bY1, bX2, bY2) - local mX, mY = mp.get_mouse_pos() + local mX, mY = get_virt_mouse_pos() return (mX >= bX1 and mX <= bX2 and mY >= bY1 and mY <= bY2) end @@ -182,7 +203,7 @@ end -- get value at current mouse position function get_slider_value(element) - return get_slider_value_at(element, mp.get_mouse_pos()) + return get_slider_value_at(element, get_virt_mouse_pos()) end function countone(val) @@ -589,7 +610,7 @@ function render_elements(master_ass) end elem_ass:new_event() - elem_ass:pos(mp.get_mouse_pos(), ty) + elem_ass:pos(get_virt_mouse_pos(), ty) elem_ass:an(an) elem_ass:append(slider_lo.tooltip_style) elem_ass:append(tooltiplabel) @@ -1298,7 +1319,7 @@ function osc_init() -- set canvas resolution according to display aspect and scaling setting local baseResY = 720 - local display_w, display_h, display_aspect = mp.get_screen_size() + local display_w, display_h, display_aspect = mp.get_osd_size() local scale = 1 if (mp.get_property("video") == "no") then -- dummy/forced window @@ -1718,8 +1739,8 @@ end function render() msg.debug("rendering") - local current_screen_sizeX, current_screen_sizeY, aspect = mp.get_screen_size() - local mouseX, mouseY = mp.get_mouse_pos() + local current_screen_sizeX, current_screen_sizeY, aspect = mp.get_osd_size() + local mouseX, mouseY = get_virt_mouse_pos() local now = mp.get_time() -- check if display changed, if so request reinit @@ -1782,7 +1803,7 @@ function render() --mouse show/hide area for k,cords in pairs(osc_param.areas["showhide"]) do - mp.set_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "showhide") + set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "showhide") end do_enable_keybindings() @@ -1791,7 +1812,7 @@ function render() for _,cords in ipairs(osc_param.areas["input"]) do if state.osc_visible then -- activate only when OSC is actually visible - mp.set_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "input") + set_virt_mouse_area(cords.x1, cords.y1, cords.x2, cords.y2, "input") end if state.osc_visible ~= state.input_enabled then if state.osc_visible then @@ -1887,7 +1908,7 @@ function process_event(source, what) state.mouse_down_counter = 0 elseif source == "mouse_move" then - local mouseX, mouseY = mp.get_mouse_pos() + local mouseX, mouseY = get_virt_mouse_pos() if (user_opts.minmousemove == 0) or (not ((state.last_mouseX == nil) or (state.last_mouseY == nil)) and ((math.abs(mouseX - state.last_mouseX) >= user_opts.minmousemove) diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 5b90b95cdd..c0ce8b97c4 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -207,7 +207,7 @@ mp.add_hook("on_load", 10, function () -- audio url mp.commandv("audio-add", json["requested_formats"][2].url, - "select", json["requested_formats"][2]["format_note"]) + "select", json["requested_formats"][2]["format_note"] or "") elseif not (json.url == nil) then -- normal video diff --git a/player/main.c b/player/main.c index 70176f2d35..21c273338c 100644 --- a/player/main.c +++ b/player/main.c @@ -472,9 +472,7 @@ int mp_initialize(struct MPContext *mpctx, char **options) if (opts->force_vo == 2 && handle_force_window(mpctx, false) < 0) return -1; -#if !defined(__MINGW32__) mpctx->ipc_ctx = mp_init_ipc(mpctx->clients, mpctx->global); -#endif #ifdef _WIN32 if (opts->w32_priority > 0) diff --git a/player/misc.c b/player/misc.c index d68ad1db3e..f14f5a43e3 100644 --- a/player/misc.c +++ b/player/misc.c @@ -95,23 +95,20 @@ double get_play_end_pts(struct MPContext *mpctx) float mp_get_cache_percent(struct MPContext *mpctx) { - if (mpctx->demuxer) { - int64_t size = -1; - int64_t fill = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_SIZE, &size); - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &fill); - if (size > 0 && fill >= 0) - return fill / (size / 100.0); - } + struct stream_cache_info info = {0}; + if (mpctx->demuxer) + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size > 0 && info.fill >= 0) + return info.fill / (info.size / 100.0); return -1; } bool mp_get_cache_idle(struct MPContext *mpctx) { - int idle = 0; + struct stream_cache_info info = {0}; if (mpctx->demuxer) - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_IDLE, &idle); - return idle; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + return info.idle; } void update_vo_playback_state(struct MPContext *mpctx) diff --git a/player/osd.c b/player/osd.c index 2a09911ac7..7da4a038bf 100644 --- a/player/osd.c +++ b/player/osd.c @@ -257,9 +257,9 @@ static void print_status(struct MPContext *mpctx) } if (mpctx->demuxer) { - int64_t fill = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &fill); - if (fill >= 0) { + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + if (info.size > 0) { saddf(&line, " Cache: "); struct demux_ctrl_reader_state s = {.ts_duration = -1}; @@ -270,10 +270,10 @@ static void print_status(struct MPContext *mpctx) } else { saddf(&line, "%2ds", (int)s.ts_duration); } - if (fill >= 1024 * 1024) { - saddf(&line, "+%lldMB", (long long)(fill / 1024 / 1024)); + if (info.fill >= 1024 * 1024) { + saddf(&line, "+%lldMB", (long long)(info.fill / 1024 / 1024)); } else { - saddf(&line, "+%lldKB", (long long)(fill / 1024)); + saddf(&line, "+%lldKB", (long long)(info.fill / 1024)); } } } @@ -561,6 +561,6 @@ void update_osd_msg(struct MPContext *mpctx) text = talloc_asprintf_append(text, "%s%s", text ? "\n" : "", mpctx->osd_msg_text); } - osd_set_text(osd, OSDTYPE_OSD, text); + osd_set_text(osd, text); talloc_free(text); } diff --git a/player/playloop.c b/player/playloop.c index 63234812d4..fcbb86ac04 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -522,8 +522,9 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx) if (!mpctx->demuxer) return; - int idle = -1; - demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_IDLE, &idle); + struct stream_cache_info info = {0}; + demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_INFO, &info); + int idle = info.size > 0 ? info.idle : -1; struct demux_ctrl_reader_state s = {.idle = true, .ts_duration = -1}; demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s); diff --git a/player/sub.c b/player/sub.c index 6892ac935b..6d01e0ca5d 100644 --- a/player/sub.c +++ b/player/sub.c @@ -71,8 +71,7 @@ void uninit_sub(struct MPContext *mpctx, struct track *track) reset_subtitles(mpctx, track); sub_select(track->d_sub, false); int order = get_order(mpctx, track); - if (order >= 0 && order <= 1) - osd_set_sub(mpctx->osd, OSDTYPE_SUB + order, NULL); + osd_set_sub(mpctx->osd, order, NULL); } }< |