From 72e71b67c419960b5bca15af8a85219d54230fe3 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Tue, 12 Mar 2019 13:57:17 -0600 Subject: qsv: add i965 VA driver fallback The iHD VA driver does not work for Sandy bridge, Ivy bridge and Haswell. iHD will fail to initialize on these CPUs. So when a failure occurs, fallback to i965. --- libhb/ports.c | 78 ++++++++++++++++++++++++++++++++++++++++-------------- libhb/ports.h | 4 +-- libhb/qsv_common.c | 6 ++--- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/libhb/ports.c b/libhb/ports.c index 649896d90..02b486b4d 100644 --- a/libhb/ports.c +++ b/libhb/ports.c @@ -1568,30 +1568,18 @@ static int open_adapter(const char * name) return fd; } -hb_display_t * hb_display_init(const char * driver_name, - const char * interface_name) +static int try_va_interface(hb_display_t * hbDisplay, + const char * interface_name) { - hb_display_t * hbDisplay = calloc(sizeof(hb_display_t), 1); - - hbDisplay->vaDisplay = NULL; - hbDisplay->vaFd = open_adapter(driver_name); - if (hbDisplay->vaFd < 0) - { - hb_deep_log( 3, "hb_va_display_init: no display found" ); - free(hbDisplay); - return NULL; - } - - if (getenv("LIBVA_DRIVER_NAME") == NULL) + if (interface_name != NULL) { setenv("LIBVA_DRIVER_NAME", interface_name, 1); } + hbDisplay->vaDisplay = vaGetDisplayDRM(hbDisplay->vaFd); if (hbDisplay->vaDisplay == NULL) { - close(hbDisplay->vaFd); - free(hbDisplay); - return NULL; + return -1; } int major = 0, minor = 0; @@ -1599,13 +1587,63 @@ hb_display_t * hb_display_init(const char * driver_name, if (vaRes != VA_STATUS_SUCCESS) { vaTerminate(hbDisplay->vaDisplay); - close(hbDisplay->vaFd); - free(hbDisplay); - return NULL; + return -1; } hbDisplay->handle = hbDisplay->vaDisplay; hbDisplay->mfxType = MFX_HANDLE_VA_DISPLAY; + return 0; +} + +hb_display_t * hb_display_init(const char * driver_name, + const char * const * interface_names) +{ + hb_display_t * hbDisplay = calloc(sizeof(hb_display_t), 1); + char * env; + int ii; + + hbDisplay->vaDisplay = NULL; + hbDisplay->vaFd = open_adapter(driver_name); + if (hbDisplay->vaFd < 0) + { + hb_deep_log( 3, "hb_va_display_init: no display found" ); + free(hbDisplay); + return NULL; + } + + if ((env = getenv("LIBVA_DRIVER_NAME")) != NULL) + { + // Use only environment if it's set + hb_log("hb_display_init: using VA driver '%s'", env); + if (try_va_interface(hbDisplay, NULL) != 0) + { + close(hbDisplay->vaFd); + free(hbDisplay); + return NULL; + } + } + else + { + // Try list of VA driver names + for (ii = 0; interface_names[ii] != NULL; ii++) + { + hb_log("hb_display_init: attempting VA driver '%s'", + interface_names[ii]); + if (try_va_interface(hbDisplay, interface_names[ii]) == 0) + { + return hbDisplay; + } + } + // Try default + unsetenv("LIBVA_DRIVER_NAME"); + hb_log("hb_display_init: attempting VA default driver"); + if (try_va_interface(hbDisplay, NULL) != 0) + { + close(hbDisplay->vaFd); + free(hbDisplay); + return NULL; + } + } return hbDisplay; } diff --git a/libhb/ports.h b/libhb/ports.h index 02e4ebd5b..5f8a008dc 100644 --- a/libhb/ports.h +++ b/libhb/ports.h @@ -51,8 +51,8 @@ typedef struct #endif } hb_display_t; -hb_display_t * hb_display_init(const char * driver_name, - const char * interface_name); +hb_display_t * hb_display_init(const char * driver_name, + const char * const * interface_names); void hb_display_close(hb_display_t ** _d); /************************************************************************ diff --git a/libhb/qsv_common.c b/libhb/qsv_common.c index 0069e2f38..de907bb45 100644 --- a/libhb/qsv_common.c +++ b/libhb/qsv_common.c @@ -638,12 +638,12 @@ static int query_capabilities(mfxSession session, mfxVersion version, hb_qsv_inf return 0; } -const char* DRM_INTEL_DRIVER_NAME = "i915"; -const char* VA_INTEL_DRIVER_NAME = "iHD"; +const char * DRM_INTEL_DRIVER_NAME = "i915"; +const char * VA_INTEL_DRIVER_NAMES[] = { "iHD", "i965", NULL}; hb_display_t * hb_qsv_display_init(void) { - return hb_display_init(DRM_INTEL_DRIVER_NAME, VA_INTEL_DRIVER_NAME); + return hb_display_init(DRM_INTEL_DRIVER_NAME, VA_INTEL_DRIVER_NAMES); } int hb_qsv_info_init() -- cgit v1.2.3