Commit Graph

76 Commits

Author SHA1 Message Date
Andreas Rheinhardt 2b0e9e278a avcodec/h263dec: Remove AVCodec.pix_fmts arrays
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 <andreas.rheinhardt@outlook.com>
2024-02-09 08:16:25 +01:00
Andreas Rheinhardt 36b5f71b1f avcodec/msmpeg4dec: Avoid superfluous VLC structures
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 <andreas.rheinhardt@outlook.com>
2023-10-31 20:47:00 +01:00
Andreas Rheinhardt 7902c0df4c avcodec/msmpeg4_vc1_data: Avoid superfluous VLC structures
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.
Also combine the ff_msmp4_dc_(luma|chroma)_vlcs as well
as the tables used to generate them to simplify the code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-31 20:46:59 +01:00
Andreas Rheinhardt ff886fc282 avcodec/ituh263dec: Avoid superfluous VLC structures
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>
2023-10-31 20:46:59 +01:00
Andreas Rheinhardt 9cdf82c2c2 avcodec/vlc: Use proper namespace
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 595324e143, 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>
2023-09-11 00:27:45 +02:00
Andreas Rheinhardt cbe6ef1031 avcodec/vc1dec: Split VC-1 decoders from msmpeg4
The only msmpeg4 code that is ever executed by the VC-1 based
decoders is ff_msmpeg4_decode_init() and what is directly
reachable from it. This is:
a) A call to av_image_check_size(), then ff_h263_decode_init(),
b) followed by setting [yc]_dc_scale_table and initializing
scantable/permutations.
c) Afterwards, some static tables are initialized.
d) Finally, slice_height is set.

The replacement for ff_msmpeg4_decode_init() performs a)
just like now; it also sets [yc]_dc_scale_table,
but it only initializes inter_scantable and intra_scantable
and not permutated_intra_[hv]_scantable: The latter are only
used inside decode_mb callbacks which are only called
in ff_h263_decode_frame() which is unused for VC-1.*

The static tables initialized in c) are not used at all by
VC-1 (the ones that are used have been factored out in
previous commits); this avoids touching 327KiB of .bss.

slice_height is also not used by the VC-1 decoder (setting
it in ff_msmpeg4_decode_init() is probably redundant after
b34397b4cd).

*: It follows from this that the VC-1 decoder is not really
based upon the H.263 decoder either; changing this will
be done in a future commit.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-06 17:41:26 +01:00
Andreas Rheinhardt d1d30edf42 avcodec/msmpeg4data: Move data shared between msmpeg4 and VC-1 out
This is in preparation for splitting VC-1 from msmpeg4.
(msmpeg4data.c was originally intended to be just this;
9488b966c7 changed it).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-06 17:41:26 +01:00
Andreas Rheinhardt 83dfc21a21 avcodec/msmpeg4dec: Factor initializing VLCs shared with VC-1 out
It will be useful in the following commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-06 17:41:26 +01:00
Andreas Rheinhardt 8f7bf45895 avcodec/vc1_block: Don't duplicate #defines
VC1 shares some VLCs with MSMPEG-4, but vc1_block.c
simply duplicates the defines instead of including
the appropriate headers; furthermore, use a proper
prefix for these defines: DC_VLC_BITS is also used
by other codecs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-06 17:41:26 +01:00
Andreas Rheinhardt ca96456c0e avcodec/msmpeg4dec: Move setting decode_mb for WMV2 to wmv2dec.c
It avoids checks and allows to make ff_wmv2_decode_mb() static;
furthermore, it allows to avoid a config_components.h inclusion.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-10-29 13:37:41 +02:00
Andreas Rheinhardt 5ec9d26b2b avcodec/mpegvideo: Don't use ScanTable where unnecessary
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>
2022-10-24 01:23:59 +02:00
Andreas Rheinhardt 48286d4d98 avcodec/codec_internal: Add macro to set AVCodec.long_name
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>
2022-09-03 15:42:57 +02:00
Andreas Rheinhardt 21b23ceab3 avcodec: Make init-threadsafety the default
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>
2022-07-18 20:04:59 +02:00
Andreas Rheinhardt 2d764069be avcodec/vlc: Use structure instead of VLC_TYPE array as VLC element
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 <andreas.rheinhardt@outlook.com>
2022-06-17 16:47:29 +02:00
Andreas Rheinhardt 4243da4ff4 avcodec/codec_internal: Use union for FFCodec decode/encode callbacks
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>
2022-04-05 20:02:37 +02:00
Andreas Rheinhardt 20f9727018 avcodec/codec_internal: Add FFCodec, hide internal part of AVCodec
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>
2022-03-21 01:33:09 +01:00
Andreas Rheinhardt a688f3c13c avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.h
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>
2022-03-21 01:33:09 +01:00
Martin Storsjö a78f136f3f configure: Use a separate config_components.h header for $ALL_COMPONENTS
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>
2022-03-16 14:12:49 +02:00
Andreas Rheinhardt 3abb80f65b avcodec/msmpeg4dec: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-18 20:35:30 +01:00
Andreas Rheinhardt 569a0d0012 avcodec/msmpeg4dec: Make initializing VLCs thread-safe
This automatically makes the remaining mpegvideo-decoders
(namely msmpeg4v[1-3], mss2, VC-1, VC-1 Image, WMV-[1-3]
and WMV-3 Image) init-threadsafe.
These were the last native codecs that were not init-threadsafe;
only wrappers for external libraries and for hardware accelerations
are now not init-threadsafe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-18 20:29:45 +01:00
Andreas Rheinhardt 1187765f3b avcodec/mpeg4video.h: Move decoder-only parts to a new header
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 19:41:57 +01:00
Andreas Rheinhardt 20d74fb09d avcodec/h263.h: Move encoder-only stuff to a new header h263enc.h
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 19:41:43 +01:00
Andreas Rheinhardt e2cf60f040 avcodec/msmpeg4.h: Move decoder-only parts to a new header
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 19:35:58 +01:00
Andreas Rheinhardt 78087da47c avcodec/wmv2.h: Move encoder- and decoder-only parts to new headers
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 15:28:17 +01:00
Andreas Rheinhardt 7f6596c8bb avcodec/h263: Move decoding-only stuff to a new header h263dec.h
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 18:34:30 +01:00
Andreas Rheinhardt a247ac640d avcodec: Constify AVCodecs
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>
2021-04-27 10:43:15 -03:00
Andreas Rheinhardt 1d5d666601 avcodec/msmpeg4: Factor out common RLTable initialization code
Up until now, both the msmpeg4 decoders and encoders initialized several
RLTables common to them (the decoders also initialized the VLCs of these
RLTables). This is an obstacle to making these codecs init-threadsafe.
So move this initialization to ff_msmpeg4_common_init() that already
contains this initialization code. This allows to reuse the AVOnce used
for initializing ff_v2_dc_lum/chroma_table which automatically makes
initializing these RLTables thread-safe.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-04-27 00:43:51 +02:00
Andreas Rheinhardt e9bcb08794 avcodec/msmpeg4dec: Avoid duplication of VLC init code
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-12 18:29:11 +02:00
Andreas Rheinhardt d4b9e117ce Revert "avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common_init()"
This mostly reverts commit 4b2863ff01.
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 76cea1d2ce.
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>
2021-04-08 01:07:50 +02:00
Andreas Rheinhardt d8b2fae3c7 avcodec/msmpeg4: Inline number of motion vectors
Both motion vector tables have the same number of elements, hence one
can inline said number and remove the field containing the number of
elements from the structure.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-01-29 06:28:24 +01:00
Andreas Rheinhardt fbb81ea2c6 avcodec/msmpeg4dec: Don't check for errors for complete VLCs
This also affected other users of VLCs from msmpeg4dec, namely vc1_block
and wmv2dec.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-01-29 06:28:24 +01:00
Andreas Rheinhardt 27eea249cc avcodec/msmpeg4dec: Reuse identical MV VLC
msmpeg4dec and ituh263dec both create VLCs with identical parameters out
of ff_mvtab. Given that ff_msmpeg4_decode_init() always (indirectly) calls
ff_h263_decode_init_vlc(), the VLC initialized by the latter can be
directly used by msmpeg4dec. Doing so saves a bit more than 2KB from the
.bss segment as well as the code to initialize a VLC.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-01-25 14:51:53 +01:00
Andreas Rheinhardt d90d0a715f avcodec/msmpeg4dec: Reuse identical RL VLCs
Some of the RLTables used by msmpeg4dec actually coincide with other
RLTables: ff_rl_table[5] coincides with ff_h263_rl_inter (and
ff_rl_table[2] with ff_mpeg4_rl_intra). Given that ff_h263_rl_inter is
always initialized before msmpeg4dec's RLTables are initialized, one can
just reuse the VLC tables by copying the pointers; after all, there are
no ownership issues for static data. This saves 70912B from the .bss
segment, translating into actual memory savings when this decoder is
actually used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-01-25 14:51:53 +01:00
Andreas Rheinhardt b0c4748770 avcodec/msmpeg4dec: Don't initialize unused RL VLCs
For the RLTables ff_rl_table[0..2] only the very first VLC is only ever
used, so it makes no sense to create 32 of them. This saves 285200B from
the .bss segment; this amount of memory is actually saved when this
decoder is used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-01-25 14:51:53 +01:00
Limin Wang 4b2863ff01 avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common_init()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-13 06:59:18 +08:00
Michael Niedermayer 09ec182864 avcodec/msmpeg4dec: Skip frame if its smaller than 1/8 of the minimal size
Frames that small are not valid and of limited use for error concealment, while
being very computationally intensive to process.

Fixes: Timeout
Fixes: 11318/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MSMPEG4V1_fuzzer-5710884555456512

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-05 00:50:13 +01:00
Michael Niedermayer f9cb17f988 avcodec/msmpeg4dec: Check for input end in msmpeg4v34_decode_mb()
Fixes: Timeout
Fixes: 6276/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMV1_fuzzer-5881196690014208

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-02-27 19:37:06 +01:00
Michael Niedermayer 15e892aad1 avcodec/msmpeg4dec: Check for cbpy VLC errors
Fixes: runtime error: left shift of negative value -1
Fixes: 1480/clusterfuzz-testcase-minimized-5188321007370240

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-11 20:04:57 +02:00
Michael Niedermayer 1121d92707 avcodec/msmpeg4dec: Correct table depth
Fixes undefined shift
Fixes: 1381/clusterfuzz-testcase-minimized-5513944540119040

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-07 04:11:21 +02:00
Clément Bœsch 95a29b1a82 Merge commit 'f2f145f3032bc8808708a4bd694fbce5f1b8b63c'
* commit 'f2f145f3032bc8808708a4bd694fbce5f1b8b63c':
  msmpeg4: Drop disabled debug cruft

Merged-by: Clément Bœsch <u@pkh.me>
2017-03-19 16:06:49 +01:00
Michael Niedermayer cde007dcd3 avcodec: Add FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM to most h263 based codecs
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-01-21 02:30:38 +01:00
Hendrik Leppkes 2335e189fb Merge commit '4f98bb7b6d0323d9ecc3bebd6e24d46a3a374bad'
* commit '4f98bb7b6d0323d9ecc3bebd6e24d46a3a374bad':
  msmpeg4: Remove commented-out debug logging code

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-10-07 13:23:38 +02:00
Hendrik Leppkes 5114c62902 Merge commit 'eedbeb4c2737f28844157fae4bd87ed42a61bb1d'
* commit 'eedbeb4c2737f28844157fae4bd87ed42a61bb1d':
  msmpeg4: Remove some broken, commented-out cruft

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-10-07 13:22:25 +02:00
Diego Biurrun f2f145f303 msmpeg4: Drop disabled debug cruft 2016-08-17 12:16:42 +02:00
Hendrik Leppkes c142dc203e Merge commit 'dc40a70c5755bccfb1a1349639943e1f408bea50'
* commit 'dc40a70c5755bccfb1a1349639943e1f408bea50':
  Drop unnecessary libavutil/x86/asm.h #includes

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-06-26 15:53:00 +02:00
Diego Biurrun 4f98bb7b6d msmpeg4: Remove commented-out debug logging code 2016-06-24 13:25:36 +02:00
Diego Biurrun eedbeb4c27 msmpeg4: Remove some broken, commented-out cruft 2016-06-24 13:25:36 +02:00
Clément Bœsch 8ef57a0d61 Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'
* commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb':
  cosmetics: Fix spelling mistakes

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-21 21:55:34 +02:00
Diego Biurrun dc40a70c57 Drop unnecessary libavutil/x86/asm.h #includes 2016-05-28 19:18:26 +02:00
Vittorio Giovara 41ed7ab45f cosmetics: Fix spelling mistakes
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2016-05-04 18:16:21 +02:00