aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/ffv1dec.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/ffv1dec: don't check chroma_planes for f->colorspace > 0James Almer2025-07-221-8/+6
| | | | | | | It's RGB, so check instead if it's packed or planar. Fixes: libavcodec/ffv1dec.c:461:43: runtime error: applying zero offset to null pointer Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/ffv1dec: don't add offsets to more NULL pointersJames Almer2025-07-221-6/+10
| | | | | Fixes: libavcodec/ffv1dec.c:453:43: runtime error: applying zero offset to null pointer Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/ffv1dec: Check k in get_vlc_symbol()Michael Niedermayer2025-07-201-0/+5
| | | | | | | | | | | | The true problem happens in several previous get_vlc_symbol() but checking that is more expensive (involving FFABS()) here its just a simple check between 2 variables we have. Fixes: Assertion log >= k failed at libavcodec/golomb.h:406 Fixes: 429296194/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_DEC_fuzzer-4691594622337024 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: don't add offsets to NULL pointersJames Almer2025-07-151-4/+6
| | | | | Fixes: libavcodec/ffv1dec.c:452:43: runtime error: applying zero offset to null pointer Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/ffv1: Store slices*planes with the minimum bits needed after remapMichael Niedermayer2025-04-071-3/+14
| | | | | | | | | | This also means that if a plane*slice has only 1 color nothing is stored after the remap table This also corrects the RCT offset to the exact value after remap not a fixed 65536 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: Limit size of fltmap* to pixel numberMichael Niedermayer2025-04-041-15/+10
| | | | | | | This reduces needed memory and also removes the 65536 maximum for remap on the decoder side Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: Only allocate fltmap* and bitmap when neededMichael Niedermayer2025-04-041-1/+17
| | | | | | This reduces memory requirements Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: Fix end handlingMichael Niedermayer2025-03-271-2/+2
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: replace literal 65535 by what it isMichael Niedermayer2025-03-251-1/+1
| | | | | | should make the code easier to understand Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: compute end instead of hardcoding it and test for fltmap ↵Michael Niedermayer2025-03-251-2/+2
| | | | | | | | correctly A step toward supporting remap for integer formats less than 16 bit Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: Implement 2D RLE for remapMichael Niedermayer2025-03-241-23/+54
| | | | | | | | | | | | | | | | | | ATM this performs as well or better as any other algorithm tried. Its simple for the decoder. On the encoder side complexity depends on how parameters are chosen. But with a fixed mul_count of 1 and basic heuristic it performs as well as any more complex choice i tried so far. The encoder code here is flexible and allows mul_count > 1 and also can easily be used to exactly test various parameters. With mul_count=512 we can gain another 6% in remap table size for fixed point in float data. (this is not implemented in this patch though) Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: remove unused varMichael Niedermayer2025-03-241-1/+0
|
* avcodec/ffv1: 32-bit float sample supportMichael Niedermayer2025-03-241-8/+28
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: Fix a YUVA issue with remapingMichael Niedermayer2025-03-171-1/+2
| | | | | | Untested Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: Add GRAYF16 supportMichael Niedermayer2025-03-171-8/+19
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: Add YAF16 supportMichael Niedermayer2025-03-171-2/+2
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: fix remap without chroma planesMichael Niedermayer2025-03-171-2/+1
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: implement remap for encode/decode_plane()Michael Niedermayer2025-03-171-7/+13
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* ffv1: add a Vulkan-based decoderLynne2025-03-171-0/+6
| | | | | | | | | | This patch adds a fully-featured level 3 and 4 decoder for FFv1, supporting Golomb and all Range coding variants, all pixel formats, and all features, except for the newly added floating-point formats. On a 6000 Ada, for 3840x2160 bgr0 content at 50Mbps (standard desktop recording), it is able to do 400fps. An Alder Lake with 24 threads can barely do 100fps.
* FFHWAccel: add buffer_ref argument to start_frameLynne2025-03-171-1/+1
| | | | | | | | This commit adds a reference to the buffer as an argument to start_frame, and adapts all existing code. This allows for asynchronous hardware accelerators to skip copying packet data by referencing it.
* ffv1dec: add support for hwaccelsLynne2025-03-171-8/+73
| | | | | | | This commit adds support for hardware accelerated decoding to the decoder. The previous commits already refactored the decoder, this commit simply adds calls to hooks to decode.
* avcodec/ffv1dec: set the FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM capabilityJames Almer2025-03-151-4/+8
| | | | | | Will prevent decoding frame data during probing. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/ffv1: Implement jeromes idea of making remap flip optionalMichael Niedermayer2025-03-141-4/+5
| | | | | | | | | | | | | | This also makes remap optional (which is a good idea even if we decide to keep flip fixed) Effect on compression (using 2 rawlsb, golomb rice, large context model with ACES_OT_VWG_SampleFrames -rw-r----- 1 michael michael 499101306 Mär 11 14:58 float-303503-try3d-m2.nut -rw-r----- 1 michael michael 503700199 Mär 11 14:57 float-303503-try3d-m1.nut -rw-r----- 1 michael michael 518150578 Mär 11 14:57 float-303503-try3d-m0.nut (the test above used the rawlsb patch, which is not applied yet) Reviewed-by: Jerome Martinez <jerome@mediaarea.net> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: Fix remap and float with golomb riceMichael Niedermayer2025-03-111-0/+37
| | | | | | Sponsored-by: Sovereign Tech Fund Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: Store remap flag per sliceMichael Niedermayer2025-03-081-0/+8
| | | | | | | | | This allows switching it on conditionally and also for non float, it may improve compression for RGB data that was paletted or other synthetic images Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: split off and share frame header parsing codeJames Almer2025-02-061-431/+28
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* ffv1dec: fix threaded decode failuresLynne2025-02-061-0/+1
| | | | | | | | | Fixes 7187eadf8c0f0c640f1d23811c55fad0cba60aa5 The issue is that while avctx->pix_fmt is synchronized between threads, f->pix_fmt was not. Fixes fate-vsynth1-ffv1-2pass10 with THREADS=2.
* avcodec/ffv1: simplify version checks with combined_versionMichael Niedermayer2025-01-211-3/+6
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* ffv1dec: move slice decoding into a separate functionLynne2025-01-221-46/+60
| | | | | This simply movies all slice decoding code from decode_frame to decode_slices; nothing more.
* ffv1dec: move header parsing into a separate functionLynne2025-01-221-24/+40
|
* ffv1dec: move slice start finding into a functionLynne2025-01-221-19/+47
| | | | This also cleans up and gives the code some much needed comments.
* ffv1dec: use dedicated pix_fmt field and call ff_get_formatLynne2025-01-221-63/+77
| | | | | Adding support for hwaccels means that avctx->pix_fmt will indicate hardware formats.
* lavc/refstruct: move to lavu and make publicAnton Khirnov2024-12-151-6/+6
| | | | It is highly versatile and generally useful.
* avcodec/ffv1: Support slice coding mode 1 with golomb riceMichael Niedermayer2024-11-161-10/+10
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: Implement new slice tilingMichael Niedermayer2024-10-241-4/+4
| | | | | | | | | This fixes corner cases (requires version 4 or a spec update) Fixes: Ticket5548 Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: RCT is only possible with RGBMichael Niedermayer2024-10-161-1/+1
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: Fix end computation with ec=2Michael Niedermayer2024-10-141-1/+1
| | | | | Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1: Implement CRC with non zero initial and final valueMichael Niedermayer2024-10-101-4/+6
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/ffv1dec: Blow up if user asks for explosionMichael Niedermayer2024-09-251-0/+3
| | | | | | | Fixes: Ticket8403 Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc/ffv1dec: fix races in accessing FFV1SliceContext.slice_damagedAnton Khirnov2024-08-121-17/+30
| | | | | | | | | That variable is shared between frame threads in the same defective way described in the previous commit. Fix it by adding a RefStruct-managed arrays of flags that is propagated across frame threads in the standard manner. Remove now-unused FFV1Context.fsrc
* lavc/ffv1dec: drop code handling AV_PIX_FMT_FLAG_PALAnton Khirnov2024-08-121-4/+1
| | | | No paletted pixel formats are supported by the decoder.
* lavc/ffv1: change FFV1SliceContext.plane into a RefStruct objectAnton Khirnov2024-08-011-24/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Frame threading in the FFV1 decoder works in a very unusual way - the state that needs to be propagated from the previous frame is not decoded pixels(¹), but each slice's entropy coder state after decoding the slice. For that purpose, the decoder's update_thread_context() callback stores a pointer to the previous frame thread's private data. Then, when decoding each slice, the frame thread uses the standard progress mechanism to wait for the corresponding slice in the previous frame to be completed, then copies the entropy coder state from the previously-stored pointer. This approach is highly dubious, as update_thread_context() should be the only point where frame-thread contexts come into direct contact. There are no guarantees that the stored pointer will be valid at all, or will contain any particular data after update_thread_context() finishes. More specifically, this code can break due to the fact that keyframes reset entropy coder state and thus do not need to wait for the previous frame. As an example, consider a decoder process with 2 frame threads - thread 0 with its context 0, and thread 1 with context 1 - decoding a previous frame P, current frame F, followed by a keyframe K. Then consider concurrent execution consistent with the following sequence of events: * thread 0 starts decoding P * thread 0 reads P's slice header, then calls ff_thread_finish_setup() allowing next frame thread to start * main thread calls update_thread_context() to transfer state from context 0 to context 1; context 1 stores a pointer to context 0's private data * thread 1 starts decoding F * thread 1 reads F's slice header, then calls ff_thread_finish_setup() allowing the next frame thread to start decoding * thread 0 finishes decoding P * thread 0 starts decoding K; since K is a keyframe, it does not wait for F and reallocates the arrays holding entropy coder state * thread 0 finishes decoding K * thread 1 reads entropy coder state from its stored pointer to context 0, however it finds state from K rather than from P This execution is currently prevented by special-casing FFV1 in the generic frame threading code, however that is supremely ugly. It also involves unnecessary copies of the state arrays, when in fact they can only be used by one thread at a time. This commit addresses these deficiencies by changing the array of PlaneContext (each of which contains the allocated state arrays) embedded in FFV1SliceContext into a RefStruct object. This object can then be propagated across frame threads in standard manner. Since the code structure guarantees only one thread accesses it at a time, no copies are necessary. It is also re-created for keyframes, solving the above issue cleanly. Special-casing of FFV1 in the generic frame threading code will be removed in a later commit. (¹) except in the case of a damaged slice, when previous frame's pixels are used directly
* lavc/ffv1dec: inline copy_fields() into update_thread_context()Anton Khirnov2024-08-011-22/+16
| | | | | It is now only called from a single place, so there is no point in it being a separate function.
* lavc/ffv1dec: stop using per-slice FFV1ContextAnton Khirnov2024-08-011-32/+22
| | | | | | | All remaining accesses to them are for fields that have the same value in the main encoder context. Drop now-unused FFV1Context.slice_contexts.
* lavc/ffv1dec: move slice_damaged to per-slice contextAnton Khirnov2024-08-011-10/+8
|
* lavc/ffv1dec: move slice_reset_contexts to per-slice contextAnton Khirnov2024-08-011-2/+2
|
* lavc/ffv1: move ac_byte_count to per-slice contextAnton Khirnov2024-08-011-3/+3
|
* lavc/ffv1: move RangeCoder to per-slice contextAnton Khirnov2024-08-011-35/+37
|
* lavc/ffv1: move FFV1Context.plane to per-slice contextAnton Khirnov2024-08-011-8/+8
|
* lavc/ffv1: always use the main context values of acAnton Khirnov2024-08-011-10/+9
| | | | It cannot change between slices.