+//This code is only required for Linux since a display handle is required.
+//For Windows the session is complete and ready to use.
+
+#ifdef AVCODEC_QSV_LINUX_SESSION_HANDLE
+static int ff_qsv_set_display_handle(AVCodecContext *avctx, QSVSession *qs)
+{
+ AVDictionary *child_device_opts = NULL;
+ AVVAAPIDeviceContext *hwctx;
+ int ret;
+
+ av_dict_set(&child_device_opts, "kernel_driver", "i915", 0);
+ av_dict_set(&child_device_opts, "driver", "iHD", 0);
+
+ ret = av_hwdevice_ctx_create(&qs->va_device_ref, AV_HWDEVICE_TYPE_VAAPI, NULL, child_device_opts, 0);
+ av_dict_free(&child_device_opts);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to create a VAAPI device.\n");
+ return ret;
+ } else {
+ qs->va_device_ctx = (AVHWDeviceContext*)qs->va_device_ref->data;
+ hwctx = qs->va_device_ctx->hwctx;
+
+ ret = MFXVideoCORE_SetHandle(qs->session,
+ (mfxHandleType)MFX_HANDLE_VA_DISPLAY, (mfxHDL)hwctx->display);
+ if (ret < 0) {
+ return ff_qsv_print_error(avctx, ret, "Error during set display handle\n");
+ }
+ }
+
+ return 0;
+}
+#endif //AVCODEC_QSV_LINUX_SESSION_HANDLE
+
+int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs,
+ const char *load_plugins, int gpu_copy)