Commit Graph

50 Commits

Author SHA1 Message Date
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
b9eaf77ed1 avcodec/internal: Move ff_set_dimensions() to decode.h
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>
2022-08-27 14:14:57 +02:00
Andreas Rheinhardt
b6a680989c avcodec/internal: Move ff_set_sar() to decode.h
Only used by decoders, as the SAR has to be set by the user
when encoding.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-27 14:14:56 +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
ManojGuptaBonda
a44fba0b5b AV1 VDPAU hwaccel Decode support
Support for VDPAU accelerated AV1 decoding was added with libvdpau-1.5.
Support for the same in ffmpeg is added with this patch. Profiles
related to VDPAU AV1 can be found in latest vdpau.h present in
libvdpau-1.5.

Add AV1 VDPAU to list of hwaccels and supported formats
Added file vdpau_av1.c and Modified configure to add VDPAU AV1 support.
Mapped AV1 profiles to VDPAU AV1 profiles. Populated the codec specific
params that need to be passed to VDPAU.

Signed-off-by: Philip Langdale <philipl@overt.org>
2022-06-25 09:05:58 +08: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
ce7dbd0481 avcodec/codec_internal: Make FFCodec.decode use AVFrame*
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>
2022-04-05 19:54:09 +02:00
James Almer
b65ce7bed8 Revert "avcodec/av1dec: Check tile_cols"
This reverts commit 4fdfe430c1.

The previous commit ensures this field will never be zero.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-23 12:03:57 -03:00
James Almer
5670eddf8c avcodec/av1: only set the private context pix_fmt field if get_pixel_format() succeeds
Otherwise get_pixel_format() will not be called when parsing a subsequent Sequence
Header in non hwaccel enabled scenarios, allowing frame parsing when it shouldn't.

This prevents the scenario seqhdr -> frame_hdr/redundant_frame_hdr -> seqhdr ->
redundant_frame_hdr from having the latter redundant frame header parsed as if it
was a frame header by the decoder because the former was discarded.
Since CBS did not discard it, the latter redundant frame header is output with a
zeroed AV1RawFrameHeader struct, which can have undesired results, like division
by zero with fields normally guaranteed to be anything else.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-23 12:03:57 -03:00
Michael Niedermayer
4fdfe430c1 avcodec/av1dec: Check tile_cols
Fixes: division by zero
Fixes: 43769/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AV1_fuzzer-5392562205097984
Fixes: 43950/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AV1_fuzzer-5769210217758720

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-21 22:27:14 +01: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
02220b88fc avcodec/thread: Don't use ThreadFrame when unnecessary
The majority of frame-threaded decoders (mainly the intra-only)
need exactly one part of ThreadFrame: The AVFrame. They don't
need the owners nor the progress, yet they had to use it because
ff_thread_(get|release)_buffer() requires it.

This commit changes this and makes these functions work with ordinary
AVFrames; the decoders that need the extra fields for progress
use ff_thread_(get|release)_ext_buffer() which work exactly
as ff_thread_(get|release)_buffer() used to do.

This also avoids some unnecessary allocations of progress AVBuffers,
namely for H.264 and HEVC film grain frames: These frames are not
used for synchronization and therefore don't need a ThreadFrame.

Also move the ThreadFrame structure as well as ff_thread_ref_frame()
to threadframe.h, the header for frame-threaded decoders with
inter-frame dependencies.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 17:22:35 +01:00
James Almer
4b053b8db1 avcodec/av1dec: honor the requested skip_frame level
This supports dropping non-intra, non-key, or all frames.

Tested-by: nevcairiel
Signed-off-by: James Almer <jamrial@gmail.com>
2022-01-11 09:51:58 -03:00
Fei Wang
7787cca180 lavc/av1dec: use frame split bsf
Split packed data in case of its contains multiple show frame in some
non-standard bitstream. This can benefit decoder which can decode
continuously instead of interrupt with unexpected error.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-01-07 14:05:58 +08:00
Fei Wang
de7475b111 avcodec/av1dec: support setup shear process
Defined in spec 7.11.3.6/7.11.3.7.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
2021-10-16 19:00:44 -03:00
James Almer
9b05263ac1 avcodec/av1: signal the presence of Film Grain in the decoder context
Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-24 10:00:20 -03: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
James Almer
5f9632e491 avcodec/av1dec: add an option to select an operating point
Signed-off-by: James Almer <jamrial@gmail.com>
2021-01-04 16:28:29 -03:00
Andreas Rheinhardt
2c6f532e0a Mark some pointers as const
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-01-01 15:25:48 +01:00
James Almer
1a8e719f36 avcodec/av1dec: support exporting Film Grain params as frame side data
Signed-off-by: James Almer <jamrial@gmail.com>
2020-12-16 13:34:11 -03:00
Philip Langdale
67bb11b5f6 avcodec/nvdec: Add support for decoding monochrome av1
The nvidia hardware explicitly supports decoding monochrome content,
presumably for the AVIF alpha channel. Supporting this requires an
adjustment in av1dec and explicit monochrome detection in nvdec.

I'm not sure why the monochrome path in av1dec did what it did - it
seems non-functional - YUV440P doesn't seem a logical pix_fmt for
monochrome and conditioning on chroma sub-sampling doesn't make sense.
So I changed it.

I've tested 8bit content, but I haven't found a way to create a 10bit
sample, so that path is untested for now.
2020-12-06 14:59:24 -08:00
Andreas Rheinhardt
e546d02919 avcodec/av1dec: Fix leak in case of failure
A reference to an AV1RawFrameHeader and consequently the
AV1RawFrameHeader itself and everything it has a reference to leak
if the hardware has no AV1 decoding capabilities or if some other error
happens. It happens e.g. in the cbs-av1-av1-1-b8-02-allintra FATE-test;
it has just been masked because the return value of ffmpeg (which
indicates failure when using Valgrind or ASAN) is ignored when doing
tests of type md5.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-05 00:29:09 +01:00
James Almer
eee7ba8dba avcodec/av1dec: infer and store film grain param values in AV1Frame
They are not always coded in the bistream for each frame. In some cases, the
values need to be taken from a reference frame.

See section 6.8.20 from the AV1 spec.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-11-30 19:12:39 -03:00
Jan Ekström
8fbc139e61 avcodec/av1{dec,parser}: move to ff_cbs_read_extradata_from_codec
This lets us re-utilize the extradata-related checks in the CBS
to add support for passing the AV1CodecConfigurationRecord
as extradata as-is without further filtering.
2020-11-24 10:13:55 +02:00
James Almer
5d4a6bbd4b avcodec/av1dec: remove order_hint from AV1Frame
We now have access to the raw frame header, so use that

Signed-off-by: James Almer <jamrial@gmail.com>
2020-11-13 10:38:18 -03:00
James Almer
f5517be32a avcodec/av1dec: add a reference to the raw frame header to AV1Frames
Signed-off-by: James Almer <jamrial@gmail.com>
2020-11-13 10:38:18 -03:00
Hendrik Leppkes
8f4aec719e avcodec/dxva2: add AV1 decode support
Signed-off-by: Hendrik Leppkes <h.leppkes@gmail.com>
2020-11-12 15:55:16 +01:00
Timo Rothenpieler
ac5b45abab avcodec/nvdec: add av1 hwaccel
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
Co-authored-by: James Almer <jamrial@gmail.com>
2020-11-11 18:36:09 +01:00
Timo Rothenpieler
5868f1c66b avcodec/av1dec: expose coded_lossless
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
Co-authored-by: James Almer <jamrial@gmail.com>
2020-11-11 18:36:09 +01:00
Timo Rothenpieler
e1efff8906 avcodec/av1dec: expose skip mode frame index
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
Co-authored-by: James Almer <jamrial@gmail.com>
2020-11-11 18:36:09 +01:00
Fei Wang
3308bbf776 avcodec: add av1 VAAPI decoder
Example cmdline:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -v verbose \
-c:v av1 -i input.ivf -pix_fmt yuv420p -vsync passthrough -f md5     \
-y out.md5

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
2020-11-02 22:57:23 +00:00
James Almer
fec1b4738f avcodec/av1dec: fix loading PrevGmParams for frames with primary_ref_frame none
Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-10-28 11:26:25 -03:00
James Almer
7dac8ddb20 avcodec/av1dec: don't derive loop filter delta parameters
This is now handled by CBS.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-10-28 11:26:25 -03:00
Michael Niedermayer
718e862da3 avcodec/av1dec: Check for unset obu instead of crashing
Fixes: NULL pointer dereference
Fixes: 26550/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AV1_fuzzer-5417762807349248

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-10-26 19:27:53 +01:00
James Almer
0ed455b84e avcodec/av1dec: add cur_frame.spatial_id and temporal_id to AV1Frame
Will be used by hwaccels, which have access to a frame's AV1RawFrameHeader but not
its AV1RawOBUHeader.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-10-16 13:34:31 -03:00
James Almer
214998c55f avcodec/av1dec: avoid probing with av1dec
av1dec should no longer attempt to output empty frames if another decoder
was used for probing and it sucessfully set a pix_fmt ever since 05872c67a4,
so we can re-add the AV_CODEC_CAP_AVOID_PROBING cap.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-10-06 11:28:12 -03:00
James Almer
05872c67a4 avcodec/av1dec: partially clean state on frame decoding errors
Fixes: member access within null pointer of type 'TileGroupInfo' (aka 'struct TileGroupInfo')
Fixes: 25725/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AV1_fuzzer-5166692706287616

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: James Almer <jamrial@gmail.com>
2020-10-04 10:34:15 -03:00
James Almer
aa5e49e46d avcodec/av1dec: call ff_cbs_flush() on decoder flush
Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-29 21:38:27 -03:00
James Almer
3392c1b05e avcodec/av1dec: fix check for active sequence header
We clear the AV1RawSequenceHeader pointer on flush, not the relevant AVBufferRef.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-29 21:38:27 -03:00
James Almer
ea4b10249d avcodec/av1dec: parse dimensions from the sequence header in extradata
Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-29 21:38:27 -03:00
Andreas Rheinhardt
93b7f9312d avcodec/av1dec: Check tiles sizes, fix assert, don't read bytes bitwise
Tiles have a size field with a length from one to four bytes. As such it
is not possible to read it all at once with a call to get_bits() as this
only allows to read up to 25 bits; this is guarded by an av_assert2. Yet
this is done by the AV1 decoder in get_tiles_info(). It has been done
despite said size fields being byte-aligned. This commit fixes this by
using the bytestream2 API instead.

Furthermore, it is now explicitly checked whether the data is
consistent, i.e. whether the data that is supposed to be there extends
beyond the end of the data actually present.

Reviewed-by: Wang, Fei W <fei.w.wang@intel.com>
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-18 02:34:55 +02:00
Andreas Rheinhardt
3e057dd8b1 avcodec/av1dec: Remove redundant second free
The AV1 decoder has the FF_CODEC_CAP_INIT_CLEANUP flag set and yet
the decoder's close function is called manually on some error paths.
This is unnecessary and has been removed in this commit.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-17 05:47:06 +02:00
Andreas Rheinhardt
92b578e1d6 avcodec/av1dec: Fix segfault upon allocation error
Up until now, the AV1 decoder always checks before calling its wrapper
around ff_thread_release_buffer() whether the ThreadFrame was used at
all, i.e. it checked whether the first data buffer of the AVFrame
contained therein is NULL or not. Yet this presumes that the AVFrame has
been successfully allocated, even though this can of course fail; and if
it did, one would encounter a segfault.
Fix this by removing the checks altogether: ff_thread_release_buffer()
can handle both unallocated as well as empty frames (since commit
f6774f905f).

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-17 05:46:24 +02:00
James Almer
e46f34e85b avcodec/av1dec: fix setting pix_fmt
Fill the array with the software pix_fmt and move the avctx->hwaccel
check back to the proper place.
Also remove the avoid probing flag to ensure an external av1 decoder
will not set a pix_fmt we don't want during format probing.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-12 17:39:45 -03:00
James Almer
9c6026bc72 avcodec/av1dec: update reference frame state on show_existing_frame
As defined in Section 7.4

Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-12 13:10:16 -03:00
James Almer
b80c66bb6b avcodec/av1dec: set chroma_sample_location
Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-12 13:10:16 -03:00
James Almer
b7a06885f1 avcodec/av1dec: use av_cmp_q() to compare aspect ratio
Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-12 13:10:16 -03:00
Fei Wang
47be5a5056 avcodec: add AV1 hardware accelerated decoder
This AV1 decoder is currently only used for hardware accelerated decoding.
It can be extended into a native decoder in the future, so set its name to
"av1" and temporarily give it the lowest priority in the codec list.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-12 13:08:34 -03:00