Commit Graph

103 Commits

Author SHA1 Message Date
Mark Thompson 77fd2f9c7c vaapi_encode_h265: Explicitly set and correct some flags
max_14bit_constraint_flag should be set if the bit depth is not greater than
14 (currently always true).

one_picture_only_flag should not be set because we don't support the still
picture profiles.

general_profile_compatibility_flag should be set according to general_profile_idc
instead of bit depth.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
2022-04-11 11:38:43 +08:00
Mark Thompson 99b333e5ff vaapi_encode: Move block size calculation after entrypoint selection
The block size can be dependent on the profile and entrypoint selected.
It defaults to 16x16, with codecs able to override this choice with their
own function.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
2022-04-11 11:38:43 +08:00
Linjie Fu a285968a0b lavc/vaapi_encode_h265: Add GPB frame support for hevc_vaapi
Use GPB frames to replace regular P/B frames if backend driver does not
support it.

- GPB:
    Generalized P and B picture. Regular P/B frames replaced by B
    frames with previous-predict only, L0 == L1. Normal B frames
    still have 2 different ref_lists and allow bi-prediction

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
2022-04-11 11:38:43 +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 5aabb2596f avcodec/codec_internal: Rename AVCodecDefault->FFCodecDefault
This structure is no longer declared in a public header,
so using an FF-prefix is more appropriate.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:10 +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
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 a1cd4191e0 avcodec/vaapi_encode: use AVCodecContext.get_encode_buffer()
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-17 13:44:16 -03:00
Mark Thompson 8843607f49 cbs_h2645: Merge SEI message handling in common between codecs 2021-01-21 17:13:54 +00:00
Mark Thompson 773857df59 hevc: Use common SEI types 2021-01-21 17:13:54 +00:00
Mark Thompson 4bf3384800 cbs_h2645: Merge SEI messages in common between codecs
Make a new template file for common SEI messages - this will also apply
to H.266.
2021-01-21 17:13:54 +00:00
Mark Thompson 486817e1ae vaapi_encode_h265: Fix setting colour properties
Matching the previous commit for H.264.

Reviewed-By: Jan Ekström <jeebjp@gmail.com>
Tested-By: Xu, Yefeng <yefengx.xu@intel.com>
2020-11-03 20:36:14 +00:00
Mark Thompson 3d19c5ee68 vaapi_encode_h265: Don't require uniform_spacing_flag
Though still use it if the tile arrangement matches.  Also try to keep the
fields in the same order as the standard.
2020-08-01 17:39:32 +01:00
Mark Thompson bc58d1f58e vaapi_encode_h265: Fix ordering of tile dimensions
Dimensions are normally specified as width x height, and this will match
the same option to libaom-av1.

Remove the indirection through the private context at the same time.
2020-08-01 17:39:13 +01:00
Mark Thompson e80fe32943 vaapi_encode_h265: Remove confusing and redundant tile options
The tile_rows/cols options currently do a confusingly different thing to
the options of the same name on other encoders like libvpx and libaom.
There is no backward-compatibility reason to implement the log2 behaviour
as there was for libaom, so just get rid of them entirely.
2020-08-01 17:18:30 +01:00
Mark Thompson 9badc60292 vaapi_encode_h265: Enable 4:2:2 support 2020-07-24 13:44:09 +08:00
Linjie Fu 43a08d907b lavc/vaapi_encode_h265: add h265 tile encoding support
Default to enable uniform_spacing_flag. Guess level by the tile
rows/cols. Supported for ICL+ platforms.

Also add documentations.

To encode with 4 rows 2 columns:
    ffmpeg ... -c:v hevc_vaapi -tiles 4x2 ...
    ffmpeg ... -c:v hevc_vaapi -tile_rows 4 -tile_cols 2 ...

Suggested-by: Jun Zhao <mypopydev@gmail.com>
Signed-off-by: Linjie Fu <linjie.justin.fu@gmail.com>
2020-07-20 15:27:05 +08:00
Andreas Rheinhardt 1bdbc50bf4 avcodec/cbs: Remove unused function parameters
Several cbs-functions had an unused CodedBitstreamContext parameter.
This commit removes these.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-07-07 04:46:51 +02: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
Linjie Fu 2b32068916 lavc/vaapi_encode: add FF_CODEC_CAP_INIT_CLEANUP caps for encoders
ff_vaapi_encode_close() is not enough to free the resources like cbs
if initialization failure happens after codec->configure (except for
vp8/vp9).

We need to call avctx->codec->close() to deallocate, otherwise memory
leak happens.

Add FF_CODEC_CAP_INIT_CLEANUP for vaapi encoders and deallocate the
resources at free_and_end inside avcodec_open2().

Reviewed-by: Timo Rothenpieler <timo@rothenpieler.org>
Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2020-05-04 12:33:30 -03:00
Mark Thompson 344e6c3ff1 lavc/vaapi_encode: Add hardware config metadata
These encoders all accept VAAPI surfaces in a hardware frames context.
2020-04-26 18:38:25 +01:00
Linjie Fu 2847c5c6f9 lavc/vaapi_encode_h265: fix conf_win_xxx_offset for 4:2:2/4:4:4 encoding
Use desc->log2_chroma_w/h to calculate the sps->conf_win_right/bottom_offset.

Based on Table 6-1, SubWidthC and SubHeightC depend on chroma format(log2_chroma_w/h).

Based on D-28 and D-29, set the correct cropped width/height.

croppedWidth  = pic_width_in_luma_samples −
                SubWidthC * ( conf_win_right_offset + conf_win_left_offset );

croppedHeight = pic_height_in_luma_samples −
                SubHeightC * ( conf_win_bottom_offset + conf_win_top_offset );

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2020-03-09 23:44:04 +00:00
Mark Thompson 3387147860 vaapi_encode: Add ROI support 2019-07-28 22:34:26 +01:00
Mark Thompson d237b6b549 vaapi_encode_h265: Enable support for more RC modes
Also fixes QP going out of range when modified by the quant factor/offset
values, and clarifies the QP behaviour for >8-bit modes.
2019-02-25 23:32:23 +00:00
Mark Thompson 9d5ca71ec2 vaapi_encode: Do not zero access unit structures
Following b8c45bbcbc they contain allocated
unit arrays which will get leaked.  These operations were inconsistently
applied and never actually needed (the old uninit left them in the correct
state), so just drop them entirely.
2019-02-25 23:27:11 +00:00
Andreas Rheinhardt b8c45bbcbc libavcodec/cbs: Stop needlessly reallocating the units array
Currently, a fragment's unit array is constantly reallocated during
splitting of a packet. This commit changes this: One can keep the units
array by distinguishing between the number of allocated and the number
of valid units in the units array.

The more units a packet is split into, the bigger the benefit.
So MPEG-2 benefits the most; for a video coming from an NTSC-DVD
(usually 32 units per frame) the average cost of cbs_insert_unit (for a
single unit) went down from 6717 decicycles to 450 decicycles (based
upon 10 runs with 4194304 runs each); if each packet consists of only
one unit, it went down from 2425 to 448; for a H.264 video where most
packets contain nine units, it went from 4431 to 450.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
2019-02-25 21:40:13 +00:00
Mark Thompson 44bcccb7f0 vaapi_encode_h265: Ensure that ref pics are always in the RPS
When making a new P-frame when B-frames are present the previous P-frame
is normally in the DPB because it will be referred to by subsequent
B-frames.  However, this is not true if there are no B-frames, or in edge
cases where a GOP ends with two P-frames.  Fix this by adding the direct
ref pics to the RPS explicitly.

Fixes #7699.

Tested-by: Ullysses A Eoff <ullysses.a.eoff@intel.com>
2019-01-27 17:38:38 +00:00
Mark Thompson 362992e94b vaapi_encode_h265: Support more complex reference structures
The reference picture sets are now constructed directly from the DPB
information.
2019-01-23 23:04:11 +00:00
Mark Thompson 5fdcf85bbf vaapi_encode: Convert to send/receive API
This attaches the logic of picking the mode of for the next picture to
the output, which simplifies some choices by removing the concept of
the picture for which input is not yet available.  At the same time,
we allow more complex reference structures and track more reference
metadata (particularly the contents of the DPB) for use in the
codec-specific code.

It also adds flags to explicitly track the available features of the
different codecs.  The new structure also allows open-GOP support, so
that is now available for codecs which can do it.
2019-01-23 23:04:11 +00:00
Mark Thompson 80ce23da65 vaapi_encode_h265: Reduce SAR to valid range
Matching previous commit for H.264.
2018-11-18 21:34:18 +00:00
Mark Thompson a7eda762dc vaapi_encode_h265: Enable multiple-slice support 2018-10-27 19:35:35 +01:00
Mark Thompson 74b4134d2f vaapi_encode_h265: Add missing error return
Fixes CID #1439657.
2018-09-24 23:09:45 +01:00
Mark Thompson bfc4d0f6e4 vaapi_encode_h265: Set level based on stream if not set by user
Sets the level based on the stream properties if it is not explicitly
set by the user.  Also add a tier option to set general_tier_flag, since
that affects the level choice.
2018-09-23 14:42:34 +01:00
Mark Thompson 61aea24662 vaapi_encode_h265: Improve profile support
Set profile compatibility/constraint flags properly (including the
constraint flags used for RExt profiles, as all streams we can currently
generate are RExt-compatible), and use that to add support for the "Main
Intra" and "Main 10 Intra" RExt subprofiles (for which we can re-use the
existing Main and Main10 VAAPI profiles).
2018-09-23 14:42:34 +01:00
Mark Thompson 91534786fa vaapi_encode_h26[45]: Make the AUD option a boolean 2018-09-23 14:42:34 +01:00
Mark Thompson 851a63c22a vaapi_encode: Clean up the packed header configuration
Add a larger warning more clearly explaining the consequences of missing
packed header support in the driver.  Also only write the extradata if the
user actually requests it via the GLOBAL_HEADER flag.
2018-09-23 14:42:34 +01:00
Mark Thompson bf726c26fd vaapi_encode: Clean up the GOP structure configuration
Choose what types of reference frames will be used based on what types
are available, and make the intra-only mode explicit (GOP size one,
which must be used for MJPEG).
2018-09-23 14:42:33 +01:00
Mark Thompson 8479f99c7d vaapi_encode: Add support for max QP in rate control
This was added in libva 2.1.0 (VAAPI 1.1.0).  Use AVCodecContext.qmax,
matching the existing behaviour for qmin, and clean up the defaults so
that we only pass min/max when explicitly set.
2018-09-23 14:42:33 +01:00
Mark Thompson af532c9215 vaapi_encode: Clean up rate control configuration
Query which modes are supported and select between VBR and CBR based
on that - this removes all of the codec-specific rate control mode
selection code.
2018-09-23 14:42:33 +01:00
Mark Thompson aa2563aecc vaapi_encode: Add common options between all encoders
The only common option here is low_power - it was previously supported
for H.264 only, that specific option is removed.
2018-09-23 14:42:33 +01:00
Mark Thompson 3b188666f1 vaapi_encode: Choose profiles dynamically
Previously there was one fixed choice for each codec (e.g. H.265 -> Main
profile), and using anything else then required an explicit option from
the user.  This changes to selecting the profile based on the input format
and the set of profiles actually supported by the driver (e.g. P010 input
will choose Main 10 profile for H.265 if the driver supports it).

The entrypoint and render target format are also chosen dynamically in the
same way, removing those explicit selections from the per-codec code.
2018-09-23 14:42:33 +01:00
Mark Thompson c5b4ad247b vaapi_encode: Remove common priv_data and options fields
The codec-specific context now contains both the common context and the
codec-specific options directly.
2018-08-27 16:21:38 +01:00
Mark Thompson 46d1313fcd vaapi_encode_h265: Move options and common structures into context
Matching previous commit for H.264.
2018-08-27 16:21:37 +01:00
Haihao Xiang 0612e29b59 vaapi_encode_h265: Insert content light level information
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2018-05-10 20:55:42 +01:00
Haihao Xiang 345b6962b6 vaapi_encode_h265: Insert mastering display colour volume
'-sei xxx' is added to control SEI insertion, so far only mastering
display colour volume is available for testing.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2018-05-10 20:55:32 +01:00
Mark Thompson 0cc8e34a94 Merge commit 'ce5870a3a8f2b10668ee4f04c2ae0287f66f31b2'
* commit 'ce5870a3a8f2b10668ee4f04c2ae0287f66f31b2':
  cbs: Refcount all the things!

Some changes for bitstream API.

Merged-by: Mark Thompson <sw@jkqxz.net>
2018-02-21 22:22:54 +00:00
Mark Thompson f082dcab7c Merge commit '67eb2b16daa77f6ba3e04a28ca18e53193723b7f'
* commit '67eb2b16daa77f6ba3e04a28ca18e53193723b7f':
  vaapi_h265: Mark unused entries in RefPicList[01] as explicitly invalid

Merged-by: Mark Thompson <sw@jkqxz.net>
2018-02-21 21:52:20 +00:00
Mark Thompson ce5870a3a8 cbs: Refcount all the things!
This makes it easier for users of the CBS API to get alloc/free right -
all subelements use the buffer API so that it's clear how to free them.
It also allows eliding some redundant copies: the packet -> fragment copy
disappears after this change if the input packet is refcounted, and more
codec-specific cases are now possible (but not included in this patch).
2018-02-20 22:04:12 +00:00
Mark Thompson 67eb2b16da vaapi_h265: Mark unused entries in RefPicList[01] as explicitly invalid
The iHD driver looks at entries beyond num_ref_idx_l[01]_active_minus1
for unknown reasons.
2018-02-20 22:04:12 +00:00