Commit Graph

125834 Commits

Author SHA1 Message Date
Kacper Michajłow
ff818b87bf avformat/mpeg: fix demuxing of DVD-Audio LPCM
Substream 0xa0 packets without the DVD-Video dynamic range control
marker byte were assumed to be MLP, while in DVD-Audio AOBs substream
0xa0 always carries LPCM (MLP uses 0xa1), so hi-res LPCM streams were
misdetected and decoded as garbage. Classify them as PCM_DVDA and keep
the private stream header in the packet for the decoder to parse, as
its length is variable and it carries the audio format.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 17:55:33 +02:00
Kacper Michajłow
047eb18451 avcodec: add PCM DVD-Audio decoder
Decodes the LPCM variant found in DVD-Audio AOB streams. Unlike
DVD-Video LPCM it supports up to 192 kHz sample rates and splits
channels in two channel groups, which may use different quantization.
Samples are grouped in sets of 2 samples over all channels, with the
second channel group's data stored first within each set, as 16-bit
big-endian most significant parts followed by the remaining bits.

Based on information from expired US 6,580,671 patent et al.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 17:54:07 +02:00
Kacper Michajłow
88c8100e22 avcodec/pcm-dvd: rename long codec name to DVD-Video
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 17:39:23 +02:00
Kacper Michajłow
cac3543529 avcodec/codec_desc: sync long_name with pcm-dvd.c
It was outdated for a long time.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 17:39:23 +02:00
Kacper Michajłow
fe953596e9 avcodec/d3d12va: add AV1 Profile 2 support
Accept the AV1 Professional profile in the D3D12VA hwaccel and select the
matching decode profile GUID, offer D3D12 for YUV420P12 in the decoder,
map the frames context to P012, and add P016 (12-bit) support to the
d3d12va hwcontext.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 08:39:15 +00:00
Kacper Michajłow
099aa71902 avcodec/av1dec: allow D3D11VA for 12-bit 4:2:0
Offer the D3D11VA hwaccel pixel formats for YUV420P12 (AV1 Profile 2),
enabling hardware decoding of 12-bit 4:2:0 streams on capable devices.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 08:39:15 +00:00
Kacper Michajłow
04d2790ab7 avcodec/dxva2: add AV1 Profile 2 decoder GUIDs
Add the AV1 Professional (Profile 2) decoder GUIDs, including the
dedicated 12-bit 4:2:0 mode, so D3D11VA/DXVA2 can match a decoder for
Profile 2 streams.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 08:39:15 +00:00
Kacper Michajłow
5dbf1dccad avcodec/dxva2: map 4:2:0 12-bit to P012 surfaces
Select P012 as the D3D11VA/DXVA2 frames sw_format for YUV420P12 content
and map it to DXGI_FORMAT_P016, so 12-bit 4:2:0 hardware decoding can
allocate a usable surface.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-28 08:39:15 +00:00
Christopher Decker
94ff335d76 avformat/os_support: fix return value of win32_rename
The return value of MoveFileExW was not being correctly interpreted,
see https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexw.

On Windows a failed rename over the file: protocol now surfaces as failed to rename file %s to %s:
Operation not permitted (ff_rename, libavformat/avio.c:867) plus an AVERROR(EPERM) return, where previously the muxer
reported success and the user was left with a missing or stale output file and no diagnostic. This affects the
write-to-temp-then-rename paths in hlsenc, dashenc, hdsenc, smoothstreamingenc, segment, and img2enc (e.g. HLS/DASH
playlist updates, -write_temp_file, segment list finalization).

Also, added unit tests to exercise the rename function.

Signed-off-by: Christopher Decker <chris.decker08@gmail.com>
2026-07-28 04:59:01 +00:00
Andreas Rheinhardt
c6309b5c63 tests/checkasm/h264pred: Avoid declare_func_emms
This is possible after the recent MMX->XMM conversions
and preferable as it makes the test stricter.

Reviewed-by: Niklas Haas <ffmpeg@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-07-28 00:54:20 +02:00
Andreas Rheinhardt
42970ac7e2 tests/checkasm/checkasm: Map rnd to checkasm_rand_uint32
Before the switch to libcheckasm, rnd returned an unsigned value;
now it only returns a signed value in the range 0..INT_MAX,
so that the sign bit is not random at all. This means that when
rnd is used to initialize four bytes at a time, one bit is not random.
Fix this by mapping rnd to checkasm_rand_uint32().

Reviewed-by: Niklas Haas <ffmpeg@haasn.dev>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-07-28 00:53:50 +02:00
Timo Rothenpieler
2be4a694a3 Revert "fate: disable tests that depend on premultipled conversion"
This reverts commit 336b175c9f.
2026-07-27 20:34:37 +02:00
Timo Rothenpieler
80f14b251b Revert "lavfi: do not send premultiplied alpha to filters not ready for it"
This reverts commit f3431169da, which
introduced various regressions and hangs with at least exr, as
reported by fate, and potentially other codecs that are not as
thouroughly tested.
2026-07-27 20:32:34 +02:00
Timo Rothenpieler
7e1f4dc318 Reapply "avfilter/avfiltergraph: always retry format negotiation after auto-filters"
This reverts commit cd9d265344.
2026-07-27 20:13:00 +02:00
Kacper Michajłow
298f67fa2a avformat/libcurl: fix comments
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
d097f9385f avformat/libcurl: limit buffer_size to INT_MAX
Larger values silently truncate on 32-bit, which can make the resulting
FIFO too small to ever satisfy the unpause threshold.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
6d626c1a3c avformat/libcurl: fix AVBPrint leak on setup_protocols() error paths
The API is not clear to me if AVBPrint has to be finalized on errors,
but there is nothing wrong to be defensive here

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
798fb1f9aa avformat/libcurl: clear the pause flag when unpausing
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
c2b0152ad3 avformat/libcurl: keep the seekable user override across replies
It was applied once after the probe, from the wrong thread, and any
follow-up reply re-evaluating seekability discarded it.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
be6b6743b8 avformat/libcurl: improve content size tracking
Track the size for non-seekable replies too, don't reset a known size when
a reply omits it, and don't store the encoded length of a compressed body.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
aec0c7a0cb avformat/libcurl: only offer compression for full unbounded requests
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
723a855e52 avformat/libcurl: validate that the server honored a requested start offset
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Niklas Haas
cbed990021 avformat/libcurl: guard against unexpected reply content-range
Harden against malicious or badly misbehaving servers.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
488061b9cb avformat/libcurl: guard against overflow from over-reading data
In theory a client could be coaxed by a malicious server to seek to a
large 64-bit offset, which would then trigger an overflow of the position.

Better safe than sorry and just error out with EIO in such cases.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
337b884a4e avformat/libcurl: guard against integer overflow on start_request()
The failure mode here is to just request the rest of the file, which is
explicitly safe.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
fea5d3ccc3 avformat/libcurl: guard against overflow on seek()
Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
2a6514b7c4 avformat/libcurl: harden against malicious underflow
If the server sends a value of INT64_MIN here, we would correctly parse
it and then subtract off -1, underflowing to a huge positive value
(and triggering undefined behavior in the process).

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
6150323029 avformat/libcurl: use int64_t consistently
Instead of randomly mixing in uint64_t. As far as I can tell, we don't
depend on defined overflow behavior anywhere, except where such would be a
bug anyways, and I'm also pretty sure we won't exhaust the 63-bit file size
limit of int64_t any time soon, so this is just a footgun prevention
mechanism.

We already have a few dodgy places of mixing int64_t and uint64_t values
in the code haphazardly.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
7530aa12ee avformat/libcurl: avoid integer overflow in connect_timeout
This is multiplied by 1000, which can overflow on systems with 32-bit
long (i.e. most of them).

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
946a450cec avformat/libcurl: implement -initial_request_size
See corresponding feature in http.c.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
d754fb37a5 avformat/libcurl: simplify continuation decision logic
Instead of trying to statically guess whether or not we expect more data
to be available by exactly recreating the logic, we can consult the parsed
content-range header directly to determine if there are more bytes in the
file.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
34015e179d avformat/libcurl: fully parse Content-Range header
Logic copied from http.c

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
90a08d3657 avformat/libcurl: early exit on no-op seek
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
d993f37a1b avformat/avio: propagate prefer_libcurl preference from parent URLContext
Since this is consumed by e.g. protocols which open inner protocols.
This would normally be propagated by the `av_opt_copy` call, but as this
check happens *before* the inner URLContext is even allocated, we're
forced to propagate the options manually.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
cee0613cf7 avformat/libcurl: track and report connection/request statistics
In theory, we could expand this a lot more, by adding more verbose
statistics about individual request latency etc, but I don't think that's
as helpful (to me) as at least tracking the number of requests made.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
835ebef535 avformat/libcurl: keep track of owning AVFormatContext
For avfc-attached curl loops.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
b5bf0a1a87 avformat/hls: check if http protocol is native or not
When using -prefer_libcurl, http might be served by libcurl instead of the
native HTTP backend; in this case we shouldn't use `ff_http_do_new_request2`
and instead create a new request.

I added a few assertions to safeguard some of the assumptions this code
clearly relies on.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
45c4f59eb2 avformat/aviobuf: add prefer_libcurl to ffurl_copy_url_options()
Otherwise this doesn't reach e.g. the inner HTTP requets made by HLS etc.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
b737bddaf1 avformat/avio: re-use av_opt_set() to parse prefer_libcurl
Otherwise, this fails to parse values like "true" or "yes". This does
require stack-allocating a dummy object, but that's not a big deal, as
we only ever set this single option on it, so nothing should ever
get allocated.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
e11cec1059 avformat/libcurl: respect format whitelist
And also set a reasonable default whitelist. This is especially important
because libcurl supports a much wider range of protocols than FFmpeg,
including e.g. smtps, telnet, gopher, etc.

We have to include "libcurl" in libcurl's own default whitelist, otherwise
it will refuse te recursively open itself for e.g. HLS.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
c70d777f7f avformat/libcurl: enable cookie engine unconditionally
With the previous commit, this allows cookies to persist across requests.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
6c338a6595 avformat/libcurl: attach a CURLSH shared handle to all requests
This allows sharing cookies, HSTS state etc. between requests inside a single
AVFormatContext. This is analogous to the status quo of http.c, which also
re-uses cookies across all requests.

Note that the connection state, DNS cache, SSL session etc. are shared by
default when using a multi handle, so we only need to explicitly share the
rest.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
4127eb2d6a avformat/libcurl: avoid TOCTOU in libcurl_seek()
If this triggers while an asynchronous header_callback() (e.g. from a previous
seek or redirect) is still running, the seekable/content_size fields can
be written to while libcurl_seek() is still reading from them.

I'm not convinced this is an actual bug in practice, but tsan at least is
bound to complain about it.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
a910a30326 avformat/libcurl: also allow forcing streams to be seekable
The documentation states this as a valid option, but the code only allows
force-disabling atm.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Niklas Haas
0a3cf17d5f avformat/libcurl: set minimum buffer size to curl write size
Otherwise, there will never be enough space in the FIFO to put the data
written, resulting in the write callback being stuck/paused indefinitely.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
7346f917e4 avformat: add prefer_libcurl option to route http(s) via libcurl
Register a prefer_libcurl IO option that, when set, opens http(s) URLs
with the libcurl protocol instead of the native one. The native http
protocol stays the default.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
d0972a725d avformat/libcurl: add options, TLS, proxy, cookies and headers
Add the AVOption table and map it onto libcurl. Verbose curl output is
routed to av_log at debug level. This mirrors subset of http.c options.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
363f04fee9 avformat/libcurl: add seek, size and retry
Probe Accept-Ranges/Content-Range/Content-Encoding to determine
seekability and total size, issue ranged requests via CURLOPT_RANGE,
implement url_seek (including AVSEEK_SIZE) as a reconnect at the new
offset, and resume seekable transfers from the next missing byte after a
recoverable error.

Note that we prefer the compression over seekability, as servers are
unlikely to compress media files in practice, as this would be huge
performance cost for zero gain. However downloading text playlists
benefits a lot from compression. YouTube for example can serve text
files that have 30MB+ which is huge bandwidth usage when not compressed.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
15e07fbcd1 avformat/libcurl: implement event loop and read path
Add the per-AVFormatContext curl_multi worker thread, the command queue,
write/header/xferinfo callbacks and a FIFO with pause/unpause
backpressure. url_open2 probes the response on a dedicated thread.
url_read drains the FIFO and yields to the avio layer so the interrupt
callback is honoured. An explicit "libcurl:" URL prefix forces the
protocol.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow
dd25543316 avformat/libcurl: add libcurl protocol skeleton
configure changes, and protocol with ENOSYS impl.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00