Ticket #11426: qsv_decode_flush_fix.diff

File qsv_decode_flush_fix.diff, 2.1 KB (added by Aleksoid1978, 18 months ago)

qsv_decode_flush_fix

  • libavcodec/qsvdec.c

    diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
    index 19fa791..b238a52 100644
    a b typedef struct QSVContext {  
    104104    int suggest_pool_size;
    105105    int initialized;
    106106
     107    int flush;
     108
    107109    // options set by the caller
    108110    int async_depth;
    109111    int iopattern;
    static int qsv_decode_init_context(AVCodecContext *avctx, QSVContext *q, mfxVide  
    412414
    413415    q->frame_info = param->mfx.FrameInfo;
    414416
     417    q->flush = 0;
     418
    415419    if (!avctx->hw_frames_ctx) {
    416420        ret = av_image_get_buffer_size(avctx->pix_fmt, FFALIGN(avctx->coded_width, 128), FFALIGN(avctx->coded_height, 64), 1);
    417421        if (ret < 0)
    static int qsv_process_data(AVCodecContext *avctx, QSVContext *q,  
    10571061        q->initialized = 1;
    10581062    }
    10591063
     1064    if (q->flush) {
     1065        q->reinit_flag = 0;
     1066        ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
     1067        if (ret < 0) {
     1068            if (ret == AVERROR(EAGAIN))
     1069                av_log(avctx, AV_LOG_VERBOSE, "More data is required to decode header\n");
     1070            else
     1071                av_log(avctx, AV_LOG_ERROR, "Error decoding header\n");
     1072            goto reinit_fail;
     1073        }
     1074
     1075        q->orig_pix_fmt = avctx->pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
     1076        q->flush = 0;
     1077    }
     1078
    10601079    return qsv_decode(avctx, q, frame, got_frame, pkt);
    10611080
    10621081reinit_fail:
    static void qsv_decode_flush(AVCodecContext *avctx)  
    12091228
    12101229    qsv_clear_buffers(s);
    12111230
     1231    if (s->qsv.session) {
     1232        mfxVideoParam param = { 0 };
     1233
     1234        int ret = MFXVideoDECODE_GetVideoParam(s->qsv.session, &param);
     1235        if (ret < 0) {
     1236            ff_qsv_print_error(avctx, ret, "MFX decode get param error");
     1237            return;
     1238        }
     1239
     1240        ret = MFXVideoDECODE_Reset(s->qsv.session, &param);
     1241        if (ret < 0) {
     1242            ff_qsv_print_error(avctx, ret, "MFX decode reset error");
     1243            return;
     1244        }
     1245    }
     1246
    12121247    s->qsv.orig_pix_fmt = AV_PIX_FMT_NONE;
    1213     s->qsv.initialized = 0;
     1248    s->qsv.flush = 1;
    12141249}
    12151250
    12161251#define OFFSET(x) offsetof(QSVDecContext, x)