mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
lavc/qsvenc: add quality status to side_data
Add fix a memory leak issue as James's comments. V2: use a local pict_type since coded_frame is deprecated. Signed-off-by: Zhong Li <zhong.li@intel.com>
This commit is contained in:
parent
7e0df5910e
commit
900487043b
@ -1175,6 +1175,8 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
|
|||||||
enc_info->Header.BufferSz = sizeof (*enc_info);
|
enc_info->Header.BufferSz = sizeof (*enc_info);
|
||||||
bs->NumExtParam = 1;
|
bs->NumExtParam = 1;
|
||||||
enc_buf = av_mallocz(sizeof(mfxExtBuffer *));
|
enc_buf = av_mallocz(sizeof(mfxExtBuffer *));
|
||||||
|
if (!enc_buf)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
enc_buf[0] = (mfxExtBuffer *)enc_info;
|
enc_buf[0] = (mfxExtBuffer *)enc_info;
|
||||||
|
|
||||||
bs->ExtParam = enc_buf;
|
bs->ExtParam = enc_buf;
|
||||||
@ -1189,8 +1191,10 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
|
|||||||
if (!sync) {
|
if (!sync) {
|
||||||
av_freep(&bs);
|
av_freep(&bs);
|
||||||
#if QSV_VERSION_ATLEAST(1, 26)
|
#if QSV_VERSION_ATLEAST(1, 26)
|
||||||
if (avctx->codec_id == AV_CODEC_ID_H264)
|
if (avctx->codec_id == AV_CODEC_ID_H264) {
|
||||||
av_freep(&enc_info);
|
av_freep(&enc_info);
|
||||||
|
av_freep(&enc_buf);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
av_packet_unref(&new_pkt);
|
av_packet_unref(&new_pkt);
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
@ -1209,8 +1213,10 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
|
|||||||
av_packet_unref(&new_pkt);
|
av_packet_unref(&new_pkt);
|
||||||
av_freep(&bs);
|
av_freep(&bs);
|
||||||
#if QSV_VERSION_ATLEAST(1, 26)
|
#if QSV_VERSION_ATLEAST(1, 26)
|
||||||
if (avctx->codec_id == AV_CODEC_ID_H264)
|
if (avctx->codec_id == AV_CODEC_ID_H264) {
|
||||||
av_freep(&enc_info);
|
av_freep(&enc_info);
|
||||||
|
av_freep(&enc_buf);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
av_freep(&sync);
|
av_freep(&sync);
|
||||||
return (ret == MFX_ERR_MORE_DATA) ?
|
return (ret == MFX_ERR_MORE_DATA) ?
|
||||||
@ -1229,8 +1235,10 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
|
|||||||
av_packet_unref(&new_pkt);
|
av_packet_unref(&new_pkt);
|
||||||
av_freep(&bs);
|
av_freep(&bs);
|
||||||
#if QSV_VERSION_ATLEAST(1, 26)
|
#if QSV_VERSION_ATLEAST(1, 26)
|
||||||
if (avctx->codec_id == AV_CODEC_ID_H264)
|
if (avctx->codec_id == AV_CODEC_ID_H264) {
|
||||||
av_freep(&enc_info);
|
av_freep(&enc_info);
|
||||||
|
av_freep(&enc_buf);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1253,7 +1261,9 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
|
|||||||
mfxSyncPoint *sync;
|
mfxSyncPoint *sync;
|
||||||
#if QSV_VERSION_ATLEAST(1, 26)
|
#if QSV_VERSION_ATLEAST(1, 26)
|
||||||
mfxExtAVCEncodedFrameInfo *enc_info;
|
mfxExtAVCEncodedFrameInfo *enc_info;
|
||||||
|
mfxExtBuffer **enc_buf;
|
||||||
#endif
|
#endif
|
||||||
|
enum AVPictureType pict_type;
|
||||||
|
|
||||||
av_fifo_generic_read(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL);
|
av_fifo_generic_read(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL);
|
||||||
av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
|
av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL);
|
||||||
@ -1271,23 +1281,27 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,
|
|||||||
bs->FrameType & MFX_FRAMETYPE_xIDR)
|
bs->FrameType & MFX_FRAMETYPE_xIDR)
|
||||||
new_pkt.flags |= AV_PKT_FLAG_KEY;
|
new_pkt.flags |= AV_PKT_FLAG_KEY;
|
||||||
|
|
||||||
|
if (bs->FrameType & MFX_FRAMETYPE_I || bs->FrameType & MFX_FRAMETYPE_xI)
|
||||||
|
pict_type = AV_PICTURE_TYPE_I;
|
||||||
|
else if (bs->FrameType & MFX_FRAMETYPE_P || bs->FrameType & MFX_FRAMETYPE_xP)
|
||||||
|
pict_type = AV_PICTURE_TYPE_P;
|
||||||
|
else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType & MFX_FRAMETYPE_xB)
|
||||||
|
pict_type = AV_PICTURE_TYPE_B;
|
||||||
|
|
||||||
#if FF_API_CODED_FRAME
|
#if FF_API_CODED_FRAME
|
||||||
FF_DISABLE_DEPRECATION_WARNINGS
|
FF_DISABLE_DEPRECATION_WARNINGS
|
||||||
if (bs->FrameType & MFX_FRAMETYPE_I || bs->FrameType & MFX_FRAMETYPE_xI)
|
avctx->coded_frame->pict_type = pict_type;
|
||||||
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
|
|
||||||
else if (bs->FrameType & MFX_FRAMETYPE_P || bs->FrameType & MFX_FRAMETYPE_xP)
|
|
||||||
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P;
|
|
||||||
else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType & MFX_FRAMETYPE_xB)
|
|
||||||
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B;
|
|
||||||
FF_ENABLE_DEPRECATION_WARNINGS
|
FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if QSV_VERSION_ATLEAST(1, 26)
|
#if QSV_VERSION_ATLEAST(1, 26)
|
||||||
if (avctx->codec_id == AV_CODEC_ID_H264) {
|
if (avctx->codec_id == AV_CODEC_ID_H264) {
|
||||||
|
enc_buf = bs->ExtParam;
|
||||||
enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam);
|
enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam);
|
||||||
av_log(avctx, AV_LOG_DEBUG, "QP is %d\n", enc_info->QP);
|
ff_side_data_set_encoder_stats(&new_pkt,
|
||||||
q->sum_frame_qp += enc_info->QP;
|
enc_info->QP * FF_QP2LAMBDA, NULL, 0, pict_type);
|
||||||
av_freep(&enc_info);
|
av_freep(&enc_info);
|
||||||
|
av_freep(&enc_buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
av_freep(&bs);
|
av_freep(&bs);
|
||||||
|
@ -103,8 +103,6 @@ typedef struct QSVEncContext {
|
|||||||
int width_align;
|
int width_align;
|
||||||
int height_align;
|
int height_align;
|
||||||
|
|
||||||
int sum_frame_qp;
|
|
||||||
|
|
||||||
mfxVideoParam param;
|
mfxVideoParam param;
|
||||||
mfxFrameAllocRequest req;
|
mfxFrameAllocRequest req;
|
||||||
|
|
||||||
|
@ -94,11 +94,6 @@ static av_cold int qsv_enc_close(AVCodecContext *avctx)
|
|||||||
{
|
{
|
||||||
QSVH264EncContext *q = avctx->priv_data;
|
QSVH264EncContext *q = avctx->priv_data;
|
||||||
|
|
||||||
#if QSV_VERSION_ATLEAST(1, 26)
|
|
||||||
av_log(avctx, AV_LOG_VERBOSE, "encoded %d frames, avarge qp is %.2f\n",
|
|
||||||
avctx->frame_number,(double)q->qsv.sum_frame_qp / avctx->frame_number);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ff_qsv_enc_close(avctx, &q->qsv);
|
return ff_qsv_enc_close(avctx, &q->qsv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user