summaryrefslogtreecommitdiff
path: root/libavcodec/utvideodec.c
Commit message (Collapse)AuthorAge
* avcodec: Constify AVCodecsAndreas Rheinhardt2021-04-27
| | | | | | | | | | Given that the AVCodec.next pointer has now been removed, most of the AVCodecs are not modified at all any more and can therefore be made const (as this patch does); the only exceptions are the very few codecs for external libraries that have a init_static_data callback. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/utvideodec: Avoid implicit qsort when creating Huffman tablesAndreas Rheinhardt2020-12-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Huffman trees used by Ut Video have two important characteristics: (i) Longer codes are on the left of the tree and (ii) for codes of the same length, the symbol is descending from left to right in the tree. Therefore all the information that needs to be transmitted is how long the code corresponding to a given symbol is; and this is also all that is transmitted. Before 341914495e5c2f60bc920b0c6f660e5948a47f5a, the decoder used qsort to sort the (length, symbol) pairs by ascending length and for equal lengths by ascending symbol. Since said commit, the decoder uses a first pass over the lengths table to count how many symbols of each length there are; with (i) one can then easily calculate the code of the left-most code with a given length in the tree and from there one can calculate the codes for all entries, using one running counter for each possible length. This eliminated the explicit qsort in build_huff(). Yet ff_init_vlc_sparse() sorts the table itself as it has to ensure that all the entries that will be placed in the same subtable are contiguous. The tables created now are non-contiguous (they are ordered by symbol and codes of different length aren't ordered at all; only codes of the same length are ordered according to (ii)). This commit therefore modifies the algorithm used to automatically create tables whose codes are sorted from left to right in the tree. The key to do so is the observation that the counts obtained in the first pass can be used to contain the range of the codes of each length in the second pass: If counts[i] is the count of codes with length i, then the first counts[32] codes are of length 32, the next counts[31] codes are of length 31 etc. So one knows the index of the lowest symbol whose code has length 32 (if any): It is counts[32] - 1 due to (ii), whereas the index of the lowest symbol whose code has length 31 (if any) is counts[32] + counts[31] - 1; the index of the second-to-lowest symbol of length 32 (if existing) is counts[32] - 2 etc. If one follows the algorithm outlined above, one can switch to ff_init_vlc_from_lengths() which has no implicit qsort; it also means that one can offload the computation of the codes. This turned out to be beneficial for performance: For the sample from ticket #4044 it decreased the decicycles spent on one call to build_huff() from 508480 to 340688 (GCC 9.3, looping 10 times over the file to get enough runs and then repeating this ten times); for another sample (YUV420p, natural content, 5500 frames, also ten iterations) the time went down from 382346 to 275533 decicycles. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/utvideodec: Avoid qsort when creating Huffman tablesAndreas Rheinhardt2020-09-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Ut video format uses Huffman trees which are only implicitly coded in the bitstream: Only the lengths of the codes are coded, the rest has to be inferred by the decoder according to the rule that the longer codes are to the left of shorter codes in the tree and on each level the symbols are descending from left to right. Because longer codes are to the left of shorter codes, one needs to know how many non-leaf nodes there are on each level in order to know the code of the next left-most leaf (which belongs to the highest symbol on that level). The current code does this by sorting the entries to be ascending according to length and (for entries with the same length) ascending according to their symbols. This array is then traversed in reverse order, so that the lowest level is dealt with first, so that the number of non-leaf nodes of the next higher level is known when processing said level. But this can also be calculated without sorting: Simply count how many leaf nodes there are on each level. Then one can calculate the number of non-leaf nodes on each level iteratively from the lowest level upwards: It is just half the number of nodes of the level below. This improves performance: For the sample from ticket #4044 the amount of decicycles for one call to build_huff() decreased from 1055489 to 446310 for Clang 10 and from 1080306 to 535155 for GCC 9. Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/utvideodec: Remove code duplication when creating Huffman tablesAndreas Rheinhardt2020-09-26
| | | | | Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/utvideodec/enc: Fix edge case of creating Huffman tableAndreas Rheinhardt2020-09-26
| | | | | | | | | | | | | | | | | | | | The Ut Video format stores Huffman tables in its bitstream by coding the length of a given symbol; it does not code the actual code directly, instead this is to be inferred by the rule that a symbol is to the left of every shorter symbol in the Huffman tree and that for symbols of the same length the symbol is descending from left to right. With one exception, this is also what our de- and encoder did. The exception only matters when there are codes of length 32, because in this case the first symbol of this length did not get the code 0, but 1; this is tantamount to pretending that there is a (nonexistent) leaf of length 32. This is simply false. The reference software agrees with this [1]. [1]: https://github.com/umezawatakeshi/utvideo/blob/2700a471a78402e5c340150b38e8a793ef3676f1/utv_core/HuffmanCode.cpp#L280 Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/utvideodec: Fix integer overflow in decode_plane()Michael Niedermayer2020-05-12
| | | | | | | | Fixes: signed integer overflow: 2147483594 + 142 cannot be represented in type 'int' Fixes: 20492/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_UTVIDEO_fuzzer-5658568101724160 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/utvideodec: add support for UQY0Paul B Mahol2020-02-25
|
* avcodec/get_bits: unbreak get_bits_le() with cached readerPaul B Mahol2019-04-19
|
* avcodec/utvideodec: use cached bitstream reader everywhere except on x86_32Paul B Mahol2018-08-30
| | | | | | From 100x real-time decoding to 138x real-time decoding for 320x240 video. Signed-off-by: Paul B Mahol <onemda@gmail.com>
* avcodec/utvideodec: Set pro flag based on fourccMichael Niedermayer2018-04-01
| | | | | | | | | | This avoids mixing 8bit variants with pro and 10bit with non pro mode. Fixes: out of array read Fixes: poc_03_30.avi Found-by: GwanYeong Kim <gy741.kim@gmail.com> Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/utvideodec: Check subsample factorsMichael Niedermayer2018-02-27
| | | | | | | | Fixes: Out of array read Fixes: heap_poc Found-by: GwanYeong Kim <gy741.kim@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/utvideodec: Add several out of array read related checksMichael Niedermayer2018-02-11
| | | | | | | Fixes: OV_decode_plane.avi Found-by: GwanYeong Kim <gy741.kim@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/utvideodec: Fix bytes left check in decode_frame()Michael Niedermayer2018-02-05
| | | | | | | | Fixes: out of array read Fixes: poc-2017.avi Found-by: GwanYeong Kim <gy741.kim@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/utvideodec: add support for UMH2, UMY2, UMH4, UMY4, UMRA, UMRGPaul B Mahol2018-01-02
| | | | | | These are new modes which are supposed to be more SIMD friendly. Signed-off-by: Paul B Mahol <onemda@gmail.com>
* avcodec/utvideodec : use gradient_pred dsp in interlace decodingMartin Vignali2017-12-19
|
* avcodec/utvideodec : add SIMD (SSSE3 and AVX2) for gradient_predMartin Vignali2017-12-09
|
* avcodec/utvideodec : use dsp add_median_pred for second lineMartin Vignali2017-12-09
| | | | | process start of the line in scalar, before call dsp (dsp need align 16)
* libavcodec/utvideo : simplify decode_planeMartin Vignali2017-11-07
| | | | | the func is only call with step = 1 no need to pass it in the func
* Merge commit '7c25523cc8e618e77dc84d960e41e9644eaf8c33'James Almer2017-10-30
|\ | | | | | | | | | | | | | | | | * commit '7c25523cc8e618e77dc84d960e41e9644eaf8c33': utvideodec: Fix decoding odd sizes with interlaced video with some formats See 9ef21a897c64417a0575cbc6fad6222f3163d103 Merged-by: James Almer <jamrial@gmail.com>
| * utvideodec: Fix decoding odd sizes with interlaced video with some formatsPaul B Mahol2017-04-25
| | | | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * utvideodec: Support for gradient predictionPaul B Mahol2017-04-15
| | | | | | | | | | | | | | Introduced with utvideo 18. Signed-off-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * utvideodec: Reuse the huffyuv add_leftPaul B Mahol2017-04-15
| | | | | | | | | | | | | | ~10% faster when simd is available. Signed-off-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * utvideodec: Support ULY4 and ULH4Paul B Mahol2017-04-15
| | | | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * utvideodec: Support UQRA and UQRGPaul B Mahol2017-04-15
| |
| * utvideodec: Support UQY2Paul B Mahol2017-04-13
| | | | | | | | Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * utvideodec: Prevent possible signed overflowGanesh Ajjanagadde2017-04-13
| | | | | | | | | | | | | | | | | | Doing slice_end - slice_start is unsafe and can lead to undefined behavior until slice_end has been properly sanitized. Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com> Signed-off-by: Ganesh Ajjanagadde <gajjanag@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * utvideodec: Add a missing includeMartin Storsjö2017-02-10
| | | | | | | | | | | | This was missing from 77c23704c76, fixing building. Signed-off-by: Martin Storsjö <martin@martin.st>
| * avcodec: Mark some codecs with threadsafe init as suchDerek Buitenhuis2017-02-09
| | | | | | | | | | Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * Use bitstream_init8() where appropriateDiego Biurrun2017-02-07
| |
| * utvideodec: Convert to the new bitstream readerAlexandra Hájková2016-11-24
| |
* | avcodec/utvideodec: Factor multiply out of inner loopMichael Niedermayer2017-06-28
| | | | | | | | | | | | | | | | 0.5% faster loop Reviewed-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: Steven Liu <lingjiujianke@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avcodec/utvideodec: bswap directly without memcpyMichael Niedermayer2017-06-28
| | | | | | | | | | Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avcodec/utvideodec: enable unchecked bitreaderMichael Niedermayer2017-06-28
| | | | | | | | | | | | | | inner reader loop becomes 16% faster Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avcodec/utvideodec: hardcode vlc bitsMichael Niedermayer2017-06-28
| | | | | | | | | | | | | | 2.5% faster vlc decoding Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avcodec/utvideodec: Move bitstream end check out of inner loopMichael Niedermayer2017-06-28
| | | | | | | | | | | | | | | | | | This is not needed when the buffer is large enough for the worst case of a line 2% faster vlc reading Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avcodec/utvideodec: add SIMD for restore_rgb_planesPaul B Mahol2017-06-27
| | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | avcodec/utvideodec: decode to GBR(A)PPaul B Mahol2017-06-26
| | | | | | | | | | | | | | | | | | | | | | This is actually internal utvideo format. Allows to make use of SIMD for median prediction for rgb(a) formats, thus speeding up decoding. Simplifies code, eases further developement and maintenance. Update FATE because of pixel format switch. Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | avcodec/utvideodec: fix gradient prediction when stride does not match widthPaul B Mahol2017-04-21
| | | | | | | | | | | | Fixes #6340. Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | avcodec/utvideodec: fix decoding odd sizes with interlaced video with some ↵Paul B Mahol2017-04-21
| | | | | | | | | | | | | | | | formats Fixes #6316. Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | avcodec/utvideodec: add support for gradient predictionPaul B Mahol2017-04-07
| | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | Merge commit '131a85a1fed9966bbd38517f76abfac0237e39dc'Clément Bœsch2017-03-20
|\| | | | | | | | | | | | | * commit '131a85a1fed9966bbd38517f76abfac0237e39dc': utvideo: Change type of array stride parameters to ptrdiff_t Merged-by: Clément Bœsch <u@pkh.me>
| * utvideo: Change type of array stride parameters to ptrdiff_tDiego Biurrun2016-09-08
| | | | | | | | ptrdiff_t is the correct type for array strides and similar.
* | avcodec: Mark some codecs with threadsafe init as suchDerek Buitenhuis2017-02-07
| | | | | | | | | | Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | huffyuvdsp: move functions only used by huffyuv from lossless_videodspJames Almer2017-01-12
| | | | | | | | Signed-off-by: James Almer <jamrial@gmail.com>
* | lossless_videodsp: move shared functions from huffyuvdspJames Almer2017-01-12
| | | | | | | | | | | | Several codecs other than huffyuv use them. Signed-off-by: James Almer <jamrial@gmail.com>
* | avcodec/utvideo: fix mistake using wrong arguments for left and lefttop ↵Paul B Mahol2016-12-24
| | | | | | | | | | | | pixel components Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | avcodec/utvideodec: add SIMD support for median prediction for planar formatsPaul B Mahol2016-12-23
| | | | | | | | | | | | ~10% faster overall. Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | avcodec/utvideodec: add support for ULY4 and ULH4Paul B Mahol2016-09-04
| | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | avcodec/utvideodec: add support for UQRG and UQRA formatsPaul B Mahol2016-06-12
| | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* | avcodec/utvideodec: fix multiple slices for UQY2 and other issuesPaul B Mahol2016-06-11
| | | | | | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>