summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo.c
Commit message (Collapse)AuthorAge
* avcodec/pthread_frame: Remove ff_thread_release_buffer()Andreas Rheinhardt2023-10-22
| | | | | | | | | | | | | | It is unnecessary since the removal of non-thread-safe callbacks in e0786a8eeb9e7c8feb057e83f284491f0a87e463. Since then, the AVCodecContext has only been used as logcontext. Removing ff_thread_release_buffer() allowed to remove AVCodecContext* parameters from several other functions (not only unref functions, but also e.g. ff_h264_ref_picture() which calls ff_h264_unref_picture() on error). Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move allocating new_picture to the encoderAndreas Rheinhardt2023-10-06
| | | | | | | | It is only used by encoders; this unfortunately necessitated to add separate allocations to the SVQ1 encoder which uses motion estimation without being a full member of mpegvideo. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: remove FF_API_FLAG_TRUNCATEDJames Almer2023-02-09
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/mpegvideo: Remove incorrect commentAndreas Rheinhardt2022-10-29
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Remove always-false checkAndreas Rheinhardt2022-10-29
| | | | | | | | | | | | | | | | This basically reverts cc0380222add8df8ff9b3bd95eaf2b9d8c4c0d11. At the time of said commit, cleanup on init failure was very buggy. For codecs with the INIT_CLEANUP cap, the close function could be called on error even before the private data has been allocated; and when using frame threading the same could also happen even without said flag. Some mpegvideo decoders were affected by the latter. Yet both of these issues have been fixed long ago, the latter in commit e9b66175793e5c2af19beefe8e143f6e4901b5df. Therefore the workaround in ff_mpv_common_end() can be removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Allocate map and score_map buffers jointlyAndreas Rheinhardt2022-10-29
| | | | | | Reduces the amounts of allocs, frees and allocation checks. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't overallocate bufferAndreas Rheinhardt2022-10-29
| | | | | | | | | Only encoders need two sets of int16_t [12][64] (one to save the current best state and one for the current working state); decoders need only one. This saves 1.5KiB per slice context for a decoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't initialize H264Chroma ctx unnecessarilyAndreas Rheinhardt2022-10-27
| | | | | | | It is only used by the decoders' lowres code, so only initialize it for decoders. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't use ScanTable where unnecessaryAndreas Rheinhardt2022-10-24
| | | | | | | | | For the intra_[hv]_scantables, only ScanTable.permutated is used, so one only needs to keep that. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Reviewed-by: Peter Ross <pross@xvid.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/idctdsp: Move ScanTable to mpegvideoAndreas Rheinhardt2022-10-24
| | | | | | | Only used there. Reviewed-by: Peter Ross <pross@xvid.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideodsp: Make MpegVideoDSP MPEG-4 onlyAndreas Rheinhardt2022-10-20
| | | | | | | | It is only used by gmc/gmc1 which is only used by the MPEG-4 decoder, so move it to Mpeg4DecContext and rename it to Mpeg4VideoDSP. Also compile it iff the MPEG-4 decoder is compiled. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Split ff_mpv_reconstruct_mb() into de/encoder partAndreas Rheinhardt2022-10-20
| | | | | | | | | | | | | | | | | | | | | | 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>
* avcodec/mpegvideo: Inline is_encoder in mpv_reconstruct_mb_internal()Andreas Rheinhardt2022-10-20
| | | | | | | | | | | | | | | | | | Up until now, we inlined lowres_flag as well as is_mpeg12 independently (unless CONFIG_SMALL was true); this commit changes this to instead inline mpv_reconstruct_mb_internal() (at most) four times, namely once for encoders, once for decoders using lowres and once for non-lowres mpeg-1/2 decoders and once for non-lowres non-mpeg-1/2 decoders (mpeg-1/2 is not inlined in case of CONFIG_SMALL). This is neutral performance-wise, but proved beneficial size-wise: It saved 1776B of .text for GCC 11 or 1344B for Clang 14 (both -O3 x64). Notice that inlining is_mpeg12 for is_encoder would not really be beneficial, as the encoder codepath does mostly not depend on is_mpeg12 at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Make inlining is_mpeg12 more flexibleAndreas Rheinhardt2022-10-20
| | | | | | | | | | | | | | | | | | | | | | | | | | There are two types of checks for whether the current codec is MPEG-1/2 in mpv_reconstruct_mb_internal(): Those that are required for correctness and those that are not; an example of the latter is "is_mpeg12 || (s->codec_id != AV_CODEC_ID_WMV2)". The reason for the existence of such checks is that mpv_reconstruct_mb_internal() has the av_always_inline attribute and is_mpeg12 is usually inlined, so that in case we are dealing with MPEG-1/2 the above check can be completely optimized away. But is_mpeg12 is not always inlined: it is not in case CONFIG_SMALL is true in which case is_mpeg12 is always zero, so that the checks required for correctness need to check out_format explicitly. This is currently done via a macro in mpv_reconstruct_mb_internal(), so that the fact that it is CONFIG_SMALL that determines this is encoded at two places. This commit changes this by making is_mpeg12 a three-state: DEFINITELY_MPEG12, MAY_BE_MPEG12 and NOT_MPEG12. In the second case, one has to resort to check out_format, in the other cases is_mpeg12 can be taken at face-value. This will allow to make inlining is_mpeg12 more flexible in a future commit. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Ignore skip_idct for encodersAndreas Rheinhardt2022-10-20
| | | | | | It is documented to be unused for encoders. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Reindent after the last commitAndreas Rheinhardt2022-10-20
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't check for draw_horiz_bandAndreas Rheinhardt2022-10-20
| | | | | | | | | | | | | | | | | | Some parts of mpegvideo.c behave differently depending upon whether AVCodecContext.draw_horiz_band is set or not. This differing behaviour makes lots of FATE tests fail and leads to garbage output, although setting this callback is not supposed to change the output at all. These checks have been added in commits 3994623df2efd2749631c3492184dd8d4ffa9d1b and b68ab2609c67d07b6f12ed65125d76bf9a054479. The commit messages do not contain a real reason for adding the checks and it is indeed a mystery to me. But removing these checks fixes the FATE tests when one adds an (empty) draw_horiz_band when using a codec that claims to support it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Fix undefined left shift of negative numbersAndreas Rheinhardt2022-09-30
| | | | | | | Fixes the rv20-1239 FATE-test. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/blockdsp: Remove unused AVCodecContext parameterAndreas Rheinhardt2022-09-21
| | | | | | | Possible since be95df12bb06b183c8d2aea3b0831fdf05466cf3. Reviewed-by: Rémi Denis-Courmont <remi@remlab.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Allocate encoder-only tables in mpegvideo_enc.cAndreas Rheinhardt2022-08-21
| | | | | | | | | | | | | | | This commit moves the encoder-only allocations of the tables owned solely by the main encoder context to mpegvideo_enc.c. This avoids checks in mpegvideo.c for whether we are dealing with an encoder; it also improves modularity (if encoders are disabled, this code will no longer be included in the binary). And it also avoids having to reset these pointers at the beginning of ff_mpv_common_init() (in case the dst context is uninitialized, ff_mpeg_update_thread_context() simply copies the src context into dst which therefore may contain pointers not owned by it, but this does not happen for encoders at all). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't zero unnecessarilyAndreas Rheinhardt2022-08-15
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move setting mb_height to ff_mpv_init_context_frameAndreas Rheinhardt2022-08-10
| | | | | | | | | | | It is the proper place to set it, directly besides mb_width and mb_stride. The reason for doing it the way it is done now seems to be that the code does not create more slice contexts than necessary (i.e. not more than one per row), so that this number needs to be known before setting the number of slices. But this can always be arranged by just moving the code that sets the number of slices. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_motion: Constify ff_mpv_motionAndreas Rheinhardt2022-08-05
| | | | | | | | | | | | Also constify the corresponding code in mpegvideo.c that handles lowres. (Unfortunately, not everything that is const could be constified: ref_picture could be made const uint8_t* const* if C allowed the safe automatic conversion from uint8_t**; and pix_op, qpix_op could be made to point to const function pointers, but C's handling of const in pointers to arrays is broken.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* all: Replace if (ARCH_FOO) checks by #if ARCH_FOOAndreas Rheinhardt2022-06-15
| | | | | | | | | | | | | | | | | | This is more spec-compliant because it does not rely on dead-code elimination by the compiler. Especially MSVC has problems with this, as can be seen in https://ffmpeg.org/pipermail/ffmpeg-devel/2022-May/296373.html or https://ffmpeg.org/pipermail/ffmpeg-devel/2022-May/297022.html This commit does not eliminate every instance where we rely on dead code elimination: It only tackles branching to the initialization of arch-specific dsp code, not e.g. all uses of CONFIG_ and HAVE_ checks. But maybe it is already enough to compile FFmpeg with MSVC with whole-programm-optimizations enabled (if one does not disable too many components). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Make new_picture an ordinary AVFrameAndreas Rheinhardt2022-04-01
| | | | | | | | | It is currently a "Picture", an mpegvideo-specific type that has a lot of baggage, all of which is unnecessary for new_picture, because only its embedded AVFrame is ever used. So just use an ordinary AVFrame. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* configure: Use a separate config_components.h header for $ALL_COMPONENTSMartin Storsjö2022-03-16
| | | | | | | | This avoids unnecessary rebuilds of most source files if only the list of enabled components has changed, but not the other properties of the build, set in config.h. Signed-off-by: Martin Storsjö <martin@martin.st>
* lavc/mpeg*: drop the XvMC hwaccel codeAnton Khirnov2022-02-15
| | | | | XvMC was last relevant over 10 years ago, if ever. There is no reason to use it today.
* avcodec/mpegvideo: Constify src of ff_update_duplicate_context()Andreas Rheinhardt2022-02-13
| | | | | | | Also do the same for update_duplicate_context_after_me() in mpegvideo_enc.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4video.h: Move decoder-only parts to a new headerAndreas Rheinhardt2022-02-13
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/wmv2.h: Move encoder- and decoder-only parts to new headersAndreas Rheinhardt2022-02-13
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/thread: Move ff_thread_(await|report)_progress to new headerAndreas Rheinhardt2022-02-09
| | | | | | | | | | This is in preparation for further commits that will stop using ThreadFrame for frame-threaded codecs that don't use ff_thread_(await|report)_progress(); the API for those codecs having inter-frame depdendencies will live in threadframe.h. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Add function to completely free MPEG-PictureAndreas Rheinhardt2022-01-29
| | | | | | | | | Also use said function in mpegvideo.c and mpegvideo_enc.c; and make ff_free_picture_tables() static as it isn't needed anymore outside of mpegpicture.c. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move MPEG-4 Simple Studio Profile fields to mpeg4videoAndreas Rheinhardt2022-01-29
| | | | | | | | | | This is possible now that dealing with the Simple Studio Profile has been moved to mpeg4videodec.c. It also allows to avoid allocations, because one can simply put the required buffers on the context (if one made these buffers part of MpegEncContext, the memory would be wasted for every codec other than MPEG-4). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move handling Simple Studio Profile to mpeg4videodecAndreas Rheinhardt2022-01-29
| | | | | | This is its only user. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Fix crash when using lowres with 10bit MPEG-4Andreas Rheinhardt2022-01-29
| | | | | | | | | | | | | | In this case the macroblocks written to are smaller, yet the MPEG-4 Simple Studio Profile code for 10bit DPCM ignored this; e.g. in case of lowres = 2 or = 3, the sample mpeg4_sstp_dpcm.m4v from the FATE-suite reads beyond the end of the buffer. This commit fixes this by taking lowres into account. The DPCM macroblocks of the aforementioned sample look as good as can be expected after this patch; yet the non-DPCM coded macroblocks are simply corrupt. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Fix off-by-one error when decoding >8 bit MPEG-4Andreas Rheinhardt2022-01-29
| | | | | | | | Fixes visual corruptions on two macroblocks from two frames from https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket4447/A003C003_SR_422_23.98p.mxf Reviewed-by: Kieran Kunhya <kierank@obe.tv> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Avoid macro/av_calloc for ordinary allocationsAndreas Rheinhardt2022-01-09
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't unnecessarily allocate buffersAndreas Rheinhardt2022-01-09
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* configure: Add new mpegvideodec CONFIG_EXTRAAndreas Rheinhardt2022-01-04
| | | | | | | | | | | | This allows to remove the spurious dependencies of mpegvideo encoders on error_resilience; some other components that do not use mpegvideo to its fullest turned out to not need it either. Adding a new CONFIG_EXTRA needs a reconfigure to take effect. In order to force this a few unnecessary headers from lavfi/allfilters.c have been removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move decoding-only code into a new fileAndreas Rheinhardt2022-01-04
| | | | | | | This will allow to disable this code altogether when all decoders are disabled. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Remove always-false checkAndreas Rheinhardt2022-01-04
| | | | | | | | | | An AVCodecContext's private data is always allocated in avcodec_open2() and calling avcodec_flush_buffers() on an unopened AVCodecContext (or an already closed one) is not allowed (and will crash before the decoder's flush function is even called). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't initialize error resilience context for encoderAndreas Rheinhardt2022-01-04
| | | | | | It is only used for decoders. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Check for no_rounding at compile-time if possibleAndreas Rheinhardt2022-01-04
| | | | | | | | It is partially possible if it is inlined whether we deal with MPEG-1/2, because no_rounding is never set for MPEG-1/2. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Remove always-true branchAndreas Rheinhardt2022-01-04
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Try to perform check for MPEG-1/2 at compile-timeAndreas Rheinhardt2022-01-04
| | | | | | This is possible if CONFIG_SMALL is not true. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Partially check for being encoder at compile-timeAndreas Rheinhardt2022-01-04
| | | | | | | | | | | | Whether lowres is in use or not is inlined in mpv_reconstruct_mb_internal(), so one can use the fact that lowres is always zero during encoding to evaluate the checks for whether one is encoding or not at compile-time when one is in lowres mode. Also reorder the main check to check for whether it is an encoder first to shortcircuit it in the common case of a decoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't check for > 8 bit MPEG-1/2Andreas Rheinhardt2022-01-04
| | | | | | It doesn't exist. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Avoid needlessly calling functionAndreas Rheinhardt2022-01-04
| | | | | | | | The very first check in this if-else if-else if construct is "if (s->encoding ||", i.e. in case of the WMV2 encoder the else branches are never executed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't duplicate identical codeAndreas Rheinhardt2022-01-04
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Remove unnecessary headersAndreas Rheinhardt2022-01-04
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>