Commit d071a111 authored by Zhong Li's avatar Zhong Li

lavc/qsvenc: get vps extradata from MSDK

Signed-off-by: 's avatarZhong Li <zhong.li@intel.com>
Reviewed-by: 's avatarMark Thompson <sw@jkqxz.net>
parent a8355eed
...@@ -810,22 +810,37 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) ...@@ -810,22 +810,37 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
}; };
#endif #endif
mfxExtBuffer *ext_buffers[] = { #if QSV_HAVE_CO_VPS
(mfxExtBuffer*)&extradata, uint8_t vps_buf[128];
(mfxExtBuffer*)&co, mfxExtCodingOptionVPS extradata_vps = {
.Header.BufferId = MFX_EXTBUFF_CODING_OPTION_VPS,
.Header.BufferSz = sizeof(extradata_vps),
.VPSBuffer = vps_buf,
.VPSBufSize = sizeof(vps_buf),
};
#endif
mfxExtBuffer *ext_buffers[2 + QSV_HAVE_CO2 + QSV_HAVE_CO3 + QSV_HAVE_CO_VPS];
int need_pps = avctx->codec_id != AV_CODEC_ID_MPEG2VIDEO;
int ret, ext_buf_num = 0, extradata_offset = 0;
ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata;
ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co;
#if QSV_HAVE_CO2 #if QSV_HAVE_CO2
(mfxExtBuffer*)&co2, ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co2;
#endif #endif
#if QSV_HAVE_CO3 #if QSV_HAVE_CO3
(mfxExtBuffer*)&co3, ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co3;
#endif
#if QSV_HAVE_CO_VPS
q->hevc_vps = ((avctx->codec_id == AV_CODEC_ID_HEVC) && QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 17));
if (q->hevc_vps)
ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata_vps;
#endif #endif
};
int need_pps = avctx->codec_id != AV_CODEC_ID_MPEG2VIDEO;
int ret;
q->param.ExtParam = ext_buffers; q->param.ExtParam = ext_buffers;
q->param.NumExtParam = FF_ARRAY_ELEMS(ext_buffers); q->param.NumExtParam = ext_buf_num;
ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param); ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param);
if (ret < 0) if (ret < 0)
...@@ -834,20 +849,37 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) ...@@ -834,20 +849,37 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000; q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000;
if (!extradata.SPSBufSize || (need_pps && !extradata.PPSBufSize)) { if (!extradata.SPSBufSize || (need_pps && !extradata.PPSBufSize)
#if QSV_HAVE_CO_VPS
|| (q->hevc_vps && !extradata_vps.VPSBufSize)
#endif
) {
av_log(avctx, AV_LOG_ERROR, "No extradata returned from libmfx.\n"); av_log(avctx, AV_LOG_ERROR, "No extradata returned from libmfx.\n");
return AVERROR_UNKNOWN; return AVERROR_UNKNOWN;
} }
avctx->extradata = av_malloc(extradata.SPSBufSize + need_pps * extradata.PPSBufSize + avctx->extradata_size = extradata.SPSBufSize + need_pps * extradata.PPSBufSize;
AV_INPUT_BUFFER_PADDING_SIZE); #if QSV_HAVE_CO_VPS
avctx->extradata_size += q->hevc_vps * extradata_vps.VPSBufSize;
#endif
avctx->extradata = av_malloc(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata) if (!avctx->extradata)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
memcpy(avctx->extradata, sps_buf, extradata.SPSBufSize); #if QSV_HAVE_CO_VPS
if (need_pps) if (q->hevc_vps) {
memcpy(avctx->extradata + extradata.SPSBufSize, pps_buf, extradata.PPSBufSize); memcpy(avctx->extradata, vps_buf, extradata_vps.VPSBufSize);
avctx->extradata_size = extradata.SPSBufSize + need_pps * extradata.PPSBufSize; extradata_offset += extradata_vps.VPSBufSize;
}
#endif
memcpy(avctx->extradata + extradata_offset, sps_buf, extradata.SPSBufSize);
extradata_offset += extradata.SPSBufSize;
if (need_pps) {
memcpy(avctx->extradata + extradata_offset, pps_buf, extradata.PPSBufSize);
extradata_offset += extradata.PPSBufSize;
}
memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
cpb_props = ff_add_cpb_side_data(avctx); cpb_props = ff_add_cpb_side_data(avctx);
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#define QSV_HAVE_CO2 QSV_VERSION_ATLEAST(1, 6) #define QSV_HAVE_CO2 QSV_VERSION_ATLEAST(1, 6)
#define QSV_HAVE_CO3 QSV_VERSION_ATLEAST(1, 11) #define QSV_HAVE_CO3 QSV_VERSION_ATLEAST(1, 11)
#define QSV_HAVE_CO_VPS QSV_VERSION_ATLEAST(1, 17)
#define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8) #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8)
#define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9) #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9)
...@@ -134,6 +135,8 @@ typedef struct QSVEncContext { ...@@ -134,6 +135,8 @@ typedef struct QSVEncContext {
mfxVersion ver; mfxVersion ver;
int hevc_vps;
// options set by the caller // options set by the caller
int async_depth; int async_depth;
int idr_interval; int idr_interval;
......
...@@ -194,11 +194,13 @@ static av_cold int qsv_enc_init(AVCodecContext *avctx) ...@@ -194,11 +194,13 @@ static av_cold int qsv_enc_init(AVCodecContext *avctx)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (!q->qsv.hevc_vps) {
ret = generate_fake_vps(&q->qsv, avctx); ret = generate_fake_vps(&q->qsv, avctx);
if (ret < 0) { if (ret < 0) {
ff_qsv_enc_close(avctx, &q->qsv); ff_qsv_enc_close(avctx, &q->qsv);
return ret; return ret;
} }
}
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment