aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mpegvideo_enc.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/mpegvideo_enc: Add check for av_packet_new_side_data()Jiasheng Jiang2024-07-021-0/+2
| | | | | | | | | Add check for av_packet_new_side_data() to avoid null pointer dereference if allocation fails. Fixes: bdc1220eeb ("h263enc: Add an option for outputting info about MBs as side data") Signed-off-by: Jiasheng Jiang <jiashengjiangcool@outlook.com> Signed-off-by: Anton Khirnov <anton@khirnov.net>
* avcodec/mpegvideo_enc: Constify pointers to static storageAndreas Rheinhardt2024-06-201-2/+1
| | | | | | | These must not be modified (even when they are initialized at runtime and therefore modifiable). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move quant_precision to Mpeg4DecContextAndreas Rheinhardt2024-06-201-2/+0
| | | | | | | | It is an MPEG-4-only value; it is always five for the MPEG-4 encoder, so just hardcode this value and move the MpegEncContext field to Mpeg4DecContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Unquantize coefficients while parsing themAndreas Rheinhardt2024-06-201-1/+1
| | | | | | | | | This is beneficial for performance: When concatenating the file from the vsynth1-h261 fate-test 100 times, performance (measured by timing the codec's decode callback) improved by 9.6%. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't update qscale unnecessarilyAndreas Rheinhardt2024-06-201-3/+3
| | | | | | The new value will be overwritten in ff_set_qscale() below. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Initialize qscale tab for all codecsAndreas Rheinhardt2024-06-201-3/+3
| | | | | | | Calling it is the first thing ff_clean_h263_qscales() and ff_clean_mpeg4_qscales() do anyway. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Only keep what is used from MECmpContextAndreas Rheinhardt2024-06-201-26/+33
| | | | | | | | | | A MECmpContext is quite big (792B here) and given how ff_update_duplicate_context() works, it is (unfortunately) copied quite frequently when using slice threading. Therefore keep only what is needed from MECmpContext and remove MECmpContext from MpegEncContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Avoid branch for sse vs nsse cmpAndreas Rheinhardt2024-06-201-12/+11
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/me_cmp, motion_est: Sanitize permissible cmp_funcsAndreas Rheinhardt2024-06-201-3/+3
| | | | | | | | | Several of the potential choices of comparison functions need an initialized MpegEncContext (initialized for encoding, not only ff_mpv_common_init()) or they crash when called. Modify ff_set_cmp() to check for this. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/me_cmp,dvenc,mpegvideo: Move ildct_cmp to its usersAndreas Rheinhardt2024-06-201-24/+25
| | | | | | | | | | | | MECmpContext.ildct_cmp is an array of function pointers that are not set by ff_me_cmp_init(), but that are set by users to one of the other arrays via ff_set_cmp(). Remove these pointers from MECmpContext and add pointers for the actually used functions to its users. (The DV encoder already did so.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/me_cmp, mpegvideo: Move frame_skip_cmp to MpegEncContextAndreas Rheinhardt2024-06-201-4/+6
| | | | | | | | | | | | | | | MECmpContext has several arrays of function pointers that are not set by ff_me_cmp_init(), but that are set by users to one of the other arrays via ff_set_cmp(). One of these other users is mpegvideo_enc; it is the only user of MECmpContext.frame_skip_cmp and it only uses one of these function pointers at all. This commit therefore moves this function pointer to MpegEncContext; and removes the array from MECmpContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/motion_est: Factor one-time initialization out of ff_init_meAndreas Rheinhardt2024-06-201-3/+16
| | | | | | | | | | The majority of the stuff performed in it needs to be done only once; so factor it out into a function of its own to be called in the user's init function. Also avoid using MpegEncContext in it, to separate the two a bit more. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Check for existence of ildct cmp functionsAndreas Rheinhardt2024-06-201-2/+8
| | | | | | | | Not all compare functions are implemented for all compare function types. Therefore check for the existence of the used functions. Fixes issue #10245. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Avoid excessive inliningAndreas Rheinhardt2024-06-201-4/+4
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Avoid branches for flipping no_roundingAndreas Rheinhardt2024-06-201-6/+4
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't pretend ff_dct_encode_init() can failAndreas Rheinhardt2024-06-121-3/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Remove fast_dct_quantizeAndreas Rheinhardt2024-06-121-1/+0
| | | | | | | | It has been added in 3a87ac948f0cd95218e62d5a98b8b8d5e4c11366, but there was never an implementation different from the ordinary dct_quantize of it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Always set c funcs in ff_dct_encode_init()Andreas Rheinhardt2024-06-121-4/+3
| | | | | | | | | Use the common approach whereby the _c versions are set first and then (potentially) overwritten by the arch-specific ones instead of calling the arch-specific code first, followed by setting the function pointers that have not already been set. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mips/mpegvideo: Set denoise_dct only for encoderAndreas Rheinhardt2024-06-121-1/+3
| | | | | | | | The C version is set in ff_dct_encode_init(), yet the MIPS version is set in dct_init() (in ff_mpv_common_init() and therefore also for decoders). This commit fixes this inconsistency. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Move initializing H263DSP to ituh263enc.cAndreas Rheinhardt2024-06-121-2/+0
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Make ff_dct_quantize_c() staticAndreas Rheinhardt2024-06-121-5/+8
| | | | | | Only used here. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Binarize referenceAndreas Rheinhardt2024-06-121-2/+1
| | | | | | | | | The H.264 decoder used reference to store its picture_structure into it; yet it does not use mpegvideo any more since commit 2c541554076cc8a72e7145d4da30389ca763f32f. Afterwards commit 629259bdb58061b7b7c1ae4cdc44599f6c0bb050 removed the last remnants. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Use enum for msmpeg4_versionAndreas Rheinhardt2024-06-121-11/+17
| | | | | | Improves readability. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Unify initializing PutBitContextsAndreas Rheinhardt2024-06-121-23/+19
| | | | | | | This also rids us of the requirement to preserve the PutBitContext in ff_update_duplicate_context(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Avoid MotionEstContext in ff_mpeg_framesize_alloc()Andreas Rheinhardt2024-06-121-2/+5
| | | | | | | | | | Only set the ScratchpadContext and let the users that need it (i.e. encoders) set the MotionEstContext stuff themselves. Also add an explicit pointer to ScratchpadContext to point to the allocated buffer so that none of the other scratchpad pointers is singled out as being used for the allocations. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Use ThreadProgress instead of ThreadFrame APIAndreas Rheinhardt2024-06-121-1/+1
| | | | | | | | | | | | Given that MPVPictures are already directly shared between threads in case of frame-threaded decoding, one can simply use it to pass decoding progress information between threads. This allows to avoid one level of indirection; it also means avoids allocations (of the ThreadFrameProgress structure) in case of frame-threading and indeed makes ff_thread_release_ext_buffer() decoder-only (actually, H.264-decoder-only). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Make MPVPicture refcountedAndreas Rheinhardt2024-06-121-33/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now, an initialized MpegEncContext had an array of MPVPictures (way more than were ever needed) and the MPVPicture* contained in the MPVWorkPictures as well as the input_picture and reordered_input_picture arrays (for the encoder) pointed into this array. Several of the pointers could point to the same slot and because there was no reference counting involved, one had to check for aliasing before unreferencing. Furthermore, given that these pointers were not ownership pointers the pointers were often simply reset without unreferencing the slot (happened e.g. for the RV30 and RV40 decoders) or there were moved without resetting the src pointer (happened for the encoders where the entries in the input_picture and reordered_input_picture arrays were not reset). Instead actually releasing these pictures was performed by looping over the whole array and checking which one of the entries needed to be kept. Given that the array had way too many slots (36), this meant that more than 30 MPVPictures have been unnecessarily unreferenced in every ff_mpv_frame_start(); something similar happened for the encoder. This commit changes this by making the MPVPictures refcounted via the RefStruct API. The MPVPictures itself are part of a pool so that this does not entail constant allocations; instead, the amount of allocations actually goes down, because the earlier code used such a large array of MPVPictures (36 entries) and allocated an AVFrame for every one of these on every ff_mpv_common_init(). In fact, the pool is only freed when closing the codec, so that reinitializations don't lead to new allocations (this avoids having to sync the pool in update_thread_context). Making MPVPictures refcounted also has another key benefit: It makes it possible to directly share them across threads (when using frame-threaded decoding), eliminating ugly code with underlying av_frame_ref()'s; sharing these pictures can't fail any more. The pool is allocated in ff_mpv_decode_init() for decoders, which therefore can fail now. This and the fact that the pool is not unreferenced in ff_mpv_common_end() also necessitated to mark several mpegvideo-decoders with the FF_CODEC_CAP_INIT_CLEANUP flag. *: This also means that there is no good reason any more for ff_mpv_common_frame_size_change() to exist. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: ReindentationAndreas Rheinhardt2024-06-121-97/+96
| | | | | | Also try to use loop-scope for iterators. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Return early when getting length of B frame chainAndreas Rheinhardt2024-06-121-2/+4
| | | | | | Possible now that this is a function of its own. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Factor setting length of B frame chain outAndreas Rheinhardt2024-06-121-8/+25
| | | | | | | It already avoids a goto and will be useful in the future to be able to specify each functions tasks and obligations. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Split MPVPicture into WorkPicture and ordinary PicAndreas Rheinhardt2024-06-121-64/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two types of MPVPictures: Three (cur_pic, last_pic, next_pic) that are directly part of MpegEncContext and an array of MPVPictures that are separately allocated and are mostly accessed via pointers (cur|last|next)_pic_ptr; they are also used to store AVFrames in the encoder (necessary due to B-frames). As the name implies, each of the former is directly associated with one of the _ptr pointers: They actually share the same underlying buffers, but the ones that are part of the context can have their data pointers offset and their linesize doubled for field pictures. Up until now, each of these had their own references; in particular, there was an underlying av_frame_ref() to sync cur_pic and cur_pic_ptr etc. This is wasteful. This commit changes this relationship: cur_pic, last_pic and next_pic now become MPVWorkPictures; this structure does not have an AVFrame at all any more, but only the cached values of data and linesize. It also contains a pointer to the corresponding MPVPicture, establishing a more natural relationsship between the two. This already means that creating the context-pictures from the pointers can no longer fail. What has not been changed is the fact that the MPVPicture* pointers are not ownership pointers and that the MPVPictures are part of an array of MPVPictures that is owned by a single AVCodecContext. Doing so will be done in a latter commit. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Rename Picture->MPVPictureAndreas Rheinhardt2024-06-121-3/+3
| | | | | | Picture is just too generic. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Move copying properties to alloc_picture()Andreas Rheinhardt2024-06-121-11/+11
| | | | | | | | This way said function sets everything (except for the actual contents of the frame's data). Also rename it to prepare_picture() given its new role. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Pass AVFrame*, not Picture* to alloc_picture()Andreas Rheinhardt2024-06-121-12/+12
| | | | | | It now only deals with the AVFrame and no longer with the accessories. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Split ff_alloc_picture() into check and alloc partAndreas Rheinhardt2024-06-121-31/+26
| | | | | | | | | | | | ff_alloc_picture() currently does two things: It checks the consistency of the linesize (which should not be necessary, but is) and it allocates certain buffers. (It does not actually allocate the picture buffers, so its name is misleading.) This commit splits it into two separate functions. The rationale for this is that for the encoders, every picture needs its linesizes checked, but not every picture needs these extra buffers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Add const where appropriateAndreas Rheinhardt2024-06-121-3/+3
| | | | | | | | 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/rv30, rv34, rv40: Avoid indirectionAndreas Rheinhardt2024-06-121-1/+1
| | | | | | | | Use the cached values from MpegEncContext.(cur|last|next)_pic instead of the corresponding *_pic_ptr. Also do the same in wmv2dec.c and mpegvideo_enc.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Cache AVFrame.data and linesize valuesAndreas Rheinhardt2024-06-121-8/+8
| | | | | | | This avoids an indirection and is in preparation for removing the AVFrame from MpegEncContext.(cur|last|next)_pic altogether. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Reduce value of MAX_PLANES defineAndreas Rheinhardt2024-06-121-4/+3
| | | | | | | No mpegvideo based codec supports alpha. While just at it, also make the define shorter. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Shorten variable namesAndreas Rheinhardt2024-06-121-93/+89
| | | | | | | | current_picture->cur_pic, last_picture->last_pic, similarly for new_picture and next_picture. Also rename the corresponding *_ptr fields. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h263: Move encoder-only part out of ff_h263_update_motion_val()Andreas Rheinhardt2024-06-121-2/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo, mpegpicture: Add buffer poolAndreas Rheinhardt2024-06-121-6/+7
| | | | | | | | | | | | | This avoids constant allocations+frees and will also allow to simply switch to the RefStruct API, thereby avoiding the overhead of the AVBuffer API. It also simplifies the code, because it removes the "needs_realloc" field: It was added in 435c0b87d28b48dc2e0360adc404a0e2d66d16a0, before the introduction of the AVBuffer API: given that these buffers may be used by different threads, they were not freed immediately and instead were marked as being freed later by setting needs_realloc. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo, ratecontrol: Remove write-only skip_countAndreas Rheinhardt2024-06-121-4/+0
| | | | | | Write-only since 6cf0cb8935f515a7b5f79d2e3cf02bd0764943bf. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ratecontrol: Pass RCContext directly in ff_rate_control_uninit()Andreas Rheinhardt2024-06-121-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: give magic number a nameRamiro Polla2024-06-051-1/+1
|
* avcodec/mpegvideo_enc: Fix potential overflow in RDMichael Niedermayer2024-05-191-2/+2
| | | | | | | Fixes: CID1500285 Unintentional integer overflow Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* libavcodec/mpegvideo_enc: fix multi-threaded motion estimation rounding for ↵Ramiro Polla2024-05-111-3/+3
| | | | | | | | | | | | | mpeg4 ff_init_me() was being called after ff_update_duplicate_context(), which caused the propagation of the initialization to other thread contexts to be delayed by one frame. In the case of mpeg4 (or flipflop_rounding), this would make the hpel_put functions differ between the first thread (which would be correctly initialized) and the other threads (which would be stale from the previous frame).
* avcodec/mpegvideo_enc: Fix 1 line and one column imagesMichael Niedermayer2024-05-061-2/+2
| | | | | | Fixes: Ticket10952 Fixes: poc21ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/mpegvideo_enc: Don't update current_picture unnecessarilyAndreas Rheinhardt2024-04-081-1/+0
| | | | | | | | current_picture is not changed after frame_start() at all and it therefore does not need to be updated (i.e. copied to the slice thread contexts) a second time. 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>