Commit Graph

855 Commits

Author SHA1 Message Date
Andreas Rheinhardt ca3dea8a36 avcodec/h263dec, mpeg4videodec: Parse extradata during init
Possible now that the IDCT is already initialized at this point.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-05 22:05:21 +02:00
James Almer 3ceffe7839 avcodec: remove FF_API_FLAG_TRUNCATED
Signed-off-by: James Almer <jamrial@gmail.com>
2023-02-09 15:35:14 +01:00
James Almer 261cd929e0 avcodec/mpeg4videodec: duplicate the last decoded frame when the last coded frame was skipped
This ensures the video stream duration is not lost after decoding.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-12-12 18:30:17 -03:00
Michael Niedermayer b32316923d
avcodec/h263dec: Avoid parsing extradata repeatedly
Fixes: Timeout
Fixes: 52329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-4716563886637056

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-11-28 21:20:56 +01: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 33b838aad6 avcodec/mpegvideo: Move ASM-offset warning to its proper place
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-10-24 00:47:16 +02:00
Andreas Rheinhardt 7f45691769 avcodec/idctdsp: Move ScanTable to mpegvideo
Only used there.

Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-10-24 00:47:14 +02:00
Andreas Rheinhardt 5d93c330f7 avcodec/mpegvideo: Move sprite-related fields to Mpeg4DecContext
Only used there.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-10-20 07:56:17 +02:00
Andreas Rheinhardt 4209216ee8 avcodec/mpegvideodsp: Make MpegVideoDSP MPEG-4 only
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 <andreas.rheinhardt@outlook.com>
2022-10-20 07:56:17 +02:00
Andreas Rheinhardt 6fe4e8fab4 avcodec/mpegvideo: Split ff_mpv_reconstruct_mb() into de/encoder part
This has the advantage of not having to check for whether
a given MpegEncContext is actually a decoder or an encoder
context at runtime.

To do so, mpv_reconstruct_mb_internal() is moved into a new
template file that is included by both mpegvideo_enc.c
and mpegvideo_dec.c; the decoder-only code (mainly lowres)
are also moved to mpegvideo_dec.c. The is_encoder checks are
changed to #if IS_ENCODER in order to avoid having to include
headers for decoder-only functions in mpegvideo_enc.c.

This approach also has the advantage that it is easy to adapt
mpv_reconstruct_mb_internal() to using different structures
for decoders and encoders (e.g. the check for whether
a macroblock should be processed for the encoder or not
uses MpegEncContext elements that make no sense for decoders
and should not be part of their context).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-10-20 07:29:03 +02:00
Andreas Rheinhardt 85f02c300f avcodec/mpegvideo: Move VIDEO_FORMAT_* defines to mpeg12enc.c
Forgotten in f899e3b51b.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-10-20 06:57:30 +02:00
Andreas Rheinhardt 73ea6db0ba avcodec/mpegpicture: Move encoding_error and mb_var_sum to MpegEncCtx
These fields are only ever set by the encoder for the current picture
and for no other picture. So only one set of these values needs to
exist, so move them to MpegEncContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-10 18:49:35 +02:00
Andreas Rheinhardt bc109a53c7 avcodec/mpegpicture: Move mb_var, mc_mb_var and mb_mean to MpegEncCtx
These tables are only used by encoders and only for the current picture;
ergo they need not be put into the picture at all, but rather into
the encoder's context. They also don't need to be refcounted,
because there is only one owner.

In contrast to this, the earlier code refcounts them which
incurs unnecessary overhead. These references are not unreferenced
in ff_mpeg_unref_picture() (they are kept in order to have something
like a buffer pool), so that several buffers are kept at the same
time, although only one is needed, thereby wasting memory.

The code also propagates references to other pictures not part of
the pictures array (namely the copy of the current/next/last picture
in the MpegEncContext which get references of their own). These
references are not unreferenced in ff_mpeg_unref_picture() (the
buffers are probably kept in order to have something like a pool),
yet if the current picture is a B-frame, it gets unreferenced
at the end of ff_mpv_encode_picture() and its slot in the picture
array will therefore be reused the next time; but the copy of the
current picture also still has its references and therefore
these buffers will be made duplicated in order to make them writable
in the next call to ff_mpv_encode_picture(). This is of course
unnecessary.

Finally, ff_find_unused_picture() is supposed to just return
any unused picture and the code is supposed to work with it;
yet for the vsynth*-mpeg4-adap tests the result depends upon
the content of these buffers; given that this patchset
changes the content of these buffers (the initial content is now
the state of these buffers after encoding the last frame;
before this patch the buffers used came from the last picture
that occupied the same slot in the picture array) their ref-files
needed to be changed. This points to a bug somewhere (if one removes
the initialization, one gets uninitialized reads in
adaptive_quantization in ratecontrol.c).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-09 19:17:22 +02:00
Andreas Rheinhardt cee40a945a avcodec/mpegvideo_motion: Constify ff_mpv_motion
Also constify the corresponding code in mpegvideo.c that handles
lowres.
(Unfortunately, not everything that is const could be constified:
ref_picture could be made const uint8_t* const* if C allowed the
safe automatic conversion from uint8_t**; and pix_op, qpix_op
could be made to point to const function pointers, but C's handling
of const in pointers to arrays is broken.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-05 03:04:05 +02:00
Andreas Rheinhardt 145236741d avcodec/mpegvideo: Inline values in ff_update_block_index()
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>
2022-07-31 01:53:19 +02:00
Andreas Rheinhardt 8d788c567a avcodec/mjpegenc: Remove ineffective pred option
Never did anything, so it is removed immediately.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-24 21:38:16 +02:00
Andreas Rheinhardt d587b1c323 avcodec/mpegvideoenc: Remove ineffective options
This commit removes the ineffective FF_MPV_DEPRECATED_ options,
namely mpeg_quant (this is only an option for MPEG-4), a53cc
(this is only an option for MPEG-2), force_duplicated_matrix
(applies only to MJPEG) and b_strategy, b_sensitivity and brd_scale
(these options only make sense for encoders supporting B-frames,
which currently means the MPEG-1/2 and MPEG-4 encoders).
Given that these options never changed the outcome of encoding,
they are removed at once.

Notice that the options for the encoders for which it made sense
are not affected by this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-24 21:37:17 +02:00
Andreas Rheinhardt 2c8f97831a avcodec/mpegvideo: Move float.h inclusion to mpegvideoenc.h
It is only needed for the options in mpegvideoenc.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-19 19:16:23 +02:00
Andreas Rheinhardt 37250f7f64 avcodec/mpegvideo: Make new_picture an ordinary AVFrame
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>
2022-04-01 17:02:54 +02:00
Andreas Rheinhardt 88720f3d81 avcodec/mpegvideo: Remove strict_std_compliance from MpegEncContext
It just duplicates AVCodecContext.strict_std_compliance.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-01 16:51:32 +02:00
Andreas Rheinhardt 046736f342 avcodec/speedhqenc: Add SpeedHQEncContext and move slice_start to it
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-01 16:14:10 +02:00
Anton Khirnov be95df12bb lavc/mpeg*: drop the XvMC hwaccel code
XvMC was last relevant over 10 years ago, if ever. There is no reason to
use it today.
2022-02-15 10:16:15 +01:00
Andreas Rheinhardt 314e0a821e avcodec/mpegvideo: Constify src of ff_update_duplicate_context()
Also do the same for update_duplicate_context_after_me()
in mpegvideo_enc.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 19:49:29 +01:00
Andreas Rheinhardt 18e75f493d avcodec/mpegvideo: Remove write-only [fb]_code
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 19:49:29 +01:00
Andreas Rheinhardt 965cfc6684 avcodec/mpegvideo: Move decoder-only stuff to a new header
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 19:49:29 +01:00
Andreas Rheinhardt 746e7102be avcodec/mpegvideo: Move encoder-only stuff to a new header
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 19:49:29 +01:00
Andreas Rheinhardt 20033c7da4 avcodec/msmpegenc: Add MSMPEG4EncContext and move ac_stats to it
Also avoid the allocation by making it part of the context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 19:36:50 +01:00
Andreas Rheinhardt 725e2300af avcodec/mpegvideo: Enable private contexts
MpegEncContext is used by many different codecs and
every one of these uses just a subset of its fields.
If one tries to separate this and e.g. add a real MpegContext
and extension structures (say MpegDecContext and MpegEncContext),
one runs into two difficulties:

a) Some code is shared between decoder and encoder of
the same format and they therefore use the same contexts,
either MpegEncContext itself or identical extensions thereof.
The latter is the case for H.261 as well as WMV2.
b) In case of slice threading, the generic code can only allocate
and initialize the structure it knows about; right now this is
an MpegEncContext. If the codec has an even more extensive structure,
it is only available for the main thread's MpegEncContext.
Fixing this would involve making ff_mpv_common_init() aware
of the size the size of slice context to allocate and would be
part of separating the main thread's context from the slice contexts
in general.

This commit only intends to tackle the first issue by adding
a pointer to MpegEncContext that codecs can set to a common
context so that the aforementioned codecs can use this context
(together with the MpegEncContext) in their common code.
This will allow to move fields only used by the main thread
to more specialized contexts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-13 15:16:28 +01:00
Andreas Rheinhardt 24a654c6c9 avcodec/mpegvideo: Use offset instead of pointer for vbv_delay
An offset has the advantage of not needing to be updated
when the buffer is reallocated. Furthermore, the way the pointer
is currently updated is undefined behaviour in case the pointer
is not already set (i.e. when not encoding MPEG-1/2), because
it calculates the nonsense NULL - s->pb.buf.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt dcdb34be91 avcodec/mpegvideo: Move MPEG-4 Simple Studio Profile fields to mpeg4video
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>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt aeb83322aa avcodec/mpegvideo: Move frame_rate_index to (Mpeg1|MPEG12Enc)Context
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:24 +01:00
Andreas Rheinhardt 4bbfe02ca0 avcodec/mpegvideo: Move gop_picture_number to MPEG12EncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 18:34:31 +01:00
Andreas Rheinhardt 757be51ded avcodec/mpegvideo: Move timecode_frame_start to Mpeg1Context
It is only used there and only by the main thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 18:34:31 +01:00
Andreas Rheinhardt 01f60973a4 avcodec/mpegvideo: Move aspect_ratio_info to Mpeg1Context
Only used there and only by the main thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 18:34:31 +01:00
Andreas Rheinhardt 426d65e3e3 avcodec/mpeg4?video: Move vo_type to Mpeg4DecContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 18:34:30 +01:00
Andreas Rheinhardt 42d30c9019 avcodec/mpegvideo, svq3: Remove unused next_p_frame_damaged
Always zero since 4d2858deac.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:25:10 +01:00
Andreas Rheinhardt d83479bec1 avcodec/mpegvideo: Move decoding-only code into a new file
This will allow to disable this code altogether when
all decoders are disabled.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 16:28:55 +01:00
Andreas Rheinhardt f899e3b51b avcodec/mpeg12enc: Move options-related fields to MPEG12EncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 16:28:55 +01:00
Andreas Rheinhardt 4989ad4c76 avcodec/mpeg12enc: Add custom context, move mpeg2_frame_rate_ext to it
It is only used here.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 16:28:55 +01:00
Andreas Rheinhardt ac49439e77 avcodec/mpeg12enc: Simplify check for A53 closed captions
The a53_cc option is only useful and meaningful for MPEG-2,
yet it was accidentally added for all mpegvideo-based encoders.
This means that it is possible for a53_cc to be set for other
encoders as well.
This commit changes this and reroutes a53_cc to the dummy field
in MpegEncContext for all codecs for which it is not supported.
This allows to avoid a check for the current codec in mpeg12enc.c.

Also add a compile-time check for whether the MPEG-2 encoder is
available while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 16:28:55 +01:00
Andreas Rheinhardt 4707023a95 avcodec/mpegvideo: Remove unnecessary headers
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 16:28:54 +01:00
Andreas Rheinhardt 7aee9e326f avcodec/mjpegenc: Deprecate unused prediction type
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 16:28:54 +01:00
Andreas Rheinhardt bd2ec3d345 avcodec/mpegvideo: Move MJPEG/AMV-only fields to MJpegContext
This is possible now that MJpegContext is allocated jointly
with MpegEncContext as part of the AVCodecContext's private data.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 16:28:54 +01:00
Andreas Rheinhardt 9088cc6df9 avcodec/mpegvideo: Allocate several buffers jointly
Reduces the amount of allocations and frees.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-17 02:54:52 +01:00
Andreas Rheinhardt 81c6b8ffe8 avcodec/mpegvideo: Move closed_gop to Mpeg1Context
Only used there and only by the main thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-12-17 01:53:50 +01:00
Andreas Rheinhardt 8edf6c3bf1 avcodec/(h263|mpeg4?video)_parser: Make *_find_frame_end() static
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 00:20:15 +02:00
Anton Khirnov dd846bc4a9 lavc: deprecate AV_CODEC_(FLAG|CAP)_TRUNCATED
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>
2021-09-20 00:20:13 +02:00
Andreas Rheinhardt 9c489a0f3a avcodec/mpegvideo: Move startcodes to mpeg12.h
And remove the MPEG-4-specific SLICE_START_CODE, which duplicates
SLICE_STARTCODE.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 00:10:35 +02:00
Andreas Rheinhardt 34ff543672 avcodec/mpegvideo_enc: Deduplicate ff_mpv_generic_options-based AVClasses
The child_class_next API relied on different AVCodecs to use
different AVClasses; yet this API has been replaced by
child_class_iterate.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-08 20:10:17 +02:00
Andreas Rheinhardt 7c1f347b18 avcodec: Remove deprecated old encode/decode APIs
Deprecated in commits 7fc329e2dd
and 31f6a4b4b8.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:12 -03:00