Quoting Mark Thompson (2017-03-05 00:57:43)
> ---
>  libavutil/hwcontext_qsv.c | 122 
> +++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 93 insertions(+), 29 deletions(-)
> 
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index 3409e9b97..2d202017d 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -792,19 +792,103 @@ static mfxIMPL choose_implementation(const char 
> *device)
>      return impl;
>  }
>  
> -static int qsv_device_create(AVHWDeviceContext *ctx, const char *device,
> -                             AVDictionary *opts, int flags)
> +static int qsv_device_derive_from_child(AVHWDeviceContext *ctx,
> +                                        mfxIMPL implementation,
> +                                        AVHWDeviceContext *child_device_ctx,
> +                                        int flags)
>  {
>      AVQSVDeviceContext *hwctx = ctx->hwctx;
> -    QSVDevicePriv *priv;
> -    enum AVHWDeviceType child_device_type;
> -    AVDictionaryEntry *e;
> +    QSVDeviceContext       *s = ctx->internal->priv;
>  
>      mfxVersion    ver = { { 3, 1 } };
> -    mfxIMPL       impl;
>      mfxHDL        handle;
>      mfxHandleType handle_type;
>      mfxStatus     err;
> +    enum AVPixelFormat child_pix_fmt;
> +    int ret;
> +
> +    switch (child_device_ctx->type) {
> +#if CONFIG_VAAPI
> +    case AV_HWDEVICE_TYPE_VAAPI:
> +        {
> +            AVVAAPIDeviceContext *child_device_hwctx = 
> child_device_ctx->hwctx;
> +            handle_type = MFX_HANDLE_VA_DISPLAY;
> +            handle = (mfxHDL)child_device_hwctx->display;
> +            child_pix_fmt = AV_PIX_FMT_VAAPI;
> +        }
> +        break;
> +#endif
> +#if CONFIG_DXVA2
> +    case AV_HWDEVICE_TYPE_DXVA2:
> +        {
> +            AVDXVA2DeviceContext *child_device_hwctx = 
> child_device_ctx->hwctx;
> +            handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER;
> +            handle = (mfxHDL)child_device_hwctx->devmgr;
> +            child_pix_fmt = AV_PIX_FMT_DXVA2_VLD;
> +        }
> +        break;
> +#endif
> +    default:
> +        ret = AVERROR(ENOSYS);
> +        goto fail;
> +    }
> +
> +    err = MFXInit(implementation, &ver, &hwctx->session);
> +    if (err != MFX_ERR_NONE) {
> +        av_log(ctx, AV_LOG_ERROR, "Error initializing an MFX session: "
> +               "%d.\n", err);
> +        ret = AVERROR_UNKNOWN;
> +        goto fail;
> +    }
> +
> +    err = MFXVideoCORE_SetHandle(hwctx->session, handle_type, handle);
> +    if (err != MFX_ERR_NONE) {
> +        av_log(ctx, AV_LOG_ERROR, "Error setting child device handle: "
> +               "%d\n", err);
> +        ret = AVERROR_UNKNOWN;
> +        goto fail;
> +    }
> +
> +    s->handle            = handle;
> +    s->handle_type       = handle_type;
> +    s->child_device_type = child_device_ctx->type;
> +    s->child_pix_fmt     = child_pix_fmt;
> +
> +    err = MFXQueryIMPL(hwctx->session, &s->impl);
> +    if (err == MFX_ERR_NONE)
> +        err = MFXQueryVersion(hwctx->session, &s->ver);
> +    if (err != MFX_ERR_NONE) {
> +        av_log(ctx, AV_LOG_ERROR, "Error querying the session attributes: "
> +               "%d\n", err);
> +        ret = AVERROR_UNKNOWN;
> +        goto fail;
> +    }
> +
> +

This is duplicated with init, perhaps it should be shared somehow?

nit: extra empty line

Otherwise looks ok.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to