[FFmpeg-devel] [PATCH 1/2] lavc/qsvenc: always allocate the array to store mfxExtBuffer points
Xiang, Haihao
haihao.xiang at intel.com
Thu Feb 29 07:34:33 EET 2024
From: Haihao Xiang <haihao.xiang at intel.com>
This allows us to append mfxExtBuffer per user's settings
Signed-off-by: Haihao Xiang <haihao.xiang at intel.com>
---
libavcodec/qsvenc.c | 44 +++++++++++++++++++++++++-------------------
libavcodec/qsvenc.h | 1 +
2 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index c63b72e384..27e0e7ee71 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1608,6 +1608,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
int iopattern = 0;
int opaque_alloc = 0;
int ret;
+ void *tmp;
q->param.AsyncDepth = q->async_depth;
@@ -1668,35 +1669,40 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
if (ret < 0)
return ret;
+ tmp = av_realloc_array(q->extparam, q->nb_extparam_internal, sizeof(*q->extparam));
+ if (!tmp)
+ return AVERROR(ENOMEM);
+
+ q->extparam = tmp;
+ q->nb_extparam = q->nb_extparam_internal;
+ memcpy(q->extparam, q->extparam_internal, q->nb_extparam * sizeof(*q->extparam));
+
if (avctx->hwaccel_context) {
AVQSVContext *qsv = avctx->hwaccel_context;
int i, j;
- q->extparam = av_calloc(qsv->nb_ext_buffers + q->nb_extparam_internal,
- sizeof(*q->extparam));
- if (!q->extparam)
- return AVERROR(ENOMEM);
-
- q->param.ExtParam = q->extparam;
- for (i = 0; i < qsv->nb_ext_buffers; i++)
- q->param.ExtParam[i] = qsv->ext_buffers[i];
- q->param.NumExtParam = qsv->nb_ext_buffers;
-
- for (i = 0; i < q->nb_extparam_internal; i++) {
- for (j = 0; j < qsv->nb_ext_buffers; j++) {
- if (qsv->ext_buffers[j]->BufferId == q->extparam_internal[i]->BufferId)
+ for (i = 0; i < qsv->nb_ext_buffers; i++) {
+ for (j = 0; j < q->nb_extparam_internal; j++) {
+ if (qsv->ext_buffers[i]->BufferId == q->extparam_internal[j]->BufferId) {
+ q->extparam[j] = qsv->ext_buffers[i];
break;
+ }
}
- if (j < qsv->nb_ext_buffers)
- continue;
- q->param.ExtParam[q->param.NumExtParam++] = q->extparam_internal[i];
+ if (j == q->nb_extparam_internal) {
+ tmp = av_realloc_array(q->extparam, q->nb_extparam + 1, sizeof(*q->extparam));
+ if (!tmp)
+ return AVERROR(ENOMEM);
+
+ q->extparam = tmp;
+ q->extparam[q->nb_extparam++] = qsv->ext_buffers[i];
+ }
}
- } else {
- q->param.ExtParam = q->extparam_internal;
- q->param.NumExtParam = q->nb_extparam_internal;
}
+ q->param.ExtParam = q->extparam;
+ q->param.NumExtParam = q->nb_extparam;
+
ret = MFXVideoENCODE_Query(q->session, &q->param, &q->param);
if (ret == MFX_WRN_PARTIAL_ACCELERATION) {
av_log(avctx, AV_LOG_WARNING, "Encoder will work with partial HW acceleration\n");
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index c71bf2ed50..f2f0687bfe 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -196,6 +196,7 @@ typedef struct QSVEncContext {
int nb_extparam_internal;
mfxExtBuffer **extparam;
+ int nb_extparam;
AVFifo *async_fifo;
--
2.34.1
More information about the ffmpeg-devel
mailing list