diff options
author | Anton Khirnov <anton@khirnov.net> | 2015-08-05 15:22:34 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2015-10-16 20:00:02 +0200 |
commit | 772c87c5a658f36d7c0612f5da583fc2bfa54f79 (patch) | |
tree | 4a7e02420a44101d79d8029c5a60d644daa83eeb | |
parent | 68e00ad66d13c57d9eb3a3862b44ab3fb030e19f (diff) | |
download | ffmpeg-772c87c5a658f36d7c0612f5da583fc2bfa54f79.tar.gz |
qsvenc: support passing arbitrary external buffers to the encoder
-rw-r--r-- | libavcodec/qsvenc.c | 36 | ||||
-rw-r--r-- | libavcodec/qsvenc.h | 3 |
2 files changed, 34 insertions, 5 deletions
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index d6a731f416..7a57d441b0 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -134,10 +134,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) q->extco.CAVLC = avctx->coder_type == FF_CODER_TYPE_VLC ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN; - q->extparam[0] = (mfxExtBuffer *)&q->extco; - - q->param.ExtParam = q->extparam; - q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam); + q->extparam_internal[0] = (mfxExtBuffer *)&q->extco; } return 0; @@ -228,6 +225,35 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) return ff_qsv_error(ret); } + if (avctx->hwaccel_context) { + AVQSVContext *qsv = avctx->hwaccel_context; + int i, j; + + q->extparam = av_mallocz_array(qsv->nb_ext_buffers + FF_ARRAY_ELEMS(q->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 < FF_ARRAY_ELEMS(q->extparam_internal); i++) { + for (j = 0; j < qsv->nb_ext_buffers; j++) { + if (qsv->ext_buffers[j]->BufferId == q->extparam_internal[i]->BufferId) + break; + } + if (j < qsv->nb_ext_buffers) + continue; + + q->param.ExtParam[q->param.NumExtParam++] = q->extparam_internal[i]; + } + } else { + q->param.ExtParam = q->extparam_internal; + q->param.NumExtParam = FF_ARRAY_ELEMS(q->extparam_internal); + } + ret = MFXVideoENCODE_Init(q->session, &q->param); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error initializing the encoder\n"); @@ -512,5 +538,7 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) av_fifo_free(q->async_fifo); q->async_fifo = NULL; + av_freep(&q->extparam); + return 0; } diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index 7bbeec33aa..d240c7c7cb 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -49,7 +49,8 @@ typedef struct QSVEncContext { mfxFrameAllocRequest req; mfxExtCodingOption extco; - mfxExtBuffer *extparam[1]; + mfxExtBuffer *extparam_internal[1]; + mfxExtBuffer **extparam; AVFifoBuffer *async_fifo; |