aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mpv_reconstruct_mb_template.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/mpv_reconstruct_mb_template: Merge template into its usersAndreas Rheinhardt2025-02-231-272/+0
| | | | | | | | A large part of this template is decoder-only. This makes the complexity of the IS_ENCODER-checks not worth it. So simply merge the template into both its users. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_enc: Don't reset intra buffers in mpv_reconstruct_mb()Andreas Rheinhardt2025-02-231-9/+0
| | | | | | It is not part of reconstructing the macroblock. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h263dec: Clean intra tables in decoder, not ff_mpv_reconstruct_mbAndreas Rheinhardt2025-02-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | This is a more appropriate place than a function designed to reconstruct a macroblock. It furthermore limits these checks to the codecs that actually need it (and removes it from e.g. RV10 and RV20 -- the latter actually uses these buffers, but only for intra-frames, so they don't need to be cleaned manually). This furthermore means that ff_mpv_reconstruct_mb() and therefore also the error-resilience code no longer needs block_index set. This fixes a crash caused by 65d5ccb808ec93de46a2458ea8cc082ce4460f34 when ff_mpv_reconstruct_mb() is called by VC-1 code without block_index being initialized properly (VC-1 uses and initializes block_index itself normally). Fixes: 69814/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VC1_fuzzer-4868081575329792 Fixes: heap-buffer-overflow Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg12enc: Move resetting last_dc to encoderAndreas Rheinhardt2025-02-231-4/+0
| | | | | | | | The MPEG-1/2 encoders are the only non-intra-only mpegvideo encoders that want last_dc reset when encoding non-intra macroblocks. Therefore move resetting it to mpeg12enc.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg12dec: Move resetting last_dc to decoderAndreas Rheinhardt2025-02-231-1/+1
| | | | | | | | | | | | | | | | | | Only the MPEG-1/2, MSMPEG4V1, MPEG-4 and RV.10 decoders use last_dc at all. Of these, RV.10 only uses it for intra frames; it does not need these predictors reset in ff_mpv_reconstruct_mb(). MSMPEG4V1 has h263_pred set, so that last_dc is already not reset in ff_mpv_reconstruct_mb() (instead it is reset at the beginning of every line). MPEG-4 also has h263_pred set (and uses last_dc only for the intra-only studio profile and needs them reset to sligthly different values anyway). So only the MPEG-1/2 decoders need these values reset. So move resetting them there. This avoids resetting them unnecessarily for FLV1, H.261, H.263I, RV.10, RV.20 and H.263(+) (for the latter it depends upon whether h263_aic is in use). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Unquantize coefficients while parsing themAndreas Rheinhardt2024-06-201-12/+12
| | | | | | | | | 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/mpv_reconstruct_mb_template: Optimize WMV2 code away if possibleAndreas Rheinhardt2024-06-201-1/+1
| | | | | | | The WMV2 decoder does not support lowres, so one can optimize the WMV2 specific code away in the lowres version of this function. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpv_reconstruct_mb_template: Optimize always-true branch awayAndreas Rheinhardt2024-06-201-1/+2
| | | | | | | | | | There are only two mpegvideo decoders that use another (software) pixel format than YUV420: MPEG-1/2 and the MPEG-4 studio profile. Neither of these use this part of the code, so one can optimize the 422 code away when this code is compiled for the decoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy dataAndreas Rheinhardt2024-06-201-21/+2
| | | | | | | | | | There is no reason to use a temporary buffer as destination for the new macroblock before copying it into its proper place. (Originally, this has been added in commit b68ab2609c67d07b6f12ed65125d76bf9a054479 due to concerns about copying from GPU memory.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Use enum for msmpeg4_versionAndreas Rheinhardt2024-06-121-1/+1
| | | | | | Improves readability. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Use ThreadProgress instead of ThreadFrame APIAndreas Rheinhardt2024-06-121-4/+4
| | | | | | | | | | | | 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: Split MPVPicture into WorkPicture and ordinary PicAndreas Rheinhardt2024-06-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/mpegvideo: Add const where appropriateAndreas Rheinhardt2024-06-121-2/+2
| | | | | | | | 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/mpegpicture: Cache AVFrame.data and linesize valuesAndreas Rheinhardt2024-06-121-6/+6
| | | | | | | 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/mpegvideo: Shorten variable namesAndreas Rheinhardt2024-06-121-10/+10
| | | | | | | | 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/mpegvideo_dec: Don't use MotionEstContext as scratch spaceAndreas Rheinhardt2022-11-061-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Decoders that might use quarter pixel motion estimation (namely MPEG-4 as well as the VC-1 family) currently use MpegEncContext.me.qpel_(put|avg) as scratch space for pointers to arrays of function pointers. (MotionEstContext contains such pointers as it supports quarter pixel motion estimation.) The MotionEstContext is unused apart from this for the decoding part of mpegvideo. Using the context at all is for decoding is actually unnecessary and easily avoided: All codecs with quarter pixels set me.qpel_avg to qdsp.avg_qpel_pixels_tab, so one can just unconditionally use this in ff_mpv_reconstruct_mb(). MPEG-4 sets qpel_put to qdsp.put_qpel_pixels_tab or to qdsp.put_no_rnd_qpel_pixels_tab based upon whether the current frame is a b-frame with no_rounding or not, while the VC-1-based decoders set it to qdsp.put_qpel_pixels_tab unconditionally. Given that no_rounding is always zero for VC-1, using the same check for VC-1 as well as for MPEG-4 would work. Since ff_mpv_reconstruct_mb() already has exactly the right check (for hpeldsp), it can simply be reused. (This change will result in ff_mpv_motion() receiving a pointer to an array of NULL function pointers instead of a NULL pointer for codecs without qpeldsp (like MPEG-1/2). It doesn't matter.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpv_reconstruct_mb_template: Optimize dead code awayAndreas Rheinhardt2022-10-201-1/+2
| | | | | | | None of the MPEG-1/2 codecs support frame threading, so one can optimize the check for it away. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Split ff_mpv_reconstruct_mb() into de/encoder partAndreas Rheinhardt2022-10-201-0/+300
This has the advantage of not having to check for whether a given MpegEncContext is actually a decoder or an encoder context at runtime. To do so, mpv_reconstruct_mb_internal() is moved into a new template file that is included by both mpegvideo_enc.c and mpegvideo_dec.c; the decoder-only code (mainly lowres) are also moved to mpegvideo_dec.c. The is_encoder checks are changed to #if IS_ENCODER in order to avoid having to include headers for decoder-only functions in mpegvideo_enc.c. This approach also has the advantage that it is easy to adapt mpv_reconstruct_mb_internal() to using different structures for decoders and encoders (e.g. the check for whether a macroblock should be processed for the encoder or not uses MpegEncContext elements that make no sense for decoders and should not be part of their context). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>