summaryrefslogtreecommitdiffstats
path: root/libavcodec/mpeg4videodec.c
Commit message (Collapse)AuthorAgeFilesLines
...
* avcodec/mpeg4videodec: Don't initialize unused stuffAndreas Rheinhardt2024-06-201-15/+2
| | | | | | Only the intra scantable is used for studio profile. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: Inline constantsAndreas Rheinhardt2024-06-201-4/+2
| | | | | | Partitioned macroblocks are always 8bit and not studio profile. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: Use VLC symbol tableAndreas Rheinhardt2024-06-201-5/+5
| | | | | | | Possible now that MB_TYPE_L1 (which does not fit into an int16_t) is no longer used). Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideoAndreas Rheinhardt2024-06-201-28/+25
| | | | | | | | | | | | | | | | | | | MB_TYPE_L[01] is based upon H.264 terminology (it stands for list); yet the mpegvideo based decoders don't have lists of reference frames, they have at most one forward and one backward reference. So use terminology based upon this. This also has a second advantage: MB_TYPE_L[01] is actually an OR of two flags (which are set independently for H.264, but aren't for mpegvideo). Switching to different flags makes the flags fit into an int16_t, which will be useful in future commits. The only downside to this is a very small amount of code in error_resilience.c and mpegutils.c (the only code shared between the H.264 decoder and mpegvideo). Signed-off-by: Andreas Rheinhardt <[email protected]>
* 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 <[email protected]>
* avcodec/mpegpicture: Make MPVPicture refcountedAndreas Rheinhardt2024-06-121-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <[email protected]>
* avcodec/mpegvideo_dec: Add close function for mpegvideo-decodersAndreas Rheinhardt2024-06-121-1/+1
| | | | | | | Currently identical to the H.261 and H.263 close functions (which it replaces). It will be extended in future commits. Signed-off-by: Andreas Rheinhardt <[email protected]>
* 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 <[email protected]>
* avcodec/mpegvideo: Add const where appropriateAndreas Rheinhardt2024-06-121-5/+4
| | | | | | | | 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 <[email protected]>
* avcodec/mpegvideo: Shorten variable namesAndreas Rheinhardt2024-06-121-42/+42
| | | | | | | | 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 <[email protected]>
* avcodec/h263: Move setting mbskip_table to decoder/encodersAndreas Rheinhardt2024-06-121-0/+4
| | | | | | This removes a branch from H.263 based decoders. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: assert impossible wrap pointsMichael Niedermayer2024-05-191-0/+2
| | | | | | | | Helps: CID1473517 Uninitialized scalar variable Helps: CID1473497 Uninitialized scalar variable Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer <[email protected]>
* avcodec/codec_internal: Remove FF_CODEC_CAP_ALLOCATE_PROGRESSAndreas Rheinhardt2024-04-191-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before commit f025b8e110b36c1cdb4fb56c4cd57aeca1767b5b, every frame-threaded decoder used ThreadFrames, even when they did not have any inter-frame dependencies at all. In order to distinguish those decoders that need the AVBuffer for progress communication from those that do not (to avoid the allocation for the latter), the former decoders were marked with the FF_CODEC_CAP_ALLOCATE_PROGRESS internal codec cap. Yet distinguishing these two can be done in a more natural way: Don't use ThreadFrames when not needed and split ff_thread_get_buffer() into a core function that calls the user's get_buffer2 callback and a wrapper around it that also allocates the progress AVBuffer. This has been done in 02220b88fc38ef9dd4f2d519f5d3e4151258b60c and since that commit the ALLOCATE_PROGRESS cap was nearly redundant. The only exception was WebP and VP8. WebP can contain VP8 and uses the VP8 decoder directly (i.e. they share the same AVCodecContext). Both decoders are frame-threaded and VP8 has inter-frame dependencies (in general, not in valid WebP) and therefore the ALLOCATE_PROGRESS cap. In order to avoid allocating progress in case of a frame-threaded WebP decoder the cap and the check for the cap has been kept in place. Yet now the VP8 decoder has been switched to use ProgressFrames and therefore there is just no reason any more for this check and the cap. This commit therefore removes both. Also change the value of FF_CODEC_CAP_USES_PROGRESSFRAMES to leave no gaps. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/h263dec: Remove AVCodec.pix_fmts arraysAndreas Rheinhardt2024-02-091-1/+0
| | | | | | | | | | They are not intended for decoders (for which there is the get_format callback in case the user has a choice). Also note that the list was wrong for MPEG4, because it did not contain the high bit depth pixel formats used for studio profiles. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: Remove write-only variableZhao Zhili2024-01-301-3/+1
| | | | | | Fix warning: variable 'time_incr' set but not used. Signed-off-by: Zhao Zhili <[email protected]>
* Revert "all: Don't set AVClass.item_name to its default value"Anton Khirnov2024-01-201-0/+1
| | | | | | | Some callers assume that item_name is always set, so this may be considered an API break. This reverts commit 0c6203c97a99f69dbaa6e4011d48c331e1111f5e.
* all: Don't set AVClass.item_name to its default valueAndreas Rheinhardt2023-12-221-1/+0
| | | | | | | | Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9; also avoids relocations. Reviewed-by: Anton Khirnov <[email protected]> Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: Avoid superfluous VLC structuresAndreas Rheinhardt2023-10-311-48/+45
| | | | | | | | | | | For all VLCs here, the number of bits of the VLC is write-only, because it is hardcoded at the call site. Therefore one can replace these VLC structures with the only thing that is actually used: The pointer to the VLCElem table. And in some cases one can even avoid this. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/ituh263dec: Avoid superfluous VLC structuresAndreas Rheinhardt2023-10-311-9/+9
| | | | | | | | Of all these VLCs here, only VLC.table was really used after init, so use the ff_vlc_init_tables API to get rid of them. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/h263dec, mpeg4videodec: Parse extradata during initAndreas Rheinhardt2023-10-051-0/+9
| | | | | | Possible now that the IDCT is already initialized at this point. Signed-off-by: Andreas Rheinhardt <[email protected]>
* lavc/mpeg4videodec: do not invent a framerate from guessed numbersAnton Khirnov2023-10-031-3/+0
| | | | Improves timestamps for fate-m4v*
* avcodec/vlc: Use proper namespaceAndreas Rheinhardt2023-09-111-9/+9
| | | | | | | | | | | | | | | | Therefore use a proper prefix for this API, e.g. ff_init_vlc_sparse -> ff_vlc_init_sparse ff_free_vlc -> ff_vlc_free INIT_VLC_LE -> VLC_INIT_LE INIT_VLC_USE_NEW_STATIC -> VLC_INIT_USE_STATIC (The ancient INIT_VLC_USE_STATIC has been removed in 595324e143b57a52e2329eb47b84395c70f93087, so that the NEW has been dropped.) Finally, reorder the flags and change their values accordingly. Reviewed-by: Michael Niedermayer <[email protected]> Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: consider lowres in dest_pcm[]Michael Niedermayer2023-09-081-1/+1
| | | | | | | | Fixes: out of array access Fixes: 59999/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-5767982157266944 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]>
* avcodec/defs: Add AV_PROFILE_* defines, deprecate FF_PROFILE_* definesAndreas Rheinhardt2023-09-071-3/+3
| | | | | | | | | These defines are also used in other contexts than just AVCodecContext ones, e.g. in libavformat. Furthermore, given that these defines are public, the AV-prefix is the right one, so deprecate (and not just move) the FF-macros. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: more unsigned in amv computationMichael Niedermayer2023-09-041-1/+1
| | | | | | | | Fixes: signed integer overflow: -2147483648 + -1048576 cannot be represented in type 'int' Fixes: 59365/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-642654923954585 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]>
* avcodec: Ignoring errors is only possible before the input endMichael Niedermayer2023-06-181-2/+2
| | | | | | | Fixes: out of array read Fixes: Ticket 10308 Signed-off-by: Michael Niedermayer <[email protected]>
* avcodec: remove FF_API_FLAG_TRUNCATEDJames Almer2023-02-091-3/+0
| | | | Signed-off-by: James Almer <[email protected]>
* avcodec: remove FF_API_AVCTX_TIMEBASEJames Almer2023-02-091-3/+0
| | | | Signed-off-by: James Almer <[email protected]>
* avcodec/mpeg4data: Move ff_mpeg4_resync_prefix to its only userAndreas Rheinhardt2022-11-111-1/+5
| | | | | | This array is only ever useful to a decoder. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/h263dec: Move initializing qpel DSP context to mpeg4videodec.cAndreas Rheinhardt2022-11-061-0/+2
| | | | | | | The MPEG-4 decoder is the only decoder based upon H.263 that supports quarterpel motion vectors. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpegvideo: Don't use ScanTable where unnecessaryAndreas Rheinhardt2022-10-241-10/+18
| | | | | | | | | For the intra_[hv]_scantables, only ScanTable.permutated is used, so one only needs to keep that. Reviewed-by: Michael Niedermayer <[email protected]> Reviewed-by: Peter Ross <[email protected]> Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: Reindent after the previous commitAndreas Rheinhardt2022-10-201-16/+16
| | | | Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: Remove always-true checksAndreas Rheinhardt2022-10-201-4/+2
| | | | | | | | | | | | | | | codec_id is always AV_CODEC_ID_MPEG4 for mpeg4_decode_mb(), as the MPEG-4 decoder is the only decoder for which ff_mpeg4_decode_picture_header() as well as decode_init() are ever called and these are the only places where the decode_mb function pointer is ever set to mpeg4_decode_mb(). ff_mpeg4_workaround_bugs() is also only called for the MPEG-4 decoder (the caller checks the codec id). (ff_mpeg4_decode_picture_header() is also called for the MPEG-4 parser, but it never uses the decode_mb function pointer.) Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: Sync sprite_warping_accuracy between threadsAndreas Rheinhardt2022-10-201-0/+1
| | | | | | | It is set in the vol header and is therefore a sequence and not only a picture property. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpegvideo: Move sprite-related fields to Mpeg4DecContextAndreas Rheinhardt2022-10-201-53/+53
| | | | | | Only used there. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpegvideodsp: Make MpegVideoDSP MPEG-4 onlyAndreas Rheinhardt2022-10-201-26/+32
| | | | | | | | 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 <[email protected]>
* avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.cAndreas Rheinhardt2022-10-201-0/+168
| | | | | | It is the only codec for which mcsel is ever set. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/codec_internal: Add macros for update_thread_context(_for_user)Andreas Rheinhardt2022-09-031-2/+2
| | | | | | | | | It reduces typing: Before this patch, there were 11 callbacks that exceeded the 80 char line length limit; now there are zero. It also allows to remove ONLY_IF_THREADS_ENABLED() in libavutil/internal.h. Signed-off-by: Andreas Rheinhardt <[email protected]>
* 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 <[email protected]>
* avcodec/mpeg4video: Factor non-codec stuff out into a header of its ownAndreas Rheinhardt2022-09-021-0/+1
| | | | | | This avoids including mpegvideo.h in mpeg4_unpack_bframes_bsf.c. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpeg4videodec: Keep data_partitioning in sync between threadsAndreas Rheinhardt2022-08-211-0/+1
| | | | | | | | | Fixes frame-threaded decoding of samples created by concatting a video with data partitioning and a video not using it. (Only the MPEG-4 decoder sets this, so it is synced in mpeg4_update_thread_context() despite being a MpegEncContext-field.) Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpegvideo: Inline values in ff_update_block_index()Andreas Rheinhardt2022-07-311-2/+4
| | | | | | | | | 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 <[email protected]> Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec: Make init-threadsafety the defaultAndreas Rheinhardt2022-07-181-2/+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 <[email protected]> Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/vlc: Use structure instead of VLC_TYPE array as VLC elementAndreas Rheinhardt2022-06-171-1/+1
| | | | | | | | | | | | | | | | | | In C, qualifiers for arrays are broken: const VLC_TYPE (*foo)[2] is a pointer to an array of two const VLC_TYPE elements and unfortunately this is not compatible with a pointer to a const array of two VLC_TYPE, because the latter does not exist as array types are never qualified (the qualifier applies to the base type instead). This is the reason why get_vlc2() doesn't accept a const VLC table despite not modifying the table at all, as there is no automatic conversion from VLC_TYPE (*)[2] to const VLC_TYPE (*)[2]. Fix this by using a structure VLCElem for the VLC table. This also has the advantage of making it clear which element is which. Signed-off-by: Andreas Rheinhardt <[email protected]>
* 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 <[email protected]>
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-211-10/+10
| | | | | | | | | | | | | | | | 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 <[email protected]> Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.hAndreas Rheinhardt2022-03-211-1/+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 <[email protected]>
* configure: Use a separate config_components.h header for $ALL_COMPONENTSMartin Storsjö2022-03-161-0/+2
| | | | | | | | 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ö <[email protected]>
* avcodec/ituh263dec: Make initializing VLCs thread-safeAndreas Rheinhardt2022-02-181-1/+2
| | | | | | | This automatically makes the FLV, H.263, H.263+, Intel H.263, MPEG-4, RealVideo 1.0 and RealVideo 2.0 decoders init-threadsafe. Signed-off-by: Andreas Rheinhardt <[email protected]>
* avcodec/mpegvideo: Move decoder-only stuff to a new headerAndreas Rheinhardt2022-02-131-0/+1
| | | | Signed-off-by: Andreas Rheinhardt <[email protected]>