aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/vc2enc.c
Commit message (Collapse)AuthorAgeFilesLines
* all: fix typos found by codespellTimo Rothenpieler17 hours1-1/+1
|
* avcodec/vc2enc: Use LUT to avoid repeated av_log2()Andreas Rheinhardt2025-05-271-2/+6
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Improve error codesAndreas Rheinhardt2025-04-211-3/+3
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Avoid excessive inliningAndreas Rheinhardt2025-03-121-2/+7
| | | | | | | | | | There is no reason to inline put_vc2_ue_uint() everywhere; only one call site is actually hot: The one in encode_subband() (which accounts for 35735040 of 35739495 calls to said function in a FATE run). Uninline all the others. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Use LUT to assemble interleaved golomb codeAndreas Rheinhardt2025-03-121-12/+33
| | | | | | | | Up until now, the encoder processed only one bit at a time. With this patch, it is eight bits. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/put_bits: Add and use put_bits63()Andreas Rheinhardt2025-03-111-1/+1
| | | | | | | | | | | When using a 64bit PutBitContext (i.e. on x64), put_bits_no_assert() can naturally write up to 63 bits. So one can avoid treating the cases <32bits, 32 bits and <63 bits differently. As it turns out, no user actually wants to write 64 bit at once (maybe except testprograms). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Simplify writing dirac golomb codesAndreas Rheinhardt2025-03-111-27/+3
| | | | | | | | | | The earlier code used a loop to determine the number of bits used and called ff_log2() on a power of two (and it would be easy to keep track of the exponent of said power-of-two); neither GCC nor Clang optimized the loop away or avoided the ff_log2(). This patch replaces the loop and the log2 with a single av_log2(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal, all: Use macros to set deprecated AVCodec fieldsAndreas Rheinhardt2025-03-101-1/+1
| | | | | | | | | | | | | | The aim of this is twofold: a) Clang warns when setting a deprecated field in a definition and because several of the widely set AVCodec fields are deprecated, one gets several hundred warnings from Clang for an ordinary build. Yet fortunately Clang (unlike GCC) allows to disable deprecation warnings inside a definition, so that one can create simple macros to set these fields that also suppress deprecation warnings for Clang. This has already been done in fdff1b9cbfd8cf5a9810c29efa4baf13a4786742 for AVCodec.channel_layouts. b) Using macros will allow to easily migrate these fields to internal ones. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: basic sanity check on slice_max_bytesMichael Niedermayer2024-09-191-1/+1
| | | | | | | | Fixes: left shift of 896021632 by 3 places cannot be represented in type 'int' Fixes: 70544/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VC2_fuzzer-6685593652756480 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/internal: add FFCodec.color_rangesNiklas Haas2024-09-081-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I went through all codecs and put them into five basic categories: 1. JPEG range only 2. MPEG range only 3. Explicitly tagged 4. Broken (codec supports both but encoder ignores tags) 5. N/A (headerless or pseudo-formats) Filters in category 5 remain untouched. The rest gain an explicit assignment of their supported color ranges, with codecs in category 4 being set to MPEG-only for safety. It might be considered redundant to distinguish between 0 (category 5) and MPEG+JPEG (category 3), but in doing so we effectively communicate that we can guarantee that these tags will be encoded, which is distinct from the situation where there are some codecs that simply don't have tagging or implied semantics (e.g. rawvideo). A full list of codecs follows: JPEG range only: - amv - roqvideo MPEG range only: - asv1, asv2 - avui - cfhd - cljr - dnxhd - dvvideo - ffv1 - flv - h261, h263, h263p - {h263,vp8}_v4l2m2m - huffyuv, ffvhuff - jpeg2000 - libopenjpeg - libtheora - libwebp, libwebp_anim - libx262 - libxavs, libxavs2 - libxvid - mpeg1video, mpeg2video - mpeg2_qsv - mpeg2_vaapi - mpeg4, msmpeg4, msmpeg4v2, wmv1, wmv2 - mpeg4_omx - prores, prores_aw, prores_ks - rv10, rv20 - snow - speedhq - svq1 - tiff - utvideo Explicitly tagged (MPEG/JPEG): - {av1,h264,hevc}_nvenc - {av1,h264,hevc}_vaapi - {av1,h264,hevc,vp8,vp9,mpeg4}_mediacodec - {av1,h264,hevc,vp9}_qsv - h264_amf - {h264,hevc,prores}_videotoolbox - libaom-av1 - libkvazaar - libopenh264 - librav1e - libsvtav1 - libvpx, libvpx-vp9 - libx264 - libx265 - ljpeg - mjpeg - vc2 Broken (encoder ignores tags): - {av1,hevc}_amf - {h264,hevc,mpeg4}_v4l2m2m - h264_omx - libxeve - magicyuv - {vp8,vp9,mjpeg}_vaapi N/A: - ayuv, yuv4, y41p, v308, v210, v410, v408 (headerless) - pgmyuv (headerless) - rawvideo, bitpacked (headerless) - vnull, wrapped_avframe (pseudocodecs)
* avcodec/vc2enc: Fix overflows with storing large valuesMichael Niedermayer2024-07-161-2/+5
| | | | | | | | | Fixes: left shift of 1431634944 by 2 places cannot be represented in type 'int' Fixes: left shift of 1073741824 by 1 places cannot be represented in type 'int' Fixes: 69061/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VC2_fuzzer-6325700826038272 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/vc2enc: Use already available AVPixFmtDescriptorAndreas Rheinhardt2024-05-311-6/+7
| | | | | Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Move transient PutBitContext from ctx to stackAndreas Rheinhardt2024-05-311-7/+10
| | | | | Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Avoid relocations for short stringsAndreas Rheinhardt2024-05-311-2/+3
| | | | | | | | | | | These strings are so short that they can be put directly into the containing structure, avoiding the pointer and putting it into .rodata. Also use chars for interlaced and level while at it, as these are so small. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Fix slice lengthAndreas Rheinhardt2024-05-311-1/+1
| | | | | | | | | | | | | args->bytes here already includes prefix_bytes (see SSIZE_ROUND macro), so including it here again and forgetting it when offsetting skip seems wrong. This only works because prefix_bytes is currently always zero in this encoder. (This has been added in b88be742fac7a77a8095e8155ba8790db4b77568 without any reason.) Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Remove superfluous error messageAndreas Rheinhardt2024-05-311-3/+1
| | | | | | | | ff_get_encode_buffer() already emits an error message of its own. While just at it, also check for ret < 0 instead of just ret != 0. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Constify slices->main context pointersAndreas Rheinhardt2024-05-311-9/+9
| | | | | Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Avoid void* where possibleAndreas Rheinhardt2024-05-311-2/+2
| | | | | Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avutil/common: Don't auto-include mem.hAndreas Rheinhardt2024-03-311-0/+1
| | | | | | | | | | | There are lots of files that don't need it: The number of object files that actually need it went down from 2011 to 884 here. Keep it for external users in order to not cause breakages. Also improve the other headers a bit while just at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* all: use designated initializers for AVOption.unitAnton Khirnov2024-02-141-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | Makes it robust against adding fields before it, which will be useful in following commits. Majority of the patch generated by the following Coccinelle script: @@ typedef AVOption; identifier arr_name; initializer list il; initializer list[8] il1; expression tail; @@ AVOption arr_name[] = { il, { il1, - tail + .unit = tail }, ... }; with some manual changes, as the script: * has trouble with options defined inside macros * sometimes does not handle options under an #else branch * sometimes swallows whitespace
* Revert "all: Don't set AVClass.item_name to its default value"Anton Khirnov2024-01-201-0/+1
| | | | | | | Some callers assume that item_name is always set, so this may be considered an API break. This reverts commit 0c6203c97a99f69dbaa6e4011d48c331e1111f5e.
* all: Don't set AVClass.item_name to its default valueAndreas Rheinhardt2023-12-221-1/+0
| | | | | | | | Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9; also avoids relocations. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc: support AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE in all no-delay encodersAnton Khirnov2023-01-291-1/+2
| | | | Including fake-delay encoders marked with FF_CODEC_CAP_EOF_FLUSH.
* avcodec/vc2enc: Don't use bitcount when byte-alignedAndreas Rheinhardt2022-10-091-6/+5
| | | | | | | | | | | | | | (There is a small issue that is now being treated differently: The earlier code would record a position in a buffer that is being written to via put_bits(), then write data, then overwrite the byte at the position recorded earlier and only then flush the PutBitContext. In case there was no writeout in the meantime, said flush would overwrite what one has just written. This never happened in my tests, but maybe it can happen. In this case this commit fixes this issue by flushing before overwriting the old data.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add macro to set AVCodec.long_nameAndreas Rheinhardt2022-09-031-1/+1
| | | | | | | | It reduces typing: Before this patch, there were 105 codecs whose long_name-definition exceeded the 80 char line length limit. Now there are only nine of them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Constify frame->data pointers for encoders where possibleAndreas Rheinhardt2022-08-051-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Make init-threadsafety the defaultAndreas Rheinhardt2022-07-181-1/+1
| | | | | | | | | | | and remove FF_CODEC_CAP_INIT_THREADSAFE All our native codecs are already init-threadsafe (only wrappers for external libraries and hwaccels are typically not marked as init-threadsafe yet), so it is only natural for this to also be the default state. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Use union for FFCodec decode/encode callbacksAndreas Rheinhardt2022-04-051-1/+1
| | | | | | | | | | | This is possible, because every given FFCodec has to implement exactly one of these. Doing so decreases sizeof(FFCodec) and therefore decreases the size of the binary. Notice that in case of position-independent code the decrease is in .data.rel.ro, so that this translates to decreased memory consumption. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Rename AVCodecDefault->FFCodecDefaultAndreas Rheinhardt2022-03-211-1/+1
| | | | | | | This structure is no longer declared in a public header, so using an FF-prefix is more appropriate. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-211-8/+8
| | | | | | | | | | | | | | | | Up until now, codec.h contains both public and private parts of AVCodec. This exposes the internals of AVCodec to users and leads them into the temptation of actually using them and forces us to forward-declare structures and types that users can't use at all. This commit changes this by adding a new structure FFCodec to codec_internal.h that extends AVCodec, i.e. contains the public AVCodec as first member; the private fields of AVCodec are moved to this structure, leaving codec.h clean. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.hAndreas Rheinhardt2022-03-211-1/+1
| | | | | | | | | | Also move FF_CODEC_TAGS_END as well as struct AVCodecDefault. This reduces the amount of files that have to include internal.h (which comes with quite a lot of indirect inclusions), as e.g. most encoders don't need it. It is furthemore in preparation for moving the private part of AVCodec out of the public codec.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* libavcodec: Split version.hMartin Storsjö2022-03-161-0/+1
| | | | | | | | | | | | | | This avoids including version.h in all source files, avoiding unnecessary rebuilds when the version number is bumped. Only version_major.h is included by the main header, which defines availability of e.g. FF_API_* macros, and which is bumped much less often. This isn't done for libavutil/version.h, because that header needs to be included essentially everywhere due to LIBAVUTIL_VERSION_INT being used wherever an AVClass is constructed. Signed-off-by: Martin Storsjö <martin@martin.st>
* Remove obsolete version.h inclusionsAndreas Rheinhardt2022-02-241-1/+1
| | | | | | | Forgotten in e7bd47e657bbf9e1ce9915e93bc80cb1a29fb7f3. Reviewed-by: Martin Storsjö <martin@martin.st> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Cleanup generically on allocation failureAndreas Rheinhardt2022-02-111-9/+4
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vc2enc: Check for non negative slice boundsMichael Niedermayer2021-06-081-0/+2
| | | | | | | Fixes: invalid shifts Fixes: Ticket 8221 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/vc2enc: Allow user-supplied buffersAndreas Rheinhardt2021-05-151-4/+4
| | | | | | | Trivial for an encoder that has a very good estimate of the size of the output packet in advance. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Constify AVCodecsAndreas Rheinhardt2021-04-271-1/+1
| | | | | | | | | | 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/vc2enc: Actually zero paddingAndreas Rheinhardt2021-04-261-1/+1
| | | | | | | | This encoder sets the min_size in ff_alloc_packet2(), so it can not rely on av_packet_make_refcounted() to zero the padding. Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* vc2enc: Add missing static to local variablesMark Thompson2021-02-021-2/+2
|
* 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-7/+7
| | | | | | | | | 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, avfilter, avformat: Remove redundant avpriv_align_put_bitsAndreas Rheinhardt2020-08-011-1/+0
| | | | | | | | flush_put_bits() already fills the bitstream with zeroes, so it is unnecessary to align the bitstream before. Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* vc2enc: zero padding of the coefficient bufferLynne2019-12-171-0/+2
| | | | | | | | | | Wavelet types with large amounts of overreading/writing like 9_7 would write into the padding at high wavelet depths, which would remain and be read by the next frame's transform and quickly cause artifacts to appear for subsequent frames. This fix affects all frames encoded with a non-power-of-two width, with the artifacts varying between non-observable to very noticeable, depending on encoder settings, so reencoding is advisable.
* vc2enc: properly promote operations to 64 bitsRostislav Pehlivanov2018-03-131-5/+5
| | | | | | | | | | | On Windows machines, the UL suffix still means 32 bits. The only parts that need 64 bits are (1ULL << (m + 32)) and (t*qf + qf). Hence, use the proper ULL suffix for the former and just increase the type of the qf constant for the latter. No overflows can happen as long as these are done in 64 bits and the quantization table doesn't change. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* vc2enc: replace quantization LUT with a smaller division LUTRostislav Pehlivanov2018-03-101-87/+31
| | | | | | | | | This commit replaces the huge and impractical LUT which converted coeffs and a quantizer to bits to encode and instead uses a standard multiplication and a shift to replace the division and then codes the values using the regular golomb coding functions. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* avcodec/vc2enc: prevent bitrate overshootsRostislav Pehlivanov2018-01-311-8/+14
| | | | | | | The rounding caused by the size scaler wasn't compensated for and the slice sizes grew beyond what is allowed per frame. Signed-off-by: Rostislav Pehlivanov <rpehlivanov@obe.tv>
* avcodec/vc2enc: Clear coef_buf on allocationMichael Niedermayer2017-11-151-1/+1
| | | | | | | | Fixes: Use of uninitialized memory Fixes: assertion failure Reviewed-by: <atomnuker> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* vc2enc_dwt: pad the temporary buffer by the slice sizeRostislav Pehlivanov2017-11-091-1/+2
| | | | | | | | | | | | | | | Since non-Haar wavelets need to look into pixels outside the frame, we need to pad the buffer. The old factor of two seemed to be a workaround that fact and only padded to the left and bottom. This correctly pads by the slice size and as such reduces memory usage and potential exploits. Reported by Liu Bingchang. Ideally, there should be no temporary buffer but the encoder is designed to deinterleave the coefficients into the classical wavelet structure with the lower frequency values in the top left corner. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* avcodec: remove remaining uses of avcodec_get_chroma_sub_sampleMartin Vignali2017-11-061-2/+4
| | | | | | Replace them with av_pix_fmt_get_chroma_sub_sample. Signed-off-by: James Almer <jamrial@gmail.com>
* Revert "vc2enc: Calculate average slice quantiser correctly"Kieran Kunhya2017-11-041-3/+3
| | | | This reverts commit 626d200e76e15487cff20992256a55919432b0b3.