diff options
author | Carl Zhang <carl.zhang@intel.com> | 2019-12-10 10:50:25 -0500 |
---|---|---|
committer | XinfengZhang <carl.zhang@intel.com> | 2019-12-25 14:31:12 +0800 |
commit | b4d0af7f43f0ef2d51f070c75429c0d6acca663b (patch) | |
tree | 942712839785dc6a344521d9392187f72c08703d | |
parent | fbd16a1604b1a7a8e4d0ea20d500cfef43b63a3d (diff) | |
download | libva-b4d0af7f43f0ef2d51f070c75429c0d6acca663b.tar.gz |
enable driver candidate select fucntion for DRM
add multiple backend driver support part 3
enable vaGetDriverNameByIndex for DRM
add comments for the implementation
mv authenticate operation into vaGetNumCandidates function
from vaGetDriverName.
Signed-off-by: Carl Zhang <carl.zhang@intel.com>
-rw-r--r-- | va/android/va_android.cpp | 20 | ||||
-rw-r--r-- | va/drm/va_drm.c | 30 | ||||
-rw-r--r-- | va/drm/va_drm_utils.c | 35 | ||||
-rw-r--r-- | va/drm/va_drm_utils.h | 6 | ||||
-rw-r--r-- | va/va.c | 15 | ||||
-rw-r--r-- | va/wayland/va_wayland_drm.c | 27 |
6 files changed, 108 insertions, 25 deletions
diff --git a/va/android/va_android.cpp b/va/android/va_android.cpp index c49d3f3..4b5d81e 100644 --- a/va/android/va_android.cpp +++ b/va/android/va_android.cpp @@ -100,9 +100,10 @@ static void va_DisplayContextDestroy ( free(pDisplayContext); } -static VAStatus va_DisplayContextGetDriverName ( +} +static VAStatus va_DisplayContextGetNumCandidates( VADisplayContextP pDisplayContext, - char **driver_name + int *num_candidates ) { VADriverContextP const ctx = pDisplayContext->pDriverContext; @@ -116,8 +117,18 @@ static VAStatus va_DisplayContextGetDriverName ( return VA_STATUS_ERROR_UNKNOWN; } drm_state->auth_type = VA_DRM_AUTH_CUSTOM; + return VA_DRM_GetNumCandidates(ctx, num_candidates); +} + +static VAStatus va_DisplayContextGetDriverNameByIndex ( + VADisplayContextP pDisplayContext, + char **driver_name, + int candidate_index +) +{ + VADriverContextP const ctx = pDisplayContext->pDriverContext; - return VA_DRM_GetDriverName(ctx, driver_name); + return VA_DRM_GetDriverName(ctx, driver_name, candidate_index); } @@ -138,7 +149,8 @@ VADisplay vaGetDisplay ( pDisplayContext->vaIsValid = va_DisplayContextIsValid; pDisplayContext->vaDestroy = va_DisplayContextDestroy; - pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; + pDisplayContext->vaGetDriverNameByIndex = va_DisplayContextGetDriverNameByIndex; + pDisplayContext->vaGetNumCandidates = va_DisplayContextGetNumCandidates; pDriverContext = va_newDriverContext(pDisplayContext); if (!pDriverContext) { diff --git a/va/drm/va_drm.c b/va/drm/va_drm.c index b406e68..c135a0f 100644 --- a/va/drm/va_drm.c +++ b/va/drm/va_drm.c @@ -51,24 +51,19 @@ va_DisplayContextDestroy(VADisplayContextP pDisplayContext) free(pDisplayContext->pDriverContext); free(pDisplayContext); } - -static VAStatus -va_DisplayContextGetDriverName( +static VAStatus va_DisplayContextGetNumCandidates( VADisplayContextP pDisplayContext, - char **driver_name_ptr + int *num_candidates ) { - VADriverContextP const ctx = pDisplayContext->pDriverContext; struct drm_state * const drm_state = ctx->drm_state; + VAStatus status = VA_STATUS_SUCCESS; drm_magic_t magic; - VAStatus status; int ret; - - status = VA_DRM_GetDriverName(ctx, driver_name_ptr); + status = VA_DRM_GetNumCandidates(ctx, num_candidates); if (status != VA_STATUS_SUCCESS) return status; - /* Authentication is only needed for a legacy DRM device */ if (ctx->display_type != VA_DISPLAY_DRM_RENDERNODES) { ret = drmGetMagic(drm_state->fd, &magic); @@ -80,10 +75,22 @@ va_DisplayContextGetDriverName( } drm_state->auth_type = VA_DRM_AUTH_CUSTOM; - return VA_STATUS_SUCCESS; } +static VAStatus +va_DisplayContextGetDriverNameByIndex( + VADisplayContextP pDisplayContext, + char **driver_name_ptr, + int candidate_index +) +{ + + VADriverContextP const ctx = pDisplayContext->pDriverContext; + + return VA_DRM_GetDriverName(ctx, driver_name_ptr, candidate_index); +} + VADisplay vaGetDisplayDRM(int fd) { @@ -108,7 +115,8 @@ vaGetDisplayDRM(int fd) pDisplayContext->vaIsValid = va_DisplayContextIsValid; pDisplayContext->vaDestroy = va_DisplayContextDestroy; - pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; + pDisplayContext->vaGetNumCandidates = va_DisplayContextGetNumCandidates; + pDisplayContext->vaGetDriverNameByIndex = va_DisplayContextGetDriverNameByIndex; pDriverContext = va_newDriverContext(pDisplayContext); if (!pDriverContext) diff --git a/va/drm/va_drm_utils.c b/va/drm/va_drm_utils.c index cd67ecb..905ccdd 100644 --- a/va/drm/va_drm_utils.c +++ b/va/drm/va_drm_utils.c @@ -48,14 +48,39 @@ static const struct driver_name_map g_driver_name_map[] = { { NULL, 0, NULL } }; +/* Returns the VA driver candidate num for the active display*/ +VAStatus +VA_DRM_GetNumCandidates(VADriverContextP ctx, int * num_candidates) +{ + struct drm_state * const drm_state = ctx->drm_state; + drmVersionPtr drm_version; + int num_of_candidate = 0; + const struct driver_name_map *m = NULL; + if (!drm_state || drm_state->fd < 0) + return VA_STATUS_ERROR_INVALID_DISPLAY; + drm_version = drmGetVersion(drm_state->fd); + if (!drm_version) + return VA_STATUS_ERROR_UNKNOWN; + for (m = g_driver_name_map; m->key != NULL; m++) { + if (drm_version->name_len >= m->key_len && + strncmp(drm_version->name, m->key, m->key_len) == 0) { + num_of_candidate ++; + } + } + drmFreeVersion(drm_version); + *num_candidates = num_of_candidate; + return VA_STATUS_SUCCESS; +} + /* Returns the VA driver name for the active display */ VAStatus -VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr) +VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr, int candidate_index) { struct drm_state * const drm_state = ctx->drm_state; drmVersionPtr drm_version; char *driver_name = NULL; const struct driver_name_map *m; + int current_index = 0; *driver_name_ptr = NULL; @@ -68,8 +93,12 @@ VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr) for (m = g_driver_name_map; m->key != NULL; m++) { if (drm_version->name_len >= m->key_len && - strncmp(drm_version->name, m->key, m->key_len) == 0) - break; + strncmp(drm_version->name, m->key, m->key_len) == 0) { + if (current_index == candidate_index) { + break; + } + current_index ++; + } } drmFreeVersion(drm_version); diff --git a/va/drm/va_drm_utils.h b/va/drm/va_drm_utils.h index b468c59..1e9d90c 100644 --- a/va/drm/va_drm_utils.h +++ b/va/drm/va_drm_utils.h @@ -41,7 +41,9 @@ #ifdef __cplusplus extern "C" { #endif - +DLL_HIDDEN +VAStatus +VA_DRM_GetNumCandidates(VADriverContextP ctx, int * num_candidates); /** * \brief Returns the VA driver name for the active display. * @@ -62,7 +64,7 @@ extern "C" { */ DLL_HIDDEN VAStatus -VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr); +VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr, int candidate_index); /** * \brief Checks whether the file descriptor is a DRM Render-Nodes one @@ -341,7 +341,9 @@ va_getDriverInitName(char *name, int namelen, int major, int minor) int ret = snprintf(name, namelen, "__vaDriverInit_%d_%d", major, minor); return ret > 0 && ret < namelen; } - +/** retrieve the back end driver candidate num , by default it should be 1 + * if there are no vaGetNumCandidates implementation in the display context + * it should be 1 to avoid backward compatible issue */ static VAStatus va_getDriverNumCandidates(VADisplay dpy, int *num_candidates) { VADisplayContextP pDisplayContext = (VADisplayContextP)dpy; @@ -368,7 +370,7 @@ static VAStatus va_getDriverNameByIndex(VADisplay dpy, char **driver_name, int c ctx = CTX(dpy); driver_name_env = getenv("LIBVA_DRIVER_NAME"); - + /*if user set driver name by vaSetDriverName */ if (ctx->override_driver_name){ *driver_name = strdup(ctx->override_driver_name); if (!(*driver_name)) { @@ -378,10 +380,12 @@ static VAStatus va_getDriverNameByIndex(VADisplay dpy, char **driver_name, int c va_infoMessage(dpy, "User requested driver '%s'\n", *driver_name); return VA_STATUS_SUCCESS; } else if (driver_name_env && (geteuid() == getuid())) { + /*if user set driver name by environment variable*/ *driver_name = strdup(driver_name_env); va_infoMessage(dpy, "User environment variable requested driver '%s'\n", *driver_name); return VA_STATUS_SUCCESS; } else if (pDisplayContext->vaGetDriverNameByIndex) { + /*if vaGetDriverNameByIndex is implemented*/ return pDisplayContext->vaGetDriverNameByIndex(pDisplayContext, driver_name, candidate_index); } else { if (candidate_index == 0) @@ -713,12 +717,15 @@ VAStatus vaInitialize ( va_MessagingInit(); va_infoMessage(dpy, "VA-API version %s\n", VA_VERSION_S); - + /*get backend driver candidate number, by default the value should be 1*/ vaStatus = va_getDriverNumCandidates(dpy, &num_candidates); if (vaStatus != VA_STATUS_SUCCESS) { num_candidates = 1; } + /*load driver one by one, until load success */ for (candidate_index = 0; candidate_index < num_candidates; candidate_index ++) { + if(driver_name) + free(driver_name); vaStatus = va_getDriverNameByIndex(dpy, &driver_name, candidate_index); if(vaStatus != VA_STATUS_SUCCESS) { va_errorMessage(dpy, "vaGetDriverNameByIndex() failed with %s, driver_name = %s\n", vaErrorStr(vaStatus), driver_name); @@ -729,7 +736,7 @@ VAStatus vaInitialize ( if (vaStatus == VA_STATUS_SUCCESS) { break; - } + } } diff --git a/va/wayland/va_wayland_drm.c b/va/wayland/va_wayland_drm.c index 4cd3f6c..aebddcc 100644 --- a/va/wayland/va_wayland_drm.c +++ b/va/wayland/va_wayland_drm.c @@ -117,6 +117,29 @@ static const struct wl_drm_listener drm_listener = { }; static VAStatus +va_DisplayContextGetNumCandidates( + VADisplayContextP pDisplayContext, + int *candidate_index +) +{ + VADriverContextP const ctx = pDisplayContext->pDriverContext; + + return VA_DRM_GetNumCandidates(ctx, candidate_index); +} + +static VAStatus +va_DisplayContextGetDriverNameByIndex( + VADisplayContextP pDisplayContext, + char **driver_name_ptr, + int candidate_index +) +{ + VADriverContextP const ctx = pDisplayContext->pDriverContext; + + return VA_DRM_GetDriverName(ctx, driver_name_ptr, candidate_index); +} + +static VAStatus va_DisplayContextGetDriverName( VADisplayContextP pDisplayContext, char **driver_name_ptr @@ -124,7 +147,7 @@ va_DisplayContextGetDriverName( { VADriverContextP const ctx = pDisplayContext->pDriverContext; - return VA_DRM_GetDriverName(ctx, driver_name_ptr); + return VA_DRM_GetDriverName(ctx, driver_name_ptr, 0); } void @@ -237,6 +260,8 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext) wl_drm_ctx->is_authenticated = 0; pDisplayContext->opaque = wl_drm_ctx; pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; + pDisplayContext->vaGetNumCandidates = va_DisplayContextGetNumCandidates; + pDisplayContext->vaGetDriverNameByIndex = va_DisplayContextGetDriverNameByIndex; drm_state = calloc(1, sizeof(struct drm_state)); if (!drm_state) { |