static VADriverContextP init_i965_contex(struct WrapperContext *wr_ctx) { VADriverContextP ctx = NULL; char driver_name[] = "i965"; char driver_dir_default[] = VA_DRIVERS_PATH; char *driver_path = NULL, *search_path = NULL; char *driver_dir = NULL; char *saveptr; void *handle = NULL; VADriverInit init_func = NULL; char init_func_s[256]; int i; driver_dir = driver_dir_default; search_path = getenv("LIBVA_DRIVERS_PATH"); if (search_path != NULL) { search_path = strdup((const char *)search_path); driver_dir = strtok_r(search_path, ":", &saveptr); } while(driver_dir) { driver_path = (char *)calloc(strlen(driver_dir) + strlen(driver_name) + strlen(DRIVER_EXTENSION) + 2, 1); if (!driver_path) { WR_LOG("allocate driver patch fail %s\n", driver_path); break; } strncpy(driver_path, driver_dir, strlen(driver_dir) + 1); strncat(driver_path, "/", strlen("/")); strncat(driver_path, driver_name, strlen(driver_name)); strncat(driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION)); WR_LOG("Trying to open %s\n", driver_path); handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL); if(handle == NULL) { WR_LOG("dlopen %s fail\n", driver_path); } else { static const struct { int major; int minor; } compatible_versions[] = { { VA_MAJOR_VERSION, VA_MINOR_VERSION }, { 0, 34 }, { 0, 33 }, { 0, 32 }, { -1, } }; for (i = 0; compatible_versions[i].major >= 0; i++) { if (va_getDriverInitName(init_func_s, sizeof(init_func_s), compatible_versions[i].major, compatible_versions[i].minor)) { init_func = (VADriverInit)dlsym(handle, init_func_s); if (init_func) { WR_LOG("Found init function %s\n", init_func_s); break; } } } if (compatible_versions[i].major < 0) { WR_LOG("%s has no function %s\n", driver_path, init_func_s); dlclose(handle); } else { struct VADriverVTable *vtable = NULL; struct VADriverVTableVPP *vtable_vpp = NULL; VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; vaStatus = VA_STATUS_SUCCESS; ctx = calloc(sizeof(*ctx), 1); if(ctx == NULL) { WR_LOG("allocate i965 ctx fail\n"); vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; goto CHECK; } vtable = calloc(sizeof(*vtable), 1); if(vtable == NULL) { WR_LOG("allocate i965 vtable fail\n"); vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; goto CHECK; } else if(ctx != NULL) ctx->vtable = vtable; vtable_vpp = calloc(sizeof(*vtable_vpp), 1); if(vtable_vpp == NULL) { WR_LOG("allocate i965 vtable_vpp fail\n"); vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; goto CHECK; } else if(ctx != NULL) { ctx->vtable_vpp = vtable_vpp; vtable_vpp->version = VA_DRIVER_VTABLE_VPP_VERSION; } //keep the drm_state ctx->drm_state = wr_ctx->hybrid_ctx->drm_state; if (init_func && VA_STATUS_SUCCESS == vaStatus) vaStatus = (*init_func)(ctx); CHECK: if (VA_STATUS_SUCCESS != vaStatus) { WR_LOG("%s init failed\n", driver_path); dlclose(handle); if(ctx != NULL) { free(ctx); ctx = NULL; } if(vtable != NULL) free(vtable); if(vtable_vpp != NULL) free(vtable_vpp); } else { free(driver_path); //init func done, get the right context of the driver ctx->handle = handle; break; } } } free(driver_path); driver_dir = strtok_r(NULL, ":", &saveptr); } free(search_path); return ctx; }
static VAStatus va_openDriver(VADisplay dpy, char *driver_name) { VADriverContextP ctx = CTX(dpy); VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; char *search_path = NULL; char *saveptr; char *driver_dir; if (!search_path) search_path = VA_DRIVERS_PATH; search_path = strdup((const char *)search_path); driver_dir = strtok_r(search_path, ":", &saveptr); while (driver_dir) { void *handle = NULL; char *driver_path = (char *) malloc( strlen(driver_dir) + strlen(driver_name) + strlen(DRIVER_EXTENSION) + 2 ); if (!driver_path) { va_errorMessage("%s L%d Out of memory!n", __FUNCTION__, __LINE__); free(search_path); return VA_STATUS_ERROR_ALLOCATION_FAILED; } strncpy( driver_path, driver_dir, strlen(driver_dir) + 1); strncat( driver_path, "/", strlen("/") ); strncat( driver_path, driver_name, strlen(driver_name) ); strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) ); va_infoMessage("Trying to open %s\n", driver_path); handle = load_library( driver_path); if (!handle) { /* Don't give errors for non-existing files */ if (0 == access( driver_path, F_OK)) va_errorMessage("load_library of %s failed\n", driver_path); } else { VADriverInit init_func = NULL; char init_func_s[256]; int i; static const struct { int major; int minor; } compatible_versions[] = { { VA_MAJOR_VERSION, VA_MINOR_VERSION }, { 0, 35 }, { 0, 34 }, { 0, 33 }, { 0, 32 }, { -1, } }; for (i = 0; compatible_versions[i].major >= 0; i++) { if (va_getDriverInitName(init_func_s, sizeof(init_func_s), compatible_versions[i].major, compatible_versions[i].minor)) { init_func = (VADriverInit)get_proc_address(handle, init_func_s); if (init_func) { va_infoMessage("Found init function %s\n", init_func_s); break; } } } if (compatible_versions[i].major < 0) { va_errorMessage("%s has no function %s\n", driver_path, init_func_s); // dlclose(handle); } else { struct VADriverVTable *vtable = ctx->vtable; struct VADriverVTableVPP *vtable_vpp = ctx->vtable_vpp; vaStatus = VA_STATUS_SUCCESS; if (!vtable) { vtable = calloc(1, sizeof(*vtable)); if (!vtable) vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; } ctx->vtable = vtable; if (!vtable_vpp) { vtable_vpp = calloc(1, sizeof(*vtable_vpp)); if (vtable_vpp) vtable_vpp->version = VA_DRIVER_VTABLE_VPP_VERSION; else vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; } ctx->vtable_vpp = vtable_vpp; if (init_func && VA_STATUS_SUCCESS == vaStatus) vaStatus = (*init_func)(ctx); if (VA_STATUS_SUCCESS == vaStatus) { CHECK_MAXIMUM(vaStatus, ctx, profiles); CHECK_MAXIMUM(vaStatus, ctx, entrypoints); CHECK_MAXIMUM(vaStatus, ctx, attributes); CHECK_MAXIMUM(vaStatus, ctx, image_formats); CHECK_MAXIMUM(vaStatus, ctx, subpic_formats); CHECK_MAXIMUM(vaStatus, ctx, display_attributes); CHECK_STRING(vaStatus, ctx, vendor); CHECK_VTABLE(vaStatus, ctx, Terminate); CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles); CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints); CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes); CHECK_VTABLE(vaStatus, ctx, CreateConfig); CHECK_VTABLE(vaStatus, ctx, DestroyConfig); CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes); CHECK_VTABLE(vaStatus, ctx, CreateSurfaces); CHECK_VTABLE(vaStatus, ctx, DestroySurfaces); CHECK_VTABLE(vaStatus, ctx, CreateContext); CHECK_VTABLE(vaStatus, ctx, DestroyContext); CHECK_VTABLE(vaStatus, ctx, CreateBuffer); CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements); CHECK_VTABLE(vaStatus, ctx, MapBuffer); CHECK_VTABLE(vaStatus, ctx, UnmapBuffer); CHECK_VTABLE(vaStatus, ctx, DestroyBuffer); CHECK_VTABLE(vaStatus, ctx, BeginPicture); CHECK_VTABLE(vaStatus, ctx, RenderPicture); CHECK_VTABLE(vaStatus, ctx, EndPicture); CHECK_VTABLE(vaStatus, ctx, SyncSurface); CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus); CHECK_VTABLE(vaStatus, ctx, PutSurface); CHECK_VTABLE(vaStatus, ctx, QueryImageFormats); CHECK_VTABLE(vaStatus, ctx, CreateImage); CHECK_VTABLE(vaStatus, ctx, DeriveImage); CHECK_VTABLE(vaStatus, ctx, DestroyImage); CHECK_VTABLE(vaStatus, ctx, SetImagePalette); CHECK_VTABLE(vaStatus, ctx, GetImage); CHECK_VTABLE(vaStatus, ctx, PutImage); CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats); CHECK_VTABLE(vaStatus, ctx, CreateSubpicture); CHECK_VTABLE(vaStatus, ctx, DestroySubpicture); CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage); CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey); CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha); CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture); CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture); CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes); CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes); CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes); } if (VA_STATUS_SUCCESS != vaStatus) { va_errorMessage("%s init failed\n", driver_path); // dlclose(handle); } if (VA_STATUS_SUCCESS == vaStatus) ctx->handle = handle; free(driver_path); break; } } free(driver_path); driver_dir = strtok_r(NULL, ":", &saveptr); } free(search_path); return vaStatus; }