diff mbox series

[FFmpeg-devel,v2,1/3] lavc/qsv: allow to add more parameter buffers to QSV frame

Message ID 20220124082455.30931-1-haihao.xiang@intel.com
State Accepted
Commit 8dd507bf0daa826691ea5960ed5634233518c57c
Headers show
Series [FFmpeg-devel,v2,1/3] lavc/qsv: allow to add more parameter buffers to QSV frame | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished

Commit Message

Xiang, Haihao Jan. 24, 2022, 8:24 a.m. UTC
From: Haihao Xiang <haihao.xiang@intel.com>

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
v2: rebased the patchset against the latest FFmpeg and added code to
make sure the corresponding extra parameter buffer is added for AV1
only.

 libavcodec/qsv.c          | 27 +++++++++++++++++++++++++++
 libavcodec/qsv_internal.h |  8 +++++++-
 libavcodec/qsvdec.c       |  8 +++++---
 3 files changed, 39 insertions(+), 4 deletions(-)

Comments

Xiang, Haihao Jan. 27, 2022, 5:37 a.m. UTC | #1
On Mon, 2022-01-24 at 16:24 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang <haihao.xiang@intel.com>
> 
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
> v2: rebased the patchset against the latest FFmpeg and added code to
> make sure the corresponding extra parameter buffer is added for AV1
> only.
> 
>  libavcodec/qsv.c          | 27 +++++++++++++++++++++++++++
>  libavcodec/qsv_internal.h |  8 +++++++-
>  libavcodec/qsvdec.c       |  8 +++++---
>  3 files changed, 39 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 9d08485c92..1a432dbd82 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -828,3 +828,30 @@ int ff_qsv_close_internal_session(QSVSession *qs)
>  #endif
>      return 0;
>  }
> +
> +void ff_qsv_frame_add_ext_param (AVCodecContext *avctx, QSVFrame *frame,
> +                                 mfxExtBuffer * param)
> +{
> +    int i;
> +
> +    for (i = 0; i < frame->num_ext_params; i++) {
> +        mfxExtBuffer *ext_buffer = frame->ext_param[i];
> +
> +        if (ext_buffer->BufferId == param->BufferId) {
> +            av_log(avctx, AV_LOG_WARNING, "A buffer with the same type has
> been "
> +                   "added\n");
> +            return;
> +        }
> +    }
> +
> +    if (frame->num_ext_params < QSV_MAX_FRAME_EXT_PARAMS) {
> +        frame->ext_param[frame->num_ext_params] = param;
> +        frame->num_ext_params++;
> +        frame->surface.Data.NumExtParam = frame->num_ext_params;
> +    } else {
> +        av_log(avctx, AV_LOG_WARNING, "Ignore this extra buffer because do
> not "
> +               "have enough space\n");
> +    }
> +
> +
> +}
> diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
> index fe9d5319c4..6a38e87d23 100644
> --- a/libavcodec/qsv_internal.h
> +++ b/libavcodec/qsv_internal.h
> @@ -52,6 +52,8 @@
>  
>  #define QSV_MAX_ENC_PAYLOAD 2       // # of mfxEncodeCtrl payloads supported
>  
> +#define QSV_MAX_FRAME_EXT_PARAMS 4
> +
>  #define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
>      (MFX_VERSION_MAJOR > (MAJOR) ||         \
>       MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
> @@ -74,7 +76,8 @@ typedef struct QSVFrame {
>      mfxFrameSurface1 surface;
>      mfxEncodeCtrl enc_ctrl;
>      mfxExtDecodedFrameInfo dec_info;
> -    mfxExtBuffer *ext_param;
> +    mfxExtBuffer *ext_param[QSV_MAX_FRAME_EXT_PARAMS];
> +    int num_ext_params;
>  
>      mfxPayload *payloads[QSV_MAX_ENC_PAYLOAD]; ///< used for enc_ctrl.Payload
>  
> @@ -138,4 +141,7 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx,
> mfxSession *session,
>  
>  int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame);
>  
> +void ff_qsv_frame_add_ext_param(AVCodecContext *avctx, QSVFrame *frame,
> +                                mfxExtBuffer *param);
> +
>  #endif /* AVCODEC_QSV_INTERNAL_H */
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index d9e0fef1f1..783d252002 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -423,11 +423,13 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext
> *q, QSVFrame *frame)
>  
>          frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
>      }
> -    frame->surface.Data.ExtParam    = &frame->ext_param;
> -    frame->surface.Data.NumExtParam = 1;
> -    frame->ext_param                = (mfxExtBuffer*)&frame->dec_info;
> +
> +    frame->surface.Data.ExtParam    = frame->ext_param;
> +    frame->surface.Data.NumExtParam = 0;
> +    frame->num_ext_params           = 0;
>      frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
>      frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
> +    ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer *)&frame-
> >dec_info);
>  
>      frame->used = 1;

Will apply

-Haihao

>
Timo Rothenpieler Jan. 29, 2022, 2:30 p.m. UTC | #2
On 27.01.2022 06:37, Xiang, Haihao wrote:
> Will apply
> 
> -Haihao
> 

Something in this patchset broke build on Windows:
https://github.com/BtbN/FFmpeg-Builds/runs/4991054208#step:4:9491
Timo Rothenpieler Jan. 29, 2022, 2:41 p.m. UTC | #3
On 29.01.2022 15:30, Timo Rothenpieler wrote:
> On 27.01.2022 06:37, Xiang, Haihao wrote:
>> Will apply
>>
>> -Haihao
>>
> 
> Something in this patchset broke build on Windows:
> https://github.com/BtbN/FFmpeg-Builds/runs/4991054208#step:4:9491

Seems like it really was the typo gcc suggests. Pushed a fix for it.
Xiang, Haihao Jan. 30, 2022, 1:02 a.m. UTC | #4
On Sat, 2022-01-29 at 15:41 +0100, Timo Rothenpieler wrote:
> On 29.01.2022 15:30, Timo Rothenpieler wrote:
> > On 27.01.2022 06:37, Xiang, Haihao wrote:
> > > Will apply
> > > 
> > > -Haihao
> > > 
> > 
> > Something in this patchset broke build on Windows:
> > https://github.com/BtbN/FFmpeg-Builds/runs/4991054208#step:4:9491
> 
> Seems like it really was the typo gcc suggests. Pushed a fix for it.

Sorry for this stupid error, and thanks for the patch, we'll check the ourinternal CI and review process. 

BRs
Haihao
diff mbox series

Patch

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 9d08485c92..1a432dbd82 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -828,3 +828,30 @@  int ff_qsv_close_internal_session(QSVSession *qs)
 #endif
     return 0;
 }
+
+void ff_qsv_frame_add_ext_param (AVCodecContext *avctx, QSVFrame *frame,
+                                 mfxExtBuffer * param)
+{
+    int i;
+
+    for (i = 0; i < frame->num_ext_params; i++) {
+        mfxExtBuffer *ext_buffer = frame->ext_param[i];
+
+        if (ext_buffer->BufferId == param->BufferId) {
+            av_log(avctx, AV_LOG_WARNING, "A buffer with the same type has been "
+                   "added\n");
+            return;
+        }
+    }
+
+    if (frame->num_ext_params < QSV_MAX_FRAME_EXT_PARAMS) {
+        frame->ext_param[frame->num_ext_params] = param;
+        frame->num_ext_params++;
+        frame->surface.Data.NumExtParam = frame->num_ext_params;
+    } else {
+        av_log(avctx, AV_LOG_WARNING, "Ignore this extra buffer because do not "
+               "have enough space\n");
+    }
+
+
+}
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index fe9d5319c4..6a38e87d23 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -52,6 +52,8 @@ 
 
 #define QSV_MAX_ENC_PAYLOAD 2       // # of mfxEncodeCtrl payloads supported
 
+#define QSV_MAX_FRAME_EXT_PARAMS 4
+
 #define QSV_VERSION_ATLEAST(MAJOR, MINOR)   \
     (MFX_VERSION_MAJOR > (MAJOR) ||         \
      MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
@@ -74,7 +76,8 @@  typedef struct QSVFrame {
     mfxFrameSurface1 surface;
     mfxEncodeCtrl enc_ctrl;
     mfxExtDecodedFrameInfo dec_info;
-    mfxExtBuffer *ext_param;
+    mfxExtBuffer *ext_param[QSV_MAX_FRAME_EXT_PARAMS];
+    int num_ext_params;
 
     mfxPayload *payloads[QSV_MAX_ENC_PAYLOAD]; ///< used for enc_ctrl.Payload
 
@@ -138,4 +141,7 @@  int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *session,
 
 int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame);
 
+void ff_qsv_frame_add_ext_param(AVCodecContext *avctx, QSVFrame *frame,
+                                mfxExtBuffer *param);
+
 #endif /* AVCODEC_QSV_INTERNAL_H */
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index d9e0fef1f1..783d252002 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -423,11 +423,13 @@  static int alloc_frame(AVCodecContext *avctx, QSVContext *q, QSVFrame *frame)
 
         frame->surface.Data.MemId = &q->frames_ctx.mids[ret];
     }
-    frame->surface.Data.ExtParam    = &frame->ext_param;
-    frame->surface.Data.NumExtParam = 1;
-    frame->ext_param                = (mfxExtBuffer*)&frame->dec_info;
+
+    frame->surface.Data.ExtParam    = frame->ext_param;
+    frame->surface.Data.NumExtParam = 0;
+    frame->num_ext_params           = 0;
     frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
     frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
+    ff_qsv_frame_add_ext_param(avctx, frame, (mfxExtBuffer *)&frame->dec_info);
 
     frame->used = 1;