aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/get_bits.h
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/get_bits: Remove GetBitContext.buffer_endAndreas Rheinhardt2025-07-111-5/+1
| | | | | | | | | | | It is unused. Furthermore, this automatically fixes the issue that init_get_bits() failure would lead to NULL + 0 (when setting buffer_end) which is UB before C23. This happened in the fic-avi and fic-avi-skip_cursor FATE-tests. This saved 7296B of .text here. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/get_bits: Add get_bits_bytesize()Andreas Rheinhardt2025-07-111-0/+15
| | | | | | And use it to avoid accesses to GetBitContext.buffer_end. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vlc: Merge VLCElem and RL_VLC_ELEMAndreas Rheinhardt2025-03-171-3/+3
| | | | | | | | | | | | | | | | | | | | | | | It will simplify creating RL-VLCs (which until now used a stack-based VLC as temporary buffer). Notice that there would be another option to merge them, namely: struct VLCElem { union { VLCBaseType sym; int16_t level; }; int8_t len; uint8_t run; }; The main difference to the current patch is that this would change the type of the length field of VLCElem to int8_t from int16_t. It turns out that that this would entail additional sign extensions on ppc, see https://godbolt.org/z/behWYEYE7. I have therefore refrained from doing so, although it would make the patch simpler. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/get_bits: Remove LONG_BITSTREAM_READERAndreas Rheinhardt2025-02-271-18/+1
| | | | | | No longer used anywhere. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vlc, bitstream: Fix multi VLC with uint8_t syms on BEAndreas Rheinhardt2024-04-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | VLC_MULTI_ELEM contains an uint8_t array that is supposed to be treated as an array of uint16_t when the used symbols have a size of two; otherwise it should be treated as just an array of uint8_t, but it was not always treated that way: vlc_multi_gen() initialized the first entry of the array by writing the symbol via AV_WN16; on big endian systems, the intended value was instead written into the second entry of the array (where it would likely be overwritten lateron during initialization). read_vlc_multi() also treated this case incorrectly: In case the code is so long that it needs a classical multi-stage lookup, the symbol has been written to the destination as if via AV_WN16. On little endian systems, this sets the correct first symbol and clobbers (zeroes) the next one, but the next one will be overwritten lateron anyway, so it won't be recognized. But on big-endian systems, the first symbol will be set to zero and the actually read symbol will be put into the slot for the next one (where it will be overwritten lateron). This commit fixes this; this fixes the magicyuv and utvideo FATE-tests on big endian arches. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: move leb reading functions to its own headerJames Almer2024-01-311-24/+0
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/get_bits: add get_leb()James Almer2023-12-181-0/+24
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/vlc: Use proper namespaceAndreas Rheinhardt2023-09-111-1/+1
| | | | | | | | | | | | | | | | Therefore use a proper prefix for this API, e.g. ff_init_vlc_sparse -> ff_vlc_init_sparse ff_free_vlc -> ff_vlc_free INIT_VLC_LE -> VLC_INIT_LE INIT_VLC_USE_NEW_STATIC -> VLC_INIT_USE_STATIC (The ancient INIT_VLC_USE_STATIC has been removed in 595324e143b57a52e2329eb47b84395c70f93087, so that the NEW has been dropped.) Finally, reorder the flags and change their values accordingly. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/get_bits: Avoid reading multiple times in get_bits_longAndreas Rheinhardt2023-09-101-9/+29
| | | | | | | | | | | | | | | | | | Due to non-byte-alignment a read of 32 bits guarantees only 25 usable bits; therefore get_bits_long() (which is used to potentially read more than 25 bits) performs two reads in case it needs to read more than 25 bits and combines the result. Yet this is not necessary: One can just read 64 bits at a time to get 32 usable bits (57 would be possible). This commit does so. This reduced the size of .text by 30144B for GCC 11.4 and 5648B for Clang 14 (both with -O3). (get_bits_long() is a building block of show_bits_long() and get_ue_golomb_long(), so this patch affects these, too.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: add multi vlc readerPaul B Mahol2023-09-071-0/+10
| | | | | | Heavily based and inspired by Christophe's cache branches. Co-Authored-by: Christophe Gisquet
* lavc/bitstream: avoid UB in bits_{read,peek}_signed(0)Anton Khirnov2023-01-181-1/+1
| | | | | | | | | | bits_*_signed(0) will currently invoke an undefined shift by 8 * sizeof(int). Add bits_*_signed_nz() that only works for n>0, analogous to bits_read_nz(). Add an explicit check for n=0 in bits_*_signed(). Found-by: James Almer
* lavc/get_bits: add a compat wrapper for the cached bitstream readerAnton Khirnov2023-01-061-247/+62
| | | | Use that instead of the merged version.
* libavcodec/flacdec: Implement decoding of 32 bit-per-sample PCMMartijn van Beurden2022-12-261-0/+12
| | | | Add decoding of FLAC files coding for 32 bit-per-sample PCM to libavcodec.
* get_bits: move check_marker() to mpegvideodec.hAnton Khirnov2022-07-041-11/+0
| | | | | It is only used by mpegvideo-based decoders - specifically mpeg12, intelh263, ituh263, mpeg4video.
* avcodec/vlc: Use structure instead of VLC_TYPE array as VLC elementAndreas Rheinhardt2022-06-171-12/+12
| | | | | | | | | | | | | | | | | | In C, qualifiers for arrays are broken: const VLC_TYPE (*foo)[2] is a pointer to an array of two const VLC_TYPE elements and unfortunately this is not compatible with a pointer to a const array of two VLC_TYPE, because the latter does not exist as array types are never qualified (the qualifier applies to the base type instead). This is the reason why get_vlc2() doesn't accept a const VLC table despite not modifying the table at all, as there is no automatic conversion from VLC_TYPE (*)[2] to const VLC_TYPE (*)[2]. Fix this by using a structure VLCElem for the VLC table. This also has the advantage of making it clear which element is which. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/get_bits: avoid avcodec.h dependencyAnton Khirnov2021-06-101-1/+2
| | | | Include only defs.h, needed for AV_INPUT_BUFFER_PADDING_SIZE.
* avcodec/get_bits: cosmeticsRamiro Polla2020-03-221-4/+4
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/get_bits: unbreak get_bits_le() with cached readerPaul B Mahol2019-04-191-24/+58
|
* avcodec/get_bits: add assertion to limit ouptut value of get_bitsMarton Balint2019-03-011-0/+1
| | | | | | | | | | | | | | | Should fix the following Coverity false positives: Coverity CID #1415651. Coverity CID #1420392. Coverity CID #1420473. Coverity CID #1433770. Coverity CID #1435320. Coverity CID #1439573. Coverity CID #1439580. Coverity CID #1439588. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/get_bits: use unsigned integers in show_bits and get_bitsMarton Balint2019-03-011-2/+2
| | | | | | The return value is also unsigned. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/get_bits: actually make cached reader correctly disabledJames Almer2018-08-301-18/+22
|
* avcodec/get_bits: add cached bitstream readerPaul B Mahol2018-08-301-2/+216
| | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* avcodec/get_bits: Document skip_bits_long()Michael Niedermayer2018-04-071-0/+7
| | | | | Found-by: Kieran Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/get_bits: Make sure the input bitstream with padding can be addressedMichael Niedermayer2018-03-261-1/+2
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/get_bits: Document the return code of get_vlc2()Michael Niedermayer2018-01-291-0/+1
| | | | | | Found-by: kierank Reviewed-by: Kieran Kunhya <kieran618@googlemail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec: add Newtek SpeedHQ decoderSteinar H. Gunderson2017-01-111-0/+14
| | | | | | | | | | | | | | This decoder can decode all existing SpeedHQ formats (SHQ0–5, 7, and 9), including correct decoding of the alpha channel. 1080p is decoded in 142 fps on one core of my i7-4600U (2.1 GHz Haswell), about evenly split between bitstream reader and IDCT. There is currently no attempt at slice or frame threading, even though the format trivially supports both. NewTek very helpfully provided a full set of SHQ samples, as well as source code for an SHQ2 encoder (not included) and assistance with understanding some details of the format.
* avcodec/get_bits: add av_assert2 to get_bits_long()Paul B Mahol2016-12-181-0/+1
| | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* avcodec/get_bits: Fix get_sbits_long(0)Michael Niedermayer2016-12-031-0/+4
| | | | | | | | Fixes undefined behavior Fixes: 640889-media Found-by: Matt Wolenetz <wolenetz@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* Merge commit '52567e8198669a1e7493c75771613f87a90466c3'Hendrik Leppkes2016-06-261-86/+1
|\ | | | | | | | | | | | | * commit '52567e8198669a1e7493c75771613f87a90466c3': get_bits: Drop some TRACE-level debug code Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
| * get_bits: Drop some TRACE-level debug codeDiego Biurrun2016-05-221-64/+0
| | | | | | | | It will not be provided by the new bit reader anyway.
* | Merge commit 'ffa190d0479d2370dd89c95692f822cbff2cc24c'Clément Bœsch2016-06-231-41/+1
|\| | | | | | | | | | | | | * commit 'ffa190d0479d2370dd89c95692f822cbff2cc24c': Move VLC and RL_VLC_ELEM structure definitions to a separate header Merged-by: Clément Bœsch <u@pkh.me>
| * Move VLC and RL_VLC_ELEM structure definitions to a separate headerAlexandra Hájková2016-05-171-41/+1
| | | | | | | | | | | | | | Use the newly created vlc.h directly instead of including get_bits when needed. The VLC and RL_VLC_ELEM structures are independent from the bitreader. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * Move check_marker() from get_bits to mpeg4videodecAlexandra Hájková2016-05-161-9/+0
| | | | | | | | | | | | MPEG-4 is the only decoder which uses check_marker(). Signed-off-by: Anton Khirnov <anton@khirnov.net>
* | lavc/get_bits: add a logging context to check_marker()Clément Bœsch2016-06-221-2/+3
| | | | | | | | Based on d338abb664febbc2c7266af7818aab1f12dbc161
* | Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'Clément Bœsch2016-06-211-2/+2
|\| | | | | | | | | | | | | * commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb': cosmetics: Fix spelling mistakes Merged-by: Clément Bœsch <u@pkh.me>
| * cosmetics: Fix spelling mistakesVittorio Giovara2016-05-041-2/+2
| | | | | | | | Signed-off-by: Diego Biurrun <diego@biurrun.de>
| * lavc: Add get_bitsz()Andreas Cadhalpun2016-01-111-0/+8
| | | | | | | | | | | | get_bit variant supporting 0-bits reads. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
| * get_bits: Support max_depth > 2 in GET_RL_VLC_INTERNALKieran Kunhya2016-01-111-0/+11
| |
* | get_bits: add get_bitsz for reading 0-25 bitsAndreas Cadhalpun2016-01-031-0/+8
| | | | | | | | | | | | | | This can be used to simplify code in a couple of places. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
* | get_bits: Support max_depth > 2 in GET_RL_VLC_INTERNALKieran Kunhya2015-12-131-0/+11
| |
* | Merge commit '059a934806d61f7af9ab3fd9f74994b838ea5eba'Michael Niedermayer2015-07-271-2/+2
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '059a934806d61f7af9ab3fd9f74994b838ea5eba': lavc: Consistently prefix input buffer defines Conflicts: doc/examples/decoding_encoding.c libavcodec/4xm.c libavcodec/aac_adtstoasc_bsf.c libavcodec/aacdec.c libavcodec/aacenc.c libavcodec/ac3dec.h libavcodec/asvenc.c libavcodec/avcodec.h libavcodec/avpacket.c libavcodec/dvdec.c libavcodec/ffv1enc.c libavcodec/g2meet.c libavcodec/gif.c libavcodec/h264.c libavcodec/h264_mp4toannexb_bsf.c libavcodec/huffyuvdec.c libavcodec/huffyuvenc.c libavcodec/jpeglsenc.c libavcodec/libxvid.c libavcodec/mdec.c libavcodec/motionpixels.c libavcodec/mpeg4videodec.c libavcodec/mpegvideo.c libavcodec/noise_bsf.c libavcodec/nuv.c libavcodec/nvenc.c libavcodec/options.c libavcodec/parser.c libavcodec/pngenc.c libavcodec/proresenc_kostya.c libavcodec/qsvdec.c libavcodec/svq1enc.c libavcodec/tiffenc.c libavcodec/truemotion2.c libavcodec/utils.c libavcodec/utvideoenc.c libavcodec/vc1dec.c libavcodec/wmalosslessdec.c libavformat/adxdec.c libavformat/aiffdec.c libavformat/apc.c libavformat/apetag.c libavformat/avidec.c libavformat/bink.c libavformat/cafdec.c libavformat/flvdec.c libavformat/id3v2.c libavformat/isom.c libavformat/matroskadec.c libavformat/mov.c libavformat/mpc.c libavformat/mpc8.c libavformat/mpegts.c libavformat/mvi.c libavformat/mxfdec.c libavformat/mxg.c libavformat/nutdec.c libavformat/oggdec.c libavformat/oggparsecelt.c libavformat/oggparseflac.c libavformat/oggparseopus.c libavformat/oggparsespeex.c libavformat/omadec.c libavformat/rawdec.c libavformat/riffdec.c libavformat/rl2.c libavformat/rmdec.c libavformat/rtpdec_latm.c libavformat/rtpdec_mpeg4.c libavformat/rtpdec_qdm2.c libavformat/rtpdec_svq3.c libavformat/sierravmd.c libavformat/smacker.c libavformat/smush.c libavformat/spdifenc.c libavformat/takdec.c libavformat/tta.c libavformat/utils.c libavformat/vqf.c libavformat/westwood_vqa.c libavformat/xmv.c libavformat/xwma.c libavformat/yop.c Merged-by: Michael Niedermayer <michael@niedermayer.cc>
| * lavc: Consistently prefix input buffer definesVittorio Giovara2015-07-271-2/+2
| | | | | | | | Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
* | Merge commit '6a85dfc830f51f1f5c2d36d4182d265c1ea3ba25'Michael Niedermayer2015-04-201-4/+0
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '6a85dfc830f51f1f5c2d36d4182d265c1ea3ba25': lavc: Replace av_dlog and tprintf with internal macros Conflicts: libavcodec/aacdec.c libavcodec/audio_frame_queue.c libavcodec/bitstream.c libavcodec/dcadec.c libavcodec/dnxhddec.c libavcodec/dvbsubdec.c libavcodec/dvdec.c libavcodec/dvdsubdec.c libavcodec/get_bits.h libavcodec/gifdec.c libavcodec/h264.h libavcodec/h264_cabac.c libavcodec/h264_cavlc.c libavcodec/h264_loopfilter.c libavcodec/h264_refs.c libavcodec/imc.c libavcodec/interplayvideo.c libavcodec/jpeglsdec.c libavcodec/libopencore-amr.c libavcodec/mjpegdec.c libavcodec/mpeg12dec.c libavcodec/mpegvideo_enc.c libavcodec/mpegvideo_parser.c libavcodec/pngdec.c libavcodec/ratecontrol.c libavcodec/rv10.c libavcodec/svq1dec.c libavcodec/vqavideo.c libavcodec/wmadec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * lavc: Replace av_dlog and tprintf with internal macrosVittorio Giovara2015-04-191-5/+0
| |
| * get_bits: remove unused assignmentVittorio Giovara2014-11-031-1/+1
| | | | | | | | Bug-Id: CID 1238816
* | avcodec/get_bits: print details of the location of the missing bit in ↵Michael Niedermayer2015-04-141-1/+1
| | | | | | | | | | | | check_marker() Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit 'b574e1e97ea7067a5fcd3876e30a67df0e4e6611'Michael Niedermayer2014-09-051-6/+7
|\| | | | | | | | | | | | | | | | | | | * commit 'b574e1e97ea7067a5fcd3876e30a67df0e4e6611': get_bits: Add OPEN_READER macro variant w/o size_plus8 Conflicts: libavcodec/get_bits.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * get_bits: Add OPEN_READER macro variant w/o size_plus8Diego Biurrun2014-09-051-6/+7
| | | | | | | | This avoids a trillion warnings from MSVC.
* | Merge commit '91d305790ea0f6fe0f54b48236da42181c39c18b'Michael Niedermayer2014-09-021-2/+2
|\| | | | | | | | | | | | | | | | | | | * commit '91d305790ea0f6fe0f54b48236da42181c39c18b': get_bits: Rename HAVE_BITS_REMAINING --> BITS_AVAILABLE Conflicts: libavcodec/golomb.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * get_bits: Rename HAVE_BITS_REMAINING --> BITS_AVAILABLEDiego Biurrun2014-09-021-2/+2
| | | | | | | | The HAVE_ prefix is reserved for macros set by configure.