2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
24 #include "windowing/WindowingFactory.h"
26 #include "guilib/GraphicContext.h"
27 #include "guilib/TextureManager.h"
28 #include "cores/VideoRenderers/RenderManager.h"
29 #include "DVDVideoCodecFFmpeg.h"
31 #include "settings/Settings.h"
32 #include "settings/AdvancedSettings.h"
33 #include "settings/MediaSettings.h"
34 #include "Application.h"
35 #include "utils/MathUtils.h"
36 #include "utils/TimeUtils.h"
37 #include "DVDCodecs/DVDCodecUtils.h"
38 #include "cores/VideoRenderers/RenderFlags.h"
40 using namespace VDPAU;
41 #define NUM_RENDER_PICS 7
43 #define ARSIZE(x) (sizeof(x) / sizeof((x)[0]))
45 // settings codecs mapping
46 DVDCodecAvailableType g_vdpau_available[] = {
47 { AV_CODEC_ID_H263, "videoplayer.usevdpaumpeg4" },
48 { AV_CODEC_ID_MPEG4, "videoplayer.usevdpaumpeg4" },
49 { AV_CODEC_ID_WMV3, "videoplayer.usevdpauvc1" },
50 { AV_CODEC_ID_VC1, "videoplayer.usevdpauvc1" },
51 { AV_CODEC_ID_MPEG2VIDEO, "videoplayer.usevdpaumpeg2" },
53 const size_t settings_count = sizeof(g_vdpau_available) / sizeof(DVDCodecAvailableType);
55 CDecoder::Desc decoder_profiles[] = {
56 {"MPEG1", VDP_DECODER_PROFILE_MPEG1},
57 {"MPEG2_SIMPLE", VDP_DECODER_PROFILE_MPEG2_SIMPLE},
58 {"MPEG2_MAIN", VDP_DECODER_PROFILE_MPEG2_MAIN},
59 {"H264_BASELINE",VDP_DECODER_PROFILE_H264_BASELINE},
60 {"H264_MAIN", VDP_DECODER_PROFILE_H264_MAIN},
61 {"H264_HIGH", VDP_DECODER_PROFILE_H264_HIGH},
62 {"VC1_SIMPLE", VDP_DECODER_PROFILE_VC1_SIMPLE},
63 {"VC1_MAIN", VDP_DECODER_PROFILE_VC1_MAIN},
64 {"VC1_ADVANCED", VDP_DECODER_PROFILE_VC1_ADVANCED},
65 #ifdef VDP_DECODER_PROFILE_MPEG4_PART2_ASP
66 {"MPEG4_PART2_ASP", VDP_DECODER_PROFILE_MPEG4_PART2_ASP},
69 const size_t decoder_profile_count = sizeof(decoder_profiles)/sizeof(CDecoder::Desc);
71 static struct SInterlaceMapping
73 const EINTERLACEMETHOD method;
74 const VdpVideoMixerFeature feature;
75 } g_interlace_mapping[] =
76 { {VS_INTERLACEMETHOD_VDPAU_TEMPORAL , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL}
77 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL}
78 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL}
79 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF, VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL}
80 , {VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE , VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE}
81 , {VS_INTERLACEMETHOD_NONE , (VdpVideoMixerFeature)-1}
84 static float studioCSCKCoeffs601[3] = {0.299, 0.587, 0.114}; //BT601 {Kr, Kg, Kb}
85 static float studioCSCKCoeffs709[3] = {0.2126, 0.7152, 0.0722}; //BT709 {Kr, Kg, Kb}
87 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
90 CVDPAUContext *CVDPAUContext::m_context = 0;
91 CCriticalSection CVDPAUContext::m_section;
92 Display *CVDPAUContext::m_display = 0;
93 void *CVDPAUContext::m_dlHandle = 0;
95 CVDPAUContext::CVDPAUContext()
101 void CVDPAUContext::Release()
103 CSingleLock lock(m_section);
114 void CVDPAUContext::Close()
116 CLog::Log(LOGNOTICE, "VDPAU::Close - closing decoder context");
120 bool CVDPAUContext::EnsureContext(CVDPAUContext **ctx)
122 CSingleLock lock(m_section);
126 m_context->m_refCount++;
131 m_context = new CVDPAUContext();
134 CSingleLock gLock(g_graphicsContext);
135 if (!m_context->LoadSymbols() || !m_context->CreateContext())
143 m_context->m_refCount++;
149 VDPAU_procs& CVDPAUContext::GetProcs()
154 VdpVideoMixerFeature* CVDPAUContext::GetFeatures()
156 return m_vdpFeatures;
159 int CVDPAUContext::GetFeatureCount()
161 return m_featureCount;
164 bool CVDPAUContext::LoadSymbols()
168 m_dlHandle = dlopen("libvdpau.so.1", RTLD_LAZY);
171 const char* error = dlerror();
173 error = "dlerror() returned NULL";
175 CLog::Log(LOGERROR,"VDPAU::LoadSymbols: Unable to get handle to lib: %s", error);
182 dl_vdp_device_create_x11 = (VdpStatus (*)(Display*, int, VdpDevice*, VdpStatus (**)(VdpDevice, VdpFuncId, void**)))dlsym(m_dlHandle, (const char*)"vdp_device_create_x11");
186 CLog::Log(LOGERROR,"(VDPAU) - %s in %s",error,__FUNCTION__);
187 m_vdpDevice = VDP_INVALID_HANDLE;
193 bool CVDPAUContext::CreateContext()
195 CLog::Log(LOGNOTICE,"VDPAU::CreateContext - creating decoder context");
198 { CSingleLock lock(g_graphicsContext);
200 m_display = XOpenDisplay(NULL);
201 mScreen = g_Windowing.GetCurrentScreen();
206 vdp_st = dl_vdp_device_create_x11(m_display,
209 &m_vdpProcs.vdp_get_proc_address);
211 CLog::Log(LOGNOTICE,"vdp_device = 0x%08x vdp_st = 0x%08x",m_vdpDevice,vdp_st);
212 if (vdp_st != VDP_STATUS_OK)
214 CLog::Log(LOGERROR,"(VDPAU) unable to init VDPAU - vdp_st = 0x%x. Falling back.",vdp_st);
215 m_vdpDevice = VDP_INVALID_HANDLE;
220 SpewHardwareAvailable();
224 void CVDPAUContext::QueryProcs()
228 #define VDP_PROC(id, proc) \
230 vdp_st = m_vdpProcs.vdp_get_proc_address(m_vdpDevice, id, (void**)&proc); \
231 if (vdp_st != VDP_STATUS_OK) \
233 CLog::Log(LOGERROR, "CVDPAUContext::GetProcs - failed to get proc id"); \
237 VDP_PROC(VDP_FUNC_ID_GET_ERROR_STRING , m_vdpProcs.vdp_get_error_string);
238 VDP_PROC(VDP_FUNC_ID_DEVICE_DESTROY , m_vdpProcs.vdp_device_destroy);
239 VDP_PROC(VDP_FUNC_ID_GENERATE_CSC_MATRIX , m_vdpProcs.vdp_generate_csc_matrix);
240 VDP_PROC(VDP_FUNC_ID_VIDEO_SURFACE_CREATE , m_vdpProcs.vdp_video_surface_create);
241 VDP_PROC(VDP_FUNC_ID_VIDEO_SURFACE_DESTROY , m_vdpProcs.vdp_video_surface_destroy);
242 VDP_PROC(VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR , m_vdpProcs.vdp_video_surface_put_bits_y_cb_cr);
243 VDP_PROC(VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_CB_CR , m_vdpProcs.vdp_video_surface_get_bits_y_cb_cr);
244 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_Y_CB_CR , m_vdpProcs.vdp_output_surface_put_bits_y_cb_cr);
245 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE , m_vdpProcs.vdp_output_surface_put_bits_native);
246 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_CREATE , m_vdpProcs.vdp_output_surface_create);
247 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY , m_vdpProcs.vdp_output_surface_destroy);
248 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_GET_BITS_NATIVE , m_vdpProcs.vdp_output_surface_get_bits_native);
249 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE, m_vdpProcs.vdp_output_surface_render_output_surface);
250 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED , m_vdpProcs.vdp_output_surface_put_bits_indexed);
251 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_CREATE , m_vdpProcs.vdp_video_mixer_create);
252 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES , m_vdpProcs.vdp_video_mixer_set_feature_enables);
253 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_DESTROY , m_vdpProcs.vdp_video_mixer_destroy);
254 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_RENDER , m_vdpProcs.vdp_video_mixer_render);
255 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES , m_vdpProcs.vdp_video_mixer_set_attribute_values);
256 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_QUERY_PARAMETER_SUPPORT , m_vdpProcs.vdp_video_mixer_query_parameter_support);
257 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_QUERY_FEATURE_SUPPORT , m_vdpProcs.vdp_video_mixer_query_feature_support);
258 VDP_PROC(VDP_FUNC_ID_DECODER_CREATE , m_vdpProcs.vdp_decoder_create);
259 VDP_PROC(VDP_FUNC_ID_DECODER_DESTROY , m_vdpProcs.vdp_decoder_destroy);
260 VDP_PROC(VDP_FUNC_ID_DECODER_RENDER , m_vdpProcs.vdp_decoder_render);
261 VDP_PROC(VDP_FUNC_ID_DECODER_QUERY_CAPABILITIES , m_vdpProcs.vdp_decoder_query_caps);
265 VdpDevice CVDPAUContext::GetDevice()
270 void CVDPAUContext::DestroyContext()
272 if (!m_vdpProcs.vdp_device_destroy)
275 m_vdpProcs.vdp_device_destroy(m_vdpDevice);
276 m_vdpDevice = VDP_INVALID_HANDLE;
279 void CVDPAUContext::SpewHardwareAvailable() //CopyrighVDPAUt (c) 2008 Wladimir J. van der Laan -- VDPInfo
282 CLog::Log(LOGNOTICE,"VDPAU Decoder capabilities:");
283 CLog::Log(LOGNOTICE,"name level macbs width height");
284 CLog::Log(LOGNOTICE,"------------------------------------");
285 for(unsigned int x=0; x<decoder_profile_count; ++x)
287 VdpBool is_supported = false;
288 uint32_t max_level, max_macroblocks, max_width, max_height;
289 rv = m_vdpProcs.vdp_decoder_query_caps(m_vdpDevice, decoder_profiles[x].id,
290 &is_supported, &max_level, &max_macroblocks, &max_width, &max_height);
291 if(rv == VDP_STATUS_OK && is_supported)
293 CLog::Log(LOGNOTICE,"%-16s %2i %5i %5i %5i\n", decoder_profiles[x].name,
294 max_level, max_macroblocks, max_width, max_height);
297 CLog::Log(LOGNOTICE,"------------------------------------");
299 #define CHECK_SUPPORT(feature) \
302 if(m_vdpProcs.vdp_video_mixer_query_feature_support(m_vdpDevice, feature, &supported) == VDP_STATUS_OK && supported) { \
303 CLog::Log(LOGNOTICE, "Mixer feature: "#feature); \
304 m_vdpFeatures[m_featureCount++] = feature; \
308 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION);
309 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_SHARPNESS);
310 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL);
311 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL);
312 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE);
313 #ifdef VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
314 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1);
315 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2);
316 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3);
317 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4);
318 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5);
319 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6);
320 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7);
321 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8);
322 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9);
327 bool CVDPAUContext::Supports(VdpVideoMixerFeature feature)
329 for(int i = 0; i < m_featureCount; i++)
331 if(m_vdpFeatures[i] == feature)
337 //-----------------------------------------------------------------------------
338 // VDPAU Video Surface states
339 //-----------------------------------------------------------------------------
341 #define SURFACE_USED_FOR_REFERENCE 0x01
342 #define SURFACE_USED_FOR_RENDER 0x02
344 void CVideoSurfaces::AddSurface(VdpVideoSurface surf)
346 CSingleLock lock(m_section);
347 m_state[surf] = SURFACE_USED_FOR_REFERENCE;
350 void CVideoSurfaces::ClearReference(VdpVideoSurface surf)
352 CSingleLock lock(m_section);
353 if (m_state.find(surf) == m_state.end())
355 CLog::Log(LOGWARNING, "CVideoSurfaces::ClearReference - surface invalid");
358 m_state[surf] &= ~SURFACE_USED_FOR_REFERENCE;
359 if (m_state[surf] == 0)
361 m_freeSurfaces.push_back(surf);
365 bool CVideoSurfaces::MarkRender(VdpVideoSurface surf)
367 CSingleLock lock(m_section);
368 if (m_state.find(surf) == m_state.end())
370 CLog::Log(LOGWARNING, "CVideoSurfaces::MarkRender - surface invalid");
373 std::list<VdpVideoSurface>::iterator it;
374 it = std::find(m_freeSurfaces.begin(), m_freeSurfaces.end(), surf);
375 if (it != m_freeSurfaces.end())
377 m_freeSurfaces.erase(it);
379 m_state[surf] |= SURFACE_USED_FOR_RENDER;
383 void CVideoSurfaces::ClearRender(VdpVideoSurface surf)
385 CSingleLock lock(m_section);
386 if (m_state.find(surf) == m_state.end())
388 CLog::Log(LOGWARNING, "CVideoSurfaces::ClearRender - surface invalid");
391 m_state[surf] &= ~SURFACE_USED_FOR_RENDER;
392 if (m_state[surf] == 0)
394 m_freeSurfaces.push_back(surf);
398 bool CVideoSurfaces::IsValid(VdpVideoSurface surf)
400 CSingleLock lock(m_section);
401 if (m_state.find(surf) != m_state.end())
407 VdpVideoSurface CVideoSurfaces::GetFree(VdpVideoSurface surf)
409 CSingleLock lock(m_section);
410 if (m_state.find(surf) != m_state.end())
412 std::list<VdpVideoSurface>::iterator it;
413 it = std::find(m_freeSurfaces.begin(), m_freeSurfaces.end(), surf);
414 if (it == m_freeSurfaces.end())
416 CLog::Log(LOGWARNING, "CVideoSurfaces::GetFree - surface not free");
420 m_freeSurfaces.erase(it);
421 m_state[surf] = SURFACE_USED_FOR_REFERENCE;
426 if (!m_freeSurfaces.empty())
428 VdpVideoSurface freeSurf = m_freeSurfaces.front();
429 m_freeSurfaces.pop_front();
430 m_state[freeSurf] = SURFACE_USED_FOR_REFERENCE;
434 return VDP_INVALID_HANDLE;
437 VdpVideoSurface CVideoSurfaces::GetAtIndex(int idx)
439 if (idx >= m_state.size())
440 return VDP_INVALID_HANDLE;
442 std::map<VdpVideoSurface, int>::iterator it = m_state.begin();
443 for(int i = 0; i < idx; i++)
448 VdpVideoSurface CVideoSurfaces::RemoveNext(bool skiprender)
450 CSingleLock lock(m_section);
451 VdpVideoSurface surf;
452 std::map<VdpVideoSurface, int>::iterator it;
453 for(it = m_state.begin(); it != m_state.end(); ++it)
455 if (skiprender && it->second & SURFACE_USED_FOR_RENDER)
460 std::list<VdpVideoSurface>::iterator it2;
461 it2 = std::find(m_freeSurfaces.begin(), m_freeSurfaces.end(), surf);
462 if (it2 != m_freeSurfaces.end())
463 m_freeSurfaces.erase(it2);
466 return VDP_INVALID_HANDLE;
469 void CVideoSurfaces::Reset()
471 CSingleLock lock(m_section);
472 m_freeSurfaces.clear();
476 int CVideoSurfaces::Size()
478 CSingleLock lock(m_section);
479 return m_state.size();
482 //-----------------------------------------------------------------------------
484 //-----------------------------------------------------------------------------
486 CDecoder::CDecoder() : m_vdpauOutput(&m_inMsgEvent)
488 m_vdpauConfig.videoSurfaces = &m_videoSurfaces;
490 m_vdpauConfigured = false;
491 m_hwContext.bitstream_buffers_allocated = 0;
492 m_DisplayState = VDPAU_OPEN;
493 m_vdpauConfig.context = 0;
496 bool CDecoder::Open(AVCodecContext* avctx, const enum PixelFormat fmt, unsigned int surfaces)
498 // check if user wants to decode this format with VDPAU
499 if (CDVDVideoCodec::IsCodecDisabled(g_vdpau_available, settings_count, avctx->codec_id))
502 #ifndef GL_NV_vdpau_interop
503 CLog::Log(LOGNOTICE, "VDPAU: compilation without required extension GL_NV_vdpau_interop");
506 if (!g_Windowing.IsExtSupported("GL_NV_vdpau_interop"))
508 CLog::Log(LOGNOTICE, "VDPAU: required extension GL_NV_vdpau_interop not found");
512 if(avctx->coded_width == 0
513 || avctx->coded_height == 0)
515 CLog::Log(LOGWARNING,"(VDPAU) no width/height available, can't init");
518 m_vdpauConfig.numRenderBuffers = surfaces;
519 m_decoderThread = CThread::GetCurrentThreadId();
521 if (!CVDPAUContext::EnsureContext(&m_vdpauConfig.context))
524 m_DisplayState = VDPAU_OPEN;
525 m_vdpauConfigured = false;
527 if (!m_dllAvUtil.Load())
530 m_presentPicture = 0;
533 VdpDecoderProfile profile = 0;
534 if(avctx->codec_id == AV_CODEC_ID_H264)
535 profile = VDP_DECODER_PROFILE_H264_HIGH;
536 #ifdef VDP_DECODER_PROFILE_MPEG4_PART2_ASP
537 else if(avctx->codec_id == AV_CODEC_ID_MPEG4)
538 profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
542 if (!CDVDCodecUtils::IsVP3CompatibleWidth(avctx->coded_width))
543 CLog::Log(LOGWARNING,"(VDPAU) width %i might not be supported because of hardware bug", avctx->width);
545 /* attempt to create a decoder with this width/height, some sizes are not supported by hw */
547 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_create(m_vdpauConfig.context->GetDevice(), profile, avctx->coded_width, avctx->coded_height, 5, &m_vdpauConfig.vdpDecoder);
549 if(vdp_st != VDP_STATUS_OK)
551 CLog::Log(LOGERROR, " (VDPAU) Error: %s(%d) checking for decoder support\n", m_vdpauConfig.context->GetProcs().vdp_get_error_string(vdp_st), vdp_st);
555 m_vdpauConfig.context->GetProcs().vdp_decoder_destroy(m_vdpauConfig.vdpDecoder);
556 CheckStatus(vdp_st, __LINE__);
559 /* finally setup ffmpeg */
560 memset(&m_hwContext, 0, sizeof(AVVDPAUContext));
561 m_hwContext.render = CDecoder::Render;
562 m_hwContext.bitstream_buffers_allocated = 0;
563 avctx->get_buffer = CDecoder::FFGetBuffer;
564 avctx->reget_buffer = CDecoder::FFGetBuffer;
565 avctx->release_buffer = CDecoder::FFReleaseBuffer;
566 avctx->draw_horiz_band = CDecoder::FFDrawSlice;
567 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD;
568 avctx->hwaccel_context = &m_hwContext;
569 avctx->thread_count = 1;
571 g_Windowing.Register(this);
577 CDecoder::~CDecoder()
582 void CDecoder::Close()
584 CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);
586 g_Windowing.Unregister(this);
588 CSingleLock lock(m_DecoderSection);
591 m_vdpauOutput.Dispose();
593 if (m_hwContext.bitstream_buffers_allocated)
595 m_dllAvUtil.av_freep(&m_hwContext.bitstream_buffers);
598 m_dllAvUtil.Unload();
600 if (m_vdpauConfig.context)
601 m_vdpauConfig.context->Release();
602 m_vdpauConfig.context = 0;
605 long CDecoder::Release()
607 // check if we should do some pre-cleanup here
608 // a second decoder might need resources
609 if (m_vdpauConfigured == true)
611 CSingleLock lock(m_DecoderSection);
612 CLog::Log(LOGNOTICE,"CVDPAU::Release pre-cleanup");
615 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::PRECLEANUP,
619 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
623 CLog::Log(LOGERROR, "VDPAU::%s - pre-cleanup returned error", __FUNCTION__);
624 m_DisplayState = VDPAU_ERROR;
629 CLog::Log(LOGERROR, "VDPAU::%s - pre-cleanup timed out", __FUNCTION__);
630 m_DisplayState = VDPAU_ERROR;
633 VdpVideoSurface surf;
634 while((surf = m_videoSurfaces.RemoveNext(true)) != VDP_INVALID_HANDLE)
636 m_vdpauConfig.context->GetProcs().vdp_video_surface_destroy(surf);
639 return IHardwareDecoder::Release();
642 long CDecoder::ReleasePicReference()
644 return IHardwareDecoder::Release();
647 void CDecoder::SetWidthHeight(int width, int height)
649 m_vdpauConfig.upscale = g_advancedSettings.m_videoVDPAUScaling;
651 //pick the smallest dimensions, so we downscale with vdpau and upscale with opengl when appropriate
652 //this requires the least amount of gpu memory bandwidth
653 if (g_graphicsContext.GetWidth() < width || g_graphicsContext.GetHeight() < height || m_vdpauConfig.upscale >= 0)
655 //scale width to desktop size if the aspect ratio is the same or bigger than the desktop
656 if ((double)height * g_graphicsContext.GetWidth() / width <= (double)g_graphicsContext.GetHeight())
658 m_vdpauConfig.outWidth = g_graphicsContext.GetWidth();
659 m_vdpauConfig.outHeight = MathUtils::round_int((double)height * g_graphicsContext.GetWidth() / width);
661 else //scale height to the desktop size if the aspect ratio is smaller than the desktop
663 m_vdpauConfig.outHeight = g_graphicsContext.GetHeight();
664 m_vdpauConfig.outWidth = MathUtils::round_int((double)width * g_graphicsContext.GetHeight() / height);
669 m_vdpauConfig.outWidth = width;
670 m_vdpauConfig.outHeight = height;
672 CLog::Log(LOGDEBUG, "CVDPAU::SetWidthHeight Setting OutWidth: %i OutHeight: %i", m_vdpauConfig.outWidth, m_vdpauConfig.outHeight);
675 void CDecoder::OnLostDevice()
677 CLog::Log(LOGNOTICE,"CVDPAU::OnLostDevice event");
679 int count = g_graphicsContext.exit();
681 CSingleLock lock(m_DecoderSection);
683 if (m_vdpauConfig.context)
684 m_vdpauConfig.context->Release();
685 m_vdpauConfig.context = 0;
687 m_DisplayState = VDPAU_LOST;
689 m_DisplayEvent.Reset();
691 g_graphicsContext.restore(count);
694 void CDecoder::OnResetDevice()
696 CLog::Log(LOGNOTICE,"CVDPAU::OnResetDevice event");
698 int count = g_graphicsContext.exit();
700 CSingleLock lock(m_DecoderSection);
701 if (m_DisplayState == VDPAU_LOST)
703 m_DisplayState = VDPAU_RESET;
705 m_DisplayEvent.Set();
708 g_graphicsContext.restore(count);
711 int CDecoder::Check(AVCodecContext* avctx)
715 { CSingleLock lock(m_DecoderSection);
716 state = m_DisplayState;
719 if (state == VDPAU_LOST)
721 CLog::Log(LOGNOTICE,"CVDPAU::Check waiting for display reset event");
722 if (!m_DisplayEvent.WaitMSec(4000))
724 CLog::Log(LOGERROR, "CVDPAU::Check - device didn't reset in reasonable time");
729 CSingleLock lock(m_DecoderSection);
730 state = m_DisplayState;
733 if (state == VDPAU_RESET || state == VDPAU_ERROR)
735 CSingleLock lock(m_DecoderSection);
738 if (m_vdpauConfig.context)
739 m_vdpauConfig.context->Release();
740 m_vdpauConfig.context = 0;
742 if (CVDPAUContext::EnsureContext(&m_vdpauConfig.context))
744 m_DisplayState = VDPAU_OPEN;
745 m_vdpauConfigured = false;
748 if (state == VDPAU_RESET)
756 bool CDecoder::IsVDPAUFormat(PixelFormat format)
758 if (format == AV_PIX_FMT_VDPAU)
764 bool CDecoder::Supports(VdpVideoMixerFeature feature)
766 return m_vdpauConfig.context->Supports(feature);
769 bool CDecoder::Supports(EINTERLACEMETHOD method)
771 if(method == VS_INTERLACEMETHOD_VDPAU_BOB
772 || method == VS_INTERLACEMETHOD_AUTO)
775 if (method == VS_INTERLACEMETHOD_RENDER_BOB)
778 if (method == VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE)
781 for(SInterlaceMapping* p = g_interlace_mapping; p->method != VS_INTERLACEMETHOD_NONE; p++)
783 if(p->method == method)
784 return Supports(p->feature);
789 EINTERLACEMETHOD CDecoder::AutoInterlaceMethod()
791 return VS_INTERLACEMETHOD_RENDER_BOB;
794 void CDecoder::FiniVDPAUOutput()
796 if (!m_vdpauConfigured)
799 CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);
802 m_vdpauOutput.Dispose();
803 m_vdpauConfigured = false;
807 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_destroy(m_vdpauConfig.vdpDecoder);
808 if (CheckStatus(vdp_st, __LINE__))
810 m_vdpauConfig.vdpDecoder = VDP_INVALID_HANDLE;
812 CLog::Log(LOGDEBUG, "CVDPAU::FiniVDPAUOutput destroying %d video surfaces", m_videoSurfaces.Size());
814 VdpVideoSurface surf;
815 while((surf = m_videoSurfaces.RemoveNext()) != VDP_INVALID_HANDLE)
817 m_vdpauConfig.context->GetProcs().vdp_video_surface_destroy(surf);
818 if (CheckStatus(vdp_st, __LINE__))
821 m_videoSurfaces.Reset();
824 void CDecoder::ReadFormatOf( AVCodecID codec
825 , VdpDecoderProfile &vdp_decoder_profile
826 , VdpChromaType &vdp_chroma_type)
830 case AV_CODEC_ID_MPEG1VIDEO:
831 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
832 vdp_chroma_type = VDP_CHROMA_TYPE_420;
834 case AV_CODEC_ID_MPEG2VIDEO:
835 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
836 vdp_chroma_type = VDP_CHROMA_TYPE_420;
838 case AV_CODEC_ID_H264:
839 vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
840 vdp_chroma_type = VDP_CHROMA_TYPE_420;
842 case AV_CODEC_ID_WMV3:
843 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
844 vdp_chroma_type = VDP_CHROMA_TYPE_420;
846 case AV_CODEC_ID_VC1:
847 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
848 vdp_chroma_type = VDP_CHROMA_TYPE_420;
850 case AV_CODEC_ID_MPEG4:
851 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
852 vdp_chroma_type = VDP_CHROMA_TYPE_420;
855 vdp_decoder_profile = 0;
861 bool CDecoder::ConfigVDPAU(AVCodecContext* avctx, int ref_frames)
866 VdpDecoderProfile vdp_decoder_profile;
868 m_vdpauConfig.vidWidth = avctx->width;
869 m_vdpauConfig.vidHeight = avctx->height;
870 m_vdpauConfig.surfaceWidth = avctx->coded_width;
871 m_vdpauConfig.surfaceHeight = avctx->coded_height;
873 SetWidthHeight(avctx->width,avctx->height);
875 CLog::Log(LOGNOTICE, " (VDPAU) screenWidth:%i vidWidth:%i surfaceWidth:%i",m_vdpauConfig.outWidth,m_vdpauConfig.vidWidth,m_vdpauConfig.surfaceWidth);
876 CLog::Log(LOGNOTICE, " (VDPAU) screenHeight:%i vidHeight:%i surfaceHeight:%i",m_vdpauConfig.outHeight,m_vdpauConfig.vidHeight,m_vdpauConfig.surfaceHeight);
878 ReadFormatOf(avctx->codec_id, vdp_decoder_profile, m_vdpauConfig.vdpChromaType);
880 if(avctx->codec_id == AV_CODEC_ID_H264)
882 m_vdpauConfig.maxReferences = ref_frames;
883 if (m_vdpauConfig.maxReferences > 16) m_vdpauConfig.maxReferences = 16;
884 if (m_vdpauConfig.maxReferences < 5) m_vdpauConfig.maxReferences = 5;
887 m_vdpauConfig.maxReferences = 2;
889 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_create(m_vdpauConfig.context->GetDevice(),
891 m_vdpauConfig.surfaceWidth,
892 m_vdpauConfig.surfaceHeight,
893 m_vdpauConfig.maxReferences,
894 &m_vdpauConfig.vdpDecoder);
895 if (CheckStatus(vdp_st, __LINE__))
899 CSingleLock lock(g_graphicsContext);
900 m_vdpauConfig.stats = &m_bufferStats;
901 m_vdpauConfig.vdpau = this;
902 m_bufferStats.Reset();
903 m_vdpauOutput.Start();
905 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::INIT,
909 sizeof(m_vdpauConfig)))
911 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
915 CLog::Log(LOGERROR, "VDPAU::%s - vdpau output returned error", __FUNCTION__);
916 m_vdpauOutput.Dispose();
922 CLog::Log(LOGERROR, "VDPAU::%s - failed to init output", __FUNCTION__);
923 m_vdpauOutput.Dispose();
927 m_inMsgEvent.Reset();
928 m_vdpauConfigured = true;
932 int CDecoder::FFGetBuffer(AVCodecContext *avctx, AVFrame *pic)
934 //CLog::Log(LOGNOTICE,"%s",__FUNCTION__);
935 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)avctx->opaque;
936 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
938 // while we are waiting to recover we can't do anything
939 CSingleLock lock(vdp->m_DecoderSection);
941 if(vdp->m_DisplayState != VDPAU_OPEN)
943 CLog::Log(LOGWARNING, "CVDPAU::FFGetBuffer - returning due to awaiting recovery");
947 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)pic->data[3];
948 surf = vdp->m_videoSurfaces.GetFree(surf != 0 ? surf : VDP_INVALID_HANDLE);
950 VdpStatus vdp_st = VDP_STATUS_ERROR;
951 if (surf == VDP_INVALID_HANDLE)
953 // create a new surface
954 VdpDecoderProfile profile;
955 ReadFormatOf(avctx->codec_id, profile, vdp->m_vdpauConfig.vdpChromaType);
957 vdp_st = vdp->m_vdpauConfig.context->GetProcs().vdp_video_surface_create(vdp->m_vdpauConfig.context->GetDevice(),
958 vdp->m_vdpauConfig.vdpChromaType,
962 vdp->CheckStatus(vdp_st, __LINE__);
963 if (vdp_st != VDP_STATUS_OK)
965 CLog::Log(LOGERROR, "CVDPAU::FFGetBuffer - No Video surface available could be created");
968 vdp->m_videoSurfaces.AddSurface(surf);
971 pic->data[1] = pic->data[2] = NULL;
972 pic->data[0] = (uint8_t*)(uintptr_t)surf;
973 pic->data[3] = (uint8_t*)(uintptr_t)surf;
975 pic->linesize[0] = pic->linesize[1] = pic->linesize[2] = 0;
977 pic->type= FF_BUFFER_TYPE_USER;
979 pic->reordered_opaque= avctx->reordered_opaque;
983 void CDecoder::FFReleaseBuffer(AVCodecContext *avctx, AVFrame *pic)
985 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)avctx->opaque;
986 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
988 VdpVideoSurface surf;
991 CSingleLock lock(vdp->m_DecoderSection);
993 surf = (VdpVideoSurface)(uintptr_t)pic->data[3];
995 vdp->m_videoSurfaces.ClearReference(surf);
1001 VdpStatus CDecoder::Render( VdpDecoder decoder, VdpVideoSurface target,
1002 VdpPictureInfo const *picture_info,
1003 uint32_t bitstream_buffer_count,
1004 VdpBitstreamBuffer const * bitstream_buffers)
1006 return VDP_STATUS_OK;
1009 void CDecoder::FFDrawSlice(struct AVCodecContext *s,
1010 const AVFrame *src, int offset[4],
1011 int y, int type, int height)
1013 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)s->opaque;
1014 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
1016 // while we are waiting to recover we can't do anything
1017 CSingleLock lock(vdp->m_DecoderSection);
1019 if(vdp->m_DisplayState != VDPAU_OPEN)
1022 if(src->linesize[0] || src->linesize[1] || src->linesize[2]
1023 || offset[0] || offset[1] || offset[2])
1025 CLog::Log(LOGERROR, "CVDPAU::FFDrawSlice - invalid linesizes or offsets provided");
1030 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)src->data[3];
1032 // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid
1033 if (!vdp->m_videoSurfaces.IsValid(surf))
1035 CLog::Log(LOGWARNING, "CVDPAU::FFDrawSlice - ignoring invalid buffer");
1039 uint32_t max_refs = 0;
1040 if(s->codec_id == AV_CODEC_ID_H264)
1041 max_refs = vdp->m_hwContext.info.h264.num_ref_frames;
1043 if(vdp->m_vdpauConfig.vdpDecoder == VDP_INVALID_HANDLE
1044 || vdp->m_vdpauConfigured == false
1045 || vdp->m_vdpauConfig.maxReferences < max_refs)
1047 if(!vdp->ConfigVDPAU(s, max_refs))
1051 uint64_t startTime = CurrentHostCounter();
1052 uint16_t decoded, processed, rend;
1053 vdp->m_bufferStats.Get(decoded, processed, rend);
1054 vdp_st = vdp->m_vdpauConfig.context->GetProcs().vdp_decoder_render(vdp->m_vdpauConfig.vdpDecoder,
1056 (VdpPictureInfo const *)&(vdp->m_hwContext.info),
1057 vdp->m_hwContext.bitstream_buffers_used,
1058 vdp->m_hwContext.bitstream_buffers);
1059 vdp->CheckStatus(vdp_st, __LINE__);
1060 uint64_t diff = CurrentHostCounter() - startTime;
1061 if (diff*1000/CurrentHostFrequency() > 30)
1062 CLog::Log(LOGDEBUG, "CVDPAU::DrawSlice - VdpDecoderRender long decoding: %d ms, dec: %d, proc: %d, rend: %d", (int)((diff*1000)/CurrentHostFrequency()), decoded, processed, rend);
1066 int CDecoder::Decode(AVCodecContext *avctx, AVFrame *pFrame)
1068 int result = Check(avctx);
1072 CSingleLock lock(m_DecoderSection);
1074 if (!m_vdpauConfigured)
1078 { // we have a new frame from decoder
1080 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)pFrame->data[3];
1081 // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid
1082 if (!m_videoSurfaces.IsValid(surf))
1084 CLog::Log(LOGWARNING, "CVDPAU::Decode - ignoring invalid buffer");
1087 m_videoSurfaces.MarkRender(surf);
1089 // send frame to output for processing
1090 CVdpauDecodedPicture pic;
1091 memset(&pic.DVDPic, 0, sizeof(pic.DVDPic));
1092 ((CDVDVideoCodecFFmpeg*)avctx->opaque)->GetPictureCommon(&pic.DVDPic);
1093 pic.videoSurface = surf;
1094 pic.DVDPic.color_matrix = avctx->colorspace;
1095 m_bufferStats.IncDecoded();
1096 m_vdpauOutput.m_dataPort.SendOutMessage(COutputDataProtocol::NEWFRAME, &pic, sizeof(pic));
1099 // m_codecControl = pic.DVDPic.iFlags & (DVP_FLAG_DRAIN | DVP_FLAG_NO_POSTPROC);
1103 uint16_t decoded, processed, render;
1105 while (m_vdpauOutput.m_controlPort.ReceiveInMessage(&msg))
1107 if (msg->signal == COutputControlProtocol::ERROR)
1109 m_DisplayState = VDPAU_ERROR;
1115 m_bufferStats.Get(decoded, processed, render);
1117 uint64_t startTime = CurrentHostCounter();
1120 // first fill the buffers to keep vdpau busy
1121 // mixer will run with decoded >= 2. output is limited by number of output surfaces
1122 // In case mixer is bypassed we limit by looking at processed
1123 if (decoded < 3 && processed < 3)
1125 retval |= VC_BUFFER;
1127 else if (m_vdpauOutput.m_dataPort.ReceiveInMessage(&msg))
1129 if (msg->signal == COutputDataProtocol::PICTURE)
1131 if (m_presentPicture)
1133 m_presentPicture->ReturnUnused();
1134 m_presentPicture = 0;
1137 m_presentPicture = *(CVdpauRenderPicture**)msg->data;
1138 m_presentPicture->vdpau = this;
1139 m_bufferStats.DecRender();
1140 m_bufferStats.Get(decoded, processed, render);
1141 retval |= VC_PICTURE;
1147 else if (m_vdpauOutput.m_controlPort.ReceiveInMessage(&msg))
1149 if (msg->signal == COutputControlProtocol::STATS)
1151 m_bufferStats.Get(decoded, processed, render);
1155 m_DisplayState = VDPAU_ERROR;
1161 if (decoded < 3 && processed < 3)
1163 retval |= VC_BUFFER;
1166 if (!retval && !m_inMsgEvent.WaitMSec(2000))
1169 uint64_t diff = CurrentHostCounter() - startTime;
1170 if (retval & VC_PICTURE)
1172 m_bufferStats.SetParams(diff, m_codecControl);
1174 if (diff*1000/CurrentHostFrequency() > 50)
1175 CLog::Log(LOGDEBUG,"CVDPAU::Decode long wait: %d", (int)((diff*1000)/CurrentHostFrequency()));
1179 CLog::Log(LOGERROR, "VDPAU::%s - timed out waiting for output message", __FUNCTION__);
1180 m_DisplayState = VDPAU_ERROR;
1187 bool CDecoder::GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture)
1189 CSingleLock lock(m_DecoderSection);
1191 if (m_DisplayState != VDPAU_OPEN)
1194 *picture = m_presentPicture->DVDPic;
1195 picture->vdpau = m_presentPicture;
1200 void CDecoder::Reset()
1202 CSingleLock lock(m_DecoderSection);
1204 if (!m_vdpauConfigured)
1208 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::FLUSH,
1212 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
1216 CLog::Log(LOGERROR, "VDPAU::%s - flush returned error", __FUNCTION__);
1217 m_DisplayState = VDPAU_ERROR;
1220 m_bufferStats.Reset();
1224 CLog::Log(LOGERROR, "VDPAU::%s - flush timed out", __FUNCTION__);
1225 m_DisplayState = VDPAU_ERROR;
1229 bool CDecoder::CanSkipDeint()
1231 return m_bufferStats.CanSkipDeint();
1234 void CDecoder::ReturnRenderPicture(CVdpauRenderPicture *renderPic)
1236 m_vdpauOutput.m_dataPort.SendOutMessage(COutputDataProtocol::RETURNPIC, &renderPic, sizeof(renderPic));
1239 bool CDecoder::CheckStatus(VdpStatus vdp_st, int line)
1241 if (vdp_st != VDP_STATUS_OK)
1243 CLog::Log(LOGERROR, " (VDPAU) Error: %s(%d) at %s:%d\n", m_vdpauConfig.context->GetProcs().vdp_get_error_string(vdp_st), vdp_st, __FILE__, line);
1245 if(m_DisplayState == VDPAU_OPEN)
1247 if (vdp_st == VDP_STATUS_DISPLAY_PREEMPTED)
1249 m_DisplayEvent.Reset();
1250 m_DisplayState = VDPAU_LOST;
1253 m_DisplayState = VDPAU_ERROR;
1261 //-----------------------------------------------------------------------------
1263 //-----------------------------------------------------------------------------
1265 CVdpauRenderPicture* CVdpauRenderPicture::Acquire()
1267 CSingleLock lock(renderPicSection);
1276 long CVdpauRenderPicture::Release()
1278 CSingleLock lock(renderPicSection);
1285 vdpau->ReturnRenderPicture(this);
1286 vdpau->ReleasePicReference();
1291 void CVdpauRenderPicture::ReturnUnused()
1293 { CSingleLock lock(renderPicSection);
1298 vdpau->ReturnRenderPicture(this);
1301 void CVdpauRenderPicture::Sync()
1304 CSingleLock lock(renderPicSection);
1309 glDeleteSync(fence);
1312 fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
1317 //-----------------------------------------------------------------------------
1319 //-----------------------------------------------------------------------------
1320 CMixer::CMixer(CEvent *inMsgEvent) :
1321 CThread("Vdpau Mixer"),
1322 m_controlPort("ControlPort", inMsgEvent, &m_outMsgEvent),
1323 m_dataPort("DataPort", inMsgEvent, &m_outMsgEvent)
1325 m_inMsgEvent = inMsgEvent;
1333 void CMixer::Start()
1338 void CMixer::Dispose()
1341 m_outMsgEvent.Set();
1344 m_controlPort.Purge();
1348 bool CMixer::IsActive()
1353 void CMixer::OnStartup()
1355 CLog::Log(LOGNOTICE, "CMixer::OnStartup: Output Thread created");
1358 void CMixer::OnExit()
1360 CLog::Log(LOGNOTICE, "CMixer::OnExit: Output Thread terminated");
1367 M_TOP_UNCONFIGURED, // 2
1368 M_TOP_CONFIGURED, // 3
1369 M_TOP_CONFIGURED_WAIT1, // 4
1370 M_TOP_CONFIGURED_STEP1, // 5
1371 M_TOP_CONFIGURED_WAIT2, // 6
1372 M_TOP_CONFIGURED_STEP2, // 7
1375 int MIXER_parentStates[] = {
1378 0, //TOP_UNCONFIGURED
1380 3, //TOP_CONFIGURED_WAIT1
1381 3, //TOP_CONFIGURED_STEP1
1382 3, //TOP_CONFIGURED_WAIT2
1383 3, //TOP_CONFIGURED_STEP2
1386 void CMixer::StateMachine(int signal, Protocol *port, Message *msg)
1388 for (int state = m_state; ; state = MIXER_parentStates[state])
1393 if (port == &m_controlPort)
1397 case CMixerControlProtocol::FLUSH:
1399 msg->Reply(CMixerControlProtocol::ACC);
1406 std::string portName = port == NULL ? "timer" : port->portName;
1407 CLog::Log(LOGWARNING, "CMixer::%s - signal: %d form port: %s not handled for state: %d", __FUNCTION__, signal, portName.c_str(), m_state);
1411 case M_TOP_ERROR: // TOP
1414 case M_TOP_UNCONFIGURED:
1415 if (port == &m_controlPort)
1419 case CMixerControlProtocol::INIT:
1421 data = (CVdpauConfig*)msg->data;
1429 m_state = M_TOP_CONFIGURED_WAIT1;
1430 msg->Reply(CMixerControlProtocol::ACC);
1434 msg->Reply(CMixerControlProtocol::ERROR);
1443 case M_TOP_CONFIGURED:
1444 if (port == &m_dataPort)
1448 case CMixerDataProtocol::FRAME:
1449 CVdpauDecodedPicture *frame;
1450 frame = (CVdpauDecodedPicture*)msg->data;
1453 m_decodedPics.push(*frame);
1457 case CMixerDataProtocol::BUFFER:
1458 VdpOutputSurface *surf;
1459 surf = (VdpOutputSurface*)msg->data;
1462 m_outputSurfaces.push(*surf);
1472 case M_TOP_CONFIGURED_WAIT1:
1473 if (port == NULL) // timeout
1477 case CMixerControlProtocol::TIMEOUT:
1478 if (!m_decodedPics.empty() && !m_outputSurfaces.empty())
1480 m_state = M_TOP_CONFIGURED_STEP1;
1481 m_bStateMachineSelfTrigger = true;
1494 case M_TOP_CONFIGURED_STEP1:
1495 if (port == NULL) // timeout
1499 case CMixerControlProtocol::TIMEOUT:
1500 m_mixerInput.push_front(m_decodedPics.front());
1501 m_decodedPics.pop();
1502 if (m_mixerInput.size() < 2)
1504 m_state = M_TOP_CONFIGURED_WAIT1;
1512 m_state = M_TOP_CONFIGURED_WAIT1;
1513 m_extTimeout = 1000;
1516 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
1517 m_outputSurfaces.pop();
1518 m_config.stats->IncProcessed();
1519 m_config.stats->DecDecoded();
1520 m_dataPort.SendInMessage(CMixerDataProtocol::PICTURE,&m_processPicture,sizeof(m_processPicture));
1521 if (m_mixersteps > 1)
1523 m_state = M_TOP_CONFIGURED_WAIT2;
1529 m_state = M_TOP_CONFIGURED_WAIT1;
1539 case M_TOP_CONFIGURED_WAIT2:
1540 if (port == NULL) // timeout
1544 case CMixerControlProtocol::TIMEOUT:
1545 if (!m_outputSurfaces.empty())
1547 m_state = M_TOP_CONFIGURED_STEP2;
1548 m_bStateMachineSelfTrigger = true;
1561 case M_TOP_CONFIGURED_STEP2:
1562 if (port == NULL) // timeout
1566 case CMixerControlProtocol::TIMEOUT:
1567 m_processPicture.outputSurface = m_outputSurfaces.front();
1572 m_state = M_TOP_CONFIGURED_WAIT1;
1573 m_extTimeout = 1000;
1576 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
1577 m_outputSurfaces.pop();
1578 m_config.stats->IncProcessed();
1579 m_dataPort.SendInMessage(CMixerDataProtocol::PICTURE,&m_processPicture,sizeof(m_processPicture));
1581 m_state = M_TOP_CONFIGURED_WAIT1;
1590 default: // we are in no state, should not happen
1591 CLog::Log(LOGERROR, "CMixer::%s - no valid state: %d", __FUNCTION__, m_state);
1597 void CMixer::Process()
1599 Message *msg = NULL;
1600 Protocol *port = NULL;
1603 m_state = M_TOP_UNCONFIGURED;
1604 m_extTimeout = 1000;
1605 m_bStateMachineSelfTrigger = false;
1611 if (m_bStateMachineSelfTrigger)
1613 m_bStateMachineSelfTrigger = false;
1614 // self trigger state machine
1615 StateMachine(msg->signal, port, msg);
1616 if (!m_bStateMachineSelfTrigger)
1623 // check control port
1624 else if (m_controlPort.ReceiveOutMessage(&msg))
1627 port = &m_controlPort;
1630 else if (m_dataPort.ReceiveOutMessage(&msg))
1638 StateMachine(msg->signal, port, msg);
1639 if (!m_bStateMachineSelfTrigger)
1648 else if (m_outMsgEvent.WaitMSec(m_extTimeout))
1655 msg = m_controlPort.GetMessage();
1656 msg->signal = CMixerControlProtocol::TIMEOUT;
1658 // signal timeout to state machine
1659 StateMachine(msg->signal, port, msg);
1660 if (!m_bStateMachineSelfTrigger)
1670 void CMixer::CreateVdpauMixer()
1672 CLog::Log(LOGNOTICE, " (VDPAU) Creating the video mixer");
1674 InitCSCMatrix(m_config.vidWidth);
1676 VdpVideoMixerParameter parameters[] = {
1677 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
1678 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
1679 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE};
1681 void const * parameter_values[] = {
1682 &m_config.surfaceWidth,
1683 &m_config.surfaceHeight,
1684 &m_config.vdpChromaType};
1686 VdpStatus vdp_st = VDP_STATUS_ERROR;
1687 vdp_st = m_config.context->GetProcs().vdp_video_mixer_create(m_config.context->GetDevice(),
1688 m_config.context->GetFeatureCount(),
1689 m_config.context->GetFeatures(),
1694 CheckStatus(vdp_st, __LINE__);
1698 void CMixer::InitCSCMatrix(int Width)
1700 m_Procamp.struct_version = VDP_PROCAMP_VERSION;
1701 m_Procamp.brightness = 0.0;
1702 m_Procamp.contrast = 1.0;
1703 m_Procamp.saturation = 1.0;
1707 void CMixer::CheckFeatures()
1709 if (m_Upscale != m_config.upscale)
1712 m_Upscale = m_config.upscale;
1714 if (m_Brightness != CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness ||
1715 m_Contrast != CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast ||
1716 m_ColorMatrix != m_mixerInput[1].DVDPic.color_matrix)
1719 m_Brightness = CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness;
1720 m_Contrast = CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast;
1721 m_ColorMatrix = m_mixerInput[1].DVDPic.color_matrix;
1723 if (m_NoiseReduction != CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction)
1725 m_NoiseReduction = CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction;
1726 SetNoiseReduction();
1728 if (m_Sharpness != CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness)
1730 m_Sharpness = CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness;
1733 if (m_DeintMode != CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode ||
1734 m_Deint != CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod)
1736 m_DeintMode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1737 m_Deint = CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod;
1742 void CMixer::SetPostProcFeatures(bool postProcEnabled)
1744 if (m_PostProc != postProcEnabled)
1746 if (postProcEnabled)
1748 SetNoiseReduction();
1755 m_PostProc = postProcEnabled;
1759 void CMixer::PostProcOff()
1763 if (m_videoMixer == VDP_INVALID_HANDLE)
1766 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL,
1767 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL,
1768 VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE};
1770 VdpBool enabled[]={0,0,0};
1771 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1772 CheckStatus(vdp_st, __LINE__);
1774 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION))
1776 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION};
1778 VdpBool enabled[]={0};
1779 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1780 CheckStatus(vdp_st, __LINE__);
1783 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_SHARPNESS))
1785 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_SHARPNESS};
1787 VdpBool enabled[]={0};
1788 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1789 CheckStatus(vdp_st, __LINE__);
1795 bool CMixer::GenerateStudioCSCMatrix(VdpColorStandard colorStandard, VdpCSCMatrix &studioCSCMatrix)
1797 // instead use studioCSCKCoeffs601[3], studioCSCKCoeffs709[3] to generate float[3][4] matrix (float studioCSC[3][4])
1798 // m00 = mRY = red: luma factor (contrast factor) (1.0)
1799 // m10 = mGY = green: luma factor (contrast factor) (1.0)
1800 // m20 = mBY = blue: luma factor (contrast factor) (1.0)
1802 // m01 = mRB = red: blue color diff coeff (0.0)
1803 // m11 = mGB = green: blue color diff coeff (-2Kb(1-Kb)/(Kg))
1804 // m21 = mBB = blue: blue color diff coeff ((1-Kb)/0.5)
1806 // m02 = mRR = red: red color diff coeff ((1-Kr)/0.5)
1807 // m12 = mGR = green: red color diff coeff (-2Kr(1-Kr)/(Kg))
1808 // m22 = mBR = blue: red color diff coeff (0.0)
1810 // m03 = mRC = red: colour zero offset (brightness factor) (-(1-Kr)/0.5 * (128/255))
1811 // m13 = mGC = green: colour zero offset (brightness factor) ((256/255) * (Kb(1-Kb) + Kr(1-Kr)) / Kg)
1812 // m23 = mBC = blue: colour zero offset (brightness factor) (-(1-Kb)/0.5 * (128/255))
1823 // colour standard coefficients for red, geen, blue
1825 // colour diff zero position (use standard 8-bit coding precision)
1826 double CDZ = 128; //256*0.5
1827 // range excursion (use standard 8-bit coding precision)
1828 double EXC = 255; //256-1
1830 if (colorStandard == VDP_COLOR_STANDARD_ITUR_BT_601)
1832 Kr = studioCSCKCoeffs601[0];
1833 Kg = studioCSCKCoeffs601[1];
1834 Kb = studioCSCKCoeffs601[2];
1836 else // assume VDP_COLOR_STANDARD_ITUR_BT_709
1838 Kr = studioCSCKCoeffs709[0];
1839 Kg = studioCSCKCoeffs709[1];
1840 Kb = studioCSCKCoeffs709[2];
1842 // we keep luma unscaled to retain the levels present in source so that 16-235 luma is converted to RGB 16-235
1843 studioCSCMatrix[R][Y] = 1.0;
1844 studioCSCMatrix[G][Y] = 1.0;
1845 studioCSCMatrix[B][Y] = 1.0;
1847 studioCSCMatrix[R][Cb] = 0.0;
1848 studioCSCMatrix[G][Cb] = (double)-2 * Kb * (1 - Kb) / Kg;
1849 studioCSCMatrix[B][Cb] = (double)(1 - Kb) / 0.5;
1851 studioCSCMatrix[R][Cr] = (double)(1 - Kr) / 0.5;
1852 studioCSCMatrix[G][Cr] = (double)-2 * Kr * (1 - Kr) / Kg;
1853 studioCSCMatrix[B][Cr] = 0.0;
1855 studioCSCMatrix[R][C] = (double)-1 * studioCSCMatrix[R][Cr] * CDZ/EXC;
1856 studioCSCMatrix[G][C] = (double)-1 * (studioCSCMatrix[G][Cb] + studioCSCMatrix[G][Cr]) * CDZ/EXC;
1857 studioCSCMatrix[B][C] = (double)-1 * studioCSCMatrix[B][Cb] * CDZ/EXC;
1862 void CMixer::SetColor()
1866 if (m_Brightness != CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness)
1867 m_Procamp.brightness = (float)((CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness)-50) / 100;
1868 if (m_Contrast != CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast)
1869 m_Procamp.contrast = (float)((CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast)+50) / 100;
1871 VdpColorStandard colorStandard;
1872 switch(m_mixerInput[1].DVDPic.color_matrix)
1874 case AVCOL_SPC_BT709:
1875 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_709;
1877 case AVCOL_SPC_BT470BG:
1878 case AVCOL_SPC_SMPTE170M:
1879 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_601;
1881 case AVCOL_SPC_SMPTE240M:
1882 colorStandard = VDP_COLOR_STANDARD_SMPTE_240M;
1885 case AVCOL_SPC_UNSPECIFIED:
1888 if(m_config.surfaceWidth > 1000)
1889 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_709;
1891 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_601;
1894 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX };
1895 if (CSettings::Get().GetBool("videoscreen.limitedrange"))
1897 float studioCSC[3][4];
1898 GenerateStudioCSCMatrix(colorStandard, studioCSC);
1899 void const * pm_CSCMatix[] = { &studioCSC };
1900 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
1904 vdp_st = m_config.context->GetProcs().vdp_generate_csc_matrix(&m_Procamp, colorStandard, &m_CSCMatrix);
1905 void const * pm_CSCMatix[] = { &m_CSCMatrix };
1906 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
1909 CheckStatus(vdp_st, __LINE__);
1912 void CMixer::SetNoiseReduction()
1914 if(!m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION))
1917 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION };
1918 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL };
1921 if (!CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction)
1923 VdpBool enabled[]= {0};
1924 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1925 CheckStatus(vdp_st, __LINE__);
1928 VdpBool enabled[]={1};
1929 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1930 CheckStatus(vdp_st, __LINE__);
1931 void* nr[] = { &CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction };
1932 CLog::Log(LOGNOTICE,"Setting Noise Reduction to %f",CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction);
1933 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, nr);
1934 CheckStatus(vdp_st, __LINE__);
1937 void CMixer::SetSharpness()
1939 if(!m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_SHARPNESS))
1942 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_SHARPNESS };
1943 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL };
1946 if (!CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness)
1948 VdpBool enabled[]={0};
1949 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1950 CheckStatus(vdp_st, __LINE__);
1953 VdpBool enabled[]={1};
1954 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1955 CheckStatus(vdp_st, __LINE__);
1956 void* sh[] = { &CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness };
1957 CLog::Log(LOGNOTICE,"Setting Sharpness to %f",CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness);
1958 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, sh);
1959 CheckStatus(vdp_st, __LINE__);
1962 EINTERLACEMETHOD CMixer::GetDeinterlacingMethod(bool log /* = false */)
1964 EINTERLACEMETHOD method = CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod;
1965 if (method == VS_INTERLACEMETHOD_AUTO)
1968 // if (m_config.outHeight >= 720)
1969 // deint = g_advancedSettings.m_videoVDPAUdeintHD;
1971 // deint = g_advancedSettings.m_videoVDPAUdeintSD;
1975 if (m_config.vdpau->Supports(EINTERLACEMETHOD(deint)))
1977 method = EINTERLACEMETHOD(deint);
1979 CLog::Log(LOGNOTICE, "CVDPAU::GetDeinterlacingMethod: set de-interlacing to %d", deint);
1984 CLog::Log(LOGWARNING, "CVDPAU::GetDeinterlacingMethod: method for de-interlacing (advanced settings) not supported");
1991 void CMixer::SetDeinterlacing()
1995 if (m_videoMixer == VDP_INVALID_HANDLE)
1998 EDEINTERLACEMODE mode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1999 EINTERLACEMETHOD method = GetDeinterlacingMethod(true);
2001 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL,
2002 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL,
2003 VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE };
2005 if (mode == VS_DEINTERLACEMODE_OFF)
2007 VdpBool enabled[] = {0,0,0};
2008 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2012 if (method == VS_INTERLACEMETHOD_AUTO)
2014 VdpBool enabled[] = {1,0,0};
2015 if (g_advancedSettings.m_videoVDPAUtelecine)
2017 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2019 else if (method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL
2020 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF)
2022 VdpBool enabled[] = {1,0,0};
2023 if (g_advancedSettings.m_videoVDPAUtelecine)
2025 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2027 else if (method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL
2028 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF)
2030 VdpBool enabled[] = {1,1,0};
2031 if (g_advancedSettings.m_videoVDPAUtelecine)
2033 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2037 VdpBool enabled[]={0,0,0};
2038 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2041 CheckStatus(vdp_st, __LINE__);
2043 SetDeintSkipChroma();
2045 m_config.useInteropYuv = !CSettings::Get().GetBool("videoplayer.usevdpaumixer");
2048 void CMixer::SetDeintSkipChroma()
2050 VdpVideoMixerAttribute attribute[] = { VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE};
2054 if (g_advancedSettings.m_videoVDPAUdeintSkipChromaHD && m_config.outHeight >= 720)
2059 void const *values[]={&val};
2060 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attribute), attribute, values);
2062 CheckStatus(vdp_st, __LINE__);
2065 void CMixer::SetHWUpscaling()
2067 #ifdef VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
2070 VdpBool enabled[]={1};
2071 switch (m_config.upscale)
2074 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9))
2076 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9 };
2077 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2081 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8))
2083 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8 };
2084 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2088 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7))
2090 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7 };
2091 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2095 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6))
2097 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6 };
2098 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2102 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5))
2104 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5 };
2105 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2109 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4))
2111 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4 };
2112 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2116 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3))
2118 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3 };
2119 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2123 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2))
2125 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2 };
2126 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2130 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1))
2132 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 };
2133 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2140 CheckStatus(vdp_st, __LINE__);
2144 void CMixer::DisableHQScaling()
2148 if (m_videoMixer == VDP_INVALID_HANDLE)
2151 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1))
2153 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 };
2154 VdpBool enabled[]={0};
2155 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2156 CheckStatus(vdp_st, __LINE__);
2159 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2))
2161 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2 };
2162 VdpBool enabled[]={0};
2163 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2164 CheckStatus(vdp_st, __LINE__);
2167 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3))
2169 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3 };
2170 VdpBool enabled[]={0};
2171 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2172 CheckStatus(vdp_st, __LINE__);
2175 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4))
2177 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4 };
2178 VdpBool enabled[]={0};
2179 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2180 CheckStatus(vdp_st, __LINE__);
2183 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5))
2185 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5 };
2186 VdpBool enabled[]={0};
2187 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2188 CheckStatus(vdp_st, __LINE__);
2191 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6))
2193 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6 };
2194 VdpBool enabled[]={0};
2195 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2196 CheckStatus(vdp_st, __LINE__);
2199 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7))
2201 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7 };
2202 VdpBool enabled[]={0};
2203 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2204 CheckStatus(vdp_st, __LINE__);
2207 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8))
2209 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8 };
2210 VdpBool enabled[]={0};
2211 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2212 CheckStatus(vdp_st, __LINE__);
2215 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9))
2217 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9 };
2218 VdpBool enabled[]={0};
2219 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2220 CheckStatus(vdp_st, __LINE__);
2228 m_NoiseReduction = 0.0;
2233 m_SeenInterlaceFlag = false;
2238 m_config.upscale = g_advancedSettings.m_videoVDPAUScaling;
2239 m_config.useInteropYuv = !CSettings::Get().GetBool("videoplayer.usevdpaumixer");
2244 void CMixer::Uninit()
2247 while (!m_outputSurfaces.empty())
2249 m_outputSurfaces.pop();
2251 m_config.context->GetProcs().vdp_video_mixer_destroy(m_videoMixer);
2254 void CMixer::Flush()
2256 while (!m_mixerInput.empty())
2258 CVdpauDecodedPicture pic = m_mixerInput.back();
2259 m_mixerInput.pop_back();
2260 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2262 while (!m_decodedPics.empty())
2264 CVdpauDecodedPicture pic = m_decodedPics.front();
2265 m_decodedPics.pop();
2266 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2269 while (m_dataPort.ReceiveOutMessage(&msg))
2271 if (msg->signal == CMixerDataProtocol::FRAME)
2273 CVdpauDecodedPicture pic = *(CVdpauDecodedPicture*)msg->data;
2274 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2276 else if (msg->signal == CMixerDataProtocol::BUFFER)
2278 VdpOutputSurface *surf;
2279 surf = (VdpOutputSurface*)msg->data;
2280 m_outputSurfaces.push(*surf);
2286 void CMixer::InitCycle()
2291 m_config.stats->GetParams(latency, flags);
2293 if (0) //flags & DVP_FLAG_NO_POSTPROC)
2294 SetPostProcFeatures(false);
2296 SetPostProcFeatures(true);
2298 m_config.stats->SetCanSkipDeint(false);
2300 EDEINTERLACEMODE mode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
2301 EINTERLACEMETHOD method = GetDeinterlacingMethod();
2302 bool interlaced = m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_INTERLACED;
2303 m_SeenInterlaceFlag |= interlaced;
2306 if (//!(flags & DVP_FLAG_NO_POSTPROC) &&
2307 (mode == VS_DEINTERLACEMODE_FORCE ||
2308 (mode == VS_DEINTERLACEMODE_AUTO && interlaced)))
2310 if((method == VS_INTERLACEMETHOD_AUTO && interlaced)
2311 || method == VS_INTERLACEMETHOD_VDPAU_BOB
2312 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL
2313 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF
2314 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL
2315 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF
2316 || method == VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE )
2318 if(method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF
2319 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF
2320 || !g_graphicsContext.IsFullScreenVideo())
2325 m_config.stats->SetCanSkipDeint(true);
2329 if (0) //m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_DROPDEINT)
2334 if(m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_TOP_FIELD_FIRST)
2335 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
2337 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
2339 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2340 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2341 DVP_FLAG_REPEAT_TOP_FIELD |
2342 DVP_FLAG_INTERLACED);
2343 m_config.useInteropYuv = false;
2345 else if (method == VS_INTERLACEMETHOD_RENDER_BOB)
2348 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2349 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU_420;
2350 m_config.useInteropYuv = true;
2354 CLog::Log(LOGERROR, "CMixer::%s - interlace method: %d not supported, setting to AUTO", __FUNCTION__, method);
2356 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2357 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2358 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2359 DVP_FLAG_REPEAT_TOP_FIELD |
2360 DVP_FLAG_INTERLACED);
2362 CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod = VS_INTERLACEMETHOD_AUTO;
2368 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2370 if (m_config.useInteropYuv)
2371 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU_420;
2374 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2375 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2376 DVP_FLAG_REPEAT_TOP_FIELD |
2377 DVP_FLAG_INTERLACED);
2382 if (m_mixerInput[1].DVDPic.format == RENDER_FMT_VDPAU)
2384 m_processPicture.outputSurface = m_outputSurfaces.front();
2385 m_mixerInput[1].DVDPic.iWidth = m_config.outWidth;
2386 m_mixerInput[1].DVDPic.iHeight = m_config.outHeight;
2387 if (m_SeenInterlaceFlag)
2389 double ratio = (double)m_mixerInput[1].DVDPic.iDisplayHeight / m_mixerInput[1].DVDPic.iHeight;
2390 m_mixerInput[1].DVDPic.iHeight -= 6;
2391 m_mixerInput[1].DVDPic.iDisplayHeight = lrint(ratio*m_mixerInput[1].DVDPic.iHeight);
2396 m_mixerInput[1].DVDPic.iWidth = m_config.vidWidth;
2397 m_mixerInput[1].DVDPic.iHeight = m_config.vidHeight;
2400 m_processPicture.DVDPic = m_mixerInput[1].DVDPic;
2401 m_processPicture.videoSurface = m_mixerInput[1].videoSurface;
2404 void CMixer::FiniCycle()
2406 // Keep video surfaces for one 2 cycles longer than used
2407 // by mixer. This avoids blocking in decoder.
2408 // NVidia recommends num_ref + 5
2409 while (m_mixerInput.size() > 5)
2411 CVdpauDecodedPicture &tmp = m_mixerInput.back();
2412 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
2414 m_config.videoSurfaces->ClearRender(tmp.videoSurface);
2416 m_mixerInput.pop_back();
2420 void CMixer::ProcessPicture()
2422 if (m_processPicture.DVDPic.format == RENDER_FMT_VDPAU_420)
2427 if (m_mixerstep == 1)
2429 if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD)
2430 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
2432 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
2435 VdpVideoSurface past_surfaces[4] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
2436 VdpVideoSurface futu_surfaces[2] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
2437 uint32_t pastCount = 4;
2438 uint32_t futuCount = 2;
2440 if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME)
2442 // use only 2 past 1 future for progressive/weave
2443 // (only used for postproc anyway eg noise reduction)
2444 if (m_mixerInput.size() > 3)
2445 past_surfaces[1] = m_mixerInput[3].videoSurface;
2446 if (m_mixerInput.size() > 2)
2447 past_surfaces[0] = m_mixerInput[2].videoSurface;
2448 futu_surfaces[0] = m_mixerInput[0].videoSurface;
2454 if(m_mixerstep == 0)
2456 if (m_mixerInput.size() > 3)
2458 past_surfaces[3] = m_mixerInput[3].videoSurface;
2459 past_surfaces[2] = m_mixerInput[3].videoSurface;
2461 if (m_mixerInput.size() > 2)
2463 past_surfaces[1] = m_mixerInput[2].videoSurface;
2464 past_surfaces[0] = m_mixerInput[2].videoSurface;
2466 futu_surfaces[0] = m_mixerInput[1].videoSurface;
2467 futu_surfaces[1] = m_mixerInput[0].videoSurface;
2471 if (m_mixerInput.size() > 3)
2473 past_surfaces[3] = m_mixerInput[3].videoSurface;
2475 if (m_mixerInput.size() > 2)
2477 past_surfaces[2] = m_mixerInput[2].videoSurface;
2478 past_surfaces[1] = m_mixerInput[2].videoSurface;
2480 past_surfaces[0] = m_mixerInput[1].videoSurface;
2481 futu_surfaces[0] = m_mixerInput[0].videoSurface;
2482 futu_surfaces[1] = m_mixerInput[0].videoSurface;
2484 if (m_mixerInput[0].DVDPic.pts != DVD_NOPTS_VALUE &&
2485 m_mixerInput[1].DVDPic.pts != DVD_NOPTS_VALUE)
2487 m_processPicture.DVDPic.pts = m_mixerInput[1].DVDPic.pts +
2488 (m_mixerInput[0].DVDPic.pts -
2489 m_mixerInput[1].DVDPic.pts) / 2;
2492 m_processPicture.DVDPic.pts = DVD_NOPTS_VALUE;
2493 m_processPicture.DVDPic.dts = DVD_NOPTS_VALUE;
2495 m_processPicture.DVDPic.iRepeatPicture = 0.0;
2501 sourceRect.x1 = m_config.vidWidth;
2502 sourceRect.y1 = m_config.vidHeight;
2507 destRect.x1 = m_config.outWidth;
2508 destRect.y1 = m_config.outHeight;
2510 // start vdpau video mixer
2511 vdp_st = m_config.context->GetProcs().vdp_video_mixer_render(m_videoMixer,
2517 m_mixerInput[1].videoSurface,
2521 m_processPicture.outputSurface,
2526 CheckStatus(vdp_st, __LINE__);
2530 bool CMixer::CheckStatus(VdpStatus vdp_st, int line)
2532 if (vdp_st != VDP_STATUS_OK)
2534 CLog::Log(LOGERROR, " (VDPAU) Error: %s(%d) at %s:%d\n", m_config.context->GetProcs().vdp_get_error_string(vdp_st), vdp_st, __FILE__, line);
2541 //-----------------------------------------------------------------------------
2543 //-----------------------------------------------------------------------------
2545 VdpauBufferPool::VdpauBufferPool()
2547 CVdpauRenderPicture *pic;
2548 for (unsigned int i = 0; i < NUM_RENDER_PICS; i++)
2550 pic = new CVdpauRenderPicture(renderPicSec);
2551 allRenderPics.push_back(pic);
2555 VdpauBufferPool::~VdpauBufferPool()
2557 CVdpauRenderPicture *pic;
2558 for (unsigned int i = 0; i < NUM_RENDER_PICS; i++)
2560 pic = allRenderPics[i];
2563 allRenderPics.clear();
2566 //-----------------------------------------------------------------------------
2568 //-----------------------------------------------------------------------------
2569 COutput::COutput(CEvent *inMsgEvent) :
2570 CThread("Vdpau Output"),
2571 m_controlPort("OutputControlPort", inMsgEvent, &m_outMsgEvent),
2572 m_dataPort("OutputDataPort", inMsgEvent, &m_outMsgEvent),
2573 m_mixer(&m_outMsgEvent)
2575 m_inMsgEvent = inMsgEvent;
2577 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); ++i)
2579 m_bufferPool.freeRenderPics.push_back(i);
2583 void COutput::Start()
2592 m_bufferPool.freeRenderPics.clear();
2593 m_bufferPool.usedRenderPics.clear();
2596 void COutput::Dispose()
2598 CSingleLock lock(g_graphicsContext);
2600 m_outMsgEvent.Set();
2602 m_controlPort.Purge();
2606 void COutput::OnStartup()
2608 CLog::Log(LOGNOTICE, "COutput::OnStartup: Output Thread created");
2611 void COutput::OnExit()
2613 CLog::Log(LOGNOTICE, "COutput::OnExit: Output Thread terminated");
2620 O_TOP_UNCONFIGURED, // 2
2621 O_TOP_CONFIGURED, // 3
2622 O_TOP_CONFIGURED_IDLE, // 4
2623 O_TOP_CONFIGURED_WORK, // 5
2626 int VDPAU_OUTPUT_parentStates[] = {
2629 0, //TOP_UNCONFIGURED
2631 3, //TOP_CONFIGURED_IDLE
2632 3, //TOP_CONFIGURED_WORK
2635 void COutput::StateMachine(int signal, Protocol *port, Message *msg)
2637 for (int state = m_state; ; state = VDPAU_OUTPUT_parentStates[state])
2642 if (port == &m_controlPort)
2646 case COutputControlProtocol::FLUSH:
2647 msg->Reply(COutputControlProtocol::ACC);
2649 case COutputControlProtocol::PRECLEANUP:
2650 msg->Reply(COutputControlProtocol::ACC);
2656 else if (port == &m_dataPort)
2660 case COutputDataProtocol::RETURNPIC:
2661 CVdpauRenderPicture *pic;
2662 pic = *((CVdpauRenderPicture**)msg->data);
2663 QueueReturnPicture(pic);
2670 std::string portName = port == NULL ? "timer" : port->portName;
2671 CLog::Log(LOGWARNING, "COutput::%s - signal: %d form port: %s not handled for state: %d", __FUNCTION__, signal, portName.c_str(), m_state);
2678 case O_TOP_UNCONFIGURED:
2679 if (port == &m_controlPort)
2683 case COutputControlProtocol::INIT:
2685 data = (CVdpauConfig*)msg->data;
2692 if (m_mixer.m_controlPort.SendOutMessageSync(CMixerControlProtocol::INIT,
2693 &reply, 1000, &m_config, sizeof(m_config)))
2695 if (reply->signal != CMixerControlProtocol::ACC)
2700 // set initial number of
2701 m_bufferPool.numOutputSurfaces = 4;
2705 m_state = O_TOP_CONFIGURED_IDLE;
2706 msg->Reply(COutputControlProtocol::ACC, &m_config, sizeof(m_config));
2710 m_state = O_TOP_ERROR;
2711 msg->Reply(COutputControlProtocol::ERROR);
2720 case O_TOP_CONFIGURED:
2721 if (port == &m_controlPort)
2725 case COutputControlProtocol::FLUSH:
2727 msg->Reply(COutputControlProtocol::ACC);
2729 case COutputControlProtocol::PRECLEANUP:
2732 msg->Reply(COutputControlProtocol::ACC);
2738 else if (port == &m_dataPort)
2742 case COutputDataProtocol::NEWFRAME:
2743 CVdpauDecodedPicture *frame;
2744 frame = (CVdpauDecodedPicture*)msg->data;
2747 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::FRAME,
2748 frame,sizeof(CVdpauDecodedPicture));
2751 case COutputDataProtocol::RETURNPIC:
2752 CVdpauRenderPicture *pic;
2753 pic = *((CVdpauRenderPicture**)msg->data);
2754 QueueReturnPicture(pic);
2755 m_controlPort.SendInMessage(COutputControlProtocol::STATS);
2756 m_state = O_TOP_CONFIGURED_WORK;
2763 else if (port == &m_mixer.m_dataPort)
2767 case CMixerDataProtocol::PICTURE:
2768 CVdpauProcessedPicture *pic;
2769 pic = (CVdpauProcessedPicture*)msg->data;
2770 m_bufferPool.processedPics.push(*pic);
2771 m_state = O_TOP_CONFIGURED_WORK;
2780 case O_TOP_CONFIGURED_IDLE:
2781 if (port == NULL) // timeout
2785 case COutputControlProtocol::TIMEOUT:
2786 if (ProcessSyncPicture())
2792 m_state = O_TOP_CONFIGURED_WORK;
2802 case O_TOP_CONFIGURED_WORK:
2803 if (port == NULL) // timeout
2807 case COutputControlProtocol::TIMEOUT:
2810 CVdpauRenderPicture *pic;
2811 pic = ProcessMixerPicture();
2814 m_config.stats->DecProcessed();
2815 m_config.stats->IncRender();
2816 m_dataPort.SendInMessage(COutputDataProtocol::PICTURE, &pic, sizeof(pic));
2822 m_state = O_TOP_CONFIGURED_IDLE;
2832 default: // we are in no state, should not happen
2833 CLog::Log(LOGERROR, "COutput::%s - no valid state: %d", __FUNCTION__, m_state);
2839 void COutput::Process()
2841 Message *msg = NULL;
2842 Protocol *port = NULL;
2845 m_state = O_TOP_UNCONFIGURED;
2846 m_extTimeout = 1000;
2847 m_bStateMachineSelfTrigger = false;
2853 if (m_bStateMachineSelfTrigger)
2855 m_bStateMachineSelfTrigger = false;
2856 // self trigger state machine
2857 StateMachine(msg->signal, port, msg);
2858 if (!m_bStateMachineSelfTrigger)
2865 // check control port
2866 else if (m_controlPort.ReceiveOutMessage(&msg))
2869 port = &m_controlPort;
2872 else if (m_dataPort.ReceiveOutMessage(&msg))
2877 // check mixer data port
2878 else if (m_mixer.m_dataPort.ReceiveInMessage(&msg))
2881 port = &m_mixer.m_dataPort;
2885 StateMachine(msg->signal, port, msg);
2886 if (!m_bStateMachineSelfTrigger)
2895 else if (m_outMsgEvent.WaitMSec(m_extTimeout))
2902 msg = m_controlPort.GetMessage();
2903 msg->signal = COutputControlProtocol::TIMEOUT;
2905 // signal timeout to state machine
2906 StateMachine(msg->signal, port, msg);
2907 if (!m_bStateMachineSelfTrigger)
2918 bool COutput::Init()
2920 if (!CreateGlxContext())
2932 bool COutput::Uninit()
2936 ReleaseBufferPool();
2937 DestroyGlxContext();
2941 void COutput::Flush()
2943 if (m_mixer.IsActive())
2946 if (m_mixer.m_controlPort.SendOutMessageSync(CMixerControlProtocol::FLUSH,
2953 CLog::Log(LOGERROR, "Coutput::%s - failed to flush mixer", __FUNCTION__);
2957 while (m_mixer.m_dataPort.ReceiveInMessage(&msg))
2959 if (msg->signal == CMixerDataProtocol::PICTURE)
2961 CVdpauProcessedPicture pic = *(CVdpauProcessedPicture*)msg->data;
2962 m_bufferPool.processedPics.push(pic);
2967 while (m_dataPort.ReceiveOutMessage(&msg))
2969 if (msg->signal == COutputDataProtocol::NEWFRAME)
2971 CVdpauDecodedPicture pic = *(CVdpauDecodedPicture*)msg->data;
2972 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2974 else if (msg->signal == COutputDataProtocol::RETURNPIC)
2976 CVdpauRenderPicture *pic;
2977 pic = *((CVdpauRenderPicture**)msg->data);
2978 QueueReturnPicture(pic);
2983 while (m_dataPort.ReceiveInMessage(&msg))
2985 if (msg->signal == COutputDataProtocol::PICTURE)
2987 CVdpauRenderPicture *pic;
2988 pic = *((CVdpauRenderPicture**)msg->data);
2989 QueueReturnPicture(pic);
2993 // reset used render flag which was cleared on mixer flush
2994 std::deque<int>::iterator it;
2995 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
2997 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[*it];
2998 if (pic->DVDPic.format == RENDER_FMT_VDPAU_420)
3000 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it2;
3001 it2 = m_bufferPool.glVideoSurfaceMap.find(pic->sourceIdx);
3002 if (it2 == m_bufferPool.glVideoSurfaceMap.end())
3004 CLog::Log(LOGDEBUG, "COutput::Flush - gl surface not found");
3007 m_config.videoSurfaces->MarkRender(it2->second.sourceVuv);
3011 // clear processed pics
3012 while(!m_bufferPool.processedPics.empty())
3014 CVdpauProcessedPicture procPic = m_bufferPool.processedPics.front();
3015 if (procPic.DVDPic.format == RENDER_FMT_VDPAU)
3017 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER, &procPic.outputSurface, sizeof(procPic.outputSurface));
3019 else if (procPic.DVDPic.format == RENDER_FMT_VDPAU_420)
3021 m_config.videoSurfaces->ClearRender(procPic.videoSurface);
3023 m_bufferPool.processedPics.pop();
3027 bool COutput::HasWork()
3029 if (!m_bufferPool.processedPics.empty() && !m_bufferPool.freeRenderPics.empty())
3034 CVdpauRenderPicture* COutput::ProcessMixerPicture()
3036 CVdpauRenderPicture *retPic = NULL;
3038 if (!m_bufferPool.processedPics.empty() && !m_bufferPool.freeRenderPics.empty())
3040 int idx = m_bufferPool.freeRenderPics.front();
3041 retPic = m_bufferPool.allRenderPics[idx];
3042 m_bufferPool.freeRenderPics.pop_front();
3043 m_bufferPool.usedRenderPics.push_back(idx);
3044 CVdpauProcessedPicture procPic = m_bufferPool.processedPics.front();
3045 m_bufferPool.processedPics.pop();
3047 retPic->DVDPic = procPic.DVDPic;
3048 retPic->valid = true;
3049 if (retPic->DVDPic.format == RENDER_FMT_VDPAU)
3051 m_config.useInteropYuv = false;
3052 m_bufferPool.numOutputSurfaces = NUM_RENDER_PICS;
3055 retPic->sourceIdx = procPic.outputSurface;
3056 retPic->texture[0] = m_bufferPool.glOutputSurfaceMap[procPic.outputSurface].texture[0];
3057 retPic->texWidth = m_config.outWidth;
3058 retPic->texHeight = m_config.outHeight;
3059 retPic->crop.x1 = 0;
3060 retPic->crop.y1 = (m_config.outHeight - retPic->DVDPic.iHeight) / 2;
3061 retPic->crop.x2 = m_config.outWidth;
3062 retPic->crop.y2 = m_config.outHeight - retPic->crop.y1;
3066 m_config.useInteropYuv = true;
3068 retPic->sourceIdx = procPic.videoSurface;
3069 for (unsigned int i=0; i<4; ++i)
3070 retPic->texture[i] = m_bufferPool.glVideoSurfaceMap[procPic.videoSurface].texture[i];
3071 retPic->texWidth = m_config.surfaceWidth;
3072 retPic->texHeight = m_config.surfaceHeight;
3073 retPic->crop.x1 = 0;
3074 retPic->crop.y1 = 0;
3075 retPic->crop.x2 = m_config.surfaceWidth - m_config.vidWidth;
3076 retPic->crop.y2 = m_config.surfaceHeight - m_config.vidHeight;
3082 void COutput::QueueReturnPicture(CVdpauRenderPicture *pic)
3084 std::deque<int>::iterator it;
3085 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3087 if (m_bufferPool.allRenderPics[*it] == pic)
3093 if (it == m_bufferPool.usedRenderPics.end())
3095 CLog::Log(LOGWARNING, "COutput::QueueReturnPicture - pic not found");
3099 // check if already queued
3100 std::deque<int>::iterator it2 = find(m_bufferPool.syncRenderPics.begin(),
3101 m_bufferPool.syncRenderPics.end(),
3103 if (it2 == m_bufferPool.syncRenderPics.end())
3105 m_bufferPool.syncRenderPics.push_back(*it);
3108 ProcessSyncPicture();
3111 bool COutput::ProcessSyncPicture()
3113 CVdpauRenderPicture *pic;
3116 std::deque<int>::iterator it;
3117 for (it = m_bufferPool.syncRenderPics.begin(); it != m_bufferPool.syncRenderPics.end(); )
3119 pic = m_bufferPool.allRenderPics[*it];
3124 if (glIsSync(pic->fence))
3128 glGetSynciv(pic->fence, GL_SYNC_STATUS, 1, &length, &state);
3129 if(state == GL_SIGNALED)
3131 glDeleteSync(pic->fence);
3144 m_bufferPool.freeRenderPics.push_back(*it);
3146 std::deque<int>::iterator it2 = find(m_bufferPool.usedRenderPics.begin(),
3147 m_bufferPool.usedRenderPics.end(),
3149 if (it2 == m_bufferPool.usedRenderPics.end())
3151 CLog::Log(LOGERROR, "COutput::ProcessSyncPicture - pic not found in queue");
3155 m_bufferPool.usedRenderPics.erase(it2);
3157 it = m_bufferPool.syncRenderPics.erase(it);
3161 ProcessReturnPicture(pic);
3165 CLog::Log(LOGDEBUG, "COutput::%s - return of invalid render pic", __FUNCTION__);
3171 void COutput::ProcessReturnPicture(CVdpauRenderPicture *pic)
3173 if (pic->DVDPic.format == RENDER_FMT_VDPAU_420)
3175 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3176 it = m_bufferPool.glVideoSurfaceMap.find(pic->sourceIdx);
3177 if (it == m_bufferPool.glVideoSurfaceMap.end())
3179 CLog::Log(LOGDEBUG, "COutput::ProcessReturnPicture - gl surface not found");
3182 VdpVideoSurface surf = it->second.sourceVuv;
3183 m_config.videoSurfaces->ClearRender(surf);
3185 else if (pic->DVDPic.format == RENDER_FMT_VDPAU)
3187 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3188 it = m_bufferPool.glOutputSurfaceMap.find(pic->sourceIdx);
3189 if (it == m_bufferPool.glOutputSurfaceMap.end())
3191 CLog::Log(LOGDEBUG, "COutput::ProcessReturnPicture - gl surface not found");
3194 VdpOutputSurface outSurf = it->second.sourceRgb;
3195 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER, &outSurf, sizeof(outSurf));
3199 bool COutput::EnsureBufferPool()
3203 // Creation of outputSurfaces
3204 VdpOutputSurface outputSurface;
3205 for (int i = m_bufferPool.outputSurfaces.size(); i < m_bufferPool.numOutputSurfaces; i++)
3207 vdp_st = m_config.context->GetProcs().vdp_output_surface_create(m_config.context->GetDevice(),
3208 VDP_RGBA_FORMAT_B8G8R8A8,
3212 if (CheckStatus(vdp_st, __LINE__))
3214 m_bufferPool.outputSurfaces.push_back(outputSurface);
3216 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER,
3218 sizeof(VdpOutputSurface));
3219 CLog::Log(LOGNOTICE, "VDPAU::COutput::InitBufferPool - Output Surface created");
3224 void COutput::ReleaseBufferPool()
3228 CSingleLock lock(m_bufferPool.renderPicSec);
3230 // release all output surfaces
3231 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3233 if (m_bufferPool.outputSurfaces[i] == VDP_INVALID_HANDLE)
3235 vdp_st = m_config.context->GetProcs().vdp_output_surface_destroy(m_bufferPool.outputSurfaces[i]);
3236 CheckStatus(vdp_st, __LINE__);
3238 m_bufferPool.outputSurfaces.clear();
3240 // wait for all fences
3241 XbmcThreads::EndTime timeout(1000);
3242 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); i++)
3244 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[i];
3248 while (glIsSync(pic->fence))
3252 glGetSynciv(pic->fence, GL_SYNC_STATUS, 1, &length, &state);
3253 if(state == GL_SIGNALED || timeout.IsTimePast())
3255 glDeleteSync(pic->fence);
3266 if (timeout.IsTimePast())
3268 CLog::Log(LOGERROR, "COutput::%s - timeout waiting for fence", __FUNCTION__);
3270 ProcessSyncPicture();
3272 // invalidate all used render pictures
3273 for (unsigned int i = 0; i < m_bufferPool.usedRenderPics.size(); ++i)
3275 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[m_bufferPool.usedRenderPics[i]];
3280 void COutput::PreCleanup()
3286 ProcessSyncPicture();
3288 CSingleLock lock(m_bufferPool.renderPicSec);
3289 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3291 if (m_bufferPool.outputSurfaces[i] == VDP_INVALID_HANDLE)
3294 // check if output surface is in use
3296 std::deque<int>::iterator it;
3297 CVdpauRenderPicture *pic;
3298 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3300 pic = m_bufferPool.allRenderPics[*it];
3301 if ((pic->sourceIdx == m_bufferPool.outputSurfaces[i]) && pic->valid)
3310 #ifdef GL_NV_vdpau_interop
3312 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it_map;
3313 it_map = m_bufferPool.glOutputSurfaceMap.find(m_bufferPool.outputSurfaces[i]);
3314 if (it_map == m_bufferPool.glOutputSurfaceMap.end())
3316 CLog::Log(LOGERROR, "%s - could not find gl surface", __FUNCTION__);
3319 glVDPAUUnregisterSurfaceNV(it_map->second.glVdpauSurface);
3320 glDeleteTextures(1, it_map->second.texture);
3321 m_bufferPool.glOutputSurfaceMap.erase(it_map);
3324 vdp_st = m_config.context->GetProcs().vdp_output_surface_destroy(m_bufferPool.outputSurfaces[i]);
3325 CheckStatus(vdp_st, __LINE__);
3327 m_bufferPool.outputSurfaces[i] = VDP_INVALID_HANDLE;
3329 CLog::Log(LOGDEBUG, "VDPAU::PreCleanup - released output surface");
3334 void COutput::InitMixer()
3336 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3338 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER,
3339 &m_bufferPool.outputSurfaces[i],
3340 sizeof(VdpOutputSurface));
3344 bool COutput::GLInit()
3346 #ifdef GL_NV_vdpau_interop
3347 glVDPAUInitNV = NULL;
3348 glVDPAUFiniNV = NULL;
3349 glVDPAURegisterOutputSurfaceNV = NULL;
3350 glVDPAURegisterVideoSurfaceNV = NULL;
3351 glVDPAUIsSurfaceNV = NULL;
3352 glVDPAUUnregisterSurfaceNV = NULL;
3353 glVDPAUSurfaceAccessNV = NULL;
3354 glVDPAUMapSurfacesNV = NULL;
3355 glVDPAUUnmapSurfacesNV = NULL;
3356 glVDPAUGetSurfaceivNV = NULL;
3359 #ifdef GL_NV_vdpau_interop
3361 glVDPAUInitNV = (PFNGLVDPAUINITNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUInitNV");
3363 glVDPAUFiniNV = (PFNGLVDPAUFININVPROC)glXGetProcAddress((GLubyte *) "glVDPAUFiniNV");
3364 if (!glVDPAURegisterOutputSurfaceNV)
3365 glVDPAURegisterOutputSurfaceNV = (PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAURegisterOutputSurfaceNV");
3366 if (!glVDPAURegisterVideoSurfaceNV)
3367 glVDPAURegisterVideoSurfaceNV = (PFNGLVDPAUREGISTERVIDEOSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAURegisterVideoSurfaceNV");
3368 if (!glVDPAUIsSurfaceNV)
3369 glVDPAUIsSurfaceNV = (PFNGLVDPAUISSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAUIsSurfaceNV");
3370 if (!glVDPAUUnregisterSurfaceNV)
3371 glVDPAUUnregisterSurfaceNV = (PFNGLVDPAUUNREGISTERSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAUUnregisterSurfaceNV");
3372 if (!glVDPAUSurfaceAccessNV)
3373 glVDPAUSurfaceAccessNV = (PFNGLVDPAUSURFACEACCESSNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUSurfaceAccessNV");
3374 if (!glVDPAUMapSurfacesNV)
3375 glVDPAUMapSurfacesNV = (PFNGLVDPAUMAPSURFACESNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUMapSurfacesNV");
3376 if (!glVDPAUUnmapSurfacesNV)
3377 glVDPAUUnmapSurfacesNV = (PFNGLVDPAUUNMAPSURFACESNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUUnmapSurfacesNV");
3378 if (!glVDPAUGetSurfaceivNV)
3379 glVDPAUGetSurfaceivNV = (PFNGLVDPAUGETSURFACEIVNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUGetSurfaceivNV");
3381 while (glGetError() != GL_NO_ERROR);
3382 glVDPAUInitNV(reinterpret_cast<void*>(m_config.context->GetDevice()), reinterpret_cast<void*>(m_config.context->GetProcs().vdp_get_proc_address));
3383 if (glGetError() != GL_NO_ERROR)
3385 CLog::Log(LOGERROR, "VDPAU::COutput - GLInitInterop glVDPAUInitNV failed");
3389 CLog::Log(LOGNOTICE, "VDPAU::COutput: vdpau gl interop initialized");
3393 bool hasfence = glewIsSupported("GL_ARB_sync");
3394 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); i++)
3396 m_bufferPool.allRenderPics[i]->usefence = hasfence;
3403 void COutput::GLMapSurfaces()
3405 #ifdef GL_NV_vdpau_interop
3407 if (m_config.useInteropYuv)
3409 VdpauBufferPool::GLVideoSurface glSurface;
3410 VdpVideoSurface surf;
3411 if (m_config.videoSurfaces->Size() != m_bufferPool.glVideoSurfaceMap.size())
3413 for (unsigned int i = 0; i < m_config.videoSurfaces->Size(); i++)
3415 surf = m_config.videoSurfaces->GetAtIndex(i);
3417 if (surf == VDP_INVALID_HANDLE)
3420 if (m_bufferPool.glVideoSurfaceMap.find(surf) == m_bufferPool.glVideoSurfaceMap.end())
3422 glSurface.sourceVuv = surf;
3423 while (glGetError() != GL_NO_ERROR) ;
3424 glGenTextures(4, glSurface.texture);
3425 if (glGetError() != GL_NO_ERROR)
3427 CLog::Log(LOGERROR, "VDPAU::COutput error creating texture");
3430 glSurface.glVdpauSurface = glVDPAURegisterVideoSurfaceNV(reinterpret_cast<void*>(surf),
3431 GL_TEXTURE_2D, 4, glSurface.texture);
3433 if (glGetError() != GL_NO_ERROR)
3435 CLog::Log(LOGERROR, "VDPAU::COutput error register video surface");
3438 glVDPAUSurfaceAccessNV(glSurface.glVdpauSurface, GL_READ_ONLY);
3439 if (glGetError() != GL_NO_ERROR)
3441 CLog::Log(LOGERROR, "VDPAU::COutput error setting access");
3444 glVDPAUMapSurfacesNV(1, &glSurface.glVdpauSurface);
3445 if (glGetError() != GL_NO_ERROR)
3447 CLog::Log(LOGERROR, "VDPAU::COutput error mapping surface");
3450 m_bufferPool.glVideoSurfaceMap[surf] = glSurface;
3453 CLog::Log(LOGNOTICE, "VDPAU::COutput registered surface");
3460 if (m_bufferPool.glOutputSurfaceMap.size() != m_bufferPool.numOutputSurfaces)
3462 VdpauBufferPool::GLVideoSurface glSurface;
3463 for (unsigned int i = m_bufferPool.glOutputSurfaceMap.size(); i<m_bufferPool.outputSurfaces.size(); i++)
3465 glSurface.sourceRgb = m_bufferPool.outputSurfaces[i];
3466 glGenTextures(1, glSurface.texture);
3467 glSurface.glVdpauSurface = glVDPAURegisterOutputSurfaceNV(reinterpret_cast<void*>(m_bufferPool.outputSurfaces[i]),
3468 GL_TEXTURE_2D, 1, glSurface.texture);
3469 if (glGetError() != GL_NO_ERROR)
3471 CLog::Log(LOGERROR, "VDPAU::COutput error register output surface");
3474 glVDPAUSurfaceAccessNV(glSurface.glVdpauSurface, GL_READ_ONLY);
3475 if (glGetError() != GL_NO_ERROR)
3477 CLog::Log(LOGERROR, "VDPAU::COutput error setting access");
3480 glVDPAUMapSurfacesNV(1, &glSurface.glVdpauSurface);
3481 if (glGetError() != GL_NO_ERROR)
3483 CLog::Log(LOGERROR, "VDPAU::COutput error mapping surface");
3486 m_bufferPool.glOutputSurfaceMap[m_bufferPool.outputSurfaces[i]] = glSurface;
3490 CLog::Log(LOGNOTICE, "VDPAU::COutput registered output surfaces");
3496 void COutput::GLUnmapSurfaces()
3498 #ifdef GL_NV_vdpau_interop
3501 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3502 for (it = m_bufferPool.glVideoSurfaceMap.begin(); it != m_bufferPool.glVideoSurfaceMap.end(); ++it)
3504 glVDPAUUnregisterSurfaceNV(it->second.glVdpauSurface);
3505 glDeleteTextures(4, it->second.texture);
3507 m_bufferPool.glVideoSurfaceMap.clear();
3510 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3511 for (it = m_bufferPool.glOutputSurfaceMap.begin(); it != m_bufferPool.glOutputSurfaceMap.end(); ++it)
3513 glVDPAUUnregisterSurfaceNV(it->second.glVdpauSurface);
3514 glDeleteTextures(1, it->second.texture);
3516 m_bufferPool.glOutputSurfaceMap.clear();
3520 CLog::Log(LOGNOTICE, "VDPAU::COutput: vdpau gl interop finished");
3525 bool COutput::CheckStatus(VdpStatus vdp_st, int line)
3527 if (vdp_st != VDP_STATUS_OK)
3529 CLog::Log(LOGERROR, " (VDPAU) Error: %s(%d) at %s:%d\n", m_config.context->GetProcs().vdp_get_error_string(vdp_st), vdp_st, __FILE__, line);
3536 bool COutput::CreateGlxContext()
3538 GLXContext glContext;
3540 m_Display = g_Windowing.GetDisplay();
3541 glContext = g_Windowing.GetGlxContext();
3542 m_Window = g_Windowing.GetWindow();
3544 // Get our window attribs.
3545 XWindowAttributes wndattribs;
3546 XGetWindowAttributes(m_Display, m_Window, &wndattribs);
3549 XVisualInfo visInfo;
3550 visInfo.visualid = wndattribs.visual->visualid;
3552 XVisualInfo* visuals = XGetVisualInfo(m_Display, VisualIDMask, &visInfo, &nvisuals);
3555 CLog::Log(LOGERROR, "VDPAU::COutput::CreateGlxContext - could not find visual");
3558 visInfo = visuals[0];
3561 m_pixmap = XCreatePixmap(m_Display,
3568 CLog::Log(LOGERROR, "VDPAU::COutput::CreateGlxContext - Unable to create XPixmap");
3573 m_glPixmap = glXCreateGLXPixmap(m_Display, &visInfo, m_pixmap);
3577 CLog::Log(LOGINFO, "VDPAU::COutput::CreateGlxContext - Could not create glPixmap");
3581 m_glContext = glXCreateContext(m_Display, &visInfo, glContext, True);
3583 if (!glXMakeCurrent(m_Display, m_glPixmap, m_glContext))
3585 CLog::Log(LOGINFO, "VDPAU::COutput::CreateGlxContext - Could not make Pixmap current");
3589 CLog::Log(LOGNOTICE, "VDPAU::COutput::CreateGlxContext - created context");
3593 bool COutput::DestroyGlxContext()
3597 glXMakeCurrent(m_Display, None, NULL);
3598 glXDestroyContext(m_Display, m_glContext);
3603 glXDestroyPixmap(m_Display, m_glPixmap);
3607 XFreePixmap(m_Display, m_pixmap);