@@ -76,8 +76,10 @@ VAProfile preferredProfile(MythCodecID codec)
7676class VAAPIDisplay
7777{
7878 protected:
79- VAAPIDisplay () : m_va_disp(NULL ), m_x_disp(NULL ), m_display(NULL ),
80- m_ref_count (0 ), m_driver(QString()) { }
79+ VAAPIDisplay (VAAPIDisplayType display_type)
80+ : m_va_disp_type(display_type),
81+ m_va_disp (NULL ), m_x_disp(NULL ),
82+ m_ref_count(0 ), m_driver(QString()) { }
8183 public:
8284 ~VAAPIDisplay ()
8385 {
@@ -96,40 +98,45 @@ class VAAPIDisplay
9698
9799 bool Create (void )
98100 {
99- MythMainWindow *mw = GetMythMainWindow ();
100- if (!mw)
101- return false ;
102-
103- MythRenderOpenGL *gl =
104- static_cast <MythRenderOpenGL*>(mw->GetRenderDevice ());
105-
106- if (!gl)
107- {
108- LOG (VB_PLAYBACK, LOG_ERR, LOC +
109- QString (" Failed to get OpenGL context - you must use the "
110- " OpenGL UI painter for VAAPI support." ));
111- return false ;
112- }
113- gl->makeCurrent ();
114- m_display = glXGetCurrentDisplay ();
115- gl->doneCurrent ();
116-
117101 m_x_disp = OpenMythXDisplay ();
118102 if (!m_x_disp)
119103 return false ;
120104
121105 MythXLocker locker (m_x_disp);
122- int major_ver, minor_ver;
123106
124- // m_va_disp = vaGetDisplayGLX(m_x_disp->GetDisplay());
125- m_va_disp = vaGetDisplayGLX (m_display);
107+ if (m_va_disp_type == kVADisplayGLX )
108+ {
109+ MythMainWindow *mw = GetMythMainWindow ();
110+ if (!mw)
111+ return false ;
112+ MythRenderOpenGL *gl =
113+ static_cast <MythRenderOpenGL*>(mw->GetRenderDevice ());
114+ if (!gl)
115+ {
116+ LOG (VB_PLAYBACK, LOG_ERR, LOC +
117+ QString (" Failed to get OpenGL context - you must use the "
118+ " OpenGL UI painter for VAAPI GLX support." ));
119+ return false ;
120+ }
121+
122+ gl->makeCurrent ();
123+ Display *display = glXGetCurrentDisplay ();
124+ gl->doneCurrent ();
125+
126+ m_va_disp = vaGetDisplayGLX (display);
127+ }
128+ else
129+ {
130+ m_va_disp = vaGetDisplay (m_x_disp->GetDisplay ());
131+ }
126132
127133 if (!m_va_disp)
128134 {
129135 LOG (VB_GENERAL, LOG_ERR, LOC + " Failed to create VADisplay" );
130136 return false ;
131137 }
132138
139+ int major_ver, minor_ver;
133140 INIT_ST;
134141 va_status = vaInitialize (m_va_disp, &major_ver, &minor_ver);
135142 CHECK_ST;
@@ -148,7 +155,9 @@ class VAAPIDisplay
148155 if (ok)
149156 {
150157 UpRef ();
151- LOG (VB_PLAYBACK, LOG_INFO, LOC + " Created VAAPI GLX display" );
158+ LOG (VB_PLAYBACK, LOG_INFO, LOC +
159+ QString (" Created VAAPI %1 display" )
160+ .arg (m_va_disp_type == kVADisplayGLX ? " GLX" : " X11" ));
152161 }
153162 return ok;
154163 }
@@ -181,15 +190,21 @@ class VAAPIDisplay
181190 return ret;
182191 }
183192
184- static VAAPIDisplay* GetDisplay (void )
193+ static VAAPIDisplay* GetDisplay (VAAPIDisplayType display_type )
185194 {
186195 if (gVAAPIDisplay )
187196 {
197+ if (gVAAPIDisplay ->m_va_disp_type != display_type)
198+ {
199+ LOG (VB_GENERAL, LOG_ERR, " Already have a VAAPI display "
200+ " of a different type - aborting" );
201+ return NULL ;
202+ }
188203 gVAAPIDisplay ->UpRef ();
189204 return gVAAPIDisplay ;
190205 }
191206
192- gVAAPIDisplay = new VAAPIDisplay ();
207+ gVAAPIDisplay = new VAAPIDisplay (display_type );
193208 if (gVAAPIDisplay && gVAAPIDisplay ->Create ())
194209 return gVAAPIDisplay ;
195210
@@ -199,9 +214,9 @@ class VAAPIDisplay
199214 }
200215
201216 static VAAPIDisplay *gVAAPIDisplay ;
217+ VAAPIDisplayType m_va_disp_type;
202218 void *m_va_disp;
203219 MythXDisplay *m_x_disp;
204- Display *m_display;
205220 int m_ref_count;
206221 QString m_driver;
207222};
@@ -212,7 +227,7 @@ bool VAAPIContext::IsFormatAccelerated(QSize size, MythCodecID codec,
212227 PixelFormat &pix_fmt)
213228{
214229 bool result = false ;
215- VAAPIContext *ctx = new VAAPIContext (codec);
230+ VAAPIContext *ctx = new VAAPIContext (kVADisplayX11 , codec);
216231 if (ctx && ctx->CreateDisplay (size))
217232 {
218233 pix_fmt = ctx->GetPixelFormat ();
@@ -222,8 +237,10 @@ bool VAAPIContext::IsFormatAccelerated(QSize size, MythCodecID codec,
222237 return result;
223238}
224239
225- VAAPIContext::VAAPIContext (MythCodecID codec)
226- : m_codec(codec),
240+ VAAPIContext::VAAPIContext (VAAPIDisplayType display_type,
241+ MythCodecID codec)
242+ : m_dispType(display_type),
243+ m_codec(codec),
227244 m_display(NULL ),
228245 m_vaProfile(VAProfileMPEG2Main)/* ?? */ ,
229246 m_vaEntrypoint(VAEntrypointEncSlice),
@@ -280,7 +297,7 @@ bool VAAPIContext::CreateDisplay(QSize size)
280297{
281298 m_size = size;
282299 bool ok = true ;
283- m_display = VAAPIDisplay::GetDisplay ();
300+ m_display = VAAPIDisplay::GetDisplay (m_dispType );
284301 CREATE_CHECK (!m_size.isEmpty (), " Invalid size" );
285302 CREATE_CHECK (m_display != NULL , " Invalid display" );
286303 CREATE_CHECK (InitDisplay (), " Invalid VADisplay" );
@@ -619,7 +636,7 @@ uint8_t* VAAPIContext::GetSurfaceIDPointer(void* buf)
619636bool VAAPIContext::CopySurfaceToTexture (const void * buf, uint texture,
620637 uint texture_type, FrameScanType scan)
621638{
622- if (!buf)
639+ if (!buf || (m_dispType != kVADisplayGLX ) )
623640 return false ;
624641
625642 const vaapi_surface *surf = (vaapi_surface*)buf;
@@ -643,6 +660,9 @@ bool VAAPIContext::CopySurfaceToTexture(const void* buf, uint texture,
643660
644661void * VAAPIContext::GetGLXSurface (uint texture, uint texture_type)
645662{
663+ if (m_dispType != kVADisplayGLX )
664+ return NULL ;
665+
646666 if (m_glxSurfaces.contains (texture))
647667 return m_glxSurfaces.value (texture);
648668
@@ -667,7 +687,7 @@ void* VAAPIContext::GetGLXSurface(uint texture, uint texture_type)
667687
668688void VAAPIContext::ClearGLXSurfaces (void )
669689{
670- if (!m_display)
690+ if (!m_display || (m_dispType != kVADisplayGLX ) )
671691 return ;
672692
673693 MythXLocker locker (m_display->m_x_disp );
0 commit comments