bool VAApiWriter::open() { addParam( "Zoom" ); addParam( "AspectRatio" ); addParam( "Deinterlace" ); addParam( "PrepareForHWBobDeint", true ); addParam( "Hue" ); addParam( "Saturation" ); addParam( "Brightness" ); addParam( "Contrast" ); clr(); VADisp = vaGetDisplay( QX11Info::display() ); int minor, major; if ( vaInitialize( VADisp, &minor, &major ) == VA_STATUS_SUCCESS ) { const QString vendor = vaQueryVendorString( VADisp ); isVDPAU = vendor.contains( "VDPAU" ); if ( isVDPAU && !allowVDPAU ) return false; isXvBA = vendor.contains( "XvBA" ); int numProfiles = vaMaxNumProfiles( VADisp ); VAProfile profiles[ numProfiles ]; if ( vaQueryConfigProfiles( VADisp, profiles, &numProfiles ) == VA_STATUS_SUCCESS ) { for ( int i = 0 ; i < numProfiles ; ++i ) profileList.push_back( profiles[ i ] ); return true; } } return false; }
static void vaapi_encode_h264_write_identifier(PutBitContext *pbc, VAAPIEncodeContext *ctx, VAAPIEncodePicture *pic) { const char *lavc = LIBAVCODEC_IDENT; const char *vaapi = VA_VERSION_S; const char *driver = vaQueryVendorString(ctx->hwctx->display); char tmp[256]; int i; // Random (version 4) ISO 11578 UUID. uint8_t uuid[16] = { 0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf, 0x96, 0x75, 0x19, 0xd4, 0x1f, 0xea, 0xa9, 0x4d, }; for (i = 0; i < 16; i++) u(8, uuid[i], uuid_iso_iec_11578); snprintf(tmp, sizeof(tmp), "%s / VAAPI %s / %s", lavc, vaapi, driver); for (i = 0; i < sizeof(tmp) && tmp[i]; i++) u(8, tmp[i], user_data_payload_byte); }
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; }
static int Create( vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt, const es_format_t *fmt, picture_sys_t *p_sys ) { if( pix_fmt != AV_PIX_FMT_VAAPI_VLD ) return VLC_EGENERIC; (void) fmt; (void) p_sys; #ifdef VLC_VA_BACKEND_XLIB if( !vlc_xlib_init( VLC_OBJECT(va) ) ) { msg_Warn( va, "Ignoring VA-X11 API" ); return VLC_EGENERIC; } #endif VAProfile i_profile, *p_profiles_list; bool b_supported_profile = false; int i_profiles_nb = 0; unsigned count = 3; /* */ switch( ctx->codec_id ) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: i_profile = VAProfileMPEG2Main; count = 4; break; case AV_CODEC_ID_MPEG4: i_profile = VAProfileMPEG4AdvancedSimple; break; case AV_CODEC_ID_WMV3: i_profile = VAProfileVC1Main; break; case AV_CODEC_ID_VC1: i_profile = VAProfileVC1Advanced; break; case AV_CODEC_ID_H264: i_profile = VAProfileH264High; count = 18; break;; default: return VLC_EGENERIC; } count += ctx->thread_count; vlc_va_sys_t *sys; void *mem; assert(popcount(sizeof (sys->surfaces)) == 1); if (unlikely(posix_memalign(&mem, sizeof (sys->surfaces), sizeof (*sys)))) return VLC_ENOMEM; sys = mem; memset(sys, 0, sizeof (*sys)); /* */ sys->hw_ctx.display = NULL; sys->hw_ctx.config_id = VA_INVALID_ID; sys->hw_ctx.context_id = VA_INVALID_ID; sys->width = ctx->coded_width; sys->height = ctx->coded_height; sys->count = count; sys->available = (1 << sys->count) - 1; assert(count < sizeof (sys->available) * CHAR_BIT); assert(count * sizeof (sys->surfaces[0]) <= sizeof (sys->surfaces)); /* Create a VA display */ #ifdef VLC_VA_BACKEND_XLIB sys->p_display_x11 = XOpenDisplay(NULL); if( !sys->p_display_x11 ) { msg_Err( va, "Could not connect to X server" ); goto error; } sys->hw_ctx.display = vaGetDisplay(sys->p_display_x11); #endif #ifdef VLC_VA_BACKEND_DRM sys->drm_fd = vlc_open("/dev/dri/card0", O_RDWR); if( sys->drm_fd == -1 ) { msg_Err( va, "Could not access rendering device: %m" ); goto error; } sys->hw_ctx.display = vaGetDisplayDRM(sys->drm_fd); #endif if (sys->hw_ctx.display == NULL) { msg_Err( va, "Could not get a VAAPI device" ); goto error; } int major, minor; if (vaInitialize(sys->hw_ctx.display, &major, &minor)) { msg_Err( va, "Failed to initialize the VAAPI device" ); goto error; } /* Check if the selected profile is supported */ i_profiles_nb = vaMaxNumProfiles(sys->hw_ctx.display); p_profiles_list = calloc( i_profiles_nb, sizeof( VAProfile ) ); if( !p_profiles_list ) goto error; if (vaQueryConfigProfiles(sys->hw_ctx.display, p_profiles_list, &i_profiles_nb) == VA_STATUS_SUCCESS) { for( int i = 0; i < i_profiles_nb; i++ ) { if ( p_profiles_list[i] == i_profile ) { b_supported_profile = true; break; } } } free( p_profiles_list ); if ( !b_supported_profile ) { msg_Dbg( va, "Codec and profile not supported by the hardware" ); goto error; } /* Create a VA configuration */ VAConfigAttrib attrib; memset( &attrib, 0, sizeof(attrib) ); attrib.type = VAConfigAttribRTFormat; if (vaGetConfigAttributes(sys->hw_ctx.display, i_profile, VAEntrypointVLD, &attrib, 1)) goto error; /* Not sure what to do if not, I don't have a way to test */ if( (attrib.value & VA_RT_FORMAT_YUV420) == 0 ) goto error; if (vaCreateConfig(sys->hw_ctx.display, i_profile, VAEntrypointVLD, &attrib, 1, &sys->hw_ctx.config_id)) { sys->hw_ctx.config_id = VA_INVALID_ID; goto error; } /* Create surfaces */ assert(ctx->coded_width > 0 && ctx->coded_height > 0); if (vaCreateSurfaces(sys->hw_ctx.display, VA_RT_FORMAT_YUV420, ctx->coded_width, ctx->coded_height, sys->surfaces, sys->count, NULL, 0)) { goto error; } /* Create a context */ if (vaCreateContext(sys->hw_ctx.display, sys->hw_ctx.config_id, ctx->coded_width, ctx->coded_height, VA_PROGRESSIVE, sys->surfaces, sys->count, &sys->hw_ctx.context_id)) { sys->hw_ctx.context_id = VA_INVALID_ID; vaDestroySurfaces(sys->hw_ctx.display, sys->surfaces, sys->count); goto error; } if (FindFormat(sys)) goto error; if (unlikely(CopyInitCache(&sys->image_cache, ctx->coded_width))) goto error; vlc_mutex_init(&sys->lock); msg_Dbg(va, "using %s image format 0x%08x", sys->do_derive ? "derive" : "get", sys->format.fourcc); ctx->hwaccel_context = &sys->hw_ctx; va->sys = sys; va->description = vaQueryVendorString(sys->hw_ctx.display); va->get = Get; va->release = Release; va->extract = Extract; return VLC_SUCCESS; error: if (sys->hw_ctx.context_id != VA_INVALID_ID) { vaDestroyContext(sys->hw_ctx.display, sys->hw_ctx.context_id); vaDestroySurfaces(sys->hw_ctx.display, sys->surfaces, sys->count); } if (sys->hw_ctx.config_id != VA_INVALID_ID) vaDestroyConfig(sys->hw_ctx.display, sys->hw_ctx.config_id); if (sys->hw_ctx.display != NULL) vaTerminate(sys->hw_ctx.display); #ifdef VLC_VA_BACKEND_XLIB if( sys->p_display_x11 != NULL ) XCloseDisplay( sys->p_display_x11 ); #endif #ifdef VLC_VA_BACKEND_DRM if( sys->drm_fd != -1 ) close( sys->drm_fd ); #endif free( sys ); return VLC_EGENERIC; }