static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags) { QSVDevicePriv *priv; enum AVHWDeviceType child_device_type; AVHWDeviceContext *child_device; AVDictionaryEntry *e; mfxIMPL impl; int ret; priv = av_mallocz(sizeof(*priv)); if (!priv) return AVERROR(ENOMEM); ctx->user_opaque = priv; ctx->free = qsv_device_free; e = av_dict_get(opts, "child_device", NULL, 0); if (CONFIG_VAAPI) child_device_type = AV_HWDEVICE_TYPE_VAAPI; else if (CONFIG_DXVA2) child_device_type = AV_HWDEVICE_TYPE_DXVA2; else { av_log(ctx, AV_LOG_ERROR, "No supported child device type is enabled\n"); return AVERROR(ENOSYS); } ret = av_hwdevice_ctx_create(&priv->child_device_ctx, child_device_type, e ? e->value : NULL, NULL, 0); if (ret < 0) return ret; child_device = (AVHWDeviceContext*)priv->child_device_ctx->data; impl = choose_implementation(device); return qsv_device_derive_from_child(ctx, impl, child_device, 0); }
static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags) { AVQSVDeviceContext *hwctx = ctx->hwctx; QSVDevicePriv *priv; enum AVHWDeviceType child_device_type; AVDictionaryEntry *e; mfxVersion ver = { { 3, 1 } }; mfxIMPL impl; mfxHDL handle; mfxHandleType handle_type; mfxStatus err; int ret; priv = av_mallocz(sizeof(*priv)); if (!priv) return AVERROR(ENOMEM); ctx->user_opaque = priv; ctx->free = qsv_device_free; e = av_dict_get(opts, "child_device", NULL, 0); if (CONFIG_VAAPI) child_device_type = AV_HWDEVICE_TYPE_VAAPI; else if (CONFIG_DXVA2) child_device_type = AV_HWDEVICE_TYPE_DXVA2; else { av_log(ctx, AV_LOG_ERROR, "No supported child device type is enabled\n"); return AVERROR(ENOSYS); } ret = av_hwdevice_ctx_create(&priv->child_device_ctx, child_device_type, e ? e->value : NULL, NULL, 0); if (ret < 0) return ret; { AVHWDeviceContext *child_device_ctx = (AVHWDeviceContext*)priv->child_device_ctx->data; #if CONFIG_VAAPI AVVAAPIDeviceContext *child_device_hwctx = child_device_ctx->hwctx; handle_type = MFX_HANDLE_VA_DISPLAY; handle = (mfxHDL)child_device_hwctx->display; #elif CONFIG_DXVA2 AVDXVA2DeviceContext *child_device_hwctx = child_device_ctx->hwctx; handle_type = MFX_HANDLE_D3D9_DEVICE_MANAGER; handle = (mfxHDL)child_device_hwctx->devmgr; #endif } impl = choose_implementation(device); err = MFXInit(impl, &ver, &hwctx->session); if (err != MFX_ERR_NONE) { av_log(ctx, AV_LOG_ERROR, "Error initializing an MFX session\n"); return AVERROR_UNKNOWN; } err = MFXVideoCORE_SetHandle(hwctx->session, handle_type, handle); if (err != MFX_ERR_NONE) return AVERROR_UNKNOWN; return 0; }