[FFmpeg-devel] [PATCH] avcodec/qsv: polling free synchronization

Fu, Linjie linjie.fu at intel.com
Thu Oct 10 05:45:59 EEST 2019


> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of
> Dmitry Rogozhkin
> Sent: Wednesday, October 9, 2019 21:28
> To: ffmpeg-devel at ffmpeg.org
> Cc: Orlov, Andrey <andrey.orlov at intel.com>
> Subject: [FFmpeg-devel] [PATCH] avcodec/qsv: polling free synchronization
> 
> From: Andrey Orlov <andrey.orlov at intel.com>
> 
> synchronization by sync point after DEVICE_BUSY
> 
> Fixes: CPU usage on AVC decode cases (18% -> 9%)
> ---
>  libavcodec/qsv.c          | 17 +++++++++++++++++
>  libavcodec/qsv_internal.h |  2 ++
>  libavcodec/qsvdec.c       | 12 ++++++++----
>  libavcodec/qsvdec.h       |  2 ++
>  libavcodec/qsvenc.c       | 13 +++++++++----
>  libavcodec/qsvenc.h       |  2 ++
>  6 files changed, 40 insertions(+), 8 deletions(-)
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -457,8 +457,12 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
> 
>          ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ?
> &bs : NULL,
>                                                insurf, &outsurf, sync);
> +
> +        if (ret == MFX_ERR_NONE)
> +            q->last_dec_sync = *sync;
> +
>          if (ret == MFX_WRN_DEVICE_BUSY)
> -            av_usleep(500);

Since av_usleep is removed, "libavutil/time.h" is redundant and should be removed as well.

> +            ff_qsv_handle_device_busy(&q->session, &q->last_dec_sync, &ret,
> 500);

If the value of sleep is hardcode to 500, is it still necessary to pass it as a parameter?

> 
>      } while (ret == MFX_WRN_DEVICE_BUSY || ret ==
> MFX_ERR_MORE_SURFACE);
> 
> @@ -510,9 +514,9 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
>          out_frame->queued = 0;
> 
>          if (avctx->pix_fmt != AV_PIX_FMT_QSV) {
> -            do {
> -                ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000);
> -            } while (ret == MFX_WRN_IN_EXECUTION);
> +            ret = MFXVideoCORE_SyncOperation(q->session, *sync,
> MFX_INFINITE);
> +            if (ret < 0)
> +                return ret;
>          }
> 
>          av_freep(&sync);
> diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h
> index dec1f61..d27ea68 100644
> --- a/libavcodec/qsvdec.h
> +++ b/libavcodec/qsvdec.h
> @@ -72,6 +72,8 @@ typedef struct QSVContext {
> 
>      mfxExtBuffer **ext_buffers;
>      int         nb_ext_buffers;
> +
> +    mfxSyncPoint last_dec_sync;
>  } QSVContext;
> 
>  extern const AVCodecHWConfigInternal *ff_qsv_hw_configs[];
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index ba85d64..bd5dd75 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -1368,8 +1368,13 @@ static int encode_frame(AVCodecContext *avctx,
> QSVEncContext *q,
> 
>      do {
>          ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf,
> bs, sync);
> +
> +        if (ret == MFX_ERR_NONE)
> +            q->last_enc_sync = *sync;
> +
>          if (ret == MFX_WRN_DEVICE_BUSY)
> -            av_usleep(500);

Same here.

- linjie


More information about the ffmpeg-devel mailing list