Commit Graph

109535 Commits

Author SHA1 Message Date
Anton Khirnov
b6742259bf lavc/tests: add a cached bitstream reader test 2023-01-06 11:01:00 +01:00
Anton Khirnov
9177970bca lavc/bitstream: templatize for BE/LE
Allows using both BE and LE bitstream readers in the same file.
2023-01-06 10:49:42 +01:00
Alexandra Hájková
8fe551eca0 lavc: add standalone cached bitstream reader
The cached bitstream reader was originally written by Alexandra Hájková
for Libav, with significant input from Kostya Shishkov and Luca Barbato.
It was then committed to FFmpeg in ca079b0954, by merging it with the
implementation of the current bitstream reader.

This merge makes the code of get_bits.h significantly harder to read,
since it now contains two different bitstream readers interleaved with
 #ifdefs. Additionally, the code was committed without proper authorship
attribution.

This commit re-adds the cached bitstream reader as a standalone header,
as it was originally developed. It will be made useful in following
commits.

Integration by Anton Khirnov.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2023-01-06 10:48:56 +01:00
Aman Karmani
4b2b9a6604 avcodec/mpeg12dec: flush a53 data
Signed-off-by: Aman Karmani <aman@tmm1.net>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2023-01-06 10:47:53 +01:00
James Almer
4a80db5fc2 avcodec/mpeg12dec: use init_get_bits8 and check the return value in all remaining cases
Signed-off-by: James Almer <jamrial@gmail.com>
2023-01-04 20:48:06 -03:00
Thierry Foucu
efbe84eb1b avcodec/mpeg12dec: use init_get_bits8 and check the return value
Signed-off-by: James Almer <jamrial@gmail.com>
2023-01-04 16:18:21 -03:00
Paul B Mahol
99bd2dbc91 swresample/swresample_frame: fix regression in detecting changes
Do not overwrite return variable values, instead use different
one for checking results.
2023-01-04 18:19:07 +01:00
Anton Khirnov
a0b5aaceca lavc/libx265: restructure handling reordered_opaque
Current code stores a pointer to allocated data in libx265 and frees it
when the encoded packet is retrieved. This will leak if the packet is
never retrieved, e.g. if the encoder is closed without being flushed.

Restructure the code such that only indices to an array stored in our
private data are given to libx265. This ensures no allocated memory can
be lost.
2023-01-04 11:48:17 +01:00
Anton Khirnov
7399e5305c lavc/libx264: do not leave an invalid array size on alloc error 2023-01-04 11:48:17 +01:00
Anton Khirnov
a4a81be1a8 lavc/libx264: zero reordered opaque on alloc
This is safer.
2023-01-04 11:48:17 +01:00
Anton Khirnov
141303f323 lavc/libx264: print an error on invalid opaque pointer 2023-01-04 11:48:17 +01:00
Anton Khirnov
89761c2122 lavc/libx264: use a local variable to shorten code 2023-01-04 11:48:17 +01:00
Anton Khirnov
4469ce10a6 lavc/libx264: reindent after previous commit 2023-01-04 11:48:17 +01:00
Anton Khirnov
9ed5b0ac3b lavc/libx264: reorder control flow in setup_roi() to reduce nesting depth 2023-01-04 11:48:17 +01:00
Anton Khirnov
ce5b2d34b4 lavc/libx264: reindent after previous commit 2023-01-04 11:48:17 +01:00
Anton Khirnov
e17b609fc6 lavc/libx264: do not ignore memory allocation errors 2023-01-04 11:48:17 +01:00
Anton Khirnov
cccd2c2179 lavc/libx264: unify cleanup in setup_frame() 2023-01-04 11:48:17 +01:00
Anton Khirnov
87eb362693 lavc/libx264: reindent after previous commit 2023-01-04 11:48:17 +01:00
Anton Khirnov
b1a184283b lavc/libx264: factor out setting up ROI 2023-01-04 11:48:17 +01:00
Anton Khirnov
c7a8a6939b lavc/libx264: use a local variable for input frame in setup_frame() 2023-01-04 11:48:17 +01:00
Anton Khirnov
9f8f980165 lavc/libx264: reindent after previous commit 2023-01-04 11:48:17 +01:00
Anton Khirnov
33cbba165c lavc/libx264: factor out setting up the input frame
X264_frame() is currently too large and complex.
2023-01-04 11:48:17 +01:00
James Almer
a781279871 avformat/oggenc: don't flush twice when the last packet is side data only
Commit 18f24527eb accidentally made side data only packets be handled like a
flush request. Fix this regression by effectively ignoring them as was the
original intention.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-01-03 21:35:03 -03:00
James Almer
99e3d26f20 avformat/mux: use only valid timestamps when calculating packet distance
Fixes: signed integer overflow: 0 - -9223372036854775808 cannot be represented in type 'long int'
Fixes: fate-cover-art-aiff-id3v2-remux, fate-cover-art-mp3-id3v2-remux and fate-mov-cover-image
under ubsan.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-01-03 21:35:03 -03:00
Clément Bœsch
6e05622216 avfilter/paletteuse: use explicit key indexes in set_frame_lut 2023-01-03 17:29:13 +01:00
Clément Bœsch
68275043a0 avfilter/paletteuse: add atkinson dithering
Atkinson according to
https://bisqwit.iki.fi/jutut/kuvat/ordered_dither/error_diffusion.txt:

        *   1   1    / 8
    1   1   1
        1
2023-01-03 17:29:13 +01:00
Clément Bœsch
c973e8ae79 avfilter/paletteuse: add burkes dithering
Burkes according to
https://bisqwit.iki.fi/jutut/kuvat/ordered_dither/error_diffusion.txt:

          *  8  4
    2  4  8  4  2   / 32
2023-01-03 17:29:13 +01:00
Clément Bœsch
9973343bf9 avfilter/paletteuse: add sierra3 dithering
Sierra3 according to
https://bisqwit.iki.fi/jutut/kuvat/ordered_dither/error_diffusion.txt:

          *  5  3
    2  4  5  4  2
       2  3  2      / 32
2023-01-03 17:29:13 +01:00
Clément Bœsch
11926c4bd4 avfilter/palette{gen,use}: misc for-loop cosmetics 2023-01-03 17:18:56 +01:00
Clément Bœsch
1340fe7caf avfilter/paletteuse: move r,g,b computation in a more local scope 2023-01-03 17:18:55 +01:00
Clément Bœsch
1ae1b707e2 avfilter/paletteuse: remove mean error tool
This belongs in another filter.
2023-01-03 17:18:55 +01:00
Clément Bœsch
8789a9e05b avfilter/paletteuse: remove alternative search methods
This is a maintenance pain more than anything. It appears to make the
code slightly faster as a side effect.
2023-01-03 17:18:55 +01:00
Clément Bœsch
0f7942afa6 avfilter/paletteuse: switch to recursive method
It appears faster than the iterative method on my machine (1.06x
faster), so I'm guessing compilers improved over time (the iterative
version was slightly faster in the past).
2023-01-03 17:18:55 +01:00
Clément Bœsch
6c7b54e962 avfilter/paletteuse: use lowbias32 for color hashing
Impact is more negligible than previous commit but still faster (1.02x).
2023-01-03 17:18:55 +01:00
Clément Bœsch
c9084cd0e2 avfilter/palettegen: use lowbias32 for color hashing
1.12x faster overall in palettegen on my machine.
2023-01-03 17:18:55 +01:00
Clément Bœsch
3cafbdc083 avfilter/palette: add lowbias32 hashing 2023-01-03 17:18:55 +01:00
Clément Bœsch
051926868c avfilter/palette{gen,use}: update Copyright after recent changes 2023-01-03 17:18:55 +01:00
Clément Bœsch
3a4a6c7815 avfilter/palettegen: use libc qsort
Now that the sort function is deterministic, we can rely on the libc
sorting function.
2023-01-03 17:18:55 +01:00
Clément Bœsch
8057e1a618 avfilter/palettegen: make refs order deterministic
Currently, in case of equality on the first color channel, the order of
the ref colors is defined by the hashing function. This commit makes the
sorting deterministic and improve the hierarchical ordering.
2023-01-03 17:18:55 +01:00
Clément Bœsch
2441e53c0a avfilter/palettegen: add a warning about supporting only sRGB 2023-01-03 17:18:55 +01:00
Clément Bœsch
9026d92c13 avfilter/palettegen: base box split decision on a perceptual model
Similar to the change in paletteuse, we rely on a perceptual model to
decide how and where to split the box.
2023-01-03 17:18:55 +01:00
Clément Bœsch
724f52b906 avfilter/palettegen: switch to signed arithmetic
This prevents mixed sign arithmetic (typically because we have signed
color channel differences), which has nasty side effects in C.
2023-01-03 17:18:55 +01:00
Clément Bœsch
67ce6ad9a2 avfilter/palettegen: rename local variable box_weight to weight
This variable is used only for the running weight (used to reach the
target median). The places where we actually need the box weight are
changed to use box->weight.
2023-01-03 17:18:55 +01:00
Clément Bœsch
61d334d8c3 avfilter/palettegen: misc cosmetics 2023-01-03 17:18:55 +01:00
Clément Bœsch
efb0a6f6ce avfilter/palettegen: compute average color within compute_box_stats() 2023-01-03 17:18:55 +01:00
Clément Bœsch
dafd43b78d avfilter/palettegen: change cut score from ∑e² to max e²
This is following the results from personal research¹.

¹: https://github.com/ubitux/research/tree/main/color-quantization#results
2023-01-03 17:18:55 +01:00
Clément Bœsch
187f5e7f90 avfilter/palettegen: rename variance to cut_score
"Variance" wasn't exactly the correct word; "cut score" is more
agnostic, which will be useful when changing the algorithm in the next
commit.
2023-01-03 17:18:55 +01:00
Clément Bœsch
e49fc1a6ef avfilter/palettegen: always compute the box variance
The variance computation is simple enough now (since we can use the axis
squared errors) that it doesn't need to have a complex lazy computation
logic.
2023-01-03 17:18:55 +01:00
Clément Bœsch
9e5f494d26 avfilter/palettegen: use box->major_axis without intermediate variable 2023-01-03 17:18:55 +01:00
Clément Bœsch
86bced7c65 avfilter/palettegen: define the best axis to cut using the squared error
This is following the results from personal research¹.

¹: https://github.com/ubitux/research/tree/main/color-quantization#results
2023-01-03 17:18:55 +01:00