Re: [FFmpeg-devel] [PATCH 5/5] avcodec/atrac9dec: Check init_get_bits8() for failure

2024-04-28 Thread Paul B Mahol
On Sun, Apr 28, 2024 at 11:31 PM Michael Niedermayer 
wrote:

> Fixes: CID1439569 Unchecked return value
> Fixes: CID1439578 Unchecked return value
>
> Sponsored-by: Sovereign Tech Fund
>

And they paid you for this low effort work!

Applause!



> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/atrac9dec.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
> index df68407af92..e375f46fd04 100644
> --- a/libavcodec/atrac9dec.c
> +++ b/libavcodec/atrac9dec.c
> @@ -802,7 +802,9 @@ static int atrac9_decode_frame(AVCodecContext *avctx,
> AVFrame *frame,
>  if (ret < 0)
>  return ret;
>
> -init_get_bits8(&gb, avpkt->data, avpkt->size);
> +ret = init_get_bits8(&gb, avpkt->data, avpkt->size);
> +if (ret < 0)
> +return ret;
>
>  for (int i = 0; i < frames; i++) {
>  for (int j = 0; j < s->block_config->count; j++) {
> @@ -922,7 +924,9 @@ static av_cold int atrac9_decode_init(AVCodecContext
> *avctx)
>  return AVERROR_INVALIDDATA;
>  }
>
> -init_get_bits8(&gb, avctx->extradata + 4, avctx->extradata_size);
> +err = init_get_bits8(&gb, avctx->extradata + 4,
> avctx->extradata_size);
> +if (err < 0)
> +return err;
>
>  if (get_bits(&gb, 8) != 0xFE) {
>  av_log(avctx, AV_LOG_ERROR, "Incorrect magic byte!\n");
> --
> 2.43.2
>
> ___
> 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 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] [RFC] 5 year plan & Inovation

2024-04-28 Thread Davy Durham

On 4/19/24 09:50, Niklas Haas wrote:

So, rather than all of the above, what I think we should do is contract
somebody to set up, manage, host and maintain a GitLab instance for us.

This would probably be the single most cost effective boost to both
community growth and innovation I can think of, as it will remove
several of the major grievances and barriers to entry with the
ML+pingspam model.

We can use a system like VLC's auto-merge bot, where any MR that has at
least one developer approval, no unresolved issues, and no activity for
N days gets *automatically* merged.

I'm sure that if we try, we can find an interested party willing to fund
this. (Maybe SPI?)


+1 from me too.  Please oh, please oh, /please/ modernize the patch 
management.  I don't know what the opposition/inability to use github is 
all about.  But gitlab should be a great improvement on the ML/patchwork 
situation.


gitlab has a hosted edition for opensource projects 
.   (Or is the 
opposition to github about trusting someone else to host it in general?)


Automated CI/CD pipelines will change your /life/ if you've never used 
them.  I was once opposed but wouldn't want to do it any other way for 
any significant project anymore.


Inline comments on MRs would be a great improvement for discussions and 
requests from maintainers, and plus it's much easier to see/drill-into 
those discussion from the blame view.


my two cents

___
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 WIP 0/9] Refactor DNN

2024-04-28 Thread Chen, Wenbin
> > On Apr 28, 2024, at 18:58, Paul B Mahol  wrote:
> >
> > Extremely low quality filters, both in source code quality and
> > performance/security and output quality should be queued for removal.

These filters cannot be removed because there are users using them.
What are your suggestions to improve them if you think they are low quality 
filters?

- Wenbin

> 
> I don’t think there is any replacement for the function provided by
> dnn_detect,
> which is very important for ROI encoding.
> 
> > ___
> > 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 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 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 13/14] avcodec/mpegvideo: Don't reset coded_block unnecessarily

2024-04-28 Thread Andreas Rheinhardt
coded_block is only used for I-frames, so it is unnecessary
to reset it in ff_clean_intra_table_entries() (which
cleans certain tables for a non-intra MB).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 74be22346d..ca6e637920 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -808,7 +808,7 @@ void ff_mpv_common_end(MpegEncContext *s)
 
 
 /**
- * Clean dc, ac, coded_block for the current non-intra MB.
+ * Clean dc, ac for the current non-intra MB.
  */
 void ff_clean_intra_table_entries(MpegEncContext *s)
 {
@@ -822,12 +822,6 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
 /* ac pred */
 memset(s->ac_val[0][xy   ], 0, 32 * sizeof(int16_t));
 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t));
-if (s->msmpeg4_version>=3) {
-s->coded_block[xy   ] =
-s->coded_block[xy + 1   ] =
-s->coded_block[xy + wrap] =
-s->coded_block[xy + 1 + wrap] = 0;
-}
 /* chroma */
 wrap = s->mb_stride;
 xy = s->mb_x + s->mb_y * wrap;
-- 
2.40.1

___
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 14/14] avcodec/mpegvideo: Only allocate cbp_table, pred_dir_table when needed

2024-04-28 Thread Andreas Rheinhardt
Namely for the MPEG-4 decoder.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index ca6e637920..2ef69a5224 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -593,13 +593,12 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
 tmp += mv_table_size;
 }
 }
-}
-
-if (s->out_format == FMT_H263) {
-/* cbp, ac_pred, pred_dir */
-if (!(s->cbp_table= av_mallocz(mb_array_size)) ||
-!(s->pred_dir_table   = av_mallocz(mb_array_size)))
-return AVERROR(ENOMEM);
+if (s->codec_id == AV_CODEC_ID_MPEG4 && !s->encoding) {
+/* cbp, pred_dir */
+if (!(s->cbp_table  = av_mallocz(mb_array_size)) ||
+!(s->pred_dir_table = av_mallocz(mb_array_size)))
+return AVERROR(ENOMEM);
+}
 }
 
 if (s->msmpeg4_version >= 3) {
-- 
2.40.1

___
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 12/14] avcodec/mpegvideo: Only allocate coded_block when needed

2024-04-28 Thread Andreas Rheinhardt
It is only needed for msmpeg4v3, wmv1, wmv2 and VC-1.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 130ccb4c97..74be22346d 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -596,11 +596,16 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
 }
 
 if (s->out_format == FMT_H263) {
-/* cbp values, cbp, ac_pred, pred_dir */
-if (!(s->coded_block_base = av_mallocz(y_size + 
(s->mb_height&1)*2*s->b8_stride)) ||
-!(s->cbp_table= av_mallocz(mb_array_size)) ||
+/* cbp, ac_pred, pred_dir */
+if (!(s->cbp_table= av_mallocz(mb_array_size)) ||
 !(s->pred_dir_table   = av_mallocz(mb_array_size)))
 return AVERROR(ENOMEM);
+}
+
+if (s->msmpeg4_version >= 3) {
+s->coded_block_base = av_mallocz(y_size + 
(s->mb_height&1)*2*s->b8_stride);
+if (!s->coded_block_base)
+return AVERROR(ENOMEM);
 s->coded_block = s->coded_block_base + s->b8_stride + 1;
 }
 
-- 
2.40.1

___
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 06/14] avcodec/mpeg12dec: Allocate dummy frames for non-I fields

2024-04-28 Thread Andreas Rheinhardt
MPEG-2 allows to pair an intra field (as first field) together
with a P-field. In this case a conformant bitstream has to satisfy
certain restrictions in order to ensure that only the I field
is used for prediction. See section 7.6.3.5 of the MPEG-2
specifications.

We do not check these restrictions; normally we simply allocate
dummy frames for reference in order to avoid checks lateron.
This happens in ff_mpv_frame_start() and therefore does not happen
for a second field. This is inconsistent. Fix this by allocating
these dummy frames for the second field, too.

This already fixes two bugs:
1. Undefined pointer arithmetic in prefetch_motion() in
mpegvideo_motion.c where it is simply presumed that the reference
frame exists.
2. Several MPEG-2 hardware accelerations rely on last_picture
being allocated for P pictures and next picture for B pictures;
e.g. VDPAU returns VDP_STATUS_INVALID_HANDLE when decoding
an I-P fields pair because the forward_reference was set incorrectly.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpeg12dec.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 21a214ef5b..9940ff898c 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1372,6 +1372,9 @@ static int mpeg_field_start(MpegEncContext *s, const 
uint8_t *buf, int buf_size)
 return ret;
 }
 }
+ret = ff_mpv_alloc_dummy_frames(s);
+if (ret < 0)
+return ret;
 
 for (int i = 0; i < 3; i++) {
 s->current_picture.f->data[i] = s->current_picture_ptr->f->data[i];
@@ -1727,7 +1730,7 @@ static int slice_decode_thread(AVCodecContext *c, void 
*arg)
  * Handle slice ends.
  * @return 1 if it seems to be the last slice
  */
-static int slice_end(AVCodecContext *avctx, AVFrame *pict)
+static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
 {
 Mpeg1Context *s1  = avctx->priv_data;
 MpegEncContext *s = &s1->mpeg_enc_ctx;
@@ -1758,14 +1761,16 @@ static int slice_end(AVCodecContext *avctx, AVFrame 
*pict)
 return ret;
 ff_print_debug_info(s, s->current_picture_ptr, pict);
 ff_mpv_export_qp_table(s, pict, s->current_picture_ptr, 
FF_MPV_QSCALE_TYPE_MPEG2);
+*got_output = 1;
 } else {
 /* latency of 1 frame for I- and P-frames */
-if (s->last_picture_ptr) {
+if (s->last_picture_ptr && !s->last_picture_ptr->dummy) {
 int ret = av_frame_ref(pict, s->last_picture_ptr->f);
 if (ret < 0)
 return ret;
 ff_print_debug_info(s, s->last_picture_ptr, pict);
 ff_mpv_export_qp_table(s, pict, s->last_picture_ptr, 
FF_MPV_QSCALE_TYPE_MPEG2);
+*got_output = 1;
 }
 }
 
@@ -2204,14 +2209,9 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame 
*picture,
 s2->er.error_count += 
s2->thread_context[i]->er.error_count;
 }
 
-ret = slice_end(avctx, picture);
+ret = slice_end(avctx, picture, got_output);
 if (ret < 0)
 return ret;
-else if (ret) {
-// FIXME: merge with the stuff in mpeg_decode_slice
-if (s2->last_picture_ptr || s2->low_delay || s2->pict_type 
== AV_PICTURE_TYPE_B)
-*got_output = 1;
-}
 }
 s2->pict_type = 0;
 
-- 
2.40.1

___
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 11/14] avcodec/msmpeg4enc: Only calculate coded_cbp when used

2024-04-28 Thread Andreas Rheinhardt
With this patch, msmpeg4v1 and msmpeg4v2 no longer use
MpegEncContext.coded_block.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/msmpeg4enc.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 119ea8f15e..282b3e958b 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -389,7 +389,6 @@ void ff_msmpeg4_encode_mb(MpegEncContext * s,
 {
 int cbp, coded_cbp, i;
 int pred_x, pred_y;
-uint8_t *coded_block;
 
 ff_msmpeg4_handle_slices(s);
 
@@ -450,20 +449,10 @@ void ff_msmpeg4_encode_mb(MpegEncContext * s,
 } else {
 /* compute cbp */
 cbp = 0;
-coded_cbp = 0;
-for (i = 0; i < 6; i++) {
-int val, pred;
-val = (s->block_last_index[i] >= 1);
+for (int i = 0; i < 6; i++) {
+int val = (s->block_last_index[i] >= 1);
 cbp |= val << (5 - i);
-if (i < 4) {
-/* predict value for close blocks only for luma */
-pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
-*coded_block = val;
-val = val ^ pred;
-}
-coded_cbp |= val << (5 - i);
 }
-
 if(s->msmpeg4_version<=2){
 if (s->pict_type == AV_PICTURE_TYPE_I) {
 put_bits(&s->pb,
@@ -481,6 +470,18 @@ void ff_msmpeg4_encode_mb(MpegEncContext * s,
  ff_h263_cbpy_tab[cbp>>2][0]);
 }else{
 if (s->pict_type == AV_PICTURE_TYPE_I) {
+/* compute coded_cbp; the 0x3 corresponds to chroma cbp;
+ * luma coded_cbp are set in the loop below */
+coded_cbp = cbp & 0x3;
+for (int i = 0; i < 4; i++) {
+uint8_t *coded_block;
+int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
+int val = (s->block_last_index[i] >= 1);
+*coded_block = val;
+val ^= pred;
+coded_cbp |= val << (5 - i);
+}
+
 put_bits(&s->pb,
  ff_msmp4_mb_i_table[coded_cbp][1], 
ff_msmp4_mb_i_table[coded_cbp][0]);
 } else {
-- 
2.40.1

___
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 10/14] avcodec/mpegvideo_motion: Avoid constant function argument

2024-04-28 Thread Andreas Rheinhardt
Always 8.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_motion.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index ccda20c0f1..56bdce59c0 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -239,18 +239,18 @@ static void mpeg_motion_field(MpegEncContext *s, uint8_t 
*dest_y,
   int bottom_field, int field_select,
   uint8_t *const *ref_picture,
   op_pixels_func (*pix_op)[4],
-  int motion_x, int motion_y, int h, int mb_y)
+  int motion_x, int motion_y, int mb_y)
 {
 #if !CONFIG_SMALL
 if (s->out_format == FMT_MPEG1)
 mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1,
  bottom_field, field_select, ref_picture, pix_op,
- motion_x, motion_y, h, 1, 0, mb_y);
+ motion_x, motion_y, 8, 1, 0, mb_y);
 else
 #endif
 mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1,
  bottom_field, field_select, ref_picture, pix_op,
- motion_x, motion_y, h, 0, 0, mb_y);
+ motion_x, motion_y, 8, 0, 0, mb_y);
 }
 
 // FIXME: SIMDify, avg variant, 16x16 version
@@ -738,12 +738,12 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 mpeg_motion_field(s, dest_y, dest_cb, dest_cr,
   0, s->field_select[dir][0],
   ref_picture, pix_op,
-  s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y);
+  s->mv[dir][0][0], s->mv[dir][0][1], mb_y);
 /* bottom field */
 mpeg_motion_field(s, dest_y, dest_cb, dest_cr,
   1, s->field_select[dir][1],
   ref_picture, pix_op,
-  s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y);
+  s->mv[dir][1][0], s->mv[dir][1][1], mb_y);
 }
 } else {
 av_assert2(s->out_format == FMT_MPEG1);
@@ -790,7 +790,7 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 mpeg_motion_field(s, dest_y, dest_cb, dest_cr,
   j, j ^ i, ref_picture, pix_op,
   s->mv[dir][2 * i + j][0],
-  s->mv[dir][2 * i + j][1], 8, mb_y);
+  s->mv[dir][2 * i + j][1], mb_y);
 pix_op = s->hdsp.avg_pixels_tab;
 }
 } else {
-- 
2.40.1

___
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 09/14] avcodec/mpegvideo_motion: Optimize check away

2024-04-28 Thread Andreas Rheinhardt
When !CONFIG_SMALL, we create separate functions for FMT_MPEG1
(i.e. for MPEG-1/2); given that there are only three possibilities
for out_format (FMT_MPEG1, FMT_H263 and FMT_H261 -- MJPEG and SpeedHQ
are both intra-only and do not have motion vectors at all, ergo
they don't call this function), one can optimize MPEG-1/2-only code
away in mpeg_motion_internal().

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_motion.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index 5b72196395..ccda20c0f1 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -114,13 +114,16 @@ void mpeg_motion_internal(MpegEncContext *s,
 uvsrc_y = src_y >> 1;
 }
 // Even chroma mv's are full pel in H261
-} else if (!is_mpeg12 && s->out_format == FMT_H261) {
+} else if (!CONFIG_SMALL && !is_mpeg12 ||
+   CONFIG_SMALL && s->out_format == FMT_H261) {
+av_assert2(s->out_format == FMT_H261);
 mx  = motion_x / 4;
 my  = motion_y / 4;
 uvdxy   = 0;
 uvsrc_x = s->mb_x * 8 + mx;
 uvsrc_y = mb_y * 8 + my;
 } else {
+av_assert2(s->out_format == FMT_MPEG1);
 if (s->chroma_y_shift) {
 mx  = motion_x / 2;
 my  = motion_y / 2;
@@ -820,6 +823,9 @@ void ff_mpv_motion(MpegEncContext *s,
op_pixels_func (*pix_op)[4],
qpel_mc_func (*qpix_op)[16])
 {
+av_assert2(s->out_format == FMT_MPEG1 ||
+   s->out_format == FMT_H263  ||
+   s->out_format == FMT_H261);
 prefetch_motion(s, ref_picture, dir);
 
 #if !CONFIG_SMALL
-- 
2.40.1

___
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 08/14] avcodec/mpegvideo_motion: Optimize check away

2024-04-28 Thread Andreas Rheinhardt
Only MPEG-2 can have field motion vectors with coded fields.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_motion.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index 01c8d82e98..5b72196395 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -719,7 +719,11 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
   dir, ref_picture, qpix_op, pix_op);
 break;
 case MV_TYPE_FIELD:
-if (s->picture_structure == PICT_FRAME) {
+// Only MPEG-1/2 can have a picture_structure != PICT_FRAME here.
+if (!CONFIG_SMALL)
+av_assert2(is_mpeg12 || s->picture_structure == PICT_FRAME);
+if ((!CONFIG_SMALL && !is_mpeg12) ||
+s->picture_structure == PICT_FRAME) {
 if (!is_mpeg12 && s->quarter_sample) {
 for (i = 0; i < 2; i++)
 qpel_motion(s, dest_y, dest_cb, dest_cr,
@@ -739,6 +743,7 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
   s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y);
 }
 } else {
+av_assert2(s->out_format == FMT_MPEG1);
 if (s->picture_structure != s->field_select[dir][0] + 1 &&
 s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) {
 ref_picture = s->current_picture_ptr->f->data;
-- 
2.40.1

___
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 07/14] avcodec/mpegvideo_motion: Remove dead checks for existence of reference

2024-04-28 Thread Andreas Rheinhardt
These references now always exist due to dummy frames.
Also remove the corresponding checks in the lowres code
in mpegvideo_dec.c.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_dec.c| 12 
 libavcodec/mpegvideo_motion.c | 12 
 2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index bf274e0c48..c1f49bce14 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -862,8 +862,8 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
s->mv[dir][1][0], s->mv[dir][1][1],
block_s, mb_y);
 } else {
-if (   s->picture_structure != s->field_select[dir][0] + 1 && 
s->pict_type != AV_PICTURE_TYPE_B && !s->first_field
-|| !ref_picture[0]) {
+if (s->picture_structure != s->field_select[dir][0] + 1 &&
+s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) {
 ref_picture = s->current_picture_ptr->f->data;
 }
 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
@@ -877,9 +877,8 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
 for (int i = 0; i < 2; i++) {
 uint8_t *const *ref2picture;
 
-if ((s->picture_structure == s->field_select[dir][i] + 1 ||
- s->pict_type == AV_PICTURE_TYPE_B || s->first_field) &&
-ref_picture[0]) {
+if (s->picture_structure == s->field_select[dir][i] + 1 ||
+s->pict_type == AV_PICTURE_TYPE_B || s->first_field) {
 ref2picture = ref_picture;
 } else {
 ref2picture = s->current_picture_ptr->f->data;
@@ -910,9 +909,6 @@ static inline void MPV_motion_lowres(MpegEncContext *s,
 pix_op = s->h264chroma.avg_h264_chroma_pixels_tab;
 }
 } else {
-if (!ref_picture[0]) {
-ref_picture = s->current_picture_ptr->f->data;
-}
 for (int i = 0; i < 2; i++) {
 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
0, 0, s->picture_structure != i + 1,
diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index 8922f5b1a5..01c8d82e98 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -739,8 +739,8 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
   s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y);
 }
 } else {
-if (   s->picture_structure != s->field_select[dir][0] + 1 && 
s->pict_type != AV_PICTURE_TYPE_B && !s->first_field
-|| !ref_picture[0]) {
+if (s->picture_structure != s->field_select[dir][0] + 1 &&
+s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) {
 ref_picture = s->current_picture_ptr->f->data;
 }
 
@@ -755,9 +755,8 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 for (i = 0; i < 2; i++) {
 uint8_t *const *ref2picture;
 
-if ((s->picture_structure == s->field_select[dir][i] + 1 ||
- s->pict_type == AV_PICTURE_TYPE_B || s->first_field) &&
-ref_picture[0]) {
+if (s->picture_structure == s->field_select[dir][i] + 1 ||
+s->pict_type == AV_PICTURE_TYPE_B || s->first_field) {
 ref2picture = ref_picture;
 } else {
 ref2picture = s->current_picture_ptr->f->data;
@@ -787,9 +786,6 @@ static av_always_inline void 
mpv_motion_internal(MpegEncContext *s,
 pix_op = s->hdsp.avg_pixels_tab;
 }
 } else {
-if (!ref_picture[0]) {
-ref_picture = s->current_picture_ptr->f->data;
-}
 for (i = 0; i < 2; i++) {
 mpeg_motion(s, dest_y, dest_cb, dest_cr,
 s->picture_structure != i + 1,
-- 
2.40.1

___
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 05/14] avcodec/mpegpicture: Mark dummy frames as such

2024-04-28 Thread Andreas Rheinhardt
This will allow to avoid outputting them.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegpicture.c   | 2 ++
 libavcodec/mpegpicture.h   | 1 +
 libavcodec/mpegvideo_dec.c | 2 ++
 3 files changed, 5 insertions(+)

diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index aa882cf747..88b4d5dec1 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -270,6 +270,7 @@ void ff_mpeg_unref_picture(Picture *pic)
 if (pic->needs_realloc)
 free_picture_tables(pic);
 
+pic->dummy = 0;
 pic->field_picture = 0;
 pic->b_frame_score = 0;
 pic->needs_realloc = 0;
@@ -331,6 +332,7 @@ int ff_mpeg_ref_picture(Picture *dst, Picture *src)
 ff_refstruct_replace(&dst->hwaccel_picture_private,
   src->hwaccel_picture_private);
 
+dst->dummy   = src->dummy;
 dst->field_picture   = src->field_picture;
 dst->b_frame_score   = src->b_frame_score;
 dst->needs_realloc   = src->needs_realloc;
diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h
index 215e7388ef..664c116a47 100644
--- a/libavcodec/mpegpicture.h
+++ b/libavcodec/mpegpicture.h
@@ -70,6 +70,7 @@ typedef struct Picture {
 /// RefStruct reference for hardware accelerator private data
 void *hwaccel_picture_private;
 
+int dummy;  ///< Picture is a dummy and should not be 
output
 int field_picture;  ///< whether or not the picture was encoded in 
separate fields
 
 int b_frame_score;
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index efc257d43e..bf274e0c48 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -288,6 +288,8 @@ static int av_cold alloc_dummy_frame(MpegEncContext *s, 
Picture **picp, Picture
 if (ret < 0)
 return ret;
 
+pic->dummy = 1;
+
 ff_mpeg_unref_picture(wpic);
 ret = ff_mpeg_ref_picture(wpic, pic);
 if (ret < 0) {
-- 
2.40.1

___
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 04/14] avcodec/mpegvideo_dec: Factor allocating dummy frames out

2024-04-28 Thread Andreas Rheinhardt
This will allow to reuse it to allocate dummy frames for
the second field (which can be a P-field even if the first
field was an intra field).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_dec.c | 85 +++---
 libavcodec/mpegvideodec.h  |  4 ++
 2 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 597ffde7f8..efc257d43e 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -281,14 +281,21 @@ fail:
 return ret;
 }
 
-static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp)
+static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp, 
Picture *wpic)
 {
 Picture *pic;
-int ret = alloc_picture(s, picp, 1);
+int ret = alloc_picture(s, &pic, 1);
 if (ret < 0)
 return ret;
 
-pic = *picp;
+ff_mpeg_unref_picture(wpic);
+ret = ff_mpeg_ref_picture(wpic, pic);
+if (ret < 0) {
+ff_mpeg_unref_picture(pic);
+return ret;
+}
+
+*picp = pic;
 
 ff_thread_report_progress(&pic->tf, INT_MAX, 0);
 ff_thread_report_progress(&pic->tf, INT_MAX, 1);
@@ -314,6 +321,45 @@ static void color_frame(AVFrame *frame, int luma)
 }
 }
 
+int ff_mpv_alloc_dummy_frames(MpegEncContext *s)
+{
+AVCodecContext *avctx = s->avctx;
+int ret;
+
+if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
+(s->pict_type != AV_PICTURE_TYPE_I)) {
+if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && 
s->next_picture_ptr->f->buf[0])
+av_log(avctx, AV_LOG_DEBUG,
+   "allocating dummy last picture for B frame\n");
+else if (s->codec_id != AV_CODEC_ID_H261 /* H.261 has no keyframes */ 
&&
+ (s->picture_structure == PICT_FRAME || s->first_field))
+av_log(avctx, AV_LOG_ERROR,
+   "warning: first frame is no keyframe\n");
+
+/* Allocate a dummy frame */
+ret = alloc_dummy_frame(s, &s->last_picture_ptr, &s->last_picture);
+if (ret < 0)
+return ret;
+
+if (!avctx->hwaccel) {
+int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == 
AV_CODEC_ID_H263 ? 16 : 0x80;
+color_frame(s->last_picture_ptr->f, luma_val);
+}
+}
+if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
+s->pict_type == AV_PICTURE_TYPE_B) {
+/* Allocate a dummy frame */
+ret = alloc_dummy_frame(s, &s->next_picture_ptr, &s->next_picture);
+if (ret < 0)
+return ret;
+}
+
+av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
+ 
s->last_picture_ptr->f->buf[0]));
+
+return 0;
+}
+
 /**
  * generic function called after decoding
  * the header and before a frame is decoded.
@@ -382,34 +428,6 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL,
 s->pict_type, s->droppable);
 
-if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
-(s->pict_type != AV_PICTURE_TYPE_I)) {
-if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && 
s->next_picture_ptr->f->buf[0])
-av_log(avctx, AV_LOG_DEBUG,
-   "allocating dummy last picture for B frame\n");
-else if (s->codec_id != AV_CODEC_ID_H261)
-av_log(avctx, AV_LOG_ERROR,
-   "warning: first frame is no keyframe\n");
-
-/* Allocate a dummy frame */
-ret = alloc_dummy_frame(s, &s->last_picture_ptr);
-if (ret < 0)
-return ret;
-
-if (!avctx->hwaccel) {
-int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == 
AV_CODEC_ID_H263 ? 16 : 0x80;
-color_frame(s->last_picture_ptr->f, luma_val);
-}
-
-}
-if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
-s->pict_type == AV_PICTURE_TYPE_B) {
-/* Allocate a dummy frame */
-ret = alloc_dummy_frame(s, &s->next_picture_ptr);
-if (ret < 0)
-return ret;
-}
-
 if (s->last_picture_ptr) {
 if (s->last_picture_ptr->f->buf[0] &&
 (ret = ff_mpeg_ref_picture(&s->last_picture,
@@ -423,8 +441,9 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext 
*avctx)
 return ret;
 }
 
-av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
- 
s->last_picture_ptr->f->buf[0]));
+ret = ff_mpv_alloc_dummy_frames(s);
+if (ret < 0)
+return ret;
 
 /* set dequantizer, we can't do it during init as
  * it might change for MPEG-4 and we can't do it in the header
diff --git a/libavcodec/mpegvideodec.h b/libavcodec/mpegvideodec.h
index 0b841bc1a1..42c2697749 100644
--- a/libavcodec/

[FFmpeg-devel] [PATCH 03/14] avcodec/mpegvideo_dec: Sync linesize and uvlinesize between threads

2024-04-28 Thread Andreas Rheinhardt
linesize and uvlinesize are supposed to be the common linesize of all
the Y/UV-planes of all the currently cached pictures.
ff_mpeg_update_thread_context() syncs the pictures, yet it did not sync
linesize and uvlinesize. This mostly works, because ff_alloc_picture()
only accepts new pictures if they coincide with the linesize of the
already provided pictures (if any).  Yet there is a catch: Linesize
changes are accepted when the dimensions change (in which case the
cached frames are discarded).

So imagine a scenario where all frame threads use the same dimension A
until a frame with a different dimension B is encountered in the
bitstream, only to be instantly reverted to A in the next picture. If
the user changes the linesize of the frames upon the change to dimension
B and keeps the linesize thereafter (possible if B > A),
ff_alloc_picture() will report an error when frame-threading is in use:
The thread decoding B will perform a frame size change and so will the
next thread in ff_mpeg_update_thread_context() as well as when decoding
its picture. But the next thread will (presuming it is not the same
thread that decoded B, i.e. presuming >= 3 threads) not perform a frame
size change, because the new frame size coincides with its old frame
size, yet the linesize it expects from ff_alloc_picture() is outdated,
so that it errors out.

It is also possible for the user to use the original linesizes for
the frame after the frame that reverted back to A; this will be
accepted, yet the assumption that of all pictures are the same
will be broken, leading to segfaults.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_dec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 31403d9acc..597ffde7f8 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -127,6 +127,9 @@ do {\
 UPDATE_PICTURE(last_picture);
 UPDATE_PICTURE(next_picture);
 
+s->linesize   = s1->linesize;
+s->uvlinesize = s1->uvlinesize;
+
 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
 ((pic && pic >= old_ctx->picture &&   \
   pic < old_ctx->picture + MAX_PICTURE_COUNT) ?   \
-- 
2.40.1

___
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 02/14] avcodec/mpegpicture: Store linesize in ScratchpadContext

2024-04-28 Thread Andreas Rheinhardt
The mpegvideo-based codecs currently require the linesize to be
constant (except when the frame dimensions change); one reason
for this is that certain scratch buffers whose size depend on
linesize are only allocated once and are presumed to be correctly
sized if the pointers are != NULL.

This commit changes this by storing the actual linesize these
buffers belong to and reallocating the buffers if it does not
suffice. This is not enough to actually support changing linesizes,
but it is a start. And it is a prerequisite for the next patch.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegpicture.c   | 19 ++-
 libavcodec/mpegpicture.h   |  1 +
 libavcodec/mpegvideo.c | 19 +++
 libavcodec/mpegvideo_dec.c | 19 +++
 4 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index 06b6daa01a..aa882cf747 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -89,12 +89,16 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, 
MotionEstContext *me,
 ScratchpadContext *sc, int linesize)
 {
 #   define EMU_EDGE_HEIGHT (4 * 70)
-int alloc_size = FFALIGN(FFABS(linesize) + 64, 32);
+int linesizeabs = FFABS(linesize);
+int alloc_size = FFALIGN(linesizeabs + 64, 32);
+
+if (linesizeabs <= sc->linesize)
+return 0;
 
 if (avctx->hwaccel)
 return 0;
 
-if (linesize < 24) {
+if (linesizeabs < 24) {
 av_log(avctx, AV_LOG_ERROR, "Image too small, temporary buffers cannot 
function\n");
 return AVERROR_PATCHWELCOME;
 }
@@ -102,6 +106,9 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, 
MotionEstContext *me,
 if (av_image_check_size2(alloc_size, EMU_EDGE_HEIGHT, avctx->max_pixels, 
AV_PIX_FMT_NONE, 0, avctx) < 0)
 return AVERROR(ENOMEM);
 
+av_freep(&sc->edge_emu_buffer);
+av_freep(&me->scratchpad);
+
 // edge emu needs blocksize + filter length - 1
 // (= 17x17 for  halfpel / 21x21 for H.264)
 // VC-1 computes luma and chroma simultaneously and needs 19X19 + 9x9
@@ -110,9 +117,11 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, 
MotionEstContext *me,
 // we also use this buffer for encoding in encode_mb_internal() needig an 
additional 32 lines
 if (!FF_ALLOCZ_TYPED_ARRAY(sc->edge_emu_buffer, alloc_size * 
EMU_EDGE_HEIGHT) ||
 !FF_ALLOCZ_TYPED_ARRAY(me->scratchpad,  alloc_size * 4 * 16 * 2)) {
+sc->linesize = 0;
 av_freep(&sc->edge_emu_buffer);
 return AVERROR(ENOMEM);
 }
+sc->linesize = linesizeabs;
 
 me->temp= me->scratchpad;
 sc->rd_scratchpad   = me->scratchpad;
@@ -149,9 +158,9 @@ static int handle_pic_linesizes(AVCodecContext *avctx, 
Picture *pic,
 return -1;
 }
 
-if (!sc->edge_emu_buffer &&
-(ret = ff_mpeg_framesize_alloc(avctx, me, sc,
-   pic->f->linesize[0])) < 0) {
+ret = ff_mpeg_framesize_alloc(avctx, me, sc,
+  pic->f->linesize[0]);
+if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR,
"get_buffer() failed to allocate context scratch buffers.\n");
 ff_mpeg_unref_picture(pic);
diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h
index a457586be5..215e7388ef 100644
--- a/libavcodec/mpegpicture.h
+++ b/libavcodec/mpegpicture.h
@@ -38,6 +38,7 @@ typedef struct ScratchpadContext {
 uint8_t *rd_scratchpad;   ///< scratchpad for rate distortion mb 
decision
 uint8_t *obmc_scratchpad;
 uint8_t *b_scratchpad;///< scratchpad used for writing into write 
only buffers
+int  linesize;///< linesize that the buffers in this 
context have been allocated for
 } ScratchpadContext;
 
 /**
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 7af823b8bd..130ccb4c97 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -443,6 +443,7 @@ static void free_duplicate_context(MpegEncContext *s)
 s->sc.rd_scratchpad =
 s->sc.b_scratchpad =
 s->sc.obmc_scratchpad = NULL;
+s->sc.linesize = 0;
 
 av_freep(&s->dct_error_sum);
 av_freep(&s->me.map);
@@ -464,12 +465,9 @@ static void free_duplicate_contexts(MpegEncContext *s)
 static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src)
 {
 #define COPY(a) bak->a = src->a
-COPY(sc.edge_emu_buffer);
+COPY(sc);
 COPY(me.scratchpad);
 COPY(me.temp);
-COPY(sc.rd_scratchpad);
-COPY(sc.b_scratchpad);
-COPY(sc.obmc_scratchpad);
 COPY(me.map);
 COPY(me.score_map);
 COPY(blocks);
@@ -503,9 +501,9 @@ int ff_update_duplicate_context(MpegEncContext *dst, const 
MpegEncContext *src)
 // exchange uv
 FFSWAP(void *, dst->pblocks[4], dst->pblocks[5]);
 }
-if (!dst->sc.edge_emu_buffer &&
-(ret = ff_mpeg_framesize_alloc(dst->avctx, &dst->me,
-   

[FFmpeg-devel] [PATCH 01/14] avcodec/get_buffer: Remove redundant check

2024-04-28 Thread Andreas Rheinhardt
It is unnecessary to check for whether the number of planes
of an already existing audio pool coincides with the number
of planes to use for the frame: If the common format of both
is planar, then the number of planes coincides with the number
of channels for which there is already a check*; if not,
then both the existing pool as well as the frame use one pool.

*: In fact, one could reuse the pool in this case even if the
number of channels changes.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/get_buffer.c | 20 
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c
index 9b35fde7c6..ff19f61e86 100644
--- a/libavcodec/get_buffer.c
+++ b/libavcodec/get_buffer.c
@@ -65,20 +65,15 @@ static void frame_pool_free(FFRefStructOpaque unused, void 
*obj)
 static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
 {
 FramePool *pool = avctx->internal->pool;
-int i, ret, ch, planes;
-
-if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-int planar = av_sample_fmt_is_planar(frame->format);
-ch = frame->ch_layout.nb_channels;
-planes = planar ? ch : 1;
-}
+int i, ret;
 
 if (pool && pool->format == frame->format) {
 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
 pool->width == frame->width && pool->height == frame->height)
 return 0;
-if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && pool->planes == planes 
&&
-pool->channels == ch && frame->nb_samples == pool->samples)
+if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
+pool->channels == frame->ch_layout.nb_channels &&
+frame->nb_samples == pool->samples)
 return 0;
 }
 
@@ -141,7 +136,8 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame 
*frame)
 break;
 }
 case AVMEDIA_TYPE_AUDIO: {
-ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
+ret = av_samples_get_buffer_size(&pool->linesize[0],
+ frame->ch_layout.nb_channels,
  frame->nb_samples, frame->format, 0);
 if (ret < 0)
 goto fail;
@@ -153,9 +149,9 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame 
*frame)
 }
 
 pool->format = frame->format;
-pool->planes = planes;
-pool->channels   = ch;
+pool->channels   = frame->ch_layout.nb_channels;
 pool->samples = frame->nb_samples;
+pool->planes = av_sample_fmt_is_planar(pool->format) ? 
pool->channels : 1;
 break;
 }
 default: av_assert0(0);
-- 
2.40.1

___
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] avformat: enable UDP IPv6 multicast interface selection using zone index

2024-04-28 Thread Brad Smith

On 2024-04-28 2:15 p.m., Rémi Denis-Courmont wrote:

Le torstaina 11. huhtikuuta 2024, 10.50.01 EEST Lynne a écrit :

Is there a reason why we can't switch to IPv4 addresses mapped
in IPv6 and just use the IPv6 API everywhere?

IPv6-mapped IPv4 addresses are pretty much deprecated, if supported anymore.
Some people consider them insecure. But even if you don't agree with that
assessment, the fact of the matter is that they are not portable.


OpenBSD does not support IPv4-mapped IPv6 addresses and has a split stack.
___
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/5] avcodec/aaccoder: assert that escape case len is not causing issues

2024-04-28 Thread Lynne
Apr 28, 2024, 23:57 by mich...@niedermayer.cc:

> On Sun, Apr 28, 2024 at 11:41:20PM +0200, Lynne wrote:
>
>> Apr 28, 2024, 23:31 by mich...@niedermayer.cc:
>>
>> > Inspired by CID1465483 Unintentional integer overflow
>> >
>> > Sponsored-by: Sovereign Tech Fund
>> > Signed-off-by: Michael Niedermayer 
>> > ---
>> >  libavcodec/aaccoder.c | 2 ++
>> >  1 file changed, 2 insertions(+)
>> >
>> > diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
>> > index 4ce54ca8867..6e5817e237b 100644
>> > --- a/libavcodec/aaccoder.c
>> > +++ b/libavcodec/aaccoder.c
>> > @@ -178,6 +178,8 @@ static av_always_inline float 
>> > quantize_and_encode_band_cost_template(
>> >  int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q, ROUNDING), 13);
>> >  int len = av_log2(coef);
>> > 
>> > +av_assert2(len >= 4);
>> > +
>> >  put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
>> >  put_sbits(pb, len, coef);
>> >  }
>> >
>>
>> I'm not sure that's correct to do. Any specific cases where this happens?
>>
>
> if len is 3 or less then put_bits will have a negative value or
> undefined shift
>
> coverity sasid this:
> " overflow_before_widen: Potentially overflowing expression 1 << len - 4 + 1 
> with type int (32 bits, signed) is evaluated using 32-bit arithmetic, and 
> then used in a context that expects an expression of type BitBuf (64 bits, 
> unsigned). To avoid overflow, cast 1 to type BitBuf."
>
> So what coverity really said is that the expression could exeed 32bit 
> _because_ its
> used in 64bit context. Thats just stupid from coverity also teh clip above
> limits this to 13 bit so i dont see how it can overflow in the "too large" 
> direction
> and i marked this one as false positive.
>
> I wasnt 100% sure about the too small side, i tested it and its never too 
> small
> but coverity didnt claim it could be too small, so that question is outside 
> the issue
> So i added a assert in this patch.
>

Could you instead use 64-bit arithmetic for `coef`?
Such a general assert here could result in false alarms, like the AAC
encoder suffered from before, which would make development harder.
___
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/5] avcodec/aaccoder: assert that escape case len is not causing issues

2024-04-28 Thread Michael Niedermayer
On Sun, Apr 28, 2024 at 11:41:20PM +0200, Lynne wrote:
> Apr 28, 2024, 23:31 by mich...@niedermayer.cc:
> 
> > Inspired by CID1465483 Unintentional integer overflow
> >
> > Sponsored-by: Sovereign Tech Fund
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavcodec/aaccoder.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
> > index 4ce54ca8867..6e5817e237b 100644
> > --- a/libavcodec/aaccoder.c
> > +++ b/libavcodec/aaccoder.c
> > @@ -178,6 +178,8 @@ static av_always_inline float 
> > quantize_and_encode_band_cost_template(
> >  int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q, ROUNDING), 13);
> >  int len = av_log2(coef);
> >  
> > +av_assert2(len >= 4);
> > +
> >  put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
> >  put_sbits(pb, len, coef);
> >  }
> >
> 
> I'm not sure that's correct to do. Any specific cases where this happens?

if len is 3 or less then put_bits will have a negative value or
undefined shift

coverity sasid this:
" overflow_before_widen: Potentially overflowing expression 1 << len - 4 + 1 
with type int (32 bits, signed) is evaluated using 32-bit arithmetic, and then 
used in a context that expects an expression of type BitBuf (64 bits, 
unsigned). To avoid overflow, cast 1 to type BitBuf."

So what coverity really said is that the expression could exeed 32bit _because_ 
its
used in 64bit context. Thats just stupid from coverity also teh clip above
limits this to 13 bit so i dont see how it can overflow in the "too large" 
direction
and i marked this one as false positive.

I wasnt 100% sure about the too small side, i tested it and its never too small
but coverity didnt claim it could be too small, so that question is outside the 
issue
So i added a assert in this patch.

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 


signature.asc
Description: PGP signature
___
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] doc/Doxfyile: Refactor for maintainability

2024-04-28 Thread Michael Niedermayer
Hi

On Sun, Apr 28, 2024 at 11:10:22AM +0100, Andrew Sayers wrote:
[...]
> Ping ?
> 
> Michael, this is in response to your request[0].  I've queued up some more
> patches that depend on this and would help attract and retain developers (e.g.
> warning when you're looking at old documentation).  What would be involved in
> getting this sort of thing on the website itself?

I dont have the time to review this

if you split the patch between updates to to comments and updates to teh actual
configuration this may make it easier to review to whoever does review it

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf


signature.asc
Description: PGP signature
___
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 5/5] avcodec/atrac9dec: Check init_get_bits8() for failure

2024-04-28 Thread Lynne
Apr 28, 2024, 23:31 by mich...@niedermayer.cc:

> Fixes: CID1439569 Unchecked return value
> Fixes: CID1439578 Unchecked return value
>
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/atrac9dec.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
> index df68407af92..e375f46fd04 100644
> --- a/libavcodec/atrac9dec.c
> +++ b/libavcodec/atrac9dec.c
> @@ -802,7 +802,9 @@ static int atrac9_decode_frame(AVCodecContext *avctx, 
> AVFrame *frame,
>  if (ret < 0)
>  return ret;
>  
> -init_get_bits8(&gb, avpkt->data, avpkt->size);
> +ret = init_get_bits8(&gb, avpkt->data, avpkt->size);
> +if (ret < 0)
> +return ret;
>  
>  for (int i = 0; i < frames; i++) {
>  for (int j = 0; j < s->block_config->count; j++) {
> @@ -922,7 +924,9 @@ static av_cold int atrac9_decode_init(AVCodecContext 
> *avctx)
>  return AVERROR_INVALIDDATA;
>  }
>  
> -init_get_bits8(&gb, avctx->extradata + 4, avctx->extradata_size);
> +err = init_get_bits8(&gb, avctx->extradata + 4, avctx->extradata_size);
> +if (err < 0)
> +return err;
>  
>  if (get_bits(&gb, 8) != 0xFE) {
>  av_log(avctx, AV_LOG_ERROR, "Incorrect magic byte!\n");
>

This and ac3 lgtm
___
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/5] avcodec/aaccoder: assert that escape case len is not causing issues

2024-04-28 Thread Lynne
Apr 28, 2024, 23:31 by mich...@niedermayer.cc:

> Inspired by CID1465483 Unintentional integer overflow
>
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/aaccoder.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
> index 4ce54ca8867..6e5817e237b 100644
> --- a/libavcodec/aaccoder.c
> +++ b/libavcodec/aaccoder.c
> @@ -178,6 +178,8 @@ static av_always_inline float 
> quantize_and_encode_band_cost_template(
>  int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q, ROUNDING), 13);
>  int len = av_log2(coef);
>  
> +av_assert2(len >= 4);
> +
>  put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
>  put_sbits(pb, len, coef);
>  }
>

I'm not sure that's correct to do. Any specific cases where this happens?
___
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/5] avcodec/atrac9dec: Check init_get_bits8() for failure

2024-04-28 Thread Michael Niedermayer
Fixes: CID1439569 Unchecked return value
Fixes: CID1439578 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/atrac9dec.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
index df68407af92..e375f46fd04 100644
--- a/libavcodec/atrac9dec.c
+++ b/libavcodec/atrac9dec.c
@@ -802,7 +802,9 @@ static int atrac9_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 if (ret < 0)
 return ret;
 
-init_get_bits8(&gb, avpkt->data, avpkt->size);
+ret = init_get_bits8(&gb, avpkt->data, avpkt->size);
+if (ret < 0)
+return ret;
 
 for (int i = 0; i < frames; i++) {
 for (int j = 0; j < s->block_config->count; j++) {
@@ -922,7 +924,9 @@ static av_cold int atrac9_decode_init(AVCodecContext *avctx)
 return AVERROR_INVALIDDATA;
 }
 
-init_get_bits8(&gb, avctx->extradata + 4, avctx->extradata_size);
+err = init_get_bits8(&gb, avctx->extradata + 4, avctx->extradata_size);
+if (err < 0)
+return err;
 
 if (get_bits(&gb, 8) != 0xFE) {
 av_log(avctx, AV_LOG_ERROR, "Incorrect magic byte!\n");
-- 
2.43.2

___
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/5] avcodec/amrwbdec: assert mode to be valid in decode_fixed_vector()

2024-04-28 Thread Michael Niedermayer
Inspired-by: CID1473499 Uninitialized scalar variable

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/amrwbdec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index 9d75b972fa7..21a730b835d 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -26,6 +26,7 @@
 
 #include "config.h"
 
+#include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
 #include "libavutil/lfg.h"
@@ -554,6 +555,8 @@ static void decode_fixed_vector(float *fixed_vector, const 
uint16_t *pulse_hi,
 decode_6p_track(sig_pos[i], (int) pulse_lo[i] +
((int) pulse_hi[i] << 11), 4, 1);
 break;
+default:
+av_assert2(0);
 }
 
 memset(fixed_vector, 0, sizeof(float) * AMRWB_SFR_SIZE);
-- 
2.43.2

___
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/5] avcodec/ac3_parser: Check init_get_bits8() for failure

2024-04-28 Thread Michael Niedermayer
Fixes: CID1420393 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/ac3_parser.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 4152fd4e018..4e0ba734818 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -204,7 +204,9 @@ int av_ac3_parse_header(const uint8_t *buf, size_t size,
 AC3HeaderInfo hdr;
 int err;
 
-init_get_bits8(&gb, buf, size);
+err = init_get_bits8(&gb, buf, size);
+if (err < 0)
+return AVERROR_INVALIDDATA;
 err = ff_ac3_parse_header(&gb, &hdr);
 if (err < 0)
 return AVERROR_INVALIDDATA;
-- 
2.43.2

___
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/5] avcodec/aaccoder: assert that escape case len is not causing issues

2024-04-28 Thread Michael Niedermayer
Inspired by CID1465483 Unintentional integer overflow

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 libavcodec/aaccoder.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 4ce54ca8867..6e5817e237b 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -178,6 +178,8 @@ static av_always_inline float 
quantize_and_encode_band_cost_template(
 int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q, 
ROUNDING), 13);
 int len = av_log2(coef);
 
+av_assert2(len >= 4);
+
 put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
 put_sbits(pb, len, coef);
 }
-- 
2.43.2

___
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/5] tools/opt_common: Check for malloc failure

2024-04-28 Thread Michael Niedermayer
Fixes: CID1539100 Negative loop bound

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer 
---
 fftools/opt_common.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 947a226d8d1..9d2d5184a08 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -724,10 +724,13 @@ int show_codecs(void *optctx, const char *opt, const char 
*arg)
 return 0;
 }
 
-static void print_codecs(int encoder)
+static int print_codecs(int encoder)
 {
 const AVCodecDescriptor **codecs;
-unsigned i, nb_codecs = get_codecs_sorted(&codecs);
+int i, nb_codecs = get_codecs_sorted(&codecs);
+
+if (nb_codecs < 0)
+return nb_codecs;
 
 printf("%s:\n"
" V. = Video\n"
@@ -762,18 +765,17 @@ static void print_codecs(int encoder)
 }
 }
 av_free(codecs);
+return 0;
 }
 
 int show_decoders(void *optctx, const char *opt, const char *arg)
 {
-print_codecs(0);
-return 0;
+return print_codecs(0);
 }
 
 int show_encoders(void *optctx, const char *opt, const char *arg)
 {
-print_codecs(1);
-return 0;
+return print_codecs(1);
 }
 
 int show_bsfs(void *optctx, const char *opt, const char *arg)
-- 
2.43.2

___
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] avformat: enable UDP IPv6 multicast interface selection using zone index

2024-04-28 Thread Lynne
Apr 28, 2024, 20:15 by r...@remlab.net:

> Le torstaina 11. huhtikuuta 2024, 10.50.01 EEST Lynne a écrit :
>
>> Is there a reason why we can't switch to IPv4 addresses mapped
>> in IPv6 and just use the IPv6 API everywhere?
>>
>
> IPv6-mapped IPv4 addresses are pretty much deprecated, if supported anymore. 
> Some people consider them insecure. But even if you don't agree with that 
> assessment, the fact of the matter is that they are not portable.
>

They were they deprecated? Why would they not be portable?
They seem to work fine in libavtransport.
___
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] avformat: enable UDP IPv6 multicast interface selection using zone index

2024-04-28 Thread Rémi Denis-Courmont
Le torstaina 11. huhtikuuta 2024, 10.50.01 EEST Lynne a écrit :
> Is there a reason why we can't switch to IPv4 addresses mapped
> in IPv6 and just use the IPv6 API everywhere?

IPv6-mapped IPv4 addresses are pretty much deprecated, if supported anymore. 
Some people consider them insecure. But even if you don't agree with that 
assessment, the fact of the matter is that they are not portable.


-- 
Rémi Denis-Courmont
http://www.remlab.net/



___
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/vc1dsp: R-V V mspel_pixels

2024-04-28 Thread Rémi Denis-Courmont
Le sunnuntaina 7. huhtikuuta 2024, 8.38.54 EEST flow gg a écrit :
> ping

I have been away for a while, and catching up takes time, sorry.

-- 
レミ・デニ-クールモン
http://www.remlab.net/
___
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".


Re: [FFmpeg-devel] [PATCH] avcodec/aacenc: don't redundantly re-compute max sfb

2024-04-28 Thread Lynne
Apr 28, 2024, 11:37 by yotam.o...@gmail.com:

> Remove an unneeded inner loop in adjust_frame_information that
> had no effect, the loop body can be run only once and will compute
> the same max sfb.
> ---
>  libavcodec/aacenc.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
> index 7feb723289..163598e938 100644
> --- a/libavcodec/aacenc.c
> +++ b/libavcodec/aacenc.c
> @@ -538,11 +538,9 @@ static void adjust_frame_information(ChannelElement 
> *cpe, int chans)
>  maxsfb = 0;
>  cpe->ch[ch].pulse.num_pulse = 0;
>  for (w = 0; w < ics->num_windows; w += ics->group_len[w]) {
> -for (w2 =  0; w2 < ics->group_len[w]; w2++) {
> -for (cmaxsfb = ics->num_swb; cmaxsfb > 0 && 
> cpe->ch[ch].zeroes[w*16+cmaxsfb-1]; cmaxsfb--)
> -;
> -maxsfb = FFMAX(maxsfb, cmaxsfb);
> -}
> +for (cmaxsfb = ics->num_swb; cmaxsfb > 0 && 
> cpe->ch[ch].zeroes[w*16+cmaxsfb-1]; cmaxsfb--)
> +;
> +maxsfb = FFMAX(maxsfb, cmaxsfb);
>  }
>  ics->max_sfb = maxsfb; 
>

Thanks, pushed
___
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 WIP 0/9] Refactor DNN

2024-04-28 Thread Zhao Zhili

> On Apr 28, 2024, at 18:58, Paul B Mahol  wrote:
> 
> Extremely low quality filters, both in source code quality and
> performance/security and output quality should be queued for removal.

I don’t think there is any replacement for the function provided by dnn_detect,
which is very important for ROI encoding.

> ___
> 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 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 WIP 0/9] Refactor DNN

2024-04-28 Thread Paul B Mahol
Extremely low quality filters, both in source code quality and
performance/security and output quality should be queued for removal.
___
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 WIP 0/9] Refactor DNN

2024-04-28 Thread Zhao Zhili


> On Apr 28, 2024, at 18:34, Guo, Yejun  
> wrote:
> 
>> -Original Message-
>> From: ffmpeg-devel > > On Behalf Of Zhao
>> Zhili
>> Sent: Sunday, April 28, 2024 12:42 AM
>> To: ffmpeg-devel@ffmpeg.org 
>> Cc: Zhao Zhili mailto:zhiliz...@tencent.com>>
>> Subject: [FFmpeg-devel] [PATCH WIP 0/9] Refactor DNN
>> 
>> From: Zhao Zhili 
>> 
>> During the refactor progress, I have found some serious issues, which is not
>> resolved by the patchset:
>> 
>> 1. Tensorflow backend is broken.
>> 
>> I think it doesn't work since 2021 at least. For example, it destroy a 
>> thread and
>> create a new thread for each frame, and it destroy an invalid thread at the 
>> first
>> frame:
> 
> It works from the day that code is merged, till today. It is by design to 
> keep the
> code simplicity by using the feature that pthread_join accepts a parameter 
> that
> is not a joinable thread.
> 
> Please share more info if you experienced a real case that it does not work.

It will abort if ASSERT_LEVEL > 1.

#define ASSERT_PTHREAD_ABORT(func, ret) do {\
char errbuf[AV_ERROR_MAX_STRING_SIZE] = ""; \
av_log(NULL, AV_LOG_FATAL, AV_STRINGIFY(func)   \
   " failed with error: %s\n",  \
   av_make_error_string(errbuf, AV_ERROR_MAX_STRING_SIZE,   \
AVERROR(ret))); \
abort();\
} while (0)

I think the check is there just to prevent call pthread_join(0, &ptr) by 
accident, so we
shouldn’t do that on purpose.

>> 
>> 
>>pthread_join(async_module->thread_id, &status);
>>if (status == DNN_ASYNC_FAIL) {
>>av_log(ctx, AV_LOG_ERROR, "Unable to start inference as previous
>> inference failed.\n");
>>return DNN_GENERIC_ERROR;
>>}
>>ret = pthread_create(&async_module->thread_id, NULL,
>> async_thread_routine, async_module);
>> 
>> 
>> 2. Openvino V1 doesn't compile. It doesn't compile and no one complains, I
>> think it's a hint to just keep the code for V2.
> 
> In plan, and patch is welcome.
> 
>> 
>> 3. Error handling. It's easy to crash with incorrect command line arguments.
> 
> Thanks, will review your patchset one by one, it may take some time.
> 
>> 
>> I don't have enough test case. Please share your test case and help on test.
>> 
>> Zhao Zhili (9):
>>  avfilter/dnn: Refactor DNN parameter configuration system
>>  avfilter/dnn_backend_openvino: Fix free context at random place
>>  avfilter/dnn_backend_openvino: simplify memory allocation
>>  avfilter/dnn_backend_tf: Remove one level of indentation
>>  avfilter/dnn_backend_tf: Fix free context at random place
>>  avfilter/dnn_backend_tf: Simplify memory allocation
>>  avfilter/dnn_backend_torch: Simplify memory allocation
>>  avfilter/dnn: Remove a level of dereference
>>  avfilter/dnn: Use dnn_backend_info_list to search for dnn module
>> 
>> libavfilter/dnn/dnn_backend_common.h   |  13 +-
>> libavfilter/dnn/dnn_backend_openvino.c | 210 ++---
>> libavfilter/dnn/dnn_backend_tf.c   | 194 ++-
>> libavfilter/dnn/dnn_backend_torch.cpp  | 112 +
>> libavfilter/dnn/dnn_interface.c| 107 ++---
>> libavfilter/dnn_filter_common.c|  38 -
>> libavfilter/dnn_filter_common.h|  37 ++---
>> libavfilter/dnn_interface.h|  73 +++--
>> libavfilter/vf_derain.c|   5 +-
>> libavfilter/vf_dnn_classify.c  |   3 +-
>> libavfilter/vf_dnn_detect.c|   3 +-
>> libavfilter/vf_dnn_processing.c|   3 +-
>> libavfilter/vf_sr.c|   5 +-
>> 13 files changed, 428 insertions(+), 375 deletions(-)
>> 
>> --
>> 2.34.1
>> 
>> ___
>> 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 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 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 WIP 0/9] Refactor DNN

2024-04-28 Thread Guo, Yejun



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Zhao
> Zhili
> Sent: Sunday, April 28, 2024 12:42 AM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Zhao Zhili 
> Subject: [FFmpeg-devel] [PATCH WIP 0/9] Refactor DNN
> 
> From: Zhao Zhili 
> 
> During the refactor progress, I have found some serious issues, which is not
> resolved by the patchset:
> 
> 1. Tensorflow backend is broken.
> 
> I think it doesn't work since 2021 at least. For example, it destroy a thread 
> and
> create a new thread for each frame, and it destroy an invalid thread at the 
> first
> frame:

It works from the day that code is merged, till today. It is by design to keep 
the
code simplicity by using the feature that pthread_join accepts a parameter that
is not a joinable thread.

Please share more info if you experienced a real case that it does not work.
> 
> 
> pthread_join(async_module->thread_id, &status);
> if (status == DNN_ASYNC_FAIL) {
> av_log(ctx, AV_LOG_ERROR, "Unable to start inference as previous
> inference failed.\n");
> return DNN_GENERIC_ERROR;
> }
> ret = pthread_create(&async_module->thread_id, NULL,
> async_thread_routine, async_module);
> 
> 
> 2. Openvino V1 doesn't compile. It doesn't compile and no one complains, I
> think it's a hint to just keep the code for V2.

In plan, and patch is welcome.

> 
> 3. Error handling. It's easy to crash with incorrect command line arguments.

Thanks, will review your patchset one by one, it may take some time.

> 
> I don't have enough test case. Please share your test case and help on test.
> 
> Zhao Zhili (9):
>   avfilter/dnn: Refactor DNN parameter configuration system
>   avfilter/dnn_backend_openvino: Fix free context at random place
>   avfilter/dnn_backend_openvino: simplify memory allocation
>   avfilter/dnn_backend_tf: Remove one level of indentation
>   avfilter/dnn_backend_tf: Fix free context at random place
>   avfilter/dnn_backend_tf: Simplify memory allocation
>   avfilter/dnn_backend_torch: Simplify memory allocation
>   avfilter/dnn: Remove a level of dereference
>   avfilter/dnn: Use dnn_backend_info_list to search for dnn module
> 
>  libavfilter/dnn/dnn_backend_common.h   |  13 +-
>  libavfilter/dnn/dnn_backend_openvino.c | 210 ++---
>  libavfilter/dnn/dnn_backend_tf.c   | 194 ++-
>  libavfilter/dnn/dnn_backend_torch.cpp  | 112 +
>  libavfilter/dnn/dnn_interface.c| 107 ++---
>  libavfilter/dnn_filter_common.c|  38 -
>  libavfilter/dnn_filter_common.h|  37 ++---
>  libavfilter/dnn_interface.h|  73 +++--
>  libavfilter/vf_derain.c|   5 +-
>  libavfilter/vf_dnn_classify.c  |   3 +-
>  libavfilter/vf_dnn_detect.c|   3 +-
>  libavfilter/vf_dnn_processing.c|   3 +-
>  libavfilter/vf_sr.c|   5 +-
>  13 files changed, 428 insertions(+), 375 deletions(-)
> 
> --
> 2.34.1
> 
> ___
> 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 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] avcodec/aacenc: don't redundantly re-compute max sfb

2024-04-28 Thread Yotam Ofek
Remove an unneeded inner loop in adjust_frame_information that
had no effect, the loop body can be run only once and will compute
the same max sfb.
---
 libavcodec/aacenc.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 7feb723289..163598e938 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -538,11 +538,9 @@ static void adjust_frame_information(ChannelElement *cpe, 
int chans)
 maxsfb = 0;
 cpe->ch[ch].pulse.num_pulse = 0;
 for (w = 0; w < ics->num_windows; w += ics->group_len[w]) {
-for (w2 =  0; w2 < ics->group_len[w]; w2++) {
-for (cmaxsfb = ics->num_swb; cmaxsfb > 0 && 
cpe->ch[ch].zeroes[w*16+cmaxsfb-1]; cmaxsfb--)
-;
-maxsfb = FFMAX(maxsfb, cmaxsfb);
-}
+for (cmaxsfb = ics->num_swb; cmaxsfb > 0 && 
cpe->ch[ch].zeroes[w*16+cmaxsfb-1]; cmaxsfb--)
+;
+maxsfb = FFMAX(maxsfb, cmaxsfb);
 }
 ics->max_sfb = maxsfb;
 
-- 
2.40.1

___
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 8/9] lavfi/qsvvpp: use the right mfxFrameInfo when dynamic frame pool is used

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 libavfilter/qsvvpp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8c92fec0c1..6814d8add8 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -308,7 +308,7 @@ static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, 
AVFilterLink *link)
 
 frames_ctx   = (AVHWFramesContext *)link->hw_frames_ctx->data;
 frames_hwctx = frames_ctx->hwctx;
-*frameinfo   = frames_hwctx->surfaces[0].Info;
+*frameinfo   = frames_hwctx->nb_surfaces ? 
frames_hwctx->surfaces[0].Info : *frames_hwctx->info;
 } else {
 pix_fmt = link->format;
 desc = av_pix_fmt_desc_get(pix_fmt);
-- 
2.34.1

___
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 7/9] lavc/qsvdec: require a dynamic frame pool if possible

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

This allows a downstream element stores more frames from qsv decoders
and fixes error in get_buffer().

$ ffmpeg -hwaccel qsv -hwaccel_output_format qsv -i input.mp4 -vf
reverse -f null -

[vist#0:0/h264 @ 0x562248f12c50] Decoding error: Cannot allocate memory
[h264_qsv @ 0x562248f66b10] get_buffer() failed

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvdec.c | 57 +++--
 1 file changed, 45 insertions(+), 12 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 5528bcdc8c..f7eaf88e50 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -42,6 +42,7 @@
 #include "libavutil/imgutils.h"
 #include "libavutil/film_grain_params.h"
 #include "libavutil/mastering_display_metadata.h"
+#include "libavutil/avassert.h"
 
 #include "avcodec.h"
 #include "codec_internal.h"
@@ -68,6 +69,8 @@ static const AVRational mfx_tb = { 1, 9 };
 AV_NOPTS_VALUE : pts_tb.num ? \
 av_rescale_q(mfx_pts, mfx_tb, pts_tb) : mfx_pts)
 
+#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
+
 typedef struct QSVAsyncFrame {
 mfxSyncPoint *sync;
 QSVFrame *frame;
@@ -77,6 +80,7 @@ typedef struct QSVContext {
 // the session used for decoding
 mfxSession session;
 mfxVersion ver;
+mfxHandleType handle_type;
 
 // the session we allocated internally, in case the caller did not provide
 // one
@@ -183,6 +187,7 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 AVBufferRef *hw_frames_ref, AVBufferRef 
*hw_device_ref)
 {
 int ret;
+mfxIMPL impl;
 
 if (q->gpu_copy == MFX_GPUCOPY_ON &&
 !(q->iopattern & MFX_IOPATTERN_OUT_SYSTEM_MEMORY)) {
@@ -240,27 +245,52 @@ static int qsv_init_session(AVCodecContext *avctx, 
QSVContext *q, mfxSession ses
 q->session = q->internal_qs.session;
 }
 
-if (MFXQueryVersion(q->session, &q->ver) != MFX_ERR_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
-q->session = NULL;
+if (MFXQueryIMPL(q->session, &impl) == MFX_ERR_NONE) {
+switch (MFX_IMPL_VIA_MASK(impl)) {
+case MFX_IMPL_VIA_VAAPI:
+q->handle_type = MFX_HANDLE_VA_DISPLAY;
+break;
 
-if (q->internal_qs.session) {
-MFXClose(q->internal_qs.session);
-q->internal_qs.session = NULL;
-}
+case MFX_IMPL_VIA_D3D11:
+q->handle_type = MFX_HANDLE_D3D11_DEVICE;
+break;
+
+case MFX_IMPL_VIA_D3D9:
+q->handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+break;
 
-if (q->internal_qs.loader) {
-MFXUnload(q->internal_qs.loader);
-q->internal_qs.loader = NULL;
+default:
+av_assert0(!"should not reach here");
 }
+} else {
+av_log(avctx, AV_LOG_ERROR, "Error querying the implementation. \n");
+goto fail;
+}
 
-return AVERROR_EXTERNAL;
+if (MFXQueryVersion(q->session, &q->ver) != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error querying the session version. \n");
+goto fail;
 }
 
 /* make sure the decoder is uninitialized */
 MFXVideoDECODE_Close(q->session);
 
 return 0;
+
+fail:
+q->session = NULL;
+
+if (q->internal_qs.session) {
+MFXClose(q->internal_qs.session);
+q->internal_qs.session = NULL;
+}
+
+if (q->internal_qs.loader) {
+MFXUnload(q->internal_qs.loader);
+q->internal_qs.loader = NULL;
+}
+
+return AVERROR_EXTERNAL;
 }
 
 static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum 
AVPixelFormat pix_fmt, mfxVideoParam *param)
@@ -310,7 +340,10 @@ static int qsv_decode_preinit(AVCodecContext *avctx, 
QSVContext *q, enum AVPixel
 hwframes_ctx->height= FFALIGN(avctx->coded_height, 32);
 hwframes_ctx->format= AV_PIX_FMT_QSV;
 hwframes_ctx->sw_format = avctx->sw_pix_fmt;
-hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 + 
avctx->extra_hw_frames;
+if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 9) && q->handle_type != 
MFX_HANDLE_D3D9_DEVICE_MANAGER)
+hwframes_ctx->initial_pool_size = 0;
+else
+hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 + 
avctx->extra_hw_frames;
 frames_hwctx->frame_type= 
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
 
 ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
-- 
2.34.1

___
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 9/9] lavfi/qsvvpp: require a dynamic frame pool for output if possible

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 libavfilter/qsvvpp.c | 52 
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 6814d8add8..f3897823db 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -604,6 +604,26 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 device_ctx   = (AVHWDeviceContext *)device_ref->data;
 device_hwctx = device_ctx->hwctx;
 
+/* extract the properties of the "master" session given to us */
+ret = MFXQueryIMPL(device_hwctx->session, &impl);
+if (ret == MFX_ERR_NONE)
+ret = MFXQueryVersion(device_hwctx->session, &ver);
+if (ret != MFX_ERR_NONE) {
+av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
+return AVERROR_UNKNOWN;
+}
+
+if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_VA_DISPLAY;
+} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D11_DEVICE;
+} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
+handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
+} else {
+av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
+return AVERROR_UNKNOWN;
+}
+
 if (outlink->format == AV_PIX_FMT_QSV) {
 AVHWFramesContext *out_frames_ctx;
 AVBufferRef *out_frames_ref = av_hwframe_ctx_alloc(device_ref);
@@ -625,9 +645,15 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 out_frames_ctx->width = FFALIGN(outlink->w, 32);
 out_frames_ctx->height= FFALIGN(outlink->h, 32);
 out_frames_ctx->sw_format = s->out_sw_format;
-out_frames_ctx->initial_pool_size = 64;
-if (avctx->extra_hw_frames > 0)
-out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+
+if (QSV_RUNTIME_VERSION_ATLEAST(ver, 2, 9) && handle_type != 
MFX_HANDLE_D3D9_DEVICE_MANAGER)
+out_frames_ctx->initial_pool_size = 0;
+else {
+out_frames_ctx->initial_pool_size = 64;
+if (avctx->extra_hw_frames > 0)
+out_frames_ctx->initial_pool_size += avctx->extra_hw_frames;
+}
+
 out_frames_hwctx->frame_type  = s->out_mem_mode;
 
 ret = av_hwframe_ctx_init(out_frames_ref);
@@ -653,26 +679,6 @@ static int init_vpp_session(AVFilterContext *avctx, 
QSVVPPContext *s)
 } else
 s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;
 
-/* extract the properties of the "master" session given to us */
-ret = MFXQueryIMPL(device_hwctx->session, &impl);
-if (ret == MFX_ERR_NONE)
-ret = MFXQueryVersion(device_hwctx->session, &ver);
-if (ret != MFX_ERR_NONE) {
-av_log(avctx, AV_LOG_ERROR, "Error querying the session attributes\n");
-return AVERROR_UNKNOWN;
-}
-
-if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_VA_DISPLAY;
-} else if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_D3D11_DEVICE;
-} else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
-handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
-} else {
-av_log(avctx, AV_LOG_ERROR, "Error unsupported handle type\n");
-return AVERROR_UNKNOWN;
-}
-
 ret = MFXVideoCORE_GetHandle(device_hwctx->session, handle_type, &handle);
 if (ret < 0)
 return ff_qsvvpp_print_error(avctx, ret, "Error getting the session 
handle");
-- 
2.34.1

___
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/9] lavc/qsvenc: use the right info for encoding

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsvenc.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 018d193495..ca1a88e49f 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -744,8 +744,9 @@ static int init_video_param_jpeg(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->hw_frames_ctx) {
 AVHWFramesContext *frames_ctx= (AVHWFramesContext 
*)avctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
-q->param.mfx.FrameInfo.Width  = frames_hwctx->surfaces[0].Info.Width;
-q->param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
+mfxFrameInfo *info = frames_hwctx->nb_surfaces ? 
&frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+q->param.mfx.FrameInfo.Width  = info->Width;
+q->param.mfx.FrameInfo.Height = info->Height;
 }
 
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
@@ -868,8 +869,9 @@ static int init_video_param(AVCodecContext *avctx, 
QSVEncContext *q)
 if (avctx->hw_frames_ctx) {
 AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)avctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
-q->param.mfx.FrameInfo.Width  = frames_hwctx->surfaces[0].Info.Width;
-q->param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
+mfxFrameInfo *info = frames_hwctx->nb_surfaces ? 
&frames_hwctx->surfaces[0].Info : frames_hwctx->info;
+q->param.mfx.FrameInfo.Width  = info->Width;
+q->param.mfx.FrameInfo.Height = info->Height;
 }
 
 if (avctx->framerate.den > 0 && avctx->framerate.num > 0) {
-- 
2.34.1

___
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/9] lavc/qsv: fix the mfx allocator to support dynamic frame pool

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

When the external allocator is used for dynamic frame allocation, only
video memory is supported, the SDK doesn't lock/unlock the memory block
via Lock()/Unlock() calls.

Signed-off-by: Haihao Xiang 
---
 libavcodec/qsv.c | 68 +++-
 1 file changed, 56 insertions(+), 12 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index b07302cdf6..6bbfe2a5a9 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -825,8 +825,16 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
 AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 mfxFrameInfo  *i  = &req->Info;
-mfxFrameInfo  *i1 = &frames_hwctx->surfaces[0].Info;
+mfxFrameInfo  *i1;
 
+if (!frames_hwctx->nb_surfaces) {
+av_log(ctx->logctx, AV_LOG_DEBUG,
+   "Dynamic frame pools, no frame is pre-allocated\n");
+
+return MFX_ERR_NONE;
+}
+
+i1 = &frames_hwctx->surfaces[0].Info;
 if (i->Width  > i1->Width  || i->Height > i1->Height ||
 i->FourCC != i1->FourCC || i->ChromaFormat != i1->ChromaFormat) {
 av_log(ctx->logctx, AV_LOG_ERROR, "Mismatching surface properties 
in an "
@@ -845,6 +853,7 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 } else if (req->Type & MFX_MEMTYPE_INTERNAL_FRAME) {
 /* internal frames -- allocate a new hw frames context */
 AVHWFramesContext *ext_frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *ext_frames_hwctx = ext_frames_ctx->hwctx;
 mfxFrameInfo  *i  = &req->Info;
 
 AVBufferRef *frames_ref;
@@ -852,6 +861,9 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 AVHWFramesContext *frames_ctx;
 AVQSVFramesContext *frames_hwctx;
 
+if (!ext_frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
+
 frames_ref = av_hwframe_ctx_alloc(ext_frames_ctx->device_ref);
 if (!frames_ref)
 return MFX_ERR_MEMORY_ALLOC;
@@ -899,6 +911,9 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, 
mfxFrameAllocRequest *req,
 
 static mfxStatus qsv_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp)
 {
+if (!resp->mids)
+return MFX_ERR_NONE;
+
 av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual]);
 ff_refstruct_unref(&resp->mids[resp->NumFrameActual + 1]);
 av_freep(&resp->mids);
@@ -907,11 +922,20 @@ static mfxStatus qsv_frame_free(mfxHDL pthis, 
mfxFrameAllocResponse *resp)
 
 static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
 {
-QSVMid *qsv_mid = mid;
-AVHWFramesContext *hw_frames_ctx = 
(AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
-AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+QSVMid *qsv_mid;
+AVHWFramesContext *hw_frames_ctx;
+AVQSVFramesContext *hw_frames_hwctx;
 int ret;
 
+if (!frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
+
+qsv_mid = mid;
+hw_frames_ctx = (AVHWFramesContext*)qsv_mid->hw_frames_ref->data;
+hw_frames_hwctx = hw_frames_ctx->hwctx;
 if (qsv_mid->locked_frame)
 return MFX_ERR_UNDEFINED_BEHAVIOR;
 
@@ -964,8 +988,15 @@ fail:
 
 static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData 
*ptr)
 {
-QSVMid *qsv_mid = mid;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
+QSVMid *qsv_mid;
+
+if (!frames_hwctx->nb_surfaces)
+return MFX_ERR_UNSUPPORTED;
 
+qsv_mid = mid;
 av_frame_free(&qsv_mid->locked_frame);
 av_frame_free(&qsv_mid->hw_frame);
 
@@ -974,9 +1005,18 @@ static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId 
mid, mfxFrameData *ptr)
 
 static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
 {
-QSVMid *qsv_mid = (QSVMid*)mid;
+QSVFramesContext *ctx = (QSVFramesContext *)pthis;
+AVHWFramesContext *frames_ctx = 
(AVHWFramesContext*)ctx->hw_frames_ctx->data;
+AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
 mfxHDLPair *pair_dst = (mfxHDLPair*)hdl;
-mfxHDLPair *pair_src = (mfxHDLPair*)qsv_mid->handle_pair;
+mfxHDLPair *pair_src;
+
+if (frames_hwctx->nb_surfaces) {
+QSVMid *qsv_mid = (QSVMid*)mid;
+pair_src = (mfxHDLPair*)qsv_mid->handle_pair;
+} else {
+pair_src = (mfxHDLPair*)mid;
+}
 
 pair_dst->first = pair_src->first;
 
@@ -1090,13 +1130,17 @@ int ff_qsv_init_session_fr

[FFmpeg-devel] [PATCH 4/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_map_to

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Make it work with the source which has a dynamic frame pool.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 131 +-
 1 file changed, 129 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 1d3091e6f8..8b7b4dc501 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -2122,8 +2122,8 @@ static int qsv_frames_derive_to(AVHWFramesContext 
*dst_ctx,
 }
 }
 
-static int qsv_map_to(AVHWFramesContext *dst_ctx,
-  AVFrame *dst, const AVFrame *src, int flags)
+static int qsv_fixed_pool_map_to(AVHWFramesContext *dst_ctx,
+ AVFrame *dst, const AVFrame *src, int flags)
 {
 AVQSVFramesContext *hwctx = dst_ctx->hwctx;
 int i, err, index = -1;
@@ -2182,6 +2182,133 @@ static int qsv_map_to(AVHWFramesContext *dst_ctx,
 return 0;
 }
 
+static void qsv_dynamic_pool_unmap(AVHWFramesContext *ctx, HWMapDescriptor 
*hwmap)
+{
+mfxFrameSurface1 *surfaces_internal = (mfxFrameSurface1 *)hwmap->priv;
+mfxHDLPair *handle_pairs_internal = (mfxHDLPair 
*)surfaces_internal->Data.MemId;
+AVHWFramesContext *src_ctx = (AVHWFramesContext 
*)ffhwframesctx(ctx)->source_frames->data;
+
+switch (src_ctx->format) {
+#if CONFIG_VAAPI
+case AV_PIX_FMT_VAAPI:
+{
+av_freep(&handle_pairs_internal->first);
+
+break;
+}
+#endif
+
+#if CONFIG_D3D11VA
+case AV_PIX_FMT_D3D11:
+{
+/* Do nothing */
+break;
+}
+#endif
+default:
+av_log(ctx, AV_LOG_ERROR, "Should not reach here. \n");
+break;
+}
+
+av_freep(&handle_pairs_internal);
+av_freep(&surfaces_internal);
+}
+
+static int qsv_dynamic_pool_map_to(AVHWFramesContext *dst_ctx,
+   AVFrame *dst, const AVFrame *src, int flags)
+{
+mfxFrameSurface1 *surfaces_internal = NULL;
+mfxHDLPair *handle_pairs_internal = NULL;
+int ret = 0;
+
+surfaces_internal = av_calloc(1, sizeof(*surfaces_internal));
+if (!surfaces_internal) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+handle_pairs_internal = av_calloc(1, sizeof(*handle_pairs_internal));
+if (!handle_pairs_internal) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+ret = qsv_init_surface(dst_ctx, surfaces_internal);
+if (ret < 0)
+goto fail;
+
+switch (src->format) {
+#if CONFIG_VAAPI
+case AV_PIX_FMT_VAAPI:
+{
+VASurfaceID *surface_id_internal;
+
+surface_id_internal = av_calloc(1, sizeof(*surface_id_internal));
+if (!surface_id_internal) {
+ret =AVERROR(ENOMEM);
+goto fail;
+}
+
+*surface_id_internal = (VASurfaceID)(uintptr_t)src->data[3];
+handle_pairs_internal->first = (mfxHDL)surface_id_internal;
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+
+break;
+}
+#endif
+
+#if CONFIG_D3D11VA
+case AV_PIX_FMT_D3D11:
+{
+AVHWFramesContext *src_ctx = 
(AVHWFramesContext*)src->hw_frames_ctx->data;
+AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx;
+
+handle_pairs_internal->first = (mfxMemId)src->data[0];
+
+if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) {
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+} else {
+handle_pairs_internal->second = (mfxMemId)src->data[1];
+}
+
+break;
+}
+#endif
+default:
+ret = AVERROR(ENOSYS);
+goto fail;
+}
+
+surfaces_internal->Data.MemId = (mfxMemId)handle_pairs_internal;
+
+ret = ff_hwframe_map_create(dst->hw_frames_ctx,
+dst, src, qsv_dynamic_pool_unmap, 
surfaces_internal);
+if (ret)
+goto fail;
+
+dst->width   = src->width;
+dst->height  = src->height;
+dst->data[3] = (uint8_t*)surfaces_internal;
+
+return 0;
+
+fail:
+av_freep(&handle_pairs_internal);
+av_freep(&surfaces_internal);
+return ret;
+}
+
+static int qsv_map_to(AVHWFramesContext *dst_ctx,
+  AVFrame *dst, const AVFrame *src, int flags)
+{
+AVQSVFramesContext *hwctx = dst_ctx->hwctx;
+
+if (hwctx->nb_surfaces)
+return qsv_fixed_pool_map_to(dst_ctx, dst, src, flags);
+else
+return qsv_dynamic_pool_map_to(dst_ctx, dst, src, flags);
+}
+
 static int qsv_frames_get_constraints(AVHWDeviceContext *ctx,
   const void *hwconfig,
   AVHWFramesConstraints *constraints)
-- 
2.34.1

___
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/9] lavu/hwcontext_qsv: add support for dynamic frame pool in qsv_frames_derive_to

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

Make it work with the source which has a dynamic frame pool.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 61 ++-
 1 file changed, 54 insertions(+), 7 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 01bd273a08..1d3091e6f8 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1972,18 +1972,52 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 return 0;
 }
 
-static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
-AVHWFramesContext *src_ctx, int flags)
+static int qsv_dynamic_frames_derive_to(AVHWFramesContext *dst_ctx,
+AVHWFramesContext *src_ctx, int flags)
 {
 QSVFramesContext *s = dst_ctx->hwctx;
 AVQSVFramesContext *dst_hwctx = &s->p;
-int i;
+mfxFrameSurface1 mfx_surf1;
 
-if (src_ctx->initial_pool_size == 0) {
-av_log(dst_ctx, AV_LOG_ERROR, "Only fixed-size pools can be "
-"mapped to QSV frames.\n");
-return AVERROR(EINVAL);
+switch (src_ctx->device_ctx->type) {
+#if CONFIG_VAAPI
+case AV_HWDEVICE_TYPE_VAAPI:
+dst_hwctx->frame_type  = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
+break;
+#endif
+
+#if CONFIG_D3D11VA
+case AV_HWDEVICE_TYPE_D3D11VA:
+{
+AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx;
+
+if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) {
+dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
+} else {
+dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
+}
 }
+break;
+#endif
+
+default:
+return AVERROR(ENOSYS);
+}
+
+memset(&mfx_surf1, 0, sizeof(mfx_surf1));
+qsv_init_surface(dst_ctx, &mfx_surf1);
+s->frame_info = mfx_surf1.Info;
+dst_hwctx->info = &s->frame_info;
+dst_hwctx->nb_surfaces = 0;
+return 0;
+}
+
+static int qsv_fixed_frames_derive_to(AVHWFramesContext *dst_ctx,
+  AVHWFramesContext *src_ctx, int flags)
+{
+QSVFramesContext *s = dst_ctx->hwctx;
+AVQSVFramesContext *dst_hwctx = &s->p;
+int i;
 
 switch (src_ctx->device_ctx->type) {
 #if CONFIG_VAAPI
@@ -2075,6 +2109,19 @@ static int qsv_frames_derive_to(AVHWFramesContext 
*dst_ctx,
 return 0;
 }
 
+static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
+AVHWFramesContext *src_ctx, int flags)
+{
+if (src_ctx->initial_pool_size < 0) {
+av_log(dst_ctx, AV_LOG_ERROR, "Invalid src frame pool. \n");
+return AVERROR(EINVAL);
+} else if (src_ctx->initial_pool_size == 0) {
+return qsv_dynamic_frames_derive_to(dst_ctx, src_ctx, flags);
+} else {
+return qsv_fixed_frames_derive_to(dst_ctx, src_ctx, flags);
+}
+}
+
 static int qsv_map_to(AVHWFramesContext *dst_ctx,
   AVFrame *dst, const AVFrame *src, int flags)
 {
-- 
2.34.1

___
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/9] lavu/hwcontext_qsv: create dynamic frame pool if required

2024-04-28 Thread Xiang, Haihao
From: Haihao Xiang 

When AVHWFramesContext.initial_pool_size is 0, a dynamic frame pool is
required. We may support this under certain conditions, e.g. oneVPL 2.9+
support dynamic frame allocation, we needn't provide a fixed frame pool
in the mfxFrameAllocator.Alloc callback.

Signed-off-by: Haihao Xiang 
---
 libavutil/hwcontext_qsv.c | 157 +-
 1 file changed, 154 insertions(+), 3 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index f552811346..01bd273a08 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -118,8 +118,15 @@ typedef struct QSVFramesContext {
 #endif
 AVFrame realigned_upload_frame;
 AVFrame realigned_download_frame;
+
+mfxFrameInfo frame_info;
 } QSVFramesContext;
 
+typedef struct QSVSurface {
+mfxFrameSurface1 mfx_surface;
+AVFrame *child_frame;
+} QSVSurface;
+
 static const struct {
 enum AVPixelFormat pix_fmt;
 uint32_t   fourcc;
@@ -165,6 +172,8 @@ extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 
*surf,
   enum AVHWDeviceType base_dev_type,
   void **base_handle);
 
+static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf);
+
 /**
  * Caller needs to allocate enough space for base_handle pointer.
  **/
@@ -373,7 +382,32 @@ static void qsv_pool_release_dummy(void *opaque, uint8_t 
*data)
 {
 }
 
-static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size)
+static void qsv_pool_release(void *opaque, uint8_t *data)
+{
+AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
+QSVFramesContext *s = ctx->hwctx;
+QSVSurface *qsv_surface = (QSVSurface *)data;
+mfxHDLPair *hdl_pair = (mfxHDLPair *)qsv_surface->mfx_surface.Data.MemId;
+AVHWFramesContext *child_frames_ctx;
+
+if (!s->child_frames_ref)
+return;
+
+child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
+if (!child_frames_ctx->device_ctx)
+return;
+
+#if CONFIG_VAAPI
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI)
+av_freep(&hdl_pair->first);
+#endif
+
+av_freep(&hdl_pair);
+av_frame_free(&qsv_surface->child_frame);
+av_freep(&qsv_surface);
+}
+
+static AVBufferRef *qsv_fixed_pool_alloc(void *opaque, size_t size)
 {
 AVHWFramesContext*ctx = (AVHWFramesContext*)opaque;
 QSVFramesContext   *s = ctx->hwctx;
@@ -388,6 +422,104 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, size_t 
size)
 return NULL;
 }
 
+static AVBufferRef *qsv_dynamic_pool_alloc(void *opaque, size_t size)
+{
+AVHWFramesContext*ctx = (AVHWFramesContext*)opaque;
+QSVFramesContext   *s = ctx->hwctx;
+AVHWFramesContext *child_frames_ctx;
+QSVSurface *qsv_surface = NULL;
+mfxHDLPair *handle_pairs_internal = NULL;
+int ret;
+
+if (!s->child_frames_ref)
+goto fail;
+
+child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
+if (!child_frames_ctx->device_ctx)
+goto fail;
+
+#if CONFIG_DXVA2
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_DXVA2) {
+av_log(ctx, AV_LOG_ERROR,
+   "QSV on dxva2 requires a fixed frame pool size\n");
+goto fail;
+}
+#endif
+
+qsv_surface = av_calloc(1, sizeof(*qsv_surface));
+if (!qsv_surface)
+goto fail;
+
+qsv_surface->child_frame = av_frame_alloc();
+if (!qsv_surface->child_frame)
+goto fail;
+
+ret = av_hwframe_get_buffer(s->child_frames_ref, qsv_surface->child_frame, 
0);
+if (ret < 0)
+goto fail;
+
+handle_pairs_internal = av_calloc(1, sizeof(*handle_pairs_internal));
+if (!handle_pairs_internal)
+goto fail;
+
+ret = qsv_init_surface(ctx, &qsv_surface->mfx_surface);
+if (ret < 0)
+goto fail;
+
+#if CONFIG_VAAPI
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_VAAPI) {
+VASurfaceID *surface_id_internal;
+
+surface_id_internal = av_calloc(1, sizeof(*surface_id_internal));
+if (!surface_id_internal)
+goto fail;
+
+*surface_id_internal = 
(VASurfaceID)(uintptr_t)qsv_surface->child_frame->data[3];
+handle_pairs_internal->first = (mfxHDL)surface_id_internal;
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+}
+#endif
+
+#if CONFIG_D3D11VA
+if (child_frames_ctx->device_ctx->type == AV_HWDEVICE_TYPE_D3D11VA) {
+AVD3D11VAFramesContext *child_frames_hwctx = child_frames_ctx->hwctx;
+handle_pairs_internal->first = 
(mfxMemId)qsv_surface->child_frame->data[0];
+
+if (child_frames_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET)
+handle_pairs_internal->second = (mfxMemId)MFX_INFINITE;
+else
+handle_pairs_internal->second = 
(mfxMemId)qsv_surface->child_frame->data[1];
+
+}
+#endif
+
+qsv_surface->mfx_surface.Data.MemId = (mfxMemId)handle_pairs_internal

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

2024-04-28 Thread Xiang, Haihao
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;
+};
+
+/**
+ * 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;
 
 /**
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, \
-- 
2.34.1

___
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_av1: Avoid sending the same slice buffer multiple times

2024-04-28 Thread David Rosca
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(-)

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;
 
-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));
+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 = {
-- 
2.44.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/vaapi_decode: Make it possible to send multiple slice params buffers

2024-04-28 Thread David Rosca
---
 libavcodec/vaapi_av1.c| 2 +-
 libavcodec/vaapi_decode.c | 3 ++-
 libavcodec/vaapi_decode.h | 1 +
 libavcodec/vaapi_h264.c   | 2 +-
 libavcodec/vaapi_hevc.c   | 4 ++--
 libavcodec/vaapi_mjpeg.c  | 2 +-
 libavcodec/vaapi_mpeg2.c  | 2 +-
 libavcodec/vaapi_mpeg4.c  | 2 +-
 libavcodec/vaapi_vc1.c| 2 +-
 libavcodec/vaapi_vp8.c| 2 +-
 libavcodec/vaapi_vp9.c| 2 +-
 11 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index 1f563483b9..4a90db1e09 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -409,7 +409,7 @@ static int vaapi_av1_decode_slice(AVCodecContext *avctx,
 .tg_end= s->tg_end,
 };
 
-err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param,
+err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &slice_param, 1,
 
sizeof(VASliceParameterBufferAV1),
 buffer,
 size);
diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 21b273cd0f..8e9f647c20 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -63,6 +63,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
 int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
   VAAPIDecodePicture *pic,
   const void *params_data,
+  int nb_params,
   size_t params_size,
   const void *slice_data,
   size_t slice_size)
@@ -88,7 +89,7 @@ int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
 
 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
  VASliceParameterBufferType,
- params_size, 1, (void*)params_data,
+ params_size, nb_params, (void*)params_data,
  &pic->slice_buffers[index]);
 if (vas != VA_STATUS_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Failed to create slice "
diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h
index 6beda14e52..702171e108 100644
--- a/libavcodec/vaapi_decode.h
+++ b/libavcodec/vaapi_decode.h
@@ -73,6 +73,7 @@ int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
 int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx,
   VAAPIDecodePicture *pic,
   const void *params_data,
+  int nb_params,
   size_t params_size,
   const void *slice_data,
   size_t slice_size);
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
index 55cf5a05ee..b47531ce1c 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -375,7 +375,7 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
slice_param.chroma_offset_l1);
 
 err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
-&slice_param, sizeof(slice_param),
+&slice_param, 1, 
sizeof(slice_param),
 buffer, size);
 if (err) {
 ff_vaapi_decode_cancel(avctx, pic);
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 3bdd2dd1b8..3937b7574a 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -353,7 +353,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx)
 if (pic->last_size) {
 last_slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
 ret = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
-&pic->last_slice_param, 
slice_param_size,
+&pic->last_slice_param, 1, 
slice_param_size,
 pic->last_buffer, 
pic->last_size);
 if (ret < 0)
 goto fail;
@@ -471,7 +471,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
 
 if (!sh->first_slice_in_pic_flag) {
 err = ff_vaapi_decode_make_slice_buffer(avctx, &pic->pic,
-&pic->last_slice_param, 
slice_param_size,
+&pic->last_slice_param, 1, 
slice_param_size,
 pic->last_buffer, 
pic->last_size);
 pic->last_buffer = NULL;
 pic->last_size   = 0;
diff --git a/libavcodec/vaapi_mjpeg.c b/libavcodec/vaapi_mjpeg.c
index 5b8d47bb2a..9557cf5f9b 100644
--- a/libavcodec/vaapi_mjpeg.c
+++ b/libavcodec/vaapi_mjpeg.c
@@ -131,7 +131,7 @@ static int vaapi_mjpe