summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo.c
Commit message (Collapse)AuthorAge
* 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>
* avcodec/utils: Unavpriv avpriv_toupper4()Andreas Rheinhardt2022-01-04
| | | | | | | | | | | | | | | | This function is quite small (96B with GCC 11.2 on x64 Ubuntu 21.10 at -O3), making it more economical to duplicate it into libavformat instead of exporting it as avpriv: Doing so saves 2x24B in .dynsim, 2x16B in .dynstr, 2x2B .gnu.version, 24B in .rela.plt, 16B in .plt, 16B in .plt.sec (if enabled), 4B .gnu.hash; besides the actual duplicated code this also adds 2x8B .eh_frame_hdr and 24B .eh_frame. In other words: Duplicating is neutral size-wise (it is also presumed neutral for other systems). Given that it avoids the runtime overhead of dynamic symbols, it is advantageouos to duplicate the function. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: ReindentationAndreas Rheinhardt2021-12-17
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Allocate several buffers jointlyAndreas Rheinhardt2021-12-17
| | | | | | Reduces the amount of allocations and frees. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't allocate encoder-only buffers when decodingAndreas Rheinhardt2021-12-17
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't update encoder-only fields for decodersAndreas Rheinhardt2021-12-17
| | | | | | ff_mpeg_update_thread_context() is only used by decoders. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move closed_gop to Mpeg1ContextAndreas Rheinhardt2021-12-17
| | | | | | Only used there and only by the main thread. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: remove the unused low_delayLimin Wang2021-09-29
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* lavc: deprecate AV_CODEC_(FLAG|CAP)_TRUNCATEDAnton Khirnov2021-09-20
| | | | | | | | | | It is supported only by a few decoders (h263, h263p, mpeg(1|2|)video and mpeg4) and is entirely redundant with parsers. Furthermore, using it leads to missing frames, as flushing the decoder at the end does not work properly. Co-authored-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/rv34, mpegvideo: Fix segfault upon frame size change errorAndreas Rheinhardt2021-04-08
| | | | | | | | | | | | | | | | | | | | | The RealVideo 3.0 and 4.0 decoders call ff_mpv_common_init() only during their init function and not during decode_frame(); when the size of the frame changes, they call ff_mpv_common_frame_size_change(). Yet upon error, said function calls ff_mpv_common_end() which frees the whole MpegEncContext and not only those parts that ff_mpv_common_frame_size_change() reinits. As a result, the context will never be usable again; worse, because decode_frame() contains no check for whether the context is initialized or not, it is presumed that it is initialized, leading to segfaults. Basically the same happens if rv34_decoder_realloc() fails. This commit fixes this by only resetting the parts that ff_mpv_common_frame_size_change() changes upon error and by actually checking whether the context is in need of reinitialization in ff_rv34_decode_frame(). Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Factor common freeing code outAndreas Rheinhardt2021-04-08
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mpegvideo: Fix memleak upon allocation errorAndreas Rheinhardt2021-04-08
| | | | | | | | | | | | | | | | | | | | | | | | | When slice-threading is used, ff_mpv_common_init() duplicates the first MpegEncContext and allocates some buffers for each MpegEncContext (the first as well as the copies). But the count of allocated MpegEncContexts is not updated until after everything has been allocated and if an error happens after the first one has been allocated, only the first one is freed; the others leak. This commit fixes this: The count is now set before the copies are allocated. Furthermore, the copies are now created and initialized before the first MpegEncContext, so that the buffers exclusively owned by each MpegEncContext are still NULL in the src MpegEncContext so that no double-free happens upon allocation failure. Given that this effectively touches every line of the init code, it has also been factored out in a function of its own in order to remove code duplication with the same code in ff_mpv_common_frame_size_change() (which was never called when using more than one slice (and if it were, there would be potential double-frees)). Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* Revert "avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ↵Andreas Rheinhardt2021-04-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ff_mpv_common_init()" This mostly reverts commit 4b2863ff01b1fe93d9a518523c9098d17a9d8c6f. Said commit removed the freeing code from ff_mpv_common_init(), ff_mpv_common_frame_size_change() and ff_mpeg_framesize_alloc() and instead added the FF_CODEC_CAP_INIT_CLEANUP to several codecs that use ff_mpv_common_init(). This introduced several bugs: a) Several decoders using ff_mpv_common_init() in their init function were forgotten: This affected FLV, Intel H.263, RealVideo 3.0 and V4.0 as well as VC-1/WMV3. b) ff_mpv_common_init() is not only called from the init function of codecs, it is also called from AVCodec.decode functions. If an error happens after an allocation has succeeded, it can lead to memleaks; furthermore, it is now possible for the MpegEncContext to be marked as initialized even when ff_mpv_common_init() returns an error and this can lead to segfaults because decoders that call ff_mpv_common_init() when decoding a frame can mistakenly think that the MpegEncContext has been properly initialized. This can e.g. happen with H.261 or MPEG-4. c) Removing code for freeing from ff_mpeg_framesize_alloc() (which can't be called from any init function) can lead to segfaults because the check for whether it needs to allocate consists of checking whether the first of the buffers allocated there has been allocated. This part has already been fixed in 76cea1d2ce3f23e8131c8664086a1daf873ed694. d) ff_mpv_common_frame_size_change() can also not be reached from any AVCodec.init function; yet the changes can e.g. lead to segfaults with decoders using ff_h263_decode_frame() upon allocation failure, because the MpegEncContext will upon return be flagged as both initialized and not in need of reinitialization (granted, the fact that ff_h263_decode_frame() clears context_reinit before the context has been reinited is a bug in itself). With the earlier version, the context would be cleaned upon failure and it would be attempted to initialize the context again in the next call to ff_h263_decode_frame(). While a) could be fixed by adding the missing FF_CODEC_CAP_INIT_CLEANUP, keeping the current approach would entail adding cleanup code to several other places because of b). Therefore ff_mpv_common_init() is again made to clean up after itself; the changes to the wmv2 decoder and the SVQ1 encoder have not been reverted: The former fixed a memleak, the latter allowed to remove cleanup code. Fixes: double free Fixes: ff_free_picture_tables.mp4 Fixes: ff_mpeg_update_thread_context.mp4 Fixes: decode_colskip.mp4 Fixes: memset.mp4 Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mpegvideo: Update chroma_?_shift in ff_mpv_common_frame_size_change()Michael Niedermayer2021-03-31
| | | | | | | | Fixes: out of array access Fixes: 31201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-4627865612189696.fuzz Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* mpegvideo: use the AVVideoEncParams API for exporting QP tablesAnton Khirnov2021-01-01
| | | | | | | | | | Do it only when requested with the AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS flag. Drop previous code using the long-deprecated AV_FRAME_DATA_QP_TABLE* API. Temporarily disable fate-filter-pp, fate-filter-pp7, fate-filter-spp. They will be reenabled once these filters are converted in following commits.
* avcodec/mpegvideo: Don't zero-initialize unnecessarilyAndreas Rheinhardt2020-12-31
| | | | | | | mbintra_table will be memset to 1 a few lines after its allocation. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mpegvideo: Merge ff_mpv_decode_defaults into ff_mpv_decode_initAndreas Rheinhardt2020-12-31
| | | | | | | | | | | | | These two are always called directly after each other (with the exception of the calls in mpeg_decode_init() where some irrelevant modifications of the avctx (which could just as well be done before ff_mpv_decode_defaults(), because it doesn't have a pointer to the AVCodecContext at all and therefore can't see these modifications at all) are performed in between), so merge ff_mpv_decode_defaults() in ff_mpv_decode_init(). Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/mpegvideo: remove extra spaceLimin Wang2020-06-14
| | | | | Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avcodec/mpegvideo: remove FF_ALLOCZ_ARRAY_OR_GOTO and gotos labelLimin Wang2020-06-13
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avcodec/mpegvideo: simplify check for av_frame_allocLimin Wang2020-06-13
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ↵Limin Wang2020-06-13
| | | | | | ff_mpv_common_init() Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avcodec/mpegvideo: return more specific error codes for init_duplicate_context()Limin Wang2020-05-09
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avcodec/mpegvideo: return more specific error codes for ff_mpv_common_init()Limin Wang2020-05-09
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* mpegvideo: drop an unnecessary function parameterAnton Khirnov2020-03-16
| | | | It is always 0.
* libavcodec, libpostproc: Remove outcommented START/STOP_TIMERAndreas Rheinhardt2020-03-14
| | | | | | | as well as includes of libavutil/timer.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>