aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/h261enc.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/mpegvideo: Move loop_filter to {H263Dec,MPVEnc,VC1}ContextAndreas Rheinhardt2025-07-031-2/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move fields to {H263Dec,MPVEnc}Context when possibleAndreas Rheinhardt2025-07-031-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move mb_skip_run to {RV34Dec,MPVEnc}ContextAndreas Rheinhardt2025-07-031-6/+6
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo encs: Add put_bits_assume_flushed() to encode_headerAndreas Rheinhardt2025-05-211-1/+2
| | | | | | | This allows the compiler to remove the implicit "Do I need to output the PutBitContext buffer here?" checks. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move MotionEstContext to MPVEncContextAndreas Rheinhardt2025-03-261-1/+1
| | | | | | | All that is necessary to do so is perform ff_me_init_pic() on every slice. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Add MPVEncContextAndreas Rheinhardt2025-03-261-52/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many of the fields of MpegEncContext (which is also used by decoders) are actually only used by encoders. Therefore this commit adds a new encoder-only structure and moves all of the encoder-only fields to it except for those which require more explicit synchronisation between the main slice context and the other slice contexts. This synchronisation is currently mainly provided by ff_update_thread_context() which simply copies most of the main slice context over the other slice contexts. Fields which are moved to the new MPVEncContext no longer participate in this (which is desired, because it is horrible and for the fields b) below wasteful) which means that some fields can only be moved when explicit synchronisation code is added in later commits. More explicitly, this commit moves the following fields: a) Fields not copied by ff_update_duplicate_context(): dct_error_sum and dct_count; the former does not need synchronisation, the latter is synchronised in merge_context_after_encode(). b) Fields which do not change after initialisation (these fields could also be put into MPVMainEncContext at the cost of an indirection to access them): lambda_table, adaptive_quant, {luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp, {p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table, [pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff, {inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields, the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info, mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function pointers, mpv_flags, quantizer_noise_shaping, frame_reconstruction_bitfield, error_rate and intra_penalty. c) Fields which are already (re)set explicitly: The PutBitContexts pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir, esc_pos (reset when writing the header). d) Fields which are only used by encoders not supporting slice threading for which synchronisation doesn't matter: esc3_level_length and the remaining mb_info fields. e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD is set (which implies trellis) and even then it is only used for non-intra blocks. For these blocks dct_quantize_trellis_c() either sets coded_score[n] or returns a last_non_zero value of -1 in which case coded_score will be reset in encode_mb_internal(). Therefore no old values are ever used. The MotionEstContext has not been moved yet. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/{h261,ituh263}enc: Don't set ptr_lastgob unnecessarilyAndreas Rheinhardt2025-03-261-3/+0
| | | | | | It will be overwritten later in encode_thread() anyway. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Use func ptr for encoding macroblocksAndreas Rheinhardt2025-03-261-2/+3
| | | | | | | | | | | | | It gets rid of a switch (with accompanying CONFIG_*_ENCODER checks); for MJPEG, it even lets one perform the check for whether one is really encoding or only recording the macroblock once during init. Furthermore, the switch actually contained lots of dead code -- it is compiled three times (for different pixel formats: 420, 422, 444), yet most encoders only support 420. The approach used here automatically fixes this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Use function ptr for encode_picture_headerAndreas Rheinhardt2025-03-261-2/+6
| | | | | | | This gets rid of a switch and (in case of FMT_H263) several ifs. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261enc: Make h261_encode_init() call ff_mpv_encode_init()Andreas Rheinhardt2025-03-261-8/+9
| | | | | | | | Right now, ff_mpv_encode_init() is set as FFCodec.init and calls ff_h261_encode_init(). The opposite is more natural and avoids a non-static function. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Add MPVMainEncContextAndreas Rheinhardt2025-03-261-2/+2
| | | | | | | | This is in preparation for moving all the elements from MpegEncContext that are only used by the main encoder thread to MPVMainEncContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261enc: Don't use (size_t)-1Andreas Rheinhardt2025-03-201-1/+1
| | | | | | | | Fixes "runtime error: addition of unsigned offset to 0x765a09523a90 overflowed to 0x765a09523a8e". This fixes all H.261 tests when run under UBsan. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal, all: Use macros to set deprecated AVCodec fieldsAndreas Rheinhardt2025-03-101-2/+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/mpegvideo_enc: Move default_mv_penalty to h261enc.cAndreas Rheinhardt2025-03-071-0/+6
| | | | | | | | | | | MPEG-1/2 and the H.263-based encoders overwrite the default later and SpeedHQ and MJPEG-based encoders are intra-only and don't need a mv_penalty table at all. So only H.261 uses this table. Also add a comment to explain why it exists and is non-const. Reviewed-by: Ramiro Polla <ramiro.polla@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Add AV_CODEC_CAP_DR1Andreas Rheinhardt2025-03-041-1/+1
| | | | | | | | | | The mpegvideo-based encoders do one uncommon thing with the packet's data given by ff_alloc_packet(): They potentially reallocate it. But this only affects the internal buffer and is not user-facing at all, so one can nevertheless use the AV_CODEC_CAP_DR1 for them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261enc: Use LUT to write motion vector differencesAndreas Rheinhardt2025-02-231-14/+19
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: add FFCodec.color_rangesNiklas Haas2024-09-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/h261enc: Fix ac_vlc_length tablesAndreas Rheinhardt2024-06-201-47/+12
| | | | | | | | | | | | | | | | | | | | | | These tables are supposed to contain the number of bits needed to encode a given (run, level) pair. Yet the number of bits for pairs needing the escape code was wrong (it only contained the escape code and not the bits needed for run and level). Furthermore, H.261 (a format with explicit end-of-block codes) does not work well together with the RLTable API from rl.c: The EOB code is the first one in ff_h261_rl_tcoeff's VLC table and has a run value of zero. Therefore the result of get_rl_index() is off by one for run == 0 and level values with explicit (run, level) pair. Fixing this necessitated changing the ref files of the vsynth*-h261-trellis tests. Both filesizes as well as PSNR decreased. If one used a qscale value of 11 for this test, one would have received files with about the same size as before this patch (with qscale 12), but with better PSNR. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261enc: Avoid RLTable when writing macroblockAndreas Rheinhardt2024-06-201-20/+31
| | | | | | | | | | | | | | | The RLTable API in rl.c is not well designed for codecs with an explicit end-of-block code. ff_h261_rl_tcoeff's vlc has the EOB code as first element (presumably so that the decoder can check for it via "if (level == 0)") and this implies that the indices returned by get_rl_index() are off by one for run == 0 which is therefore explicitly checked. This commit changes this by adding a simple LUT for the values not requiring escaping. It is easy to directly include the sign bit into this, so this has also been done. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261enc: Inline constantsAndreas Rheinhardt2024-06-201-3/+3
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261enc, msmpeg4: Avoid setting dc_scale_tables unnecessarilyAndreas Rheinhardt2024-06-201-3/+0
| | | | | | | It is unnecessary because ff_mpeg1_dc_scale_table is the default for both dc_scale_tables. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Add const where appropriateAndreas Rheinhardt2024-06-121-1/+1
| | | | | | | | Specifically, add const to the pointed-to-type of pointers that point to something static or that belong to last_pic or next_pic (because modifying these might lead to data races). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo, ratecontrol: Remove write-only skip_countAndreas Rheinhardt2024-06-121-1/+0
| | | | | | Write-only since 6cf0cb8935f515a7b5f79d2e3cf02bd0764943bf. 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-0/+1
| | | | Including fake-delay encoders marked with FF_CODEC_CAP_EOF_FLUSH.
* avcodec/mpegvideo_enc: remove picture_number parameter from encode functionsMarton Balint2023-01-261-1/+1
| | | | | | They are unused. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/h261enc: Store the H.261 format valueAndreas Rheinhardt2022-10-061-24/+15
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Move H.261 size check to h261enc.cAndreas Rheinhardt2022-10-061-1/+10
| | | | 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/mpegvideo: Inline values in ff_update_block_index()Andreas Rheinhardt2022-07-311-1/+1
| | | | | | | | | This is possible for most of the callers, because e.g. only the MPEG-4 decoder can have bits_per_raw_sample > 8. Also most mpegvideo-based codecs are 420 only. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> 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: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-211-7/+7
| | | | | | | | | | | | | | | | 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-0/+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>
* avcodec/mpegvideo: Move encoder-only stuff to a new headerAndreas Rheinhardt2022-02-131-0/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261enc: Pass PutBitContext directly in h261_encode_motion()Andreas Rheinhardt2022-02-131-7/+6
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261: Move encoder-only stuff to a new headerAndreas Rheinhardt2022-02-131-0/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261: Separate decode and encode contextsAndreas Rheinhardt2022-02-131-20/+34
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Remove unnecessary h263.h inclusionsAndreas Rheinhardt2022-01-091-1/+0
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Deduplicate ff_mpv_generic_options-based AVClassesAndreas Rheinhardt2021-07-081-8/+1
| | | | | | | | The child_class_next API relied on different AVCodecs to use different AVClasses; yet this API has been replaced by child_class_iterate. 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/h261enc: Make encoder init-threadsafeAndreas Rheinhardt2021-01-251-4/+12
| | | | | | | | This is easy now that the H.261 encoder is the only user that initializes the non-VLC parts of ff_h261_rl_tcoeff. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/h261enc: Remove unused function parameterAndreas Rheinhardt2020-12-081-3/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* put_bits: make avpriv_align_put_bits() inlineAnton Khirnov2020-10-281-1/+1
| | | | | | | | | 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: Add FF_CODEC_CAP_INIT_CLEANUPLimin Wang2020-05-271-0/+1
| | | | | | | | | | then ff_mpv_encode_end() will be unnecessary in ff_mpv_encode_init() if it's failed. The FF_CODEC_CAP_INIT_CLEANUP flag is need for single thread, For multithread, it'll be cleanup still by AV_CODEC_CAP_FRAME_THREADS flag if have. Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'Clément Bœsch2016-06-211-1/+1
|\ | | | | | | | | | | | | * commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb': cosmetics: Fix spelling mistakes Merged-by: Clément Bœsch <u@pkh.me>
| * cosmetics: Fix spelling mistakesVittorio Giovara2016-05-041-1/+1
| | | | | | | | Signed-off-by: Diego Biurrun <diego@biurrun.de>
* | Merge commit '02b7c630875c0bc63cee5ec597aa33baf9bf4e20'Michael Niedermayer2015-07-091-1/+1
|\| | | | | | | | | | | | | | | | | | | | | * commit '02b7c630875c0bc63cee5ec597aa33baf9bf4e20': h261: Signal freeze picture release for intra frames Conflicts: tests/ref/vsynth/vsynth1-h261 tests/ref/vsynth/vsynth2-h261 Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * h261: Signal freeze picture release for intra framesStian Selnes2015-07-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Freeze picture release should be set to 1 when we're responding to a fast update request. For simplicity we set it for all intra frames, including those that starts a GOP. Fixes issue where Tandberg MXP1700 does not recover from packet loss state since it's waiting for the freeze picture relase indication. Bug-Id: 873 CC: libav-stable@libav.org Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
* | Merge commit 'dc1de0b958836545339611e9c050a1d4fdded263'Michael Niedermayer2015-07-091-2/+2
|\| | | | | | | | | | | | | | | | | | | | | * commit 'dc1de0b958836545339611e9c050a1d4fdded263': h261: Set 'still image mode off' in picture header Conflicts: tests/ref/vsynth/vsynth1-h261 tests/ref/vsynth/vsynth2-h261 Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * h261: Set 'still image mode off' in picture headerStian Selnes2015-07-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ref H.261 recommendation section 4.2.1.3, setting the still image flag to 1 disables still image mode. Some decoders require this in order to decode the bitstream as normal video. Fixes H.261 calls to Cisco E20. Also, reserved (aka spare) bits should be set to 1 unless specified otherwise. Bug-Id: 872 CC: libav-stable@libav.org Signed-off-by: Luca Barbato <lu_zero@gentoo.org>