1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-07 11:13:41 +02:00
Commit Graph

48860 Commits

Author SHA1 Message Date
Andreas Rheinhardt
ab95338a20 avcodec/mpeg4video_parser: Don't set write-only current_picture_ptr
It is unused by ff_mpeg4_decode_picture_header() (unsurprisingly given
that when decoding this function is called before the context has been
initialized).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-11 22:28:24 +02:00
Andreas Rheinhardt
b561dafd56 avcodec/h261dec: Discard whole packet when discarding
(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>
2023-10-11 22:28:24 +02:00
Andreas Rheinhardt
c995311bcf avcodec/h261dec: Don't set write-only picture_number
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-11 22:28:24 +02:00
John Mather
a2175ca861 avcodec/libkvazaar: Respect codec context color settings.
This patch makes the libkvazaar encoder respect color settings that are
present on the codec context, including color range, primaries, transfer
function and colorspace.
2023-10-11 21:50:47 +03:00
Paul B Mahol
44dc42e4ac avcodec/mlpenc: export lpc_coeff_precision option
Change default precision from 11 to 15, improves compression.
2023-10-10 13:53:11 +02:00
Paul B Mahol
394106a138 avcodec/mlpenc: fix regression in encoding only zeroes
Previously it would use more bits than neccessary.
2023-10-10 10:31:37 +02:00
Andreas Rheinhardt
9c1294eadd avcodec/vdpau_vc1: Fix indentation
Forgotten after af6e232ccf.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:22:55 +02:00
Andreas Rheinhardt
c77aee61b8 avcodec/mpeg(picture|video_dec): Move comment to more appropriate place
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:22:35 +02:00
Andreas Rheinhardt
52509f63ce avcodec/mpegpicture: Move caller-specific parts of function to callers
Since at least commit c954cf1e1b
(adding ff_encode_alloc_frame()), a large part of ff_alloc_picture()
is completely separate for the two callers. Move the caller-specific
parts out to the callers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:22:19 +02:00
Andreas Rheinhardt
2a8ac5a780 avcodec/mpegvideo_enc: Don't call av_frame_copy_props() unnecessarily
It is unnecessary in case of user-supplied frames, because
it happens directly after a av_frame_ref() with the same
src and dst.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:22:15 +02:00
Andreas Rheinhardt
22b0141d87 avcodec/mpegvideo_enc: Don't allocate buffers unnecessarily
ff_alloc_picture() performs two tasks: a) In most instances,
it allocates frame buffers and b) it allocates certain
auxiliary buffers.

The exception to a) is the case when the encoder can reuse
user-supplied frames. And for these frames the auxiliary buffers
are unused, because this frame will never be used as current_picture
(and therefore also not as next_picture or last_picture);
see select_input_picture().

This means that we can simply avoid calling ff_alloc_picture()
with user-supplied frames at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:21:48 +02:00
Andreas Rheinhardt
d87c358ee6 avcodec/mpegvideo_enc: Remove dead block
None of the mpegvideo encoders support anything but coded frames;
and if this were to change, it is unclear whether they would need
the adjustment here. So remove it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:21:46 +02:00
Andreas Rheinhardt
070bc4d2c5 avcodec/mpegvideo_enc: Don't set write-only properties
The frame is immediately reset in the ff_mpeg_unref_picture()
call below.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:21:40 +02:00
Andreas Rheinhardt
3937a21f21 avcodec/mpegvideo_enc: Don't overallocate arrays
Only entries 0..max_b_frames are ever used.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:21:20 +02:00
Andreas Rheinhardt
0524b4ec3e avcodec/mpegvideo_enc: Don't reget known values
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:20:57 +02:00
Andreas Rheinhardt
18f7d8d880 avcodec/mpegvideo_enc: Don't pretend input to be non-refcounted
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:20:44 +02:00
Andreas Rheinhardt
f5220475de avcodec/mpegvideo_enc: Reindentation
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:20:39 +02:00
Andreas Rheinhardt
5aaaa7dbee avcodec/mpegvideo_enc: Remove always-false checks
In case "!direct" we are not reusing the input buffers
(due to e.g. insufficient alignment), but allocating
new ones. These of course do not alias with the ones
provided by the user, so these checks are always-false.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:20:09 +02:00
Andreas Rheinhardt
b96ba62bdd avcodec/mpegvideo_enc: Fix abort on allocation errors
mpegvideo_enc uses a fixed-size array of Pictures; a slot is
considered taken if the Picture's AVFrame is set.
When an error happens after a slot has been taken, this Picture
has typically not been reset and is therefore not usable for
future requests. The code aborts when one runs out of slots
and this can happen in case of allocation failures.
Fix this by always unreferencing a Picture in case of errors.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-10 00:19:52 +02:00
Paul B Mahol
78fa1cff70 avcodec/mlpenc: export max_interval option 2023-10-09 23:48:00 +02:00
Paul B Mahol
ee9fb28429 avcodec/mlpenc: export codebook_search option too 2023-10-09 23:47:58 +02:00
Paul B Mahol
1703bfa133 avcodec/hcadec: implement proper .flush callback 2023-10-09 21:23:25 +02:00
Timo Rothenpieler
e006680d8e avcodec/nvenc: add option to control subsampling of packed rgb input 2023-10-09 20:17:44 +02:00
Rémi Denis-Courmont
3c6516330f lavc/exrdsp: R-V V reoder_pixels 2023-10-09 19:52:51 +03:00
Paul B Mahol
8786b91607 avcodec/mlpenc: change flag for shorten_by in THD case 2023-10-09 18:42:43 +02:00
Paul B Mahol
27c623b3d5 avcodec/mlpenc: fix stereo decorrelation 2023-10-09 18:42:42 +02:00
Andreas Rheinhardt
12c4cf9f72 avcodec/refstruct: Inline ff_refstruct_allocz()
Suggested by James Almer.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-09 15:54:09 +02:00
Andreas Rheinhardt
fc880c7032 avcodec/h261dec: Remove pointless goto
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>
2023-10-09 15:53:06 +02:00
Andreas Rheinhardt
cae30c5ed2 avcodec/wmv2dec: Parse extradata during init
And stop setting picture_number which was only done to not parse
extradata multiple times.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-09 15:52:23 +02:00
Michael Niedermayer
7fedbc7606
avcodec/h264_parser: saturate dts a bit
Fixes: signed integer overflow: 0 - -9223372036854775808 cannot be represented in type 'long'
Fixes: 51896/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-6112289464123392

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-10-08 21:36:09 +02:00
Andreas Rheinhardt
c7fb4d0eb6 avcodec/nvdec: Use RefStruct API for decoder_ref
Avoids allocations and error checks as well as the boilerplate
code for creating an AVBuffer with a custom free callback.
Also increases type safety.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Tested-by: Timo Rothenpieler <timo@rothenpieler.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:36:21 +02:00
Andreas Rheinhardt
2ec62b1ca6 avcodec/pthread_frame: Use RefStruct API for ThreadFrame.progress
Avoids allocations and error checks and allows to remove
cleanup code for earlier allocations. Also avoids casts
and indirections.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:36:04 +02:00
Andreas Rheinhardt
452089ee23 avcodec/hevcdec: Use RefStruct API for RefPicListTab buffer
Given that the RefStruct API relies on the user to know
the size of the objects and does not provide a way to get it,
we need to store the number of elements allocated ourselves;
but this is actually better than deriving it from the size
in bytes.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:35:56 +02:00
Andreas Rheinhardt
6695c0af0e avcodec/vulkan_decode: Use RefStruct API for shared_ref
Avoids allocations, error checks and indirections.
Also increases type-safety.

Reviewed-by: Lynne <dev@lynne.ee>
Tested-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:35:50 +02:00
Andreas Rheinhardt
f8252d6ce3 avcodec/decode: Use RefStruct API for hwaccel_picture_private
Avoids allocations and therefore error checks: Syncing
hwaccel_picture_private across threads can't fail any more.
Also gets rid of an unnecessary pointer in structures and
in the parameter list of ff_hwaccel_frame_priv_alloc().

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Reviewed-by: Lynne <dev@lynne.ee>
Tested-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:35:22 +02:00
Andreas Rheinhardt
3ba4f9c21e avcodec/cbs_sei: Use RefStruct API for SEI messages
The SEI message code uses the AVBuffer API for its SEI messages
and contained buffers (like the extension buffer for HEVC
or the user data (un)registered payload buffers).

Contrary to the ordinary CBS code (where some of these
contained buffer references are actually references
to the provided AVPacket's data so that one can't replace
them with the RefStruct API), the CBS SEI code never uses
outside buffers at all and can therefore be switched entirely
to the RefStruct API. This avoids the overhead inherent
in the AVBuffer API (namely the separate allocations etc.).

Notice that the refcounting here is actually currently unused;
the refcounts are always one (or zero in case of no refcounting);
its only advantage is the flexibility provided by custom
free functions.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:35:14 +02:00
Andreas Rheinhardt
3e9b8d14e5 avcodec/cbs: Use RefStruct-API for unit content
This avoids allocations and error checks etc. as well
as duplicate pointer lists in the CodedBitstreamFooContexts.
It also avoids casting const away for use as opaque,
as the RefStruct API supports const opaques.

The fact that some of the units are not refcounted
(i.e. they are sometimes part of an encoding context
like VAAPIEncodeH264Context) meant that CodedBitstreamUnit
still contains two pointers, one to the content
and another ownership pointer, replacing the AVBufferRef* pointer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:35:05 +02:00
Andreas Rheinhardt
56dd585146 avcodec/refstruct: Allow checking for exclusive ownership
This is the analog of av_buffer_is_writable();
it will be used in the next commit.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:57 +02:00
Andreas Rheinhardt
61bc8764d4 avcodec/dovi_rpu: Use RefStruct API for Vdr data
It avoids allocations and the corresponding error checks.
Also avoids casts and indirections.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:49 +02:00
Andreas Rheinhardt
05f557b259 avcodec/wavpack: Use RefStruct API for DSD context
It avoids allocations and the corresponding error checks.
It also avoids indirections and casts.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:43 +02:00
Andreas Rheinhardt
e1ba00ac8f avcodec/vp8: Use RefStruct API for seg_map
Avoids allocations and error checks when syncing the buffers.
Also avoids indirections.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:36 +02:00
Andreas Rheinhardt
2db94a96c8 avcodec/hevc_ps: Use RefStruct API for parameter sets
Avoids allocations and error checks for these allocations;
e.g. syncing buffers across threads can't fail any more
and needn't be checked. It also gets rid of casts and
indirections.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:28 +02:00
Andreas Rheinhardt
787351a68e avcodec/h264_ps: Use RefStruct API for SPS/PPS
Avoids allocations and error checks for these allocations;
e.g. syncing buffers across threads can't fail any more
and needn't be checked. It also avoids having to keep
H264ParamSets.pps and H264ParamSets.pps_ref and PPS.sps
and PPS.sps_ref in sync and gets rid of casts and indirections.

(The removal of these checks and the syncing code even more
than offset the additional code for RefStruct.)

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:20 +02:00
Andreas Rheinhardt
78c9ed26b6 avcodec/get_buffer: Use RefStruct API for FramePool
Avoids allocations and frees and error checks for said allocations;
also avoids a few indirections and casts.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:10 +02:00
Andreas Rheinhardt
9281dcb801 avcodec/refstruct: Add simple API for refcounted objects
For now, this API is supposed to replace all the internal uses
of reference counted objects in libavcodec; "internal" here
means that the object is created in libavcodec and is never
put directly in the hands of anyone outside of it.

It is intended to be made public eventually, but for now
I enjoy the ability to modify it freely.

Several shortcomings of the AVBuffer API motivated this API:
a) The unnecessary allocations (and ensuing error checks)
when using the API. Besides the need for runtime checks it
imposes upon the developer the burden of thinking through
what happens in case an error happens. Furthermore, these
error paths are typically not covered by FATE.
b) The AVBuffer API is designed with buffers and not with
objects in mind: The type for the actual buffers used
is uint8_t*; it pretends to be able to make buffers
writable, but this is wrong in case the buffer is not a POD.
Another instance of this thinking is the lack of a reset
callback in the AVBufferPool API.
c) The AVBuffer API incurs unnecessary indirections by
going through the AVBufferRef.data pointer. In case the user
tries to avoid this indirection and stores a pointer to
AVBuffer.data separately (which also allows to use the correct
type), the user has to keep these two pointers in sync
in case they can change (and in any case has two pointers
occupying space in the containing context). See the following
commit using this API for H.264 parameter sets for an example
of the removal of such syncing code as well as the casts
involved in the parts where only the AVBufferRef* pointer
was stored.
d) Given that the AVBuffer API allows custom allocators,
creating refcounted objects with dedicated free functions
often involves a lot of boilerplate like this:
obj = av_mallocz(sizeof(*obj));
ref = av_buffer_create((uint8_t*)obj, sizeof(*obj), free_func, opaque, 0);
if (!ref) {
    av_free(obj);
    return AVERROR(ENOMEM);
}
(There is also a corresponding av_free() at the end of free_func().)
This is now just
obj = ff_refstruct_alloc_ext(sizeof(*obj), 0, opaque, free_func);
if (!obj)
    return AVERROR(ENOMEM);
See the subsequent patch for the framepool (i.e. get_buffer.c)
for an example.

This API does things differently; it is designed to be lightweight*
as well as geared to the common case where the allocator of the
underlying object does not matter as long as it is big enough and
suitably aligned. This allows to allocate the user data together
with the API's bookkeeping data which avoids an allocation as well
as the need for separate pointers to the user data and the API's
bookkeeping data. This entails that the actual allocation of the
object is performed by RefStruct, not the user. This is responsible
for avoiding the boilerplate code mentioned in d).

As a downside, custom allocators are not supported, but it will
become apparent in subsequent commits that there are enough
usecases to make it worthwhile.

Another advantage of this API is that one only needs to include
the relevant header if one uses the API and not when one includes
the header or some other component that uses it. This is because there
is no RefStruct type analog of AVBufferRef. This brings with it
one further downside: It is not apparent from the pointer itself
whether the underlying object is managed by the RefStruct API
or whether this pointer is a reference to it (or merely a pointer
to it).

Finally, this API supports const-qualified opaque pointees;
this will allow to avoid casting const away by the CBS code.

*: Basically the only exception to the you-only-pay-for-what-you-use
rule is that it always uses atomics for the refcount.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:33:32 +02:00
Paul B Mahol
84e0e2f43e avcodec/mlpenc: rename some variables related to thd
Remove warning message that is no longer needed.
2023-10-07 11:19:53 +02:00
Andreas Rheinhardt
4c422de1db avcodec/mpegvideo: Move allocating new_picture to the encoder
It is only used by encoders; this unfortunately necessitated
to add separate allocations to the SVQ1 encoder which uses
motion estimation without being a full member of mpegvideo.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-06 20:47:53 +02:00
James Almer
ae22271620 avcodec/decode: propagate global side data to frames
The changed references for fate-hevc-dv-rpu fate-mov-zombie happen because,
unlike ffmpeg and ffplay, ffprobe never injected packet side data, so the
display matrix side data at the container level is now present in the output
frames.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:11:18 -03:00
James Almer
804be7f9e3 avcodec/hevcdec: check for DOVI configuration record in AVCodecContext side data
Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:11:18 -03:00
James Almer
e500eb5a95 avcodec/packet: add some documentation for AVPacketSideData
Explaining what or who may use it, and in what scenarios.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:04:02 -03:00