VaApi::VaApi() { init = true; auto xdpy = QX11Info::display(); VADisplay display = m_display = vaGetDisplayGLX(xdpy); if (!check(display ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNIMPLEMENTED, "Cannot create VADisplay.")) return; int major, minor; if (!check(vaInitialize(m_display, &major, &minor), "Cannot initialize VA-API.")) return; auto size = vaMaxNumProfiles(display); m_profiles.resize(size); if (!check(vaQueryConfigProfiles(display, m_profiles.data(), &size), "No available profiles.")) return; m_profiles.resize(size); for (auto profile : m_profiles) { int size = vaMaxNumEntrypoints(display); QVector<VAEntrypoint> entries(size); if (!isSuccess(vaQueryConfigEntrypoints(display, profile, entries.data(), &size))) continue; entries.resize(size); m_entries.insert(profile, entries); } initCodecs(); #ifdef USE_VAVPP initFilters(); #endif _Debug("VA-API is initialized."); ok = true; }
static int create(struct gl_hwdec *hw) { if (hw->info->vaapi_ctx) return -1; if (!hw->mpgl->vo->x11 || !glXGetCurrentContext()) return -1; struct priv *p = talloc_zero(hw, struct priv); hw->priv = p; p->display = vaGetDisplayGLX(hw->mpgl->vo->x11->display); if (!p->display) return -1; p->ctx = va_initialize(p->display); if (!p->ctx) { vaTerminate(p->display); return -1; } hw->info->vaapi_ctx = p->ctx; hw->converted_imgfmt = IMGFMT_RGBA; return 0; }
bool Create(void) { m_x_disp = OpenMythXDisplay(); if (!m_x_disp) return false; MythXLocker locker(m_x_disp); if (m_va_disp_type == kVADisplayGLX) { MythMainWindow *mw = GetMythMainWindow(); if (!mw) return false; MythRenderOpenGL *gl = static_cast<MythRenderOpenGL*>(mw->GetRenderDevice()); if (!gl) { LOG(VB_PLAYBACK, LOG_ERR, LOC + QString("Failed to get OpenGL context - you must use the " "OpenGL UI painter for VAAPI GLX support.")); return false; } gl->makeCurrent(); Display *display = glXGetCurrentDisplay(); gl->doneCurrent(); m_va_disp = vaGetDisplayGLX(display); } else { m_va_disp = vaGetDisplay(m_x_disp->GetDisplay()); } if (!m_va_disp) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create VADisplay"); return false; } int major_ver, minor_ver; INIT_ST; va_status = vaInitialize(m_va_disp, &major_ver, &minor_ver); CHECK_ST; if (ok) m_driver = vaQueryVendorString(m_va_disp); static bool debugged = false; if (ok && !debugged) { debugged = true; LOG(VB_GENERAL, LOG_INFO, LOC + QString("Version: %1.%2") .arg(major_ver).arg(minor_ver)); LOG(VB_GENERAL, LOG_INFO, LOC + QString("Driver : %1").arg(m_driver)); } if (ok) { LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Created VAAPI %1 display") .arg(m_va_disp_type == kVADisplayGLX ? "GLX" : "X11")); } return ok; }
int main(int argc, char *argv[]) { GstVaapiDisplay *display, *display2; guint width, height, par_n, par_d; gst_init(&argc, &argv); #if USE_DRM g_print("#\n"); g_print("# Create display with gst_vaapi_display_drm_new()\n"); g_print("#\n"); { display = gst_vaapi_display_drm_new(NULL); if (!display) g_error("could not create Gst/VA display"); dump_info(display); gst_vaapi_display_unref(display); } g_print("\n"); g_print("#\n"); g_print("# Create display with gst_vaapi_display_drm_new_with_device()\n"); g_print("#\n"); { int drm_device; drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC); if (drm_device < 0) g_error("could not open DRM device"); display = gst_vaapi_display_drm_new_with_device(drm_device); if (!display) g_error("could not create Gst/VA display"); dump_info(display); gst_vaapi_display_unref(display); close(drm_device); } g_print("\n"); g_print("#\n"); g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayDRM()]\n"); g_print("#\n"); { int drm_device; VADisplay va_display; drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC); if (drm_device < 0) g_error("could not open DRM device"); va_display = vaGetDisplayDRM(drm_device); if (!va_display) g_error("could not create VA display"); display = gst_vaapi_display_new_with_display(va_display); if (!display) g_error("could not create Gst/VA display"); dump_info(display); gst_vaapi_display_unref(display); close(drm_device); } g_print("\n"); #endif #if USE_X11 g_print("#\n"); g_print("# Create display with gst_vaapi_display_x11_new()\n"); g_print("#\n"); { display = gst_vaapi_display_x11_new(NULL); if (!display) g_error("could not create Gst/VA display"); if (CHECK_DISPLAY_CACHE) { display2 = gst_vaapi_display_x11_new(NULL); /* Check for the same X11 display */ g_assert(gst_vaapi_display_x11_get_display( GST_VAAPI_DISPLAY_X11(display)) == gst_vaapi_display_x11_get_display( GST_VAAPI_DISPLAY_X11(display2))); /* Check for the same VA display */ g_assert(gst_vaapi_display_get_display(display) == gst_vaapi_display_get_display(display2)); gst_vaapi_display_unref(display2); #if USE_GLX display2 = gst_vaapi_display_glx_new(NULL); /* Check for the different X11 display */ /* XXX: it is also desired to cache underlying X11 displays */ g_assert(gst_vaapi_display_x11_get_display( GST_VAAPI_DISPLAY_X11(display)) != gst_vaapi_display_x11_get_display( GST_VAAPI_DISPLAY_X11(display2))); /* Check for different VA display */ g_assert(gst_vaapi_display_get_display(display) != gst_vaapi_display_get_display(display2)); gst_vaapi_display_unref(display2); #endif } gst_vaapi_display_get_size(display, &width, &height); g_print("Display size: %ux%u\n", width, height); gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d); g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d); dump_info(display); gst_vaapi_display_unref(display); } g_print("\n"); g_print("#\n"); g_print("# Create display with gst_vaapi_display_x11_new_with_display()\n"); g_print("#\n"); { Display *x11_display; x11_display = XOpenDisplay(NULL); if (!x11_display) g_error("could not create X11 display"); display = gst_vaapi_display_x11_new_with_display(x11_display); if (!display) g_error("could not create Gst/VA display"); if (CHECK_DISPLAY_CACHE) { display2 = gst_vaapi_display_x11_new_with_display(x11_display); /* Check for the same VA display */ g_assert(gst_vaapi_display_get_display(display) == gst_vaapi_display_get_display(display2)); gst_vaapi_display_unref(display2); } dump_info(display); gst_vaapi_display_unref(display); XCloseDisplay(x11_display); } g_print("\n"); g_print("#\n"); g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplay()]\n"); g_print("#\n"); { Display *x11_display; VADisplay va_display; x11_display = XOpenDisplay(NULL); if (!x11_display) g_error("could not create X11 display"); va_display = vaGetDisplay(x11_display); if (!va_display) g_error("could not create VA display"); display = gst_vaapi_display_new_with_display(va_display); if (!display) g_error("could not create Gst/VA display"); dump_info(display); gst_vaapi_display_unref(display); XCloseDisplay(x11_display); } g_print("\n"); #endif #if USE_GLX g_print("#\n"); g_print("# Create display with gst_vaapi_display_glx_new()\n"); g_print("#\n"); { display = gst_vaapi_display_glx_new(NULL); if (!display) g_error("could not create Gst/VA display"); if (CHECK_DISPLAY_CACHE) { display2 = gst_vaapi_display_glx_new(NULL); /* Check for the same X11 display */ g_assert(gst_vaapi_display_x11_get_display( GST_VAAPI_DISPLAY_X11(display)) == gst_vaapi_display_x11_get_display( GST_VAAPI_DISPLAY_X11(display2))); /* Check for the same VA display */ g_assert(gst_vaapi_display_get_display(display) == gst_vaapi_display_get_display(display2)); gst_vaapi_display_unref(display2); display2 = gst_vaapi_display_x11_new(NULL); /* Check for the same X11 display */ g_assert(gst_vaapi_display_x11_get_display( GST_VAAPI_DISPLAY_X11(display)) == gst_vaapi_display_x11_get_display( GST_VAAPI_DISPLAY_X11(display2))); /* Check for the same VA display */ g_assert(gst_vaapi_display_get_display(display) == gst_vaapi_display_get_display(display2)); gst_vaapi_display_unref(display2); } gst_vaapi_display_get_size(display, &width, &height); g_print("Display size: %ux%u\n", width, height); gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d); g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d); dump_info(display); gst_vaapi_display_unref(display); } g_print("\n"); g_print("#\n"); g_print("# Create display with gst_vaapi_display_glx_new_with_display()\n"); g_print("#\n"); { Display *x11_display; x11_display = XOpenDisplay(NULL); if (!x11_display) g_error("could not create X11 display"); display = gst_vaapi_display_glx_new_with_display(x11_display); if (!display) g_error("could not create Gst/VA display"); dump_info(display); gst_vaapi_display_unref(display); XCloseDisplay(x11_display); } g_print("\n"); #ifdef HAVE_VA_VA_GLX_H g_print("#\n"); g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayGLX()]\n"); g_print("#\n"); { Display *x11_display; VADisplay va_display; x11_display = XOpenDisplay(NULL); if (!x11_display) g_error("could not create X11 display"); va_display = vaGetDisplayGLX(x11_display); if (!va_display) g_error("could not create VA display"); display = gst_vaapi_display_new_with_display(va_display); if (!display) g_error("could not create Gst/VA display"); dump_info(display); gst_vaapi_display_unref(display); XCloseDisplay(x11_display); } g_print("\n"); #endif #endif #if USE_WAYLAND g_print("#\n"); g_print("# Create display with gst_vaapi_display_wayland_new()\n"); g_print("#\n"); { display = gst_vaapi_display_wayland_new(NULL); if (!display) g_error("could not create Gst/VA display"); gst_vaapi_display_get_size(display, &width, &height); g_print("Display size: %ux%u\n", width, height); gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d); g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d); dump_info(display); gst_vaapi_display_unref(display); } g_print("\n"); #endif gst_deinit(); return 0; }