aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mpeg4videodec.c
Commit message (Collapse)AuthorAgeFilesLines
* all: fix typos found by codespellTimo Rothenpieler47 hours1-1/+1
|
* avcodec/mpegvideo: Move partitioned_frame to {H263Dec,MPVEnc}ContextAndreas Rheinhardt2025-07-031-5/+5
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move fields to {H263Dec,MPVEnc}Context when possibleAndreas Rheinhardt2025-07-031-9/+11
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h263dec: Use function ptr for decode_picture_headerAndreas Rheinhardt2025-07-031-1/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move mb_num_left to {H263,RV34}DecContextAndreas Rheinhardt2025-07-031-2/+2
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move fields only used by H.263 decoders to H263DecCtxAndreas Rheinhardt2025-07-031-17/+19
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg12dec: Don't use MPVContext.blockAndreas Rheinhardt2025-07-031-1/+0
| | | | | | | Instead add the necessary blocks directly into Mpeg12SliceContext. This allows to completely remove MPVContext.block. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h263dec: Stop using MpegEncContext.gbAndreas Rheinhardt2025-07-031-160/+160
| | | | | | | | Add a GetBitContext to H263DecContext instead. This is in preparation for removing MpegEncContext.gb. Also move last_resync_gb to H263DecContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h263dec: Don't use MpegEncContext.blockAndreas Rheinhardt2025-07-031-7/+7
| | | | | | | | Instead add the necessary blocks directly to H263DecContext (only six are needed, not 12 as ff_mpv_common_init() currently allocates). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h263dec: Remove redundant block parameter from decode_mbAndreas Rheinhardt2025-07-031-6/+6
| | | | | | | | | | | With the exception of mpeg4_decode_studio_mb(), all decode_mb functions implicitly presumed that the block provided as argument coincides with MpegEncContext.block (they zeroed the latter and then used the former to decode the block); mpeg4_decode_studio_mb() meanwhile did not use the provided block at all (it uses blocks of int32_t). So remove said parameter. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h263dec: Add H263DecContextAndreas Rheinhardt2025-07-031-849/+854
| | | | | | | | | This is in preparation for moving the fields only used by H.263-based decoders from MPVContext to H263DecContext. For now only the decode_mb function pointer has been moved (to be able to switch said callback to use an H263DecContext*). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move dct_precision to Mpeg4DecContextAndreas Rheinhardt2025-07-031-11/+14
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/{h263,mpeg4video}dec: Pass MPVContext*, not Mpeg4DecContext*Andreas Rheinhardt2025-07-031-6/+6
| | | | | | | | | | | The code in h263dec.c is not supposed to know that the MPEG-4 decoder uses an Mpeg4DecContext as private context at all (said context is only exposed in a header so that hardware accelerations can access it and for the parser to use). Passing an MPVContext* directly also allows to remove the indirection via AVCodecContext.priv_data. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Avoid unnecessary indirectionsAndreas Rheinhardt2025-07-031-6/+3
| | | | | | | | | | This basically reverts d4967c04e040b3b2f937cad88599af825147ec94. Said commit was based on the false premise that it would be an aliasing violation to upcast a pointer to structure to a pointer to a bigger structure containing the original structure as its first element, but this is just not true. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideoenc: Allocate blocks as part of MPVEncContextAndreas Rheinhardt2025-07-031-1/+0
| | | | | | | | This avoids mpegvideo.c having to deal with the fact that the encoders use two sets of blocks and is in preparation for not allocating blocks at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/ituh263dec: Only initialize ff_h263_rl_inter when neededAndreas Rheinhardt2025-07-031-0/+1
| | | | | | | The H.263 decoder itself does not need max_run/max_level of this RLTable, only the MPEG-4 decoder does. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4video: Move ff_mpeg4_pred_dc() to decoderAndreas Rheinhardt2025-06-211-2/+45
| | | | | | | | Only used by the decoder now that the encoder solves out-of-slice predictions by setting the out-of-slice values appropriately. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Only keep MpegEncContext.dc_val[0]Andreas Rheinhardt2025-06-211-2/+2
| | | | | | | The chroma dc_val pointers are mostly unused (accesses use dc_val[0] and block_index), so remove them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Only use a single ac_val pointerAndreas Rheinhardt2025-06-211-4/+2
| | | | | | The chroma pointers ac_val[1] and ac_val[2] are no longer used anywhere. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Redo resetting intra table entryAndreas Rheinhardt2025-06-211-4/+2
| | | | | | | | | | | | | | All callers check the corresponding entry of MpegEncContext.mbintra_table and if set (indicating that the intra tables might have been written to when decodeing a intra MB, so that they are "dirty"), call ff_clean_intra_table_entries(), which resets them to default values and resets the mbintra_table entry. Move resetting to the callers (via an inline function that also performs the checks). This currently has the advantage that the additional load of the mbintra_table ptr can be avoided. It will also allow to simplify ff_clean_intra_table_entries() (by using block_index[4] and [5]). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Don't zero blocks twiceAndreas Rheinhardt2025-06-211-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move mpeg_quant to {Mpeg4Dec,MPVEnc}ContextAndreas Rheinhardt2025-05-261-7/+8
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_dec: Simplify check for unquantizing inter blocksAndreas Rheinhardt2025-05-261-2/+4
| | | | | | | Just ensure that dct_unquantize_inter is set iff it is used and check for the function pointer instead. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Remove unnecessary ff_xvid_idct_init()Andreas Rheinhardt2025-05-261-4/+0
| | | | | | | | | | | | | | | It is unnecessary: If the dst context is not already initialized, then it will be initialized by memcpy(dst, src, sizeof(*dst), which already initializes the IDCT to the desired one, potentially followed by ff_mpv_common_init(), which does not touch the IDCT. (This call has been added in f89d76c10355242c39b08f253c1d1524f45ef778; the aforementioned copying took place back then, too, but ff_mpv_common_init() reinitialized the IDCT to a non-xvid one, therefore the initialization here has been added to fix multithreaded decoding.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4video: Nuke ff_mpeg4_init_rl_intra()Andreas Rheinhardt2025-05-261-1/+3
| | | | | | | | The MPEG-4 decoder can now initialize ff_mpeg4_rl_intra directly given that the MPEG-4 encoder no longer wants it performed, too. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Don't initialize unused parts of RLTablesAndreas Rheinhardt2025-05-261-3/+0
| | | | | | | | The reversible VLC tables use a simpler escaping method than the ordinary VLCs: It does not use max_run, max_level etc. and therefore one does not need to initialize these at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Mark impossible switch case as unreachableAndreas Rheinhardt2025-05-211-1/+3
| | | | | | Alternative to 8fc649b931a3cbc3a2dd9b50b75a9261a2fb4b49. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Move setting has_b_frames to mpeg4video_parser.cAndreas Rheinhardt2025-05-161-1/+0
| | | | | | ff_h263_decode_frame() already does it generically for the decoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec,h263dec: Only set skipped_last_frame for !vop_codedAndreas Rheinhardt2025-05-161-0/+3
| | | | | | This is more in line with the spec and avoids a branch. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Keep skipped_last_frame in sync between threadsAndreas Rheinhardt2025-05-161-0/+1
| | | | | | Otherwise the output may depend upon the number of frame threads used. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Don't set chroma matrices unnecessarilyAndreas Rheinhardt2025-05-161-4/+0
| | | | | | | | | | Only the studio profile uses chroma_inter/intra matrices; the ordinary profile has only inter/intra matrices. And our code (namely the MPEG-2 unquantize functions) only use these two matrices (the MPEG-2 decoder unquantizes on its own while parsing). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move clear_context() to mpeg4videodec.cAndreas Rheinhardt2025-05-161-3/+40
| | | | | | | | | There is only one source of dirty MpegEncContexts: update_mpvctx() (which copies an MpegEncContext over another one in order to initialize it). So only clear these contexts. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_dec: Move memcpy'ing ctx to mpeg4videodec.cAndreas Rheinhardt2025-05-161-1/+26
| | | | | | | | | | | | | | | | | | When the destination MpegEncContext in ff_mpeg_update_thread_context() is not initialized, the source MpegEncContext is simply copied over it before (potentially) calling ff_mpv_common_init(). This leads to data races when this code is executed which is why it should be replaced with only copying the necessary fields (this is for future commits). Given that the RV30 and RV40 decoders always call said function with an already initialized MpegEncContext (they use context_reinit in case of frame size changes), they don't need this ugly initialization (and are therefore race-free). This means that this code can be moved to the only decoder that actually needs it: MPEG-4. This commit does so. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move [fb]_code to Mpeg4Dec and MPVEncContextAndreas Rheinhardt2025-05-161-30/+30
| | | | | | | | It is only used by the MPEG-4 decoder and the encoders. Notice that this field is a per-frame property and therefore does not need to by synced in mpeg4_update_thread_context(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4video: Pass parameters directlyAndreas Rheinhardt2025-05-161-2/+2
| | | | | | | Namely in ff_mpeg4_get_video_packet_prefix_length(). This will allow to move [fb]_code from MpegEncContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Permute quant matrices directly upon IDCT reinitAndreas Rheinhardt2025-05-161-7/+32
| | | | | | | | | | | | | | | | | | | | | | | | | When switching to the XviD IDCT, the IDCT permutation can change. Given that we already permute the quant matrices when parsing them, they need to be permuted, too. Up until now this has not been done; instead the header has been parsed again in the expectation that the currently active quant matrix is contained in this header. This expectation is wrong; it is for example wrong when the VOL header is only available via extradata (such a file can be easily created from xvid_vlc_trac7411.h263 (in the FATE suite) via the remove_extra BSF). It could also be wrong if the XviD user data is only available in a subsequent packet. This commit therefore switches to permuting the relevant matrices directly. It also stops parsing the header a second time when switching to the XviD IDCT. (I wonder whether ff_mpv_idct_init() should take alternate_scan into account when initializing permutated_intra_h_scantable as the decoder does. Does the MPEG-4 encoder use a wrong scantable in this case?) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Set [yd]c_scale_table during initAndreas Rheinhardt2025-05-161-4/+4
| | | | | | | | | | It does not change lateron. (If we were to add short header support later, it would involve a branch in mpeg4_decode_block() anyway and we would then hardcode the dc_scaler value of eight there; the *_scale_tables would stay the same.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Don't set [bf]_code for non-MPEG-4 decodersAndreas Rheinhardt2025-03-291-4/+4
| | | | | | It is only used by encoders and the MPEG-4 decoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Actually check av_buffer_replace()Andreas Rheinhardt2025-03-271-3/+1
| | | | | | Forgotten in 4f2becc2dc4668f837b5ba96c11c3426bc120ac0. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Only keep the actually used unquantize funcsAndreas Rheinhardt2025-03-261-0/+14
| | | | | | | | | | | | | | For all encoders and all decoders except MPEG-4 the unquantize functions to use don't change at all and therefore needn't be kept in the context. So discard them after setting them; for MPEG-4, the functions get assigned on a per-frame basis. Decoders not using any unquantize functions (H.261, MPEG-1/2) as well as decoders that only call ff_mpv_reconstruct_mb() through error resilience (RV30/40, the VC-1 family) don't have the remaining pointers set at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4video: Move IS_3IV1 macro to mpeg4videodec.cAndreas Rheinhardt2025-03-071-0/+6
| | | | | | Also add parentheses around the replacement to make it safer. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4video: Split ff_mpeg4_pred_dc()Andreas Rheinhardt2025-03-071-5/+43
| | | | | | | | | | | | | | | | | | | | | It currently does two things: a) Get a prediction for the dc and the dc direction and b) process said prediction. Processing the prediction differs for encoding (getting a diff) and decoding (getting the level via diff+prediction). So having a common function performing b) makes no sense. Even worse, there is a decoding mode where the dc coefficient (diff) is not coded specially and therefore unavailable before entering the block decoding loop, so that one can only perform a). Before this commit, the decoder simply called ff_mpeg4_pred_dc() twice; the results of the b) part of the call before the loop were ignored (but the compiler could not elide them because they involved error messages) and a) was also performed twice. This commit changes this by splitting b) out of ff_mpeg4_pred_dc() and moving this code to decoder and encoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Bail out earlier when parsingAndreas Rheinhardt2025-03-071-6/+6
| | | | | | | The scantables are unused for the parser (and in fact the IDCT permutation used has not been initialized at all). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Avoid copying packed bitstream dataAndreas Rheinhardt2025-03-041-36/+21
| | | | | | | This is possible because the packet is reference-counted and because we never combine the data from several packets. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move bitstream_buffer to mpeg4videodecAndreas Rheinhardt2025-03-041-21/+74
| | | | | | | This is possible by moving the code using it to open a GetBitContext from h263dec.c to mpeg4videodec.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_dec: Move syncing DivX-stuff to mpeg4videodec.cAndreas Rheinhardt2025-03-041-0/+14
| | | | | | | It is only used by MPEG-4 (and is used in h263dec.c and can therefore not just be moved to Mpeg4DecContext...). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move quant_precision to Mpeg4DecContextAndreas Rheinhardt2024-06-201-10/+10
| | | | | | | | 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/mpeg4videodec: Don't initialize unused inter_scantableAndreas Rheinhardt2024-06-201-7/+2
| | | | | | | | | | | | inter_scantable is only used by the dct_unquantize_h263_inter functions, yet this is not used by the MPEG-4 decoder at all (in case H.263 quantization is used, the unquantization already happens in mpeg4_decode_block()). Also move the common initialization of ff_permute_scantable() out of the if. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4videodec: Remove always-false checkAndreas Rheinhardt2024-06-201-1/+1
| | | | | | | All valid values of dc_lum and dc_chrom are in the range 0..9, because they are initialized via tables with 10 elements. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* 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 <andreas.rheinhardt@outlook.com>