Commit Graph

234 Commits

Author SHA1 Message Date
Vittorio Giovara
548aeb9383 lavc: switch to the new channel layout API
Since the request_channel_layout is used only by a handful of codecs,
move the option to codec private contexts.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-15 09:42:39 -03:00
Andreas Rheinhardt
70a90fb73e avcodec/internal.h: Move avpriv_find_start_code() to startcode.h
This is by definition the appropriate place for it.
Remove all the now unnecessary libavcodec/internal.h inclusions;
also remove other unnecessary headers from the affected files.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 06:22:14 +01:00
Anton Khirnov
37e70d4802 lavc/avcodec: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Andreas Rheinhardt
b74e47c4ff avcodec/utils: Unavpriv avpriv_toupper4()
This function is quite small (96B with GCC 11.2 on x64 Ubuntu 21.10
at -O3), making it more economical to duplicate it into libavformat
instead of exporting it as avpriv: Doing so saves 2x24B in .dynsim,
2x16B in .dynstr, 2x2B .gnu.version, 24B in .rela.plt, 16B in .plt,
16B in .plt.sec (if enabled), 4B .gnu.hash; besides the actual
duplicated code this also adds 2x8B .eh_frame_hdr and 24B .eh_frame.

In other words: Duplicating is neutral size-wise (it is also presumed
neutral for other systems). Given that it avoids the runtime
overhead of dynamic symbols, it is advantageouos to duplicate the
function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 13:16:50 +01:00
Andreas Rheinhardt
007ffbeb53 avcodec/internal: Remove unused av_export_avcodec
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-04 13:16:50 +01:00
Andreas Rheinhardt
ffdda740fe avcodec/internal: Allow receive_frame codecs to use decode_simple pkt
Decoders implementing the receive_frame API currently mostly use
stack packets to temporarily hold the packet they receive from
ff_decode_get_packet(). This role directly parallels the role of
in_pkt, the spare packet used in decode_simple_internal for the
decoders implementing the traditional decoding API. Said packet
is unused by the generic code for the decoders implementing the
receive_frame API, so allow them to use it to fulfill the function
it already fulfills for the traditional API for both APIs.

There is only one caveat in this: The packet is automatically
unreferenced in avcodec_flush_buffers(). But this is actually
positive as it means the decoders don't have to do this themselves
(in case the packet is preserved between receive_frame calls).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-11-07 17:12:58 +01:00
Andreas Rheinhardt
3f11eac757 avcodec/encode: Set AV_PKT_FLAG_KEY based upon AV_CODEC_PROP_INTRA_ONLY
Currently, the AV_PKT_FLAG_KEY is automatically set for audio encoders;
yet this is wrong, as both MLP and TrueHD have non-keyframes. So set it
based upon AV_CODEC_PROP_INTRA_ONLY (from the corresponding
AVCodecDescriptor) instead. This also sets it for some video codecs,
which is intended.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-28 01:56:32 +02:00
Andreas Rheinhardt
78ec2f3bd7 avcodec/internal: Update AVCodecInternal.is_copy documentation
Forgotten in 1f4cf92cfb.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-26 13:29:29 +02:00
Andreas Rheinhardt
549502868d Move ff_tlog() from lavc/internal.h to lavu/internal.h
It is also used by libavfilter and it is only natural to define it
alongside ff_dlog().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-05 20:02:35 +02:00
Andreas Rheinhardt
57b5ec6ba7 avcodec/avcodec: Stop including bsf.h in avcodec.h
Also include bsf.h directly wherever it is used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-22 11:14:16 +02:00
James Almer
7b9610ebd8 avcodec/decode: add an internal codec flag to signal a decoder sets all output frame properties
Decoders like cuviddec ignore and overwrite all the properties set by the generic
code as derived from AVCodecInternal.last_pkt_props. This flag ensures libavcodec
will not store and potentially queue input packets that ultimately will not be used.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-06-21 15:03:52 -03:00
Andreas Rheinhardt
56e9e0273a avcodec/encode: Always use intermediate buffer in ff_alloc_packet2()
Up until now, ff_alloc_packet2() has a min_size parameter:
It is supposed to be a lower bound on the final size of the packet
to allocate. If it is not too far from the upper bound (namely,
if it is at least half the upper bound), then ff_alloc_packet2()
already allocates the final, already refcounted packet; if it is
not, then the packet is not refcounted and its data only points to
a buffer owned by the AVCodecContext (in this case, the packet will
be made refcounted in encode_simple_internal() in libavcodec/encode.c).
The goal of this was to avoid data copies and intermediate buffers
if one has a precise lower bound.

Yet those encoders for which precise lower bounds exist have recently
been switched to ff_get_encode_buffer() (which automatically allocates
final buffers), leaving only two encoders to actually set the min_size
to something else than zero (namely aliaspixenc and hapenc). Both of
these encoders use a very low lower bound that is not helpful in any
nontrivial case.

This commit therefore removes the min_size parameter as well as the
codepath in ff_alloc_packet2() for the allocation of final buffers.
Furthermore, the function has been renamed to ff_alloc_packet() and
moved to encode.h alongside ff_get_encode_buffer().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-06-08 12:52:50 +02:00
Andreas Rheinhardt
4e5d2a819c avcodec/internal: Remove outdated documentation of ff_alloc_packet2()
Its documentation described the way user-supplied buffers worked
before 93016f5d1d.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-06-08 12:52:49 +02:00
Andreas Rheinhardt
29f5c1e51b avcodec/avcodec: Store whether AVCodec->close needs to be called
Right now all AVCodecContexts except those using frame-threaded decoding
call the codec's init function and expect its close function to be
called. In order to make sure that the close function is not called for
frame-threaded decoding ff_frame_thread_free() resets
AVCodecContext.codec (and because of this it has to free the private
AVOptions of the main AVCodecContext itself). This is not obvious and
potentially fragile. Instead add a field to AVCodecInternal that
indicates whether close should be called for this AVCodecContext.
It is always zero when using frame-threaded decoding, so that resetting
the codec is no longer necessary and has been removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-04-28 02:03:15 +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
Anton Khirnov
8a129077cc lavc: replace internal use of AV_CODEC_CAP_AUTO_THREADS with an internal cap
AV_CODEC_CAP_AUTO_THREADS was originally added in b4d44a45f9 to mark
codecs that spawn threads internally and are able to select an optimal
threads count by themselves (all such codecs are wrappers around
external libraries). It is used by lavc generic code to check whether it
should handle thread_count=0 itself or pass the zero directly to the
codec implementation. Within this meaning, it is clearly supposed to be
an internal cap rather than a public one, since from the viewpoint of a
libavcodec user, lavc ALWAYS handles thread_count=0. Whether it happens
in the generic code or within the codec internals is not a meaningful
difference for the caller.

External aspects of this flag will be dealt with in the following
commit.
2021-03-16 10:34:29 +01:00
James Almer
b34d1de8dc avcodec/decode: port last_pkt_props to AVFifoBuffer
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-03 13:10:27 -03:00
Anton Khirnov
9e30859cb6 lavc: shedule old encoding/decoding API for removal
It has been deprecated for 4 years and certain new codecs do not work
with it.

Also include AVCodecContext.refcounted_frames, as it has no effect with
the new API.
2021-01-26 17:05:58 +01:00
Andreas Rheinhardt
5766c8e968 avcodec/utils: Remove ff_codec_open2_recursive()
This function existed to enable codecs with non-threadsafe init functions
to initialize other codecs despite the fact that normally no two codecs
with non-threadsafe init functions can be initialized at the same time
(there is a mutex guarding this). Yet there are no users of this
function any more as all users have been made thread-safe (switching
away from ff_codec_open2_recursive() was required for this as said
function requires the caller to hold the lock to the mutex guarding the
initializations and this is only true for codecs with the
FF_CODEC_CAP_INIT_THREADSAFE flag unset); so remove it.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-04 15:46:46 +01:00
Anton Khirnov
0438521888 lavc: un-avpriv avpriv_bprint_to_extradata()
It has not been used outside of lavc since 6f69f7a8bf.

Also, move it to the only place where it is used.
2020-10-28 13:53:23 +01:00
James Almer
022a12b306 avcodec/decode: use a packet list to store packet properties
Keeping only the latest packet fed to the decoder works only for decoders that
return a frame immediately after every consumed packet. Decoders that consume
several packets before they return a frame will fill said frame with properties
taken from the last consumed packet instead of the earliest.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-15 09:53:39 -03:00
James Almer
c56d787fe3 avcodec/decode: move the ff_decode_frame_props() prototype to the proper header
Signed-off-by: James Almer <jamrial@gmail.com>
2020-08-20 13:17:50 -03:00
Limin Wang
d7af6d1469 avcodec/utils: calculate frame number of HEVC if the framerate > 30FPS
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-08-16 22:51:11 +08:00
James Almer
0de01da1d2 avcodec: move ff_alloc_a53_sei() to atsc_53
Signed-off-by: James Almer <jamrial@gmail.com>
2020-08-15 13:01:25 -03:00
James Almer
6b57d4d9eb avcodec/internal: remove unused out_frame field from DecodeSimpleContext
It was introduced in 061a0c14bb but apparently never used

Signed-off-by: James Almer <jamrial@gmail.com>
2020-07-01 00:00:51 -03:00
Limin Wang
9294f5b497 avcodec/utils: add ff_alloc_timecode_sei() for hevc timecode sei
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-28 21:00:52 +08:00
James Almer
93016f5d1d avcodec/encode: restructure the old encode API
Following the same logic as 061a0c14bb, this commit turns the old encode API
into a wrapper for the new one.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-18 17:11:37 -03:00
James Almer
827d6fe73d avcodec/encode: restructure the core encoding code
This commit follows the same logic as 061a0c14bb, but for the encode API: The
new public encoding API will no longer be a wrapper around the old deprecated
one, and the internal API used by the encoders now consists of a single
receive_packet() callback that pulls frames as required.

amf encoders adapted by James Almer
librav1e encoder adapted by James Almer
nvidia encoders adapted by James Almer
MediaFoundation encoders adapted by James Almer
vaapi encoders adapted by Linjie Fu
v4l2_m2m encoders adapted by Andriy Gelman

Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-18 17:11:37 -03:00
James Almer
6e1903938b avcodec/internal: move packet related functions to their own header
Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-02 19:02:12 -03:00
Andreas Rheinhardt
f02b1b1222 avcodec/encode: Remove ff_alloc_packet
It is no longer used anymore.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-06-01 14:52:26 +02:00
James Almer
6dd5da3f8b avcodec/decode: remove unused AVCodecInternal compat_decode field
Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-09 21:02:20 -03:00
Marton Balint
c96904f525 avcodec/decode: use a single list bsf for codec decode bsfs
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-02 19:14:08 +02:00
Anton Khirnov
9d6785d426 lavc: do not implicitly share the frame pool between threads
Currently the frame pool used by the default get_buffer2()
implementation is a single struct, allocated when opening the decoder.
A pointer to it is simply copied to each frame thread and we assume that
no thread attempts to modify it at an unexpected time. This is rather
fragile and potentially dangerous.

With this commit, the frame pool is made refcounted, with the reference
being propagated across threads along with other context variables. The
frame pool is now also immutable - when the stream parameters change we
drop the old reference and create a new one.
2020-04-10 15:47:30 +02:00
Anton Khirnov
665e5b0fba lavc: replace AVCodecInternal.allocate_progress with an internal cap
This is a constant codec property, so a capability flag is more appropriate.
2020-04-10 14:16:39 +02:00
Michael Kuron
bf070a9171 lavc/dvdsubdec: Move palette parsing to new function
Signed-off-by: Michael Kuron <michael.kuron@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-02-04 23:34:22 +01:00
Michael Niedermayer
550a6b4212 avcodec/avcodec: Add codec_tags array to AVCodec
This allows the fuzzer to target meaningfull codec tags instead
of hunting the 4gb space, which it seems to have problems with.

Suggested-by: James
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-22 21:50:49 +01:00
James Almer
717b2074ec avcodec: add a Producer Reference Time AVPacketSideData type
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:33:41 -03:00
James Almer
9ea6d2149e avcodec/decode: add a flags parameter to ff_reget_buffer()
Some decoders may not need a writable buffer in some specific cases, but only
a reference to the existing buffer with updated frame properties instead, for
the purpose of returning duplicate frames. For this, the
FF_REGET_BUFFER_FLAG_READONLY flag is added, which will prevent potential
allocations and buffer copies when they are not needed.

Signed-off-by: James Almer <jamrial@gmail.com>
2019-09-04 10:07:12 -03:00
Michael Niedermayer
d7866bf527 avcodec/internal: Bump sane_nb_chanels
This allows decoding more als reference samples

Suggested-by: Thilo Borgmann <thilo.borgmann@mail.de>
Reviewed-by: Thilo Borgmann <thilo.borgmann@mail.de>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-08-21 01:21:27 +02:00
Gyan Doshi
3153a6502a avcodec: add AV_CODEC_FLAG_DROPCHANGED to flags
Discard decoded frames which differ from first decoded frame in stream.
2019-04-20 10:38:01 +05:30
Martin Vignali
e53901ba5e avcodec/utils : add ff_int_from_list_or_default func
to check valid value, or return default_value
2018-12-04 15:17:21 +01:00
Marton Balint
3e0f3be2b0 avcodec/internal: increase FF_SANE_NB_CHANNELS to 256
This was reduced from 128 in libav commit
192f1984b1, but since we support unknown channel
layouts, we can increase this limit.

Fixes ticket #6332.

Signed-off-by: Marton Balint <cus@passwd.hu>
2018-07-13 22:24:33 +02:00
James Almer
23e1bf6e51 avcodec: remove unnecessary calls to ff_init_buffer_info()
And remove the function altogether while at it. It's a duplicate of
another.

Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-14 20:54:20 -03:00
wm4
4ed66517c6 lavc: remove complex debug code around avcodec init locking
This is just a lot of complicated and confusing code that had no purpose
anymore.

Also, the functions return values were checked only sometimes. Locking
shouldn't fail anyway, so remove the return values. Barely any other
pthread lock calls check the return value (including more important code
that is more likely to fail horribly if locking fails).

It could be argued that it might be helpful in some debugging
situations, or when the user built FFmpeg without thread support against
all good advice.

But there are dummy atomics too, so the atomic check won't help with
ensuring correctness absolutely. You gain very little.

Also, for debugging, you can just raise the ASSERT_LEVEL, and then
libavutil/thread.h will redefine the locking functions to explicitly
check the return values.
2017-12-26 02:50:00 +01:00
wm4
86a13bf2ff lavc, lavf: move avformat static mutex from avcodec to avformat
It's completely absurd that libavcodec would care about libavformat
locking, but it was there because the lock manager was in libavcodec.

This is more stright forward. Changes ABI, but we don't require ABI
compatibility currently.
2017-12-26 02:50:00 +01:00
James Darnley
8f86e66238 avcodec: add stride alignment needed for AVX-512 2017-12-24 22:02:41 +01:00
Hendrik Leppkes
fd542b6f20 Revert "libavcodec/utils.c: simplify avcodec locking with atomics"
This reverts commit 590136e78d.

Atomics are not required for this variable, because it is protected
through the lock manager, and the use of atomics here is not compatible
with the c11 emulation wrappersi.

Fixes FATE on MSVC, among other setups which use the compat wrappers.
2017-12-11 21:16:06 +01:00
Mark Thompson
67e81d79cc lavc: Use hardware config information in ff_get_format()
This removes the dependency that hardware pixel formats previously had on
AVHWAccel instances, meaning only those which actually do something need
exist after this patch.

Also updates avcodec_default_get_format() to be able to choose hardware
formats if either a matching device has been supplied or no additional
external configuration is required, and avcodec_get_hw_frames_parameters()
to use the hardware config rather than searching the old hwaccel list.

The FF_CODEC_CAP_HWACCEL_REQUIRE_CLASS mechanism is deleted because it
no longer does anything (the codec already contains the pointers to the
matching hwaccels).
2017-11-26 21:35:53 +00:00
Rostislav Pehlivanov
590136e78d libavcodec/utils.c: simplify avcodec locking with atomics
Also makes it more robust than using volatiles.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2017-11-26 02:17:23 +00:00
James Almer
c9cd990dcc Merge commit '3152058bf1dca318898550efacf0286f4836cae6'
* commit '3152058bf1dca318898550efacf0286f4836cae6':
  libavcodec: Don't use dllexport, only dllimport when building DLLs

Merged-by: James Almer <jamrial@gmail.com>
2017-11-19 18:26:45 -03:00