Commit Graph

385 Commits

Author SHA1 Message Date
David Vaughan c678033c1d input/player: add loadfile/loadlist insert-at command 2024-02-26 02:03:21 +00:00
David Vaughan da753196af player: change insert_next to insert_at
Change the `playlist_insert_next` function to `playlist_insert_at` (ie,
insert at the location of an entry, rather than after it, and rename to
be clearer that it doesn't have anything to do with the
currently-playing entry).

Also, replace calls to `playlist_add` with calls to
`playlist_insert_at`, since the former has become redundant.
2024-02-26 02:03:21 +00:00
David Vaughan 9e162d2604 player: add loadfile insert-next commands
This commit adds two new commands (`insert-next` and `insert-next-play`)
which mirror the existing commands, `append` and `append-play` in
functionality, with the difference that they insert directly after the
current playlist entry, rather than at the end of the playlist.

This change gives MPV a piece of functionality already found in (for
example) Spotify's media player: "play next". Additionally, using the
new `insert-next` command, users can trivially write a script to play a
new piece of media immediately without otherwise clearing or altering
the remainder of the playlist.
2024-02-26 02:03:21 +00:00
llyyr 4a563a6390 encode_lavc: don't use deprecated `avcodec_close`
Deprecated upstream 1cc24d7495
2024-02-19 18:09:58 +01:00
sfan5 dcf8adf289 common: don't force terminal log buffer to small size
Using the 'terminal-default' log level a client can request
to get all messages that would normally appear on the terminal.

8c2d73f112 changed the size of the
relevant buffer to 100 lines, which was prone to quickly overflowing
once you enable verbose or debug output.
This size is kept for the early terminal buffer but now enlarged
once a client actually requests this log level. This fixes the overflow
risk while not consuming more resources if this feature is unused.
2024-01-27 10:04:16 +01:00
nanahi c08e626578 version.h.in: bump copyright year 2024-01-27 10:00:36 +01:00
Guido Cella 25bef997ce msg: reset status_lines when setting --really-quiet
This prevents mp_msg_flush_status_line() from printing an unnecessary
newline when changing file after setting --really-quiet at runtime. If
mpv is backgrounded, this newline garbles the output of TUI programs.

With this change the cursor is not re-enabled after setting
--really-quiet at runtime and quitting with mpv in the foreground, so
enable it on uninit.
2024-01-21 17:54:21 +00:00
llyyr 8fe2af09f1 common: stream: don't mention Libav in errors/warnings 2024-01-20 16:10:20 +00:00
Kacper Michajłow 13ed292ab0 terminal: don't print escape sequence if not tty 2024-01-15 10:39:42 +01:00
Kacper Michajłow 485221ba22 msg: return zero length if bstr_split_utf8 fails
In theory bstr_split_utf8 should skip invalid sequence and move further,
but it doesn't do that currently, so just the string if unsuported code if
found.

Fixes infinite loop on code.len == 0 condition.

Fixes: 5864b72d1a
2024-01-10 00:31:57 +01:00
Kacper Michajłow 5864b72d1a msg: improve term_disp_width to support unicode
All characters are assumed to be single-width. This is consistent with
the rest of the code and documentation.

Fixes: #13150
2024-01-04 13:41:06 +00:00
Kacper Michajłow 1306ea9854 msg: reduce nesting in mp_msg_flush_status_line
Cosmetic change only.
2023-12-27 20:59:22 +00:00
Kacper Michajłow cadb68487e msg: keep status line on the end of file
Apparently found useful by some users.

Fixes: #13092
2023-12-27 20:59:22 +00:00
Kacper Michajłow a44f0e574d common/av_log: do not assume AVClass.item_name is always set
After recent change in FFmpeg it is not longer safe to call item_name.

Ref: 0c6203c97a
2023-12-24 12:50:24 +01:00
Dudemanguy 6d1383383b playlist: correctly populate playlist-path with the --playlist option
When using the --playlist option on the commandline, it would mark all
entries on the command as having the playlist-path of the value of that
passed option, not just the ones that were expanded from it. Fix this by
moving the playlist_populate_playlist_path to the same place where the
playlist file gets expanded.

Ref https://github.com/mpv-player/mpv/issues/13075#issuecomment-1852179164
2023-12-13 15:25:14 +00:00
Kacper Michajłow 2bcdf591fd common/av_log: use bstr for log callback
- don't use 4KiB stack array
- keep one bstr allocation for lifetime of the log
- avoid dummy strlen
2023-11-28 10:46:16 +01:00
Jan Palus 8efa6c3837 build: restrict git describe to top level source directory
fix version determination when building mpv from release tarball
extracted within another git repository
2023-11-27 15:22:22 +00:00
Kacper Michajłow 7d7276e384 common/msg: remove redundant check
It is already strcmp above, so cannot be NULL.
2023-11-18 23:55:28 +00:00
Kacper Michajłow 82451bdf04 msg: ensure status line is always visible
Restore last status line if it has been cleared by another message.
2023-11-08 21:55:08 +00:00
Kacper Michajłow 5c3faf71e8 msg: factor out print code
Will be useful for next commit.
2023-11-08 21:55:08 +00:00
Kacper Michajłow 773f72e6c6 msg: convert dump_stats to bstr 2023-11-08 21:55:08 +00:00
Kacper Michajłow 0853c719f1 msg: use bstr for partial msg 2023-11-08 21:55:08 +00:00
Kacper Michajłow 2fdb1d31ae msg: check isatty separately per each stream 2023-11-08 21:55:08 +00:00
Kacper Michajłow 24270b8587 msg: refactor how terminal messages are printed
- prepare string before printing
- reduce amount of fflush(), especially for multiline messages
- clear status line and keep it always at the bottom
- indent module name to the longest value
- disable cursor for status line
- properly support wrapped status line

Overall makes status line less flickering and remove stray status
instead of scrolling them up.
2023-11-08 21:55:08 +00:00
Kacper Michajłow d0b8472e5a msg: don't mix partial log messages, with unrelated log levels 2023-11-08 21:55:08 +00:00
Kacper Michajłow 56d35da180 mp_thread: add win32 implementation 2023-11-05 17:36:17 +00:00
Kacper Michajłow 55ed50ba90 mp_thread: prefer tracking threads with id
This change essentially removes mp_thread_self() and instead add
mp_thread_id to track threads and have ability to query current thread
id during runtime.

This will be useful for upcoming win32 implementation, where accessing
thread handle is different than on pthreads. Greatly reduces complexity.
Otherweis locked map of tid <-> handle is required which is completely
unnecessary for all mpv use-cases.

Note that this is the mp_thread_id, not to confuse with system tid. For
example on threads-posix implementation it is simply pthread_t.
2023-11-05 17:36:17 +00:00
Kacper Michajłow 174df99ffa ALL: use new mp_thread abstraction 2023-11-05 17:36:17 +00:00
Kacper Michajłow cb829879af mp_threads: rename threads for consistent naming across all of them
I'd like some names to be more descriptive, but to work with 15 chars
limit we have to make some sacrifice.

Also because of the limit, remove the `mpv/` prefix and prioritize
actuall thread name.
2023-10-27 23:18:56 +00:00
NRK 8bbcc87fee timer: remove MP_START_TIME
instead require mp_raw_time_ns() to not return 0, which all current
implementation already should follow.
2023-10-27 18:07:19 +00:00
Kacper Michajłow 29e677fea5 msg: make mp_msg_find_level case insensitive 2023-10-27 18:07:08 +00:00
NRK d05ef7fdc4 various: sort some standard headers
since i was going to fix the include order of stdatomic, might as well
sort the surrouding includes in accordance with the project's coding
style.

some headers can sometime require specific include order. standard
library headers usually don't. but mpv might "hack into" the standard
headers (e.g pthreads) so that complicates things a bit more.

hopefully nothing breaks. if it does, the style guide is to blame.
2023-10-20 21:31:09 +02:00
NRK 450a69b1d6 various: remove ATOMIC_VAR_INIT
the fallback needed it due to the struct wrapper. but the fallback is
now removed so it's no longer needed.

as for standard atomics, it was never really needed either, was useless
and then made obsolete in C17 and removed in C23.

ref: https://gustedt.wordpress.com/2018/08/06/c17-obsoletes-atomic_var_init/
ref: https://en.cppreference.com/w/c/atomic/ATOMIC_VAR_INIT
2023-10-20 21:31:09 +02:00
NRK 2070331f64 osdep: remove atomic.h
replace it with <stdatomic.h> and replace the mp_atomic_* typedefs with
explicit _Atomic qualified types.

also add missing config.h includes on some files.
2023-10-20 21:31:09 +02:00
Niklas Haas 50cd363c01 video/mp_image: handle non-power-of-two alignment
Needed for odd formats like rgb24.
2023-10-19 18:26:05 +02:00
Niklas Haas d67b0022aa common: add mp_lcm helper 2023-10-19 18:26:05 +02:00
Claude Heiland-Allen a6d1c9dd0f common/tags: add mp_tags_move_from_av_dictionary()
Abstracts a common pattern,
in which the av dictionary is cleared
immediately after copying to mp tags,
so that additional tags later in the stream
get appended to empty tags,
instead of being appended to existing tags
that were already copied.
2023-10-18 16:52:47 +02:00
Dudemanguy d310430332 stats: convert timers to nanoseconds 2023-10-16 15:38:59 +00:00
Guido Cella c470934236 command: fix segfault with playlist-{next,prev}-playlist
This was wrongly assuming that playlist_path is always set for the
current playlist entry, but it's only set when a file was added by
expanding a playlist.

The crash in playlist_get_first_in_next_playlist can be reproduced with
mpv foo.mkv foo.zip, playlist-next, playlist-prev,
playlist-next-playlist. You need to run playlist-next, playlist-prev
first because foo.zip's playlist_path is NULL until you do that, which
makes playlist_get_first_in_next_playlist return immediately.

The crash in cmd_playlist_next_prev_playlist can be replicated with mpv
--loop-playlist foo.zip foo.mkv, running playlist-next until foo.mkv,
and playlist-play-next. Again, you need to open foo.zip first or its
playlist_path is NULL which skips running strcmp(entry->playlist_path,
mpctx->playlist->current->playlist_path).

Fixes https://github.com/mpv-player/mpv/issues/12495#issuecomment-1760968608
2023-10-13 13:54:43 +00:00
Guido Cella 81dea9031d command: add playlist-next-playlist and playlist-prev-playlist
playlist-prev-playlist goes to the beginning of the previous playlist
because this seems more useful and symmetrical to
playlist-next-playlist. It does not go to the beginning when the current
playlist-path starts with the previous playlist-path, e.g. with mpv
--loop-playlist foo/, which expands to foo/{1..9}.zip, the current
playlist path foo/1.zip beings with the playlist-path foo/ of {2..9}.zip
and thus playlist-prev-playlist goes to 9.zip rather than to 2.zip.

Closes #12495.
2023-10-09 15:09:35 +00:00
Dudemanguy 034f75dacd loadfile: fix an old wonky playlist heuristic
2c6a3cb1f2 originally added this struct
member and then 1be863afdb later added
some more logic to loadfile that uses this. There's been more changes
since then of course, but bits using playback_short and playback_start
have mostly stayed the same. It's a bit strange it's worked this way for
so long since it makes an assumption on how long files should be and
leads to weird, broken behavior on playlists with shorter videos. The
main reason for playlist_short, as far as I can tell, is to deal with
some fringe cases with short videos and trying to go back in the
playlist. More specifically, if you use --loop=inf on a very short video
(say less than 1 second) and try to go back in the playlist, you won't
be able to without any of this special logic that deals with it. But the
current approach has several side effects like going back multiple items
in the playlist instead of just one if the video is less than one
second. This is just bad so delete everything related to playlist_short
and playlist_start.

Instead, let's handle this by keeping track of playlist-prev attempts.
Going forward in the playlist doesn't require any special handling since
a bad/broken file will just advance to the next one. So it's only going
backwards that requires some special consideration. If we're going
backwards and the user isn't using force, then mark the playlist entry
with a special flag. If the file loads successfully in
play_current_file, we can just clear the flag and not worry about it.
However if there's a failure, then we set a bool telling
play_current_file that it should go back one more item in the playlist
if possible and try again. This way, we avoid the previously mentioned
--loop=inf edgecase and the user can still attempt to retry previously
failed items in the playlist (like a url or such).

Fixes #6576, fixes #12548.
2023-10-05 17:09:43 +02:00
Dudemanguy 84fa7ea411 msg: use nanosecond precision
The timestamps when making a log file is actually dependent on
MP_START_TIME. This is a 10 microsecond offset that was added to the
timer as an offset. With the nanosecond change, this unit needs to be
converted as well so the offset is the same as before. After doing that,
we need to change the various mp_time_us calls in msg to mp_time_ns and
do the right conversion. This fixes the logs timestamps (i.e. so they
aren't negative anymore).
2023-09-29 18:20:30 -05:00
Kacper Michajłow cdfd5c280a win32/pthread: define _POSIX_TIMERS to notify they are not supported 2023-09-29 20:48:58 +00:00
Dudemanguy 5638fcabfd recorder: fix a couple of memory leaks
Not sure how long these have been around but it leaked on every packet.
2023-09-26 22:09:15 +00:00
Dudemanguy 36ea5d7b5c options: remove a few options marked with .deprecation_message
A bit different from the OPT_REPLACED/OPT_REMOVED ones in that the
options still possibly do something but they have a deprecation
message. Most of these are old and have no real usage. The only
potentially controversial ones are the removal of --oaffset and
--ovoffset which were deprecated years ago and seemingly have no real
replacement. There's a cryptic message about --audio-delay but who
knows. The less encoding mode code we have, the better so just chuck
it.
2023-09-21 16:06:29 +00:00
Dudemanguy 969c19c9cb options: remove ancient option fallbacks/deprecation
We've got an ungodly amount of OPT_REPLACED and OPT_REMOVED sitting
around in the code. This is harmless, but the vast majority of these are
ancient. 26f4f18c06 is the last commit
that touched the majority of these and of course that only changed how
options were declared so all of this stuff was deprecated even before
that. No use in keeping these, so just delete them all. As an aside,
there was actually a cocoa_opts but it had only a single option which
was replaced by something else and empty otherwise. So that entire thing
was just simply removed. OPT_REPLACED/OPT_REMOVED declarations that were
added in 0.35 or later were kept as is.
2023-09-21 16:06:29 +00:00
llyyr 27f0a35c53 various: add missing include in header flles
Mostly cosmetic
2023-09-21 14:40:11 +00:00
Kacper Michajłow f3f1a79fe3 vo: add --video-crop
Just cropping by VO that works with hwdec.

Fixes: #12222
2023-08-31 17:37:42 +00:00
Kacper Michajłow 8920ee5944 common: constify mp_rect_equals 2023-08-31 17:37:42 +00:00
Guido Cella e1f9444d4d playlist: remove unused code to track redirects
It turns out that the code to track redirects (playlists and
directories) never worked correctly, only the last redirect is
remembered and num_redirects is never greater than 1.

You can see this by doing quit-watch-later with the old watch later
system, before dbf244fd2f, on a m3u playlist of files and a m3u playlist
of directories. Only in the first case a redirect entry for the m3u file
is created, because in the second case the m3u redirect is replaced by
the directory one.

If you did mpv --directory-mode=lazy /foo it did create redirect entries
for all subdirectories e.g. /foo/bar, /foo/bar/baz, /foo/bar/baz/qux,
this made it seem like it worked correctly, but actually
/foo/bar/bar/qux was the only redirect entry and thus it was considered
as the first redirect, and mpv created redirect entries for each segment
of the first redirect only.

In the previous commit dbf244fd2f, rather than figuring out how to fix
the code to track redirects, and since creating redirect entries for
multiple redirects is overkill, I just used the new playlist-path
property which does the same thing but only for the last redirect.

By replacing the only other use of the old redirect code with
playlist-path, we can remove it.
2023-08-28 18:31:17 +00:00