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 std::string gpuvendor = g_Windowing.GetRenderVendor();
500 std::transform(gpuvendor.begin(), gpuvendor.end(), gpuvendor.begin(), ::tolower);
501 // nvidia is whitelisted despite for mpeg-4 we need to query user settings
502 if ((gpuvendor.compare(0, 6, "nvidia") != 0) || (avctx->codec_id == AV_CODEC_ID_MPEG4) || (avctx->codec_id == AV_CODEC_ID_H263))
504 if (CDVDVideoCodec::IsCodecDisabled(g_vdpau_available, settings_count, avctx->codec_id))
508 #ifndef GL_NV_vdpau_interop
509 CLog::Log(LOGNOTICE, "VDPAU: compilation without required extension GL_NV_vdpau_interop");
512 if (!g_Windowing.IsExtSupported("GL_NV_vdpau_interop"))
514 CLog::Log(LOGNOTICE, "VDPAU: required extension GL_NV_vdpau_interop not found");
518 if(avctx->coded_width == 0
519 || avctx->coded_height == 0)
521 CLog::Log(LOGWARNING,"(VDPAU) no width/height available, can't init");
524 m_vdpauConfig.numRenderBuffers = surfaces;
525 m_decoderThread = CThread::GetCurrentThreadId();
527 if (!CVDPAUContext::EnsureContext(&m_vdpauConfig.context))
530 m_DisplayState = VDPAU_OPEN;
531 m_vdpauConfigured = false;
533 if (!m_dllAvUtil.Load())
536 m_presentPicture = 0;
539 VdpDecoderProfile profile = 0;
540 if(avctx->codec_id == AV_CODEC_ID_H264)
541 profile = VDP_DECODER_PROFILE_H264_HIGH;
542 #ifdef VDP_DECODER_PROFILE_MPEG4_PART2_ASP
543 else if(avctx->codec_id == AV_CODEC_ID_MPEG4)
544 profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
548 if (!CDVDCodecUtils::IsVP3CompatibleWidth(avctx->coded_width))
549 CLog::Log(LOGWARNING,"(VDPAU) width %i might not be supported because of hardware bug", avctx->width);
551 /* attempt to create a decoder with this width/height, some sizes are not supported by hw */
553 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_create(m_vdpauConfig.context->GetDevice(), profile, avctx->coded_width, avctx->coded_height, 5, &m_vdpauConfig.vdpDecoder);
555 if(vdp_st != VDP_STATUS_OK)
557 CLog::Log(LOGERROR, " (VDPAU) Error: %s(%d) checking for decoder support\n", m_vdpauConfig.context->GetProcs().vdp_get_error_string(vdp_st), vdp_st);
561 m_vdpauConfig.context->GetProcs().vdp_decoder_destroy(m_vdpauConfig.vdpDecoder);
562 CheckStatus(vdp_st, __LINE__);
565 /* finally setup ffmpeg */
566 memset(&m_hwContext, 0, sizeof(AVVDPAUContext));
567 m_hwContext.render = CDecoder::Render;
568 m_hwContext.bitstream_buffers_allocated = 0;
569 avctx->get_buffer = CDecoder::FFGetBuffer;
570 avctx->reget_buffer = CDecoder::FFGetBuffer;
571 avctx->release_buffer = CDecoder::FFReleaseBuffer;
572 avctx->draw_horiz_band = CDecoder::FFDrawSlice;
573 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD;
574 avctx->hwaccel_context = &m_hwContext;
575 avctx->thread_count = 1;
577 g_Windowing.Register(this);
583 CDecoder::~CDecoder()
588 void CDecoder::Close()
590 CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);
592 g_Windowing.Unregister(this);
594 CSingleLock lock(m_DecoderSection);
597 m_vdpauOutput.Dispose();
599 if (m_hwContext.bitstream_buffers_allocated)
601 m_dllAvUtil.av_freep(&m_hwContext.bitstream_buffers);
604 m_dllAvUtil.Unload();
606 if (m_vdpauConfig.context)
607 m_vdpauConfig.context->Release();
608 m_vdpauConfig.context = 0;
611 long CDecoder::Release()
613 // check if we should do some pre-cleanup here
614 // a second decoder might need resources
615 if (m_vdpauConfigured == true)
617 CSingleLock lock(m_DecoderSection);
618 CLog::Log(LOGNOTICE,"CVDPAU::Release pre-cleanup");
621 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::PRECLEANUP,
625 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
629 CLog::Log(LOGERROR, "VDPAU::%s - pre-cleanup returned error", __FUNCTION__);
630 m_DisplayState = VDPAU_ERROR;
635 CLog::Log(LOGERROR, "VDPAU::%s - pre-cleanup timed out", __FUNCTION__);
636 m_DisplayState = VDPAU_ERROR;
639 VdpVideoSurface surf;
640 while((surf = m_videoSurfaces.RemoveNext(true)) != VDP_INVALID_HANDLE)
642 m_vdpauConfig.context->GetProcs().vdp_video_surface_destroy(surf);
645 return IHardwareDecoder::Release();
648 long CDecoder::ReleasePicReference()
650 return IHardwareDecoder::Release();
653 void CDecoder::SetWidthHeight(int width, int height)
655 m_vdpauConfig.upscale = g_advancedSettings.m_videoVDPAUScaling;
657 //pick the smallest dimensions, so we downscale with vdpau and upscale with opengl when appropriate
658 //this requires the least amount of gpu memory bandwidth
659 if (g_graphicsContext.GetWidth() < width || g_graphicsContext.GetHeight() < height || m_vdpauConfig.upscale >= 0)
661 //scale width to desktop size if the aspect ratio is the same or bigger than the desktop
662 if ((double)height * g_graphicsContext.GetWidth() / width <= (double)g_graphicsContext.GetHeight())
664 m_vdpauConfig.outWidth = g_graphicsContext.GetWidth();
665 m_vdpauConfig.outHeight = MathUtils::round_int((double)height * g_graphicsContext.GetWidth() / width);
667 else //scale height to the desktop size if the aspect ratio is smaller than the desktop
669 m_vdpauConfig.outHeight = g_graphicsContext.GetHeight();
670 m_vdpauConfig.outWidth = MathUtils::round_int((double)width * g_graphicsContext.GetHeight() / height);
675 m_vdpauConfig.outWidth = width;
676 m_vdpauConfig.outHeight = height;
678 CLog::Log(LOGDEBUG, "CVDPAU::SetWidthHeight Setting OutWidth: %i OutHeight: %i", m_vdpauConfig.outWidth, m_vdpauConfig.outHeight);
681 void CDecoder::OnLostDevice()
683 CLog::Log(LOGNOTICE,"CVDPAU::OnLostDevice event");
685 int count = g_graphicsContext.exit();
687 CSingleLock lock(m_DecoderSection);
689 if (m_vdpauConfig.context)
690 m_vdpauConfig.context->Release();
691 m_vdpauConfig.context = 0;
693 m_DisplayState = VDPAU_LOST;
695 m_DisplayEvent.Reset();
697 g_graphicsContext.restore(count);
700 void CDecoder::OnResetDevice()
702 CLog::Log(LOGNOTICE,"CVDPAU::OnResetDevice event");
704 int count = g_graphicsContext.exit();
706 CSingleLock lock(m_DecoderSection);
707 if (m_DisplayState == VDPAU_LOST)
709 m_DisplayState = VDPAU_RESET;
711 m_DisplayEvent.Set();
714 g_graphicsContext.restore(count);
717 int CDecoder::Check(AVCodecContext* avctx)
721 { CSingleLock lock(m_DecoderSection);
722 state = m_DisplayState;
725 if (state == VDPAU_LOST)
727 CLog::Log(LOGNOTICE,"CVDPAU::Check waiting for display reset event");
728 if (!m_DisplayEvent.WaitMSec(4000))
730 CLog::Log(LOGERROR, "CVDPAU::Check - device didn't reset in reasonable time");
735 CSingleLock lock(m_DecoderSection);
736 state = m_DisplayState;
739 if (state == VDPAU_RESET || state == VDPAU_ERROR)
741 CSingleLock lock(m_DecoderSection);
744 if (m_vdpauConfig.context)
745 m_vdpauConfig.context->Release();
746 m_vdpauConfig.context = 0;
748 if (CVDPAUContext::EnsureContext(&m_vdpauConfig.context))
750 m_DisplayState = VDPAU_OPEN;
751 m_vdpauConfigured = false;
754 if (state == VDPAU_RESET)
762 bool CDecoder::IsVDPAUFormat(PixelFormat format)
764 if (format == AV_PIX_FMT_VDPAU)
770 bool CDecoder::Supports(VdpVideoMixerFeature feature)
772 return m_vdpauConfig.context->Supports(feature);
775 bool CDecoder::Supports(EINTERLACEMETHOD method)
777 if(method == VS_INTERLACEMETHOD_VDPAU_BOB
778 || method == VS_INTERLACEMETHOD_AUTO)
781 if (method == VS_INTERLACEMETHOD_RENDER_BOB)
784 if (method == VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE)
787 for(SInterlaceMapping* p = g_interlace_mapping; p->method != VS_INTERLACEMETHOD_NONE; p++)
789 if(p->method == method)
790 return Supports(p->feature);
795 EINTERLACEMETHOD CDecoder::AutoInterlaceMethod()
797 return VS_INTERLACEMETHOD_RENDER_BOB;
800 void CDecoder::FiniVDPAUOutput()
802 if (!m_vdpauConfigured)
805 CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);
808 m_vdpauOutput.Dispose();
809 m_vdpauConfigured = false;
813 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_destroy(m_vdpauConfig.vdpDecoder);
814 if (CheckStatus(vdp_st, __LINE__))
816 m_vdpauConfig.vdpDecoder = VDP_INVALID_HANDLE;
818 CLog::Log(LOGDEBUG, "CVDPAU::FiniVDPAUOutput destroying %d video surfaces", m_videoSurfaces.Size());
820 VdpVideoSurface surf;
821 while((surf = m_videoSurfaces.RemoveNext()) != VDP_INVALID_HANDLE)
823 m_vdpauConfig.context->GetProcs().vdp_video_surface_destroy(surf);
824 if (CheckStatus(vdp_st, __LINE__))
827 m_videoSurfaces.Reset();
830 void CDecoder::ReadFormatOf( AVCodecID codec
831 , VdpDecoderProfile &vdp_decoder_profile
832 , VdpChromaType &vdp_chroma_type)
836 case AV_CODEC_ID_MPEG1VIDEO:
837 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
838 vdp_chroma_type = VDP_CHROMA_TYPE_420;
840 case AV_CODEC_ID_MPEG2VIDEO:
841 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
842 vdp_chroma_type = VDP_CHROMA_TYPE_420;
844 case AV_CODEC_ID_H264:
845 vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
846 vdp_chroma_type = VDP_CHROMA_TYPE_420;
848 case AV_CODEC_ID_WMV3:
849 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
850 vdp_chroma_type = VDP_CHROMA_TYPE_420;
852 case AV_CODEC_ID_VC1:
853 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
854 vdp_chroma_type = VDP_CHROMA_TYPE_420;
856 case AV_CODEC_ID_MPEG4:
857 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
858 vdp_chroma_type = VDP_CHROMA_TYPE_420;
861 vdp_decoder_profile = 0;
867 bool CDecoder::ConfigVDPAU(AVCodecContext* avctx, int ref_frames)
872 VdpDecoderProfile vdp_decoder_profile;
874 m_vdpauConfig.vidWidth = avctx->width;
875 m_vdpauConfig.vidHeight = avctx->height;
876 m_vdpauConfig.surfaceWidth = avctx->coded_width;
877 m_vdpauConfig.surfaceHeight = avctx->coded_height;
879 SetWidthHeight(avctx->width,avctx->height);
881 CLog::Log(LOGNOTICE, " (VDPAU) screenWidth:%i vidWidth:%i surfaceWidth:%i",m_vdpauConfig.outWidth,m_vdpauConfig.vidWidth,m_vdpauConfig.surfaceWidth);
882 CLog::Log(LOGNOTICE, " (VDPAU) screenHeight:%i vidHeight:%i surfaceHeight:%i",m_vdpauConfig.outHeight,m_vdpauConfig.vidHeight,m_vdpauConfig.surfaceHeight);
884 ReadFormatOf(avctx->codec_id, vdp_decoder_profile, m_vdpauConfig.vdpChromaType);
886 if(avctx->codec_id == AV_CODEC_ID_H264)
888 m_vdpauConfig.maxReferences = ref_frames;
889 if (m_vdpauConfig.maxReferences > 16) m_vdpauConfig.maxReferences = 16;
890 if (m_vdpauConfig.maxReferences < 5) m_vdpauConfig.maxReferences = 5;
893 m_vdpauConfig.maxReferences = 2;
895 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_create(m_vdpauConfig.context->GetDevice(),
897 m_vdpauConfig.surfaceWidth,
898 m_vdpauConfig.surfaceHeight,
899 m_vdpauConfig.maxReferences,
900 &m_vdpauConfig.vdpDecoder);
901 if (CheckStatus(vdp_st, __LINE__))
905 CSingleLock lock(g_graphicsContext);
906 m_vdpauConfig.stats = &m_bufferStats;
907 m_vdpauConfig.vdpau = this;
908 m_bufferStats.Reset();
909 m_vdpauOutput.Start();
911 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::INIT,
915 sizeof(m_vdpauConfig)))
917 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
921 CLog::Log(LOGERROR, "VDPAU::%s - vdpau output returned error", __FUNCTION__);
922 m_vdpauOutput.Dispose();
928 CLog::Log(LOGERROR, "VDPAU::%s - failed to init output", __FUNCTION__);
929 m_vdpauOutput.Dispose();
933 m_inMsgEvent.Reset();
934 m_vdpauConfigured = true;
938 int CDecoder::FFGetBuffer(AVCodecContext *avctx, AVFrame *pic)
940 //CLog::Log(LOGNOTICE,"%s",__FUNCTION__);
941 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)avctx->opaque;
942 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
944 // while we are waiting to recover we can't do anything
945 CSingleLock lock(vdp->m_DecoderSection);
947 if(vdp->m_DisplayState != VDPAU_OPEN)
949 CLog::Log(LOGWARNING, "CVDPAU::FFGetBuffer - returning due to awaiting recovery");
953 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)pic->data[3];
954 surf = vdp->m_videoSurfaces.GetFree(surf != 0 ? surf : VDP_INVALID_HANDLE);
956 VdpStatus vdp_st = VDP_STATUS_ERROR;
957 if (surf == VDP_INVALID_HANDLE)
959 // create a new surface
960 VdpDecoderProfile profile;
961 ReadFormatOf(avctx->codec_id, profile, vdp->m_vdpauConfig.vdpChromaType);
963 vdp_st = vdp->m_vdpauConfig.context->GetProcs().vdp_video_surface_create(vdp->m_vdpauConfig.context->GetDevice(),
964 vdp->m_vdpauConfig.vdpChromaType,
968 vdp->CheckStatus(vdp_st, __LINE__);
969 if (vdp_st != VDP_STATUS_OK)
971 CLog::Log(LOGERROR, "CVDPAU::FFGetBuffer - No Video surface available could be created");
974 vdp->m_videoSurfaces.AddSurface(surf);
977 pic->data[1] = pic->data[2] = NULL;
978 pic->data[0] = (uint8_t*)(uintptr_t)surf;
979 pic->data[3] = (uint8_t*)(uintptr_t)surf;
981 pic->linesize[0] = pic->linesize[1] = pic->linesize[2] = 0;
983 pic->type= FF_BUFFER_TYPE_USER;
985 pic->reordered_opaque= avctx->reordered_opaque;
989 void CDecoder::FFReleaseBuffer(AVCodecContext *avctx, AVFrame *pic)
991 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)avctx->opaque;
992 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
994 VdpVideoSurface surf;
997 CSingleLock lock(vdp->m_DecoderSection);
999 surf = (VdpVideoSurface)(uintptr_t)pic->data[3];
1001 vdp->m_videoSurfaces.ClearReference(surf);
1007 VdpStatus CDecoder::Render( VdpDecoder decoder, VdpVideoSurface target,
1008 VdpPictureInfo const *picture_info,
1009 uint32_t bitstream_buffer_count,
1010 VdpBitstreamBuffer const * bitstream_buffers)
1012 return VDP_STATUS_OK;
1015 void CDecoder::FFDrawSlice(struct AVCodecContext *s,
1016 const AVFrame *src, int offset[4],
1017 int y, int type, int height)
1019 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)s->opaque;
1020 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
1022 // while we are waiting to recover we can't do anything
1023 CSingleLock lock(vdp->m_DecoderSection);
1025 if(vdp->m_DisplayState != VDPAU_OPEN)
1028 if(src->linesize[0] || src->linesize[1] || src->linesize[2]
1029 || offset[0] || offset[1] || offset[2])
1031 CLog::Log(LOGERROR, "CVDPAU::FFDrawSlice - invalid linesizes or offsets provided");
1036 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)src->data[3];
1038 // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid
1039 if (!vdp->m_videoSurfaces.IsValid(surf))
1041 CLog::Log(LOGWARNING, "CVDPAU::FFDrawSlice - ignoring invalid buffer");
1045 uint32_t max_refs = 0;
1046 if(s->codec_id == AV_CODEC_ID_H264)
1047 max_refs = vdp->m_hwContext.info.h264.num_ref_frames;
1049 if(vdp->m_vdpauConfig.vdpDecoder == VDP_INVALID_HANDLE
1050 || vdp->m_vdpauConfigured == false
1051 || vdp->m_vdpauConfig.maxReferences < max_refs)
1053 if(!vdp->ConfigVDPAU(s, max_refs))
1057 uint64_t startTime = CurrentHostCounter();
1058 uint16_t decoded, processed, rend;
1059 vdp->m_bufferStats.Get(decoded, processed, rend);
1060 vdp_st = vdp->m_vdpauConfig.context->GetProcs().vdp_decoder_render(vdp->m_vdpauConfig.vdpDecoder,
1062 (VdpPictureInfo const *)&(vdp->m_hwContext.info),
1063 vdp->m_hwContext.bitstream_buffers_used,
1064 vdp->m_hwContext.bitstream_buffers);
1065 vdp->CheckStatus(vdp_st, __LINE__);
1066 uint64_t diff = CurrentHostCounter() - startTime;
1067 if (diff*1000/CurrentHostFrequency() > 30)
1068 CLog::Log(LOGDEBUG, "CVDPAU::DrawSlice - VdpDecoderRender long decoding: %d ms, dec: %d, proc: %d, rend: %d", (int)((diff*1000)/CurrentHostFrequency()), decoded, processed, rend);
1072 int CDecoder::Decode(AVCodecContext *avctx, AVFrame *pFrame)
1074 int result = Check(avctx);
1078 CSingleLock lock(m_DecoderSection);
1080 if (!m_vdpauConfigured)
1084 { // we have a new frame from decoder
1086 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)pFrame->data[3];
1087 // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid
1088 if (!m_videoSurfaces.IsValid(surf))
1090 CLog::Log(LOGWARNING, "CVDPAU::Decode - ignoring invalid buffer");
1093 m_videoSurfaces.MarkRender(surf);
1095 // send frame to output for processing
1096 CVdpauDecodedPicture pic;
1097 memset(&pic.DVDPic, 0, sizeof(pic.DVDPic));
1098 ((CDVDVideoCodecFFmpeg*)avctx->opaque)->GetPictureCommon(&pic.DVDPic);
1099 pic.videoSurface = surf;
1100 pic.DVDPic.color_matrix = avctx->colorspace;
1101 m_bufferStats.IncDecoded();
1102 m_vdpauOutput.m_dataPort.SendOutMessage(COutputDataProtocol::NEWFRAME, &pic, sizeof(pic));
1105 // m_codecControl = pic.DVDPic.iFlags & (DVP_FLAG_DRAIN | DVP_FLAG_NO_POSTPROC);
1109 uint16_t decoded, processed, render;
1111 while (m_vdpauOutput.m_controlPort.ReceiveInMessage(&msg))
1113 if (msg->signal == COutputControlProtocol::ERROR)
1115 m_DisplayState = VDPAU_ERROR;
1121 m_bufferStats.Get(decoded, processed, render);
1123 uint64_t startTime = CurrentHostCounter();
1126 // first fill the buffers to keep vdpau busy
1127 // mixer will run with decoded >= 2. output is limited by number of output surfaces
1128 // In case mixer is bypassed we limit by looking at processed
1129 if (decoded < 3 && processed < 3)
1131 retval |= VC_BUFFER;
1133 else if (m_vdpauOutput.m_dataPort.ReceiveInMessage(&msg))
1135 if (msg->signal == COutputDataProtocol::PICTURE)
1137 if (m_presentPicture)
1139 m_presentPicture->ReturnUnused();
1140 m_presentPicture = 0;
1143 m_presentPicture = *(CVdpauRenderPicture**)msg->data;
1144 m_presentPicture->vdpau = this;
1145 m_bufferStats.DecRender();
1146 m_bufferStats.Get(decoded, processed, render);
1147 retval |= VC_PICTURE;
1153 else if (m_vdpauOutput.m_controlPort.ReceiveInMessage(&msg))
1155 if (msg->signal == COutputControlProtocol::STATS)
1157 m_bufferStats.Get(decoded, processed, render);
1161 m_DisplayState = VDPAU_ERROR;
1167 if (decoded < 3 && processed < 3)
1169 retval |= VC_BUFFER;
1172 if (!retval && !m_inMsgEvent.WaitMSec(2000))
1175 uint64_t diff = CurrentHostCounter() - startTime;
1176 if (retval & VC_PICTURE)
1178 m_bufferStats.SetParams(diff, m_codecControl);
1180 if (diff*1000/CurrentHostFrequency() > 50)
1181 CLog::Log(LOGDEBUG,"CVDPAU::Decode long wait: %d", (int)((diff*1000)/CurrentHostFrequency()));
1185 CLog::Log(LOGERROR, "VDPAU::%s - timed out waiting for output message", __FUNCTION__);
1186 m_DisplayState = VDPAU_ERROR;
1193 bool CDecoder::GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture)
1195 CSingleLock lock(m_DecoderSection);
1197 if (m_DisplayState != VDPAU_OPEN)
1200 *picture = m_presentPicture->DVDPic;
1201 picture->vdpau = m_presentPicture;
1206 void CDecoder::Reset()
1208 CSingleLock lock(m_DecoderSection);
1210 if (!m_vdpauConfigured)
1214 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::FLUSH,
1218 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
1222 CLog::Log(LOGERROR, "VDPAU::%s - flush returned error", __FUNCTION__);
1223 m_DisplayState = VDPAU_ERROR;
1226 m_bufferStats.Reset();
1230 CLog::Log(LOGERROR, "VDPAU::%s - flush timed out", __FUNCTION__);
1231 m_DisplayState = VDPAU_ERROR;
1235 bool CDecoder::CanSkipDeint()
1237 return m_bufferStats.CanSkipDeint();
1240 void CDecoder::ReturnRenderPicture(CVdpauRenderPicture *renderPic)
1242 m_vdpauOutput.m_dataPort.SendOutMessage(COutputDataProtocol::RETURNPIC, &renderPic, sizeof(renderPic));
1245 bool CDecoder::CheckStatus(VdpStatus vdp_st, int line)
1247 if (vdp_st != VDP_STATUS_OK)
1249 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);
1251 if(m_DisplayState == VDPAU_OPEN)
1253 if (vdp_st == VDP_STATUS_DISPLAY_PREEMPTED)
1255 m_DisplayEvent.Reset();
1256 m_DisplayState = VDPAU_LOST;
1259 m_DisplayState = VDPAU_ERROR;
1267 //-----------------------------------------------------------------------------
1269 //-----------------------------------------------------------------------------
1271 CVdpauRenderPicture* CVdpauRenderPicture::Acquire()
1273 CSingleLock lock(renderPicSection);
1282 long CVdpauRenderPicture::Release()
1284 CSingleLock lock(renderPicSection);
1291 vdpau->ReturnRenderPicture(this);
1292 vdpau->ReleasePicReference();
1297 void CVdpauRenderPicture::ReturnUnused()
1299 { CSingleLock lock(renderPicSection);
1304 vdpau->ReturnRenderPicture(this);
1307 void CVdpauRenderPicture::Sync()
1310 CSingleLock lock(renderPicSection);
1315 glDeleteSync(fence);
1318 fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
1323 //-----------------------------------------------------------------------------
1325 //-----------------------------------------------------------------------------
1326 CMixer::CMixer(CEvent *inMsgEvent) :
1327 CThread("Vdpau Mixer"),
1328 m_controlPort("ControlPort", inMsgEvent, &m_outMsgEvent),
1329 m_dataPort("DataPort", inMsgEvent, &m_outMsgEvent)
1331 m_inMsgEvent = inMsgEvent;
1339 void CMixer::Start()
1344 void CMixer::Dispose()
1347 m_outMsgEvent.Set();
1350 m_controlPort.Purge();
1354 bool CMixer::IsActive()
1359 void CMixer::OnStartup()
1361 CLog::Log(LOGNOTICE, "CMixer::OnStartup: Output Thread created");
1364 void CMixer::OnExit()
1366 CLog::Log(LOGNOTICE, "CMixer::OnExit: Output Thread terminated");
1373 M_TOP_UNCONFIGURED, // 2
1374 M_TOP_CONFIGURED, // 3
1375 M_TOP_CONFIGURED_WAIT1, // 4
1376 M_TOP_CONFIGURED_STEP1, // 5
1377 M_TOP_CONFIGURED_WAIT2, // 6
1378 M_TOP_CONFIGURED_STEP2, // 7
1381 int MIXER_parentStates[] = {
1384 0, //TOP_UNCONFIGURED
1386 3, //TOP_CONFIGURED_WAIT1
1387 3, //TOP_CONFIGURED_STEP1
1388 3, //TOP_CONFIGURED_WAIT2
1389 3, //TOP_CONFIGURED_STEP2
1392 void CMixer::StateMachine(int signal, Protocol *port, Message *msg)
1394 for (int state = m_state; ; state = MIXER_parentStates[state])
1399 if (port == &m_controlPort)
1403 case CMixerControlProtocol::FLUSH:
1405 msg->Reply(CMixerControlProtocol::ACC);
1412 std::string portName = port == NULL ? "timer" : port->portName;
1413 CLog::Log(LOGWARNING, "CMixer::%s - signal: %d form port: %s not handled for state: %d", __FUNCTION__, signal, portName.c_str(), m_state);
1417 case M_TOP_ERROR: // TOP
1420 case M_TOP_UNCONFIGURED:
1421 if (port == &m_controlPort)
1425 case CMixerControlProtocol::INIT:
1427 data = (CVdpauConfig*)msg->data;
1435 m_state = M_TOP_CONFIGURED_WAIT1;
1436 msg->Reply(CMixerControlProtocol::ACC);
1440 msg->Reply(CMixerControlProtocol::ERROR);
1449 case M_TOP_CONFIGURED:
1450 if (port == &m_dataPort)
1454 case CMixerDataProtocol::FRAME:
1455 CVdpauDecodedPicture *frame;
1456 frame = (CVdpauDecodedPicture*)msg->data;
1459 m_decodedPics.push(*frame);
1463 case CMixerDataProtocol::BUFFER:
1464 VdpOutputSurface *surf;
1465 surf = (VdpOutputSurface*)msg->data;
1468 m_outputSurfaces.push(*surf);
1478 case M_TOP_CONFIGURED_WAIT1:
1479 if (port == NULL) // timeout
1483 case CMixerControlProtocol::TIMEOUT:
1484 if (!m_decodedPics.empty() && !m_outputSurfaces.empty())
1486 m_state = M_TOP_CONFIGURED_STEP1;
1487 m_bStateMachineSelfTrigger = true;
1500 case M_TOP_CONFIGURED_STEP1:
1501 if (port == NULL) // timeout
1505 case CMixerControlProtocol::TIMEOUT:
1506 m_mixerInput.push_front(m_decodedPics.front());
1507 m_decodedPics.pop();
1508 if (m_mixerInput.size() < 2)
1510 m_state = M_TOP_CONFIGURED_WAIT1;
1518 m_state = M_TOP_CONFIGURED_WAIT1;
1519 m_extTimeout = 1000;
1522 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
1523 m_outputSurfaces.pop();
1524 m_config.stats->IncProcessed();
1525 m_config.stats->DecDecoded();
1526 m_dataPort.SendInMessage(CMixerDataProtocol::PICTURE,&m_processPicture,sizeof(m_processPicture));
1527 if (m_mixersteps > 1)
1529 m_state = M_TOP_CONFIGURED_WAIT2;
1535 m_state = M_TOP_CONFIGURED_WAIT1;
1545 case M_TOP_CONFIGURED_WAIT2:
1546 if (port == NULL) // timeout
1550 case CMixerControlProtocol::TIMEOUT:
1551 if (!m_outputSurfaces.empty())
1553 m_state = M_TOP_CONFIGURED_STEP2;
1554 m_bStateMachineSelfTrigger = true;
1567 case M_TOP_CONFIGURED_STEP2:
1568 if (port == NULL) // timeout
1572 case CMixerControlProtocol::TIMEOUT:
1573 m_processPicture.outputSurface = m_outputSurfaces.front();
1578 m_state = M_TOP_CONFIGURED_WAIT1;
1579 m_extTimeout = 1000;
1582 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
1583 m_outputSurfaces.pop();
1584 m_config.stats->IncProcessed();
1585 m_dataPort.SendInMessage(CMixerDataProtocol::PICTURE,&m_processPicture,sizeof(m_processPicture));
1587 m_state = M_TOP_CONFIGURED_WAIT1;
1596 default: // we are in no state, should not happen
1597 CLog::Log(LOGERROR, "CMixer::%s - no valid state: %d", __FUNCTION__, m_state);
1603 void CMixer::Process()
1605 Message *msg = NULL;
1606 Protocol *port = NULL;
1609 m_state = M_TOP_UNCONFIGURED;
1610 m_extTimeout = 1000;
1611 m_bStateMachineSelfTrigger = false;
1617 if (m_bStateMachineSelfTrigger)
1619 m_bStateMachineSelfTrigger = false;
1620 // self trigger state machine
1621 StateMachine(msg->signal, port, msg);
1622 if (!m_bStateMachineSelfTrigger)
1629 // check control port
1630 else if (m_controlPort.ReceiveOutMessage(&msg))
1633 port = &m_controlPort;
1636 else if (m_dataPort.ReceiveOutMessage(&msg))
1644 StateMachine(msg->signal, port, msg);
1645 if (!m_bStateMachineSelfTrigger)
1654 else if (m_outMsgEvent.WaitMSec(m_extTimeout))
1661 msg = m_controlPort.GetMessage();
1662 msg->signal = CMixerControlProtocol::TIMEOUT;
1664 // signal timeout to state machine
1665 StateMachine(msg->signal, port, msg);
1666 if (!m_bStateMachineSelfTrigger)
1676 void CMixer::CreateVdpauMixer()
1678 CLog::Log(LOGNOTICE, " (VDPAU) Creating the video mixer");
1680 InitCSCMatrix(m_config.vidWidth);
1682 VdpVideoMixerParameter parameters[] = {
1683 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
1684 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
1685 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE};
1687 void const * parameter_values[] = {
1688 &m_config.surfaceWidth,
1689 &m_config.surfaceHeight,
1690 &m_config.vdpChromaType};
1692 VdpStatus vdp_st = VDP_STATUS_ERROR;
1693 vdp_st = m_config.context->GetProcs().vdp_video_mixer_create(m_config.context->GetDevice(),
1694 m_config.context->GetFeatureCount(),
1695 m_config.context->GetFeatures(),
1700 CheckStatus(vdp_st, __LINE__);
1704 void CMixer::InitCSCMatrix(int Width)
1706 m_Procamp.struct_version = VDP_PROCAMP_VERSION;
1707 m_Procamp.brightness = 0.0;
1708 m_Procamp.contrast = 1.0;
1709 m_Procamp.saturation = 1.0;
1713 void CMixer::CheckFeatures()
1715 if (m_Upscale != m_config.upscale)
1718 m_Upscale = m_config.upscale;
1720 if (m_Brightness != CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness ||
1721 m_Contrast != CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast ||
1722 m_ColorMatrix != m_mixerInput[1].DVDPic.color_matrix)
1725 m_Brightness = CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness;
1726 m_Contrast = CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast;
1727 m_ColorMatrix = m_mixerInput[1].DVDPic.color_matrix;
1729 if (m_NoiseReduction != CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction)
1731 m_NoiseReduction = CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction;
1732 SetNoiseReduction();
1734 if (m_Sharpness != CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness)
1736 m_Sharpness = CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness;
1739 if (m_DeintMode != CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode ||
1740 m_Deint != CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod)
1742 m_DeintMode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1743 m_Deint = CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod;
1748 void CMixer::SetPostProcFeatures(bool postProcEnabled)
1750 if (m_PostProc != postProcEnabled)
1752 if (postProcEnabled)
1754 SetNoiseReduction();
1761 m_PostProc = postProcEnabled;
1765 void CMixer::PostProcOff()
1769 if (m_videoMixer == VDP_INVALID_HANDLE)
1772 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL,
1773 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL,
1774 VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE};
1776 VdpBool enabled[]={0,0,0};
1777 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1778 CheckStatus(vdp_st, __LINE__);
1780 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION))
1782 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION};
1784 VdpBool enabled[]={0};
1785 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1786 CheckStatus(vdp_st, __LINE__);
1789 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_SHARPNESS))
1791 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_SHARPNESS};
1793 VdpBool enabled[]={0};
1794 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1795 CheckStatus(vdp_st, __LINE__);
1801 bool CMixer::GenerateStudioCSCMatrix(VdpColorStandard colorStandard, VdpCSCMatrix &studioCSCMatrix)
1803 // instead use studioCSCKCoeffs601[3], studioCSCKCoeffs709[3] to generate float[3][4] matrix (float studioCSC[3][4])
1804 // m00 = mRY = red: luma factor (contrast factor) (1.0)
1805 // m10 = mGY = green: luma factor (contrast factor) (1.0)
1806 // m20 = mBY = blue: luma factor (contrast factor) (1.0)
1808 // m01 = mRB = red: blue color diff coeff (0.0)
1809 // m11 = mGB = green: blue color diff coeff (-2Kb(1-Kb)/(Kg))
1810 // m21 = mBB = blue: blue color diff coeff ((1-Kb)/0.5)
1812 // m02 = mRR = red: red color diff coeff ((1-Kr)/0.5)
1813 // m12 = mGR = green: red color diff coeff (-2Kr(1-Kr)/(Kg))
1814 // m22 = mBR = blue: red color diff coeff (0.0)
1816 // m03 = mRC = red: colour zero offset (brightness factor) (-(1-Kr)/0.5 * (128/255))
1817 // m13 = mGC = green: colour zero offset (brightness factor) ((256/255) * (Kb(1-Kb) + Kr(1-Kr)) / Kg)
1818 // m23 = mBC = blue: colour zero offset (brightness factor) (-(1-Kb)/0.5 * (128/255))
1829 // colour standard coefficients for red, geen, blue
1831 // colour diff zero position (use standard 8-bit coding precision)
1832 double CDZ = 128; //256*0.5
1833 // range excursion (use standard 8-bit coding precision)
1834 double EXC = 255; //256-1
1836 if (colorStandard == VDP_COLOR_STANDARD_ITUR_BT_601)
1838 Kr = studioCSCKCoeffs601[0];
1839 Kg = studioCSCKCoeffs601[1];
1840 Kb = studioCSCKCoeffs601[2];
1842 else // assume VDP_COLOR_STANDARD_ITUR_BT_709
1844 Kr = studioCSCKCoeffs709[0];
1845 Kg = studioCSCKCoeffs709[1];
1846 Kb = studioCSCKCoeffs709[2];
1848 // we keep luma unscaled to retain the levels present in source so that 16-235 luma is converted to RGB 16-235
1849 studioCSCMatrix[R][Y] = 1.0;
1850 studioCSCMatrix[G][Y] = 1.0;
1851 studioCSCMatrix[B][Y] = 1.0;
1853 studioCSCMatrix[R][Cb] = 0.0;
1854 studioCSCMatrix[G][Cb] = (double)-2 * Kb * (1 - Kb) / Kg;
1855 studioCSCMatrix[B][Cb] = (double)(1 - Kb) / 0.5;
1857 studioCSCMatrix[R][Cr] = (double)(1 - Kr) / 0.5;
1858 studioCSCMatrix[G][Cr] = (double)-2 * Kr * (1 - Kr) / Kg;
1859 studioCSCMatrix[B][Cr] = 0.0;
1861 studioCSCMatrix[R][C] = (double)-1 * studioCSCMatrix[R][Cr] * CDZ/EXC;
1862 studioCSCMatrix[G][C] = (double)-1 * (studioCSCMatrix[G][Cb] + studioCSCMatrix[G][Cr]) * CDZ/EXC;
1863 studioCSCMatrix[B][C] = (double)-1 * studioCSCMatrix[B][Cb] * CDZ/EXC;
1868 void CMixer::SetColor()
1872 if (m_Brightness != CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness)
1873 m_Procamp.brightness = (float)((CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness)-50) / 100;
1874 if (m_Contrast != CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast)
1875 m_Procamp.contrast = (float)((CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast)+50) / 100;
1877 VdpColorStandard colorStandard;
1878 switch(m_mixerInput[1].DVDPic.color_matrix)
1880 case AVCOL_SPC_BT709:
1881 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_709;
1883 case AVCOL_SPC_BT470BG:
1884 case AVCOL_SPC_SMPTE170M:
1885 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_601;
1887 case AVCOL_SPC_SMPTE240M:
1888 colorStandard = VDP_COLOR_STANDARD_SMPTE_240M;
1891 case AVCOL_SPC_UNSPECIFIED:
1894 if(m_config.surfaceWidth > 1000)
1895 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_709;
1897 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_601;
1900 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX };
1901 if (CSettings::Get().GetBool("videoscreen.limitedrange"))
1903 float studioCSC[3][4];
1904 GenerateStudioCSCMatrix(colorStandard, studioCSC);
1905 void const * pm_CSCMatix[] = { &studioCSC };
1906 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
1910 vdp_st = m_config.context->GetProcs().vdp_generate_csc_matrix(&m_Procamp, colorStandard, &m_CSCMatrix);
1911 void const * pm_CSCMatix[] = { &m_CSCMatrix };
1912 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
1915 CheckStatus(vdp_st, __LINE__);
1918 void CMixer::SetNoiseReduction()
1920 if(!m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION))
1923 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION };
1924 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL };
1927 if (!CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction)
1929 VdpBool enabled[]= {0};
1930 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1931 CheckStatus(vdp_st, __LINE__);
1934 VdpBool enabled[]={1};
1935 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1936 CheckStatus(vdp_st, __LINE__);
1937 void* nr[] = { &CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction };
1938 CLog::Log(LOGNOTICE,"Setting Noise Reduction to %f",CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction);
1939 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, nr);
1940 CheckStatus(vdp_st, __LINE__);
1943 void CMixer::SetSharpness()
1945 if(!m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_SHARPNESS))
1948 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_SHARPNESS };
1949 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL };
1952 if (!CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness)
1954 VdpBool enabled[]={0};
1955 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1956 CheckStatus(vdp_st, __LINE__);
1959 VdpBool enabled[]={1};
1960 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1961 CheckStatus(vdp_st, __LINE__);
1962 void* sh[] = { &CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness };
1963 CLog::Log(LOGNOTICE,"Setting Sharpness to %f",CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness);
1964 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, sh);
1965 CheckStatus(vdp_st, __LINE__);
1968 EINTERLACEMETHOD CMixer::GetDeinterlacingMethod(bool log /* = false */)
1970 EINTERLACEMETHOD method = CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod;
1971 if (method == VS_INTERLACEMETHOD_AUTO)
1974 // if (m_config.outHeight >= 720)
1975 // deint = g_advancedSettings.m_videoVDPAUdeintHD;
1977 // deint = g_advancedSettings.m_videoVDPAUdeintSD;
1981 if (m_config.vdpau->Supports(EINTERLACEMETHOD(deint)))
1983 method = EINTERLACEMETHOD(deint);
1985 CLog::Log(LOGNOTICE, "CVDPAU::GetDeinterlacingMethod: set de-interlacing to %d", deint);
1990 CLog::Log(LOGWARNING, "CVDPAU::GetDeinterlacingMethod: method for de-interlacing (advanced settings) not supported");
1997 void CMixer::SetDeinterlacing()
2001 if (m_videoMixer == VDP_INVALID_HANDLE)
2004 EDEINTERLACEMODE mode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
2005 EINTERLACEMETHOD method = GetDeinterlacingMethod(true);
2007 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL,
2008 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL,
2009 VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE };
2011 if (mode == VS_DEINTERLACEMODE_OFF)
2013 VdpBool enabled[] = {0,0,0};
2014 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2018 if (method == VS_INTERLACEMETHOD_AUTO)
2020 VdpBool enabled[] = {1,0,0};
2021 if (g_advancedSettings.m_videoVDPAUtelecine)
2023 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2025 else if (method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL
2026 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF)
2028 VdpBool enabled[] = {1,0,0};
2029 if (g_advancedSettings.m_videoVDPAUtelecine)
2031 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2033 else if (method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL
2034 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF)
2036 VdpBool enabled[] = {1,1,0};
2037 if (g_advancedSettings.m_videoVDPAUtelecine)
2039 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2043 VdpBool enabled[]={0,0,0};
2044 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2047 CheckStatus(vdp_st, __LINE__);
2049 SetDeintSkipChroma();
2051 m_config.useInteropYuv = !CSettings::Get().GetBool("videoplayer.usevdpaumixer");
2054 void CMixer::SetDeintSkipChroma()
2056 VdpVideoMixerAttribute attribute[] = { VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE};
2060 if (g_advancedSettings.m_videoVDPAUdeintSkipChromaHD && m_config.outHeight >= 720)
2065 void const *values[]={&val};
2066 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attribute), attribute, values);
2068 CheckStatus(vdp_st, __LINE__);
2071 void CMixer::SetHWUpscaling()
2073 #ifdef VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
2076 VdpBool enabled[]={1};
2077 switch (m_config.upscale)
2080 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9))
2082 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9 };
2083 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2087 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8))
2089 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8 };
2090 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2094 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7))
2096 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7 };
2097 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2101 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6))
2103 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6 };
2104 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2108 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5))
2110 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5 };
2111 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2115 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4))
2117 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4 };
2118 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2122 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3))
2124 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3 };
2125 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2129 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2))
2131 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2 };
2132 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2136 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1))
2138 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 };
2139 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2146 CheckStatus(vdp_st, __LINE__);
2150 void CMixer::DisableHQScaling()
2154 if (m_videoMixer == VDP_INVALID_HANDLE)
2157 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1))
2159 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 };
2160 VdpBool enabled[]={0};
2161 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2162 CheckStatus(vdp_st, __LINE__);
2165 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2))
2167 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2 };
2168 VdpBool enabled[]={0};
2169 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2170 CheckStatus(vdp_st, __LINE__);
2173 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3))
2175 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3 };
2176 VdpBool enabled[]={0};
2177 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2178 CheckStatus(vdp_st, __LINE__);
2181 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4))
2183 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4 };
2184 VdpBool enabled[]={0};
2185 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2186 CheckStatus(vdp_st, __LINE__);
2189 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5))
2191 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5 };
2192 VdpBool enabled[]={0};
2193 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2194 CheckStatus(vdp_st, __LINE__);
2197 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6))
2199 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6 };
2200 VdpBool enabled[]={0};
2201 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2202 CheckStatus(vdp_st, __LINE__);
2205 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7))
2207 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7 };
2208 VdpBool enabled[]={0};
2209 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2210 CheckStatus(vdp_st, __LINE__);
2213 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8))
2215 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8 };
2216 VdpBool enabled[]={0};
2217 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2218 CheckStatus(vdp_st, __LINE__);
2221 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9))
2223 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9 };
2224 VdpBool enabled[]={0};
2225 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2226 CheckStatus(vdp_st, __LINE__);
2234 m_NoiseReduction = 0.0;
2239 m_SeenInterlaceFlag = false;
2244 m_config.upscale = g_advancedSettings.m_videoVDPAUScaling;
2245 m_config.useInteropYuv = !CSettings::Get().GetBool("videoplayer.usevdpaumixer");
2250 void CMixer::Uninit()
2253 while (!m_outputSurfaces.empty())
2255 m_outputSurfaces.pop();
2257 m_config.context->GetProcs().vdp_video_mixer_destroy(m_videoMixer);
2260 void CMixer::Flush()
2262 while (!m_mixerInput.empty())
2264 CVdpauDecodedPicture pic = m_mixerInput.back();
2265 m_mixerInput.pop_back();
2266 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2268 while (!m_decodedPics.empty())
2270 CVdpauDecodedPicture pic = m_decodedPics.front();
2271 m_decodedPics.pop();
2272 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2275 while (m_dataPort.ReceiveOutMessage(&msg))
2277 if (msg->signal == CMixerDataProtocol::FRAME)
2279 CVdpauDecodedPicture pic = *(CVdpauDecodedPicture*)msg->data;
2280 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2282 else if (msg->signal == CMixerDataProtocol::BUFFER)
2284 VdpOutputSurface *surf;
2285 surf = (VdpOutputSurface*)msg->data;
2286 m_outputSurfaces.push(*surf);
2292 void CMixer::InitCycle()
2297 m_config.stats->GetParams(latency, flags);
2299 if (0) //flags & DVP_FLAG_NO_POSTPROC)
2300 SetPostProcFeatures(false);
2302 SetPostProcFeatures(true);
2304 m_config.stats->SetCanSkipDeint(false);
2306 EDEINTERLACEMODE mode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
2307 EINTERLACEMETHOD method = GetDeinterlacingMethod();
2308 bool interlaced = m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_INTERLACED;
2309 m_SeenInterlaceFlag |= interlaced;
2312 if (//!(flags & DVP_FLAG_NO_POSTPROC) &&
2313 (mode == VS_DEINTERLACEMODE_FORCE ||
2314 (mode == VS_DEINTERLACEMODE_AUTO && interlaced)))
2316 if((method == VS_INTERLACEMETHOD_AUTO && interlaced)
2317 || method == VS_INTERLACEMETHOD_VDPAU_BOB
2318 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL
2319 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF
2320 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL
2321 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF
2322 || method == VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE )
2324 if(method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF
2325 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF
2326 || !g_graphicsContext.IsFullScreenVideo())
2331 m_config.stats->SetCanSkipDeint(true);
2335 if (0) //m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_DROPDEINT)
2340 if(m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_TOP_FIELD_FIRST)
2341 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
2343 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
2345 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2346 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2347 DVP_FLAG_REPEAT_TOP_FIELD |
2348 DVP_FLAG_INTERLACED);
2349 m_config.useInteropYuv = false;
2351 else if (method == VS_INTERLACEMETHOD_RENDER_BOB)
2354 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2355 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU_420;
2356 m_config.useInteropYuv = true;
2360 CLog::Log(LOGERROR, "CMixer::%s - interlace method: %d not supported, setting to AUTO", __FUNCTION__, method);
2362 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2363 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2364 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2365 DVP_FLAG_REPEAT_TOP_FIELD |
2366 DVP_FLAG_INTERLACED);
2368 CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod = VS_INTERLACEMETHOD_AUTO;
2374 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2376 if (m_config.useInteropYuv)
2377 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU_420;
2380 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2381 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2382 DVP_FLAG_REPEAT_TOP_FIELD |
2383 DVP_FLAG_INTERLACED);
2388 if (m_mixerInput[1].DVDPic.format == RENDER_FMT_VDPAU)
2390 m_processPicture.outputSurface = m_outputSurfaces.front();
2391 m_mixerInput[1].DVDPic.iWidth = m_config.outWidth;
2392 m_mixerInput[1].DVDPic.iHeight = m_config.outHeight;
2393 if (m_SeenInterlaceFlag)
2395 double ratio = (double)m_mixerInput[1].DVDPic.iDisplayHeight / m_mixerInput[1].DVDPic.iHeight;
2396 m_mixerInput[1].DVDPic.iHeight -= 6;
2397 m_mixerInput[1].DVDPic.iDisplayHeight = lrint(ratio*m_mixerInput[1].DVDPic.iHeight);
2402 m_mixerInput[1].DVDPic.iWidth = m_config.vidWidth;
2403 m_mixerInput[1].DVDPic.iHeight = m_config.vidHeight;
2406 m_processPicture.DVDPic = m_mixerInput[1].DVDPic;
2407 m_processPicture.videoSurface = m_mixerInput[1].videoSurface;
2410 void CMixer::FiniCycle()
2412 // Keep video surfaces for one 2 cycles longer than used
2413 // by mixer. This avoids blocking in decoder.
2414 // NVidia recommends num_ref + 5
2415 while (m_mixerInput.size() > 5)
2417 CVdpauDecodedPicture &tmp = m_mixerInput.back();
2418 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
2420 m_config.videoSurfaces->ClearRender(tmp.videoSurface);
2422 m_mixerInput.pop_back();
2426 void CMixer::ProcessPicture()
2428 if (m_processPicture.DVDPic.format == RENDER_FMT_VDPAU_420)
2433 if (m_mixerstep == 1)
2435 if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD)
2436 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
2438 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
2441 VdpVideoSurface past_surfaces[4] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
2442 VdpVideoSurface futu_surfaces[2] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
2443 uint32_t pastCount = 4;
2444 uint32_t futuCount = 2;
2446 if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME)
2448 // use only 2 past 1 future for progressive/weave
2449 // (only used for postproc anyway eg noise reduction)
2450 if (m_mixerInput.size() > 3)
2451 past_surfaces[1] = m_mixerInput[3].videoSurface;
2452 if (m_mixerInput.size() > 2)
2453 past_surfaces[0] = m_mixerInput[2].videoSurface;
2454 futu_surfaces[0] = m_mixerInput[0].videoSurface;
2460 if(m_mixerstep == 0)
2462 if (m_mixerInput.size() > 3)
2464 past_surfaces[3] = m_mixerInput[3].videoSurface;
2465 past_surfaces[2] = m_mixerInput[3].videoSurface;
2467 if (m_mixerInput.size() > 2)
2469 past_surfaces[1] = m_mixerInput[2].videoSurface;
2470 past_surfaces[0] = m_mixerInput[2].videoSurface;
2472 futu_surfaces[0] = m_mixerInput[1].videoSurface;
2473 futu_surfaces[1] = m_mixerInput[0].videoSurface;
2477 if (m_mixerInput.size() > 3)
2479 past_surfaces[3] = m_mixerInput[3].videoSurface;
2481 if (m_mixerInput.size() > 2)
2483 past_surfaces[2] = m_mixerInput[2].videoSurface;
2484 past_surfaces[1] = m_mixerInput[2].videoSurface;
2486 past_surfaces[0] = m_mixerInput[1].videoSurface;
2487 futu_surfaces[0] = m_mixerInput[0].videoSurface;
2488 futu_surfaces[1] = m_mixerInput[0].videoSurface;
2490 if (m_mixerInput[0].DVDPic.pts != DVD_NOPTS_VALUE &&
2491 m_mixerInput[1].DVDPic.pts != DVD_NOPTS_VALUE)
2493 m_processPicture.DVDPic.pts = m_mixerInput[1].DVDPic.pts +
2494 (m_mixerInput[0].DVDPic.pts -
2495 m_mixerInput[1].DVDPic.pts) / 2;
2498 m_processPicture.DVDPic.pts = DVD_NOPTS_VALUE;
2499 m_processPicture.DVDPic.dts = DVD_NOPTS_VALUE;
2501 m_processPicture.DVDPic.iRepeatPicture = 0.0;
2507 sourceRect.x1 = m_config.vidWidth;
2508 sourceRect.y1 = m_config.vidHeight;
2513 destRect.x1 = m_config.outWidth;
2514 destRect.y1 = m_config.outHeight;
2516 // start vdpau video mixer
2517 vdp_st = m_config.context->GetProcs().vdp_video_mixer_render(m_videoMixer,
2523 m_mixerInput[1].videoSurface,
2527 m_processPicture.outputSurface,
2532 CheckStatus(vdp_st, __LINE__);
2536 bool CMixer::CheckStatus(VdpStatus vdp_st, int line)
2538 if (vdp_st != VDP_STATUS_OK)
2540 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);
2547 //-----------------------------------------------------------------------------
2549 //-----------------------------------------------------------------------------
2551 VdpauBufferPool::VdpauBufferPool()
2553 CVdpauRenderPicture *pic;
2554 for (unsigned int i = 0; i < NUM_RENDER_PICS; i++)
2556 pic = new CVdpauRenderPicture(renderPicSec);
2557 allRenderPics.push_back(pic);
2561 VdpauBufferPool::~VdpauBufferPool()
2563 CVdpauRenderPicture *pic;
2564 for (unsigned int i = 0; i < NUM_RENDER_PICS; i++)
2566 pic = allRenderPics[i];
2569 allRenderPics.clear();
2572 //-----------------------------------------------------------------------------
2574 //-----------------------------------------------------------------------------
2575 COutput::COutput(CEvent *inMsgEvent) :
2576 CThread("Vdpau Output"),
2577 m_controlPort("OutputControlPort", inMsgEvent, &m_outMsgEvent),
2578 m_dataPort("OutputDataPort", inMsgEvent, &m_outMsgEvent),
2579 m_mixer(&m_outMsgEvent)
2581 m_inMsgEvent = inMsgEvent;
2583 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); ++i)
2585 m_bufferPool.freeRenderPics.push_back(i);
2589 void COutput::Start()
2598 m_bufferPool.freeRenderPics.clear();
2599 m_bufferPool.usedRenderPics.clear();
2602 void COutput::Dispose()
2604 CSingleLock lock(g_graphicsContext);
2606 m_outMsgEvent.Set();
2608 m_controlPort.Purge();
2612 void COutput::OnStartup()
2614 CLog::Log(LOGNOTICE, "COutput::OnStartup: Output Thread created");
2617 void COutput::OnExit()
2619 CLog::Log(LOGNOTICE, "COutput::OnExit: Output Thread terminated");
2626 O_TOP_UNCONFIGURED, // 2
2627 O_TOP_CONFIGURED, // 3
2628 O_TOP_CONFIGURED_IDLE, // 4
2629 O_TOP_CONFIGURED_WORK, // 5
2632 int VDPAU_OUTPUT_parentStates[] = {
2635 0, //TOP_UNCONFIGURED
2637 3, //TOP_CONFIGURED_IDLE
2638 3, //TOP_CONFIGURED_WORK
2641 void COutput::StateMachine(int signal, Protocol *port, Message *msg)
2643 for (int state = m_state; ; state = VDPAU_OUTPUT_parentStates[state])
2648 if (port == &m_controlPort)
2652 case COutputControlProtocol::FLUSH:
2653 msg->Reply(COutputControlProtocol::ACC);
2655 case COutputControlProtocol::PRECLEANUP:
2656 msg->Reply(COutputControlProtocol::ACC);
2662 else if (port == &m_dataPort)
2666 case COutputDataProtocol::RETURNPIC:
2667 CVdpauRenderPicture *pic;
2668 pic = *((CVdpauRenderPicture**)msg->data);
2669 QueueReturnPicture(pic);
2676 std::string portName = port == NULL ? "timer" : port->portName;
2677 CLog::Log(LOGWARNING, "COutput::%s - signal: %d form port: %s not handled for state: %d", __FUNCTION__, signal, portName.c_str(), m_state);
2684 case O_TOP_UNCONFIGURED:
2685 if (port == &m_controlPort)
2689 case COutputControlProtocol::INIT:
2691 data = (CVdpauConfig*)msg->data;
2698 if (m_mixer.m_controlPort.SendOutMessageSync(CMixerControlProtocol::INIT,
2699 &reply, 1000, &m_config, sizeof(m_config)))
2701 if (reply->signal != CMixerControlProtocol::ACC)
2706 // set initial number of
2707 m_bufferPool.numOutputSurfaces = 4;
2711 m_state = O_TOP_CONFIGURED_IDLE;
2712 msg->Reply(COutputControlProtocol::ACC, &m_config, sizeof(m_config));
2716 m_state = O_TOP_ERROR;
2717 msg->Reply(COutputControlProtocol::ERROR);
2726 case O_TOP_CONFIGURED:
2727 if (port == &m_controlPort)
2731 case COutputControlProtocol::FLUSH:
2733 msg->Reply(COutputControlProtocol::ACC);
2735 case COutputControlProtocol::PRECLEANUP:
2738 msg->Reply(COutputControlProtocol::ACC);
2744 else if (port == &m_dataPort)
2748 case COutputDataProtocol::NEWFRAME:
2749 CVdpauDecodedPicture *frame;
2750 frame = (CVdpauDecodedPicture*)msg->data;
2753 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::FRAME,
2754 frame,sizeof(CVdpauDecodedPicture));
2757 case COutputDataProtocol::RETURNPIC:
2758 CVdpauRenderPicture *pic;
2759 pic = *((CVdpauRenderPicture**)msg->data);
2760 QueueReturnPicture(pic);
2761 m_controlPort.SendInMessage(COutputControlProtocol::STATS);
2762 m_state = O_TOP_CONFIGURED_WORK;
2769 else if (port == &m_mixer.m_dataPort)
2773 case CMixerDataProtocol::PICTURE:
2774 CVdpauProcessedPicture *pic;
2775 pic = (CVdpauProcessedPicture*)msg->data;
2776 m_bufferPool.processedPics.push(*pic);
2777 m_state = O_TOP_CONFIGURED_WORK;
2786 case O_TOP_CONFIGURED_IDLE:
2787 if (port == NULL) // timeout
2791 case COutputControlProtocol::TIMEOUT:
2792 if (ProcessSyncPicture())
2798 m_state = O_TOP_CONFIGURED_WORK;
2808 case O_TOP_CONFIGURED_WORK:
2809 if (port == NULL) // timeout
2813 case COutputControlProtocol::TIMEOUT:
2816 CVdpauRenderPicture *pic;
2817 pic = ProcessMixerPicture();
2820 m_config.stats->DecProcessed();
2821 m_config.stats->IncRender();
2822 m_dataPort.SendInMessage(COutputDataProtocol::PICTURE, &pic, sizeof(pic));
2828 m_state = O_TOP_CONFIGURED_IDLE;
2838 default: // we are in no state, should not happen
2839 CLog::Log(LOGERROR, "COutput::%s - no valid state: %d", __FUNCTION__, m_state);
2845 void COutput::Process()
2847 Message *msg = NULL;
2848 Protocol *port = NULL;
2851 m_state = O_TOP_UNCONFIGURED;
2852 m_extTimeout = 1000;
2853 m_bStateMachineSelfTrigger = false;
2859 if (m_bStateMachineSelfTrigger)
2861 m_bStateMachineSelfTrigger = false;
2862 // self trigger state machine
2863 StateMachine(msg->signal, port, msg);
2864 if (!m_bStateMachineSelfTrigger)
2871 // check control port
2872 else if (m_controlPort.ReceiveOutMessage(&msg))
2875 port = &m_controlPort;
2878 else if (m_dataPort.ReceiveOutMessage(&msg))
2883 // check mixer data port
2884 else if (m_mixer.m_dataPort.ReceiveInMessage(&msg))
2887 port = &m_mixer.m_dataPort;
2891 StateMachine(msg->signal, port, msg);
2892 if (!m_bStateMachineSelfTrigger)
2901 else if (m_outMsgEvent.WaitMSec(m_extTimeout))
2908 msg = m_controlPort.GetMessage();
2909 msg->signal = COutputControlProtocol::TIMEOUT;
2911 // signal timeout to state machine
2912 StateMachine(msg->signal, port, msg);
2913 if (!m_bStateMachineSelfTrigger)
2924 bool COutput::Init()
2926 if (!CreateGlxContext())
2938 bool COutput::Uninit()
2942 ReleaseBufferPool();
2943 DestroyGlxContext();
2947 void COutput::Flush()
2949 if (m_mixer.IsActive())
2952 if (m_mixer.m_controlPort.SendOutMessageSync(CMixerControlProtocol::FLUSH,
2959 CLog::Log(LOGERROR, "Coutput::%s - failed to flush mixer", __FUNCTION__);
2963 while (m_mixer.m_dataPort.ReceiveInMessage(&msg))
2965 if (msg->signal == CMixerDataProtocol::PICTURE)
2967 CVdpauProcessedPicture pic = *(CVdpauProcessedPicture*)msg->data;
2968 m_bufferPool.processedPics.push(pic);
2973 while (m_dataPort.ReceiveOutMessage(&msg))
2975 if (msg->signal == COutputDataProtocol::NEWFRAME)
2977 CVdpauDecodedPicture pic = *(CVdpauDecodedPicture*)msg->data;
2978 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2980 else if (msg->signal == COutputDataProtocol::RETURNPIC)
2982 CVdpauRenderPicture *pic;
2983 pic = *((CVdpauRenderPicture**)msg->data);
2984 QueueReturnPicture(pic);
2989 while (m_dataPort.ReceiveInMessage(&msg))
2991 if (msg->signal == COutputDataProtocol::PICTURE)
2993 CVdpauRenderPicture *pic;
2994 pic = *((CVdpauRenderPicture**)msg->data);
2995 QueueReturnPicture(pic);
2999 // reset used render flag which was cleared on mixer flush
3000 std::deque<int>::iterator it;
3001 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3003 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[*it];
3004 if (pic->DVDPic.format == RENDER_FMT_VDPAU_420)
3006 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it2;
3007 it2 = m_bufferPool.glVideoSurfaceMap.find(pic->sourceIdx);
3008 if (it2 == m_bufferPool.glVideoSurfaceMap.end())
3010 CLog::Log(LOGDEBUG, "COutput::Flush - gl surface not found");
3013 m_config.videoSurfaces->MarkRender(it2->second.sourceVuv);
3017 // clear processed pics
3018 while(!m_bufferPool.processedPics.empty())
3020 CVdpauProcessedPicture procPic = m_bufferPool.processedPics.front();
3021 if (procPic.DVDPic.format == RENDER_FMT_VDPAU)
3023 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER, &procPic.outputSurface, sizeof(procPic.outputSurface));
3025 else if (procPic.DVDPic.format == RENDER_FMT_VDPAU_420)
3027 m_config.videoSurfaces->ClearRender(procPic.videoSurface);
3029 m_bufferPool.processedPics.pop();
3033 bool COutput::HasWork()
3035 if (!m_bufferPool.processedPics.empty() && !m_bufferPool.freeRenderPics.empty())
3040 CVdpauRenderPicture* COutput::ProcessMixerPicture()
3042 CVdpauRenderPicture *retPic = NULL;
3044 if (!m_bufferPool.processedPics.empty() && !m_bufferPool.freeRenderPics.empty())
3046 int idx = m_bufferPool.freeRenderPics.front();
3047 retPic = m_bufferPool.allRenderPics[idx];
3048 m_bufferPool.freeRenderPics.pop_front();
3049 m_bufferPool.usedRenderPics.push_back(idx);
3050 CVdpauProcessedPicture procPic = m_bufferPool.processedPics.front();
3051 m_bufferPool.processedPics.pop();
3053 retPic->DVDPic = procPic.DVDPic;
3054 retPic->valid = true;
3055 if (retPic->DVDPic.format == RENDER_FMT_VDPAU)
3057 m_config.useInteropYuv = false;
3058 m_bufferPool.numOutputSurfaces = NUM_RENDER_PICS;
3061 retPic->sourceIdx = procPic.outputSurface;
3062 retPic->texture[0] = m_bufferPool.glOutputSurfaceMap[procPic.outputSurface].texture[0];
3063 retPic->texWidth = m_config.outWidth;
3064 retPic->texHeight = m_config.outHeight;
3065 retPic->crop.x1 = 0;
3066 retPic->crop.y1 = (m_config.outHeight - retPic->DVDPic.iHeight) / 2;
3067 retPic->crop.x2 = m_config.outWidth;
3068 retPic->crop.y2 = m_config.outHeight - retPic->crop.y1;
3072 m_config.useInteropYuv = true;
3074 retPic->sourceIdx = procPic.videoSurface;
3075 for (unsigned int i=0; i<4; ++i)
3076 retPic->texture[i] = m_bufferPool.glVideoSurfaceMap[procPic.videoSurface].texture[i];
3077 retPic->texWidth = m_config.surfaceWidth;
3078 retPic->texHeight = m_config.surfaceHeight;
3079 retPic->crop.x1 = 0;
3080 retPic->crop.y1 = 0;
3081 retPic->crop.x2 = m_config.surfaceWidth - m_config.vidWidth;
3082 retPic->crop.y2 = m_config.surfaceHeight - m_config.vidHeight;
3088 void COutput::QueueReturnPicture(CVdpauRenderPicture *pic)
3090 std::deque<int>::iterator it;
3091 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3093 if (m_bufferPool.allRenderPics[*it] == pic)
3099 if (it == m_bufferPool.usedRenderPics.end())
3101 CLog::Log(LOGWARNING, "COutput::QueueReturnPicture - pic not found");
3105 // check if already queued
3106 std::deque<int>::iterator it2 = find(m_bufferPool.syncRenderPics.begin(),
3107 m_bufferPool.syncRenderPics.end(),
3109 if (it2 == m_bufferPool.syncRenderPics.end())
3111 m_bufferPool.syncRenderPics.push_back(*it);
3114 ProcessSyncPicture();
3117 bool COutput::ProcessSyncPicture()
3119 CVdpauRenderPicture *pic;
3122 std::deque<int>::iterator it;
3123 for (it = m_bufferPool.syncRenderPics.begin(); it != m_bufferPool.syncRenderPics.end(); )
3125 pic = m_bufferPool.allRenderPics[*it];
3130 if (glIsSync(pic->fence))
3134 glGetSynciv(pic->fence, GL_SYNC_STATUS, 1, &length, &state);
3135 if(state == GL_SIGNALED)
3137 glDeleteSync(pic->fence);
3150 m_bufferPool.freeRenderPics.push_back(*it);
3152 std::deque<int>::iterator it2 = find(m_bufferPool.usedRenderPics.begin(),
3153 m_bufferPool.usedRenderPics.end(),
3155 if (it2 == m_bufferPool.usedRenderPics.end())
3157 CLog::Log(LOGERROR, "COutput::ProcessSyncPicture - pic not found in queue");
3161 m_bufferPool.usedRenderPics.erase(it2);
3163 it = m_bufferPool.syncRenderPics.erase(it);
3167 ProcessReturnPicture(pic);
3171 CLog::Log(LOGDEBUG, "COutput::%s - return of invalid render pic", __FUNCTION__);
3177 void COutput::ProcessReturnPicture(CVdpauRenderPicture *pic)
3179 if (pic->DVDPic.format == RENDER_FMT_VDPAU_420)
3181 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3182 it = m_bufferPool.glVideoSurfaceMap.find(pic->sourceIdx);
3183 if (it == m_bufferPool.glVideoSurfaceMap.end())
3185 CLog::Log(LOGDEBUG, "COutput::ProcessReturnPicture - gl surface not found");
3188 VdpVideoSurface surf = it->second.sourceVuv;
3189 m_config.videoSurfaces->ClearRender(surf);
3191 else if (pic->DVDPic.format == RENDER_FMT_VDPAU)
3193 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3194 it = m_bufferPool.glOutputSurfaceMap.find(pic->sourceIdx);
3195 if (it == m_bufferPool.glOutputSurfaceMap.end())
3197 CLog::Log(LOGDEBUG, "COutput::ProcessReturnPicture - gl surface not found");
3200 VdpOutputSurface outSurf = it->second.sourceRgb;
3201 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER, &outSurf, sizeof(outSurf));
3205 bool COutput::EnsureBufferPool()
3209 // Creation of outputSurfaces
3210 VdpOutputSurface outputSurface;
3211 for (int i = m_bufferPool.outputSurfaces.size(); i < m_bufferPool.numOutputSurfaces; i++)
3213 vdp_st = m_config.context->GetProcs().vdp_output_surface_create(m_config.context->GetDevice(),
3214 VDP_RGBA_FORMAT_B8G8R8A8,
3218 if (CheckStatus(vdp_st, __LINE__))
3220 m_bufferPool.outputSurfaces.push_back(outputSurface);
3222 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER,
3224 sizeof(VdpOutputSurface));
3225 CLog::Log(LOGNOTICE, "VDPAU::COutput::InitBufferPool - Output Surface created");
3230 void COutput::ReleaseBufferPool()
3234 CSingleLock lock(m_bufferPool.renderPicSec);
3236 // release all output surfaces
3237 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3239 if (m_bufferPool.outputSurfaces[i] == VDP_INVALID_HANDLE)
3241 vdp_st = m_config.context->GetProcs().vdp_output_surface_destroy(m_bufferPool.outputSurfaces[i]);
3242 CheckStatus(vdp_st, __LINE__);
3244 m_bufferPool.outputSurfaces.clear();
3246 // wait for all fences
3247 XbmcThreads::EndTime timeout(1000);
3248 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); i++)
3250 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[i];
3254 while (glIsSync(pic->fence))
3258 glGetSynciv(pic->fence, GL_SYNC_STATUS, 1, &length, &state);
3259 if(state == GL_SIGNALED || timeout.IsTimePast())
3261 glDeleteSync(pic->fence);
3272 if (timeout.IsTimePast())
3274 CLog::Log(LOGERROR, "COutput::%s - timeout waiting for fence", __FUNCTION__);
3276 ProcessSyncPicture();
3278 // invalidate all used render pictures
3279 for (unsigned int i = 0; i < m_bufferPool.usedRenderPics.size(); ++i)
3281 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[m_bufferPool.usedRenderPics[i]];
3286 void COutput::PreCleanup()
3292 ProcessSyncPicture();
3294 CSingleLock lock(m_bufferPool.renderPicSec);
3295 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3297 if (m_bufferPool.outputSurfaces[i] == VDP_INVALID_HANDLE)
3300 // check if output surface is in use
3302 std::deque<int>::iterator it;
3303 CVdpauRenderPicture *pic;
3304 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3306 pic = m_bufferPool.allRenderPics[*it];
3307 if ((pic->sourceIdx == m_bufferPool.outputSurfaces[i]) && pic->valid)
3316 #ifdef GL_NV_vdpau_interop
3318 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it_map;
3319 it_map = m_bufferPool.glOutputSurfaceMap.find(m_bufferPool.outputSurfaces[i]);
3320 if (it_map == m_bufferPool.glOutputSurfaceMap.end())
3322 CLog::Log(LOGERROR, "%s - could not find gl surface", __FUNCTION__);
3325 glVDPAUUnregisterSurfaceNV(it_map->second.glVdpauSurface);
3326 glDeleteTextures(1, it_map->second.texture);
3327 m_bufferPool.glOutputSurfaceMap.erase(it_map);
3330 vdp_st = m_config.context->GetProcs().vdp_output_surface_destroy(m_bufferPool.outputSurfaces[i]);
3331 CheckStatus(vdp_st, __LINE__);
3333 m_bufferPool.outputSurfaces[i] = VDP_INVALID_HANDLE;
3335 CLog::Log(LOGDEBUG, "VDPAU::PreCleanup - released output surface");
3340 void COutput::InitMixer()
3342 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3344 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER,
3345 &m_bufferPool.outputSurfaces[i],
3346 sizeof(VdpOutputSurface));
3350 bool COutput::GLInit()
3352 #ifdef GL_NV_vdpau_interop
3353 glVDPAUInitNV = NULL;
3354 glVDPAUFiniNV = NULL;
3355 glVDPAURegisterOutputSurfaceNV = NULL;
3356 glVDPAURegisterVideoSurfaceNV = NULL;
3357 glVDPAUIsSurfaceNV = NULL;
3358 glVDPAUUnregisterSurfaceNV = NULL;
3359 glVDPAUSurfaceAccessNV = NULL;
3360 glVDPAUMapSurfacesNV = NULL;
3361 glVDPAUUnmapSurfacesNV = NULL;
3362 glVDPAUGetSurfaceivNV = NULL;
3365 #ifdef GL_NV_vdpau_interop
3367 glVDPAUInitNV = (PFNGLVDPAUINITNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUInitNV");
3369 glVDPAUFiniNV = (PFNGLVDPAUFININVPROC)glXGetProcAddress((GLubyte *) "glVDPAUFiniNV");
3370 if (!glVDPAURegisterOutputSurfaceNV)
3371 glVDPAURegisterOutputSurfaceNV = (PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAURegisterOutputSurfaceNV");
3372 if (!glVDPAURegisterVideoSurfaceNV)
3373 glVDPAURegisterVideoSurfaceNV = (PFNGLVDPAUREGISTERVIDEOSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAURegisterVideoSurfaceNV");
3374 if (!glVDPAUIsSurfaceNV)
3375 glVDPAUIsSurfaceNV = (PFNGLVDPAUISSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAUIsSurfaceNV");
3376 if (!glVDPAUUnregisterSurfaceNV)
3377 glVDPAUUnregisterSurfaceNV = (PFNGLVDPAUUNREGISTERSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAUUnregisterSurfaceNV");
3378 if (!glVDPAUSurfaceAccessNV)
3379 glVDPAUSurfaceAccessNV = (PFNGLVDPAUSURFACEACCESSNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUSurfaceAccessNV");
3380 if (!glVDPAUMapSurfacesNV)
3381 glVDPAUMapSurfacesNV = (PFNGLVDPAUMAPSURFACESNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUMapSurfacesNV");
3382 if (!glVDPAUUnmapSurfacesNV)
3383 glVDPAUUnmapSurfacesNV = (PFNGLVDPAUUNMAPSURFACESNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUUnmapSurfacesNV");
3384 if (!glVDPAUGetSurfaceivNV)
3385 glVDPAUGetSurfaceivNV = (PFNGLVDPAUGETSURFACEIVNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUGetSurfaceivNV");
3387 while (glGetError() != GL_NO_ERROR);
3388 glVDPAUInitNV(reinterpret_cast<void*>(m_config.context->GetDevice()), reinterpret_cast<void*>(m_config.context->GetProcs().vdp_get_proc_address));
3389 if (glGetError() != GL_NO_ERROR)
3391 CLog::Log(LOGERROR, "VDPAU::COutput - GLInitInterop glVDPAUInitNV failed");
3395 CLog::Log(LOGNOTICE, "VDPAU::COutput: vdpau gl interop initialized");
3399 bool hasfence = glewIsSupported("GL_ARB_sync");
3400 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); i++)
3402 m_bufferPool.allRenderPics[i]->usefence = hasfence;
3409 void COutput::GLMapSurfaces()
3411 #ifdef GL_NV_vdpau_interop
3413 if (m_config.useInteropYuv)
3415 VdpauBufferPool::GLVideoSurface glSurface;
3416 VdpVideoSurface surf;
3417 if (m_config.videoSurfaces->Size() != m_bufferPool.glVideoSurfaceMap.size())
3419 for (unsigned int i = 0; i < m_config.videoSurfaces->Size(); i++)
3421 surf = m_config.videoSurfaces->GetAtIndex(i);
3423 if (surf == VDP_INVALID_HANDLE)
3426 if (m_bufferPool.glVideoSurfaceMap.find(surf) == m_bufferPool.glVideoSurfaceMap.end())
3428 glSurface.sourceVuv = surf;
3429 while (glGetError() != GL_NO_ERROR) ;
3430 glGenTextures(4, glSurface.texture);
3431 if (glGetError() != GL_NO_ERROR)
3433 CLog::Log(LOGERROR, "VDPAU::COutput error creating texture");
3436 glSurface.glVdpauSurface = glVDPAURegisterVideoSurfaceNV(reinterpret_cast<void*>(surf),
3437 GL_TEXTURE_2D, 4, glSurface.texture);
3439 if (glGetError() != GL_NO_ERROR)
3441 CLog::Log(LOGERROR, "VDPAU::COutput error register video surface");
3444 glVDPAUSurfaceAccessNV(glSurface.glVdpauSurface, GL_READ_ONLY);
3445 if (glGetError() != GL_NO_ERROR)
3447 CLog::Log(LOGERROR, "VDPAU::COutput error setting access");
3450 glVDPAUMapSurfacesNV(1, &glSurface.glVdpauSurface);
3451 if (glGetError() != GL_NO_ERROR)
3453 CLog::Log(LOGERROR, "VDPAU::COutput error mapping surface");
3456 m_bufferPool.glVideoSurfaceMap[surf] = glSurface;
3459 CLog::Log(LOGNOTICE, "VDPAU::COutput registered surface");
3466 if (m_bufferPool.glOutputSurfaceMap.size() != m_bufferPool.numOutputSurfaces)
3468 VdpauBufferPool::GLVideoSurface glSurface;
3469 for (unsigned int i = m_bufferPool.glOutputSurfaceMap.size(); i<m_bufferPool.outputSurfaces.size(); i++)
3471 glSurface.sourceRgb = m_bufferPool.outputSurfaces[i];
3472 glGenTextures(1, glSurface.texture);
3473 glSurface.glVdpauSurface = glVDPAURegisterOutputSurfaceNV(reinterpret_cast<void*>(m_bufferPool.outputSurfaces[i]),
3474 GL_TEXTURE_2D, 1, glSurface.texture);
3475 if (glGetError() != GL_NO_ERROR)
3477 CLog::Log(LOGERROR, "VDPAU::COutput error register output surface");
3480 glVDPAUSurfaceAccessNV(glSurface.glVdpauSurface, GL_READ_ONLY);
3481 if (glGetError() != GL_NO_ERROR)
3483 CLog::Log(LOGERROR, "VDPAU::COutput error setting access");
3486 glVDPAUMapSurfacesNV(1, &glSurface.glVdpauSurface);
3487 if (glGetError() != GL_NO_ERROR)
3489 CLog::Log(LOGERROR, "VDPAU::COutput error mapping surface");
3492 m_bufferPool.glOutputSurfaceMap[m_bufferPool.outputSurfaces[i]] = glSurface;
3496 CLog::Log(LOGNOTICE, "VDPAU::COutput registered output surfaces");
3502 void COutput::GLUnmapSurfaces()
3504 #ifdef GL_NV_vdpau_interop
3507 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3508 for (it = m_bufferPool.glVideoSurfaceMap.begin(); it != m_bufferPool.glVideoSurfaceMap.end(); ++it)
3510 glVDPAUUnregisterSurfaceNV(it->second.glVdpauSurface);
3511 glDeleteTextures(4, it->second.texture);
3513 m_bufferPool.glVideoSurfaceMap.clear();
3516 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3517 for (it = m_bufferPool.glOutputSurfaceMap.begin(); it != m_bufferPool.glOutputSurfaceMap.end(); ++it)
3519 glVDPAUUnregisterSurfaceNV(it->second.glVdpauSurface);
3520 glDeleteTextures(1, it->second.texture);
3522 m_bufferPool.glOutputSurfaceMap.clear();
3526 CLog::Log(LOGNOTICE, "VDPAU::COutput: vdpau gl interop finished");
3531 bool COutput::CheckStatus(VdpStatus vdp_st, int line)
3533 if (vdp_st != VDP_STATUS_OK)
3535 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);
3542 bool COutput::CreateGlxContext()
3544 GLXContext glContext;
3546 m_Display = g_Windowing.GetDisplay();
3547 glContext = g_Windowing.GetGlxContext();
3548 m_Window = g_Windowing.GetWindow();
3550 // Get our window attribs.
3551 XWindowAttributes wndattribs;
3552 XGetWindowAttributes(m_Display, m_Window, &wndattribs);
3555 XVisualInfo visInfo;
3556 visInfo.visualid = wndattribs.visual->visualid;
3558 XVisualInfo* visuals = XGetVisualInfo(m_Display, VisualIDMask, &visInfo, &nvisuals);
3561 CLog::Log(LOGERROR, "VDPAU::COutput::CreateGlxContext - could not find visual");
3564 visInfo = visuals[0];
3567 m_pixmap = XCreatePixmap(m_Display,
3574 CLog::Log(LOGERROR, "VDPAU::COutput::CreateGlxContext - Unable to create XPixmap");
3579 m_glPixmap = glXCreateGLXPixmap(m_Display, &visInfo, m_pixmap);
3583 CLog::Log(LOGINFO, "VDPAU::COutput::CreateGlxContext - Could not create glPixmap");
3587 m_glContext = glXCreateContext(m_Display, &visInfo, glContext, True);
3589 if (!glXMakeCurrent(m_Display, m_glPixmap, m_glContext))
3591 CLog::Log(LOGINFO, "VDPAU::COutput::CreateGlxContext - Could not make Pixmap current");
3595 CLog::Log(LOGNOTICE, "VDPAU::COutput::CreateGlxContext - created context");
3599 bool COutput::DestroyGlxContext()
3603 glXMakeCurrent(m_Display, None, NULL);
3604 glXDestroyContext(m_Display, m_glContext);
3609 glXDestroyPixmap(m_Display, m_glPixmap);
3613 XFreePixmap(m_Display, m_pixmap);