aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/h261dec.c
Commit message (Collapse)AuthorAgeFilesLines
* avcodec/mpegvideo: Move SLICE_* defs to h263dec.h, h261dec.cAndreas Rheinhardt2025-07-031-0/+4
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Don't use MpegEncContext.blockAndreas Rheinhardt2025-07-031-4/+7
| | | | | | | Instead put it into H261DecContext. This is in preparation for removing MpegEncContext.block. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Stop using MpegEncContext.gbAndreas Rheinhardt2025-07-031-39/+41
| | | | | | This is in preparation for removing said field from MpegEncContext. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Set pict_type during initAndreas Rheinhardt2025-04-121-5/+6
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Export key frame informationAndreas Rheinhardt2025-04-121-7/+9
| | | | | | Implements ticket #8343. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Set FF_CODEC_CAP_SKIP_FRAME_FILL_PARAMAndreas Rheinhardt2025-03-261-0/+1
| | | | | | | This decoder sets the AVCodecContext fields even when a frame is skipped. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Don't call ff_set_qscale()Andreas Rheinhardt2025-03-071-4/+6
| | | | | | Most of what it does is unneeded for H.261. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h26[134]dec: Always report the buffer to be completely consumedAndreas Rheinhardt2025-03-041-15/+1
| | | | | | | | | | | It is pointless to try to report the true number because decode_simple_internal() always treats the buffer as completely consumed for video codecs anyway. (Apart from that: The h263dec code would report to only have consumed the header data in case decoding is aborted due to skip_frame which makes no sense.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Inline constantAndreas Rheinhardt2025-03-041-1/+1
| | | | | | | | The value here has been set in ff_set_qscale() from ff_mpeg1_dc_scale_table, all of whose entries are 8. Reviewed-by: Ramiro Polla <ramiro.polla@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Remove dead checkAndreas Rheinhardt2025-03-041-2/+1
| | | | | | H.261 does not have non-reference frames. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Don't set framerate multiple timesAndreas Rheinhardt2024-06-201-2/+2
| | | | | | Just do it once during init. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Simplify decoding motion vectorsAndreas Rheinhardt2024-06-201-7/+1
| | | | | | | Don't use a LUT to negate followed by a conditional ordinary negation immediately thereafter. Instead fold the two. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Unquantize coefficients while parsing themAndreas Rheinhardt2024-06-201-2/+9
| | | | | | | | | 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/h261dec: Simplify decoding GOB headerAndreas Rheinhardt2024-06-201-26/+1
| | | | | | | | h261_resync() can be completely removed, because h261_decode_gob_header() checks for a GOB header itself if gob_start_code_skipped is zero. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Fix UB NULL + 0, remove broken resync codeAndreas Rheinhardt2024-06-201-17/+1
| | | | | | | | last_resync_gb is never initialized, causing NULL + 0 in align_get_bits(). In addition to that, the loop is never entered. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Don't reset gob_start_code_skipped in h261_decode_init()Andreas Rheinhardt2024-06-201-2/+0
| | | | | | It always gets reset at the start of h261_decode_frame(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegutils: Don't use MB_TYPE_L[01] for mpegvideoAndreas Rheinhardt2024-06-201-2/+2
| | | | | | | | | | | | | | | | | | | 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 <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Remove nonsense information from error messageAndreas Rheinhardt2024-06-201-2/+1
| | | | | | | The "invalid mtype index" here is always -1, because that is the value the VLC api uses for not existent leafs in an incomplete tree. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Use VLC symbol tableAndreas Rheinhardt2024-06-201-5/+4
| | | | | | | | This is possible now that MB_TYPE_CBP and MB_TYPE_QUANT fit into an int16_t; only MB_TYPE_H261_FIL needs to be remapped to MB_TYPE_CODEC_SPECIFIC. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Make MPVPicture refcountedAndreas Rheinhardt2024-06-121-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_dec: Add close function for mpegvideo-decodersAndreas Rheinhardt2024-06-121-10/+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 <andreas.rheinhardt@outlook.com>
* avcodec/mpegpicture: Split MPVPicture into WorkPicture and ordinary PicAndreas Rheinhardt2024-06-121-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | 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/mpegvideo: Shorten variable namesAndreas Rheinhardt2024-06-121-13/+13
| | | | | | | | 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/h261dec: Avoid superfluous VLC structuresAndreas Rheinhardt2023-10-311-20/+20
| | | | | | | | 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 <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Don't set write-only macroblock dimensionsAndreas Rheinhardt2023-10-141-6/+0
| | | | | | | | They are generally set in ff_mpv_init_context_frame() (mostly called by ff_mpv_common_init()); setting them somewhere else should be avoided. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Discard whole packet when discardingAndreas Rheinhardt2023-10-111-1/+1
| | | | | | | (The return value doesn't really matter: For video decoders every return value >= 0 is treated as "consumed all of the input".) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Don't set write-only picture_numberAndreas Rheinhardt2023-10-111-4/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec: Remove pointless gotoAndreas Rheinhardt2023-10-091-3/+0
| | | | | | | There is no need to parse the header twice; doing so does nothing. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261dec, mpeg12dec, vc1dec: Remove setting write-only flagsAndreas Rheinhardt2023-10-051-7/+0
| | | | | | | These flags will be overwritten later in ff_mpv_frame_start(). Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo_dec: Always initialize IDCTDSPContext during initAndreas Rheinhardt2023-10-051-1/+0
| | | | | | | | | | | It has currently not been done for H263, H263P and MPEG4. Doing so avoids having to initialize the IDCT permutation lateron when decoding packets in order to be able to parse a quant matrix; it means that every mpegvideo decoder always has an initialized IDCTDSPContext after init. Initializing is done generically in ff_mpv_decode_init(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/vlc: Use proper namespaceAndreas Rheinhardt2023-09-111-4/+4
| | | | | | | | | | | | | | | | 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 <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: use the new AVFrame key_frame flag in all decoders and encodersJames Almer2023-05-041-1/+4
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: add AVCodecContext.frame_num as 64 bit variant to frame_numberMarton Balint2023-02-131-1/+1
| | | | | | | | | | Frame counters can overflow relatively easily (INT_MAX number of frames is slightly more than 1 year for 60 fps content), so make sure we use 64 bit values for them. Also deprecate the old 32 bit frame_number attribute. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/h261dec: Don't update block_index unnecessarilyAndreas Rheinhardt2022-11-111-4/+11
| | | | | | | | block_index is write-only for the H.261 decoder, so don't update it by calling ff_update_block_index(). Instead use a function of our own to set/update dest. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* 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 <andreas.rheinhardt@outlook.com>
* avcodec/internal: Move ff_set_dimensions() to decode.hAndreas Rheinhardt2022-08-271-1/+1
| | | | | | | | | Decoder-only, as the dimensions are set by the user when encoding. Also fixup the other headers a bit while removing unnecessary internal.h inclusions. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Inline values in ff_update_block_index()Andreas Rheinhardt2022-07-311-2/+2
| | | | | | | | | 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 <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Make init-threadsafety the defaultAndreas Rheinhardt2022-07-181-1/+0
| | | | | | | | | | | 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 <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* 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 <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Make FFCodec.decode use AVFrame*Andreas Rheinhardt2022-04-051-2/+1
| | | | | | | | This increases type-safety by avoiding conversions from/through void*. It also avoids the boilerplate "AVFrame *frame = data;" line for non-subtitle decoders. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-211-7/+7
| | | | | | | | | | | | | | | | 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 <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.hAndreas Rheinhardt2022-03-211-0/+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 <andreas.rheinhardt@outlook.com>
* avcodec/mpegvideo: Move decoder-only stuff to a new headerAndreas Rheinhardt2022-02-131-0/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h261: Separate decode and encode contextsAndreas Rheinhardt2022-02-131-22/+37
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Remove unnecessary h263.h inclusionsAndreas Rheinhardt2022-01-091-1/+0
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Constify AVCodecsAndreas Rheinhardt2021-04-271-1/+1
| | | | | | | | | | Given that the AVCodec.next pointer has now been removed, most of the AVCodecs are not modified at all any more and can therefore be made const (as this patch does); the only exceptions are the very few codecs for external libraries that have a init_static_data callback. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h261dec: Initialize IDCT context during initAndreas Rheinhardt2021-04-081-4/+1
| | | | | | | | | | | | | Before 998c9f15d1ca8c7489775ebcca51623b915988f1, initializing an MpegEncContext's IDCT parts occured in ff_mpv_common_init() and this has been called in h261_decode_frame(), not h261_decode_init(). Yet said commit factored this out of ff_mpv_common_init() and therefore there is no reason any more not to set this during init as this commit does. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* Revert "avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ↵Andreas Rheinhardt2021-04-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/h261dec: Remove parse_context cruftAndreas Rheinhardt2021-03-081-3/+0
| | | | | | | | The H.261 decoder doesn't use the ParseContext of its MpegEncContext since e7316976650b429345da619c3acff38004aaf6b8. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>