summaryrefslogtreecommitdiff
path: root/libavcodec/put_bits.h
Commit message (Collapse)AuthorAgeFilesLines
* libavcodec/flacenc: Implement encoding of 32 bit-per-sample PCMMartijn van Beurden2022-12-261-0/+7
| | | | | | Add encoding of 32 bit-per-sample PCM to FLAC files to libavcodec. Coding to this format is at this point considered experimental and -strict experimental is needed to get ffmpeg to encode such files.
* avutil/avassert: Don't include avutil.hAndreas Rheinhardt2022-02-241-0/+1
| | | | | Reviewed-by: Martin Storsjö <martin@martin.st> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/bitstream: Remove avpriv PutBits API functionsAndreas Rheinhardt2021-04-271-10/+0
| | | | | | | | | Scheduled for removal in 717503f7166d7032e32b935f2819d450524125d1. Also remove PutBitContext.size_in_bits which has been scheduled for removal in e7cbbd90267de2a0ad1b5fa8ccb29ab7bf8a26b8. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/put_bits: Don't set size_in_bits, fix overflowAndreas Rheinhardt2021-03-301-3/+2
| | | | | | | | | | | | | | | | | | A PutBitContext has a field called size_in_bits which is set to the context's bitsize init_put_bits(); but it isn't used at all (the PutBits API uses pointers directly and not bit indexes), so remove it (due to ABI concerns the actual element is only removed at the next bump). Furthermore, the multiplication inherent in setting this field can lead to undefined integer overflows. This is particularly true for FFV1, which uses a very big worst-case buffer (37*4*width*height; even ordinary 1080p triggers an overflow). Ticket #8350 is about this overflow which this commit fixes. This means that the effective range of the PutBits API is no longer restricted by the /8 as long as one isn't using put_bits_(count|left). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/put_bits: Add functions for amount of bytes written/leftAndreas Rheinhardt2021-03-301-0/+30
| | | | | | | | | | | | | | | | | | | | Often a caller doesn't want the amount of bits written via a PutBitContext, but the amount of bytes. This in particular happens after one has flushed the PutBitContext (e.g. at the end of encoding, when one wants to know the actual packet size). The current way of doing this is with put_bits_count(pb)/8 (or (put_bits_count(pb) + 7)/8). Yet this has some issues: It contains implicit multiplications and divisions by 8 with a cast in between; it obscurs the intent; and it restricts the size of the buffer to (currently) INT_MAX/8 (or to 1/8 of the maximum of whatever put_bits_count() returns), although said restriction is not really necessary for users that don't need a bitcount. Corresponding functions for the amount of bytes left have also been addded. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* put_bits: make avpriv_copy_bits() lavc-localAnton Khirnov2020-10-281-2/+3
| | | | | It is not used outside of lavc anymore. Keep the avpriv exported symbol around until the next bump to preserve ABI compatibility.
* put_bits: make avpriv_put_string() lavc-localAnton Khirnov2020-10-281-2/+2
| | | | | It has not been used outside of libavcodec since 20f325f320c6e18ee88983870d2a1fee94257293
* put_bits: make avpriv_align_put_bits() inlineAnton Khirnov2020-10-281-5/+14
| | | | | | | | | This function is so extremely simple that it is preferable to make it inline rather than deal with all the complications arising from it being an exported symbol. Keep avpriv_align_put_bits() around until the next major bump to preserve ABI compatibility.
* avcodec/put_bits: Make skip_put_bits() less dangerousAndreas Rheinhardt2020-08-081-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before c63c303a1f2b58677d480505ec93a90f77dd25b5 (the commit which introduced a typedef for the type of the buffer of a PutBitContext) skip_put_bits() was as follows: static inline void skip_put_bits(PutBitContext *s, int n) { s->bit_left -= n; s->buf_ptr -= 4 * (s->bit_left >> 5); s->bit_left &= 31; } If s->bit_left was negative after the first subtraction, then the next line will divide this by 32 with rounding towards -inf and multiply by four; the result will be negative, of course. The aforementioned commit changed this to: static inline void skip_put_bits(PutBitContext *s, int n) { s->bit_left -= n; s->buf_ptr -= sizeof(BitBuf) * ((unsigned)s->bit_left / BUF_BITS); s->bit_left &= (BUF_BITS - 1); } Casting s->bit_left to unsigned meant that the rounding is still towards -inf; yet the right side is now always positive (it transformed the arithmetic shift into a logical shift), so that s->buf_ptr will always be decremented (by about UINT_MAX / 8 unless n is huge) which leads to segfaults on further usage and is already undefined pointer arithmetic before that. This can be reproduced with the mpeg4 encoder with the AV_CODEC_FLAG2_NO_OUTPUT flag set. Furthermore, the earlier version as well as the new version share another bug: s->bit_left will be in the range of 0..(BUF_BITS - 1) afterwards, although the assumption throughout the other PutBitContext functions is that it is in the range of 1..BUF_BITS. This might lead to a shift by BUF_BITS in little-endian mode. This has been fixed, too. The new version is furthermore able to skip zero bits, too. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/put_bits: Make bit buffers 64-bitSteinar H. Gunderson2020-07-191-7/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change BitBuf into uint64_t on 64-bit x86. This means we need to flush the buffer less often, which is a significant speed win. All other platforms, including all 32-bit ones, are unchanged. Output bitstream is the same. All API constraints are kept in place, e.g., you still cannot put_bits() more than 31 bits at a time. This is so that codecs cannot accidentally become 64-bit-only or similar. Benchmarking on transcoding to various formats shows consistently positive results: dnxhd 25.60 fps -> 26.26 fps ( +2.6%) dvvideo 24.88 fps -> 25.17 fps ( +1.2%) ffv1 14.32 fps -> 14.58 fps ( +1.8%) huffyuv 58.75 fps -> 63.27 fps ( +7.7%) jpegls 6.22 fps -> 6.34 fps ( +1.8%) magicyuv 57.10 fps -> 63.29 fps (+10.8%) mjpeg 48.65 fps -> 49.01 fps ( +0.7%) mpeg1video 76.41 fps -> 77.01 fps ( +0.8%) mpeg2video 75.99 fps -> 77.43 fps ( +1.9%) mpeg4 80.66 fps -> 81.37 fps ( +0.9%) prores 12.35 fps -> 12.88 fps ( +4.3%) prores_ks 16.20 fps -> 16.80 fps ( +3.7%) rv20 62.80 fps -> 62.99 fps ( +0.3%) utvideo 68.41 fps -> 76.32 fps (+11.6%) Note that this includes video decoding and all other encoding work, such as DCTs. If you isolate the actual bit-writing routines, it is likely to be much more. Benchmark details: Transcoding the first 30 seconds of Big Buck Bunny in 1080p, Haswell 2.1 GHz, GCC 8.3, generally quantizer locked to 5.0. (Exceptions: DNxHD needs fixed bitrate, and JPEG-LS is so slow that I only took the first 10 seconds, not 30.) All runs were done ten times and single-threaded, top and bottom two results discarded to get rid of outliers, arithmetic mean between the remaining six. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/put_bits: Parametrize bit buffer typeSteinar H. Gunderson2020-07-191-43/+52
| | | | | | | | | | Preparatory patch for making the bit buffer different size on different platforms; make a typedef and make all the hardcoded sizes into expressions deriving from this size. No functional change; generated assembler is near-identical. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/put_bits: Relax requirements to rebase PutBitContextAndreas Rheinhardt2019-11-161-10/+10
| | | | | | | | | The earlier requirement was for the new buffer to be bigger than the old one. This has been relaxed to only demand that the new buffer can hold all the data written so far. This is in preparation for further commits. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc/g726: Add a little-endian G.726 encoder.Carl Eugen Hoyos2017-08-211-0/+40
| | | | Fixes ticket #6596.
* lavc/put_bits: Add put_bits64() to support up to 64 bits.Jun Zhao2017-06-241-0/+35
| | | | | | | | | put_bits64() can write up to 64 bits into a bitstream. Reviewed-by: Mark Thompson <sw@jkqxz.net> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Jun Zhao <jun.zhao@intel.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/put_bits: Implement put_bits32() in a single pass instead of 2 ↵Michael Niedermayer2017-06-131-6/+28
| | | | | | | | passes writing 16bits each 820 cpu cycles -> 660 cpu cycles for 100 put_bits32() Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/put_bits: Assert buf_ptr in flush_put_bits()Michael Niedermayer2016-01-181-1/+1
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/put_bits: Always check buffer end before writingMichael Niedermayer2016-01-021-6/+14
| | | | | | This causes a overall slowdown of 0.1 % (tested with mpeg4 single thread encoding of matrixbench at QP=3) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/put_bits: Assert that size in set_put_bits_buffer_size() does not ↵Michael Niedermayer2015-05-251-0/+1
| | | | | | cause integer overflows Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* avcodec/put_bits: Assert that there is enough space left in skip_put_bytes()Michael Niedermayer2015-05-251-0/+1
| | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* avcodec/put_bits: Update size_in_bits in set_put_bits_buffer_size()Michael Niedermayer2015-05-251-0/+1
| | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* avcodec/put_bits: Remove dead code in put_bits()Michael Niedermayer2015-05-151-1/+1
| | | | | | Fixes CID1297574 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* avcodec: use av_mod_uintp2() where usefulJames Almer2015-04-211-1/+1
| | | | | Reviewed-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/put_bits: remove unneeded #include, there are no assert()Paul B Mahol2015-02-011-1/+0
| | | | Signed-off-by: Paul B Mahol <onemda@gmail.com>
* avcodec/put_bits: Add rebase_put_bits()Michael Niedermayer2014-09-291-0/+18
| | | | | Reviewed-by: Benoit Fouet <benoit.fouet@free.fr> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* Merge remote-tracking branch 'qatar/master'Michael Niedermayer2014-03-041-6/+1
|\ | | | | | | | | | | | | | | | | | | * qatar/master: put_bits: Remove unused includes Conflicts: libavcodec/put_bits.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * put_bits: Remove unused includesVittorio Giovara2014-03-041-6/+1
| | | | | | | | | | This requires adding includes to other files that relied on these being included implicitly.
* | Merge commit 'afe03092dd693d025d43e1620283d8d285c92772'Michael Niedermayer2013-06-291-0/+8
|\ \ | |/ | | | | | | | | | | * commit 'afe03092dd693d025d43e1620283d8d285c92772': lavc: move put_bits_left in put_bits.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * lavc: move put_bits_left in put_bits.hLuca Barbato2013-06-281-0/+8
| |
* | Merge commit '4af5310d29379283553bcd9f541a3f6c317f706e'Michael Niedermayer2013-01-221-39/+42
|\ \ | |/ | | | | | | | | | | | | | | | | | | * commit '4af5310d29379283553bcd9f541a3f6c317f706e': get_bits/put_bits: K&R formatting cosmetics Conflicts: libavcodec/get_bits.h libavcodec/put_bits.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * get_bits/put_bits: K&R formatting cosmeticsDiego Biurrun2013-01-211-39/+42
| | | | | | | | Signed-off-by: Diego Biurrun <diego@biurrun.de>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-10-011-3/+0
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: avcodec: Convert some commented-out printf/av_log instances to av_dlog avcodec: Drop silly and/or broken printf debug output avcodec: Drop some silly commented-out av_log() invocations avformat: Convert some commented-out printf/av_log instances to av_dlog avformat: Remove non-compiling and/or silly commented-out printf/av_log statements Remove some silly disabled code. ac3dec: ensure get_buffer() gets a buffer for the correct number of channels Conflicts: libavcodec/dnxhddec.c libavcodec/ffv1.c libavcodec/h264.c libavcodec/h264_parser.c libavcodec/mjpegdec.c libavcodec/motion_est_template.c libavcodec/mpegaudiodec.c libavcodec/mpegvideo_enc.c libavcodec/put_bits.h libavcodec/ratecontrol.c libavcodec/wmaenc.c libavdevice/timefilter.c libavformat/asfdec.c libavformat/avidec.c libavformat/avienc.c libavformat/flvenc.c libavformat/utils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * avcodec: Drop silly and/or broken printf debug outputDiego Biurrun2012-10-011-3/+0
| |
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-09-101-2/+2
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: x86: dsputil: Only compile motion_est code when encoders are enabled mem: fix typo in check for __ICC fate: mp3: drop redundant CMP setting rtp: Depacketization of JPEG (RFC 2435) Rename ff_put_string to avpriv_put_string mjpeg: Rename some symbols to avpriv_* instead of ff_* yadif: cosmetics Conflicts: Changelog libavcodec/mjpegenc.c libavcodec/x86/Makefile libavfilter/vf_yadif.c libavformat/version.h libavutil/mem.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Rename ff_put_string to avpriv_put_stringMartin Storsjö2012-09-091-2/+2
| | | | | | | | | | | | | | This allows using it from libavformat as well. This will be used by the RTP/JPEG depacketizer. Signed-off-by: Martin Storsjö <martin@martin.st>
* | put_bits: use av_assertMichael Niedermayer2012-06-061-3/+3
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | put_bits: add av_assert2() to check out of array writes.Michael Niedermayer2012-04-071-0/+2
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | put_bits: switch assert to av_assert2()Michael Niedermayer2012-04-071-1/+2
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2011-10-211-4/+4
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: (47 commits) lavc: hide private symbols. lavc: deprecate img_get_alpha_info(). lavc: use avpriv_ prefix for ff_toupper4. lavc: use avpriv_ prefix for ff_copy_bits and align_put_bits. lavc: use avpriv_ prefix for ff_ac3_parse_header. lavc: use avpriv_ prefix for ff_frame_rate_tab. lavc: rename ff_find_start_code to avpriv_mpv_find_start_code lavc: use avpriv_ prefix for ff_split_xiph_headers. lavc: use avpriv_ prefix for ff_dirac_parse_sequence_header. lavc: use avpriv_ prefix for some dv symbols used in lavf. lavc: use avpriv_ prefix for some flac symbols used in lavf. lavc: use avpriv_ prefix for some mpeg4audio symbols used in lavf. lavc: use avpriv_ prefix for some mpegaudio symbols used in lavf. lavc: use avpriv_ prefix for ff_aac_parse_header(). lavf: hide private symbols. lavf: use avpriv_ prefix for some dv functions. lavf: use avpriv_ prefix for ff_new_chapter(). avcodec: add CODEC_CAP_DELAY note to avcodec_decode_audio3() documentation avcodec: clarify the CODEC_CAP_DELAY note in avcodec_decode_video2() avcodec: clarify documentation of CODEC_CAP_DELAY ... Conflicts: configure doc/general.texi libavcodec/Makefile libavcodec/aacdec.c libavcodec/allcodecs.c libavcodec/avcodec.h libavcodec/dv.c libavcodec/dvdata.c libavcodec/dvdata.h libavcodec/libspeexenc.c libavcodec/mpegvideo.c libavcodec/version.h libavformat/avidec.c libavformat/dv.c libavformat/dv.h libavformat/flvenc.c libavformat/mov.c libavformat/mp3enc.c libavformat/oggparsespeex.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * lavc: use avpriv_ prefix for ff_copy_bits and align_put_bits.Anton Khirnov2011-10-201-4/+4
| | | | | | | | They are used in lavf.
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2011-10-091-1/+2
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: lavf: fix signed overflow in avformat_find_stream_info() vp8: fix signed overflows motion_est: fix some signed overflows dca: fix signed overflow in shift aacdec: fix undefined shifts bink: Check for various out of bound writes bink: Check for out of bound writes when building tree put_bits: fix invalid shift by 32 in flush_put_bits() Conflicts: libavcodec/bink.c libavformat/utils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * put_bits: fix invalid shift by 32 in flush_put_bits()Mans Rullgard2011-10-081-1/+2
| | | | | | | | | | | | | | | | | | If flush_put_bits() is called when the 32-bit buffer is empty, e.g. after writing a multiple of 32 bits, and invalid shift by 32 is performed. Since flush_put_bits() is called infrequently, this additional check should have negligible performance impact. Signed-off-by: Mans Rullgard <mans@mansr.com>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2011-07-031-114/+3
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: ARM: ac3: update ff_ac3_extract_exponents_neon per 8b7b2d6 ARM: NEON optimised vector_clip_int32() swscale: disable full_chroma_int when converting to non-24/32bpp RGB. suggest to use av_get_bytes_per_sample() in av_get_bits_per_sample_format() doxy ffmpeg: use av_get_bytes_per_sample() in place of av_get_bits_per_sample_fmt() put_bits: remove ALT_BITSTREAM_WRITER put_bits: always use intreadwrite.h macros libavformat: Add an example how to use the metadata API doxygen: Prefer member groups over grouping into modules doxygen: be more permissive when searching for API examples avformat: doxify the Metadata API lavf: restore old behavior for custom AVIOContex with an AVFMT_NOFILE format. lavf: use the correct pointer in av_open_input_stream(). avidec: infer absolute vs relative index from first packet Conflicts: libavformat/Makefile libavformat/avidec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * put_bits: remove ALT_BITSTREAM_WRITERMans Rullgard2011-07-021-101/+1
| | | | | | | | | | | | The code for this variant does not compile. Signed-off-by: Mans Rullgard <mans@mansr.com>
| * put_bits: always use intreadwrite.h macrosMans Rullgard2011-07-021-14/+3
| | | | | | | | | | | | This fixes invalid unaligned stores in some ARM configurations. Signed-off-by: Mans Rullgard <mans@mansr.com>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2011-06-051-0/+1
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: ARM: remove MULL inline asm mathops: use MUL64 macro where it forms part of other ops tty: factorise returning error codes. rawdec: add framerate private option. x11grab: add framerate private option. fbdev,v4l2: remove some forgotten uses of AVFormatParameters.time_base. bktr: don't error when AVFormatParameters.time_base isn't set. cmdutils: add missing const qualifier Skip headers not designed to work standalone during 'make checkheaders'. Add missing #includes to make headers self-contained. musepack: remove unnecessary #include from mpcdata.h musepack: remove extraneous mpcdata.h inclusions Fix error check in av_file_map() Conflicts: cmdutils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Add missing #includes to make headers self-contained.Diego Biurrun2011-06-041-0/+1
| | | | | | | | This fixes 'make checkheaders'.
| * Replace FFmpeg with Libav in licence headersMans Rullgard2011-03-191-4/+4
|/ | | | Signed-off-by: Mans Rullgard <mans@mansr.com>
* Add av_ prefix to bswap macrosMåns Rullgård2010-07-101-5/+5
| | | | Originally committed as revision 24170 to svn://svn.ffmpeg.org/ffmpeg/trunk
* bswap: change ME to NE in macro namesMåns Rullgård2010-07-101-5/+5
| | | | | | | Other parts of FFmpeg use NE (native endian) rather than ME (machine). This makes it consistent. Originally committed as revision 24169 to svn://svn.ffmpeg.org/ffmpeg/trunk
* Fix grammar errors in documentationMåns Rullgård2010-06-301-12/+12
| | | | Originally committed as revision 23904 to svn://svn.ffmpeg.org/ffmpeg/trunk