Re: [FFmpeg-devel] [PATCH] avcodec/av1_vaapi: Enable AV1Profile2 VAAPI support.

2024-08-11 Thread Mark Thompson
On 11/08/2024 19:27, Mark Thompson wrote:
> On 30/07/2024 21:02, David (Ming Qiang) Wu via ffmpeg-devel wrote:
>> AV1Profile2 VAAPI is supported and tested on AMD VCN5.
>>
>> Signed-off-by: David (Ming Qiang) Wu 
>> ---
>>  libavcodec/av1dec.c   | 3 +++
>>  libavcodec/vaapi_decode.c | 3 +++
>>  2 files changed, 6 insertions(+)
>>
>> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
>> index 1d5b9ef4f4..77f63661a0 100644
>> --- a/libavcodec/av1dec.c
>> +++ b/libavcodec/av1dec.c
>> @@ -599,6 +599,9 @@ static int get_pixel_format(AVCodecContext *avctx)
>>  case AV_PIX_FMT_YUV420P12:
>>  #if CONFIG_AV1_VULKAN_HWACCEL
>>  *fmtp++ = AV_PIX_FMT_VULKAN;
>> +#endif
>> +#if CONFIG_AV1_VAAPI_HWACCEL
>> +*fmtp++ = AV_PIX_FMT_VAAPI;
>>  #endif
>>  break;
>>  case AV_PIX_FMT_YUV422P:
>> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
>> index a59194340f..a077e47326 100644
>> --- a/libavcodec/vaapi_decode.c
>> +++ b/libavcodec/vaapi_decode.c
>> @@ -448,6 +448,9 @@ static const struct {
>>  MAP(AV1, AV1_MAIN,AV1Profile0),
>>  MAP(AV1, AV1_HIGH,AV1Profile1),
>>  #endif
>> +#if VA_CHECK_VERSION(1, 23, 0)
>> +MAP(AV1, AV1_PROFESSIONAL,  AV1Profile2),
>> +#endif
>>  
>>  #undef MAP
>>  };
> 
> Based on <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30429> 
> this is supporting profile 2 only for 4:2:0 12-bit, and therefore can't 
> advertise profile 2 generally for the decoder because that would imply 
> support for all 4:2:2 and 4:4:4 cases as well.
> 
> I think this wants something added to VAAPI in order to be able to advertise 
> partial support for a profile?
> 
> (It would be very confusing if we got "AV1Profile2" in VAAPI meaning only 
> 4:2:0 12-bit and then have to add a separate 
> "AV1Profile2exceptreallythistime" to meant actual AV1 profile 2.)

I commented in <https://github.com/intel/libva/pull/828>.

Please fix this before it get further in Mesa, having a version reporting 
incorrect decoder capabilities which we need to hack around elsewhere would be 
non-ideal.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/av1_vaapi: Enable AV1Profile2 VAAPI support.

2024-08-11 Thread Mark Thompson
On 30/07/2024 21:02, David (Ming Qiang) Wu via ffmpeg-devel wrote:
> AV1Profile2 VAAPI is supported and tested on AMD VCN5.
> 
> Signed-off-by: David (Ming Qiang) Wu 
> ---
>  libavcodec/av1dec.c   | 3 +++
>  libavcodec/vaapi_decode.c | 3 +++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index 1d5b9ef4f4..77f63661a0 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -599,6 +599,9 @@ static int get_pixel_format(AVCodecContext *avctx)
>  case AV_PIX_FMT_YUV420P12:
>  #if CONFIG_AV1_VULKAN_HWACCEL
>  *fmtp++ = AV_PIX_FMT_VULKAN;
> +#endif
> +#if CONFIG_AV1_VAAPI_HWACCEL
> +*fmtp++ = AV_PIX_FMT_VAAPI;
>  #endif
>  break;
>  case AV_PIX_FMT_YUV422P:
> diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
> index a59194340f..a077e47326 100644
> --- a/libavcodec/vaapi_decode.c
> +++ b/libavcodec/vaapi_decode.c
> @@ -448,6 +448,9 @@ static const struct {
>  MAP(AV1, AV1_MAIN,AV1Profile0),
>  MAP(AV1, AV1_HIGH,AV1Profile1),
>  #endif
> +#if VA_CHECK_VERSION(1, 23, 0)
> +MAP(AV1, AV1_PROFESSIONAL,   AV1Profile2),
> +#endif
>  
>  #undef MAP
>  };

Based on  this 
is supporting profile 2 only for 4:2:0 12-bit, and therefore can't advertise 
profile 2 generally for the decoder because that would imply support for all 
4:2:2 and 4:4:4 cases as well.

I think this wants something added to VAAPI in order to be able to advertise 
partial support for a profile?

(It would be very confusing if we got "AV1Profile2" in VAAPI meaning only 4:2:0 
12-bit and then have to add a separate "AV1Profile2exceptreallythistime" to 
meant actual AV1 profile 2.)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] cbs_vp9: Ensure that the two superframe_header instances are identical

2024-08-11 Thread Mark Thompson
Fixes: use of uninitialized value
Fixes: 
70907/clusterfuzz-testcase-minimized-ffmpeg_BSF_VP9_METADATA_fuzzer-6339363208757248

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
---
On 11/08/2024 19:05, Mark Thompson wrote:
> The correct fix therefore would be to constrain the second read values to be 
> identical to the first, not to introduce new syntax elements not in the 
> standard to cover the invalid case.

Like this.  (Marked in the same way as your suggested patch based on my 
assumption that it fixes the problem - please check.)

Trace output is correct in the normal case, and catches the error in the bad 
one:

[trace_headers @ 0x55a0f5decb40] Packet: 11971 bytes, pts 366, dts 366.
[trace_headers @ 0x55a0f5decb40] Superframe Index
[trace_headers @ 0x55a0f5decb40] 0   superframe_marker  
   110 = 6
[trace_headers @ 0x55a0f5decb40] 3   bytes_per_framesize_minus_1
01 = 1
[trace_headers @ 0x55a0f5decb40] 5   frames_in_superframe_minus_1   
   001 = 1
[trace_headers @ 0x55a0f5decb40] 8   frame_sizes[0] 
  10101110 = 11964
[trace_headers @ 0x55a0f5decb40] 24  frame_sizes[1] 
  0001 = 1
[trace_headers @ 0x55a0f5decb40] 40  superframe_marker  
   110 = 6
[trace_headers @ 0x55a0f5decb40] 43  bytes_per_framesize_minus_1
01 = 1
[trace_headers @ 0x55a0f5decb40] 45  frames_in_superframe_minus_1   
   001 = 1

or

[trace_headers @ 0x555af04d7b40] Packet: 11971 bytes, pts 366, dts 366.
[trace_headers @ 0x555af04d7b40] Superframe Index
[trace_headers @ 0x555af04d7b40] 0   superframe_marker  
   110 = 6
[trace_headers @ 0x555af04d7b40] 3   bytes_per_framesize_minus_1
01 = 1
[trace_headers @ 0x555af04d7b40] 5   frames_in_superframe_minus_1   
   001 = 1
[trace_headers @ 0x555af04d7b40] 8   frame_sizes[0] 
  10101110 = 11964
[trace_headers @ 0x555af04d7b40] 24  frame_sizes[1] 
  0001 = 1
[trace_headers @ 0x555af04d7b40] 40  superframe_marker  
   110 = 6
[trace_headers @ 0x555af04d7b40] 43  bytes_per_framesize_minus_1
10 = 2
[trace_headers @ 0x555af04d7b40] bytes_per_framesize_minus_1 out of range: 2, 
but must be in [1,1].
[vost#0:0/copy @ 0x555af0538400] Error applying bitstream filters to a packet: 
Invalid data found when processing input

Thanks,

- Mark

 libavcodec/cbs_vp9_syntax_template.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/cbs_vp9_syntax_template.c 
b/libavcodec/cbs_vp9_syntax_template.c
index 2f08eccf18..5ed3c700dc 100644
--- a/libavcodec/cbs_vp9_syntax_template.c
+++ b/libavcodec/cbs_vp9_syntax_template.c
@@ -421,9 +421,14 @@ static int FUNC(superframe_index)(CodedBitstreamContext 
*ctx, RWContext *rw,
 frame_sizes[i], 1, i);
 }

-f(3, superframe_marker);
-f(2, bytes_per_framesize_minus_1);
-f(3, frames_in_superframe_minus_1);
+// Second instance of the superframe header must be identical
+// to the first.
+fixed(3,   superframe_marker,
+  current->superframe_marker);
+fixed(2,   bytes_per_framesize_minus_1,
+  current->bytes_per_framesize_minus_1);
+fixed(3,   frames_in_superframe_minus_1,
+  current->frames_in_superframe_minus_1);

 return 0;
 }
-- 
2.43.0


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/cbs_vp9: Try to store fewer than 2 things in the same bit

2024-08-11 Thread Mark Thompson
On 08/08/2024 00:53, Michael Niedermayer wrote:
> Fixes: use of uninitialized value
> Fixes: 
> 70907/clusterfuzz-testcase-minimized-ffmpeg_BSF_VP9_METADATA_fuzzer-6339363208757248
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/cbs_vp9.c | 9 ++---
>  libavcodec/cbs_vp9.h | 3 +++
>  libavcodec/cbs_vp9_syntax_template.c | 6 +++---
>  3 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
> index 816d06da04d..7b8bc9c7985 100644
> --- a/libavcodec/cbs_vp9.c
> +++ b/libavcodec/cbs_vp9.c
> @@ -541,9 +541,12 @@ static int 
> cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx,
>  size_len = av_log2(max) / 8 + 1;
>  av_assert0(size_len <= 4);
>  
> -sfi.superframe_marker= VP9_SUPERFRAME_MARKER;
> -sfi.bytes_per_framesize_minus_1  = size_len - 1;
> -sfi.frames_in_superframe_minus_1 = frag->nb_units - 1;
> +sfi.superframe_marker=
> +sfi.superframe_marker_2  = VP9_SUPERFRAME_MARKER;
> +sfi.bytes_per_framesize_minus_1  =
> +sfi.bytes_per_framesize_minus_1_2= size_len - 1;
> +sfi.frames_in_superframe_minus_1   =
> +sfi.frames_in_superframe_minus_1_2 = frag->nb_units - 1;
>  
>  size = 2;
>  for (i = 0; i < frag->nb_units; i++) {
> diff --git a/libavcodec/cbs_vp9.h b/libavcodec/cbs_vp9.h
> index af15eb4bace..428662a8cdb 100644
> --- a/libavcodec/cbs_vp9.h
> +++ b/libavcodec/cbs_vp9.h
> @@ -174,6 +174,9 @@ typedef struct VP9RawSuperframeIndex {
>  uint8_t bytes_per_framesize_minus_1;
>  uint8_t frames_in_superframe_minus_1;
>  uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME];
> +uint8_t superframe_marker_2;
> +uint8_t bytes_per_framesize_minus_1_2;
> +uint8_t frames_in_superframe_minus_1_2;
>  } VP9RawSuperframeIndex;
>  
>  typedef struct VP9RawSuperframe {
> diff --git a/libavcodec/cbs_vp9_syntax_template.c 
> b/libavcodec/cbs_vp9_syntax_template.c
> index 2f08eccf180..3f542d0c5d5 100644
> --- a/libavcodec/cbs_vp9_syntax_template.c
> +++ b/libavcodec/cbs_vp9_syntax_template.c
> @@ -421,9 +421,9 @@ static int FUNC(superframe_index)(CodedBitstreamContext 
> *ctx, RWContext *rw,
>  frame_sizes[i], 1, i);
>  }
>  
> -f(3, superframe_marker);
> -f(2, bytes_per_framesize_minus_1);
> -f(3, frames_in_superframe_minus_1);
> +f(3, superframe_marker_2);
> +f(2, bytes_per_framesize_minus_1_2);
> +f(3, frames_in_superframe_minus_1_2);

This gets the syntax element names wrong in traces.

>  
>  return 0;
>  }

The two instances of the syntax elements must be identical, if they aren't then 
the file is invalid.

The correct fix therefore would be to constrain the second read values to be 
identical to the first, not to introduce new syntax elements not in the 
standard to cover the invalid case.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] PATCH: Fallback to NV12 format in VAAPI drivers

2024-08-11 Thread Mark Thompson
On 10/08/2024 09:51, Lluís Batlle i Rossell wrote:
> On Fri, Aug 09, 2024 at 09:43:53AM +0200, Lluís Batlle i Rossell wrote:
>> On Fri, Aug 09, 2024 at 11:49:54AM +0800, Zhao Zhili wrote:
 vaapi drivers often lack proper image converesions and not all
 situations allow vagetimage or vaputimage with the image formats
 reported by the api. nv12 seems allowed in all circumstances.

 with this change now one can use the hwaccel directly without
 explicit conversions to nv12 for frame downloading to work.

 gstreamer adopted a similar approach:
 https://bugzilla.gnome.org/show_bug.cgi?id=752958
>>>
>>> Isn’t it break all pixel formats with bit depth > 8?
>>> I think we already have hwcontext API to select sw_format, this isn’t a bug
>>> inside ffmpeg.
>>
>> Correct... I didn't think of the need beyond NV12.
>>
>> What if I redo the patch so I keep all formats, but I simply move NV12 to
>> the first place? That will make ffmpeg pick NV12 as default if NONE
>> specified.
> 
> I attach a different patch, so NV12 is only picked in case the dst format
> is NONE.

What are the surface formats where this actually gets used, and on what 
hardware and driver?

It seems probably ok if this were restricted to 4:2:0 8-bit formats (as a 
surprise implicit downsample which can't be told anything about the source 
format seems very bad), but then what is it actually covering?

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vvc: Invalidate PPSs which refer to a changed SPS

2024-06-16 Thread Mark Thompson
On 15/06/2024 17:37, Frank Plowman wrote:
> n 15/06/2024 13:24, Nuo Mi wrote:
>> On Sat, Jun 15, 2024 at 2:35 PM Christophe Gisquet <
>> christophe.gisq...@gmail.com> wrote:
>>
>>> Le ven. 14 juin 2024, 11:39, Frank Plowman  a
>>> écrit :
>>>
 When the SPS associated with a particular SPS ID changes, invalidate all
 the PPSs which use that SPS ID.  Fixes crashes with illegal bitstreams.
 This is done in the CBS, rather than in libavcodec/vvc/ps.c like the SPS
 ID reuse validation, as parts of the CBS parsing process for PPSs
 depend on the SPS being referred to.

>>>
>>> I am uncertain about this. I have no definite knowledge nor proof, but I
>>> would have thought these are persistent, IE it's legal to update some of
>>> them, their validity depending on something else.
>>>
>>
>>> Wondering if the tested streams are thus conformant.
>>>
>>> But I don't know the actual rule. Maybe finding an EOB/EOS NUT? Related to
>>> some particular shape of a clean random access point, that would require
>>> retransmitting VPS/SPS/PPS/APS/... ?
>>>
>>> Asking Benjamin Bross might be a better option here.
>>>
>> Hi Chris,
>> spec said sps should not change in a CVS.  Frank has some patches to fix a
>> similar issue.
>> https://github.com/FFmpeg/FFmpeg/commit/2d79ae3f8a3306d24afe43ba505693a8dbefd21b
>>
>>
>> Hi Frank,
>> Did it crash before your error hand code in ps.c?
>> Could you send me the clip?
>>
>> Thank you
>>
> 
> Hi both,
> 
> Thank you for your reviews.
> 
> An example of a crashing bitstream which is fixed by this patch is ID
> 295 available here: https://github.com/ffvvc/tests/pull/43.  The
> relevant part of the bitstream is a sequence of NAL units
> 
> AU (decode_order=5)
> 18. SPS
> sps_seq_parameter_set_id = 0
> sps_ctb_log2_size_y = 5
> 19. PPS
> pps_pic_parameter_set_id = 0
> pps_seq_parameter_set_id = 0
> 20. IDR_N_LP
> ph_pic_order_cnt_lsb = 0
> NoOutputBeforeRecoveryFlag = 1
> ph_pic_parameter_set_id = 0
> 
> AU (decode_order=6)
> 21. AUD
> 22. VPS
> 23. SPS
> sps_seq_parameter_set_id = 0
> sps_ctb_log2_size_y = 7
> 24. PREFIX_APS
> 25. IDR_N_LP
> ph_pic_order_cnt_lsb = 0
> NoOutputBeforeRecoveryFlag = 1
> ph_pic_parameter_set_id = 0
> 
> The layout of SPSs alone is legal (not covered by the checks introduced
> in 2d79ae3f8a3306d24afe43ba505693a8dbefd21b) as the second AU is a CLVSS
> AU.  As a result, the bitstream crashes both before and after
> 2d79ae3f8a3306d24afe43ba505693a8dbefd21b.  What this patch does is
> produce an error when the VCL NAL unit in the second AU (25.) tries to
> use PPS ID 0, as the SPS NAL unit that PPS was defined with reference to
> (18.) is no longer available.
> 
> Christophe, is my interpretation of your point correct when I say you
> are suggesting that the above sequence may be legal, so long as the PPS
> still satisfies the new bounds etc. derived from the second SPS?  I did
> consider this, and I think it may be possible to implement by delaying
> CBS element validation and inference until libavcodec/vvc/ps.c.
> However, there are no bitstreams in the conformance suite which contain
> such a structure and this is different to how the native HEVC decoder
> behaves (see libavcodec/hevc/ps.c:72).

Is there some requirement in H.266 that in a single stream the PPS precedes the 
SPS?

Currently we effectively require that for a single stream because we use the 
SPS to enforce constraints on the PPS in both H.265 and H.266, but I'm not 
seeing a hard dependency and it looks like it will currently work on later 
stream starts as long as the parameters don't change too much.

In H.264 there is an explicit dependency because you need chroma_format_idc to 
parse scaling lists, but again this will usually work because it's unlikely to 
change inline.

If that is not required then this will discard the PPS of a stream where the 
SPS follows the PPS.  (Though I admit that before this it was only dubiously 
working because the bounds checking might be wrong.)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 07/16] hwcontext_nvtegra: add dynamic frequency scaling routines

2024-06-05 Thread Mark Thompson
On 30/05/2024 20:43, averne wrote:
> To save on energy, the clock speed of multimedia engines should be adapted to 
> their workload.
> 
> Signed-off-by: averne 
> ---
>  libavutil/hwcontext_nvtegra.c | 165 ++
>  libavutil/hwcontext_nvtegra.h |   7 ++
>  2 files changed, 172 insertions(+)
> 
> ...
> diff --git a/libavutil/hwcontext_nvtegra.h b/libavutil/hwcontext_nvtegra.h
> index 8a2383d304..7c845951d9 100644
> --- a/libavutil/hwcontext_nvtegra.h
> +++ b/libavutil/hwcontext_nvtegra.h
> @@ -82,4 +82,11 @@ static inline AVNVTegraMap 
> *av_nvtegra_frame_get_fbuf_map(const AVFrame *frame)
>   */
>  int av_nvtegra_pixfmt_to_vic(enum AVPixelFormat fmt);
>  
> +/*
> + * Dynamic frequency scaling routines
> + */
> +int av_nvtegra_dfs_init(AVHWDeviceContext *ctx, AVNVTegraChannel *channel, 
> int width, int height, double framerate_hz);
> +int av_nvtegra_dfs_update(AVHWDeviceContext *ctx, AVNVTegraChannel *channel, 
> int bitstream_len, int decode_cycles);
> +int av_nvtegra_dfs_uninit(AVHWDeviceContext *ctx, AVNVTegraChannel *channel);
> +
>  #endif /* AVUTIL_HWCONTEXT_NVTEGRA_H */

This really isn't a sensible thing to have in the public API of ffmpeg.  Why on 
earth isn't this sort of detail dealt with by the kernel?  (Which can actually 
see all of the different processes using it, as well.)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 06/16] avutil: add nvtegra hwcontext

2024-06-05 Thread Mark Thompson
On 30/05/2024 20:43, averne wrote:
> This includes hwdevice and hwframes objects.
> As the multimedia engines work with tiled surfaces (block linear in nvidia 
> jargon), two frame transfer methods are implemented.
> The first makes use of the VIC to perform the copy. Since some revisions of 
> the VIC (such as the one found in the tegra X1) did not support 10+ bit 
> formats, these go through two separate copy steps for the luma and chroma 
> planes.
> The second method copies on the CPU, and is used as a fallback if the VIC 
> constraints are not satisfied.
> 
> Signed-off-by: averne 
> ---
>  libavutil/Makefile |   7 +-
>  libavutil/hwcontext.c  |   4 +
>  libavutil/hwcontext.h  |   1 +
>  libavutil/hwcontext_internal.h |   1 +
>  libavutil/hwcontext_nvtegra.c  | 880 +
>  libavutil/hwcontext_nvtegra.h  |  85 
>  6 files changed, 976 insertions(+), 2 deletions(-)
>  create mode 100644 libavutil/hwcontext_nvtegra.c
>  create mode 100644 libavutil/hwcontext_nvtegra.h
> 
> ...> +
> +static int nvtegra_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const 
> AVFrame *src) {
> +const AVFrame *swframe;
> +bool from;
> +int num_planes, i;
> +
> +from= !dst->hw_frames_ctx;
> +swframe = from ? dst : src;
> +
> +if (swframe->hw_frames_ctx)
> +return AVERROR(ENOSYS);
> +
> +num_planes = av_pix_fmt_count_planes(swframe->format);
> +
> +for (i = 0; i < num_planes; ++i) {
> +if (((uintptr_t)swframe->data[i] & 0xff) || (swframe->linesize[i] & 
> 0xff)) {
> +av_log(ctx, AV_LOG_WARNING, "Frame address/pitch not aligned to 
> 256, "
> +"falling back to cpu transfer\n");
> +return nvtegra_cpu_transfer_data(ctx, dst, src, num_planes, 
> from);

Are you doing something somewhere to avoid this case?  It seems like it should 
be the normal one (given alignment is typically set signficantly lower than 
256), so this warning would be very spammy.

> +}
> +}
> +
> +return nvtegra_vic_transfer_data(ctx, dst, src, num_planes, from);
> +}
> +
> +const HWContextType ff_hwcontext_type_nvtegra = {
> +.type   = AV_HWDEVICE_TYPE_NVTEGRA,
> +.name   = "nvtegra",
> +
> +.device_hwctx_size  = sizeof(NVTegraDevicePriv),
> +.device_hwconfig_size   = 0,
> +.frames_hwctx_size  = 0,
> +
> +.device_create  = &nvtegra_device_create,
> +.device_init= &nvtegra_device_init,
> +.device_uninit  = &nvtegra_device_uninit,
> +
> +.frames_get_constraints = &nvtegra_frames_get_constraints,
> +.frames_init= &nvtegra_frames_init,
> +.frames_uninit  = &nvtegra_frames_uninit,
> +.frames_get_buffer  = &nvtegra_get_buffer,
> +
> +.transfer_get_formats   = &nvtegra_transfer_get_formats,
> +.transfer_data_to   = &nvtegra_transfer_data,
> +.transfer_data_from = &nvtegra_transfer_data,
> +
> +.pix_fmts = (const enum AVPixelFormat[]) {
> +AV_PIX_FMT_NVTEGRA,
> +AV_PIX_FMT_NONE,
> +},
> +};

What controls whether frames are linear or not?

It seems like the linear case could be exposed directly to the user rather than 
having to wrap it like this - the decoder could return read-only NV12 (or 
whatever) frames directly and they would work with other components.

> diff --git a/libavutil/hwcontext_nvtegra.h b/libavutil/hwcontext_nvtegra.h
> new file mode 100644
> index 00..8a2383d304
> --- /dev/null
> +++ b/libavutil/hwcontext_nvtegra.h
> @@ -0,0 +1,85 @@
> +/*
> + * Copyright (c) 2024 averne 
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#ifndef AVUTIL_HWCONTEXT_NVTEGRA_H
> +#define AVUTIL_HWCONTEXT_NVTEGRA_H
> +
> +#include 
> +
> +#include "hwcontext.h"
> +#include "buffer.h"
> +#include "frame.h"
> +#include "pixfmt.h"
> +
> +#include "nvtegra.h"
> +
> +/*
> + * Encode a hardware revision into a version number
> + */
> +#define AV_NVTEGRA_ENCODE_REV(maj, min) (((maj & 0xff) << 8) | (min & 0xff))
> +
> +/*
> + * Decode a version number
> + */
> +static inline void av_nvtegra_decode_rev(int rev, int *maj, int *min) {
> +*maj = (rev >> 8) & 0x

Re: [FFmpeg-devel] [PATCH 05/16] avutil: add common code for nvtegra

2024-06-05 Thread Mark Thompson
On 30/05/2024 20:43, averne wrote:
> This includes a new pixel format for nvtegra hardware frames, and several 
> objects for interaction with hardware blocks.
> In particular, this contains code for channels (handles to hardware engines), 
> maps (memory-mapped buffers shared with engines), and command buffers 
> (abstraction for building command lists sent to the engines).
> 
> Signed-off-by: averne 
> ---
>  configure  |2 +
>  libavutil/Makefile |4 +
>  libavutil/nvtegra.c| 1035 
>  libavutil/nvtegra.h|  258 +
>  libavutil/nvtegra_host1x.h |   94 
>  libavutil/pixdesc.c|4 +
>  libavutil/pixfmt.h |8 +
>  7 files changed, 1405 insertions(+)
>  create mode 100644 libavutil/nvtegra.c
>  create mode 100644 libavutil/nvtegra.h
>  create mode 100644 libavutil/nvtegra_host1x.h

I don't think it is reasonable for all of this to be public API surface of 
ffmpeg.

A separate library containing the headers and exposing some set of functions 
like this might make more sense.

If this has to be in ffmpeg then it really needs to all go in one library 
(libavcodec I guess) so that it's not exposing all this internal detail in the 
public API.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 2/2] hwcontext_vaapi: Deprecate quirks

2024-06-05 Thread Mark Thompson
These only apply to obsolete drivers which do not work with the
now-required libva 2.x.
---
Fixed checkheaders.


 libavutil/hwcontext_vaapi.c | 123 ++--
 libavutil/hwcontext_vaapi.h |  17 +
 2 files changed, 52 insertions(+), 88 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index caff43d1ae..8591fb88ac 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -243,8 +243,7 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext 
*hwdev,
 unsigned int fourcc;
 int err, i, j, attr_count, pix_fmt_count;
 
-if (config &&
-!(hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES)) {
+if (config) {
 attr_count = 0;
 vas = vaQuerySurfaceAttributes(hwctx->display, config->config_id,
0, &attr_count);
@@ -367,23 +366,6 @@ fail:
 return err;
 }
 
-static const struct {
-const char *friendly_name;
-const char *match_string;
-unsigned int quirks;
-} vaapi_driver_quirks_table[] = {
-{
-"Intel iHD",
-"ubit",
-AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE,
-},
-{
-"VDPAU wrapper",
-"Splitted-Desktop Systems VDPAU backend for VA-API",
-AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
-},
-};
-
 static int vaapi_device_init(AVHWDeviceContext *hwdev)
 {
 VAAPIDeviceContext *ctx = hwdev->hwctx;
@@ -436,36 +418,6 @@ static int vaapi_device_init(AVHWDeviceContext *hwdev)
 if (vendor_string)
 av_log(hwdev, AV_LOG_VERBOSE, "VAAPI driver: %s.\n", vendor_string);
 
-if (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_USER_SET) {
-av_log(hwdev, AV_LOG_VERBOSE, "Using quirks set by user (%#x).\n",
-   hwctx->driver_quirks);
-} else {
-// Detect the driver in use and set quirk flags if necessary.
-hwctx->driver_quirks = 0;
-if (vendor_string) {
-for (i = 0; i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table); i++) {
-if (strstr(vendor_string,
-   vaapi_driver_quirks_table[i].match_string)) {
-av_log(hwdev, AV_LOG_VERBOSE, "Matched driver string "
-   "as known nonstandard driver \"%s\", setting "
-   "quirks (%#x).\n",
-   vaapi_driver_quirks_table[i].friendly_name,
-   vaapi_driver_quirks_table[i].quirks);
-hwctx->driver_quirks |=
-vaapi_driver_quirks_table[i].quirks;
-break;
-}
-}
-if (!(i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table))) {
-av_log(hwdev, AV_LOG_VERBOSE, "Driver not found in known "
-   "nonstandard list, using standard behaviour.\n");
-}
-} else {
-av_log(hwdev, AV_LOG_VERBOSE, "Driver has no vendor string, "
-   "assuming standard behaviour.\n");
-}
-}
-
 av_free(image_list);
 return 0;
 fail:
@@ -562,48 +514,43 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc)
 }
 
 if (!hwfc->pool) {
-if (!(hwctx->driver_quirks & 
AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES)) {
-int need_memory_type = !(hwctx->driver_quirks & 
AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE);
-int need_pixel_format = 1;
-for (i = 0; i < avfc->nb_attributes; i++) {
-if (avfc->attributes[i].type == VASurfaceAttribMemoryType)
-need_memory_type  = 0;
-if (avfc->attributes[i].type == VASurfaceAttribPixelFormat)
-need_pixel_format = 0;
-}
-ctx->nb_attributes =
-avfc->nb_attributes + need_memory_type + need_pixel_format;
+int need_memory_type  = 1;
+int need_pixel_format = 1;
+for (i = 0; i < avfc->nb_attributes; i++) {
+if (avfc->attributes[i].type == VASurfaceAttribMemoryType)
+need_memory_type  = 0;
+if (avfc->attributes[i].type == VASurfaceAttribPixelFormat)
+need_pixel_format = 0;
+}
+ctx->nb_attributes =
+avfc->nb_attributes + need_memory_type + need_pixel_format;
 
-ctx->attributes = av_malloc(ctx->nb_attributes *
-sizeof(*ctx->attributes));
-if (!ctx->attributes) {
-err = AVERROR(ENOMEM);
-goto fail;
-}
+ctx->attributes = av_malloc(ctx->nb_attributes *
+sizeof(*ctx->attributes));
+if (!ctx->attributes) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
 
-for (i = 0; i < avfc->nb_attributes; i++)
-ctx->attributes[i] = avfc->attributes[i];
-if (need_memory_type) {
-ctx->attributes

[FFmpeg-devel] [PATCH v5 1/2] configure, lavu, lavc, lavfi: Remove libva 1.x support

2024-06-05 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.  Various features no longer need any
configure check after this change, including all codecs except AV1.
Note that the libva version is the API version plus one, so this is
removing support for VAAPI 0.x and requiring VAAPI 1.x.
---
Now squashed.


 configure  | 25 +++
 libavcodec/vaapi_decode.c  | 39 ++---
 libavcodec/vaapi_encode.c  | 78 ++
 libavcodec/vaapi_encode.h  |  9 
 libavcodec/vaapi_encode_h264.c | 18 
 libavcodec/vaapi_encode_h265.c |  2 -
 libavfilter/vaapi_vpp.c| 22 --
 libavutil/hwcontext_vaapi.c| 22 --
 8 files changed, 29 insertions(+), 186 deletions(-)

diff --git a/configure b/configure
index 6c5b8aab9a..06e6fa22f2 100755
--- a/configure
+++ b/configure
@@ -2630,7 +2630,6 @@ CONFIG_EXTRA="
 texturedsp
 texturedspenc
 tpeldsp
-vaapi_1
 vaapi_encode
 vc1dsp
 videodsp
@@ -3200,7 +3199,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
 hevc_nvdec_hwaccel_select="hevc_decoder"
-hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
+hevc_vaapi_hwaccel_deps="vaapi"
 hevc_vaapi_hwaccel_select="hevc_decoder"
 hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
 hevc_vdpau_hwaccel_select="hevc_decoder"
@@ -3272,7 +3271,7 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
 vp9_nvdec_hwaccel_select="vp9_decoder"
-vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
+vp9_vaapi_hwaccel_deps="vaapi"
 vp9_vaapi_hwaccel_select="vp9_decoder"
 vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
 vp9_vdpau_hwaccel_select="vp9_decoder"
@@ -3365,7 +3364,6 @@ hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
 hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
 hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
-hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
 hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
 hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
@@ -3374,7 +3372,6 @@ mjpeg_cuvid_decoder_deps="cuvid"
 mjpeg_qsv_decoder_select="qsvdec"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
-mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
 mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
 mp3_mf_encoder_deps="mediafoundation"
 mpeg1_cuvid_decoder_deps="cuvid"
@@ -3403,7 +3400,6 @@ vp8_mediacodec_decoder_deps="mediacodec"
 vp8_mediacodec_encoder_deps="mediacodec"
 vp8_qsv_decoder_select="qsvdec"
 vp8_rkmpp_decoder_deps="rkmpp"
-vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
 vp8_vaapi_encoder_select="vaapi_encode"
 vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
@@ -3412,7 +3408,6 @@ vp9_mediacodec_decoder_deps="mediacodec"
 vp9_mediacodec_encoder_deps="mediacodec"
 vp9_qsv_decoder_select="qsvdec"
 vp9_rkmpp_decoder_deps="rkmpp"
-vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
 vp9_vaapi_encoder_select="vaapi_encode"
 vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
 vp9_qsv_encoder_select="qsvenc"
@@ -3966,9 +3961,9 @@ xfade_vulkan_filter_deps="vulkan spirv_compiler"
 yadif_cuda_filter_deps="ffnvcodec"
 yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
 yadif_videotoolbox_filter_deps="metal corevideo videotoolbox"
-hstack_vaapi_filter_deps="vaapi_1"
-vstack_vaapi_filter_deps="vaapi_1"
-xstack_vaapi_filter_deps="vaapi_1"
+hstack_vaapi_filter_deps="vaapi"
+vstack_vaapi_filter_deps="vaapi"
+xstack_vaapi_filter_deps="vaapi"
 hstack_qsv_filter_deps="libmfx"
 hstack_qsv_filter_select="qsvvpp"
 vstack_qsv_filter_deps="libmfx"
@@ -7271,7 +7266,7 @@ enabled libdrm &&
 check_pkg_config libdrm_getfb2 libdrm "xf86drmMode.h" drmModeGetFB2
 
 enabled vaapi &&
-check_pkg_config vaapi "libva >= 0.35.0" "va/va.h" vaInitialize
+check_pkg_config vaapi "libva >= 1.0.0" "va/va.h" vaInitialize
 
 if enabled vaapi; then
 case $target_os in
@@ -7287,18 +7282,10 @@ if enabled vaapi; then
 check_pkg_config vaapi_x11 "libva-x11" "va/va_x11.h" vaGetDisplay
 fi
 
-check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
-
-check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
-check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
 check_struct "va/va.h" "VADecPictureParameterBufferAV1" bit_depth_idx
 check_type   "va/va.h va/va_vpp.h" 
"VAProcFilterParameterBufferHDRToneMapping"
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" rotation_flags
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" blend_flags
-check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
-check_type "va/va.h

[FFmpeg-devel] [PATCH v3 3/3] lavc/vaapi_hevc: Don't require exact profiles

2024-06-05 Thread Mark Thompson
Rather than turning the constraint flags into a single profile and then
searching for that profile (and failing if it doesn't match any profile
exactly), instead search all supported profiles and use the first one
which supports the given set of constraint flags.
---
 libavcodec/vaapi_decode.c | 45 +++---
 libavcodec/vaapi_hevc.c   | 99 ++-
 libavcodec/vaapi_hevc.h   |  4 +-
 3 files changed, 87 insertions(+), 61 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 7c91d50f7b..c9d8add69f 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -393,7 +393,9 @@ static const struct {
 enum AVCodecID codec_id;
 int codec_profile;
 VAProfile va_profile;
-VAProfile (*profile_parser)(AVCodecContext *avctx);
+VAProfile (*match_profile)(AVCodecContext *avctx,
+   const VAProfile *profile_list,
+   int profile_count);
 } vaapi_profile_map[] = {
 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## 
v, __VA_ARGS__ }
 MAP(MPEG2VIDEO,  MPEG2_SIMPLE,MPEG2Simple ),
@@ -420,9 +422,9 @@ static const struct {
 #endif
 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
 MAP(HEVC,HEVC_REXT,   None,
- ff_vaapi_parse_hevc_rext_scc_profile ),
+ ff_vaapi_hevc_match_rext_scc_profile ),
 MAP(HEVC,HEVC_SCC,None,
- ff_vaapi_parse_hevc_rext_scc_profile ),
+ ff_vaapi_hevc_match_rext_scc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
@@ -505,22 +507,33 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 vaapi_profile_map[i].codec_profile == AV_PROFILE_UNKNOWN)
 profile_match = 1;
 
-va_profile = vaapi_profile_map[i].profile_parser ?
- vaapi_profile_map[i].profile_parser(avctx) :
- vaapi_profile_map[i].va_profile;
 codec_profile = vaapi_profile_map[i].codec_profile;
-
-for (j = 0; j < profile_count; j++) {
-if (va_profile == profile_list[j]) {
-exact_match = profile_match;
+if (vaapi_profile_map[i].match_profile) {
+va_profile =
+vaapi_profile_map[i].match_profile(avctx, profile_list,
+   profile_count);
+if (va_profile != VAProfileNone) {
+matched_va_profile = va_profile;
+matched_ff_profile = codec_profile;
+exact_match = 1;
 break;
 }
-}
-if (j < profile_count) {
-matched_va_profile = va_profile;
-matched_ff_profile = codec_profile;
-if (exact_match)
-break;
+} else {
+va_profile = vaapi_profile_map[i].va_profile;
+
+for (j = 0; j < profile_count; j++) {
+if (va_profile == profile_list[j]) {
+exact_match = profile_match;
+break;
+}
+}
+
+if (j < profile_count) {
+matched_va_profile = va_profile;
+matched_ff_profile = codec_profile;
+if (exact_match)
+break;
+}
 }
 }
 av_freep(&profile_list);
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 6164a1d223..716a4a4b43 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -589,63 +589,74 @@ static int ptl_convert(const PTLCommon *general_ptl, 
H265RawProfileTierLevel *h2
 }
 
 /*
- * Find exact va_profile for HEVC Range Extension and Screen Content Coding 
Extension
+ * Find compatible va_profile for HEVC Range Extension and Screen
+ * Content Coding Extension profiles.
  */
-VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
+VAProfile ff_vaapi_hevc_match_rext_scc_profile(AVCodecContext *avctx,
+   const VAProfile *profile_list,
+   int profile_count)
 {
 const HEVCContext *h = avctx->priv_data;
 const HEVCSPS *sps = h->ps.sps;
 const PTL *ptl = &sps->ptl;
 const PTLCommon *general_ptl = &ptl->general_ptl;
-const H265ProfileDescriptor *profile;
 H265RawProfileTierLevel h265_raw_ptl = {0};
 
+static const struct {
+enum H265Profile profile;
+VAProfile va_profile;
+} map[] = {
+#if VA_CHECK_VERSION(1, 2, 0)
+{ H265_PROFILE_MAIN_12,
+  VAProfileHEVCMain12 },
+{ H265_PROFILE_MAIN_422_10,
+  VAProfileHEVCMain422_10 },
+{ H265_PROFILE_MAIN_422_12,
+  VAProfileHEVCMain422_12 },
+{ H265_PROFILE_MAIN_444,
+  VAProfileHEVCMain444 },
+{ H265_PROFILE_MAIN_444_10,
+  VAProfile

[FFmpeg-devel] [PATCH v3 2/3] lavc: Add test for H.265 profile handling

2024-06-05 Thread Mark Thompson
---
 libavcodec/Makefile  |   2 +-
 libavcodec/tests/.gitignore  |   1 +
 libavcodec/tests/h265_profiles.c | 440 +++
 tests/fate/libavcodec.mak|   5 +
 4 files changed, 447 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/tests/h265_profiles.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 8ab4398b6c..e7973fb2e6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1297,7 +1297,7 @@ TESTPROGS-$(CONFIG_MJPEG_ENCODER) += 
mjpegenc_huffman
 TESTPROGS-$(HAVE_MMX) += motion
 TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
 TESTPROGS-$(CONFIG_H264_METADATA_BSF) += h264_levels
-TESTPROGS-$(CONFIG_HEVC_METADATA_BSF) += h265_levels
+TESTPROGS-$(CONFIG_HEVC_METADATA_BSF) += h265_levels h265_profiles
 TESTPROGS-$(CONFIG_RANGECODER)+= rangecoder
 TESTPROGS-$(CONFIG_SNOW_ENCODER)  += snowenc
 
diff --git a/libavcodec/tests/.gitignore b/libavcodec/tests/.gitignore
index 0df4ae10a0..bf29f03911 100644
--- a/libavcodec/tests/.gitignore
+++ b/libavcodec/tests/.gitignore
@@ -10,6 +10,7 @@
 /golomb
 /h264_levels
 /h265_levels
+/h265_profiles
 /htmlsubtitles
 /iirfilter
 /jpeg2000dwt
diff --git a/libavcodec/tests/h265_profiles.c b/libavcodec/tests/h265_profiles.c
new file mode 100644
index 00..37fc545558
--- /dev/null
+++ b/libavcodec/tests/h265_profiles.c
@@ -0,0 +1,440 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/bprint.h"
+#include "libavutil/common.h"
+#include "libavcodec/h265_profile_level.h"
+
+
+enum {
+TYPE_MAIN,
+TYPE_SP,
+TYPE_REXT_INTER,
+TYPE_REXT_INTRA,
+TYPE_HT,
+TYPE_HT_INTRA,
+TYPE_SCC,
+TYPE_HT_SCC,
+TYPE_COUNT,
+};
+enum {
+DEPTH_8,
+DEPTH_10,
+DEPTH_12,
+DEPTH_14,
+DEPTH_16,
+DEPTH_COUNT,
+};
+enum {
+CHROMA_MONO,
+CHROMA_420,
+CHROMA_422,
+CHROMA_444,
+CHROMA_COUNT,
+};
+
+// Table of all profiles indexed by chroma subsampling, bit depth and
+// profile type.  This is currently only being used to verify that
+// profile properties are correct, but if there is some other need for
+// this lookup in lavc then the table should be moved to the common
+// profile-level code.  All profiles should appear exactly once in this
+// table (also verified by a test below).
+static enum H265Profile profile_table[CHROMA_COUNT][DEPTH_COUNT][TYPE_COUNT] = 
{
+[CHROMA_MONO] = {
+[DEPTH_8] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MONOCHROME,
+},
+[DEPTH_10] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MONOCHROME_10,
+},
+[DEPTH_12] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MONOCHROME_12,
+},
+[DEPTH_16] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MONOCHROME_16,
+},
+},
+[CHROMA_420] = {
+[DEPTH_8] = {
+[TYPE_MAIN]   = H265_PROFILE_MAIN,
+[TYPE_SP] = H265_PROFILE_MAIN_STILL_PICTURE,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_INTRA,
+[TYPE_SCC]= H265_PROFILE_SCREEN_EXTENDED_MAIN,
+},
+[DEPTH_10] = {
+[TYPE_MAIN]   = H265_PROFILE_MAIN_10,
+[TYPE_SP] = H265_PROFILE_MAIN_10_STILL_PICTURE,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_10_INTRA,
+[TYPE_SCC]= H265_PROFILE_SCREEN_EXTENDED_MAIN_10,
+},
+[DEPTH_12] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MAIN_12,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_12_INTRA,
+},
+},
+[CHROMA_422] ={
+[DEPTH_10] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MAIN_422_10,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_422_10_INTRA,
+},
+[DEPTH_12] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MAIN_422_12,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_422_12_INTRA,
+},
+},
+[CHROMA_444] ={
+[DEPTH_8] = {
+[TYPE_SP] = H265_PROFILE_MAIN_444_STILL_PICTURE,
+[TYPE_REXT_INTER] = H265_PROFILE_MAIN_444,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_444_INTRA,
+[TYPE_HT] = H265_PROFILE_HIGH_THROUGHPUT

[FFmpeg-devel] [PATCH v3 1/3] lavc/h265_profile_level: Expand profile compatibility checking

2024-06-05 Thread Mark Thompson
Replace existing get_profile() with find_profile(), which finds the
lowest compatible profile rather than requiring an exact match.
---
Now with an enum tag.


 libavcodec/h265_profile_level.c | 80 +
 libavcodec/h265_profile_level.h | 70 -
 libavcodec/tests/h265_levels.c  |  2 +-
 libavcodec/vaapi_hevc.c |  2 +-
 libavcodec/vdpau_hevc.c |  2 +-
 5 files changed, 124 insertions(+), 32 deletions(-)

diff --git a/libavcodec/h265_profile_level.c b/libavcodec/h265_profile_level.c
index 7ff9681f65..1e96ec1c32 100644
--- a/libavcodec/h265_profile_level.c
+++ b/libavcodec/h265_profile_level.c
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "h265_profile_level.h"
 
 
@@ -40,6 +42,7 @@ static const H265LevelDescriptor h265_levels[] = {
 };
 
 static const H265ProfileDescriptor h265_profiles[] = {
+{ "Invalid" },
 // profile_idc   8bit   one-picture
 //   HT-profile  | 422chroma| lower-bit-rate
 //   |  14bit|  | 420chroma |  | CpbVclFactor MinCrScaleFactor
@@ -119,41 +122,62 @@ static const H265ProfileDescriptor h265_profiles[] = {
   5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5, 6 },
 };
 
+static_assert(H265_PROFILE_COUNT == FF_ARRAY_ELEMS(h265_profiles),
+  "Incorrect H.265 profiles table.");
+
 
-const H265ProfileDescriptor *ff_h265_get_profile(const H265RawProfileTierLevel 
*ptl)
+const int ff_h265_profile_compatible(const H265RawProfileTierLevel *ptl,
+ enum H265Profile profile)
 {
-int i;
+const H265ProfileDescriptor *desc;
+
+av_assert0(profile > H265_PROFILE_INVALID &&
+   profile < H265_PROFILE_COUNT);
 
 if (ptl->general_profile_space)
-return NULL;
+return 0;
 
-for (i = 0; i < FF_ARRAY_ELEMS(h265_profiles); i++) {
-const H265ProfileDescriptor *profile = &h265_profiles[i];
+desc = &h265_profiles[profile];
 
-if (ptl->general_profile_idc &&
-ptl->general_profile_idc != profile->profile_idc)
-continue;
-if (!ptl->general_profile_compatibility_flag[profile->profile_idc])
-continue;
+if (ptl->general_profile_idc &&
+ptl->general_profile_idc != desc->profile_idc)
+return 0;
+if (!ptl->general_profile_compatibility_flag[desc->profile_idc])
+return 0;
 
-#define check_flag(name) \
-if (profile->name < 2) { \
-if (profile->name != ptl->general_ ## name ## _constraint_flag) \
-continue; \
-}
-check_flag(max_14bit);
-check_flag(max_12bit);
-check_flag(max_10bit);
-check_flag(max_8bit);
-check_flag(max_422chroma);
-check_flag(max_420chroma);
-check_flag(max_monochrome);
-check_flag(intra);
-check_flag(one_picture_only);
-check_flag(lower_bit_rate);
+#define check_flag(flag) \
+if (desc->flag < 2 && \
+desc->flag > ptl->general_ ## flag ## _constraint_flag) \
+return 0;
+check_flag(max_14bit);
+check_flag(max_12bit);
+check_flag(max_10bit);
+check_flag(max_8bit);
+check_flag(max_422chroma);
+check_flag(max_420chroma);
+check_flag(max_monochrome);
+check_flag(intra);
+check_flag(one_picture_only);
+check_flag(lower_bit_rate);
 #undef check_flag
 
-return profile;
+return 1;
+}
+
+
+const H265ProfileDescriptor *ff_h265_get_profile(enum H265Profile profile)
+{
+av_assert0(profile > H265_PROFILE_INVALID &&
+   profile < H265_PROFILE_COUNT);
+
+return &h265_profiles[profile];
+}
+
+const H265ProfileDescriptor *ff_h265_find_profile(const 
H265RawProfileTierLevel *ptl)
+{
+for (int p = 1; p < H265_PROFILE_COUNT; p++) {
+if (ff_h265_profile_compatible(ptl, p))
+return &h265_profiles[p];
 }
 
 return NULL;
@@ -171,12 +195,12 @@ const H265LevelDescriptor *ff_h265_guess_level(const 
H265RawProfileTierLevel *pt
 int i;
 
 if (ptl)
-profile = ff_h265_get_profile(ptl);
+profile = ff_h265_find_profile(ptl);
 else
 profile = NULL;
 if (!profile) {
 // Default to using multiplication factors for Main profile.
-profile = &h265_profiles[4];
+profile = &h265_profiles[H265_PROFILE_MAIN];
 }
 
 pic_size = width * height;
diff --git a/libavcodec/h265_profile_level.h b/libavcodec/h265_profile_level.h
index cd30ac5c50..c019c738a7 100644
--- a/libavcodec/h265_profile_level.h
+++ b/libavcodec/h265_profile_level.h
@@ -24,6 +24,50 @@
 #include "cbs_h265.h"
 
 
+// Enumeration of all H.265 profiles.
+// The list is ordered to match table A.10; numeric values are an index
+// into the latest version of this table and have no codec meaning.
+enum H265Profile {
+H265_PROFILE_INVALID,
+H265_PROFILE_MONOCHROME,
+H265_PROFILE_MONOCHRO

Re: [FFmpeg-devel] [PATCH 02/10, v3] avcodec: add amfdec.

2024-06-04 Thread Mark Thompson
On 30/05/2024 14:08, Dmitrii Ovchinnikov wrote:
> From: Evgeny Pavlov 
> 
> Added AMF based h264, hevc, av1 decoders.
> Co-authored-by: Dmitrii Ovchinnikov 
> v2: added encoder reinitialisation
> v3: use AMF_SURFACE_UNKNOWN to int decoder(ctx->output_format before)
> ---
>  libavcodec/Makefile|   7 +-
>  libavcodec/allcodecs.c |   3 +
>  libavcodec/amfdec.c| 696 +
>  libavcodec/amfdec.h|  63 
>  4 files changed, 767 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/amfdec.c
>  create mode 100644 libavcodec/amfdec.h
> 
> ...
> +
> +const enum AVPixelFormat amf_dec_pix_fmts[] = {
> +AV_PIX_FMT_YUV420P,
> +AV_PIX_FMT_NV12,
> +AV_PIX_FMT_BGRA,
> +AV_PIX_FMT_ARGB,
> +AV_PIX_FMT_RGBA,
> +AV_PIX_FMT_GRAY8,
> +AV_PIX_FMT_BGR0,
> +AV_PIX_FMT_YUYV422,
> +AV_PIX_FMT_P010,
> +AV_PIX_FMT_P012,
> +AV_PIX_FMT_YUV420P10,
> +AV_PIX_FMT_YUV420P12,
> +AV_PIX_FMT_YUV420P16,
> +#if CONFIG_D3D11VA
> +AV_PIX_FMT_D3D11,
> +#endif
> +#if CONFIG_DXVA2
> +AV_PIX_FMT_DXVA2_VLD,
> +#endif
> +AV_PIX_FMT_AMF_SURFACE,
> +AV_PIX_FMT_NONE
> +};

What is this set of formats doing?  Most of them are ignored becase get_format 
below only ever offers two choices.

> +
> +static const AVCodecHWConfigInternal *const amf_hw_configs[] = {
> +&(const AVCodecHWConfigInternal) {
> +.public = {
> +.pix_fmt = AV_PIX_FMT_AMF_SURFACE,
> +.methods = AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX |

See below, I don't think it makes sense to have HW_FRAMES_CTX in this decoder.

> +   AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
> +.device_type = AV_HWDEVICE_TYPE_AMF,
> +},
> +.hwaccel = NULL,
> +},
> +NULL
> +};
> +
> ...
> +
> +static int amf_init_decoder(AVCodecContext *avctx)
> +{
> +AMFDecoderContext *ctx = avctx->priv_data;
> +AVAMFDeviceContext * internal = ctx->amf_device_ctx;
> +const wchar_t   *codec_id = NULL;
> +AMF_RESULT  res;
> +AMFBuffer   *buffer;
> +amf_int64   color_profile;
> +int pool_size = 36;
> +
> +ctx->drain = 0;
> +ctx->resolution_changed = 0;
> +
> +switch (avctx->codec->id) {
> +case AV_CODEC_ID_H264:
> +codec_id = AMFVideoDecoderUVD_H264_AVC;
> +break;
> +case AV_CODEC_ID_HEVC: {
> +if (avctx->profile == AV_PROFILE_HEVC_MAIN_10)

You won't know profile here?  It is an output field, the decoder has to set it 
once it determines it from the stream.

> +codec_id = AMFVideoDecoderHW_H265_MAIN10;
> +else
> +codec_id = AMFVideoDecoderHW_H265_HEVC;
> +} break;
> +case AV_CODEC_ID_AV1:
> +if (avctx->profile == AV_PROFILE_AV1_PROFESSIONAL)
> +codec_id = AMFVideoDecoderHW_AV1_12BIT;
> +else
> +codec_id = AMFVideoDecoderHW_AV1;
> +break;
> +default:
> +break;
> +}
> +AMF_RETURN_IF_FALSE(ctx, codec_id != NULL, AVERROR(EINVAL), "Codec %d is 
> not supported\n", avctx->codec->id);
> +
> +...> +
> +static int amf_decode_init(AVCodecContext *avctx)
> +{
> +AMFDecoderContext *ctx = avctx->priv_data;
> +int ret;
> +ctx->local_context = 0;
> +ctx->in_pkt = av_packet_alloc();
> +if (!ctx->in_pkt)
> +return AVERROR(ENOMEM);
> +
> +if (avctx->hw_frames_ctx){

This will never be set at init time because the user sets it in the get_format 
callback (see documentation for the field).

Even ignoring that, I don't see how this would make sense ayway?  The AMF 
frames context is a dummy shell containing nothing, so the 
AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX can't do anything useful.

(How are you testing this path?)

> +AVHWFramesContext *frames_ctx = 
> (AVHWFramesContext*)avctx->hw_frames_ctx->data;
> +if (frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_AMF) {
> +ctx->amf_device_ctx =  frames_ctx->device_ctx->hwctx;
> +}
> +}
> +else if  (avctx->hw_device_ctx && !avctx->hw_frames_ctx) {
> +AVHWDeviceContext   *hwdev_ctx;
> +AVHWFramesContext *hwframes_ctx;
> +hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
> +if (hwdev_ctx->type == AV_HWDEVICE_TYPE_AMF)
> +{
> +ctx->amf_device_ctx =  hwdev_ctx->hwctx;
> +}
> +
> +avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx);
> +
> +if (!avctx->hw_frames_ctx) {
> +av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_alloc failed\n");
> +return AVERROR(ENOMEM);
> +}
> +
> +hwframes_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
> +hwframes_ctx->width = FFALIGN(avctx->coded_width,  32);
> +hwframes_ctx->height= FFALIGN(avc

Re: [FFmpeg-devel] [PATCH 01/10, v3] avutil: add hwcontext_amf.

2024-06-04 Thread Mark Thompson
On 30/05/2024 14:08, Dmitrii Ovchinnikov wrote:
> Adds hwcontext_amf, which allows to use shared AMF
> context for the encoder, decoder and AMF-based filters,
> without copy to the host memory.
> It will also allow you to use some optimisations in
> the interaction of components (for example, SAV) and make a more
> manageable and optimal setup for using GPU devices with AMF
> in the case of a fully AMF pipeline.
> It will be a significant performance uplift when full AMF pipeline
> with filters is used.
> 
> We also plan to add Compression artefact removal filter in near feature.
> v2: cleanup header files
> v3: an unnecessary class has been removed.
> ---
>  libavutil/Makefile |   4 +
>  libavutil/hwcontext.c  |   4 +
>  libavutil/hwcontext.h  |   1 +
>  libavutil/hwcontext_amf.c  | 585 +
>  libavutil/hwcontext_amf.h  |  64 
>  libavutil/hwcontext_amf_internal.h |  44 +++
>  libavutil/hwcontext_internal.h |   1 +
>  libavutil/pixdesc.c|   4 +
>  libavutil/pixfmt.h |   5 +
>  9 files changed, 712 insertions(+)
>  create mode 100644 libavutil/hwcontext_amf.c
>  create mode 100644 libavutil/hwcontext_amf.h
>  create mode 100644 libavutil/hwcontext_amf_internal.h
> 
> ...
> +
> +static void amf_dummy_free(void *opaque, uint8_t *data)
> +{
> +
> +}
> +
> +static AVBufferRef *amf_pool_alloc(void *opaque, size_t size)
> +{
> +AVHWFramesContext *hwfc = (AVHWFramesContext *)opaque;
> +AVBufferRef *buf;
> +
> +buf = av_buffer_create(NULL, NULL, amf_dummy_free, hwfc, 
> AV_BUFFER_FLAG_READONLY);
> +if (!buf) {
> +av_log(hwfc, AV_LOG_ERROR, "Failed to create buffer for AMF 
> context.\n");
> +return NULL;
> +}
> +return buf;
> +}

You're still allocating nothing here?

I think what this means is that you don't actually want to implement frames 
context creation at all because it doesn't do anything.

If it is not possible to make an AMFSurface as anything other than an output 
from an AMF component then this would make sense, the decoder can allocate the 
internals.

Look at the DRM hwcontext for an example that works like this - the DRM objects 
can only be made as outputs from devices or by mapping, so there is no frame 
context implementation.

> +
> ...
> diff --git a/libavutil/hwcontext_amf.h b/libavutil/hwcontext_amf.h
> new file mode 100644
> index 00..ef2118dd4e
> --- /dev/null
> +++ b/libavutil/hwcontext_amf.h
> @@ -0,0 +1,64 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +
> +#ifndef AVUTIL_HWCONTEXT_AMF_H
> +#define AVUTIL_HWCONTEXT_AMF_H
> +
> +#include "pixfmt.h"
> +#include "hwcontext.h"
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/**
> + * This struct is allocated as AVHWDeviceContext.hwctx
> + */
> +typedef struct AVAMFDeviceContext {
> +HMODULElibrary;

What is this type?  (It looks like a Windows type, but I thought this was 
cross-platform.)

> +AMFFactory *factory;
> +AMFDebug   *debug;
> +AMFTrace   *trace;
> +void   *trace_writer;

Are all of these objects necessary to operation of the AMF device?  Please 
remove elements which are not necessary and add them to the private context if 
they are otherwise useful.

> +
> +int64_tversion; ///< version of AMF runtime

Why is the version necessary to expose in the public API?  Is it not possible 
to call the QueryVersion function after starting?

> +AMFContext *context;
> +intmem_type;
Is mem_type really necessary to expose in the piblic API?  Can the user not 
determine this by some API call?

> +} AVAMFDeviceContext;
> +
> +enum AMF_SURFACE_FORMAT av_amf_av_to_amf_format(enum AVPixelFormat fmt);
> +enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt);
> +

All of the following functions should not be public symbols.  You want to 
implement the hwcontext functions so that these all work without needing 
special implementation for AMF, they should not be individually callable 
because that is not useful.

> +int av_amf_context_create(AVAMFDeviceContext * context,
> + 

Re: [FFmpeg-devel] [PATCH v8 12/15] avcodec/vaapi_encode: extract a free funtion to base layer

2024-05-14 Thread Mark Thompson
On 18/04/2024 09:59, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/hw_base_encode.c | 11 +++
>  libavcodec/hw_base_encode.h |  2 ++
>  libavcodec/vaapi_encode.c   |  6 +-
>  3 files changed, 14 insertions(+), 5 deletions(-)

"... free funtion to ..."

While I do approve of fun, maybe this should be a function.

> diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
> index af85bb99aa..812668f3f2 100644
> --- a/libavcodec/hw_base_encode.c
> +++ b/libavcodec/hw_base_encode.c
> @@ -751,6 +751,17 @@ fail:
>  return err;
>  }
>  
> +int ff_hw_base_encode_free(AVCodecContext *avctx, HWBaseEncodePicture *pic)
> +{
> +av_frame_free(&pic->input_image);
> +av_frame_free(&pic->recon_image);
> +
> +av_buffer_unref(&pic->opaque_ref);
> +av_freep(&pic->priv_data);
> +
> +return 0;
> +}
> +
>  int ff_hw_base_encode_init(AVCodecContext *avctx)
>  {
>  HWBaseEncodeContext *ctx = avctx->priv_data;
> diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
> index 7686cf9501..d566980efc 100644
> --- a/libavcodec/hw_base_encode.h
> +++ b/libavcodec/hw_base_encode.h
> @@ -222,6 +222,8 @@ int ff_hw_base_init_gop_structure(AVCodecContext *avctx, 
> uint32_t ref_l0, uint32
>  
>  int ff_hw_base_get_recon_format(AVCodecContext *avctx, const void *hwconfig, 
> enum AVPixelFormat *fmt);
>  
> +int ff_hw_base_encode_free(AVCodecContext *avctx, HWBaseEncodePicture *pic);
> +
>  int ff_hw_base_encode_init(AVCodecContext *avctx);
>  
>  int ff_hw_base_encode_close(AVCodecContext *avctx);
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index ee4cf42baf..08792c07c5 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -878,17 +878,13 @@ static int vaapi_encode_free(AVCodecContext *avctx,
>  av_freep(&pic->slices[i].codec_slice_params);
>  }
>  
> -av_frame_free(&base_pic->input_image);
> -av_frame_free(&base_pic->recon_image);
> -
> -av_buffer_unref(&base_pic->opaque_ref);
> +ff_hw_base_encode_free(avctx, base_pic);
>  
>  av_freep(&pic->param_buffers);
>  av_freep(&pic->slices);
>  // Output buffer should already be destroyed.
>  av_assert0(pic->output_buffer == VA_INVALID_ID);
>  
> -av_freep(&base_pic->priv_data);
>  av_freep(&pic->codec_picture_params);
>  av_freep(&pic->roi);
>  

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v8 11/15] avcodec/vaapi_encode: extract a get_recon_format function to base layer

2024-05-14 Thread Mark Thompson
On 18/04/2024 09:59, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
> 
> Surface size and block size parameters are also moved to base layer.
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/hw_base_encode.c | 58 +++
>  libavcodec/hw_base_encode.h | 12 +
>  libavcodec/vaapi_encode.c   | 81 -
>  libavcodec/vaapi_encode.h   | 10 
>  libavcodec/vaapi_encode_av1.c   | 10 ++--
>  libavcodec/vaapi_encode_h264.c  | 11 +++--
>  libavcodec/vaapi_encode_h265.c  | 25 +-
>  libavcodec/vaapi_encode_mjpeg.c |  5 +-
>  libavcodec/vaapi_encode_vp9.c   |  6 +--
>  9 files changed, 118 insertions(+), 100 deletions(-)
> 
> diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
> index a4223d90f0..af85bb99aa 100644
> --- a/libavcodec/hw_base_encode.c
> +++ b/libavcodec/hw_base_encode.c
> @@ -693,6 +693,64 @@ int ff_hw_base_init_gop_structure(AVCodecContext *avctx, 
> uint32_t ref_l0, uint32
>  return 0;
>  }
>  
> +int ff_hw_base_get_recon_format(AVCodecContext *avctx, const void *hwconfig, 
> enum AVPixelFormat *fmt)
> +{
> +HWBaseEncodeContext *ctx = avctx->priv_data;
> +AVHWFramesConstraints *constraints = NULL;
> +enum AVPixelFormat recon_format;
> +int err, i;
> +
> +constraints = av_hwdevice_get_hwframe_constraints(ctx->device_ref,
> +  hwconfig);

Does this mechanism actually make sense for D3D12?

VAAPI is the currently the only implementation of this function with non-null 
hwconfig, and this is really relying on it to get useful information (otherwise 
the formats are just everything the device can allocate as a surface and the 
sizes are 0/INT_MAX).

If D3D12 has something which would fit into the hwconfig method then this could 
work very nicely as well, but if it doesn't then presumably it does have some 
other calls to check things like the maximum frame size supported by the 
encoder and we should be using those rather than making this code generic?

(Also consider Vulkan if possible; if two thirds of the cases want it then 
maybe we should do this even if it doesn't fit in one of them.)

> +if (!constraints) {
> +err = AVERROR(ENOMEM);
> +goto fail;
> +}
> +
> +// Probably we can use the input surface format as the surface format
> +// of the reconstructed frames.  If not, we just pick the first (only?)
> +// format in the valid list and hope that it all works.
> +recon_format = AV_PIX_FMT_NONE;
> +if (constraints->valid_sw_formats) {
> +for (i = 0; constraints->valid_sw_formats[i] != AV_PIX_FMT_NONE; 
> i++) {
> +if (ctx->input_frames->sw_format ==
> +constraints->valid_sw_formats[i]) {
> +recon_format = ctx->input_frames->sw_format;
> +break;
> +}
> +}
> +if (recon_format == AV_PIX_FMT_NONE) {
> +// No match.  Just use the first in the supported list and
> +// hope for the best.
> +recon_format = constraints->valid_sw_formats[0];
> +}
> +} else {
> +// No idea what to use; copy input format.
> +recon_format = ctx->input_frames->sw_format;
> +}
> +av_log(avctx, AV_LOG_DEBUG, "Using %s as format of "
> +   "reconstructed frames.\n", av_get_pix_fmt_name(recon_format));
> +
> +if (ctx->surface_width  < constraints->min_width  ||
> +ctx->surface_height < constraints->min_height ||
> +ctx->surface_width  > constraints->max_width ||
> +ctx->surface_height > constraints->max_height) {
> +av_log(avctx, AV_LOG_ERROR, "Hardware does not support encoding at "
> +   "size %dx%d (constraints: width %d-%d height %d-%d).\n",
> +   ctx->surface_width, ctx->surface_height,
> +   constraints->min_width,  constraints->max_width,
> +   constraints->min_height, constraints->max_height);
> +err = AVERROR(EINVAL);
> +goto fail;
> +}
> +
> +*fmt = recon_format;
> +err = 0;
> +fail:
> +av_hwframe_constraints_free(&constraints);
> +return err;
> +}
> +
>  int ff_hw_base_encode_init(AVCodecContext *avctx)
>  {
>  HWBaseEncodeContext *ctx = avctx->priv_data;
> diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
> index d717f955d8..7686cf9501 100644
> --- a/libavcodec/hw_base_encode.h
> +++ b/libavcodec/hw_base_encode.h
> @@ -126,6 +126,16 @@ typedef struct HWBaseEncodeContext {
>  // Desired B frame reference depth.
>  int desired_b_depth;
>  
> +// The required size of surfaces.  This is probably the input
> +// size (AVCodecContext.width|height) aligned up to whatever
> +// block size is required by the codec.
> +int surface_width;
> +int surface_height;
> +
> +// The block size for slice calculations.
> +int slic

Re: [FFmpeg-devel] [PATCH v8 06/15] avcodec/vaapi_encode: extract the init function to base layer

2024-05-14 Thread Mark Thompson
On 18/04/2024 09:59, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
> 
> Related parameters are also moved to base layer.
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/hw_base_encode.c | 33 
>  libavcodec/hw_base_encode.h | 11 ++
>  libavcodec/vaapi_encode.c   | 68 ++---
>  libavcodec/vaapi_encode.h   |  6 ---
>  libavcodec/vaapi_encode_av1.c   |  2 +-
>  libavcodec/vaapi_encode_h264.c  |  2 +-
>  libavcodec/vaapi_encode_h265.c  |  2 +-
>  libavcodec/vaapi_encode_mjpeg.c |  6 ++-
>  8 files changed, 72 insertions(+), 58 deletions(-)
> 
> diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
> index 1d9a255f69..14f3ecfc94 100644
> --- a/libavcodec/hw_base_encode.c
> +++ b/libavcodec/hw_base_encode.c
> @@ -598,3 +598,36 @@ end:
>  
>  return 0;
>  }
> +
> +int ff_hw_base_encode_init(AVCodecContext *avctx)
> +{
> +HWBaseEncodeContext *ctx = avctx->priv_data;
> +
> +ctx->frame = av_frame_alloc();
> +if (!ctx->frame)
> +return AVERROR(ENOMEM);
> +
> +if (!avctx->hw_frames_ctx) {
> +av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is "
> +   "required to associate the encoding device.\n");
> +return AVERROR(EINVAL);
> +}
> +
> +ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
> +if (!ctx->input_frames_ref)
> +return AVERROR(ENOMEM);
> +
> +ctx->input_frames = (AVHWFramesContext *)ctx->input_frames_ref->data;
> +
> +ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
> +if (!ctx->device_ref)
> +return AVERROR(ENOMEM);
> +
> +ctx->device = (AVHWDeviceContext *)ctx->device_ref->data;
> +
> +ctx->tail_pkt = av_packet_alloc();
> +if (!ctx->tail_pkt)
> +return AVERROR(ENOMEM);
> +
> +return 0;
> +}
> diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
> index b5b676b9a8..f7e385e840 100644
> --- a/libavcodec/hw_base_encode.h
> +++ b/libavcodec/hw_base_encode.h
> @@ -19,6 +19,7 @@
>  #ifndef AVCODEC_HW_BASE_ENCODE_H
>  #define AVCODEC_HW_BASE_ENCODE_H
>  
> +#include "libavutil/hwcontext.h"
>  #include "libavutil/fifo.h"
>  
>  #define MAX_DPB_SIZE 16
> @@ -117,6 +118,14 @@ typedef struct HWBaseEncodeContext {
>  // Hardware-specific hooks.
>  const struct HWEncodePictureOperation *op;
>  
> +// The hardware device context.
> +AVBufferRef*device_ref;
> +AVHWDeviceContext *device;
> +
> +// The hardware frame context containing the input frames.
> +AVBufferRef*input_frames_ref;
> +AVHWFramesContext *input_frames;
> +
>  // Current encoding window, in display (input) order.
>  HWBaseEncodePicture *pic_start, *pic_end;
>  // The next picture to use as the previous reference picture in
> @@ -183,6 +192,8 @@ typedef struct HWBaseEncodeContext {
>  
>  int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
>  
> +int ff_hw_base_encode_init(AVCodecContext *avctx);
> +
>  #define HW_BASE_ENCODE_COMMON_OPTIONS \
>  { "async_depth", "Maximum processing parallelism. " \
>"Increase this to improve single channel performance.", \

Maybe this patch should be merged with 9/15 to keep the init/close symmetry?  
It's not clear that the intermediate makes sense, and it has some churn.

> ...

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v8 05/15] avcodec/vaapi_encode: move the dpb logic from VAAPI to base layer

2024-05-14 Thread Mark Thompson
On 18/04/2024 09:58, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
> 
> Move receive_packet function to base. This requires adding *alloc,
> *issue, *output, *free as hardware callbacks. HWBaseEncodePicture is
> introduced as the base layer structure. The related parameters in
> VAAPIEncodeContext are also extracted to HWBaseEncodeContext. Then DPB
> management logic can be fully extracted to base layer as-is.
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/Makefile |   2 +-
>  libavcodec/hw_base_encode.c | 600 
>  libavcodec/hw_base_encode.h | 123 +
>  libavcodec/vaapi_encode.c   | 793 +---
>  libavcodec/vaapi_encode.h   | 102 +---
>  libavcodec/vaapi_encode_av1.c   |  51 +-
>  libavcodec/vaapi_encode_h264.c  | 176 +++
>  libavcodec/vaapi_encode_h265.c  | 121 ++---
>  libavcodec/vaapi_encode_mjpeg.c |   7 +-
>  libavcodec/vaapi_encode_mpeg2.c |  47 +-
>  libavcodec/vaapi_encode_vp8.c   |  18 +-
>  libavcodec/vaapi_encode_vp9.c   |  54 +--
>  12 files changed, 1097 insertions(+), 997 deletions(-)
>  create mode 100644 libavcodec/hw_base_encode.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 7f6de4470e..a2174dcb2f 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -162,7 +162,7 @@ OBJS-$(CONFIG_STARTCODE)   += startcode.o
>  OBJS-$(CONFIG_TEXTUREDSP)  += texturedsp.o
>  OBJS-$(CONFIG_TEXTUREDSPENC)   += texturedspenc.o
>  OBJS-$(CONFIG_TPELDSP) += tpeldsp.o
> -OBJS-$(CONFIG_VAAPI_ENCODE)+= vaapi_encode.o
> +OBJS-$(CONFIG_VAAPI_ENCODE)+= vaapi_encode.o hw_base_encode.o
>  OBJS-$(CONFIG_AV1_AMF_ENCODER) += amfenc_av1.o
>  OBJS-$(CONFIG_VC1DSP)  += vc1dsp.o
>  OBJS-$(CONFIG_VIDEODSP)+= videodsp.o
> diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c
> new file mode 100644
> index 00..1d9a255f69
> --- /dev/null
> +++ b/libavcodec/hw_base_encode.c
> @@ -0,0 +1,600 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "libavutil/avassert.h"
> +#include "libavutil/common.h"
> +#include "libavutil/internal.h"
> +#include "libavutil/log.h"
> +#include "libavutil/mem.h"
> +#include "libavutil/pixdesc.h"
> +
> +#include "encode.h"
> +#include "avcodec.h"
> +#include "hw_base_encode.h"
> +
> ...

Everything above here looks like a copy of the VAAPI code with the names 
changed, good if so.  (If not then please highlight any differences.)

> +
> +static int hw_base_encode_send_frame(AVCodecContext *avctx, AVFrame *frame)
> +{
> +HWBaseEncodeContext *ctx = avctx->priv_data;
> +HWBaseEncodePicture *pic;
> +int err;
> +
> +if (frame) {
> +av_log(avctx, AV_LOG_DEBUG, "Input frame: %ux%u (%"PRId64").\n",
> +   frame->width, frame->height, frame->pts);
> +
> +err = hw_base_encode_check_frame(avctx, frame);
> +if (err < 0)
> +return err;
> +
> +pic = ctx->op->alloc(avctx, frame);
> +if (!pic)
> +return AVERROR(ENOMEM);

Can you push the allocation of this picture out into the base layer?  
vaapi_encode_alloc() and d3d12va_encode_alloc() are identical except for the 
types and the input_surface setting.

> +
> +pic->input_image = av_frame_alloc();
> +if (!pic->input_image) {
> +err = AVERROR(ENOMEM);
> +goto fail;
> +}
> +
> +pic->recon_image = av_frame_alloc();
> +if (!pic->recon_image) {
> +err = AVERROR(ENOMEM);
> +goto fail;
> +}
> +
> +if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I)
> +pic->force_idr = 1;
> +
> +pic->pts = frame->pts;
> +pic->duration = frame->duration;
> +
> +if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
> +err = av_buffer_replace(&pic->opaque_ref, frame->opaque_ref);
> +if (err < 0)
> +goto fail;
> +
> +pic->opaque = frame->opaque;
> +}
> +
> +av_frame_move_ref(pic->input_image, frame);
> +
> +if (ctx->input_order == 0)
> +ctx->f

Re: [FFmpeg-devel] [PATCH v8 01/15] avcodec/vaapi_encode: introduce a base layer for vaapi encode

2024-05-14 Thread Mark Thompson
On 18/04/2024 09:58, tong1.wu-at-intel@ffmpeg.org wrote:
> From: Tong Wu 
> 
> Since VAAPI and future D3D12VA implementation may share some common 
> parameters,
> a base layer encode context is introduced as vaapi context's base.
> 
> Signed-off-by: Tong Wu 
> ---
>  libavcodec/hw_base_encode.h | 52 +
>  libavcodec/vaapi_encode.h   | 36 -
>  2 files changed, 57 insertions(+), 31 deletions(-)
>  create mode 100644 libavcodec/hw_base_encode.h
> 
> diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h
> new file mode 100644
> index 00..3d1974bba3
> --- /dev/null
> +++ b/libavcodec/hw_base_encode.h
> @@ -0,0 +1,52 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#ifndef AVCODEC_HW_BASE_ENCODE_H
> +#define AVCODEC_HW_BASE_ENCODE_H
> +
> +#define MAX_DPB_SIZE 16
> +#define MAX_PICTURE_REFERENCES 2
> +#define MAX_REORDER_DELAY 16
> +#define MAX_ASYNC_DEPTH 64
> +#define MAX_REFERENCE_LIST_NUM 2

Is there a reason to change these from enum to defines?  I'm not seeing 
anywhere they should be visible to the preprocessor, and this means they are 
normally invisible to a debugger.

> +
> +enum {
> +PICTURE_TYPE_IDR = 0,
> +PICTURE_TYPE_I   = 1,
> +PICTURE_TYPE_P   = 2,
> +PICTURE_TYPE_B   = 3,
> +};
> +
> +enum {
> +// Codec supports controlling the subdivision of pictures into slices.
> +FLAG_SLICE_CONTROL = 1 << 0,
> +// Codec only supports constant quality (no rate control).
> +FLAG_CONSTANT_QUALITY_ONLY = 1 << 1,
> +// Codec is intra-only.
> +FLAG_INTRA_ONLY= 1 << 2,
> +// Codec supports B-pictures.
> +FLAG_B_PICTURES= 1 << 3,
> +// Codec supports referencing B-pictures.
> +FLAG_B_PICTURE_REFERENCES  = 1 << 4,
> +// Codec supports non-IDR key pictures (that is, key pictures do
> +// not necessarily empty the DPB).
> +FLAG_NON_IDR_KEY_PICTURES  = 1 << 5,
> +};
> +
> +#endif /* AVCODEC_HW_BASE_ENCODE_H */
> ...

Would it make more sense to put the HWBaseEncodeContext in this patch as well?  
(With just the AVClass member.)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [FFmpeg-cvslog] avcodec/cbs_av1: Avoid shift overflow

2024-05-09 Thread Mark Thompson
On 09/05/2024 16:10, Michael Niedermayer wrote:
> ffmpeg | branch: master | Michael Niedermayer  | Wed 
> May  1 21:44:33 2024 +0200| [d7924a4f60f2088de1e6790345caba929eb97030] | 
> committer: Michael Niedermayer
> 
> avcodec/cbs_av1: Avoid shift overflow
> 
> Fixes: CID1465488 Unintentional integer overflow
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> 
>> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d7924a4f60f2088de1e6790345caba929eb97030
> ---
> 
>  libavcodec/cbs_av1.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
> index 1d9ac5ab44..fb82996022 100644
> --- a/libavcodec/cbs_av1.c
> +++ b/libavcodec/cbs_av1.c
> @@ -301,7 +301,7 @@ static int cbs_av1_write_increment(CodedBitstreamContext 
> *ctx, PutBitContext *pb
>  return AVERROR(ENOSPC);
>  
>  if (len > 0)
> -put_bits(pbc, len, (1 << len) - 1 - (value != range_max));
> +put_bits(pbc, len, (1U << len) - 1 - (value != range_max));
>  
>  CBS_TRACE_WRITE_END_NO_SUBSCRIPTS();
>  
What syntax element can call this with range_max - range_min == 31?  (Do you 
have a stream?)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v4 1/5] configure: Remove libva 1.x support

2024-05-07 Thread Mark Thompson
On 07/05/2024 06:27, Xiang, Haihao wrote:
> On So, 2024-05-05 at 20:01 +0100, Mark Thompson wrote:
>> libva 2.0 was released in 2017 and the 2.x versions are included in all
>> supported distributions nowadays.  Various features no longer need any
>> configure check after this command, including all codecs except AV1.
>> Note that the libva version is the API version plus one, so this is
>> removing support for VAAPI 0.x and requiring VAAPI 1.x.
>> ---
>> Changes to the series since v3:
>> * Reorder so that the series doesn't need to be squashed.
>> * New patch to remove the driver quirk support (deprecated in the public
>>   header, but will have no effect if set).
>>
>>  configure | 25 ++---
>>  1 file changed, 6 insertions(+), 19 deletions(-)
>>
>> diff --git a/configure b/configure
>> index ed74583a6f..69fde0bf35 100755
>> --- a/configure
>> +++ b/configure
>> @@ -2625,7 +2625,6 @@ CONFIG_EXTRA="
>>  texturedsp
>>  texturedspenc
>>  tpeldsp
>> -    vaapi_1
> 
> CONFIG_VAAPI_1 is used in the code. Removing this only caused compiling 
> errors.
> 
> libavfilter/vaapi_vpp.c: In function ‘ff_vaapi_vpp_config_output’:
> libavfilter/vaapi_vpp.c:207:9: error: ‘CONFIG_VAAPI_1’ undeclared (first use 
> in
> this function); did you mean ‘CONFIG_VAAPI’?
>   207 | if (CONFIG_VAAPI_1)
>   | ^~
>   | CONFIG_VAAPI

You are correct; I didn't think this split through carefully.

I suggest returning to the original idea of squashing before push so that the 
removal is atomic?  I'm not sure it's worth dealing with the intermediate 
states given that they have no particular use.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_h264: Fix merging fields in DPB with missing references

2024-05-07 Thread Mark Thompson
On 07/05/2024 07:00, David Rosca wrote:
> If there are missing references, h264 decode does error concealment
> by copying previous refs which means there will be duplicated surfaces
> and this code would try to merge them instead of correctly appending
> to DPB. Make sure the fields were actually merged before early return.
> ---
>  libavcodec/vaapi_h264.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> index b47531ce1c..c62a320e97 100644
> --- a/libavcodec/vaapi_h264.c
> +++ b/libavcodec/vaapi_h264.c
> @@ -112,8 +112,9 @@ static int dpb_add(DPB *dpb, const H264Picture *pic)
>  } else {
>  va_pic->BottomFieldOrderCnt = 
> temp_va_pic.BottomFieldOrderCnt;
>  }
> +return 0;
>  }
> -return 0;
> +break;
>  }
>  }
>  

I agree that the old code did nasty things, but can you explain a bit more 
about the reasoning for what you've got now?

I'm thinking that given duplication a top field could appear twice, so you'd 
want to merge twice if you have the matching bottom field.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_av1: Avoid sending the same slice buffer multiple times

2024-05-07 Thread Mark Thompson
On 28/04/2024 08:26, David Rosca wrote:
> When there are multiple tiles in one slice buffer, use multiple slice
> params to avoid sending the same slice buffer multiple times and thus
> increasing the bitstream size the driver will need to upload to hw.
> ---
>  libavcodec/vaapi_av1.c | 37 +++--
>  1 file changed, 23 insertions(+), 14 deletions(-)

Can you confirm that this works on at least iHD (Intel) and Mesa (AMD)?  (I 
don't expect any issue, but it's good to check in case of something strange 
going on matching up to what this was previously doing.)

> diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
> index 4a90db1e09..567f505fbd 100644
> --- a/libavcodec/vaapi_av1.c
> +++ b/libavcodec/vaapi_av1.c
> @@ -19,6 +19,7 @@
>   */
>  
>  #include "libavutil/frame.h"
> +#include "libavutil/mem.h"
>  #include "hwaccel_internal.h"
>  #include "vaapi_decode.h"
>  #include "internal.h"
> @@ -393,13 +394,17 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
>  {
>  const AV1DecContext *s = avctx->priv_data;
>  VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
> -VASliceParameterBufferAV1 slice_param;
> -int err = 0;
> +VASliceParameterBufferAV1 *slice_params;
> +int err = 0, nb_params = 0;

Remove the spurious initialisation on err?

>  
> -for (int i = s->tg_start; i <= s->tg_end; i++) {
> -memset(&slice_param, 0, sizeof(VASliceParameterBufferAV1));
> +slice_params = av_calloc(s->tg_end - s->tg_start + 1, 
> sizeof(*slice_params));

I suggest allocating this into VAAPIAV1DecContext to avoid the alloc/free on 
every call.  (Only reallocate if it needs to be bigger than the previous 
maximum.)

> +if (!slice_params) {
> +err = AVERROR(ENOMEM);
> +goto fail;
> +}
>  
> -slice_param = (VASliceParameterBufferAV1) {
> +for (int i = s->tg_start; i <= s->tg_end; i++) {
> +slice_params[nb_params++] = (VASliceParameterBufferAV1) {
>  .slice_data_size   = s->tile_group_info[i].tile_size,
>  .slice_data_offset = s->tile_group_info[i].tile_offset,
>  .slice_data_flag   = VA_SLICE_DATA_FLAG_ALL,
> @@ -408,18 +413,22 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
>  .tg_start  = s->tg_start,
>  .tg_end= s->tg_end,
>  };
> -
> -err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
> -
> sizeof(VASliceParameterBufferAV1),
> -buffer,
> -size);
> -if (err) {
> -ff_vaapi_decode_cancel(avctx, pic);
> -return err;
> -}
>  }
>  
> +err = ff_vaapi_decode_make_slice_buffer(avctx, pic, slice_params, 
> nb_params,
> +
> sizeof(VASliceParameterBufferAV1),
> +buffer,
> +size);
> +av_free(slice_params);
> +
> +if (err)
> +goto fail;
> +
>  return 0;
> +
> +fail:
> +ff_vaapi_decode_cancel(avctx, pic);
> +return err;
>  }
>  
>  const FFHWAccel ff_av1_vaapi_hwaccel = {

It's amusing that this quadratic behaviour was around for so long!  (I guess 
people don't use many tiles.)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/3] lavc/h265_profile_level: Expand profile compatibility checking

2024-05-06 Thread Mark Thompson
On 06/05/2024 20:56, Andreas Rheinhardt wrote:
> Mark Thompson:
>> Replace existing get_profile() with find_profile(), which finds the
>> lowest compatible profile rather than requiring an exact match.
>> ---
>> Series changes since v1:
>> * Added H265_PROFILE_INVALID with value zero because it simplifies some code 
>> (and the values don't matter).
> 
> What code is simplified by using zero (instead of -1)? I only see that
> it leads to the addition of an unnecessary entry to h265_profiles.

The large number of empty entries in profile_table in the test work by being 
zero-initialised.  Filling them with -1 would not be fun.

(I originally put that table (and the bprint function) in h265_profile_level.c, 
but when no library caller was using it I moved it to the test.)

>> * Fixed the h265-levels test.
>> * Added a new h265-profiles test which tests the profile compatibility 
>> checking.
>> * Fixed missing VAAPI profiles.
>>
>>
>>  libavcodec/h265_profile_level.c | 78 +
>>  libavcodec/h265_profile_level.h | 71 +-
>>  libavcodec/tests/h265_levels.c  |  2 +-
>>  libavcodec/vaapi_hevc.c |  2 +-
>>  libavcodec/vdpau_hevc.c |  2 +-
>>  5 files changed, 123 insertions(+), 32 deletions(-)
>>
>> diff --git a/libavcodec/h265_profile_level.c 
>> b/libavcodec/h265_profile_level.c
>> index 7ff9681f65..2e4a1c88bf 100644
>> --- a/libavcodec/h265_profile_level.c
>> +++ b/libavcodec/h265_profile_level.c
>> @@ -40,6 +40,7 @@ static const H265LevelDescriptor h265_levels[] = {
>>  };
>>  
>>  static const H265ProfileDescriptor h265_profiles[] = {
>> +{ "Invalid" },
>>  // profile_idc   8bit   one-picture
>>  //   HT-profile  | 422chroma| lower-bit-rate
>>  //   |  14bit|  | 420chroma |  | CpbVclFactor MinCrScaleFactor
>> @@ -119,41 +120,62 @@ static const H265ProfileDescriptor h265_profiles[] = {
>>5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5, 6 },
>>  };
>>  
>> +_Static_assert(H265_PROFILE_COUNT == FF_ARRAY_ELEMS(h265_profiles),
>> +   "Incorrect H.265 profiles table.");
>>  
>> -const H265ProfileDescriptor *ff_h265_get_profile(const 
>> H265RawProfileTierLevel *ptl)
>> +
>> +const int ff_h265_profile_compatible(const H265RawProfileTierLevel *ptl,
>> + int profile)
> 
> Why don't you add a tag to this enum and pass a proper enum here?

No reason.  I can add an explicit type if you prefer that?

>>  {
>> -int i;
>> +const H265ProfileDescriptor *desc;
>> +
>> +av_assert0(profile > H265_PROFILE_INVALID &&
>> +   profile < H265_PROFILE_COUNT);
>>  
>>  if (ptl->general_profile_space)
>> -return NULL;
>> +return 0;
>>  
>> -for (i = 0; i < FF_ARRAY_ELEMS(h265_profiles); i++) {
>> -const H265ProfileDescriptor *profile = &h265_profiles[i];
>> +desc = &h265_profiles[profile];
>>  
>> -if (ptl->general_profile_idc &&
>> -ptl->general_profile_idc != profile->profile_idc)
>> -continue;
>> -if (!ptl->general_profile_compatibility_flag[profile->profile_idc])
>> -continue;
>> +if (ptl->general_profile_idc &&
>> +ptl->general_profile_idc != desc->profile_idc)
>> +return 0;
>> +if (!ptl->general_profile_compatibility_flag[desc->profile_idc])
>> +return 0;
>>  
>> -#define check_flag(name) \
>> -if (profile->name < 2) { \
>> -if (profile->name != ptl->general_ ## name ## _constraint_flag) 
>> \
>> -continue; \
>> -}
>> -check_flag(max_14bit);
>> -check_flag(max_12bit);
>> -check_flag(max_10bit);
>> -check_flag(max_8bit);
>> -check_flag(max_422chroma);
>> -check_flag(max_420chroma);
>> -check_flag(max_monochrome);
>> -check_flag(intra);
>> -check_flag(one_picture_only);
>> -check_flag(lower_bit_rate);
>> +#define check_flag(flag) \
>> +if (desc->flag < 2 && \
>> +desc->flag > ptl->general_ ## flag ## _constraint_flag) \
>> +return 0;
>> +check_flag(max_14bit);
>> +check_flag(max_12bit);
>> +check_flag(max_10bit);
>> +check_flag(max_8bit);
>> +check_flag(max_422chroma);
>> +check_flag(max_420chroma);
>> +check_flag(max_monochrome);
>> +check_flag(intra);
>> +check_flag(one_picture_only);
>> +check_flag(lower_bit_rate);
>>  #undef check_flag
>>  
>> -return profile;
>> +return 1;
>> +}
>> +
>> ...

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_h264: Don't try to merge fields in DPB for non-field pics

2024-05-06 Thread Mark Thompson
On 05/05/2024 17:36, David Rosca wrote:
> This path can be hit when there are missing references while decoding
> progressive stream and would completely break the DPB contents.
> ---
>  libavcodec/vaapi_h264.c | 30 --
>  1 file changed, 16 insertions(+), 14 deletions(-)

Can you share a stream which does this in a progressive case?

My understanding of this (though I suspect I am missing something) is that we 
are filling from the short/long DPB lists which should not contain duplicates 
(not RefPicListX, which can), so I'm not seeing how this case could be 
triggered.

If you do have two DPB entries which are different frames but refer to the same 
surface then that seems like a bug elsewhere.

Thanks,

- Mark


> diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
> index b47531ce1c..ca0076f57a 100644
> --- a/libavcodec/vaapi_h264.c
> +++ b/libavcodec/vaapi_h264.c
> @@ -98,22 +98,24 @@ static int dpb_add(DPB *dpb, const H264Picture *pic)
>  if (dpb->size >= dpb->max_size)
>  return -1;
>  
> -for (i = 0; i < dpb->size; i++) {
> -VAPictureH264 * const va_pic = &dpb->va_pics[i];
> -if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f)) {
> -VAPictureH264 temp_va_pic;
> -fill_vaapi_pic(&temp_va_pic, pic, 0);
> -
> -if ((temp_va_pic.flags ^ va_pic->flags) & 
> (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD)) {
> -va_pic->flags |= temp_va_pic.flags & 
> (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD);
> -/* Merge second field */
> -if (temp_va_pic.flags & VA_PICTURE_H264_TOP_FIELD) {
> -va_pic->TopFieldOrderCnt= 
> temp_va_pic.TopFieldOrderCnt;
> -} else {
> -va_pic->BottomFieldOrderCnt = 
> temp_va_pic.BottomFieldOrderCnt;
> +if (pic->field_picture) {
> +for (i = 0; i < dpb->size; i++) {
> +VAPictureH264 * const va_pic = &dpb->va_pics[i];
> +if (va_pic->picture_id == ff_vaapi_get_surface_id(pic->f)) {
> +VAPictureH264 temp_va_pic;
> +fill_vaapi_pic(&temp_va_pic, pic, 0);
> +
> +if ((temp_va_pic.flags ^ va_pic->flags) & 
> (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD)) {
> +va_pic->flags |= temp_va_pic.flags & 
> (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD);
> +/* Merge second field */
> +if (temp_va_pic.flags & VA_PICTURE_H264_TOP_FIELD) {
> +va_pic->TopFieldOrderCnt= 
> temp_va_pic.TopFieldOrderCnt;
> +} else {
> +va_pic->BottomFieldOrderCnt = 
> temp_va_pic.BottomFieldOrderCnt;
> +}
>  }
> +return 0;
>  }
> -return 0;
>  }
>  }
>  
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 4/6] nvdec_av1: Use av1dec force_integer_mv value

2024-05-06 Thread Mark Thompson
On 06/05/2024 18:19, Timo Rothenpieler wrote:
> On 27.04.2024 17:30, Mark Thompson wrote:
>> ---
>>   libavcodec/nvdec_av1.c | 4 +---
>>   1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c
>> index 4efa420e66..8a46db1ed5 100644
>> --- a/libavcodec/nvdec_av1.c
>> +++ b/libavcodec/nvdec_av1.c
>> @@ -106,9 +106,7 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx, 
>> const uint8_t *buffer, u
>>   .show_frame   = frame_header->show_frame,
>>   .disable_cdf_update   = 
>> frame_header->disable_cdf_update,
>>   .allow_screen_content_tools   = 
>> frame_header->allow_screen_content_tools,
>> -    .force_integer_mv = frame_header->force_integer_mv 
>> ||
>> -    frame_header->frame_type == 
>> AV1_FRAME_INTRA_ONLY ||
>> -    frame_header->frame_type == 
>> AV1_FRAME_KEY,
>> +    .force_integer_mv = s->cur_frame.force_integer_mv;
> 
> that ";" should be a ","
> 
> Works fine with that fixed.

Urgh, thank you for testing and catching that.

Fixed and pushed the set (with approval from Lynne).

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 3/3] lavc/vaapi_hevc: Don't require exact profiles

2024-05-06 Thread Mark Thompson
Rather than turning the constraint flags into a single profile and then
searching for that profile (and failing if it doesn't match any profile
exactly), instead search all supported profiles and use the first one
which supports the given set of constraint flags.
---
 libavcodec/vaapi_decode.c | 45 +++---
 libavcodec/vaapi_hevc.c   | 99 ++-
 libavcodec/vaapi_hevc.h   |  4 +-
 3 files changed, 87 insertions(+), 61 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 21b273cd0f..f1327464f5 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -387,7 +387,9 @@ static const struct {
 enum AVCodecID codec_id;
 int codec_profile;
 VAProfile va_profile;
-VAProfile (*profile_parser)(AVCodecContext *avctx);
+VAProfile (*match_profile)(AVCodecContext *avctx,
+   const VAProfile *profile_list,
+   int profile_count);
 } vaapi_profile_map[] = {
 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## 
v, __VA_ARGS__ }
 MAP(MPEG2VIDEO,  MPEG2_SIMPLE,MPEG2Simple ),
@@ -414,9 +416,9 @@ static const struct {
 #endif
 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
 MAP(HEVC,HEVC_REXT,   None,
- ff_vaapi_parse_hevc_rext_scc_profile ),
+ ff_vaapi_hevc_match_rext_scc_profile ),
 MAP(HEVC,HEVC_SCC,None,
- ff_vaapi_parse_hevc_rext_scc_profile ),
+ ff_vaapi_hevc_match_rext_scc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
@@ -499,22 +501,33 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 vaapi_profile_map[i].codec_profile == AV_PROFILE_UNKNOWN)
 profile_match = 1;
 
-va_profile = vaapi_profile_map[i].profile_parser ?
- vaapi_profile_map[i].profile_parser(avctx) :
- vaapi_profile_map[i].va_profile;
 codec_profile = vaapi_profile_map[i].codec_profile;
-
-for (j = 0; j < profile_count; j++) {
-if (va_profile == profile_list[j]) {
-exact_match = profile_match;
+if (vaapi_profile_map[i].match_profile) {
+va_profile =
+vaapi_profile_map[i].match_profile(avctx, profile_list,
+   profile_count);
+if (va_profile != VAProfileNone) {
+matched_va_profile = va_profile;
+matched_ff_profile = codec_profile;
+exact_match = 1;
 break;
 }
-}
-if (j < profile_count) {
-matched_va_profile = va_profile;
-matched_ff_profile = codec_profile;
-if (exact_match)
-break;
+} else {
+va_profile = vaapi_profile_map[i].va_profile;
+
+for (j = 0; j < profile_count; j++) {
+if (va_profile == profile_list[j]) {
+exact_match = profile_match;
+break;
+}
+}
+
+if (j < profile_count) {
+matched_va_profile = va_profile;
+matched_ff_profile = codec_profile;
+if (exact_match)
+break;
+}
 }
 }
 av_freep(&profile_list);
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 77f55ff8b1..bda9b5f589 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -590,63 +590,74 @@ static int ptl_convert(const PTLCommon *general_ptl, 
H265RawProfileTierLevel *h2
 }
 
 /*
- * Find exact va_profile for HEVC Range Extension and Screen Content Coding 
Extension
+ * Find compatible va_profile for HEVC Range Extension and Screen
+ * Content Coding Extension profiles.
  */
-VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
+VAProfile ff_vaapi_hevc_match_rext_scc_profile(AVCodecContext *avctx,
+   const VAProfile *profile_list,
+   int profile_count)
 {
 const HEVCContext *h = avctx->priv_data;
 const HEVCSPS *sps = h->ps.sps;
 const PTL *ptl = &sps->ptl;
 const PTLCommon *general_ptl = &ptl->general_ptl;
-const H265ProfileDescriptor *profile;
 H265RawProfileTierLevel h265_raw_ptl = {0};
 
+static const struct {
+int profile;
+VAProfile va_profile;
+} map[] = {
+#if VA_CHECK_VERSION(1, 2, 0)
+{ H265_PROFILE_MAIN_12,
+  VAProfileHEVCMain12 },
+{ H265_PROFILE_MAIN_422_10,
+  VAProfileHEVCMain422_10 },
+{ H265_PROFILE_MAIN_422_12,
+  VAProfileHEVCMain422_12 },
+{ H265_PROFILE_MAIN_444,
+  VAProfileHEVCMain444 },
+{ H265_PROFILE_MAIN_444_10,
+  VAProfileHEVCMain444_10 },

[FFmpeg-devel] [PATCH v2 2/3] lavc: Add test for H.265 profile handling

2024-05-06 Thread Mark Thompson
---
 libavcodec/Makefile  |   2 +-
 libavcodec/tests/.gitignore  |   1 +
 libavcodec/tests/h265_profiles.c | 440 +++
 tests/fate/libavcodec.mak|   5 +
 4 files changed, 447 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/tests/h265_profiles.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cff6347bdb..15e38ded28 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1307,7 +1307,7 @@ TESTPROGS-$(CONFIG_MJPEG_ENCODER) += 
mjpegenc_huffman
 TESTPROGS-$(HAVE_MMX) += motion
 TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
 TESTPROGS-$(CONFIG_H264_METADATA_BSF) += h264_levels
-TESTPROGS-$(CONFIG_HEVC_METADATA_BSF) += h265_levels
+TESTPROGS-$(CONFIG_HEVC_METADATA_BSF) += h265_levels h265_profiles
 TESTPROGS-$(CONFIG_RANGECODER)+= rangecoder
 TESTPROGS-$(CONFIG_SNOW_ENCODER)  += snowenc
 
diff --git a/libavcodec/tests/.gitignore b/libavcodec/tests/.gitignore
index 0df4ae10a0..bf29f03911 100644
--- a/libavcodec/tests/.gitignore
+++ b/libavcodec/tests/.gitignore
@@ -10,6 +10,7 @@
 /golomb
 /h264_levels
 /h265_levels
+/h265_profiles
 /htmlsubtitles
 /iirfilter
 /jpeg2000dwt
diff --git a/libavcodec/tests/h265_profiles.c b/libavcodec/tests/h265_profiles.c
new file mode 100644
index 00..6a0df58d0b
--- /dev/null
+++ b/libavcodec/tests/h265_profiles.c
@@ -0,0 +1,440 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/bprint.h"
+#include "libavutil/common.h"
+#include "libavcodec/h265_profile_level.h"
+
+
+enum {
+TYPE_MAIN,
+TYPE_SP,
+TYPE_REXT_INTER,
+TYPE_REXT_INTRA,
+TYPE_HT,
+TYPE_HT_INTRA,
+TYPE_SCC,
+TYPE_HT_SCC,
+TYPE_COUNT,
+};
+enum {
+DEPTH_8,
+DEPTH_10,
+DEPTH_12,
+DEPTH_14,
+DEPTH_16,
+DEPTH_COUNT,
+};
+enum {
+CHROMA_MONO,
+CHROMA_420,
+CHROMA_422,
+CHROMA_444,
+CHROMA_COUNT,
+};
+
+// Table of all profiles indexed by chroma subsampling, bit depth and
+// profile type.  This is currently only being used to verify that
+// profile properties are correct, but if there is some other need for
+// this lookup in lavc then the table should be moved to the common
+// profile-level code.  All profiles should appear exactly once in this
+// table (also verified by a test below).
+static int profile_table[CHROMA_COUNT][DEPTH_COUNT][TYPE_COUNT] = {
+[CHROMA_MONO] = {
+[DEPTH_8] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MONOCHROME,
+},
+[DEPTH_10] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MONOCHROME_10,
+},
+[DEPTH_12] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MONOCHROME_12,
+},
+[DEPTH_16] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MONOCHROME_16,
+},
+},
+[CHROMA_420] = {
+[DEPTH_8] = {
+[TYPE_MAIN]   = H265_PROFILE_MAIN,
+[TYPE_SP] = H265_PROFILE_MAIN_STILL_PICTURE,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_INTRA,
+[TYPE_SCC]= H265_PROFILE_SCREEN_EXTENDED_MAIN,
+},
+[DEPTH_10] = {
+[TYPE_MAIN]   = H265_PROFILE_MAIN_10,
+[TYPE_SP] = H265_PROFILE_MAIN_10_STILL_PICTURE,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_10_INTRA,
+[TYPE_SCC]= H265_PROFILE_SCREEN_EXTENDED_MAIN_10,
+},
+[DEPTH_12] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MAIN_12,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_12_INTRA,
+},
+},
+[CHROMA_422] ={
+[DEPTH_10] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MAIN_422_10,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_422_10_INTRA,
+},
+[DEPTH_12] = {
+[TYPE_REXT_INTER] = H265_PROFILE_MAIN_422_12,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_422_12_INTRA,
+},
+},
+[CHROMA_444] ={
+[DEPTH_8] = {
+[TYPE_SP] = H265_PROFILE_MAIN_444_STILL_PICTURE,
+[TYPE_REXT_INTER] = H265_PROFILE_MAIN_444,
+[TYPE_REXT_INTRA] = H265_PROFILE_MAIN_444_INTRA,
+[TYPE_HT] = H265_PROFILE_HIGH_THROUGHPUT_444,
+   

[FFmpeg-devel] [PATCH v2 1/3] lavc/h265_profile_level: Expand profile compatibility checking

2024-05-06 Thread Mark Thompson
Replace existing get_profile() with find_profile(), which finds the
lowest compatible profile rather than requiring an exact match.
---
Series changes since v1:
* Added H265_PROFILE_INVALID with value zero because it simplifies some code 
(and the values don't matter).
* Fixed the h265-levels test.
* Added a new h265-profiles test which tests the profile compatibility checking.
* Fixed missing VAAPI profiles.


 libavcodec/h265_profile_level.c | 78 +
 libavcodec/h265_profile_level.h | 71 +-
 libavcodec/tests/h265_levels.c  |  2 +-
 libavcodec/vaapi_hevc.c |  2 +-
 libavcodec/vdpau_hevc.c |  2 +-
 5 files changed, 123 insertions(+), 32 deletions(-)

diff --git a/libavcodec/h265_profile_level.c b/libavcodec/h265_profile_level.c
index 7ff9681f65..2e4a1c88bf 100644
--- a/libavcodec/h265_profile_level.c
+++ b/libavcodec/h265_profile_level.c
@@ -40,6 +40,7 @@ static const H265LevelDescriptor h265_levels[] = {
 };
 
 static const H265ProfileDescriptor h265_profiles[] = {
+{ "Invalid" },
 // profile_idc   8bit   one-picture
 //   HT-profile  | 422chroma| lower-bit-rate
 //   |  14bit|  | 420chroma |  | CpbVclFactor MinCrScaleFactor
@@ -119,41 +120,62 @@ static const H265ProfileDescriptor h265_profiles[] = {
   5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5, 6 },
 };
 
+_Static_assert(H265_PROFILE_COUNT == FF_ARRAY_ELEMS(h265_profiles),
+   "Incorrect H.265 profiles table.");
 
-const H265ProfileDescriptor *ff_h265_get_profile(const H265RawProfileTierLevel 
*ptl)
+
+const int ff_h265_profile_compatible(const H265RawProfileTierLevel *ptl,
+ int profile)
 {
-int i;
+const H265ProfileDescriptor *desc;
+
+av_assert0(profile > H265_PROFILE_INVALID &&
+   profile < H265_PROFILE_COUNT);
 
 if (ptl->general_profile_space)
-return NULL;
+return 0;
 
-for (i = 0; i < FF_ARRAY_ELEMS(h265_profiles); i++) {
-const H265ProfileDescriptor *profile = &h265_profiles[i];
+desc = &h265_profiles[profile];
 
-if (ptl->general_profile_idc &&
-ptl->general_profile_idc != profile->profile_idc)
-continue;
-if (!ptl->general_profile_compatibility_flag[profile->profile_idc])
-continue;
+if (ptl->general_profile_idc &&
+ptl->general_profile_idc != desc->profile_idc)
+return 0;
+if (!ptl->general_profile_compatibility_flag[desc->profile_idc])
+return 0;
 
-#define check_flag(name) \
-if (profile->name < 2) { \
-if (profile->name != ptl->general_ ## name ## _constraint_flag) \
-continue; \
-}
-check_flag(max_14bit);
-check_flag(max_12bit);
-check_flag(max_10bit);
-check_flag(max_8bit);
-check_flag(max_422chroma);
-check_flag(max_420chroma);
-check_flag(max_monochrome);
-check_flag(intra);
-check_flag(one_picture_only);
-check_flag(lower_bit_rate);
+#define check_flag(flag) \
+if (desc->flag < 2 && \
+desc->flag > ptl->general_ ## flag ## _constraint_flag) \
+return 0;
+check_flag(max_14bit);
+check_flag(max_12bit);
+check_flag(max_10bit);
+check_flag(max_8bit);
+check_flag(max_422chroma);
+check_flag(max_420chroma);
+check_flag(max_monochrome);
+check_flag(intra);
+check_flag(one_picture_only);
+check_flag(lower_bit_rate);
 #undef check_flag
 
-return profile;
+return 1;
+}
+
+
+const H265ProfileDescriptor *ff_h265_get_profile(int profile)
+{
+av_assert0(profile > H265_PROFILE_INVALID &&
+   profile < H265_PROFILE_COUNT);
+
+return &h265_profiles[profile];
+}
+
+const H265ProfileDescriptor *ff_h265_find_profile(const 
H265RawProfileTierLevel *ptl)
+{
+for (int p = 1; p < H265_PROFILE_COUNT; p++) {
+if (ff_h265_profile_compatible(ptl, p))
+return &h265_profiles[p];
 }
 
 return NULL;
@@ -171,12 +193,12 @@ const H265LevelDescriptor *ff_h265_guess_level(const 
H265RawProfileTierLevel *pt
 int i;
 
 if (ptl)
-profile = ff_h265_get_profile(ptl);
+profile = ff_h265_find_profile(ptl);
 else
 profile = NULL;
 if (!profile) {
 // Default to using multiplication factors for Main profile.
-profile = &h265_profiles[4];
+profile = &h265_profiles[H265_PROFILE_MAIN];
 }
 
 pic_size = width * height;
diff --git a/libavcodec/h265_profile_level.h b/libavcodec/h265_profile_level.h
index cd30ac5c50..e4e63dfef1 100644
--- a/libavcodec/h265_profile_level.h
+++ b/libavcodec/h265_profile_level.h
@@ -24,6 +24,50 @@
 #include "cbs_h265.h"
 
 
+// Enumeration of all H.265 profiles.
+// The list is ordered to match table A.10; numeric values are an index
+// into the latest version of this table and have no codec meaning.
+enum {
+H265_PROFILE_I

[FFmpeg-devel] [PATCH v4 5/5] hwcontext_vaapi: Deprecate quirks

2024-05-05 Thread Mark Thompson
These only apply to obsolete drivers which do not work with the
now-required libva 2.x.
---
 libavutil/hwcontext_vaapi.c | 123 ++--
 libavutil/hwcontext_vaapi.h |  15 +
 2 files changed, 50 insertions(+), 88 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index caff43d1ae..8591fb88ac 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -243,8 +243,7 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext 
*hwdev,
 unsigned int fourcc;
 int err, i, j, attr_count, pix_fmt_count;
 
-if (config &&
-!(hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES)) {
+if (config) {
 attr_count = 0;
 vas = vaQuerySurfaceAttributes(hwctx->display, config->config_id,
0, &attr_count);
@@ -367,23 +366,6 @@ fail:
 return err;
 }
 
-static const struct {
-const char *friendly_name;
-const char *match_string;
-unsigned int quirks;
-} vaapi_driver_quirks_table[] = {
-{
-"Intel iHD",
-"ubit",
-AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE,
-},
-{
-"VDPAU wrapper",
-"Splitted-Desktop Systems VDPAU backend for VA-API",
-AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
-},
-};
-
 static int vaapi_device_init(AVHWDeviceContext *hwdev)
 {
 VAAPIDeviceContext *ctx = hwdev->hwctx;
@@ -436,36 +418,6 @@ static int vaapi_device_init(AVHWDeviceContext *hwdev)
 if (vendor_string)
 av_log(hwdev, AV_LOG_VERBOSE, "VAAPI driver: %s.\n", vendor_string);
 
-if (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_USER_SET) {
-av_log(hwdev, AV_LOG_VERBOSE, "Using quirks set by user (%#x).\n",
-   hwctx->driver_quirks);
-} else {
-// Detect the driver in use and set quirk flags if necessary.
-hwctx->driver_quirks = 0;
-if (vendor_string) {
-for (i = 0; i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table); i++) {
-if (strstr(vendor_string,
-   vaapi_driver_quirks_table[i].match_string)) {
-av_log(hwdev, AV_LOG_VERBOSE, "Matched driver string "
-   "as known nonstandard driver \"%s\", setting "
-   "quirks (%#x).\n",
-   vaapi_driver_quirks_table[i].friendly_name,
-   vaapi_driver_quirks_table[i].quirks);
-hwctx->driver_quirks |=
-vaapi_driver_quirks_table[i].quirks;
-break;
-}
-}
-if (!(i < FF_ARRAY_ELEMS(vaapi_driver_quirks_table))) {
-av_log(hwdev, AV_LOG_VERBOSE, "Driver not found in known "
-   "nonstandard list, using standard behaviour.\n");
-}
-} else {
-av_log(hwdev, AV_LOG_VERBOSE, "Driver has no vendor string, "
-   "assuming standard behaviour.\n");
-}
-}
-
 av_free(image_list);
 return 0;
 fail:
@@ -562,48 +514,43 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc)
 }
 
 if (!hwfc->pool) {
-if (!(hwctx->driver_quirks & 
AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES)) {
-int need_memory_type = !(hwctx->driver_quirks & 
AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE);
-int need_pixel_format = 1;
-for (i = 0; i < avfc->nb_attributes; i++) {
-if (avfc->attributes[i].type == VASurfaceAttribMemoryType)
-need_memory_type  = 0;
-if (avfc->attributes[i].type == VASurfaceAttribPixelFormat)
-need_pixel_format = 0;
-}
-ctx->nb_attributes =
-avfc->nb_attributes + need_memory_type + need_pixel_format;
+int need_memory_type  = 1;
+int need_pixel_format = 1;
+for (i = 0; i < avfc->nb_attributes; i++) {
+if (avfc->attributes[i].type == VASurfaceAttribMemoryType)
+need_memory_type  = 0;
+if (avfc->attributes[i].type == VASurfaceAttribPixelFormat)
+need_pixel_format = 0;
+}
+ctx->nb_attributes =
+avfc->nb_attributes + need_memory_type + need_pixel_format;
 
-ctx->attributes = av_malloc(ctx->nb_attributes *
-sizeof(*ctx->attributes));
-if (!ctx->attributes) {
-err = AVERROR(ENOMEM);
-goto fail;
-}
+ctx->attributes = av_malloc(ctx->nb_attributes *
+sizeof(*ctx->attributes));
+if (!ctx->attributes) {
+err = AVERROR(ENOMEM);
+goto fail;
+}
 
-for (i = 0; i < avfc->nb_attributes; i++)
-ctx->attributes[i] = avfc->attributes[i];
-if (need_memory_type) {
-ctx->attributes[i++] = (VASurfaceAttr

[FFmpeg-devel] [PATCH v4 4/5] lavu: Remove libva 1.x support

2024-05-05 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
 libavutil/hwcontext_vaapi.c | 22 --
 1 file changed, 22 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 4cb25dd032..caff43d1ae 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -372,14 +372,6 @@ static const struct {
 const char *match_string;
 unsigned int quirks;
 } vaapi_driver_quirks_table[] = {
-#if !VA_CHECK_VERSION(1, 0, 0)
-// The i965 driver did not conform before version 2.0.
-{
-"Intel i965 (Quick Sync)",
-"i965",
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
-},
-#endif
 {
 "Intel iHD",
 "ubit",
@@ -1425,7 +1417,6 @@ fail:
 }
 #endif
 
-#if VA_CHECK_VERSION(0, 36, 0)
 typedef struct VAAPIDRMImageBufferMapping {
 VAImage  image;
 VABufferInfo buffer_info;
@@ -1585,7 +1576,6 @@ fail:
 av_freep(&mapping);
 return err;
 }
-#endif
 
 static int vaapi_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
 const AVFrame *src, int flags)
@@ -1596,10 +1586,7 @@ static int vaapi_map_to_drm(AVHWFramesContext *hwfc, 
AVFrame *dst,
 if (err != AVERROR(ENOSYS))
 return err;
 #endif
-#if VA_CHECK_VERSION(0, 36, 0)
 return vaapi_map_to_drm_abh(hwfc, dst, src, flags);
-#endif
-return AVERROR(ENOSYS);
 }
 
 #endif /* CONFIG_LIBDRM */
@@ -1649,7 +1636,6 @@ static void vaapi_device_free(AVHWDeviceContext *ctx)
 av_freep(&priv);
 }
 
-#if CONFIG_VAAPI_1
 static void vaapi_device_log_error(void *context, const char *message)
 {
 AVHWDeviceContext *ctx = context;
@@ -1663,7 +1649,6 @@ static void vaapi_device_log_info(void *context, const 
char *message)
 
 av_log(ctx, AV_LOG_VERBOSE, "libva: %s", message);
 }
-#endif
 
 static int vaapi_device_connect(AVHWDeviceContext *ctx,
 VADisplay display)
@@ -1672,10 +1657,8 @@ static int vaapi_device_connect(AVHWDeviceContext *ctx,
 int major, minor;
 VAStatus vas;
 
-#if CONFIG_VAAPI_1
 vaSetErrorCallback(display, &vaapi_device_log_error, ctx);
 vaSetInfoCallback (display, &vaapi_device_log_info,  ctx);
-#endif
 
 hwctx->display = display;
 
@@ -1919,7 +1902,6 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,
 
 ent = av_dict_get(opts, "driver", NULL, 0);
 if (ent) {
-#if VA_CHECK_VERSION(0, 38, 0)
 VAStatus vas;
 vas = vaSetDriverName(display, ent->value);
 if (vas != VA_STATUS_SUCCESS) {
@@ -1928,10 +1910,6 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,
 vaTerminate(display);
 return AVERROR_EXTERNAL;
 }
-#else
-av_log(ctx, AV_LOG_WARNING, "Driver name setting is not "
-   "supported with this VAAPI version.\n");
-#endif
 }
 
 return vaapi_device_connect(ctx, display);
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 3/5] lavc: Remove libva 1.x support

2024-05-05 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
 libavcodec/vaapi_decode.c  | 39 ++---
 libavcodec/vaapi_encode.c  | 78 ++
 libavcodec/vaapi_encode.h  |  9 
 libavcodec/vaapi_encode_h264.c | 18 
 libavcodec/vaapi_encode_h265.c |  2 -
 5 files changed, 15 insertions(+), 131 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 21b273cd0f..ef1ea27a08 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -191,16 +191,10 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture decode "
"issue: %d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-goto fail;
-else
-goto fail_at_end;
+goto fail;
 }
 
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-ff_vaapi_decode_destroy_buffers(avctx, pic);
+ff_vaapi_decode_destroy_buffers(avctx, pic);
 
 err = 0;
 goto exit;
@@ -213,7 +207,6 @@ fail_with_picture:
 }
 fail:
 ff_vaapi_decode_destroy_buffers(avctx, pic);
-fail_at_end:
 exit:
 pic->nb_param_buffers = 0;
 pic->nb_slices= 0;
@@ -406,12 +399,10 @@ static const struct {
H264ConstrainedBaseline),
 MAP(H264,H264_MAIN,   H264Main),
 MAP(H264,H264_HIGH,   H264High),
-#if VA_CHECK_VERSION(0, 37, 0)
 MAP(HEVC,HEVC_MAIN,   HEVCMain),
 MAP(HEVC,HEVC_MAIN_10,HEVCMain10  ),
 MAP(HEVC,HEVC_MAIN_STILL_PICTURE,
   HEVCMain),
-#endif
 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
 MAP(HEVC,HEVC_REXT,   None,
  ff_vaapi_parse_hevc_rext_scc_profile ),
@@ -429,14 +420,10 @@ static const struct {
 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
 MAP(VC1, VC1_ADVANCED,VC1Advanced ),
 MAP(VP8, UNKNOWN,   VP8Version0_3 ),
-#if VA_CHECK_VERSION(0, 38, 0)
 MAP(VP9, VP9_0,   VP9Profile0 ),
-#endif
-#if VA_CHECK_VERSION(0, 39, 0)
 MAP(VP9, VP9_1,   VP9Profile1 ),
 MAP(VP9, VP9_2,   VP9Profile2 ),
 MAP(VP9, VP9_3,   VP9Profile3 ),
-#endif
 #if VA_CHECK_VERSION(1, 8, 0)
 MAP(AV1, AV1_MAIN,AV1Profile0),
 MAP(AV1, AV1_HIGH,AV1Profile1),
@@ -599,27 +586,7 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 if (err < 0)
 goto fail;
 
-if (CONFIG_VAAPI_1)
-frames->initial_pool_size = 0;
-else {
-frames->initial_pool_size = 1;
-// Add per-codec number of surfaces used for storing reference 
frames.
-switch (avctx->codec_id) {
-case AV_CODEC_ID_H264:
-case AV_CODEC_ID_HEVC:
-case AV_CODEC_ID_AV1:
-frames->initial_pool_size += 16;
-break;
-case AV_CODEC_ID_VP9:
-frames->initial_pool_size += 8;
-break;
-case AV_CODEC_ID_VP8:
-frames->initial_pool_size += 3;
-break;
-default:
-frames->initial_pool_size += 2;
-}
-}
+frames->initial_pool_size = 0;
 }
 
 av_hwframe_constraints_free(&constraints);
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index f54b2579ec..6f062e8277 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -530,7 +530,6 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 }
 }
 
-#if VA_CHECK_VERSION(1, 0, 0)
 sd = av_frame_get_side_data(pic->input_image,
 AV_FRAME_DATA_REGIONS_OF_INTEREST);
 if (sd && ctx->roi_allowed) {
@@ -593,7 +592,6 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 if (err < 0)
 goto fail;
 }
-#endif
 
 vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context,
  pic->input_surface);
@@ -618,26 +616,17 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture encode issue: "
"%d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-// vaRenderPicture() has been called here, so we should not destroy
-// the parameter buffers unless separate destruction is required.
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-goto fail;
-else
-goto fail_at_end;
-}
-
-if (CONFIG_VAAPI_1 || ctx->h

[FFmpeg-devel] [PATCH v4 1/5] configure: Remove libva 1.x support

2024-05-05 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.  Various features no longer need any
configure check after this command, including all codecs except AV1.
Note that the libva version is the API version plus one, so this is
removing support for VAAPI 0.x and requiring VAAPI 1.x.
---
Changes to the series since v3:
* Reorder so that the series doesn't need to be squashed.
* New patch to remove the driver quirk support (deprecated in the public
  header, but will have no effect if set).

 configure | 25 ++---
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/configure b/configure
index ed74583a6f..69fde0bf35 100755
--- a/configure
+++ b/configure
@@ -2625,7 +2625,6 @@ CONFIG_EXTRA="
 texturedsp
 texturedspenc
 tpeldsp
-vaapi_1
 vaapi_encode
 vc1dsp
 videodsp
@@ -3189,7 +3188,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
 hevc_nvdec_hwaccel_select="hevc_decoder"
-hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
+hevc_vaapi_hwaccel_deps="vaapi"
 hevc_vaapi_hwaccel_select="hevc_decoder"
 hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
 hevc_vdpau_hwaccel_select="hevc_decoder"
@@ -3261,7 +3260,7 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
 vp9_nvdec_hwaccel_select="vp9_decoder"
-vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
+vp9_vaapi_hwaccel_deps="vaapi"
 vp9_vaapi_hwaccel_select="vp9_decoder"
 vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
 vp9_vdpau_hwaccel_select="vp9_decoder"
@@ -3354,7 +3353,6 @@ hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
 hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
 hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
-hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
 hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
 hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
@@ -3363,7 +3361,6 @@ mjpeg_cuvid_decoder_deps="cuvid"
 mjpeg_qsv_decoder_select="qsvdec"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
-mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
 mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
 mp3_mf_encoder_deps="mediafoundation"
 mpeg1_cuvid_decoder_deps="cuvid"
@@ -3392,7 +3389,6 @@ vp8_mediacodec_decoder_deps="mediacodec"
 vp8_mediacodec_encoder_deps="mediacodec"
 vp8_qsv_decoder_select="qsvdec"
 vp8_rkmpp_decoder_deps="rkmpp"
-vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
 vp8_vaapi_encoder_select="vaapi_encode"
 vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
@@ -3401,7 +3397,6 @@ vp9_mediacodec_decoder_deps="mediacodec"
 vp9_mediacodec_encoder_deps="mediacodec"
 vp9_qsv_decoder_select="qsvdec"
 vp9_rkmpp_decoder_deps="rkmpp"
-vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
 vp9_vaapi_encoder_select="vaapi_encode"
 vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
 vp9_qsv_encoder_select="qsvenc"
@@ -3952,9 +3947,9 @@ xfade_vulkan_filter_deps="vulkan spirv_compiler"
 yadif_cuda_filter_deps="ffnvcodec"
 yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
 yadif_videotoolbox_filter_deps="metal corevideo videotoolbox"
-hstack_vaapi_filter_deps="vaapi_1"
-vstack_vaapi_filter_deps="vaapi_1"
-xstack_vaapi_filter_deps="vaapi_1"
+hstack_vaapi_filter_deps="vaapi"
+vstack_vaapi_filter_deps="vaapi"
+xstack_vaapi_filter_deps="vaapi"
 hstack_qsv_filter_deps="libmfx"
 hstack_qsv_filter_select="qsvvpp"
 vstack_qsv_filter_deps="libmfx"
@@ -7252,7 +7247,7 @@ enabled libdrm &&
 check_pkg_config libdrm_getfb2 libdrm "xf86drmMode.h" drmModeGetFB2
 
 enabled vaapi &&
-check_pkg_config vaapi "libva >= 0.35.0" "va/va.h" vaInitialize
+check_pkg_config vaapi "libva >= 1.0.0" "va/va.h" vaInitialize
 
 if enabled vaapi; then
 case $target_os in
@@ -7268,18 +7263,10 @@ if enabled vaapi; then
 check_pkg_config vaapi_x11 "libva-x11" "va/va_x11.h" vaGetDisplay
 fi
 
-check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
-
-check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
-check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
 check_struct "va/va.h" "VADecPictureParameterBufferAV1" bit_depth_idx
 check_type   "va/va.h va/va_vpp.h" 
"VAProcFilterParameterBufferHDRToneMapping"
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" rotation_flags
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" blend_flags
-check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
-check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
-check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
-check_type "va/va.h va/va_enc_vp9.

[FFmpeg-devel] [PATCH v4 2/5] lavfi: Remove libva 1.x support

2024-05-05 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
 libavfilter/vaapi_vpp.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index 9ef7a289fb..fe14170fee 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -204,12 +204,9 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 output_frames->width = ctx->output_width;
 output_frames->height= ctx->output_height;
 
-if (CONFIG_VAAPI_1)
-output_frames->initial_pool_size = 0;
-else
-output_frames->initial_pool_size = 4;
+output_frames->initial_pool_size = 0;
 
-err = ff_filter_init_hw_frames(avctx, outlink, 10);
+err = ff_filter_init_hw_frames(avctx, outlink, 0);
 if (err < 0)
 goto fail;
 
@@ -677,15 +674,12 @@ int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx,
 goto fail_after_render;
 }
 
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
-for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) {
-vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: "
-   "%d (%s).\n", vas, vaErrorStr(vas));
-// And ignore.
-}
+for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) {
+vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+// And ignore.
 }
 }
 
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 01/10, v2] avutil: add hwcontext_amf.

2024-05-02 Thread Mark Thompson
On 01/05/2024 19:38, Dmitrii Ovchinnikov wrote:
> Adds hwcontext_amf, which allows to use shared AMF
> context for the encoder, decoder and AMF-based filters,
> without copy to the host memory.
> It will also allow you to use some optimizations in
> the interaction of components (for example, SAV) and make a more
> manageable and optimal setup for using GPU devices with AMF
> in the case of a fully AMF pipeline.
> It will be a significant performance uplift when full AMF pipeline
> with filters is used.
> 
> We also plan to add Compression artefact removal filter in near feature.
> v2: cleanup header files, fixed naming and formats
> ---
>  libavutil/Makefile |   4 +
>  libavutil/hwcontext.c  |   4 +
>  libavutil/hwcontext.h  |   1 +
>  libavutil/hwcontext_amf.c  | 588 +
>  libavutil/hwcontext_amf.h  |  41 ++
>  libavutil/hwcontext_amf_internal.h |  77 
>  libavutil/hwcontext_internal.h |   1 +
>  libavutil/pixdesc.c|   4 +
>  libavutil/pixfmt.h |   5 +
>  9 files changed, 725 insertions(+)
>  create mode 100644 libavutil/hwcontext_amf.c
>  create mode 100644 libavutil/hwcontext_amf.h
>  create mode 100644 libavutil/hwcontext_amf_internal.h
> 
> ... 
> diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c
> new file mode 100644
> index 00..8edfb20fbb
> --- /dev/null
> +++ b/libavutil/hwcontext_amf.c
> ...
> +
> +static void amf_dummy_free(void *opaque, uint8_t *data)
> +{
> +
> +}
> +
> +static AVBufferRef *amf_pool_alloc(void *opaque, size_t size)
> +{
> +AVHWFramesContext *hwfc = (AVHWFramesContext *)opaque;
> +AVBufferRef *buf;
> +
> +buf = av_buffer_create(NULL, NULL, amf_dummy_free, hwfc, 
> AV_BUFFER_FLAG_READONLY);
> +if (!buf) {
> +av_log(hwfc, AV_LOG_ERROR, "Failed to create buffer for AMF 
> context.\n");
> +return NULL;
> +}
> +return buf;
> +}

This seems to have forgotten to actually allocate anything?  It will always 
assign NULL to frame->data[0] below.

> +
> +static int amf_frames_init(AVHWFramesContext *ctx)
> +{
> +int i;
> +
> +for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
> +if (ctx->sw_format == supported_formats[i])
> +break;
> +}
> +if (i == FF_ARRAY_ELEMS(supported_formats)) {
> +av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported\n",
> +   av_get_pix_fmt_name(ctx->sw_format));
> +return AVERROR(ENOSYS);
> +}
> +
> +ffhwframesctx(ctx)->pool_internal =
> +av_buffer_pool_init2(sizeof(AMFSurface), ctx,
> + amf_pool_alloc, NULL);
> +
> +
> +return 0;
> +}
> +
> +static int amf_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
> +{
> +frame->buf[0] = av_buffer_pool_get(ctx->pool);
> +if (!frame->buf[0])
> +return AVERROR(ENOMEM);
> +
> +frame->data[0] = frame->buf[0]->data;
> +frame->format  = AV_PIX_FMT_AMF_SURFACE;
> +frame->width   = ctx->width;
> +frame->height  = ctx->height;
> +return 0;
> +}
> +
> ...
> +
> +static int amf_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
> + const AVFrame *src)
> +{
> +AMFSurface* surface = (AMFSurface*)dst->data[0];
> +AMFPlane *plane;
> +uint8_t  *dst_data[4];
> +int   dst_linesize[4];
> +int   planes;
> +int   i;
> +int w = FFMIN(dst->width,  src->width);
> +int h = FFMIN(dst->height, src->height);
> +
> +planes = (int)surface->pVtbl->GetPlanesCount(surface);
> +av_assert0(planes < FF_ARRAY_ELEMS(dst_data));
> +
> +for (i = 0; i < planes; i++) {
> +plane = surface->pVtbl->GetPlaneAt(surface, i);
> +dst_data[i] = plane->pVtbl->GetNative(plane);
> +dst_linesize[i] = plane->pVtbl->GetHPitch(plane);
> +}
> +av_image_copy(dst_data, dst_linesize,
> +(const uint8_t**)src->data, src->linesize, src->format,
> +w, h);
> +
> +return 0;
> +}
> +static int amf_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
> +const AVFrame *src)
> +{
> +AMFSurface* surface = (AMFSurface*)src->data[0];
> +AMFPlane *plane;
> +uint8_t  *src_data[4];
> +int   src_linesize[4];
> +int   planes;
> +int   i;
> +int w = FFMIN(dst->width,  src->width);
> +int h = FFMIN(dst->height, src->height);
> +int ret;
> +
> +ret = surface->pVtbl->Convert(surface, AMF_MEMORY_HOST);
> +AMF_RETURN_IF_FALSE(ctx, ret == AMF_OK, AVERROR_UNKNOWN, 
> "Convert(amf::AMF_MEMORY_HOST) failed with error %d\n", AVERROR_UNKNOWN);
> +
> +planes = (int)surface->pVtbl->GetPlanesCount(surface);
> +av_assert0(planes < FF_ARRAY_ELEMS(src_data));
> +
> +for (i = 0; i < planes; i++) {
> +plane = surface->pVtbl->GetPlaneAt(surface, i);
> +src_data[i] = plane->pVtbl->GetNative(plane);
> +sr

Re: [FFmpeg-devel] [PATCH 02/10, v2] avcodec: add amfdec.

2024-05-02 Thread Mark Thompson
On 01/05/2024 19:38, Dmitrii Ovchinnikov wrote:
> From: Evgeny Pavlov 
> 
> Added AMF based h264, hevc, av1 decoders.
> Co-authored-by: Dmitrii Ovchinnikov 
> v2: added encoder reinitialisation
> ---
>  libavcodec/Makefile|   7 +-
>  libavcodec/allcodecs.c |   3 +
>  libavcodec/amfdec.c| 719 +
>  libavcodec/amfdec.h|  72 +
>  4 files changed, 799 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/amfdec.c
>  create mode 100644 libavcodec/amfdec.h
> 
> ...
> +
> +static int amf_decode_init(AVCodecContext *avctx)
> +{
> +AvAmfDecoderContext *ctx = avctx->priv_data;
> +int ret;
> +enum AVPixelFormat pix_fmts[3] = {
> +AV_PIX_FMT_AMF_SURFACE,
> +avctx->pix_fmt,
> +AV_PIX_FMT_NONE };
> +
> +ret = ff_get_format(avctx, pix_fmts);
> ...
> +const FFCodec ff_##x##_amf_decoder = { \
> ...
> +.init   = amf_decode_init, \
> ...

This is still fundamentally incorrect.

See my reply to the previous posting of this patch: 
.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/9] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pool

2024-05-02 Thread Mark Thompson
On 28/04/2024 08:39, Xiang, Haihao wrote:
> From: Haihao Xiang 
> 
> Add AVQSVFramesContext.info and update the description.
> 
> Signed-off-by: Haihao Xiang 
> ---
>  doc/APIchanges|  3 +++
>  libavutil/hwcontext_qsv.c |  4 ++--
>  libavutil/hwcontext_qsv.h | 28 +---
>  libavutil/version.h   |  4 ++--
>  4 files changed, 32 insertions(+), 7 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 0566fcdcc5..4a434b2877 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
>  
>  API changes, most recent first:
>  
> +2024-04-xx - xx - lavu 59.17.100 - hwcontext_qsv.h
> +  Add AVQSVFramesContext.info
> +
>  2024-04-24 - 8616cfe0890 - lavu 59.16.100 - opt.h
>Add AV_OPT_SERIALIZE_SEARCH_CHILDREN.
>  
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index c7c7878644..f552811346 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -627,7 +627,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, 
> mfxFrameAllocRequest *req,
>  QSVFramesContext   *s = ctx->hwctx;
>  AVQSVFramesContext *hwctx = &s->p;
>  mfxFrameInfo *i  = &req->Info;
> -mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
> +mfxFrameInfo *i1 = hwctx->nb_surfaces ? &hwctx->surfaces[0].Info : 
> hwctx->info;
>  
>  if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
>  !(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
> @@ -1207,7 +1207,7 @@ static int qsv_init_internal_session(AVHWFramesContext 
> *ctx,
>MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
>  par.AsyncDepth = 1;
>  
> -par.vpp.In = frames_hwctx->surfaces[0].Info;
> +par.vpp.In = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info 
> : *frames_hwctx->info;
>  
>  /* Apparently VPP requires the frame rate to be set to some value, 
> otherwise
>   * init will fail (probably for the framerate conversion filter). Since 
> we
> diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
> index e2dba8ad83..9e43a237d4 100644
> --- a/libavutil/hwcontext_qsv.h
> +++ b/libavutil/hwcontext_qsv.h
> @@ -25,8 +25,8 @@
>   * @file
>   * An API-specific header for AV_HWDEVICE_TYPE_QSV.
>   *
> - * This API does not support dynamic frame pools. AVHWFramesContext.pool must
> - * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 
> struct.
> + * AVHWFramesContext.pool must contain AVBufferRefs whose data pointer points
> + * to a mfxFrameSurface1 struct.
>   */
>  
>  /**
> @@ -51,7 +51,29 @@ typedef struct AVQSVDeviceContext {
>   * This struct is allocated as AVHWFramesContext.hwctx
>   */
>  typedef struct AVQSVFramesContext {
> -mfxFrameSurface1 *surfaces;
> +/**
> + * A pointer to a mfxFrameSurface1 or mfxFrameInfo struct
> + *
> + * When nb_surfaces is non-zero, it is a pointer to a mfxFrameSurface1
> + * struct.
> + *
> + * When nb_surfaces is 0, it is a pointer to a mfxFrameInfo struct, all
> + * buffers allocated from the pool have the same mfxFrameInfo.
> + */
> +union {
> +mfxFrameSurface1 *surfaces;
> +mfxFrameInfo *info;
> +};

doc/developer.texi:

"FFmpeg is mainly programmed in the ISO C11 language, except for the public
headers which must stay C99 compatible."

Anonymous unions are therefore not allowed in public headers.

Can you explain what you need the info field for, though?  (What is needed but 
can't be inferred elsewhere?  VAAPI in particular is can be mapped here but 
doesn't contain any special information like this.)

> +
> +/**
> + * Number of frames in the pool
> + *
> + * It is 0 for dynamic frame pools or AVHWFramesContext.initial_pool_size
> + * for fixed frame pools.
> + *
> + * Note only oneVPL GPU runtime 2.9+ can support dynamic frame pools
> + * on d3d11va or vaapi
> + */
>  intnb_surfaces;

+1 to adding proper documentation for these fields.

>  
>  /**
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 735f6832e3..3b5a2e7aaa 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,8 +79,8 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  59
> -#define LIBAVUTIL_VERSION_MINOR  16
> -#define LIBAVUTIL_VERSION_MICRO 101
> +#define LIBAVUTIL_VERSION_MINOR  17
> +#define LIBAVUTIL_VERSION_MICRO 100
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> LIBAVUTIL_VERSION_MINOR, \

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/4] lavu: Remove libva 1.x support

2024-04-28 Thread Mark Thompson
On 24/04/2024 15:06, Xiang, Haihao wrote:
> On Ma, 2024-04-22 at 22:41 +0100, Mark Thompson wrote:
>> libva 2.0 was released in 2017 and the 2.x versions are included in all
>> supported distributions nowadays.
>> ---
>> Rebased.
>>
>> I think we can also drop the other quirks?  They are for the proprietary 
>> media
>> SDK driver (which I think is dead?) and the VDPAU wrapper (which I don't 
>> think
>> was ever updated for libva 2?).
> 
> Agree, please drop these quirks in a new patch. 

Sure.

> BTW I think we should require VA-API 1.x firstly, otherwise if someone has VA-
> API 0.x, he/she will get errors when building this commit. 

I was intending to squash but had them split for review, though as you say they 
can stay split with more careful ordering - I will do this.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] lavc/vaapi_hevc: Don't require exact profiles

2024-04-28 Thread Mark Thompson
On 24/04/2024 14:45, Xiang, Haihao wrote:
> On Ma, 2024-04-22 at 22:23 +0100, Mark Thompson wrote:
>> Rather than turning the constraint flags into a single profile and then
>> searching for that profile (and failing if it doesn't match any profile
>> exactly), instead search all supported profiles and use the first one
>> which supports the given set of constraint flags.
>> ---
>> This fixes decode of rext 8-bit 4:2:0; it will correctly pick Main 12 or Main
>> 4:2:2 10 or Main 4:4:4 (first one available) to use as the decoding profile
>> after this patch.
> 
> sw decoding and vaapi decoding might have different bits (There is the same
> issue if applying Fei's patchset).  
> 
> For example:
> $ ffmpeg -hwaccel vaapi -f lavfi -i testsrc -vf 'format=nv12,hwupload' -c:v
> hevc_vaapi -profile:v rext -vframes 30 -y out.mp4
> 
> 8bit ouput if using sw decoding:
> $ ffmpeg -i out.mp4 -f null - 
> [...]
> Stream #0:0(und): Video: wrapped_avframe, yuv420p(tv, progressive), 320x240 
> [SAR
> 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)
> 
> 12bit output if using vaapi decoding:
> $ ffmpeg -hwaccel vaapi -i out.mp4 -f null -
> [...]
>  Stream #0:0(und): Video: wrapped_avframe, p012le(tv, progressive), 320x240 
> [SAR
> 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn (default)

That comes from what the driver reports support for, though?

E.g. with the Intel iHD driver, I have

{
"profile": 23,
"name": "HEVCMain12",
...
"surface_formats": [
{
"rt_format": "YUV420",
"max_width": 16384,
"max_height": 16384,
"memory_types": [
"VA",
"DRM_PRIME_2",
],
"pixel_formats": [
"P012",
"P016",
],
},

So to decode a 4:2:0 8-bit input it is asking for a P012 or P016 surface.

If the driver reported that a Main 12 profile 4:2:0 8-bit input could be 
decoded to an NV12 surface then it would be picked by the logic in 
vaapi_decode_find_best_format(), since it would be a better match than the 
higher-depth formats.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 6/6] vulkan_av1: Fix force_integer_mv value

2024-04-27 Thread Mark Thompson
---
 libavcodec/vulkan_av1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index 25ab4ecc70..a550215e32 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -435,7 +435,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,
 .render_and_frame_size_different = 
frame_header->render_and_frame_size_different,
 .allow_screen_content_tools = 
frame_header->allow_screen_content_tools,
 .is_filter_switchable = frame_header->is_filter_switchable,
-.force_integer_mv = frame_header->force_integer_mv,
+.force_integer_mv = pic->force_integer_mv,
 .frame_size_override_flag = frame_header->frame_size_override_flag,
 .buffer_removal_time_present_flag = 
frame_header->buffer_removal_time_present_flag,
 .allow_intrabc = frame_header->allow_intrabc,
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 5/6] vaapi_av1: Fix force_integer_mv value

2024-04-27 Thread Mark Thompson
---
 libavcodec/vaapi_av1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index 1f563483b9..f61bf63098 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -220,7 +220,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
 .error_resilient_mode = frame_header->error_resilient_mode,
 .disable_cdf_update   = frame_header->disable_cdf_update,
 .allow_screen_content_tools   = 
frame_header->allow_screen_content_tools,
-.force_integer_mv = frame_header->force_integer_mv,
+.force_integer_mv = s->cur_frame.force_integer_mv,
 .allow_intrabc= frame_header->allow_intrabc,
 .use_superres = frame_header->use_superres,
 .allow_high_precision_mv  = 
frame_header->allow_high_precision_mv,
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/6] nvdec_av1: Use av1dec force_integer_mv value

2024-04-27 Thread Mark Thompson
---
 libavcodec/nvdec_av1.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c
index 4efa420e66..8a46db1ed5 100644
--- a/libavcodec/nvdec_av1.c
+++ b/libavcodec/nvdec_av1.c
@@ -106,9 +106,7 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx, 
const uint8_t *buffer, u
 .show_frame   = frame_header->show_frame,
 .disable_cdf_update   = frame_header->disable_cdf_update,
 .allow_screen_content_tools   = 
frame_header->allow_screen_content_tools,
-.force_integer_mv = frame_header->force_integer_mv ||
-frame_header->frame_type == 
AV1_FRAME_INTRA_ONLY ||
-frame_header->frame_type == 
AV1_FRAME_KEY,
+.force_integer_mv = s->cur_frame.force_integer_mv;
 .coded_denom  = frame_header->coded_denom,
 .allow_intrabc= frame_header->allow_intrabc,
 .allow_high_precision_mv  = 
frame_header->allow_high_precision_mv,
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/6] vdpau_av1: Use av1dec force_integer_mv value

2024-04-27 Thread Mark Thompson
---
 libavcodec/vdpau_av1.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/vdpau_av1.c b/libavcodec/vdpau_av1.c
index b74ea6aa0c..a1aff79bb7 100644
--- a/libavcodec/vdpau_av1.c
+++ b/libavcodec/vdpau_av1.c
@@ -91,9 +91,7 @@ static int vdpau_av1_start_frame(AVCodecContext *avctx,
 info->show_frame   = frame_header->show_frame;
 info->disable_cdf_update   = frame_header->disable_cdf_update;
 info->allow_screen_content_tools   = 
frame_header->allow_screen_content_tools;
-info->force_integer_mv = frame_header->force_integer_mv ||
-frame_header->frame_type == 
AV1_FRAME_INTRA_ONLY ||
-frame_header->frame_type == AV1_FRAME_KEY;
+info->force_integer_mv = s->cur_frame.force_integer_mv;
 info->coded_denom  = frame_header->coded_denom;
 info->allow_intrabc= frame_header->allow_intrabc;
 info->allow_high_precision_mv  = frame_header->allow_high_precision_mv;
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/6] dxva2_av1: Use av1dec force_integer_mv value

2024-04-27 Thread Mark Thompson
---
 libavcodec/dxva2_av1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxva2_av1.c b/libavcodec/dxva2_av1.c
index 5b95f99c9b..1b55510659 100644
--- a/libavcodec/dxva2_av1.c
+++ b/libavcodec/dxva2_av1.c
@@ -101,7 +101,7 @@ int ff_dxva2_av1_fill_picture_parameters(const 
AVCodecContext *avctx, AVDXVACont
 pp->coding.dual_filter  = seq->enable_dual_filter;
 pp->coding.jnt_comp = seq->enable_jnt_comp;
 pp->coding.screen_content_tools = 
frame_header->allow_screen_content_tools;
-pp->coding.integer_mv   = frame_header->force_integer_mv 
|| !(frame_header->frame_type & 1);
+pp->coding.integer_mv   = h->cur_frame.force_integer_mv;
 pp->coding.cdef = seq->enable_cdef;
 pp->coding.restoration  = seq->enable_restoration;
 pp->coding.film_grain   = seq->film_grain_params_present 
&& !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN);
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/6] av1dec: Add force_integer_mv derived field for decoder use

2024-04-27 Thread Mark Thompson
This is not the same as the syntax element value in the frame header
because the specification parsing tables override the value on intra
frames.
---
On 27/04/2024 15:58, Lynne wrote:
> This looks better to me.

HYG.

Of these, only VAAPI tested.  (And probably it never did anything anyway.)

 libavcodec/av1dec.c | 7 +++
 libavcodec/av1dec.h | 6 ++
 2 files changed, 13 insertions(+)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 79a30a114d..601e3f05e1 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -725,6 +725,8 @@ static void av1_frame_replace(AV1Frame *dst, const AV1Frame 
*src)
sizeof(dst->ref_frame_sign_bias));
 memcpy(dst->order_hints, src->order_hints,
sizeof(dst->order_hints));
+
+dst->force_integer_mv = src->force_integer_mv;
 }
 
 static av_cold int av1_decode_free(AVCodecContext *avctx)
@@ -1255,6 +1257,11 @@ static int get_current_frame(AVCodecContext *avctx)
 order_hint_info(s);
 load_grain_params(s);
 
+s->cur_frame.force_integer_mv =
+s->raw_frame_header->force_integer_mv ||
+s->raw_frame_header->frame_type == AV1_FRAME_KEY ||
+s->raw_frame_header->frame_type == AV1_FRAME_INTRA_ONLY;
+
 return ret;
 }
 
diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h
index 66a732d781..8b2a7b0896 100644
--- a/libavcodec/av1dec.h
+++ b/libavcodec/av1dec.h
@@ -67,6 +67,12 @@ typedef struct AV1Frame {
 // OrderHints[] when this is the current frame, otherwise
 // SavedOrderHints[s][] when is the reference frame in slot s.
 uint8_t order_hints[AV1_TOTAL_REFS_PER_FRAME];
+
+// force_integer_mv value at the end of the frame header parsing.
+// This is not the same as the syntax element value in
+// raw_frame_header because the specification parsing tables
+// override the value on intra frames.
+uint8_t force_integer_mv;
 } AV1Frame;
 
 typedef struct TileGroupInfo {
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] vulkan_av1: Set force_integer_mv on intra frames

2024-04-27 Thread Mark Thompson
On 27/04/2024 14:58, Mark Thompson wrote:
> On 27/04/2024 14:47, Ronald S. Bultje wrote:
>> Hi,
>>
>> On Sat, Apr 27, 2024 at 9:40 AM Mark Thompson  wrote:
>>
>>> The flag in CBS is the value read from the bitstream (as required for
>>> passthrough), but the specification overrides that by setting it
>>> immediately after reading if the frame is intra.
>>> ---
>>> This is already done for DXVA and VDPAU.  Also wondering whether this
>>> should be done for VAAPI?
>>>
>>>  libavcodec/vulkan_av1.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
>>> index 25ab4ecc70..694e643954 100644
>>> --- a/libavcodec/vulkan_av1.c
>>> +++ b/libavcodec/vulkan_av1.c
>>> @@ -435,7 +435,7 @@ static int vk_av1_start_frame(AVCodecContext
>>> *avctx,
>>>  .render_and_frame_size_different =
>>> frame_header->render_and_frame_size_different,
>>>  .allow_screen_content_tools =
>>> frame_header->allow_screen_content_tools,
>>>  .is_filter_switchable = frame_header->is_filter_switchable,
>>> -.force_integer_mv = frame_header->force_integer_mv,
>>> +.force_integer_mv = frame_header->force_integer_mv ||
>>> !(frame_header->frame_type & 1),
>>>  .frame_size_override_flag =
>>> frame_header->frame_size_override_flag,
>>>  .buffer_removal_time_present_flag =
>>> frame_header->buffer_removal_time_present_flag,
>>>  .allow_intrabc = frame_header->allow_intrabc,
>>> --
>>> 2.43.0
>>>
>>
>> Wouldn't it be better to adjust the CBS reader then? Prevents us from
>> having to re-do this in every hw wrapper.
> 
> How would you suggest doing this?
> 
> We could add a derived field force_integer_mv somewhere else (av1dec?) but 
> that doesn't seem obviously better for use in the "copy stuff from frame 
> header" function.

Something like this.  Unsure whether this is more or less confusing!

 libavcodec/av1dec.c | 7 +++
 libavcodec/av1dec.h | 3 +++
 libavcodec/vulkan_av1.c | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 79a30a114d..601e3f05e1 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -725,6 +725,8 @@ static void av1_frame_replace(AV1Frame *dst, const AV1Frame 
*src)
sizeof(dst->ref_frame_sign_bias));
 memcpy(dst->order_hints, src->order_hints,
sizeof(dst->order_hints));
+
+dst->force_integer_mv = src->force_integer_mv;
 }

 static av_cold int av1_decode_free(AVCodecContext *avctx)
@@ -1255,6 +1257,11 @@ static int get_current_frame(AVCodecContext *avctx)
 order_hint_info(s);
 load_grain_params(s);

+s->cur_frame.force_integer_mv =
+s->raw_frame_header->force_integer_mv ||
+s->raw_frame_header->frame_type == AV1_FRAME_KEY ||
+s->raw_frame_header->frame_type == AV1_FRAME_INTRA_ONLY;
+
 return ret;
 }

diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h
index 66a732d781..e3016b82a3 100644
--- a/libavcodec/av1dec.h
+++ b/libavcodec/av1dec.h
@@ -67,6 +67,9 @@ typedef struct AV1Frame {
 // OrderHints[] when this is the current frame, otherwise
 // SavedOrderHints[s][] when is the reference frame in slot s.
 uint8_t order_hints[AV1_TOTAL_REFS_PER_FRAME];
+
+// force_integer_mv value at the end of the frame header parsing.
+uint8_t force_integer_mv;
 } AV1Frame;

 typedef struct TileGroupInfo {
diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index 25ab4ecc70..a550215e32 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -435,7 +435,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,
 .render_and_frame_size_different = 
frame_header->render_and_frame_size_different,
 .allow_screen_content_tools = 
frame_header->allow_screen_content_tools,
 .is_filter_switchable = frame_header->is_filter_switchable,
-.force_integer_mv = frame_header->force_integer_mv,
+.force_integer_mv = pic->force_integer_mv,
 .frame_size_override_flag = frame_header->frame_size_override_flag,
 .buffer_removal_time_present_flag = 
frame_header->buffer_removal_time_present_flag,
 .allow_intrabc = frame_header->allow_intrabc,
-- 
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] vulkan_av1: Set force_integer_mv on intra frames

2024-04-27 Thread Mark Thompson
On 27/04/2024 14:47, Ronald S. Bultje wrote:
> Hi,
> 
> On Sat, Apr 27, 2024 at 9:40 AM Mark Thompson  wrote:
> 
>> The flag in CBS is the value read from the bitstream (as required for
>> passthrough), but the specification overrides that by setting it
>> immediately after reading if the frame is intra.
>> ---
>> This is already done for DXVA and VDPAU.  Also wondering whether this
>> should be done for VAAPI?
>>
>>  libavcodec/vulkan_av1.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
>> index 25ab4ecc70..694e643954 100644
>> --- a/libavcodec/vulkan_av1.c
>> +++ b/libavcodec/vulkan_av1.c
>> @@ -435,7 +435,7 @@ static int vk_av1_start_frame(AVCodecContext
>> *avctx,
>>  .render_and_frame_size_different =
>> frame_header->render_and_frame_size_different,
>>  .allow_screen_content_tools =
>> frame_header->allow_screen_content_tools,
>>  .is_filter_switchable = frame_header->is_filter_switchable,
>> -.force_integer_mv = frame_header->force_integer_mv,
>> +.force_integer_mv = frame_header->force_integer_mv ||
>> !(frame_header->frame_type & 1),
>>  .frame_size_override_flag =
>> frame_header->frame_size_override_flag,
>>  .buffer_removal_time_present_flag =
>> frame_header->buffer_removal_time_present_flag,
>>  .allow_intrabc = frame_header->allow_intrabc,
>> --
>> 2.43.0
>>
> 
> Wouldn't it be better to adjust the CBS reader then? Prevents us from
> having to re-do this in every hw wrapper.

How would you suggest doing this?

We could add a derived field force_integer_mv somewhere else (av1dec?) but that 
doesn't seem obviously better for use in the "copy stuff from frame header" 
function.

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] vulkan_av1: Set force_integer_mv on intra frames

2024-04-27 Thread Mark Thompson
The flag in CBS is the value read from the bitstream (as required for
passthrough), but the specification overrides that by setting it
immediately after reading if the frame is intra.
---
This is already done for DXVA and VDPAU.  Also wondering whether this should be 
done for VAAPI?

 libavcodec/vulkan_av1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index 25ab4ecc70..694e643954 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -435,7 +435,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,
 .render_and_frame_size_different = 
frame_header->render_and_frame_size_different,
 .allow_screen_content_tools = 
frame_header->allow_screen_content_tools,
 .is_filter_switchable = frame_header->is_filter_switchable,
-.force_integer_mv = frame_header->force_integer_mv,
+.force_integer_mv = frame_header->force_integer_mv || 
!(frame_header->frame_type & 1),
 .frame_size_override_flag = frame_header->frame_size_override_flag,
 .buffer_removal_time_present_flag = 
frame_header->buffer_removal_time_present_flag,
 .allow_intrabc = frame_header->allow_intrabc,
-- 
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 4/4] configure: Remove libva 1.x support

2024-04-22 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.  Various features no longer need any
configure check after this command, including all codecs except AV1.
Note that the libva version is the API version plus one, so this is
removing support for VAAPI 0.x and requiring VAAPI 1.x.
---
 configure | 25 ++---
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/configure b/configure
index 02711bf930..e3361a1a73 100755
--- a/configure
+++ b/configure
@@ -2625,7 +2625,6 @@ CONFIG_EXTRA="
 texturedsp
 texturedspenc
 tpeldsp
-vaapi_1
 vaapi_encode
 vc1dsp
 videodsp
@@ -3189,7 +3188,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
 hevc_nvdec_hwaccel_select="hevc_decoder"
-hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
+hevc_vaapi_hwaccel_deps="vaapi"
 hevc_vaapi_hwaccel_select="hevc_decoder"
 hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
 hevc_vdpau_hwaccel_select="hevc_decoder"
@@ -3261,7 +3260,7 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
 vp9_nvdec_hwaccel_select="vp9_decoder"
-vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
+vp9_vaapi_hwaccel_deps="vaapi"
 vp9_vaapi_hwaccel_select="vp9_decoder"
 vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
 vp9_vdpau_hwaccel_select="vp9_decoder"
@@ -3353,7 +3352,6 @@ hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
 hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
 hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
-hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
 hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
 hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
@@ -3362,7 +3360,6 @@ mjpeg_cuvid_decoder_deps="cuvid"
 mjpeg_qsv_decoder_select="qsvdec"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
-mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
 mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
 mp3_mf_encoder_deps="mediafoundation"
 mpeg1_cuvid_decoder_deps="cuvid"
@@ -3390,7 +3387,6 @@ vp8_mediacodec_decoder_deps="mediacodec"
 vp8_mediacodec_encoder_deps="mediacodec"
 vp8_qsv_decoder_select="qsvdec"
 vp8_rkmpp_decoder_deps="rkmpp"
-vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
 vp8_vaapi_encoder_select="vaapi_encode"
 vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
@@ -3399,7 +3395,6 @@ vp9_mediacodec_decoder_deps="mediacodec"
 vp9_mediacodec_encoder_deps="mediacodec"
 vp9_qsv_decoder_select="qsvdec"
 vp9_rkmpp_decoder_deps="rkmpp"
-vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
 vp9_vaapi_encoder_select="vaapi_encode"
 vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
 vp9_qsv_encoder_select="qsvenc"
@@ -3950,9 +3945,9 @@ xfade_vulkan_filter_deps="vulkan spirv_compiler"
 yadif_cuda_filter_deps="ffnvcodec"
 yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
 yadif_videotoolbox_filter_deps="metal corevideo videotoolbox"
-hstack_vaapi_filter_deps="vaapi_1"
-vstack_vaapi_filter_deps="vaapi_1"
-xstack_vaapi_filter_deps="vaapi_1"
+hstack_vaapi_filter_deps="vaapi"
+vstack_vaapi_filter_deps="vaapi"
+xstack_vaapi_filter_deps="vaapi"
 hstack_qsv_filter_deps="libmfx"
 hstack_qsv_filter_select="qsvvpp"
 vstack_qsv_filter_deps="libmfx"
@@ -7245,7 +7240,7 @@ enabled libdrm &&
 check_pkg_config libdrm_getfb2 libdrm "xf86drmMode.h" drmModeGetFB2

 enabled vaapi &&
-check_pkg_config vaapi "libva >= 0.35.0" "va/va.h" vaInitialize
+check_pkg_config vaapi "libva >= 1.0.0" "va/va.h" vaInitialize

 if enabled vaapi; then
 case $target_os in
@@ -7261,18 +7256,10 @@ if enabled vaapi; then
 check_pkg_config vaapi_x11 "libva-x11" "va/va_x11.h" vaGetDisplay
 fi

-check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
-
-check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
-check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
 check_struct "va/va.h" "VADecPictureParameterBufferAV1" bit_depth_idx
 check_type   "va/va.h va/va_vpp.h" 
"VAProcFilterParameterBufferHDRToneMapping"
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" rotation_flags
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" blend_flags
-check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
-check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
-check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
-check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
 check_type "va/va.h va/va_enc_av1.h"  "VAEncPictureParameterBufferAV1"
 fi

-- 
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-

[FFmpeg-devel] [PATCH v3 3/4] lavfi: Remove libva 1.x support

2024-04-22 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
Rebase on the dynamic pool change.


 libavfilter/vaapi_vpp.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index 9ef7a289fb..fe14170fee 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -204,12 +204,9 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 output_frames->width = ctx->output_width;
 output_frames->height= ctx->output_height;

-if (CONFIG_VAAPI_1)
-output_frames->initial_pool_size = 0;
-else
-output_frames->initial_pool_size = 4;
+output_frames->initial_pool_size = 0;

-err = ff_filter_init_hw_frames(avctx, outlink, 10);
+err = ff_filter_init_hw_frames(avctx, outlink, 0);
 if (err < 0)
 goto fail;

@@ -677,15 +674,12 @@ int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx,
 goto fail_after_render;
 }

-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
-for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) {
-vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: "
-   "%d (%s).\n", vas, vaErrorStr(vas));
-// And ignore.
-}
+for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) {
+vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+// And ignore.
 }
 }

-- 
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/4] lavc: Remove libva 1.x support

2024-04-22 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
Fixed some orphaned labels.


 libavcodec/vaapi_decode.c  | 39 ++---
 libavcodec/vaapi_encode.c  | 78 ++
 libavcodec/vaapi_encode.h  |  9 
 libavcodec/vaapi_encode_h264.c | 18 
 libavcodec/vaapi_encode_h265.c |  2 -
 5 files changed, 15 insertions(+), 131 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 21b273cd0f..ef1ea27a08 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -191,16 +191,10 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture decode "
"issue: %d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-goto fail;
-else
-goto fail_at_end;
+goto fail;
 }

-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-ff_vaapi_decode_destroy_buffers(avctx, pic);
+ff_vaapi_decode_destroy_buffers(avctx, pic);

 err = 0;
 goto exit;
@@ -213,7 +207,6 @@ fail_with_picture:
 }
 fail:
 ff_vaapi_decode_destroy_buffers(avctx, pic);
-fail_at_end:
 exit:
 pic->nb_param_buffers = 0;
 pic->nb_slices= 0;
@@ -406,12 +399,10 @@ static const struct {
H264ConstrainedBaseline),
 MAP(H264,H264_MAIN,   H264Main),
 MAP(H264,H264_HIGH,   H264High),
-#if VA_CHECK_VERSION(0, 37, 0)
 MAP(HEVC,HEVC_MAIN,   HEVCMain),
 MAP(HEVC,HEVC_MAIN_10,HEVCMain10  ),
 MAP(HEVC,HEVC_MAIN_STILL_PICTURE,
   HEVCMain),
-#endif
 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
 MAP(HEVC,HEVC_REXT,   None,
  ff_vaapi_parse_hevc_rext_scc_profile ),
@@ -429,14 +420,10 @@ static const struct {
 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
 MAP(VC1, VC1_ADVANCED,VC1Advanced ),
 MAP(VP8, UNKNOWN,   VP8Version0_3 ),
-#if VA_CHECK_VERSION(0, 38, 0)
 MAP(VP9, VP9_0,   VP9Profile0 ),
-#endif
-#if VA_CHECK_VERSION(0, 39, 0)
 MAP(VP9, VP9_1,   VP9Profile1 ),
 MAP(VP9, VP9_2,   VP9Profile2 ),
 MAP(VP9, VP9_3,   VP9Profile3 ),
-#endif
 #if VA_CHECK_VERSION(1, 8, 0)
 MAP(AV1, AV1_MAIN,AV1Profile0),
 MAP(AV1, AV1_HIGH,AV1Profile1),
@@ -599,27 +586,7 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 if (err < 0)
 goto fail;

-if (CONFIG_VAAPI_1)
-frames->initial_pool_size = 0;
-else {
-frames->initial_pool_size = 1;
-// Add per-codec number of surfaces used for storing reference 
frames.
-switch (avctx->codec_id) {
-case AV_CODEC_ID_H264:
-case AV_CODEC_ID_HEVC:
-case AV_CODEC_ID_AV1:
-frames->initial_pool_size += 16;
-break;
-case AV_CODEC_ID_VP9:
-frames->initial_pool_size += 8;
-break;
-case AV_CODEC_ID_VP8:
-frames->initial_pool_size += 3;
-break;
-default:
-frames->initial_pool_size += 2;
-}
-}
+frames->initial_pool_size = 0;
 }

 av_hwframe_constraints_free(&constraints);
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index f54b2579ec..6f062e8277 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -530,7 +530,6 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 }
 }

-#if VA_CHECK_VERSION(1, 0, 0)
 sd = av_frame_get_side_data(pic->input_image,
 AV_FRAME_DATA_REGIONS_OF_INTEREST);
 if (sd && ctx->roi_allowed) {
@@ -593,7 +592,6 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 if (err < 0)
 goto fail;
 }
-#endif

 vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context,
  pic->input_surface);
@@ -618,26 +616,17 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture encode issue: "
"%d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-// vaRenderPicture() has been called here, so we should not destroy
-// the parameter buffers unless separate destruction is required.
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-goto fail;
-else
-goto fail_at_end;
-}
-
-if (

[FFmpeg-devel] [PATCH v3 1/4] lavu: Remove libva 1.x support

2024-04-22 Thread Mark Thompson
libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
Rebased.

I think we can also drop the other quirks?  They are for the proprietary media 
SDK driver (which I think is dead?) and the VDPAU wrapper (which I don't think 
was ever updated for libva 2?).


 libavutil/hwcontext_vaapi.c | 22 --
 1 file changed, 22 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 56d03aa4cd..84bcb78087 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -372,14 +372,6 @@ static const struct {
 const char *match_string;
 unsigned int quirks;
 } vaapi_driver_quirks_table[] = {
-#if !VA_CHECK_VERSION(1, 0, 0)
-// The i965 driver did not conform before version 2.0.
-{
-"Intel i965 (Quick Sync)",
-"i965",
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
-},
-#endif
 {
 "Intel iHD",
 "ubit",
@@ -1413,7 +1405,6 @@ fail:
 }
 #endif

-#if VA_CHECK_VERSION(0, 36, 0)
 typedef struct VAAPIDRMImageBufferMapping {
 VAImage  image;
 VABufferInfo buffer_info;
@@ -1573,7 +1564,6 @@ fail:
 av_freep(&mapping);
 return err;
 }
-#endif

 static int vaapi_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
 const AVFrame *src, int flags)
@@ -1584,10 +1574,7 @@ static int vaapi_map_to_drm(AVHWFramesContext *hwfc, 
AVFrame *dst,
 if (err != AVERROR(ENOSYS))
 return err;
 #endif
-#if VA_CHECK_VERSION(0, 36, 0)
 return vaapi_map_to_drm_abh(hwfc, dst, src, flags);
-#endif
-return AVERROR(ENOSYS);
 }

 #endif /* CONFIG_LIBDRM */
@@ -1637,7 +1624,6 @@ static void vaapi_device_free(AVHWDeviceContext *ctx)
 av_freep(&priv);
 }

-#if CONFIG_VAAPI_1
 static void vaapi_device_log_error(void *context, const char *message)
 {
 AVHWDeviceContext *ctx = context;
@@ -1651,7 +1637,6 @@ static void vaapi_device_log_info(void *context, const 
char *message)

 av_log(ctx, AV_LOG_VERBOSE, "libva: %s", message);
 }
-#endif

 static int vaapi_device_connect(AVHWDeviceContext *ctx,
 VADisplay display)
@@ -1660,10 +1645,8 @@ static int vaapi_device_connect(AVHWDeviceContext *ctx,
 int major, minor;
 VAStatus vas;

-#if CONFIG_VAAPI_1
 vaSetErrorCallback(display, &vaapi_device_log_error, ctx);
 vaSetInfoCallback (display, &vaapi_device_log_info,  ctx);
-#endif

 hwctx->display = display;

@@ -1907,7 +1890,6 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,

 ent = av_dict_get(opts, "driver", NULL, 0);
 if (ent) {
-#if VA_CHECK_VERSION(0, 38, 0)
 VAStatus vas;
 vas = vaSetDriverName(display, ent->value);
 if (vas != VA_STATUS_SUCCESS) {
@@ -1916,10 +1898,6 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,
 vaTerminate(display);
 return AVERROR_EXTERNAL;
 }
-#else
-av_log(ctx, AV_LOG_WARNING, "Driver name setting is not "
-   "supported with this VAAPI version.\n");
-#endif
 }

 return vaapi_device_connect(ctx, display);
-- 
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] lavc/vaapi_hevc: Don't require exact profiles

2024-04-22 Thread Mark Thompson
Rather than turning the constraint flags into a single profile and then
searching for that profile (and failing if it doesn't match any profile
exactly), instead search all supported profiles and use the first one
which supports the given set of constraint flags.
---
This fixes decode of rext 8-bit 4:2:0; it will correctly pick Main 12 or Main 
4:2:2 10 or Main 4:4:4 (first one available) to use as the decoding profile 
after this patch.

 libavcodec/vaapi_decode.c | 45 ---
 libavcodec/vaapi_hevc.c   | 95 +--
 libavcodec/vaapi_hevc.h   |  4 +-
 3 files changed, 83 insertions(+), 61 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 21b273cd0f..f1327464f5 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -387,7 +387,9 @@ static const struct {
 enum AVCodecID codec_id;
 int codec_profile;
 VAProfile va_profile;
-VAProfile (*profile_parser)(AVCodecContext *avctx);
+VAProfile (*match_profile)(AVCodecContext *avctx,
+   const VAProfile *profile_list,
+   int profile_count);
 } vaapi_profile_map[] = {
 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## 
v, __VA_ARGS__ }
 MAP(MPEG2VIDEO,  MPEG2_SIMPLE,MPEG2Simple ),
@@ -414,9 +416,9 @@ static const struct {
 #endif
 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
 MAP(HEVC,HEVC_REXT,   None,
- ff_vaapi_parse_hevc_rext_scc_profile ),
+ ff_vaapi_hevc_match_rext_scc_profile ),
 MAP(HEVC,HEVC_SCC,None,
- ff_vaapi_parse_hevc_rext_scc_profile ),
+ ff_vaapi_hevc_match_rext_scc_profile ),
 #endif
 MAP(MJPEG,   MJPEG_HUFFMAN_BASELINE_DCT,
   JPEGBaseline),
@@ -499,22 +501,33 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 vaapi_profile_map[i].codec_profile == AV_PROFILE_UNKNOWN)
 profile_match = 1;

-va_profile = vaapi_profile_map[i].profile_parser ?
- vaapi_profile_map[i].profile_parser(avctx) :
- vaapi_profile_map[i].va_profile;
 codec_profile = vaapi_profile_map[i].codec_profile;
-
-for (j = 0; j < profile_count; j++) {
-if (va_profile == profile_list[j]) {
-exact_match = profile_match;
+if (vaapi_profile_map[i].match_profile) {
+va_profile =
+vaapi_profile_map[i].match_profile(avctx, profile_list,
+   profile_count);
+if (va_profile != VAProfileNone) {
+matched_va_profile = va_profile;
+matched_ff_profile = codec_profile;
+exact_match = 1;
 break;
 }
-}
-if (j < profile_count) {
-matched_va_profile = va_profile;
-matched_ff_profile = codec_profile;
-if (exact_match)
-break;
+} else {
+va_profile = vaapi_profile_map[i].va_profile;
+
+for (j = 0; j < profile_count; j++) {
+if (va_profile == profile_list[j]) {
+exact_match = profile_match;
+break;
+}
+}
+
+if (j < profile_count) {
+matched_va_profile = va_profile;
+matched_ff_profile = codec_profile;
+if (exact_match)
+break;
+}
 }
 }
 av_freep(&profile_list);
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 77f55ff8b1..28f7c9280e 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -590,63 +590,70 @@ static int ptl_convert(const PTLCommon *general_ptl, 
H265RawProfileTierLevel *h2
 }

 /*
- * Find exact va_profile for HEVC Range Extension and Screen Content Coding 
Extension
+ * Find compatible va_profile for HEVC Range Extension and Screen
+ * Content Coding Extension profiles.
  */
-VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
+VAProfile ff_vaapi_hevc_match_rext_scc_profile(AVCodecContext *avctx,
+   const VAProfile *profile_list,
+   int profile_count)
 {
 const HEVCContext *h = avctx->priv_data;
 const HEVCSPS *sps = h->ps.sps;
 const PTL *ptl = &sps->ptl;
 const PTLCommon *general_ptl = &ptl->general_ptl;
-const H265ProfileDescriptor *profile;
 H265RawProfileTierLevel h265_raw_ptl = {0};

+static const struct {
+int profile;
+VAProfile va_profile;
+} map[] = {
+#if VA_CHECK_VERSION(1, 2, 0)
+{ H265_PROFILE_MAIN_12,
+  VAProfileHEVCMain12 },
+{ H265_PROFILE_MAIN_422_10,
+  VAProfileHEVCMain422_10 },
+{ H265_PROFILE_MAIN_444,
+  

[FFmpeg-devel] [PATCH 1/2] lavc/h265_profile_level: Expand profile compatibility checking

2024-04-22 Thread Mark Thompson
Replace existing get_profile() with find_profile(), which finds the
lowest compatible profile rather than requiring an exact match.
---
 libavcodec/h265_profile_level.c | 73 +
 libavcodec/h265_profile_level.h | 70 ++-
 libavcodec/vaapi_hevc.c |  2 +-
 libavcodec/vdpau_hevc.c |  2 +-
 4 files changed, 117 insertions(+), 30 deletions(-)

diff --git a/libavcodec/h265_profile_level.c b/libavcodec/h265_profile_level.c
index 7ff9681f65..4bc72414cb 100644
--- a/libavcodec/h265_profile_level.c
+++ b/libavcodec/h265_profile_level.c
@@ -119,41 +119,60 @@ static const H265ProfileDescriptor h265_profiles[] = {
   5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5, 6 },
 };

+_Static_assert(H265_PROFILE_COUNT == FF_ARRAY_ELEMS(h265_profiles),
+   "Incorrect H.265 profiles table.");

-const H265ProfileDescriptor *ff_h265_get_profile(const H265RawProfileTierLevel 
*ptl)
+
+const int ff_h265_profile_compatible(const H265RawProfileTierLevel *ptl,
+ int profile)
 {
-int i;
+const H265ProfileDescriptor *desc;
+
+av_assert0(profile >= 0 && profile < H265_PROFILE_COUNT);

 if (ptl->general_profile_space)
-return NULL;
+return 0;

-for (i = 0; i < FF_ARRAY_ELEMS(h265_profiles); i++) {
-const H265ProfileDescriptor *profile = &h265_profiles[i];
+desc = &h265_profiles[profile];

-if (ptl->general_profile_idc &&
-ptl->general_profile_idc != profile->profile_idc)
-continue;
-if (!ptl->general_profile_compatibility_flag[profile->profile_idc])
-continue;
+if (ptl->general_profile_idc &&
+ptl->general_profile_idc != desc->profile_idc)
+return 0;
+if (!ptl->general_profile_compatibility_flag[desc->profile_idc])
+return 0;

-#define check_flag(name) \
-if (profile->name < 2) { \
-if (profile->name != ptl->general_ ## name ## _constraint_flag) \
-continue; \
-}
-check_flag(max_14bit);
-check_flag(max_12bit);
-check_flag(max_10bit);
-check_flag(max_8bit);
-check_flag(max_422chroma);
-check_flag(max_420chroma);
-check_flag(max_monochrome);
-check_flag(intra);
-check_flag(one_picture_only);
-check_flag(lower_bit_rate);
+#define check_flag(flag) \
+if (desc->flag < 2 && \
+desc->flag > ptl->general_ ## flag ## _constraint_flag) \
+return 0;
+check_flag(max_14bit);
+check_flag(max_12bit);
+check_flag(max_10bit);
+check_flag(max_8bit);
+check_flag(max_422chroma);
+check_flag(max_420chroma);
+check_flag(max_monochrome);
+check_flag(intra);
+check_flag(one_picture_only);
+check_flag(lower_bit_rate);
 #undef check_flag

-return profile;
+return 1;
+}
+
+
+const H265ProfileDescriptor *ff_h265_get_profile(int profile)
+{
+av_assert0(profile >= 0 && profile < H265_PROFILE_COUNT);
+
+return &h265_profiles[profile];
+}
+
+const H265ProfileDescriptor *ff_h265_find_profile(const 
H265RawProfileTierLevel *ptl)
+{
+for (int p = 0; p < H265_PROFILE_COUNT; p++) {
+if (ff_h265_profile_compatible(ptl, p))
+return &h265_profiles[p];
 }

 return NULL;
@@ -171,7 +190,7 @@ const H265LevelDescriptor *ff_h265_guess_level(const 
H265RawProfileTierLevel *pt
 int i;

 if (ptl)
-profile = ff_h265_get_profile(ptl);
+profile = ff_h265_find_profile(ptl);
 else
 profile = NULL;
 if (!profile) {
diff --git a/libavcodec/h265_profile_level.h b/libavcodec/h265_profile_level.h
index cd30ac5c50..f403f63211 100644
--- a/libavcodec/h265_profile_level.h
+++ b/libavcodec/h265_profile_level.h
@@ -24,6 +24,49 @@
 #include "cbs_h265.h"


+// Enumeration of all H.265 profiles.
+// The list is ordered to match table A.10; numeric values are an index
+// into the latest version of this table and have no codec meaning.
+enum {
+H265_PROFILE_MONOCHROME,
+H265_PROFILE_MONOCHROME_10,
+H265_PROFILE_MONOCHROME_12,
+H265_PROFILE_MONOCHROME_16,
+H265_PROFILE_MAIN,
+H265_PROFILE_SCREEN_EXTENDED_MAIN,
+H265_PROFILE_MAIN_10,
+H265_PROFILE_SCREEN_EXTENDED_MAIN_10,
+H265_PROFILE_MAIN_12,
+H265_PROFILE_MAIN_STILL_PICTURE,
+H265_PROFILE_MAIN_10_STILL_PICTURE,
+H265_PROFILE_MAIN_422_10,
+H265_PROFILE_MAIN_422_12,
+H265_PROFILE_MAIN_444,
+H265_PROFILE_HIGH_THROUGHPUT_444,
+H265_PROFILE_SCREEN_EXTENDED_MAIN_444,
+H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444,
+H265_PROFILE_MAIN_444_10,
+H265_PROFILE_HIGH_THROUGHPUT_444_10,
+H265_PROFILE_SCREEN_EXTENDED_MAIN_444_10,
+H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444_10,
+H265_PROFILE_MAIN_444_12,
+H265_PROFILE_HIGH_THROUGHPUT_444_14,
+H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444_14,
+H265_PROFILE_MAIN_INTRA,
+H265_PR

Re: [FFmpeg-devel] [PATCH v3 1/2] lavc/vaapi_encode_h265: Map HEVC AV REXT profile to VA REXT profile

2024-04-22 Thread Mark Thompson
On 18/04/2024 09:21, Wang, Fei W wrote:
> On Tue, 2024-04-16 at 04:57 +, Wang, Fei W wrote:
>> On Mon, 2024-04-15 at 23:07 +0100, Mark Thompson wrote:
>>> Why is this change helpful?
>>
>> Together with 2/2 fix on the hw support VAAPI main12 decode and
>> encode:
>>
>> $ ffmpeg -hwaccel vaapi -f lavfi -i testsrc -vf
>> 'format=nv12,hwupload'
>> -c:v hevc_vaapi -profile:v rext -vframes 30 -y out.mp4
>>
>> $ ffmpeg -hwaccel vaapi -i out.mp4 -f null -
>> ...
>> [hevc @ 0x55b4fda0a780] HEVC profile is not found.
>> [hevc @ 0x55b4fda0a780] No support for codec hevc profile 4.
>> [hevc @ 0x55b4fda0a780] Failed setup for format vaapi: hwaccel
>> initialisation returned error.
>>
>> Same for p010le as input of encoder.
> 
> Hi
> 
> Any further comments on this patchset?

I think it is better to fix this by removing the fake constraints on the 
decoder rather than by adding extra constraints to the encoder.

See patchset following.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] av1dec: Fix RefFrameSignBias calculation

2024-04-22 Thread Mark Thompson
On 22/04/2024 21:36, Lynne wrote:
> Apr 22, 2024, 22:31 by s...@jkqxz.net:
> 
>> ---
>> Actually match the specification.  (Though I'm guessing this field isn't 
>> actually used if things pass anyway?)
>>
>>  libavcodec/av1dec.c | 9 +++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
>> index 69da08b686..79a30a114d 100644
>> --- a/libavcodec/av1dec.c
>> +++ b/libavcodec/av1dec.c
>> @@ -373,8 +373,13 @@ static void order_hint_info(AV1DecContext *s)
>>  int ref_order_hint = s->ref[ref_slot].order_hint;
>>
>>  frame->order_hints[ref_name] = ref_order_hint;
>> -frame->ref_frame_sign_bias[ref_name] =
>> -get_relative_dist(seq, ref_order_hint, frame->order_hint);
>> +if (!seq->enable_order_hint) {
>> +frame->ref_frame_sign_bias[ref_name] = 0;
>> +} else {
>> +frame->ref_frame_sign_bias[ref_name] =
>> +get_relative_dist(seq, ref_order_hint,
>> +  frame->order_hint) > 0;
>> +}
>>  }
>>  }
>>
> 
> LGTM

Applied, thank you.

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/cbs_h2645: Check NAL space

2024-04-22 Thread Mark Thompson
On 22/04/2024 02:31, Michael Niedermayer wrote:
> Found-by-reviewing: CID1419833 Untrusted loop bound
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/cbs_h2645.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index fe2e383ff33..1a45d424bae 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -709,7 +709,11 @@ static int 
> cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
>  
>  start = bytestream2_tell(&gbc);
>  for(i = 0; i < num_nalus; i++) {
> +if (bytestream2_get_bytes_left(&gbc) < 2)
> +return AVERROR_INVALIDDATA;
>  size = bytestream2_get_be16(&gbc);
> +if (bytestream2_get_bytes_left(&gbc) < size)
> +return AVERROR_INVALIDDATA;
>  bytestream2_skip(&gbc, size);
>  }
>  end = bytestream2_tell(&gbc);

Seems fair.

The problem looks more general with missing bounds checks in all the H.266 code 
around this, though?  Compare with H.26[45], which have checks on all the reads 
- seems like H.266 should be doing that.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] av1dec: Fix RefFrameSignBias calculation

2024-04-22 Thread Mark Thompson
---
Actually match the specification.  (Though I'm guessing this field isn't 
actually used if things pass anyway?)

 libavcodec/av1dec.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 69da08b686..79a30a114d 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -373,8 +373,13 @@ static void order_hint_info(AV1DecContext *s)
 int ref_order_hint = s->ref[ref_slot].order_hint;

 frame->order_hints[ref_name] = ref_order_hint;
-frame->ref_frame_sign_bias[ref_name] =
-get_relative_dist(seq, ref_order_hint, frame->order_hint);
+if (!seq->enable_order_hint) {
+frame->ref_frame_sign_bias[ref_name] = 0;
+} else {
+frame->ref_frame_sign_bias[ref_name] =
+get_relative_dist(seq, ref_order_hint,
+  frame->order_hint) > 0;
+}
 }
 }

-- 
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 1/2] lavc/vaapi_encode_h265: Map HEVC AV REXT profile to VA REXT profile

2024-04-15 Thread Mark Thompson
On 15/04/2024 02:21, Xiang, Haihao wrote:
> On Ma, 2024-03-18 at 12:21 +0800, fei.w.wang-at-intel@ffmpeg.org wrote:
>> From: Fei Wang 
>>
>> There is no Main8/10 profile defined in HEVC REXT profiles. Use Main12
>> which is compatible with 8/10bit.
>>
>> Signed-off-by: Fei Wang 
>> ---
>>  libavcodec/vaapi_encode_h265.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
>> index c4aabbf5ed..43755e2188 100644
>> --- a/libavcodec/vaapi_encode_h265.c
>> +++ b/libavcodec/vaapi_encode_h265.c
>> @@ -1305,12 +1305,12 @@ static av_cold int
>> vaapi_encode_h265_configure(AVCodecContext *avctx)
>>  
>>  static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = {
>>  { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain   },
>> -    { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain   },
>>  #if VA_CHECK_VERSION(0, 37, 0)
>>  { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
>> -    { AV_PROFILE_HEVC_REXT,    10, 3, 1, 1, VAProfileHEVCMain10 },
>>  #endif
>>  #if VA_CHECK_VERSION(1, 2, 0)
>> +    { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain12 },
>> +    { AV_PROFILE_HEVC_REXT,    10, 3, 1, 1, VAProfileHEVCMain12 },
>>  { AV_PROFILE_HEVC_REXT,    12, 3, 1, 1, VAProfileHEVCMain12 },
>>  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 0, VAProfileHEVCMain422_10 },
>>  { AV_PROFILE_HEVC_REXT,    10, 3, 1, 0, VAProfileHEVCMain422_10 },
> 
> Patchset LGTM, I'll push it if there are no comments.

Why is this change helpful?

We don't use the rext features allowed in these cases (unlike in the decoder 
where we have to support them), so Main / Main 10 encoders will be able to 
produce a compatible stream without pointlessly requiring Main 12 support which 
many devices do not have.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/2] lavc/av1: Record reference ordering information for each frame

2024-04-14 Thread Mark Thompson
On 13/04/2024 20:05, Mark Thompson wrote:
> This is needed by Vulkan.  Constructing this can't be delegated to CBS
> because packets might contain multiple frames (when non-shown frames are
> present) but we need separate snapshots immediately before each frame
> for the decoder.
> ---
> Changes over v1: rename the order hint field and document exactly what the 
> new fields contain.
> 
>  libavcodec/av1dec.c | 26 ++
>  libavcodec/av1dec.h |  8 
>  2 files changed, 34 insertions(+)
> > ---
> Changes over v1: fix the OrderHints field as well; move things into the loop 
> over reference names rather than the loop over reference slots.
>
>  libavcodec/vulkan_av1.c | 23 ++-
>  1 file changed, 10 insertions(+), 13 deletions(-)
>

Both pushed with approval from Lynne.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/2] lavc/vulkan_av1: Use av1dec reference order hint information

2024-04-13 Thread Mark Thompson

---
Changes over v1: fix the OrderHints field as well; move things into the loop 
over reference names rather than the loop over reference slots.

 libavcodec/vulkan_av1.c | 23 ++-
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index c9e398eaec..fcc9a4f03b 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -76,7 +76,7 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const 
AV1Frame **ref_src,
 StdVideoDecodeAV1ReferenceInfo *vkav1_std_ref,
 VkVideoDecodeAV1DpbSlotInfoKHR *vkav1_ref, /* Goes 
in ^ */
 const AV1Frame *pic, int is_current, int has_grain,
-int *saved_order_hints)
+const uint8_t *saved_order_hints)
 {
 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
 AV1VulkanDecodePicture *hp = pic->hwaccel_picture_private;
@@ -242,7 +242,6 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 const AV1RawFrameHeader *frame_header = s->raw_frame_header;
 const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
-CodedBitstreamAV1Context *cbs_ctx = (CodedBitstreamAV1Context 
*)(s->cbc->priv_data);

 const int apply_grain = !(avctx->export_side_data & 
AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
 film_grain->apply_grain;
@@ -272,7 +271,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 ap->ref_frame_sign_bias_mask = 0x0;
 for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++)
-ap->ref_frame_sign_bias_mask |= cbs_ctx->ref_frame_sign_bias[i] << i;
+ap->ref_frame_sign_bias_mask |= pic->ref_frame_sign_bias[i] << i;

 for (int i = 0; i < STD_VIDEO_AV1_REFS_PER_FRAME; i++) {
 const int idx = pic->raw_frame_header->ref_frame_idx[i];
@@ -294,7 +293,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 err = vk_av1_fill_pict(avctx, &ap->ref_src[ref_count], 
&vp->ref_slots[ref_count],
&vp->refs[ref_count], &ap->std_refs[ref_count], 
&ap->vkav1_refs[ref_count],
-   ref_frame, 0, 0, 
cbs_ctx->ref[idx].saved_order_hints);
+   ref_frame, 0, 0, ref_frame->order_hints);
 if (err < 0)
 return err;

@@ -491,8 +490,14 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,
 }
 }

-for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++)
+for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++) {
+ap->std_pic_info.OrderHints[i] = pic->order_hints[i];
 ap->loop_filter.loop_filter_ref_deltas[i] = 
frame_header->loop_filter_ref_deltas[i];
+ap->global_motion.GmType[i] = s->cur_frame.gm_type[i];
+for (int j = 0; j < STD_VIDEO_AV1_GLOBAL_MOTION_PARAMS; j++) {
+ap->global_motion.gm_params[i][j] = s->cur_frame.gm_params[i][j];
+}
+}

 for (int i = 0; i < STD_VIDEO_AV1_MAX_CDEF_FILTER_STRENGTHS; i++) {
 ap->cdef.cdef_y_pri_strength[i] = frame_header->cdef_y_pri_strength[i];
@@ -501,14 +506,6 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,
 ap->cdef.cdef_uv_sec_strength[i] = 
frame_header->cdef_uv_sec_strength[i];
 }

-for (int i = 0; i < STD_VIDEO_AV1_NUM_REF_FRAMES; i++) {
-ap->std_pic_info.OrderHints[i] = frame_header->ref_order_hint[i];
-ap->global_motion.GmType[i] = s->cur_frame.gm_type[i];
-for (int j = 0; j < STD_VIDEO_AV1_GLOBAL_MOTION_PARAMS; j++) {
-ap->global_motion.gm_params[i][j] = s->cur_frame.gm_params[i][j];
-}
-}
-
 if (apply_grain) {
 for (int i = 0; i < STD_VIDEO_AV1_MAX_NUM_Y_POINTS; i++) {
 ap->film_grain.point_y_value[i] = film_grain->point_y_value[i];
--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/2] lavc/av1: Record reference ordering information for each frame

2024-04-13 Thread Mark Thompson

This is needed by Vulkan.  Constructing this can't be delegated to CBS
because packets might contain multiple frames (when non-shown frames are
present) but we need separate snapshots immediately before each frame
for the decoder.
---
Changes over v1: rename the order hint field and document exactly what the new 
fields contain.

 libavcodec/av1dec.c | 26 ++
 libavcodec/av1dec.h |  8 
 2 files changed, 34 insertions(+)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 824725c031..b4b741054a 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -359,6 +359,25 @@ static void coded_lossless_param(AV1DecContext *s)
 }
 }

+static void order_hint_info(AV1DecContext *s)
+{
+const AV1RawFrameHeader *header = s->raw_frame_header;
+const AV1RawSequenceHeader *seq = s->raw_seq;
+AV1Frame *frame = &s->cur_frame;
+
+frame->order_hint = header->order_hint;
+
+for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
+int ref_name = i + AV1_REF_FRAME_LAST;
+int ref_slot = header->ref_frame_idx[i];
+int ref_order_hint = s->ref[ref_slot].order_hint;
+
+frame->order_hints[ref_name] = ref_order_hint;
+frame->ref_frame_sign_bias[ref_name] =
+get_relative_dist(seq, ref_order_hint, frame->order_hint);
+}
+}
+
 static void load_grain_params(AV1DecContext *s)
 {
 const AV1RawFrameHeader *header = s->raw_frame_header;
@@ -701,6 +720,12 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame 
*dst, const AV1Frame *s
sizeof(dst->film_grain));
 dst->coded_lossless = src->coded_lossless;

+dst->order_hint = src->order_hint;
+memcpy(dst->ref_frame_sign_bias, src->ref_frame_sign_bias,
+   sizeof(dst->ref_frame_sign_bias));
+memcpy(dst->order_hints, src->order_hints,
+   sizeof(dst->order_hints));
+
 return 0;

 fail:
@@ -1257,6 +1282,7 @@ static int get_current_frame(AVCodecContext *avctx)
 global_motion_params(s);
 skip_mode_params(s);
 coded_lossless_param(s);
+order_hint_info(s);
 load_grain_params(s);

 return ret;
diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h
index 336eb61359..79a0be510b 100644
--- a/libavcodec/av1dec.h
+++ b/libavcodec/av1dec.h
@@ -53,6 +53,14 @@ typedef struct AV1Frame {
 AV1RawFilmGrainParams film_grain;

 uint8_t coded_lossless;
+
+// OrderHint for this frame.
+uint8_t order_hint;
+// RefFrameSignBias[] used when decoding this frame.
+uint8_t ref_frame_sign_bias[AV1_TOTAL_REFS_PER_FRAME];
+// OrderHints[] when this is the current frame, otherwise
+// SavedOrderHints[s][] when is the reference frame in slot s.
+uint8_t order_hints[AV1_TOTAL_REFS_PER_FRAME];
 } AV1Frame;

 typedef struct TileGroupInfo {
--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] lavc/vulkan_av1: Use av1dec reference order hint information

2024-04-07 Thread Mark Thompson

---
 libavcodec/vulkan_av1.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index c9e398eaec..8cca97c005 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -242,7 +242,6 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 const AV1RawFrameHeader *frame_header = s->raw_frame_header;
 const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
-CodedBitstreamAV1Context *cbs_ctx = (CodedBitstreamAV1Context 
*)(s->cbc->priv_data);

 const int apply_grain = !(avctx->export_side_data & 
AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
 film_grain->apply_grain;
@@ -272,7 +271,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 ap->ref_frame_sign_bias_mask = 0x0;
 for (int i = 0; i < STD_VIDEO_AV1_TOTAL_REFS_PER_FRAME; i++)
-ap->ref_frame_sign_bias_mask |= cbs_ctx->ref_frame_sign_bias[i] << i;
+ap->ref_frame_sign_bias_mask |= pic->ref_frame_sign_bias[i] << i;

 for (int i = 0; i < STD_VIDEO_AV1_REFS_PER_FRAME; i++) {
 const int idx = pic->raw_frame_header->ref_frame_idx[i];
@@ -294,7 +293,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,

 err = vk_av1_fill_pict(avctx, &ap->ref_src[ref_count], 
&vp->ref_slots[ref_count],
&vp->refs[ref_count], &ap->std_refs[ref_count], 
&ap->vkav1_refs[ref_count],
-   ref_frame, 0, 0, 
cbs_ctx->ref[idx].saved_order_hints);
+   ref_frame, 0, 0, ref_frame->saved_order_hints);
 if (err < 0)
 return err;

--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] lavc/av1: Record reference ordering information for each frame

2024-04-07 Thread Mark Thompson

This is needed by Vulkan.  Constructing this can't be delegated to CBS
because packets might contain multiple frames (when non-shown frames are
present) but we need separate snapshots immediately before each frame
for the decoder.
---
 libavcodec/av1dec.c | 26 ++
 libavcodec/av1dec.h |  4 
 2 files changed, 30 insertions(+)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 824725c031..439f17825b 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -359,6 +359,25 @@ static void coded_lossless_param(AV1DecContext *s)
 }
 }

+static void order_hint_info(AV1DecContext *s)
+{
+const AV1RawFrameHeader *header = s->raw_frame_header;
+const AV1RawSequenceHeader *seq = s->raw_seq;
+AV1Frame *frame = &s->cur_frame;
+
+frame->order_hint = header->order_hint;
+
+for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
+int ref_name = i + AV1_REF_FRAME_LAST;
+int ref_slot = header->ref_frame_idx[i];
+int ref_order_hint = s->ref[ref_slot].order_hint;
+
+frame->saved_order_hints[ref_name] = ref_order_hint;
+frame->ref_frame_sign_bias[ref_name] =
+get_relative_dist(seq, ref_order_hint, frame->order_hint);
+}
+}
+
 static void load_grain_params(AV1DecContext *s)
 {
 const AV1RawFrameHeader *header = s->raw_frame_header;
@@ -701,6 +720,12 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame 
*dst, const AV1Frame *s
sizeof(dst->film_grain));
 dst->coded_lossless = src->coded_lossless;

+dst->order_hint = src->order_hint;
+memcpy(dst->ref_frame_sign_bias, src->ref_frame_sign_bias,
+   sizeof(dst->ref_frame_sign_bias));
+memcpy(dst->saved_order_hints, src->saved_order_hints,
+   sizeof(dst->saved_order_hints));
+
 return 0;

 fail:
@@ -1257,6 +1282,7 @@ static int get_current_frame(AVCodecContext *avctx)
 global_motion_params(s);
 skip_mode_params(s);
 coded_lossless_param(s);
+order_hint_info(s);
 load_grain_params(s);

 return ret;
diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h
index 336eb61359..0a7073ddce 100644
--- a/libavcodec/av1dec.h
+++ b/libavcodec/av1dec.h
@@ -53,6 +53,10 @@ typedef struct AV1Frame {
 AV1RawFilmGrainParams film_grain;

 uint8_t coded_lossless;
+
+uint8_t order_hint;
+uint8_t ref_frame_sign_bias[AV1_NUM_REF_FRAMES];
+uint8_t saved_order_hints[AV1_NUM_REF_FRAMES];
 } AV1Frame;

 typedef struct TileGroupInfo {
--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 4/4] configure: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.  Various features no longer need any
configure check after this command, including all codecs except AV1.
Note that the libva version is the API version plus one, so this is
removing support for VAAPI 0.x and requiring VAAPI 1.x.
---
Fixed some filter checks and added a note about the version numbering.

 configure | 25 ++---
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/configure b/configure
index 29cc8773fd..0253553caf 100755
--- a/configure
+++ b/configure
@@ -2622,7 +2622,6 @@ CONFIG_EXTRA="
 texturedsp
 texturedspenc
 tpeldsp
-vaapi_1
 vaapi_encode
 vc1dsp
 videodsp
@@ -3185,7 +3184,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
 hevc_nvdec_hwaccel_select="hevc_decoder"
-hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
+hevc_vaapi_hwaccel_deps="vaapi"
 hevc_vaapi_hwaccel_select="hevc_decoder"
 hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
 hevc_vdpau_hwaccel_select="hevc_decoder"
@@ -3257,7 +3256,7 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
 vp9_nvdec_hwaccel_select="vp9_decoder"
-vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
+vp9_vaapi_hwaccel_deps="vaapi"
 vp9_vaapi_hwaccel_select="vp9_decoder"
 vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
 vp9_vdpau_hwaccel_select="vp9_decoder"
@@ -3349,7 +3348,6 @@ hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
 hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
 hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
-hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
 hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
 hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
@@ -3358,7 +3356,6 @@ mjpeg_cuvid_decoder_deps="cuvid"
 mjpeg_qsv_decoder_select="qsvdec"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
-mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
 mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
 mp3_mf_encoder_deps="mediafoundation"
 mpeg1_cuvid_decoder_deps="cuvid"
@@ -3386,7 +3383,6 @@ vp8_mediacodec_decoder_deps="mediacodec"
 vp8_mediacodec_encoder_deps="mediacodec"
 vp8_qsv_decoder_select="qsvdec"
 vp8_rkmpp_decoder_deps="rkmpp"
-vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
 vp8_vaapi_encoder_select="vaapi_encode"
 vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
@@ -3395,7 +3391,6 @@ vp9_mediacodec_decoder_deps="mediacodec"
 vp9_mediacodec_encoder_deps="mediacodec"
 vp9_qsv_decoder_select="qsvdec"
 vp9_rkmpp_decoder_deps="rkmpp"
-vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
 vp9_vaapi_encoder_select="vaapi_encode"
 vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
 vp9_qsv_encoder_select="qsvenc"
@@ -3942,9 +3937,9 @@ xfade_vulkan_filter_deps="vulkan spirv_compiler"
 yadif_cuda_filter_deps="ffnvcodec"
 yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
 yadif_videotoolbox_filter_deps="metal corevideo videotoolbox"
-hstack_vaapi_filter_deps="vaapi_1"
-vstack_vaapi_filter_deps="vaapi_1"
-xstack_vaapi_filter_deps="vaapi_1"
+hstack_vaapi_filter_deps="vaapi"
+vstack_vaapi_filter_deps="vaapi"
+xstack_vaapi_filter_deps="vaapi"
 hstack_qsv_filter_deps="libmfx"
 hstack_qsv_filter_select="qsvvpp"
 vstack_qsv_filter_deps="libmfx"
@@ -7238,7 +7233,7 @@ enabled libdrm &&
 check_pkg_config libdrm_getfb2 libdrm "xf86drmMode.h" drmModeGetFB2

 enabled vaapi &&
-check_pkg_config vaapi "libva >= 0.35.0" "va/va.h" vaInitialize
+check_pkg_config vaapi "libva >= 1.0.0" "va/va.h" vaInitialize

 if enabled vaapi; then
 case $target_os in
@@ -7254,18 +7249,10 @@ if enabled vaapi; then
 check_pkg_config vaapi_x11 "libva-x11" "va/va_x11.h" vaGetDisplay
 fi

-check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
-
-check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
-check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
 check_struct "va/va.h" "VADecPictureParameterBufferAV1" bit_depth_idx
 check_type   "va/va.h va/va_vpp.h" 
"VAProcFilterParameterBufferHDRToneMapping"
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" rotation_flags
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" blend_flags
-check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
-check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
-check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
-check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
 check_type "va/va.h va/va_enc_av1.h"  "VAEncPictureParameterBufferAV1"
 fi

--
2.43.0
_

[FFmpeg-devel] [PATCH v2 3/4] lavfi: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
No change.

 libavfilter/vaapi_vpp.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index ace1153a23..21d74f8112 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -672,15 +672,12 @@ int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx,
 goto fail_after_render;
 }

-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
-for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) {
-vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: "
-   "%d (%s).\n", vas, vaErrorStr(vas));
-// And ignore.
-}
+for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) {
+vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+// And ignore.
 }
 }

--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/4] lavc: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
Now removing lots of VA_CHECK_VERSION as well.

 libavcodec/vaapi_decode.c  | 16 +--
 libavcodec/vaapi_encode.c  | 77 ++
 libavcodec/vaapi_encode.h  |  9 
 libavcodec/vaapi_encode_h264.c | 18 
 libavcodec/vaapi_encode_h265.c |  2 -
 5 files changed, 14 insertions(+), 108 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 5665639dd7..1f923a414a 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -191,16 +191,10 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture decode "
"issue: %d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-goto fail;
-else
-goto fail_at_end;
+goto fail;
 }

-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-ff_vaapi_decode_destroy_buffers(avctx, pic);
+ff_vaapi_decode_destroy_buffers(avctx, pic);

 err = 0;
 goto exit;
@@ -406,12 +400,10 @@ static const struct {
H264ConstrainedBaseline),
 MAP(H264,H264_MAIN,   H264Main),
 MAP(H264,H264_HIGH,   H264High),
-#if VA_CHECK_VERSION(0, 37, 0)
 MAP(HEVC,HEVC_MAIN,   HEVCMain),
 MAP(HEVC,HEVC_MAIN_10,HEVCMain10  ),
 MAP(HEVC,HEVC_MAIN_STILL_PICTURE,
   HEVCMain),
-#endif
 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
 MAP(HEVC,HEVC_REXT,   None,
  ff_vaapi_parse_hevc_rext_scc_profile ),
@@ -429,14 +421,10 @@ static const struct {
 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
 MAP(VC1, VC1_ADVANCED,VC1Advanced ),
 MAP(VP8, UNKNOWN,   VP8Version0_3 ),
-#if VA_CHECK_VERSION(0, 38, 0)
 MAP(VP9, VP9_0,   VP9Profile0 ),
-#endif
-#if VA_CHECK_VERSION(0, 39, 0)
 MAP(VP9, VP9_1,   VP9Profile1 ),
 MAP(VP9, VP9_2,   VP9Profile2 ),
 MAP(VP9, VP9_3,   VP9Profile3 ),
-#endif
 #if VA_CHECK_VERSION(1, 8, 0)
 MAP(AV1, AV1_MAIN,AV1Profile0),
 MAP(AV1, AV1_HIGH,AV1Profile1),
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index f54b2579ec..2f02a7a2e1 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -530,7 +530,6 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 }
 }

-#if VA_CHECK_VERSION(1, 0, 0)
 sd = av_frame_get_side_data(pic->input_image,
 AV_FRAME_DATA_REGIONS_OF_INTEREST);
 if (sd && ctx->roi_allowed) {
@@ -593,7 +592,6 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 if (err < 0)
 goto fail;
 }
-#endif

 vas = vaBeginPicture(ctx->hwctx->display, ctx->va_context,
  pic->input_surface);
@@ -618,26 +616,17 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture encode issue: "
"%d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-// vaRenderPicture() has been called here, so we should not destroy
-// the parameter buffers unless separate destruction is required.
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-goto fail;
-else
-goto fail_at_end;
-}
-
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
-for (i = 0; i < pic->nb_param_buffers; i++) {
-vas = vaDestroyBuffer(ctx->hwctx->display,
-  pic->param_buffers[i]);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to destroy "
-   "param buffer %#x: %d (%s).\n",
-   pic->param_buffers[i], vas, vaErrorStr(vas));
-// And ignore.
-}
+goto fail;
+}
+
+for (i = 0; i < pic->nb_param_buffers; i++) {
+vas = vaDestroyBuffer(ctx->hwctx->display,
+  pic->param_buffers[i]);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to destroy "
+   "param buffer %#x: %d (%s).\n",
+   pic->param_buffers[i], vas, vaErrorStr(vas));
+// And ignore.
 }
 }

@@ -1530,25 +1519,19 @@ static const VAAPIEncodeRTFormat 
vaapi_encode_rt_formats[] = {
 { "YUV444",VA_RT_FORMAT_YUV444,8, 3, 0,

[FFmpeg-devel] [PATCH v2 1/4] lavu: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
The other two quirk cases are very old and could probably be removed?  That 
could then deprecate the quirks system as well.

 libavutil/hwcontext_vaapi.c | 22 --
 1 file changed, 22 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 56d03aa4cd..84bcb78087 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -372,14 +372,6 @@ static const struct {
 const char *match_string;
 unsigned int quirks;
 } vaapi_driver_quirks_table[] = {
-#if !VA_CHECK_VERSION(1, 0, 0)
-// The i965 driver did not conform before version 2.0.
-{
-"Intel i965 (Quick Sync)",
-"i965",
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
-},
-#endif
 {
 "Intel iHD",
 "ubit",
@@ -1413,7 +1405,6 @@ fail:
 }
 #endif

-#if VA_CHECK_VERSION(0, 36, 0)
 typedef struct VAAPIDRMImageBufferMapping {
 VAImage  image;
 VABufferInfo buffer_info;
@@ -1573,7 +1564,6 @@ fail:
 av_freep(&mapping);
 return err;
 }
-#endif

 static int vaapi_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
 const AVFrame *src, int flags)
@@ -1584,10 +1574,7 @@ static int vaapi_map_to_drm(AVHWFramesContext *hwfc, 
AVFrame *dst,
 if (err != AVERROR(ENOSYS))
 return err;
 #endif
-#if VA_CHECK_VERSION(0, 36, 0)
 return vaapi_map_to_drm_abh(hwfc, dst, src, flags);
-#endif
-return AVERROR(ENOSYS);
 }

 #endif /* CONFIG_LIBDRM */
@@ -1637,7 +1624,6 @@ static void vaapi_device_free(AVHWDeviceContext *ctx)
 av_freep(&priv);
 }

-#if CONFIG_VAAPI_1
 static void vaapi_device_log_error(void *context, const char *message)
 {
 AVHWDeviceContext *ctx = context;
@@ -1651,7 +1637,6 @@ static void vaapi_device_log_info(void *context, const 
char *message)

 av_log(ctx, AV_LOG_VERBOSE, "libva: %s", message);
 }
-#endif

 static int vaapi_device_connect(AVHWDeviceContext *ctx,
 VADisplay display)
@@ -1660,10 +1645,8 @@ static int vaapi_device_connect(AVHWDeviceContext *ctx,
 int major, minor;
 VAStatus vas;

-#if CONFIG_VAAPI_1
 vaSetErrorCallback(display, &vaapi_device_log_error, ctx);
 vaSetInfoCallback (display, &vaapi_device_log_info,  ctx);
-#endif

 hwctx->display = display;

@@ -1907,7 +1890,6 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,

 ent = av_dict_get(opts, "driver", NULL, 0);
 if (ent) {
-#if VA_CHECK_VERSION(0, 38, 0)
 VAStatus vas;
 vas = vaSetDriverName(display, ent->value);
 if (vas != VA_STATUS_SUCCESS) {
@@ -1916,10 +1898,6 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, 
const char *device,
 vaTerminate(display);
 return AVERROR_EXTERNAL;
 }
-#else
-av_log(ctx, AV_LOG_WARNING, "Driver name setting is not "
-   "supported with this VAAPI version.\n");
-#endif
 }

 return vaapi_device_connect(ctx, display);
--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/4] lavu: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

On 03/04/2024 21:09, Rémi Denis-Courmont wrote:

Le keskiviikkona 3. huhtikuuta 2024, 22.44.29 EEST Mark Thompson a écrit :

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
   libavutil/hwcontext_vaapi.c | 4 
   1 file changed, 4 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 56d03aa4cd..bc82ab31e6 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1637,7 +1637,6 @@ static void vaapi_device_free(AVHWDeviceContext *ctx)
   av_freep(&priv);
   }

-#if CONFIG_VAAPI_1


IMO, it wouldn't hurt to clarify in the change description that CONFIG_VAAPI_1
actually corresponded to libva 2.x. No objections to the code changes though.


Fair, the library major version being the API major version plus one is a 
slightly bizarre feature.  I've added some words to that effect locally.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 4/4] configure: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.  Various features no longer need any
configure check after this command, including all codecs except AV1.
---
 configure | 22 +++---
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/configure b/configure
index 71386c3920..9adada002f 100755
--- a/configure
+++ b/configure
@@ -2622,7 +2622,6 @@ CONFIG_EXTRA="
 texturedsp
 texturedspenc
 tpeldsp
-vaapi_1
 vaapi_encode
 vc1dsp
 videodsp
@@ -3184,7 +3183,7 @@ hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
 hevc_dxva2_hwaccel_select="hevc_decoder"
 hevc_nvdec_hwaccel_deps="nvdec"
 hevc_nvdec_hwaccel_select="hevc_decoder"
-hevc_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferHEVC"
+hevc_vaapi_hwaccel_deps="vaapi"
 hevc_vaapi_hwaccel_select="hevc_decoder"
 hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
 hevc_vdpau_hwaccel_select="hevc_decoder"
@@ -3256,7 +3255,7 @@ vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
 vp9_dxva2_hwaccel_select="vp9_decoder"
 vp9_nvdec_hwaccel_deps="nvdec"
 vp9_nvdec_hwaccel_select="vp9_decoder"
-vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
+vp9_vaapi_hwaccel_deps="vaapi"
 vp9_vaapi_hwaccel_select="vp9_decoder"
 vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
 vp9_vdpau_hwaccel_select="vp9_decoder"
@@ -3348,7 +3347,6 @@ hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec"
 hevc_qsv_encoder_select="hevcparse qsvenc"
 hevc_rkmpp_decoder_deps="rkmpp"
 hevc_rkmpp_decoder_select="hevc_mp4toannexb_bsf"
-hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
 hevc_vaapi_encoder_select="atsc_a53 cbs_h265 vaapi_encode"
 hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
@@ -3357,7 +3355,6 @@ mjpeg_cuvid_decoder_deps="cuvid"
 mjpeg_qsv_decoder_select="qsvdec"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
-mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
 mjpeg_vaapi_encoder_select="cbs_jpeg jpegtables vaapi_encode"
 mp3_mf_encoder_deps="mediafoundation"
 mpeg1_cuvid_decoder_deps="cuvid"
@@ -3385,7 +3382,6 @@ vp8_mediacodec_decoder_deps="mediacodec"
 vp8_mediacodec_encoder_deps="mediacodec"
 vp8_qsv_decoder_select="qsvdec"
 vp8_rkmpp_decoder_deps="rkmpp"
-vp8_vaapi_encoder_deps="VAEncPictureParameterBufferVP8"
 vp8_vaapi_encoder_select="vaapi_encode"
 vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
@@ -3394,7 +3390,6 @@ vp9_mediacodec_decoder_deps="mediacodec"
 vp9_mediacodec_encoder_deps="mediacodec"
 vp9_qsv_decoder_select="qsvdec"
 vp9_rkmpp_decoder_deps="rkmpp"
-vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
 vp9_vaapi_encoder_select="vaapi_encode"
 vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
 vp9_qsv_encoder_select="qsvenc"
@@ -3940,9 +3935,6 @@ xfade_vulkan_filter_deps="vulkan spirv_compiler"
 yadif_cuda_filter_deps="ffnvcodec"
 yadif_cuda_filter_deps_any="cuda_nvcc cuda_llvm"
 yadif_videotoolbox_filter_deps="metal corevideo videotoolbox"
-hstack_vaapi_filter_deps="vaapi_1"
-vstack_vaapi_filter_deps="vaapi_1"
-xstack_vaapi_filter_deps="vaapi_1"
 hstack_qsv_filter_deps="libmfx"
 hstack_qsv_filter_select="qsvvpp"
 vstack_qsv_filter_deps="libmfx"
@@ -7236,7 +7228,7 @@ enabled libdrm &&
 check_pkg_config libdrm_getfb2 libdrm "xf86drmMode.h" drmModeGetFB2

 enabled vaapi &&
-check_pkg_config vaapi "libva >= 0.35.0" "va/va.h" vaInitialize
+check_pkg_config vaapi "libva >= 1.0.0" "va/va.h" vaInitialize

 if enabled vaapi; then
 case $target_os in
@@ -7252,18 +7244,10 @@ if enabled vaapi; then
 check_pkg_config vaapi_x11 "libva-x11" "va/va_x11.h" vaGetDisplay
 fi

-check_cpp_condition vaapi_1 "va/va.h" "VA_CHECK_VERSION(1, 0, 0)"
-
-check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
-check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
 check_struct "va/va.h" "VADecPictureParameterBufferAV1" bit_depth_idx
 check_type   "va/va.h va/va_vpp.h" 
"VAProcFilterParameterBufferHDRToneMapping"
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" rotation_flags
 check_struct "va/va.h va/va_vpp.h" "VAProcPipelineCaps" blend_flags
-check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
-check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
-check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
-check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
 check_type "va/va.h va/va_enc_av1.h"  "VAEncPictureParameterBufferAV1"
 fi

--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 3/4] lavfi: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
 libavfilter/vaapi_vpp.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index ace1153a23..21d74f8112 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -672,15 +672,12 @@ int ff_vaapi_vpp_render_pictures(AVFilterContext *avctx,
 goto fail_after_render;
 }

-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
-for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) {
-vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: "
-   "%d (%s).\n", vas, vaErrorStr(vas));
-// And ignore.
-}
+for (int i = 0; i < cout && params_ids[i] != VA_INVALID_ID; i++) {
+vas = vaDestroyBuffer(ctx->hwctx->display, params_ids[i]);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to free parameter buffer: "
+   "%d (%s).\n", vas, vaErrorStr(vas));
+// And ignore.
 }
 }

--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/4] lavc: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
 libavcodec/vaapi_decode.c  | 10 ++
 libavcodec/vaapi_encode.c  | 31 +++
 libavcodec/vaapi_encode_h264.c | 18 --
 3 files changed, 13 insertions(+), 46 deletions(-)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 5665639dd7..4e8910ed25 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -191,16 +191,10 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture decode "
"issue: %d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-goto fail;
-else
-goto fail_at_end;
+goto fail;
 }

-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-ff_vaapi_decode_destroy_buffers(avctx, pic);
+ff_vaapi_decode_destroy_buffers(avctx, pic);

 err = 0;
 goto exit;
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index f54b2579ec..0e19281ed4 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -618,26 +618,17 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_ERROR, "Failed to end picture encode issue: "
"%d (%s).\n", vas, vaErrorStr(vas));
 err = AVERROR(EIO);
-// vaRenderPicture() has been called here, so we should not destroy
-// the parameter buffers unless separate destruction is required.
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
-goto fail;
-else
-goto fail_at_end;
-}
-
-if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks &
-AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) {
-for (i = 0; i < pic->nb_param_buffers; i++) {
-vas = vaDestroyBuffer(ctx->hwctx->display,
-  pic->param_buffers[i]);
-if (vas != VA_STATUS_SUCCESS) {
-av_log(avctx, AV_LOG_ERROR, "Failed to destroy "
-   "param buffer %#x: %d (%s).\n",
-   pic->param_buffers[i], vas, vaErrorStr(vas));
-// And ignore.
-}
+goto fail;
+}
+
+for (i = 0; i < pic->nb_param_buffers; i++) {
+vas = vaDestroyBuffer(ctx->hwctx->display,
+  pic->param_buffers[i]);
+if (vas != VA_STATUS_SUCCESS) {
+av_log(avctx, AV_LOG_ERROR, "Failed to destroy "
+   "param buffer %#x: %d (%s).\n",
+   pic->param_buffers[i], vas, vaErrorStr(vas));
+// And ignore.
 }
 }

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index bf51df0f51..4f4191e23b 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -106,7 +106,6 @@ typedef struct VAAPIEncodeH264Context {

 int aud_needed;
 int sei_needed;
-int sei_cbr_workaround_needed;
 } VAAPIEncodeH264Context;


@@ -271,19 +270,6 @@ static int 
vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,

 *type = VAEncPackedHeaderRawData;
 return 0;
-
-#if !CONFIG_VAAPI_1
-} else if (priv->sei_cbr_workaround_needed) {
-// Insert a zero-length header using the old SEI type.  This is
-// required to avoid triggering broken behaviour on Intel platforms
-// in CBR mode where an invalid SEI message is generated by the
-// driver and inserted into the stream.
-*data_len = 0;
-*type = VAEncPackedHeaderH264_SEI;
-priv->sei_cbr_workaround_needed = 0;
-return 0;
-#endif
-
 } else {
 return AVERROR_EOF;
 }
@@ -681,10 +667,6 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,

 if (priv->sei & SEI_IDENTIFIER && pic->encode_order == 0)
 priv->sei_needed |= SEI_IDENTIFIER;
-#if !CONFIG_VAAPI_1
-if (ctx->va_rc_mode == VA_RC_CBR)
-priv->sei_cbr_workaround_needed = 1;
-#endif

 if (priv->sei & SEI_TIMING) {
 priv->sei_pic_timing = (H264RawSEIPicTiming) {
--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/4] lavu: Remove libva 1.x support

2024-04-03 Thread Mark Thompson

libva 2.0 was released in 2017 and the 2.x versions are included in all
supported distributions nowadays.
---
 libavutil/hwcontext_vaapi.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 56d03aa4cd..bc82ab31e6 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1637,7 +1637,6 @@ static void vaapi_device_free(AVHWDeviceContext *ctx)
 av_freep(&priv);
 }

-#if CONFIG_VAAPI_1
 static void vaapi_device_log_error(void *context, const char *message)
 {
 AVHWDeviceContext *ctx = context;
@@ -1651,7 +1650,6 @@ static void vaapi_device_log_info(void *context, const 
char *message)

 av_log(ctx, AV_LOG_VERBOSE, "libva: %s", message);
 }
-#endif

 static int vaapi_device_connect(AVHWDeviceContext *ctx,
 VADisplay display)
@@ -1660,10 +1658,8 @@ static int vaapi_device_connect(AVHWDeviceContext *ctx,
 int major, minor;
 VAStatus vas;

-#if CONFIG_VAAPI_1
 vaSetErrorCallback(display, &vaapi_device_log_error, ctx);
 vaSetInfoCallback (display, &vaapi_device_log_info,  ctx);
-#endif

 hwctx->display = display;

--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/3] lavu/hwcontext_vaapi: Add a new quirk

2024-04-03 Thread Mark Thompson

On 28/03/2024 02:17, Xiang, Haihao wrote:

From: Haihao Xiang 

libva2 doesn't require a fixed surface-array any more, but some
driver/hardware combinations which rely on this are still used. To
reduce the impact to users, add a quirk for the driver/hardware
combination which supports dynamic surface pool.

Signed-off-by: Haihao Xiang 
---
  libavutil/hwcontext_vaapi.c | 7 +++
  libavutil/hwcontext_vaapi.h | 6 ++
  2 files changed, 13 insertions(+)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 56d03aa4cd..dae5dd4a11 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -390,6 +390,13 @@ static const struct {
  "Splitted-Desktop Systems VDPAU backend for VA-API",
  AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES,
  },
+#if CONFIG_VAAPI_1
+{
+"New Intel iHD",
+"Intel iHD driver for Intel(R) Gen Graphics",
+AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL,
+},
+#endif
  };
  
  static int vaapi_device_init(AVHWDeviceContext *hwdev)

diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
index 0b2e071cb3..07014fd526 100644
--- a/libavutil/hwcontext_vaapi.h
+++ b/libavutil/hwcontext_vaapi.h
@@ -58,6 +58,12 @@ enum {
   * and the results of the vaQuerySurfaceAttributes() call will be faked.
   */
  AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
+
+/**
+ * The driver (and the underlying HW) supports dynamic surface pool.
+ * The vaCreateContext() call doesn't require a fixed surface-array.
+ */
+AV_VAAPI_DRIVER_QUIRK_DYNAMIC_SURFACE_POOL = (1 << 4),
  };
  
  /**


I do not think a vendor-specific quirk like this is a reasonable answer, but I 
can see that your company is invested in making sure that your current driver 
doesn't hit this problem.

Given that, I give up on arguing for trying to preserve compatibility here.  
Let's just use dynamic pools unconditionally and see if anything breaks.

Is there any reason not to drop support for libva < 2.0 at the same time?  
(Making CONFIG_VAAPI_1 always true.)  It is of similar age to C17, which we are 
intending to require soon as well.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_hevc: Add support for Main Intra & Main 10 Intra

2024-04-02 Thread Mark Thompson

On 02/04/2024 07:55, Xiang, Haihao wrote:

On Ma, 2024-04-01 at 21:11 +0100, Mark Thompson wrote:

On 28/03/2024 02:07, Xiang, Haihao wrote:

From: Haihao Xiang 

Both Main Intra and Main 10 Intra are Rext, we may use Main and Main 10
instead for decoding. This patch fixes the error below:

[hevc @ 0x55a771b80a00] No support for codec hevc profile 4.
[hevc @ 0x55a771b80a00] Failed setup for format vaapi: hwaccel
initialisation returned error.

Signed-off-by: Haihao Xiang 
---
   libavcodec/vaapi_hevc.c | 7 +++
   1 file changed, 7 insertions(+)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 3bdd2dd1b8..83b94d1a55 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -612,6 +612,13 @@ VAProfile
ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
   av_log(avctx, AV_LOG_VERBOSE, "HEVC profile %s is found.\n",
profile->name);
   }
   
+#if VA_CHECK_VERSION(0, 37, 0)

+    if (!strcmp(profile->name, "Main Intra"))
+    return VAProfileHEVCMain;
+    else if (!strcmp(profile->name, "Main 10 Intra"))
+    return VAProfileHEVCMain10;
+#endif
+
   #if VA_CHECK_VERSION(1, 2, 0)
   if (!strcmp(profile->name, "Main 12") ||
   !strcmp(profile->name, "Main 12 Intra"))


What if high_precision_offsets_enabled_flag is set?

(That doesn't matter for the VAAPI encoder setting the profile because we
always have it as zero.)


Here use VAProfileHEVCMain or VAProfileHEVCMain10 to create VAConfig for
decoding,  avctx->profile (4) is not changed.
high_precision_offsets_enabled_flag is set in VAPictureParameterBufferHEVCRext
when avctx->profile is 4.


But Main and Main 10 profile have:

"Active SPSs for the base layer shall have ... high_precision_offsets_enabled_flag, 
... when present, equal to 0 only."

so a decoder implementing those profiles need not support it.  (It may work as 
a compatible extension as the field is there, but if it doesn't also support 
general rext cases then this is unlikely to be implemented.)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/mfenc: expose more properties of the media foundation encoder

2024-04-02 Thread Mark Thompson

On 01/04/2024 19:55, Mark Thompson wrote:

On 01/04/2024 17:25, Mark Samuelson wrote:

On Mon, Apr 1, 2024 at 10:06 AM Mark Thompson  wrote:


On 28/03/2024 12:34, Mark Samuelson wrote:

Thank you for the notes, here is a new patch that incorporates your

suggestions.  You are right, the default value of 12 for gop_size is
suprising, I didn't know about it before now.


---
   libavcodec/mf_utils.h |  5 +
   libavcodec/mfenc.c    | 33 +++--
   2 files changed, 32 insertions(+), 6 deletions(-)


Patch looks good.

I did a bit of testing with the Microsoft H.264 MFT: GOP size and

compression level work as expected, and VBV parameters seem to be doing
something sensible.


Under what conditions are you expecting global_quality ->

AVEncVideoEncodeQP to do anything, though?  When I set it alone the output
was always identical regardless of what value I set > it to.  (Including
with "-rate_control quality".)


Thanks,

- Mark




I have also had issues making the Media Foundation encoder respect that
value.  I put it in there so that I could easily test it, because I was
having issues with the existing opt_enc_quality -> AVEncCommonQuality.  I
figured it was better to leave it in so people can experiment with it.


Fair, these options are not particularly consistent between different encoder 
MFT implementations.

I will apply this patch tomorrow unless there are any more comments on it.


Applied.

(git hint for emails: write email commentary below the "---" line - everything 
above that ends up in the commit message.  I edited this out of the patch.)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_hevc: Add support for Main Intra & Main 10 Intra

2024-04-01 Thread Mark Thompson

On 28/03/2024 02:07, Xiang, Haihao wrote:

From: Haihao Xiang 

Both Main Intra and Main 10 Intra are Rext, we may use Main and Main 10
instead for decoding. This patch fixes the error below:

[hevc @ 0x55a771b80a00] No support for codec hevc profile 4.
[hevc @ 0x55a771b80a00] Failed setup for format vaapi: hwaccel
initialisation returned error.

Signed-off-by: Haihao Xiang 
---
  libavcodec/vaapi_hevc.c | 7 +++
  1 file changed, 7 insertions(+)

diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 3bdd2dd1b8..83b94d1a55 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -612,6 +612,13 @@ VAProfile 
ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)
  av_log(avctx, AV_LOG_VERBOSE, "HEVC profile %s is found.\n", 
profile->name);
  }
  
+#if VA_CHECK_VERSION(0, 37, 0)

+if (!strcmp(profile->name, "Main Intra"))
+return VAProfileHEVCMain;
+else if (!strcmp(profile->name, "Main 10 Intra"))
+return VAProfileHEVCMain10;
+#endif
+
  #if VA_CHECK_VERSION(1, 2, 0)
  if (!strcmp(profile->name, "Main 12") ||
  !strcmp(profile->name, "Main 12 Intra"))


What if high_precision_offsets_enabled_flag is set?

(That doesn't matter for the VAAPI encoder setting the profile because we 
always have it as zero.)

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 2/2] lavc/vaapi_encode_h265: Set general_*_constriaint flags with profile

2024-04-01 Thread Mark Thompson

On 20/03/2024 08:44, Wang, Fei W wrote:

On Mon, 2024-03-18 at 21:22 +, Mark Thompson wrote:

On 18/03/2024 04:21, fei.w.wang-at-intel@ffmpeg.org wrote:

From: Fei Wang 

According to Table A.2 in spec.

Signed-off-by: Fei Wang 
---
   libavcodec/vaapi_encode_h265.c | 176 +++-
-
   1 file changed, 123 insertions(+), 53 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c
b/libavcodec/vaapi_encode_h265.c
index 43755e2188..5ed317ce11 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -258,6 +258,124 @@ fail:
   return err;
   }
   
+static int vaapi_encode_h265_init_ptl(AVCodecContext *avctx)

+{
+VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
+H265RawVPS  *vps = &priv->raw_vps;
+H265RawProfileTierLevel *ptl = &vps->profile_tier_level;
+
+ptl->general_profile_space = 0;
+ptl->general_profile_idc   = avctx->profile;
+ptl->general_tier_flag = priv->tier;
+
+ptl->general_profile_compatibility_flag[ptl-

general_profile_idc] = 1;

+
+if (ptl->general_profile_compatibility_flag[1])
+ptl->general_profile_compatibility_flag[2] = 1;
+if (ptl->general_profile_compatibility_flag[3]) {
+ptl->general_profile_compatibility_flag[1] = 1;
+ptl->general_profile_compatibility_flag[2] = 1;
+}
+
+ptl->general_progressive_source_flag= 1;
+ptl->general_interlaced_source_flag = 0;
+ptl->general_non_packed_constraint_flag = 1;
+ptl->general_frame_only_constraint_flag = 1;
+
+if (avctx->profile >= 4) {
+ptl->general_intra_constraint_flag= ctx-

gop_size == 1;

+ptl->general_one_picture_only_constraint_flag = 0;
+ptl->general_lower_bit_rate_constraint_flag   = 1;
+ptl->general_max_14bit_constraint_flag= 0;
+
+switch (ctx->va_profile) {
+#if VA_CHECK_VERSION(1, 2, 0)
+case VAProfileHEVCMain12:
+// Main 12
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 0;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 1;
+ptl->general_max_420chroma_constraint_flag  = 1;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain422_10:
+// Main 4:2:2 10
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 1;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 1;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain422_12:
+// Main 4:2:2 12
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 0;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 1;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain444:
+// Main 4:4:4
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 1;
+ptl->general_max_8bit_constraint_flag   = 1;
+ptl->general_max_422chroma_constraint_flag  = 0;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain444_10:
+// Main 4:4:4 10
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 1;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 0;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain444_12:
+// Main 4:4:4 12
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 0;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 0;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+#endif
+default:
+av_log(avctx, AV_LOG_ERROR, "Unknown

Re: [FFmpeg-devel] [PATCH v1 1/7] lavc/vaapi_dec: Create VA parameters dynamically

2024-04-01 Thread Mark Thompson

On 28/03/2024 01:26, fei.w.wang-at-intel@ffmpeg.org wrote:

From: Fei Wang 

Signed-off-by: Fei Wang 
---
  libavcodec/vaapi_decode.c | 29 ++---
  libavcodec/vaapi_decode.h |  7 ++-
  2 files changed, 24 insertions(+), 12 deletions(-)


This is because the VVC code is going to want to make a lot more of these param 
buffers - can we just set a slightly larger fixed limit?

If you always need 20 buffers (say), then this has turned 1 allocation per 
picture into 3 and used more memory in the non-VVC case as well because of the 
overhead of that (but if you might variably need up to 200 then this is 
completely fair).


diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index cca94b5336..1b1972a2a9 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -38,12 +38,23 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
  {
  VAAPIDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
  VAStatus vas;
-VABufferID buffer;
  
-av_assert0(pic->nb_param_buffers + 1 <= MAX_PARAM_BUFFERS);

+av_assert0(pic->nb_param_buffers <= pic->param_allocated);
+if (pic->nb_param_buffers == pic->param_allocated) {
+pic->param_buffers =
+av_realloc_array(pic->param_buffers,
+ pic->param_allocated + 16,
+ sizeof(*pic->param_buffers));


Use av_reallocp_array() to avoid leaking the pointer on failure.


+if (!pic->param_buffers)
+return AVERROR(ENOMEM);
+
+pic->param_allocated += 16;
+}
+av_assert0(pic->nb_param_buffers + 1 <= pic->param_allocated);
  
  vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,

- type, size, 1, (void*)data, &buffer);
+ type, size, 1, (void*)data,
+ &pic->param_buffers[pic->nb_param_buffers]);
  if (vas != VA_STATUS_SUCCESS) {
  av_log(avctx, AV_LOG_ERROR, "Failed to create parameter "
 "buffer (type %d): %d (%s).\n",
@@ -51,14 +62,14 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
  return AVERROR(EIO);
  }
  
-pic->param_buffers[pic->nb_param_buffers++] = buffer;

-
  av_log(avctx, AV_LOG_DEBUG, "Param buffer (type %d, %zu bytes) "
-   "is %#x.\n", type, size, buffer);
+   "is %#x.\n", type, size, pic->param_buffers[pic->nb_param_buffers]);
+
+++pic->nb_param_buffers;
+
  return 0;
  }
  
-

  int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
VAAPIDecodePicture *pic,
const void *params_data,
@@ -215,6 +226,8 @@ fail:
  fail_at_end:
  exit:
  pic->nb_param_buffers = 0;
+pic->param_allocated  = 0;
+av_freep(&pic->param_buffers);
  pic->nb_slices= 0;
  pic->slices_allocated = 0;
  av_freep(&pic->slice_buffers);
@@ -228,6 +241,8 @@ int ff_vaapi_decode_cancel(AVCodecContext *avctx,
  ff_vaapi_decode_destroy_buffers(avctx, pic);
  
  pic->nb_param_buffers = 0;

+pic->param_allocated  = 0;
+av_freep(&pic->param_buffers);
  pic->nb_slices= 0;
  pic->slices_allocated = 0;
  av_freep(&pic->slice_buffers);
diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
index 6beda14e52..a41d7ff2ff 100644
--- a/libavcodec/vaapi_decode.h
+++ b/libavcodec/vaapi_decode.h
@@ -32,15 +32,12 @@ static inline VASurfaceID ff_vaapi_get_surface_id(AVFrame 
*pic)
  return (uintptr_t)pic->data[3];
  }
  
-enum {

-MAX_PARAM_BUFFERS = 16,
-};
-
  typedef struct VAAPIDecodePicture {
  VASurfaceID   output_surface;
  
  intnb_param_buffers;

-VABufferIDparam_buffers[MAX_PARAM_BUFFERS];
+VABufferID   *param_buffers;


Previously the array was zeroed at allocation but now it isn't.  Can you 
confirm that that isn't a problem?


+int   param_allocated;


Maybe "nb_param_buffers_allocated" would be clearer.

  
  intnb_slices;

  VABufferID   *slice_buffers;


Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] [v4] avcodec/vaapi_encode: add customized surface alignment

2024-04-01 Thread Mark Thompson

On 27/03/2024 11:14, Araz wrote:

On Fri, Mar 22, 2024 at 11:35 AM Anton Khirnov  wrote:
Why this unnecessary complication? Just use two ints, or two uint8_t's
if you really need to save space, though that also seems unncessary as
this struct is allocated rarely and usually does not live long.


https://github.com/intel/libva/pull/794
The alignment range for log2_size of 4bit is in range of
[2**0, 2**15] = [1, 32768] this is large enough, or other way is to
directly use the alignment value, however I would want it to be in
powers of 2 and not any number, to force this condition, the common
way is to use log2_size(), which is using less bits and forcing
the alignment to be in powers of 2.


It is not necessary to copy exactly the same field layout.

Are you sure that there is never a meaningful non-power-of-two-bytes case?

Given that this is defining new public API to libavutil we don't want to be 
artificially constrained to precisely what happens to be needed in this case.


On Sun, Mar 24, 2024 at 5:38 PM Mark Thompson  wrote:
What other users do you have in mind for this?  (Are you expecting

hwupload to use it as well, say?)


If this is only used in VAAPI encode then I would suggest putting the

query there rather than adding new library API for it.


Also agree with Anton that this form is unnecessarily confusing - just

make it a normal field, don't pack it like this.  (And possibly drop the
log2 as well?  That doesn't seem like it adds anything useful.)

The limitation is for AMD HW, and it is not limited to VAAPI, and for other
HW encoding protocols this limitation also exists.


Does that mean we need this in hwupload and other similar surface-creation 
places or not?

If this is only inside the VAAPI encoder for reconstructed frames then it 
doesn't seem useful to push the information into the public API.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode_av1: Set roi_quant_range

2024-04-01 Thread Mark Thompson

On 01/04/2024 19:00, David Rosca wrote:

---
  libavcodec/vaapi_encode_av1.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c
index a46b882ab9..02a31b894d 100644
--- a/libavcodec/vaapi_encode_av1.c
+++ b/libavcodec/vaapi_encode_av1.c
@@ -155,6 +155,8 @@ static av_cold int 
vaapi_encode_av1_configure(AVCodecContext *avctx)
  priv->q_idx_idr = priv->q_idx_p = priv->q_idx_b = 128;
  }
  
+ctx->roi_quant_range = AV1_MAX_QUANT;

+
  return 0;
  }
  


Huh, that was missed in the original AV1 encode patch.  Will apply.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/mfenc: expose more properties of the media foundation encoder

2024-04-01 Thread Mark Thompson

On 01/04/2024 17:25, Mark Samuelson wrote:

On Mon, Apr 1, 2024 at 10:06 AM Mark Thompson  wrote:


On 28/03/2024 12:34, Mark Samuelson wrote:

Thank you for the notes, here is a new patch that incorporates your

suggestions.  You are right, the default value of 12 for gop_size is
suprising, I didn't know about it before now.


---
   libavcodec/mf_utils.h |  5 +
   libavcodec/mfenc.c| 33 +++--
   2 files changed, 32 insertions(+), 6 deletions(-)


Patch looks good.

I did a bit of testing with the Microsoft H.264 MFT: GOP size and

compression level work as expected, and VBV parameters seem to be doing
something sensible.


Under what conditions are you expecting global_quality ->

AVEncVideoEncodeQP to do anything, though?  When I set it alone the output
was always identical regardless of what value I set > it to.  (Including
with "-rate_control quality".)


Thanks,

- Mark




I have also had issues making the Media Foundation encoder respect that
value.  I put it in there so that I could easily test it, because I was
having issues with the existing opt_enc_quality -> AVEncCommonQuality.  I
figured it was better to leave it in so people can experiment with it.


Fair, these options are not particularly consistent between different encoder 
MFT implementations.

I will apply this patch tomorrow unless there are any more comments on it.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/mfenc: expose more properties of the media foundation encoder

2024-04-01 Thread Mark Thompson

On 28/03/2024 12:34, Mark Samuelson wrote:

Thank you for the notes, here is a new patch that incorporates your 
suggestions.  You are right, the default value of 12 for gop_size is suprising, 
I didn't know about it before now.

---
  libavcodec/mf_utils.h |  5 +
  libavcodec/mfenc.c| 33 +++--
  2 files changed, 32 insertions(+), 6 deletions(-)


Patch looks good.

I did a bit of testing with the Microsoft H.264 MFT: GOP size and compression 
level work as expected, and VBV parameters seem to be doing something sensible.

Under what conditions are you expecting global_quality -> AVEncVideoEncodeQP to do 
anything, though?  When I set it alone the output was always identical regardless of what 
value I set it to.  (Including with "-rate_control quality".)

Thanks,

- Mark


diff --git a/libavcodec/mf_utils.h b/libavcodec/mf_utils.h
index aebfb9ad21..387c005f38 100644
--- a/libavcodec/mf_utils.h
+++ b/libavcodec/mf_utils.h
@@ -97,6 +97,11 @@ DEFINE_GUID(ff_CODECAPI_AVEncH264CABACEnable,0xee6cad62, 
0xd305, 0x4248, 0xa
  DEFINE_GUID(ff_CODECAPI_AVEncVideoForceKeyFrame, 0x398c1b98, 0x8353, 0x475a, 
0x9e, 0xf2, 0x8f, 0x26, 0x5d, 0x26, 0x3, 0x45);
  DEFINE_GUID(ff_CODECAPI_AVEncMPVDefaultBPictureCount, 0x8d390aac, 0xdc5c, 
0x4200, 0xb5, 0x7f, 0x81, 0x4d, 0x04, 0xba, 0xba, 0xb2);
  DEFINE_GUID(ff_CODECAPI_AVScenarioInfo, 
0xb28a6e64,0x3ff9,0x446a,0x8a,0x4b,0x0d,0x7a,0x53,0x41,0x32,0x36);
+DEFINE_GUID(ff_CODECAPI_AVEncCommonBufferSize, 0x0db96574, 0xb6a4, 0x4c8b, 
0x81, 0x06, 0x37, 0x73, 0xde, 0x03, 0x10, 0xcd);
+DEFINE_GUID(ff_CODECAPI_AVEncCommonMaxBitRate, 0x9651eae4, 0x39b9, 0x4ebf, 
0x85, 0xef, 0xd7, 0xf4, 0x44, 0xec, 0x74, 0x65);
+DEFINE_GUID(ff_CODECAPI_AVEncCommonQualityVsSpeed, 0x98332df8, 0x03cd, 0x476b, 
0x89, 0xfa, 0x3f, 0x9e, 0x44, 0x2d, 0xec, 0x9f);
+DEFINE_GUID(ff_CODECAPI_AVEncMPVGOPSize, 0x95f31b26, 0x95a4, 0x41aa, 0x93, 
0x03, 0x24, 0x6a, 0x7f, 0xc6, 0xee, 0xf1);
+DEFINE_GUID(ff_CODECAPI_AVEncVideoEncodeQP, 0x2cb5696b, 0x23fb, 0x4ce1, 0xa0, 
0xf9, 0xef, 0x5b, 0x90, 0xfd, 0x55, 0xca);
  
  DEFINE_GUID(ff_MF_SA_D3D11_BINDFLAGS, 0xeacf97ad, 0x065c, 0x4408, 0xbe, 0xe3, 0xfd, 0xcb, 0xfd, 0x12, 0x8b, 0xe2);

  DEFINE_GUID(ff_MF_SA_D3D11_USAGE, 0xe85fe442, 0x2ca3, 0x486e, 0xa9, 0xc7, 
0x10, 0x9d, 0xda, 0x60, 0x98, 0x80);
diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 9225692c51..cad531bd7d 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -695,6 +695,21 @@ FF_ENABLE_DEPRECATION_WARNINGS
  if (c->opt_enc_quality >= 0)
  ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonQuality, 
FF_VAL_VT_UI4(c->opt_enc_quality));
  
+if (avctx->rc_max_rate > 0)

+ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonMaxBitRate, 
FF_VAL_VT_UI4(avctx->rc_max_rate));
+
+if (avctx->gop_size > 0)
+ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncMPVGOPSize, 
FF_VAL_VT_UI4(avctx->gop_size));
+
+if(avctx->rc_buffer_size > 0)
+ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonBufferSize, 
FF_VAL_VT_UI4(avctx->rc_buffer_size));
+
+if(avctx->compression_level >= 0)
+ICodecAPI_SetValue(c->codec_api, 
&ff_CODECAPI_AVEncCommonQualityVsSpeed, FF_VAL_VT_UI4(avctx->compression_level));
+
+if(avctx->global_quality > 0)
+ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncVideoEncodeQP, 
FF_VAL_VT_UI4(avctx->global_quality ));
+
  // Always set the number of b-frames. Qualcomm's HEVC encoder on SD835
  // defaults this to 1, and that setting is buggy with many of the
  // rate control modes. (0 or 2 b-frames works fine with most rate
@@ -1223,7 +1238,7 @@ static int mf_init(AVCodecContext *avctx)
  
  #define OFFSET(x) offsetof(MFContext, x)
  
-#define MF_ENCODER(MEDIATYPE, NAME, ID, OPTS, FMTS, CAPS) \

+#define MF_ENCODER(MEDIATYPE, NAME, ID, OPTS, FMTS, CAPS, DEFAULTS) \
  static const AVClass ff_ ## NAME ## _mf_encoder_class = { 
 \
  .class_name = #NAME "_mf",
 \
  .item_name  = av_default_item_name,   
 \
@@ -1243,6 +1258,7 @@ static int mf_init(AVCodecContext *avctx)
  FMTS  
 \
  CAPS  
 \
  .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,  
 \
+   .defaults   = DEFAULTS, 
   \
  };
  
  #define AFMTS \

@@ -1252,9 +1268,9 @@ static int mf_init(AVCodecContext *avctx)
  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID |  
 \
AV_CODEC_CAP_DR1 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE,
  
-MF_ENCODER(AUDIO, aac, AAC, NULL, AFMTS, ACAPS);

-MF_ENCODER(AUDIO, ac3, AC3, NULL, AFMTS, ACAPS);
-MF_ENCODER(AUDIO, mp3,

Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: fix the problem of memcmp losing effectiveness

2024-03-29 Thread Mark Thompson

On 29/03/2024 15:58, Andreas Rheinhardt wrote:

Mark Thompson:

On 29/03/2024 14:00, Andreas Rheinhardt wrote:

James Almer:

On 3/29/2024 10:10 AM, Mark Thompson wrote:

On 28/03/2024 13:15, tong1.wu-at-intel@ffmpeg.org wrote:

From: Tong Wu 

HEVCHdrParams* receives a pointer which points to a dynamically
allocated memory block. It causes the memcmp always returning 1.
Add a function to do the comparision. A condition is also added to
avoid malloc(0).

Signed-off-by: Tong Wu 
---
    libavcodec/hevc_ps.c | 20 
    libavcodec/hevc_ps.h |  4 +++-
    2 files changed, 19 insertions(+), 5 deletions(-)


It doesn't seem like this method works at all, even before the recent
change with the pointer.

Structs can contain arbitrary padding, and any write to the struct
makes the padding unspecified.  memcmp() is therefore never valid as a
method of comparing after writing some fields, as done here.  (It
could only be valid if the structs compared were made by memcpy() with
no fields written directly.)


The struct is zero allocated, so shouldn't the padding be exactly the
same for two equal VPSs after parsing?



In practice it is (and the current code already relied on this); yet as
has already been said padding bytes take unspecified values at any store
(to any member). In practice, if the compiler uses instructions that
clobber the padding, the padding in both structs is clobbered in the
same way.


This seems like a strong assumption beyond that of the C specification
which needs to be documented.

Are you expecting that there is no case where ABI-undefined top bits of
registers can leak into the padding fields, or that all functions called
here will necessarily set those top bits to the same values, or
something else?



Yes, I am expecting that. That is also what the code already relied on
before the addition of the allocated field and there have been no
reports that this caused issues.


Huh.  Having just experimented a bit I find myself surprised by the lengths 
x86-64 gcc goes to with weird unaligned accesses to avoid this (e.g. to write 
to aligned uint8_t a[31] it may do aligned 16-byte write to a and unaligned 
16-byte write to a+15, avoiding touching the padding for no clear reason).

Are you aware of any documentation from gcc or llvm about on what they 
guarantee here?


This does not change that I consider it crazy to remove the parameter
sets referencing a parameter set that is removed.


I agree, having now read the code more.  My comment was purely driven by 
observing the use of memcmp() on structs (an operation well-known to be very 
difficult to use in standard C), not by looking carefully at the rest of the 
code involved.

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: fix the problem of memcmp losing effectiveness

2024-03-29 Thread Mark Thompson

On 29/03/2024 14:00, Andreas Rheinhardt wrote:

James Almer:

On 3/29/2024 10:10 AM, Mark Thompson wrote:

On 28/03/2024 13:15, tong1.wu-at-intel@ffmpeg.org wrote:

From: Tong Wu 

HEVCHdrParams* receives a pointer which points to a dynamically
allocated memory block. It causes the memcmp always returning 1.
Add a function to do the comparision. A condition is also added to
avoid malloc(0).

Signed-off-by: Tong Wu 
---
   libavcodec/hevc_ps.c | 20 
   libavcodec/hevc_ps.h |  4 +++-
   2 files changed, 19 insertions(+), 5 deletions(-)


It doesn't seem like this method works at all, even before the recent
change with the pointer.

Structs can contain arbitrary padding, and any write to the struct
makes the padding unspecified.  memcmp() is therefore never valid as a
method of comparing after writing some fields, as done here.  (It
could only be valid if the structs compared were made by memcpy() with
no fields written directly.)


The struct is zero allocated, so shouldn't the padding be exactly the
same for two equal VPSs after parsing?



In practice it is (and the current code already relied on this); yet as
has already been said padding bytes take unspecified values at any store
(to any member). In practice, if the compiler uses instructions that
clobber the padding, the padding in both structs is clobbered in the
same way.


This seems like a strong assumption beyond that of the C specification which 
needs to be documented.

Are you expecting that there is no case where ABI-undefined top bits of 
registers can leak into the padding fields, or that all functions called here 
will necessarily set those top bits to the same values, or something else?

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: fix the problem of memcmp losing effectiveness

2024-03-29 Thread Mark Thompson

On 28/03/2024 13:15, tong1.wu-at-intel@ffmpeg.org wrote:

From: Tong Wu 

HEVCHdrParams* receives a pointer which points to a dynamically
allocated memory block. It causes the memcmp always returning 1.
Add a function to do the comparision. A condition is also added to
avoid malloc(0).

Signed-off-by: Tong Wu 
---
  libavcodec/hevc_ps.c | 20 
  libavcodec/hevc_ps.h |  4 +++-
  2 files changed, 19 insertions(+), 5 deletions(-)


It doesn't seem like this method works at all, even before the recent change 
with the pointer.

Structs can contain arbitrary padding, and any write to the struct makes the 
padding unspecified.  memcmp() is therefore never valid as a method of 
comparing after writing some fields, as done here.  (It could only be valid if 
the structs compared were made by memcpy() with no fields written directly.)

The problem is mostly harmless because the nondeterministic replacement of 
structs which we were expecting to be equivalent doesn't actually change 
anything, so why don't we just remove the comparison and always replace?

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avcodec/mfenc: expose more properties of the media foundation encoder

2024-03-26 Thread Mark Thompson

On 26/03/2024 19:25, Mark Samuelson wrote:

---
  libavcodec/mf_utils.h |  5 +
  libavcodec/mfenc.c| 19 +++
  2 files changed, 24 insertions(+)


This seems like a good idea.


diff --git a/libavcodec/mf_utils.h b/libavcodec/mf_utils.h
index aebfb9ad21..387c005f38 100644
--- a/libavcodec/mf_utils.h
+++ b/libavcodec/mf_utils.h
@@ -97,6 +97,11 @@ DEFINE_GUID(ff_CODECAPI_AVEncH264CABACEnable,0xee6cad62, 
0xd305, 0x4248, 0xa
  DEFINE_GUID(ff_CODECAPI_AVEncVideoForceKeyFrame, 0x398c1b98, 0x8353, 0x475a, 
0x9e, 0xf2, 0x8f, 0x26, 0x5d, 0x26, 0x3, 0x45);
  DEFINE_GUID(ff_CODECAPI_AVEncMPVDefaultBPictureCount, 0x8d390aac, 0xdc5c, 
0x4200, 0xb5, 0x7f, 0x81, 0x4d, 0x04, 0xba, 0xba, 0xb2);
  DEFINE_GUID(ff_CODECAPI_AVScenarioInfo, 
0xb28a6e64,0x3ff9,0x446a,0x8a,0x4b,0x0d,0x7a,0x53,0x41,0x32,0x36);
+DEFINE_GUID(ff_CODECAPI_AVEncCommonBufferSize, 0x0db96574, 0xb6a4, 0x4c8b, 
0x81, 0x06, 0x37, 0x73, 0xde, 0x03, 0x10, 0xcd);
+DEFINE_GUID(ff_CODECAPI_AVEncCommonMaxBitRate, 0x9651eae4, 0x39b9, 0x4ebf, 
0x85, 0xef, 0xd7, 0xf4, 0x44, 0xec, 0x74, 0x65);
+DEFINE_GUID(ff_CODECAPI_AVEncCommonQualityVsSpeed, 0x98332df8, 0x03cd, 0x476b, 
0x89, 0xfa, 0x3f, 0x9e, 0x44, 0x2d, 0xec, 0x9f);
+DEFINE_GUID(ff_CODECAPI_AVEncMPVGOPSize, 0x95f31b26, 0x95a4, 0x41aa, 0x93, 
0x03, 0x24, 0x6a, 0x7f, 0xc6, 0xee, 0xf1);
+DEFINE_GUID(ff_CODECAPI_AVEncVideoEncodeQP, 0x2cb5696b, 0x23fb, 0x4ce1, 0xa0, 
0xf9, 0xef, 0x5b, 0x90, 0xfd, 0x55, 0xca);
  
  DEFINE_GUID(ff_MF_SA_D3D11_BINDFLAGS, 0xeacf97ad, 0x065c, 0x4408, 0xbe, 0xe3, 0xfd, 0xcb, 0xfd, 0x12, 0x8b, 0xe2);

  DEFINE_GUID(ff_MF_SA_D3D11_USAGE, 0xe85fe442, 0x2ca3, 0x486e, 0xa9, 0xc7, 
0x10, 0x9d, 0xda, 0x60, 0x98, 0x80);
diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 9225692c51..36f64a93b8 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -54,6 +54,8 @@ typedef struct MFContext {
  int opt_enc_quality;
  int opt_enc_scenario;
  int opt_enc_hw;
+int opt_enc_bufferSize;
+int opt_enc_encodeQP;
  } MFContext;
  
  static int mf_choose_output_type(AVCodecContext *avctx);

@@ -695,6 +697,21 @@ FF_ENABLE_DEPRECATION_WARNINGS
  if (c->opt_enc_quality >= 0)
  ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonQuality, 
FF_VAL_VT_UI4(c->opt_enc_quality));
  
+if (avctx->rc_max_rate > 0)

+ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonMaxBitRate, 
FF_VAL_VT_UI4(avctx->rc_max_rate));
+
+if (avctx->gop_size > 0)
+ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncMPVGOPSize, 
FF_VAL_VT_UI4(avctx->gop_size));


AVCodecContext.gop_size has a surprise default value of 12, which trips this 
up.  Suggest adding an FFCodecDefault section so that your new option works as 
a user might expect.


+
+if(c->opt_enc_bufferSize > 0)
+ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncCommonBufferSize, 
FF_VAL_VT_UI4(c->opt_enc_bufferSize));


For VBV/HRD buffer size use AVCodecContext.rc_buffer_size (but be careful with 
the units!).


+
+if(avctx->compression_level >= 0)
+ICodecAPI_SetValue(c->codec_api, 
&ff_CODECAPI_AVEncCommonQualityVsSpeed, FF_VAL_VT_UI4(avctx->compression_level));
+
+if(c->opt_enc_encodeQP > 15)
+ICodecAPI_SetValue(c->codec_api, &ff_CODECAPI_AVEncVideoEncodeQP, 
FF_VAL_VT_UI4(c->opt_enc_encodeQP));


Where has 15 come from?  Ideally don't constrain the range unless there is some 
specific reason to do so.

Can you use AVCodecContext.global_quality to avoid adding an ad-hoc option?


+
  // Always set the number of b-frames. Qualcomm's HEVC encoder on SD835
  // defaults this to 1, and that setting is buggy with many of the
  // rate control modes. (0 or 2 b-frames works fine with most rate
@@ -1280,6 +1297,8 @@ static const AVOption venc_opts[] = {
  
  {"quality",   "Quality", OFFSET(opt_enc_quality), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 100, VE},

  {"hw_encoding",   "Force hardware encoding", OFFSET(opt_enc_hw), 
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE},
+{"buffer_size", "BufferSize", OFFSET(opt_enc_bufferSize), AV_OPT_TYPE_INT, 
{.i64 = 0}, 0, INT_MAX, VE},
+{"encodeQP", "QualityQP", OFFSET(opt_enc_encodeQP), AV_OPT_TYPE_INT, {.i64 
= 15}, 15, 51, VE},
  {NULL}
  };
  


Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 2/2] lavc/get_buffer: Add a warning on failed allocation from a fixed pool

2024-03-25 Thread Mark Thompson

On 25/03/2024 07:35, Xiang, Haihao wrote:

On Di, 2024-03-19 at 22:52 +, Mark Thompson wrote:

On 19/03/2024 04:16, Xiang, Haihao wrote:

On Ma, 2024-03-18 at 21:33 +, Mark Thompson wrote:

On 18/03/2024 05:53, Xiang, Haihao wrote:

On So, 2024-03-17 at 20:51 +, Mark Thompson wrote:

For hardware cases where we are forced to have a fixed pool of frames
allocated up-front (such as array textures on decoder output), suggest
a possible workaround to the user if an allocation fails because the
pool is exhausted.
---
Perhaps helpful; any thoughts?

The warning comes out before any errors, looking like:

[mpeg2video @ 0x560ff51b4600] Failed to allocate a vaapi/nv12 frame
from a
fixed pool of hardware frames.
[mpeg2video @ 0x560ff51b4600] Consider setting extra_hw_frames to a
larger
value (currently set to 8, giving a pool size of 14).
[mpeg2video @ 0x560ff51b4600] get_buffer() failed
[vist#0:0/mpeg2video @ 0x560ff5199840] [dec:mpeg2video @
0x560ff51b3b40]
Error
submitting packet to decoder: Operation not permitted


I'm OK to print such warning so user may know how to work around it. But
now
many cases are impacted by this error
(e.g. https://trac.ffmpeg.org/ticket/10856
), I think it is a regression to user. I still prefer to use a dynamic
buffer
pool instead fixed frame pool to avoid such error when the dynamic
buffer
pool
can work.


How would we implement this on D3D11 or D3D12?


I understand not all can support dynamic frame pool, your patch is useful
for
decoders using fixed pool. But for driver which doesn't require array
textures,
I think we'd be better to use dynamic frame pool instead so user needn't
worry
about frame allocation. For example, we may use dynamic frame pool for vaapi
with iHD driver, what do you think about adding a quirk to enable dynamic
frame
pool for special drivers ?


I think we should come to a conclusion on what the generic code for this case
should be and then consider whether any special cases are needed.

When compared to the state right now, I agree with you that just switching
VAAPI to always be dynamic would probably be better just to avoid the nasty
failures, but given that we need to improve the situation for cases (like
D3D11) where we don't have an ad-hoc workaround we should be comparing to
whatever that concludes rather than the broken state right now.


Hi Mark,

I agree with you. Will you push this patch ? We may switch to dynamic frame pool
for vaapi cases later after pushing your patch.


Ok, pushed.

Thoughts:

* Passthrough filter chains can have the two queues worth of frames stored 
(when e.g. only editing metadata).
  * Possibly fixable by just doubling the extra frames added?  That seems very 
clumsy.

* Filters have no idea how big to make a pool when it is fixed.
  * lavfi would need negotiation backwards through the whole graph to make this 
work.

* Encoders have no way to signal that they want to hold on to more frames.
  * New API needed?
  * Without negotiation in lavfi it would be hard to work out in ffmpeg /which/ 
pool to increase the size of in the presence of nontrivial filter graphs, 
though.

* V4L2 M2M decode does not use hwcontext, but suffers from the same problems 
with a fixed pool.
  * Not updated since e0da916, probably broken by it in some cases.  (Does warn with the 
ad-hoc workaround option "num_capture_buffers".)
  * Does anyone ever use this in the ffmpeg utility?

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] [v4] avcodec/vaapi_encode: add customized surface alignment

2024-03-24 Thread Mark Thompson

On 21/03/2024 17:02, Araz Iusubov wrote:

This commit fixes issues with AMD HEVC encoding.
By default AMD hevc encoder asks for the alignment 64x16, while FFMPEG VAAPI 
has 16x16.
Adding support for customized surface size from VASurfaceAttribAlignmentSize in 
VAAPI version 1.21.0

Signed-off-by: Araz Iusubov 
---
  libavcodec/vaapi_encode.c   | 11 +++
  libavutil/hwcontext.h   |  7 +++
  libavutil/hwcontext_vaapi.c |  5 +
  3 files changed, 23 insertions(+)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 940f0678a5..2a74db23b1 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -2711,6 +2711,17 @@ static av_cold int 
vaapi_encode_create_recon_frames(AVCodecContext *avctx)
  av_log(avctx, AV_LOG_DEBUG, "Using %s as format of "
 "reconstructed frames.\n", av_get_pix_fmt_name(recon_format));
  
+if (constraints->log2_alignment) {

+ctx->surface_width = FFALIGN(avctx->width,
+  1 << (constraints->log2_alignment & 0xf));
+ctx->surface_height = FFALIGN(avctx->height,
+  1 << ((constraints->log2_alignment & 0xf0) >> 
4));
+av_log(avctx, AV_LOG_VERBOSE, "Using customized alignment size "
+"[%dx%d].\n",
+(1 << (constraints->log2_alignment & 0xf)),
+(1 << ((constraints->log2_alignment & 0xf0) >> 4)));
+}
+
  if (ctx->surface_width  < constraints->min_width  ||
  ctx->surface_height < constraints->min_height ||
  ctx->surface_width  > constraints->max_width ||
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index bac30debae..1eb56aff78 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -465,6 +465,13 @@ typedef struct AVHWFramesConstraints {
   */
  int max_width;
  int max_height;
+
+/**
+ * The frame width/height log2 alignment when available
+ * the lower 4 bits, width; another 4 bits, height
+ * (Zero is not applied, use the default value)
+ */
+int log2_alignment;


What other users do you have in mind for this?  (Are you expecting hwupload to 
use it as well, say?)

If this is only used in VAAPI encode then I would suggest putting the query 
there rather than adding new library API for it.

Also agree with Anton that this form is unnecessarily confusing - just make it 
a normal field, don't pack it like this.  (And possibly drop the log2 as well?  
That doesn't seem like it adds anything useful.)


  } AVHWFramesConstraints;
  
  /**

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 56d03aa4cd..6cda0fd811 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -294,6 +294,11 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext 
*hwdev,
  case VASurfaceAttribMaxHeight:
  constraints->max_height = attr_list[i].value.value.i;
  break;
+#if VA_CHECK_VERSION(1, 21, 0)
+case VASurfaceAttribAlignmentSize:
+constraints->log2_alignment = attr_list[i].value.value.i;
+break;
+#endif
  }
  }
  if (pix_fmt_count == 0) {


Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 2/2] lavc/vulkan_av1: port to the new stable API

2024-03-19 Thread Mark Thompson

On 18/03/2024 05:33, Lynne wrote:

Mar 17, 2024, 16:36 by s...@jkqxz.net:


On 13/03/2024 16:38, Lynne wrote:


Tested by multiple users on multiple operating systems,
driver implementations and test samples to work.

Co-Authored-by: Dave Airlie 

 From e2d31951f46fcc10e1263b8603e486e111e9578c Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Fri, 19 Jan 2024 10:49:02 +1000
Subject: [PATCH v3 2/2] lavc/vulkan_av1: port to the new stable API

Co-Authored-by: Dave Airlie 
---
  configure |   4 +-
  libavcodec/Makefile   |   5 +-
  libavcodec/av1.h  |   2 +
  libavcodec/vulkan_av1.c   | 502 ++
  libavcodec/vulkan_decode.c|  31 +-
  libavcodec/vulkan_decode.h|   2 +-
  libavcodec/vulkan_video.h |   2 -
  .../vulkan_video_codec_av1std_decode_mesa.h   |  36 --
  libavcodec/vulkan_video_codec_av1std_mesa.h   | 403 --
  libavutil/hwcontext_vulkan.c  |   2 +-
  libavutil/vulkan_functions.h  |   2 +-
  libavutil/vulkan_loader.h |   2 +-
  12 files changed, 300 insertions(+), 693 deletions(-)
  delete mode 100644 libavcodec/vulkan_video_codec_av1std_decode_mesa.h
  delete mode 100644 libavcodec/vulkan_video_codec_av1std_mesa.h

diff --git a/configure b/configure
index 05f8283af9..b07a742a74 100755
--- a/configure
+++ b/configure
@@ -7229,8 +7229,8 @@ enabled vdpau &&
  check_lib vdpau_x11 "vdpau/vdpau.h vdpau/vdpau_x11.h" vdp_device_create_x11 
-lvdpau -lX11

  if enabled vulkan; then
-check_pkg_config_header_only vulkan "vulkan >= 1.3.255" "vulkan/vulkan.h" 
"defined VK_VERSION_1_3" ||
-check_cpp_condition vulkan "vulkan/vulkan.h" "defined(VK_VERSION_1_4) || 
(defined(VK_VERSION_1_3) && VK_HEADER_VERSION >= 255)"
+check_pkg_config_header_only vulkan "vulkan >= 1.3.277" "vulkan/vulkan.h" 
"defined VK_VERSION_1_3" ||
+check_cpp_condition vulkan "vulkan/vulkan.h" "defined(VK_VERSION_1_4) || 
(defined(VK_VERSION_1_3) && VK_HEADER_VERSION >= 277)"



This bumping the requirement to the latest version needs to stop at some point. 
 Vulkan is not an experimental thing any more, it should be usable in released 
distributions.



The headers are a build-time dep that anyone can copy over without
installing.
Do you insist on making this optional? I'd rather not quite start
ifdeffing code, but if you think so, I will.


Ok for now, but we really should make this better soon so that normal people 
will get Vulkan support without a special effort to install the latest headers.


  if disabled vulkan; then
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 708434ac76..c552f034b7 100644
...
diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index 5afd5353cc..dc71ecf1fa 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -26,7 +26,7 @@
  const FFVulkanDecodeDescriptor ff_vk_dec_av1_desc = {
  .codec_id = AV_CODEC_ID_AV1,
  .decode_extension = FF_VK_EXT_VIDEO_DECODE_AV1,
-.decode_op= 0x0100, /* TODO fix this */
+.decode_op= VK_VIDEO_CODEC_OPERATION_DECODE_AV1_BIT_KHR,
  .ext_props = {
  .extensionName = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME,
  .specVersion   = VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION,
@@ -36,22 +36,34 @@ const FFVulkanDecodeDescriptor ff_vk_dec_av1_desc = {
  typedef struct AV1VulkanDecodePicture {
  FFVulkanDecodePicture   vp;

-/* Workaround for a spec issue.
- *Can be removed once no longer needed, and threading can be enabled. */
+/* TODO: investigate if this can be removed to make decoding completely
+ * independent. */
  FFVulkanDecodeContext  *dec;



Can you explain what the id_alloc_mask thing is doing which needs this?  (The 
32 size in particular seems suspicious.)



It tracks allocated frames to assign a unique index to them.
Indices for each frame are then given to the decoder via 
referenceNameSlotIndices.
The decoder needs to know this, as it keeps state for each frame that
may be internal and opaque to us.

Dave can explain it better.


Ok, makes sense.  Maybe add a bit more of a comment saying this, and have a 
clearer bound than the 32 - presumably AV1_NUM_REF_FRAMES?


-StdVideoAV1MESATiletiles[MAX_TILES];
-StdVideoAV1MESATileListtile_list;
-const uint32_t*tile_offsets;
+uint32_t tile_sizes[MAX_TILES];

  /* Current picture */
-VkVideoDecodeAV1DpbSlotInfoMESAvkav1_ref;
-StdVideoAV1MESAFrameHeader av1_frame_header;
-VkVideoDecodeAV1PictureInfoMESAav1_pic_info;
+StdVideoDecodeAV1ReferenceInfo std_ref;
+VkVideoDecodeAV1DpbSlotInfoKHR vkav1_ref;
+uint16_t width_in_sbs_minus1[64];
+uint16_t height_in_sbs_minus1[64];
+uint16_t mi_col_starts[64];
+uint16_t mi_row_starts[64];
+StdVideoAV1TileInfo til

Re: [FFmpeg-devel] [PATCH v3 1/2] ffmpeg: set extra_hw_frames to account for frames held in queues

2024-03-19 Thread Mark Thompson

On 18/03/2024 05:35, Xiang, Haihao wrote:

On So, 2024-03-17 at 20:49 +, Mark Thompson wrote:

Since e0da916b8f5b079a4865eef7f64863f50785463d the ffmpeg utility has
held multiple frames output by the decoder in internal queues without
telling the decoder that it is going to do so.  When the decoder has a
fixed-size pool of frames (common in some hardware APIs where the output
frames must be stored as an array texture) this could lead to the pool
being exhausted and the decoder getting stuck.  Fix this by telling the
decoder to allocate additional frames according to the queue size.
---
Rebased but otherwise unchanged since previous version.

   fftools/ffmpeg_dec.c   | 13 +
   fftools/ffmpeg_sched.c | 16 +++-
   fftools/ffmpeg_sched.h | 12 
   3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index c41c5748e5..ed411b6bf8 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -1207,6 +1207,19 @@ static int dec_open(DecoderPriv *dp, AVDictionary
**dec_opts,
   return ret;
   }

+    if (dp->dec_ctx->hw_device_ctx) {
+    // Update decoder extra_hw_frames option to account for the
+    // frames held in queues inside the ffmpeg utility.  This is
+    // called after avcodec_open2() because the user-set value of
+    // extra_hw_frames becomes valid in there, and we need to add
+    // this on top of it.
+    int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
+    if (dp->dec_ctx->extra_hw_frames >= 0)
+    dp->dec_ctx->extra_hw_frames += extra_frames;
+    else
+    dp->dec_ctx->extra_hw_frames = extra_frames;
+    }
+
   ret = check_avoptions(*dec_opts);
   if (ret < 0)
   return ret;
diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
index f739066921..ec88017e21 100644
--- a/fftools/ffmpeg_sched.c
+++ b/fftools/ffmpeg_sched.c
@@ -365,7 +365,21 @@ static int queue_alloc(ThreadQueue **ptq, unsigned
nb_streams, unsigned queue_si
   ThreadQueue *tq;
   ObjPool *op;

-    queue_size = queue_size > 0 ? queue_size : 8;
+    if (queue_size <= 0) {
+    if (type == QUEUE_FRAMES)
+    queue_size = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
+    else
+    queue_size = DEFAULT_PACKET_THREAD_QUEUE_SIZE;
+    }
+
+    if (type == QUEUE_FRAMES) {
+    // This queue length is used in the decoder code to ensure that
+    // there are enough entries in fixed-size frame pools to account
+    // for frames held in queues inside the ffmpeg utility.  If this
+    // can ever dynamically change then the corresponding decode
+    // code needs to be updated as well.
+    av_assert0(queue_size == DEFAULT_FRAME_THREAD_QUEUE_SIZE);
+    }

   op = (type == QUEUE_PACKETS) ? objpool_alloc_packets() :
  objpool_alloc_frames();
diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h
index a9190bd3d1..e51c26cec9 100644
--- a/fftools/ffmpeg_sched.h
+++ b/fftools/ffmpeg_sched.h
@@ -233,6 +233,18 @@ int sch_add_filtergraph(Scheduler *sch, unsigned
nb_inputs, unsigned nb_outputs,
    */
   int sch_add_mux(Scheduler *sch, SchThreadFunc func, int (*init)(void *),
   void *ctx, int sdp_auto, unsigned thread_queue_size);
+
+/**
+ * Default size of a packet thread queue.  For muxing this can be overridden
by
+ * the thread_queue_size option as passed to a call to sch_add_mux().
+ */
+#define DEFAULT_PACKET_THREAD_QUEUE_SIZE 8
+
+/**
+ * Default size of a frame thread queue.
+ */
+#define DEFAULT_FRAME_THREAD_QUEUE_SIZE 8
+
   /**
    * Add a muxed stream for a previously added muxer.


LGTM


Thanks.  Pushed because this is a strict improvement on what we have at the 
moment, but I still think we should be able to do better for this generic code.

The two obvious outstanding problems that I see are:

* Components can consume more than one frame and ffmpeg doesn't have any way to 
notice this; this is particularly a problem with asynchronous encoders.

* A filter graph which uses the same pool as output (say it only changes 
metadata or drops frames) ends up needing double this because there are two 
frame queues.

Ideas on how to deal with either of these in a generic way are welcome.

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 2/2] lavc/get_buffer: Add a warning on failed allocation from a fixed pool

2024-03-19 Thread Mark Thompson

On 19/03/2024 04:16, Xiang, Haihao wrote:

On Ma, 2024-03-18 at 21:33 +, Mark Thompson wrote:

On 18/03/2024 05:53, Xiang, Haihao wrote:

On So, 2024-03-17 at 20:51 +, Mark Thompson wrote:

For hardware cases where we are forced to have a fixed pool of frames
allocated up-front (such as array textures on decoder output), suggest
a possible workaround to the user if an allocation fails because the
pool is exhausted.
---
Perhaps helpful; any thoughts?

The warning comes out before any errors, looking like:

[mpeg2video @ 0x560ff51b4600] Failed to allocate a vaapi/nv12 frame from a
fixed pool of hardware frames.
[mpeg2video @ 0x560ff51b4600] Consider setting extra_hw_frames to a larger
value (currently set to 8, giving a pool size of 14).
[mpeg2video @ 0x560ff51b4600] get_buffer() failed
[vist#0:0/mpeg2video @ 0x560ff5199840] [dec:mpeg2video @ 0x560ff51b3b40]
Error
submitting packet to decoder: Operation not permitted


I'm OK to print such warning so user may know how to work around it. But now
many cases are impacted by this error
(e.g. https://trac.ffmpeg.org/ticket/10856
), I think it is a regression to user. I still prefer to use a dynamic
buffer
pool instead fixed frame pool to avoid such error when the dynamic buffer
pool
can work.


How would we implement this on D3D11 or D3D12?


I understand not all can support dynamic frame pool, your patch is useful for
decoders using fixed pool. But for driver which doesn't require array textures,
I think we'd be better to use dynamic frame pool instead so user needn't worry
about frame allocation. For example, we may use dynamic frame pool for vaapi
with iHD driver, what do you think about adding a quirk to enable dynamic frame
pool for special drivers ?


I think we should come to a conclusion on what the generic code for this case 
should be and then consider whether any special cases are needed.

When compared to the state right now, I agree with you that just switching 
VAAPI to always be dynamic would probably be better just to avoid the nasty 
failures, but given that we need to improve the situation for cases (like 
D3D11) where we don't have an ad-hoc workaround we should be comparing to 
whatever that concludes rather than the broken state right now.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 2/2] lavc/get_buffer: Add a warning on failed allocation from a fixed pool

2024-03-18 Thread Mark Thompson

On 18/03/2024 05:53, Xiang, Haihao wrote:

On So, 2024-03-17 at 20:51 +, Mark Thompson wrote:

For hardware cases where we are forced to have a fixed pool of frames
allocated up-front (such as array textures on decoder output), suggest
a possible workaround to the user if an allocation fails because the
pool is exhausted.
---
Perhaps helpful; any thoughts?

The warning comes out before any errors, looking like:

[mpeg2video @ 0x560ff51b4600] Failed to allocate a vaapi/nv12 frame from a
fixed pool of hardware frames.
[mpeg2video @ 0x560ff51b4600] Consider setting extra_hw_frames to a larger
value (currently set to 8, giving a pool size of 14).
[mpeg2video @ 0x560ff51b4600] get_buffer() failed
[vist#0:0/mpeg2video @ 0x560ff5199840] [dec:mpeg2video @ 0x560ff51b3b40] Error
submitting packet to decoder: Operation not permitted


I'm OK to print such warning so user may know how to work around it. But now
many cases are impacted by this error (e.g. https://trac.ffmpeg.org/ticket/10856
), I think it is a regression to user. I still prefer to use a dynamic buffer
pool instead fixed frame pool to avoid such error when the dynamic buffer pool
can work.


How would we implement this on D3D11 or D3D12?

A way of doing the second in particular would be very useful, because the 
current decoder only works on a subset of drivers which don't require array 
textures.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v3 2/2] lavc/vaapi_encode_h265: Set general_*_constriaint flags with profile

2024-03-18 Thread Mark Thompson

On 18/03/2024 04:21, fei.w.wang-at-intel@ffmpeg.org wrote:

From: Fei Wang 

According to Table A.2 in spec.

Signed-off-by: Fei Wang 
---
  libavcodec/vaapi_encode_h265.c | 176 +++--
  1 file changed, 123 insertions(+), 53 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index 43755e2188..5ed317ce11 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -258,6 +258,124 @@ fail:
  return err;
  }
  
+static int vaapi_encode_h265_init_ptl(AVCodecContext *avctx)

+{
+VAAPIEncodeContext  *ctx = avctx->priv_data;
+VAAPIEncodeH265Context *priv = avctx->priv_data;
+H265RawVPS  *vps = &priv->raw_vps;
+H265RawProfileTierLevel *ptl = &vps->profile_tier_level;
+
+ptl->general_profile_space = 0;
+ptl->general_profile_idc   = avctx->profile;
+ptl->general_tier_flag = priv->tier;
+
+ptl->general_profile_compatibility_flag[ptl->general_profile_idc] = 1;
+
+if (ptl->general_profile_compatibility_flag[1])
+ptl->general_profile_compatibility_flag[2] = 1;
+if (ptl->general_profile_compatibility_flag[3]) {
+ptl->general_profile_compatibility_flag[1] = 1;
+ptl->general_profile_compatibility_flag[2] = 1;
+}
+
+ptl->general_progressive_source_flag= 1;
+ptl->general_interlaced_source_flag = 0;
+ptl->general_non_packed_constraint_flag = 1;
+ptl->general_frame_only_constraint_flag = 1;
+
+if (avctx->profile >= 4) {
+ptl->general_intra_constraint_flag= ctx->gop_size == 1;
+ptl->general_one_picture_only_constraint_flag = 0;
+ptl->general_lower_bit_rate_constraint_flag   = 1;
+ptl->general_max_14bit_constraint_flag= 0;
+
+switch (ctx->va_profile) {
+#if VA_CHECK_VERSION(1, 2, 0)
+case VAProfileHEVCMain12:
+// Main 12
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 0;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 1;
+ptl->general_max_420chroma_constraint_flag  = 1;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain422_10:
+// Main 4:2:2 10
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 1;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 1;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain422_12:
+// Main 4:2:2 12
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 0;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 1;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain444:
+// Main 4:4:4
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 1;
+ptl->general_max_8bit_constraint_flag   = 1;
+ptl->general_max_422chroma_constraint_flag  = 0;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain444_10:
+// Main 4:4:4 10
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 1;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 0;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+case VAProfileHEVCMain444_12:
+// Main 4:4:4 12
+ptl->general_max_12bit_constraint_flag  = 1;
+ptl->general_max_10bit_constraint_flag  = 0;
+ptl->general_max_8bit_constraint_flag   = 0;
+ptl->general_max_422chroma_constraint_flag  = 0;
+ptl->general_max_420chroma_constraint_flag  = 0;
+ptl->general_max_monochrome_constraint_flag = 0;
+break;
+#endif
+default:
+av_log(avctx, AV_LOG_ERROR, "Unknown profile to init PTL.\n");
+return AVERROR(EINVAL);
+}
+}


Why is this an improvement over the current code which sets the constraint 
flags based on the actual content of the stream?

Note the requirement in A.3.5 for decoder support:

general_profile_idc is equal to 4 or general_profi

Re: [FFmpeg-devel] [PATCH v3 1/2] lavc/vaapi_encode_h265: Map HEVC AV REXT profile to VA REXT profile

2024-03-18 Thread Mark Thompson

On 18/03/2024 04:21, fei.w.wang-at-intel@ffmpeg.org wrote:

From: Fei Wang 

There is no Main8/10 profile defined in HEVC REXT profiles. Use Main12
which is compatible with 8/10bit.

Signed-off-by: Fei Wang 
---
  libavcodec/vaapi_encode_h265.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index c4aabbf5ed..43755e2188 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -1305,12 +1305,12 @@ static av_cold int 
vaapi_encode_h265_configure(AVCodecContext *avctx)
  
  static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = {

  { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain   },
-{ AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain   },
  #if VA_CHECK_VERSION(0, 37, 0)
  { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
-{ AV_PROFILE_HEVC_REXT,10, 3, 1, 1, VAProfileHEVCMain10 },
  #endif
  #if VA_CHECK_VERSION(1, 2, 0)
+{ AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain12 },
+{ AV_PROFILE_HEVC_REXT,10, 3, 1, 1, VAProfileHEVCMain12 },
  { AV_PROFILE_HEVC_REXT,12, 3, 1, 1, VAProfileHEVCMain12 },
  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 0, VAProfileHEVCMain422_10 },
  { AV_PROFILE_HEVC_REXT,10, 3, 1, 0, VAProfileHEVCMain422_10 },


What are you actually trying to do here?

See 61aea246627787e80edd1f2eae01df63688dda68: these allow support for the Main 
Intra and Main 10 Intra profiles using Main and Main 10 encoders respectively 
(since they need not use any additional rext features).

Changing this to require a Main 12 encoder and marking the streams as requiring 
such a Main 12 decoder to decode when they don't does not seem helpful.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/2] lavc/get_buffer: Add a warning on failed allocation from a fixed pool

2024-03-17 Thread Mark Thompson

For hardware cases where we are forced to have a fixed pool of frames
allocated up-front (such as array textures on decoder output), suggest
a possible workaround to the user if an allocation fails because the
pool is exhausted.
---
Perhaps helpful; any thoughts?

The warning comes out before any errors, looking like:

[mpeg2video @ 0x560ff51b4600] Failed to allocate a vaapi/nv12 frame from a 
fixed pool of hardware frames.
[mpeg2video @ 0x560ff51b4600] Consider setting extra_hw_frames to a larger 
value (currently set to 8, giving a pool size of 14).
[mpeg2video @ 0x560ff51b4600] get_buffer() failed
[vist#0:0/mpeg2video @ 0x560ff5199840] [dec:mpeg2video @ 0x560ff51b3b40] Error 
submitting packet to decoder: Operation not permitted

 libavcodec/get_buffer.c | 16 
 libavcodec/internal.h   |  6 ++
 2 files changed, 22 insertions(+)

diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c
index 46c20781af..9b35fde7c6 100644
--- a/libavcodec/get_buffer.c
+++ b/libavcodec/get_buffer.c
@@ -257,6 +257,22 @@ int avcodec_default_get_buffer2(AVCodecContext *avctx, 
AVFrame *frame, int flags

 if (avctx->hw_frames_ctx) {
 ret = av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0);
+if (ret == AVERROR(ENOMEM)) {
+AVHWFramesContext *frames_ctx =
+(AVHWFramesContext*)avctx->hw_frames_ctx->data;
+if (frames_ctx->initial_pool_size > 0 &&
+!avctx->internal->warned_on_failed_allocation_from_fixed_pool) 
{
+av_log(avctx, AV_LOG_WARNING, "Failed to allocate a %s/%s "
+   "frame from a fixed pool of hardware frames.\n",
+   av_get_pix_fmt_name(frames_ctx->format),
+   av_get_pix_fmt_name(frames_ctx->sw_format));
+av_log(avctx, AV_LOG_WARNING, "Consider setting "
+   "extra_hw_frames to a larger value "
+   "(currently set to %d, giving a pool size of %d).\n",
+   avctx->extra_hw_frames, frames_ctx->initial_pool_size);
+avctx->internal->warned_on_failed_allocation_from_fixed_pool = 
1;
+}
+}
 frame->width  = avctx->coded_width;
 frame->height = avctx->coded_height;
 return ret;
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 04f7cebdcb..64fe0122c8 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -144,6 +144,12 @@ typedef struct AVCodecInternal {
 #if CONFIG_LCMS2
 FFIccContext icc; /* used to read and write embedded ICC profiles */
 #endif
+
+/**
+ * Set when the user has been warned about a failed allocation from
+ * a fixed frame pool.
+ */
+int warned_on_failed_allocation_from_fixed_pool;
 } AVCodecInternal;

 /**
--
2.43.0
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 1/2] ffmpeg: set extra_hw_frames to account for frames held in queues

2024-03-17 Thread Mark Thompson

Since e0da916b8f5b079a4865eef7f64863f50785463d the ffmpeg utility has
held multiple frames output by the decoder in internal queues without
telling the decoder that it is going to do so.  When the decoder has a
fixed-size pool of frames (common in some hardware APIs where the output
frames must be stored as an array texture) this could lead to the pool
being exhausted and the decoder getting stuck.  Fix this by telling the
decoder to allocate additional frames according to the queue size.
---
Rebased but otherwise unchanged since previous version.

 fftools/ffmpeg_dec.c   | 13 +
 fftools/ffmpeg_sched.c | 16 +++-
 fftools/ffmpeg_sched.h | 12 
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index c41c5748e5..ed411b6bf8 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -1207,6 +1207,19 @@ static int dec_open(DecoderPriv *dp, AVDictionary 
**dec_opts,
 return ret;
 }

+if (dp->dec_ctx->hw_device_ctx) {
+// Update decoder extra_hw_frames option to account for the
+// frames held in queues inside the ffmpeg utility.  This is
+// called after avcodec_open2() because the user-set value of
+// extra_hw_frames becomes valid in there, and we need to add
+// this on top of it.
+int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
+if (dp->dec_ctx->extra_hw_frames >= 0)
+dp->dec_ctx->extra_hw_frames += extra_frames;
+else
+dp->dec_ctx->extra_hw_frames = extra_frames;
+}
+
 ret = check_avoptions(*dec_opts);
 if (ret < 0)
 return ret;
diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
index f739066921..ec88017e21 100644
--- a/fftools/ffmpeg_sched.c
+++ b/fftools/ffmpeg_sched.c
@@ -365,7 +365,21 @@ static int queue_alloc(ThreadQueue **ptq, unsigned 
nb_streams, unsigned queue_si
 ThreadQueue *tq;
 ObjPool *op;

-queue_size = queue_size > 0 ? queue_size : 8;
+if (queue_size <= 0) {
+if (type == QUEUE_FRAMES)
+queue_size = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
+else
+queue_size = DEFAULT_PACKET_THREAD_QUEUE_SIZE;
+}
+
+if (type == QUEUE_FRAMES) {
+// This queue length is used in the decoder code to ensure that
+// there are enough entries in fixed-size frame pools to account
+// for frames held in queues inside the ffmpeg utility.  If this
+// can ever dynamically change then the corresponding decode
+// code needs to be updated as well.
+av_assert0(queue_size == DEFAULT_FRAME_THREAD_QUEUE_SIZE);
+}

 op = (type == QUEUE_PACKETS) ? objpool_alloc_packets() :
objpool_alloc_frames();
diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h
index a9190bd3d1..e51c26cec9 100644
--- a/fftools/ffmpeg_sched.h
+++ b/fftools/ffmpeg_sched.h
@@ -233,6 +233,18 @@ int sch_add_filtergraph(Scheduler *sch, unsigned 
nb_inputs, unsigned nb_outputs,
  */
 int sch_add_mux(Scheduler *sch, SchThreadFunc func, int (*init)(void *),
 void *ctx, int sdp_auto, unsigned thread_queue_size);
+
+/**
+ * Default size of a packet thread queue.  For muxing this can be overridden by
+ * the thread_queue_size option as passed to a call to sch_add_mux().
+ */
+#define DEFAULT_PACKET_THREAD_QUEUE_SIZE 8
+
+/**
+ * Default size of a frame thread queue.
+ */
+#define DEFAULT_FRAME_THREAD_QUEUE_SIZE 8
+
 /**
  * Add a muxed stream for a previously added muxer.
  *
--
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] libavcodec/amfenc: Update AMF encoder options

2024-03-17 Thread Mark Thompson

On 14/03/2024 10:51, Araz Iusubov wrote:

The encoder options have been updated to the current version of the AMF.

Signed-off-by: Araz Iusubov 
---
  libavcodec/amfenc.c  |   1 +
  libavcodec/amfenc.h  |   4 +
  libavcodec/amfenc_av1.c  | 154 +-
  libavcodec/amfenc_h264.c | 155 +-
  libavcodec/amfenc_hevc.c | 158 ++-
  5 files changed, 314 insertions(+), 158 deletions(-)


This needs more explanation.  What is different about the current version and 
why does it require these changes?

The change is also mixing cosmetic changes and refactoring of some existing 
elements with addition of new options; ideally you would want to split this 
into multiple patches for each change.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


  1   2   3   4   5   6   7   8   9   10   >