summaryrefslogtreecommitdiffstats
path: root/demux
Commit message (Collapse)AuthorAgeFilesLines
* demux_playlist: use --metacode-codepage when parsing playlist filesDudemanguy2023-10-071-22/+63
| | | | | | | | | | | | It's 2023 and people don't use UTF-8 for their m3u, ini, etc. files. Well mpv already has the tools in place to try and guess other codepages, so we might as well use it I guess. This change is pretty awkward since we have to read line-by-line but mp_iconv_to_utf8 may sometimes allocate memory. So sometimes the bstr needs to be freed and sometimes not for every line. Also we need to make another copy of the line on the stack since splitting by tokens and such will mess up the original line which may possibly be allocated memory. The ugliness is mostly hidden in pl_free_line, but it's still weird. Fixes #10911.
* demux: change the default of metadata-codepage to autoDudemanguy2023-10-071-1/+1
| | | | | | | There's really no reason not to do this especially since sub-codepage already defaults to auto. Also change logging in charset_conv since telling us that the data is UTF-8 if the passed codepage value is "auto" or "utf-8" is really not useful information (that's the expectation).
* demux_cue: deprecate --demuxer-cue-codepage for --metadata-codepageDudemanguy2023-10-071-15/+6
| | | | | | | | | What are cue sheets not metadata or something? No reason this needs to be a separate option so just deprecate it. This does mean that the default value changes from "auto" to "utf-8" for this obscure fringe case. I really hope people don't use non-UTF-8 cuesheets, but the next commit will change the default of --metadata-codepage to "auto" so there's no actual change in behavior to users.
* codec_tags: map some more image mimetypesDudemanguy2023-10-021-0/+7
| | | | This only had jpeg and png in it strangely enough. Fixes #11592.
* demux: move parent_stream_info before the gotoDudemanguy2023-10-011-9/+9
| | | | | | Previously if the demuxer didn't exist, then it could jump down and try to free sinfo.filename before it was ever set thus segfaulting. Just always set the struct unconditionally so we're always sure to free it.
* Revert "demux: constify a struct member"Dudemanguy2023-10-011-2/+3
| | | | | | | | | | Some demuxers actually close the stream right after they are finished opening like cue. Since the stream->url is no longer copied with this commit, that means it gets thrown away after the stream closes. This leads to a use after free. We still need to allocate stream->url so fix this another way. This reverts commit 3e85df3b2d89d6a27806d677b6b8a99055cb1fcc.
* demux: fix erroneous condition in lazy_stream_needs_waitDudemanguy2023-10-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Yeah another try at this. So when inspecting lazy_stream_needs_wait, I realized it had a curious !ds->reader_head condition. Actually, this is what is messing everything up. This was originally added in cf2b7a4997299ff9e0ff91d4273cd294686b001f for showing large negative sub delay values correctly. It worked because the packet will eventually be discarded during playback causing ds->reader_head not exist and thus the next one will correctly be read ahead as needed. But for the "switching subtitle tracks while paused" case, this is actually bad. As the stream is read, eventually you'll find a packet and set the reader_head. But it's not going to be the correct packet (unless you're looking for the very first one), so you need to read more. This won't happen because of the !ds->reader_head check and unlike the sub delay case, nothing will eventually discard that packet since playback isn't occuring. So read_packet exits earlier than it should and isn't tried again, so the subtitle that you want won't show since the returned packet has the wrong pts. All that needs to be done here is to delete this one condition. There's already checks in place to make sure that it's not read past the desired timestamp and for the sub delay case (the only other time this logic is used), it makes no difference since you won't read past the specified pts in the first place.
* Revert "demux: improve stream selection state"Dudemanguy2023-09-304-13/+12
| | | | | | | | The stream selection state wasn't improved. I didn't realize this messed with caches. All in all, just not a good idea. Back to drawing board I guess. This reverts commit f40bbfec4fcd2d9a787a4d98ec7698a646e5607e.
* win32/pthread: define _POSIX_TIMERS to notify they are not supportedKacper Michajłow2023-09-291-0/+1
|
* timer: rename mp_time_us_to_timespec to reflect what it actually doesKacper Michajłow2023-09-291-1/+1
|
* demux: improve stream selection stateDudemanguy2023-09-274-12/+13
| | | | | | | | | | | | | | | | | | | | | | | This replaces the previous commit and makes more sense. The internal demux marked tracks as eager depending on their type and for subtitles it would always lazily read them unless there happened to be no available av stream. However, we want the sub stream to be eager if the player is paused. The existing subtitle is still preserved on the screen, but if the user changes tracks that's when the problem occurs. So to handle this case, propagate the mpctx->paused down to the stream selection logic. This modifies both demuxer_refresh_track and demuxer_select_track to take that boolean value. A few other parts of the player use this, but we can just assume false there (no change in behavior from before) since they should never be related to subtitles. The core player code is aware of its own state naturally, and can always pass the appropriate value so go ahead and do so. When we change the pause state, a refresh seek is done on all existing subtitle tracks to make sure their eager state is the appropriate value (i.e. so it's not still set to eager after a pause and a track switch). Slightly invasive change, but it works with the existing logic instead of going around it so ultimately it should be a better approach. We can additionally remove the old force boolean from sub_read_packets since it is no longer needed.
* Revert "demux: eagerly read subtitle streams when switching tracks while paused"Dudemanguy2023-09-272-9/+4
| | | | | | | Actually, I thought of a better way of handling this shortly after merging this. Revert it and redo it in the next commit. This reverts commit c2c157ebeca3d072d4f48ff36228d01ebe888699.
* demux: eagerly read subtitle streams when switching tracks while pausedDudemanguy2023-09-272-4/+9
| | | | | | | | | | | | | | | | | a323dfae426e43451f4d3e08a9a63cb7d1c1ace9 almost fixed subtitle tracks disappearing when paused but it actually missed one part: the behavior of demux_read_packet_async_until. It's a bit unintuitive, but for subtitle streams, that function would only return the very first packet regardless of whatever pts you pass to it. So the previous commit worked on the very first subtitle, but not actually any of the others (oops). This is because subtitle streams never marked as eager and thus never actually read farther ahead. While the video is playing, this is OK, but if we're paused and switching subtitle tracks then the stream should be eagerly read. Luckily, the logic is already there in the function for this. All we have to do add an extra argument to demux_read_packet_async_until to force the stream to be read eagerly and then it just works. Be sure to unset the eager flag when we're done. Actually fixes the bug for real this time.
* demuxer: remove several mp_read_option_raw callsDudemanguy2023-09-223-25/+12
| | | | | | | With the previous commit, we can just access option values directly now and avoid a lot of complication. Note that the mp_read_option_raw call for edition requires calling mp_get_config_group since that option needs to live in MPOpts.
* demux: make demux opts publicDudemanguy2023-09-222-43/+47
| | | | | | | Several parts of the code need to access options here. There's no point in hiding it demux.c so just expose it in the demux.h header. This means pulling it out of demux_internal and putting it in the demuxer struct instead.
* options: move some demux-specific opts to demux optsDudemanguy2023-09-221-0/+8
| | | | | These options are only ever accessed by the demuxer and have no need to be in MPOpts. Move them to demux.c instead.
* demux_lavf: set duration to -1 if unknownllyyr2023-09-221-3/+3
| | | | | | | | | | | | | `demux->duration` is set to -1 on initialization, and some checks rely on it being -1 when unknown. Before this commit, we set `demux->duration` to 0 when unknown. This is incorrect and breaks rtsp logic for disabling seeking outside of cached regions. To fix these issues, initialize `total_duration` and `av_duration` at -1. They're only changed if a real duration is detected, so in cases where the duration is unknown, demux->duration is set to -1 correctly. Fixes: e6afc53e7c ("demux_lavf: get total duration from track durations")
* options: remove a few options marked with .deprecation_messageDudemanguy2023-09-211-4/+1
| | | | | | | | | | | 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.
* demux_playlist: add --directory-mode=autoGuido Cella2023-09-211-1/+11
| | | | This is a more useful default with --shuffle.
* various: add missing include in header fllesllyyr2023-09-211-0/+1
| | | | Mostly cosmetic
* demux_mf: detect svgGuido Cella2023-09-211-0/+1
| | | | | This allows playing svgs without having to specify --demuxer-lavf-format=svg_pipe.
* demux: prepend some cache options with demuxerDudemanguy2023-09-181-2/+4
| | | | | | --cache-dir is an awful name that leads to confusion (see #12418). Change the name to --demuxer-cache-dir and --demuxer-cache-unlink-files instead.
* demux_mkv: support ProjectionPoseRoll elementKacper Michajłow2023-09-171-0/+23
|
* demux_mkv: support PixelCrop* elementsKacper Michajłow2023-09-171-0/+29
| | | | Fixes #6017
* demux: add crop to mp_codec_paramsKacper Michajłow2023-09-171-0/+1
|
* demux_lavf: get total duration from track durationsllyyr2023-09-021-18/+18
| | | | | | | | | | | | | | | | | | | | | | | Before this change, mpv used to get the total duration from `avformat_find_stream_info` and used the per-track duration as a fallback. This change reverses this order of preference. The timestamps returned by `avformat_find_stream_info` are truncated or rounded or floored (depending on the decoder) at the 6th decimal place. For e.g. `avformat_find_stream_info` may return us a duration like 44.138667, whereas the duration we get from the per-track struct has a higher degree of precision like 44.13866666666... and so on. This caused various problems such as the playback_pts being a bigger value than the duration, which would cause time-remaining to be a negative value in some cases. Or cause you to reach a negative starting timestamp when looping on an audio file with `gapless-audio`. Moreover, we already skipped calling `avformat_find_stream_info` for mp4, so we had already been utilizing this per-track fallback method for finding the duration for mp4 files. It should be noted that while this change is only required for audio-only formats, there is no harm in doing this for videos as well.
* demux_playlist: default to --directory-mode=lazyGuido Cella2023-08-301-3/+3
| | | | | | 64959c450d solved the problems with resuming playback, so default to --directory-mode=lazy because it's faster, especially on slow drives, and results in smaller playlists.
* demux_mf: utilize stdbool bool for if a format specifier was badJan Ekström2023-08-201-2/+4
| | | | | It is not an iterator, thus while the ++ is completely correct, it is somewhat weird.
* demux_mf: early exit with the '%%' caseJan Ekström2023-08-201-11/+23
|
* demux_playlist: remove len restriction on headerless m3uDudemanguy2023-08-151-1/+1
| | | | | | | | | | | | | Discovered by @christoph-heinrich in IRC. 09c701b797c44293dc0e22874b4acf0246b3d148 added a fallback for headerless m3u files. However, it requires that the bstr len be greater than 10. This means that a m3u playlist with a single entry with a very short filename (such as "test.flac") will not be recognized as a playlist since the amount of data is too small. The reason for this restriction is unexplained and really shouldn't matter given that the important thing mpv should be doing is checking if the data is text. Instead, loosen the check so that it only needs to be 2 or greater. This covers a single byte filename and a line terminator.
* build: remove outdated generated directoryDudemanguy2023-07-312-2/+2
| | | | | | | | | | | | | | | | This only existed as essentially a workaround for meson's behavior and to maintain compatibility with the waf build. Since waf put everything in a generated subdirectory, we had to put make a subdirectory called "generated" in the source for meson so stuff could go to the right place. Well now we don't need to do that anymore. Move the meson.build files around so they go in the appropriate place in the subdirectory of the source tree and change the paths of the headers accordingly. A couple of important things to note. 1. mpv.com now gets made in build/player/mpv.com (necessary because of a meson limitation) 2. The macos icon generation path is shortened to TOOLS/osxbundle/icon.icns.inc.
* demux_mkv: add missing space to log msgsfan52023-07-261-1/+1
|
* demux_playlist: sort files before directoriesChristoph Heinrich2023-07-061-22/+45
|
* demux_playlist: add option to control recursive directory loadingChristoph Heinrich2023-07-061-9/+40
| | | | | | | | | | | Directories were always loaded recursively, which can be slow (e.g. one of the subdirectories is a mounting point to a slow device) and can unexpectedly expand into a massive playlist. Due to the problems described in 503dada42f1ea1007768da0dc6a41b67cdf89400, this defaults to recursive loading. ref. https://github.com/mpv-player/mpv/issues/9652
* various: correctly ignore cache files with --no-configDudemanguy2023-07-061-1/+4
| | | | | | | | | | | | --no-config should prevent loading user files of any type: configs, cache, etc. For cache files, this case wasn't properly handled and it was assumed they would always get something. vo_gpu's shader cache actually already handles this, so it was left untouched. In theory, demuxer cache should never have this issue because saving it to disk is disabled by default (and likely that will never change), but go ahead and change it for consistency's sake. Fixes some segfaults with --no-config and various combinations of settings (particularly --vo=gpu-next).
* demux/demux_lavf: avoid leaking AVFormatContext during demux_open_lavfLeo Izen2023-06-181-12/+18
| | | | | | | If demux_open_lavf fails between calling avformat_alloc_context() and assigning the context to priv->avfc, it will never be properly freed. Fixes #11793.
* demux/demux_lavf: strip URL parameters before matching extensionKacper Michajłow2023-05-301-1/+4
| | | | | | | Unfortunately Content-Type matching seems to be not enough as there are mistagged streams. Try to match extension and pass-through URL. Fixes #11700
* demux/demux_lavf: pass-through mime_typeKacper Michajłow2023-05-161-0/+1
| | | | | | This fixes HLS playback. After FFmpeg@954d16f check is strict as per RFC8216 requirement and demuxer need to have this information to work properly.
* demux/demux_lavf: pass-through filename for HLSKacper Michajłow2023-05-161-2/+3
| | | | | | | Fixes local HLS playback. After FFmpeg@6b1f68c commit HLS is only processed if file extension matches RFC8216 requirement.
* Revert "demux/demux_lavf: pass dummy filename when an HLS mimetype is detected"Kacper Michajłow2023-05-161-27/+2
| | | | | | This reverts commit acababec208ec4f26c1462228a9ec1d4aac2c815. Now it has been fixed upstream FFmpeg@6b1f68c.
* demux/demux_lavf: pass dummy filename when an HLS mimetype is detectedLeo Izen2023-05-141-2/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Pass "dummy.m3u8" filename to work around FFmpeg commit 6b1f68ccb04d791f0250e05687c346a99ff47ea1 which broke their HLS demuxer and its ability to probe. Since the above commit, libavformat will check the filename of the file to be probed and reject it if it doesn't end with a valid HLS extension i.e. m3u8,hls,m3u (never mind that .hls is not a valid HLS extension). In addition to a bug with query strings, this also breaks mpv functionality as mpv explicitly doesn't tell libavformat the filename when probing, in order to properly detect the file based only on their contents. The [HLS specification](https://www.rfc-editor.org/rfc/rfc8216.txt) aka RFC 8216, specifies in section 4 that "Each Playlist file MUST be identifiable either by the path component of its URI or by HTTP Content-Type." Notably, it does not require both, so this FFmpeg commit is noncompliant. We work around this noncompliance by checking the MIME type ourselves. If the mimetype matches one of the valid HLS mimetypes (and also application/x-mpegurl, a legacy pre-standardization type), then we pass "dummy.m3u8" to libavformat in order to work around its overly strict checking of filenames. Without this patch, we are unable to play many HLS streams, including a few from the ytdl hook. This patch restores those ability to play those streams when built against FFmpeg master. Do note that if the server sends an invalid content-type header then we cannot implement this workaround so those streams will still fail to play.
* player: use XDG_CACHE_HOME by defaultDudemanguy2023-05-091-3/+5
| | | | | | | | | | | | This adds cache as a possible path for mpv to internally pick (~/.cache/mpv for non-darwin unix-like systems, the usual config directory for everyone else). For gpu shader cache and icc cache, controlling whether or not to write such files is done with the new --gpu-shader-cache and --icc-cache options respectively. Additionally, --cache-on-disk no longer requires explicitly setting the --cache-dir option. The old options, --cache-dir, --gpu-shader-cache-dir, and --icc-cache-dir simply set an override for the directory to save cache files. If unset, then the cache is saved in XDG_CACHE_HOME.
* various: fix various typos in the code baseAlexander Seiler2023-03-281-7/+7
| | | | Signed-off-by: Alexander Seiler <seileralex@gmail.com>
* demux_lavf: update to handle deprecation of `io_close`Philip Langdale2023-03-281-2/+24
| | | | | | | | `io_close2` was introduced as a superior replacement for `io_close` in ffmpeg 5.0, and then deprecated in 6.0. The difference is that `io_close2` can return errors. In our case, we're just calling through to the original function anyway, so we don't need to do more than pass the return value back.
* demux_mkv: support ARIB captionsrcombs2023-03-141-0/+38
|
* demux: propagate hls_bitrate and program_id in generated caption tracksrcombs2023-03-031-0/+2
|
* demux_lavf: report program_idrcombs2023-03-033-0/+5
| | | | This can be useful in stream selection.
* demux: constify a struct membersfan52023-02-241-3/+2
| | | | | Fixes a segfault when an invalid demuxer is given due to uninitialized use of `filename` after goto.
* options: transition options from OPT_FLAG to OPT_BOOLChristoph Heinrich2023-02-214-28/+28
| | | | | | c78482045444c488bb7948305d583a55d17cd236 introduced a bool option type as a replacement for the flag type, but didn't actually transition and remove the flag type because it would have been too much mundane work.
* various: drop unused #include "config.h"Thomas Weißschuh2023-02-204-7/+0
| | | | | | Most sources don't need config.h. The inclusion only leads to lots of unneeded recompilation if the configuration is changed.
* demux: remove unused codeKacper Michajłow2023-02-021-4/+0
|
* various: replace abort() with MP_ASSERT_UNREACHABLE() where appropriatesfan52023-01-122-3/+3
| | | | | | | | In debug mode the macro causes an assertion failure. In release mode it works differently and tells the compiler that it can assume the codepath will never execute. For this reason I was conversative in replacing it, e.g. in mpv-internal code that exhausts all valid values of an enum or when a condition is clear from directly preceding code.
* various: replace if + abort() with MP_HANDLE_OOM()sfan52023-01-122-4/+2
| | | | | MP_HANDLE_OOM also aborts but calls assert() first, which will result in an useful message if compiled in debug mode.
* demux_mf: replace unsafe string functionssfan52023-01-121-4/+3
|
* demux: new packet should not point to source buffer when copying dataPhilip Langdale2023-01-061-1/+0
| | | | | | | In `new_demux_packet_from`, we initialise a new packet and allocate a buffer which we copy the source data into. But I was then assigning the original source pointer as the packet's buffer, rather than keeping the newly allocated one. Whoops.
* demux: actually initialise packet buffer when creating new packetPhilip Langdale2023-01-061-0/+1
| | | | | | | | When I refactored the code here to stop using stack allocated AVPackets, I forgot to assign `dp->buffer` after initialising the AVPacket. Fixes #11097
* demux: boost read EBU R128 gain values to ReplayGain's reference levelSimon Ruderich2023-01-041-0/+5
| | | | | | | | | | | | | Without this change the same track encoded as Opus - which requires R128 tagging - and e.g. Vorbis with ReplayGain tagging have different volumes. This is caused by ReplayGain 2 having a higher reference level of -18 dB LUFS, while EBU R128 has a lower reference level of -23 dB LUFS. For the results of gain application to match, the read EBU R128 values need to be boosted according to the difference in reference levels. Patch inspired by mpd's source code.
* demux: add --demuxer-hysteresis-secs option to save power with cachingSultan Alsawaf2022-12-301-3/+14
| | | | | | | | | | | | | | | | | | | | | | Buffering ahead nonstop into the cache results in nonstop disk or network activity to read stream data from wherever it may originate. Currently, there's no way to configure the demuxer to back off once it's buffered ahead enough data, since the cache limit will be perpetually not-reached as a stream continues to play, until the entire stream is eventually buffered. On a laptop with an i9-12900H with decoding performed by the iGPU, watching a locally-saved 1080p video which hasn't been buffered into the page cache consumes approximately 15 W even with caching enabled. When configuring a hysteresis to make the demuxer back off, power consumption drops to 9 W when watching the same video, resulting in a whopping 6 W of power savings. To make it possible to attain significant power savings via cachi