summaryrefslogtreecommitdiffstats
path: root/player
Commit message (Collapse)AuthorAgeFilesLines
* osc.lua: seekbar hover: speed-up chapter accessAvi Halachmi (:avih)2022-02-061-8/+9
| | | | | | | | | | | | | | | | | | | | | | This speeds up chapter name access while hovering the seekbar: - Fetch the chapter-list property using observation rather than on every render while hovering the bar. Property access, especially with potentially lots of values (chapters), can be expensive-ish, and can involve locking, so the less per-render the better. - Sort the list once (on change) to simplify the iteration logic when searching the chapter which matches the mouse position. It's still O(N) (no binary search currently), but with less work. The cached sorted list is stored at the state. While there are other places which access this property and could use this cache, for now we don't touch them, because they're not performance-critical (on init for the chapter markers, on ch_{prev,next} button click for OSD). Caching properties using observation instead of using mp.get_property can indeed speedup other places too, but it should be part of a system rather than implemented per-property. Maybe some day.
* js: utils.get_user_path: make wrapper of expand-pathAvi Halachmi (:avih)2022-02-042-7/+2
| | | | | | | | When utils.get_user_path was added, the expand-path command didn't exist. Now it does, so remove the C code, make it a trivial wrapper. Keep this function for backward compat to not break scripts, but technically it's not required anymore.
* auto_profiles.lua: don't warn if profile-restore=defaultCogentRedTester2022-01-301-1/+1
| | | | | | | | | | | | | | | The code assumed that the value of the profile-restore field is "default" for such profiles, but the C implementation is such that the field is intentionally omitted in such case. This resulted in incorrectly trying to restore such profiles. However, there are no stored values with profile-restore=default, so it only resulted in a harmless warning, but otherwise behaved correctly (i.e. nothing is restored). Fix the condition by taking into account that missing field means "default", so that it doesn't try to restore in such case, and avoid the warning.
* Revert "options: add --sub-visibility=<primary-only|secondary-only>"Avi Halachmi (:avih)2022-01-191-7/+5
| | | | | | | | | | This reverts commit 04f0b0abe48d664aaa1400d1dddb02b434999b85. It's not a good idea to unify the names only for visibility, while keeping secondary-* for everything else. This needs a bit more thought before we allow secondary sub to be visible on its own.
* options: add --sub-visibility=<primary-only|secondary-only>Ripose2022-01-191-5/+7
| | | | | | | | | | | | | Adds --sub-visibility choices 'primary-only' for only displaying the primary subtitle track, and 'secondary-only' for only displaying secondary subtitle track. Removes --secondary-sub-visibility and displays a message telling the user to use --sub-visibility=yes/primary-only instead. These changes make it so that the default 'sub-visibility' bind 'v' cycles through all the 'sub-visibility' choices, 'no', 'yes', 'primary-only', and 'secondary-only'.
* player: add thd (TrueHD) to whitelist of audio extensionschelobaka2022-01-191-1/+1
|
* player: fix parentheses warning with &&LaserEyess2022-01-181-2/+2
| | | | | | Was tripping -Wparantheses as the && after the || was not explicitly wrapped. However, due to operator precedence the intended effect was still correct.
* sub: rename SUBBITMAP_RGBA to SUBBITMAP_BGRANiklas Haas2022-01-111-1/+1
| | | | | This was a misnomer, the actual channel order is IMGFMT_BGRA (as the comment explicitly point out). Rename the enum for consistency.
* js: events registration: clarify breakage/fixAvi Halachmi (:avih)2021-12-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This commit is mainly for correcting the previous commit message. The previous commit fixed an issue where [un]registering events above the first event ID "hole" is not requested from libmpv, and that's indeed true. However, this had nearly zero impact in practice, because libmpv enables all events by default anyway (except TICK). Therefore, above the first ID "hole" [un]register requests are not sent to libmpv, and the events just keep arriving. But the callback functions are still added/removed correctly (at defaults.js), and so the script is not called back even if unregister did not actually happen with libmpv. The only event which was affected is TICK - which is not enabled by default as it's deprecated, and before the previous commit could not be enabled. So the fix is more a general correctness fix now that the IDs array can have "holes", but with effctively no impact in practice.
* js: fix event registration (keys, script-message, more)Avi Halachmi (:avih)2021-12-261-3/+3
| | | | | | | | | | | | | | Commit 63205981 removed some events but left all other event IDs at their original values, which created "holes" at the events IDs array. The JS backend for mp.register_event maps a name to an ID by scanning all IDs and stopping when the name was found or a NULL name was returned. Lua does the same except that it doesn't stop on NULL name. Previously it was not possible to have a NULL name before the end of the array, but now it is possible due to the enumeration holes. Fix by skipping missing names, like lua does.
* player: make deprecated track/chapter/metadata events internalsfan52021-12-155-20/+16
| | | | | We still need these to track or notify of modifications to certain properties, but they're now gone from the libmpv ABI.
* lua: remove mp.suspend, resume and resume_allsfan52021-12-152-23/+0
| | | | | | These functions were deprecated in v0.21.0 and no-ops since v0.23.0. The matching client API functions were removed in the previous commit.
* libmpv: remove opengl_cb API and other deprecated symbolssfan52021-12-153-76/+1
| | | | | | Not all deprecated symbols were removed. Only three events were removed for now since these are not used internally. This bumps the library version to 2.0.
* {player,video}: remove references to obsolete opengl-cb APIsfan52021-12-152-5/+4
|
* audio: fix typoAman Karmani2021-12-031-1/+1
|
* player: make --keep-open=always work with --loop-playlistLeo Izen2021-11-281-2/+2
| | | | | | | | Allow --keep-open=always to work with --loop-playlist, where before this patch it would work only on the last playthrough of the playlist. This patch allows it to work on all playthroughs. Fixes #9470.
* osc: fix cache displaying 60s in some casesFunami5802021-11-271-2/+2
| | | | It was caused by string.format rounding e.g. 59.9 to 60.
* osc: add options: chapters/playlist OSD, hover chapter formatAvi Halachmi (:avih)2021-11-251-6/+17
| | | | | | | | | | | Previously OSD was always displayed on {ch,pl}_{next,prev} left-click, and seekbar-hover-chapter was always enabled and with fixed format. Now it can be controlled with: - chapters_osd, playlist_osd: yes/no (only affects left-click). - chapter_fmt: lua string.format template, or "no" to disable. Fixes #4675
* ytdl_hook.lua: improve check for sub language before inserting all-subsUmar Javed2021-11-151-1/+1
| | | | | | | youtube-dl and yt-dlp both support --sub-langs and --srt-lang in addition to --sub-lang for defining languages of subtitles. This hook only checked for sub-lang in --ytdl-raw-options and inserted --all-subs in its absence.
* options: const annotate all m_opt_choice_alternatives accessorsEmil Velikov2021-11-151-1/+1
| | | | | | | Constant data, most accessors are good but some were missing the explicit notation. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
* options: const annotate m_obj_list accessorsEmil Velikov2021-11-151-1/+1
| | | | | | | Nearly all the code base correctly references the data as constant. But a couple of instances - fix those. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
* osdep: rename MP_UNREACHABLENiklas Haas2021-11-031-1/+1
| | | | | It was pointed out on IRC that the name is misleading, since the actual semantics of the macro is to assert first.
* osdep: add MP_UNREACHABLENiklas Haas2021-11-031-1/+1
| | | | | | | | | This seems to work on gcc, clang and mingw as-is, but I made it conditional on __GNUC__ just in case, even though I can't figure out which compilers we care about that don't export this define. Also replace all instances of assert(0) in the code by MP_UNREACHABLE(), which is a strict improvement.
* js: ~~/init.js: use mp.find_config_fileAvi Halachmi (:avih)2021-11-011-9/+5
| | | | | | | | | | | | The problem with the previous code - which used mp.get_user_path, is that it returns a path even with --no-config, and even if the file doesn't exist. This is why we tested the "config" property, and also used mp.utils.file_info to check that the file exists. mp.find_config_file doesn't return a path with no-cofig and doesn't return a path if the file doesn't exists. It's simpler and better.
* console.lua: define remaining emacs keybindingsGuido Cella2021-11-011-3/+33
|
* lua: makenode: prevent lua stack corruptionAvi Halachmi (:avih)2021-10-201-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Normally there was no issue, but when the code converted a deeply nested table into an mpv node - it didn't ensure the stack has room. Lua doesn't check stack overflow when invoking lua_push* functions, and leaves this responsibility to the (c) user via lua_checkstack. Normally that's not an issue because when a lua (or autofree) function is called, it's guaranteed at least LUA_MINSTACK (20) pushes. However, pushnode and makenode are recursive, and each iteration can add few values at the stack (which are popped when the recursion unwinds), so checkstack must be used on (recursive) entry. pushnode already checked the stack, makenode did not. This commit checks the stack at makenode as well. The value of 6 (stack places to reserve) is with some room to spare, and in pratice each iteration needs 2-3 at most (pushnode also leaves room). Example which could previously corrupt the stack: utils.format_json({d1={d2={<8 more times>}}} This uses makenode to convert the lua table into an mpv node which the json writer uses as input, and if the depth is 10 or more then corruption could occur. mp.command_native is also affected, as well as any other mp/utils command which takes a lua table as input. While at it, fix the error string which pushnode used (luaL_checkstack uses the provided string with "Stack overflow (%s)", so the user message only needs to be additional info).
* lua: autofree infrastructure: x2 fasterAvi Halachmi (:avih)2021-10-191-17/+47
| | | | | | | | | | | | | | | | | | | | | The speedup is due to moving big part of the autofree runtime overhead (new lua c closure) to happen once on init at af_pushcclosure, instead of on every call. This also allows supporting upvalues trivially, even if mpv doesn't use it currently, and is more consistent with lua APIs. While x2 infrastructure speedup is meaningful - and similar between lua 5.1/5.2/jit, in practice it's a much smaller improvement because the autofree overhead is typically small compared to the "real" work (the actual functionality, and talloc+free which is needed anyway). So with this commit, fast functions improve more in percentage. E.g. utils.parse_json("0") is relatively fast and is now about 25% faster, while a slower call like mp.command_native("ignore") is now about 10% faster than before. If we had mp.noop() which does nothing (but still "needs" alloc/free) - it would now be about 50% faster. Overall, it's a mild performance improvements, the API is now more consistent with lua, and without increasing code size or complexity.
* js: custom-init: use ~~/init.js instead of ~~/.init.js (dot)Avi Halachmi (:avih)2021-10-191-6/+10
| | | | | | | | | | | | | | | | | | | | mpv doesn't have other dot files in its config dir, and it also shouldn't be "invisible". The new name ~~/init.js now replaces ~~/.init.js While mpv usually deprecates things before outright removing them, in this case the old (dot) name is replaced without deprecation: - It's a bad idea to execute hidden scripts, even if at a config dir, and we don't want to do that for the next release cycle too. - We warn if the old (dot) name exists and the new name doesn't, which should be reasonably visible for affected users. - It's likely niche enough to not cause too much pain. If for some reason both names are needed, e.g. when using also an old mpv versions, then the old name could be symlinked to the new one, or simply have one line: `require("~~/init")` to load the new name, while a new mpv version will load (only) the new name without warning.
* command: with lavfi-complex, make current-tracks return the first oneGuido Cella2021-10-151-0/+10
| | | | | | | | | | | | | | | | | | | This behavior is more convenient and allows profile conditions like: [video] profile-cond=get('current-tracks/video/image') == false [image] profile-cond=get('current-tracks/video/image') Otherwise, these profiles have to be manually applied and restored in a script. The note about discouraging the use of current-tracks in scripts is removed, because it makes people avoid using this convenient property. It was added in 720bcd79d03 without leaving an explanation of why you shouldn't use it, and the only reason seems to be that it doesn't work with lavfi-complex, but this commit changes that.
* player: add track-list/N/image sub-propertyGuido Cella2021-10-143-0/+3
| | | | | | | | | | | | | | | | | | | | | | This exposes whether a video track is detected as an image, which is useful for profile conditions, property expansion and lavfi-complex. The lavf demuxer sets image to true when the existing check detects an image. When the lavf demuxer fails, the mf one guesses if the file is an image by its extension, so sh->image is set to true when the mf demuxer succeds and there's only one file. The mkv demuxer just sets image to true for any attached picture. The timeline demuxer just copies the value of image from source to destination. This sets image to true for attached pictures, standalone images and images added with !new_stream in EDL playlists, but it is imperfect since you could concatenate multiple images in an EDL playlist (which should be done with the mf demuxer anyway). This is good enough anyway since the comment of the modified function already says it is "Imperfect and arbitrary".
* js: custom init: ignore ~~/.init.js with --no-configAvi Halachmi (:avih)2021-10-121-1/+4
| | | | | | The custom init script should be considered a configuration file, and as such it should be ignored when the user wants vanilla mpv - and now it is ignored with --no-config.
* osc.lua: avoid infinite ticks loop on idleAvi Halachmi (:avih)2021-10-031-1/+11
| | | | | | | | | | | | | | | Before this commit, animation-end was handled at render(), however, it's not called on idle, which resulted in state.anitype ~= nil, with nothing to reset it during idle, which caused in an infinite tick() loop (starts on first mouse move). Now tick resets the animation on idle, and also, as a safety measure, if we're past 1s after the animation deadline. The safety measure is because the osc states are complex, and it's easier to detect a "we really shouldn't be animating now" at tick() itself rather than detecting the exact states where animation should be reset. Generally, the safety mmeasure is not needed.
* osc.lua: unify animation reset function (no-op)Avi Halachmi (:avih)2021-10-031-6/+8
|
* Revert "player: add track-list/N/image sub-property"Jan Ekström2021-10-023-3/+0
| | | | | | | | Unfortunately, this functionality in large part based on a struct member that was made private in FFmpeg/FFmpeg@7489f632815c98ad58c3db71d1a5239b5dae266c in May. Unfortunately, this was not noticed during review. This reverts commit 0862664ac952d21fef531a8923a58ae575268fc5.
* player: add track-list/N/image sub-propertyGuido Cella2021-10-023-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This exposes whether a video track is detected as an image. This is useful for profile conditions, property expansion and lavfi-complex, and is more accurate than any detection even Lua scripts can perform, since they can't differentiate between images and videos without container-fps and audio and with duration 1 (which is the duration set by the mf demuxer with the default --mf-fps=1). The lavf demuxer image check is moved to where the number of frames is available for comparison, and is modified to check the number of frames and duration instead of the video codec. This doesn't misdetect videos in a codec commonly used for images (e.g. mjpeg) as images, and can detect images in a codec commonly used for videos (e.g. 1-frame gifs). pix files are also now detected as images, while before they weren't since the condition was checking if the AVInputFormat name ends with _pipe, and alias_pix doesn't. Both nb_frames and codec_info_nb_frames are checked because nb_frames is 0 for some video codecs (hevc, av1, vc1, mpeg1video, vp9 if forcing --demuxer=lavf), and codec_info_nb_frames is 1 for others (mpeg, mpeg4, wmv3). The duration is checked as well because for some uncommon codecs and containers found in FFMpeg's FATE suite, libavformat returns nb_frames = 0 and codec_info_nb_frames = 1. For some of them it even returns duration = 0, so they are blacklisted in order to never be considered images. The extra codecs that would have to be blacklisted without checking the duration are AV_CODEC_ID_4XM, AV_CODEC_ID_BINKVIDEO, AV_CODEC_ID_DSICINVIDEO, AV_CODEC_ID_ESCAPE130, AV_CODEC_ID_MMVIDEO, AV_CODEC_ID_NUV, AV_CODEC_ID_RL2, AV_CODEC_ID_SMACKVIDEO and AV_CODEC_ID_XAN_WC3, while the containers are film-cpk, ivf and ogg. The lower limit for duration is 10 because that's the duration of 1-frame gifs. Streams with codec_info_nb_frames 0 are not considered images because vp9 and av1 have nb_frames = 0 and codec_info_nb_frames = 0, and we can't rely on just the duration to detect them because they could be livestreams without an initial duration, and actually even if we could for these codecs libavformat returns huge negative durations like -9223372036854775808. Some more images in the FATE suite that are really frames cut from a video in an uncommon codec and container, like cine/bayer_gbrg8.cine, could be detected by allowing codec_info_nb_frames = 0, but then any present and future video codec with nb_frames = 0 and codec_info_nb_frames = 0 would need to be added to the blacklist. Some even have duration > 10, so to detect these images the duration check would have to be removed, and all the previously mentioned extra codecs and containers would have to be added added to the blacklists, which means that images that use them (if they exist anywhere) will never be detected. These FATE images aren't detected as such by mediainfo either anyway, nor can a Lua script reliably detect them as images since they have container-fps and duration > 0 and != 1, and you probably will never see files like them anywhere else. For attached pictures the lavf demuxer always set image to true, which is necessary because they have duration > 10. There is a minor change in behavior for which audio with attached pictures now has mf-fps as container-fps instead of unavailable, but this makes it consistent with external cover art, which was already being assigned mf-fps. When the lavf demuxer fails, the mf one guesses if the file is an image by its extension, so sh->image is set to true when the mf demuxer succeds and there's only one file. Even if you add a video's file type to --mf-type and open it with the mf protocol, only the first frame is used, so setting image to true is still accurate. When converting an image to the extensions listed in demux/demux_mf.c, tga and pam files are currently the only ones detected by the mf demuxer rather than lavf. Actually they are detected with the image2 format, but it is blacklisted; see d0fee0ac33a. The mkv demuxer just sets image to true for any attached picture. The timeline demuxer just copies the value of image from source to destination. This sets image to true for attached pictures, standalone images and images added with !new_stream in EDL playlists, but it is imperfect since you could concatenate multiple images in an EDL playlist (which should be done with the mf demuxer anyway). This is good enough anyway since the comment of the modified function already says it is "Imperfect and arbitrary".
* js: custom init (~~/.init.js): fail loudly on errorsAvi Halachmi (:avih)2021-09-301-3/+3
| | | | | | | | | | | | Previously, loading ~~/.init.js was inside a try block, in order to quietly ignore errors if the file doesn't exist. However, that also prevented any real errors from showing up even when the file does exist, and the script continued as if everything is OK, while in fact the custom init script didn't complete correctly. Now we first check if the file exists, and then load it without try/catch, so that any error shows up normally (and abort the script).
* ytdl_hook.lua: search for yt-dlp by defaultGuido Cella2021-09-251-18/+48
| | | | | | | | | | | Because youtube-dl is inactive and the yt-dlp fork is becoming more popular, make mpv use yt-dlp without any extra configuration. yt-dlp is ordered before youtube-dl because it's more obscure, so users who have yt-dlp installed are more likely to want to use it rather than youtube-dl. Fixes #9208.
* command: cycle: respect the prefix "repeatable"Avi Halachmi (:avih)2021-08-191-1/+3
| | | | | | | | | | | | | | | | | The "cycle" command _declaration_ enables repeatability by default, however, the command handler applies additional logic to augment it, based on the property which is being cycled - using some guesswork. Specifically, properties with discrete values are not repeatable (like sub or osd-level), while continuous properties are repeatable (like volume). Previously, the "repeatable" prefix could not override this additional logic. This commit changes the behavior so that the logic affects only the default repeatability (still based on the property like before), however, the "repeatable" prefix is now allowed to override it.
* stats.lua: typo lavfi-complexStefan de Konink2021-08-151-2/+2
| | | | Fix typo lavi-complex to lavfi-complex.
* sub: show subs without duration on vid changeGuido Cella2021-08-131-1/+1
| | | | | | | | | | | | | | | | | When changing video track with subtitles with unknown duration, they aren't shown until you seek, cycle sub back and forth, or apply a video filter. This is caused by reinit_video_chain_src() calling reset_subtitle_state() -> sub/sd_ass.c:reset() -> ass_flush_events() when ctx->duration_unknown is true. The ass_flush_events() call was added in a714f8e so subs with unknown duration wouldn't multiply on seek, i.e. when reset_subtitle_state() is called from reset_playback_state(). So keep calling it from there, and in reinit_video_chain_src() use just term_osd_set_subs(mpctx, NULL) instead to clear any subtitles printed to the terminal. The reset_subtitle_state() call was added in c1ac97b to "reset the state correctly when switching between video/no-video", but with it removed I no longer notice any issue doing that.
* sub: align ytdl-hook secondary subs to the topGuido Cella2021-08-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 29e15e6248 prefixed youtube-dl's subs url with an edl prefix to not download them until they're selected, which is useful when there are many sub languages. But this prefix broke the alignment of secondary subs, which would overlap the primary subs instead of always being placed at the top. This can be tested with --sub-file='edl://!no_clip;!delay_open,media_type=sub;secondary_sub.srt' When a sub is added, sub.c:reinit_sub() is called. This calls in init_subdec() -> dec_sub.c:sub_create() -> init_decoder() -> sd_ass:init(). Then reinit_sub() calls sub_control(track->d_sub, SD_CTRL_SET_TOP, &(bool){!!order}) which sets sd_ass_priv.on_top = true for secondary subs. But for EDL subs the real sub is initialized again when in dec_sub.c:sub_read_packets() is_new_segment() returns true and update_segment() is called, or when sub_get_bitmaps() calls update_segment(). update_segment() then calls init_decoder(), which calls sd_ass:init(), so sd_ass_priv is reinitialized, and its on_top property is left false. This commit sets it to true again. For URLs that need to be downloaded it seems that the update_segment() call that reinitializes sd_ass_priv is always the one in sub_read_packets(), but with local subs sub_get_bitmaps() is usually called earlier (though there shouldn't be a reason to use the EDL URL for local subs), so I added the order parameter to sub_create(), rather than adding it to all of update_segment(), sub_read_packets() and sub_get_bitmaps(). Also removes the cast to bool in the other sub_control call, since sub/sd_ass.c:control already casts arg to bool when cmd is SD_CTRL_SET_TOP.
* lua: read_options: quote values at error messagesAvi Halachmi (:avih)2021-08-101-3/+3
| | | | | | | This makes it easier to understand the error in cases of incorrect syntax or formatting at .conf files. (js already has this quoting). Fixes #9105
* command: check for monitor par in window-scaleDudemanguy2021-08-091-0/+6
| | | | | | | | When performing the scaling calculations, the window scale properties do not bother checking for potential monitor par. The vo keeps track of this via vo->monitor_par. Simply multiply/divide the video's width or height depending on the value of monitor_par. We also clamp the values to avoid the values running away to infinity in extreme cases.