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
42 #define NUM_CROP_PIX 3
44 #define ARSIZE(x) (sizeof(x) / sizeof((x)[0]))
46 // settings codecs mapping
47 DVDCodecAvailableType g_vdpau_available[] = {
48 { AV_CODEC_ID_H263, "videoplayer.usevdpaumpeg4" },
49 { AV_CODEC_ID_MPEG4, "videoplayer.usevdpaumpeg4" },
50 { AV_CODEC_ID_WMV3, "videoplayer.usevdpauvc1" },
51 { AV_CODEC_ID_VC1, "videoplayer.usevdpauvc1" },
52 { AV_CODEC_ID_MPEG2VIDEO, "videoplayer.usevdpaumpeg2" },
54 const size_t settings_count = sizeof(g_vdpau_available) / sizeof(DVDCodecAvailableType);
56 CDecoder::Desc decoder_profiles[] = {
57 {"MPEG1", VDP_DECODER_PROFILE_MPEG1},
58 {"MPEG2_SIMPLE", VDP_DECODER_PROFILE_MPEG2_SIMPLE},
59 {"MPEG2_MAIN", VDP_DECODER_PROFILE_MPEG2_MAIN},
60 {"H264_BASELINE",VDP_DECODER_PROFILE_H264_BASELINE},
61 {"H264_MAIN", VDP_DECODER_PROFILE_H264_MAIN},
62 {"H264_HIGH", VDP_DECODER_PROFILE_H264_HIGH},
63 {"VC1_SIMPLE", VDP_DECODER_PROFILE_VC1_SIMPLE},
64 {"VC1_MAIN", VDP_DECODER_PROFILE_VC1_MAIN},
65 {"VC1_ADVANCED", VDP_DECODER_PROFILE_VC1_ADVANCED},
66 {"MPEG4_PART2_ASP", VDP_DECODER_PROFILE_MPEG4_PART2_ASP},
68 const size_t decoder_profile_count = sizeof(decoder_profiles)/sizeof(CDecoder::Desc);
70 static struct SInterlaceMapping
72 const EINTERLACEMETHOD method;
73 const VdpVideoMixerFeature feature;
74 } g_interlace_mapping[] =
75 { {VS_INTERLACEMETHOD_VDPAU_TEMPORAL , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL}
76 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL}
77 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL}
78 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF, VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL}
79 , {VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE , VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE}
80 , {VS_INTERLACEMETHOD_NONE , (VdpVideoMixerFeature)-1}
83 static float studioCSCKCoeffs601[3] = {0.299, 0.587, 0.114}; //BT601 {Kr, Kg, Kb}
84 static float studioCSCKCoeffs709[3] = {0.2126, 0.7152, 0.0722}; //BT709 {Kr, Kg, Kb}
86 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
89 CVDPAUContext *CVDPAUContext::m_context = 0;
90 CCriticalSection CVDPAUContext::m_section;
91 Display *CVDPAUContext::m_display = 0;
92 void *CVDPAUContext::m_dlHandle = 0;
94 CVDPAUContext::CVDPAUContext()
100 void CVDPAUContext::Release()
102 CSingleLock lock(m_section);
113 void CVDPAUContext::Close()
115 CLog::Log(LOGNOTICE, "VDPAU::Close - closing decoder context");
119 bool CVDPAUContext::EnsureContext(CVDPAUContext **ctx)
121 CSingleLock lock(m_section);
125 m_context->m_refCount++;
130 m_context = new CVDPAUContext();
133 CSingleLock gLock(g_graphicsContext);
134 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::Open: required extension GL_NV_vdpau_interop not found");
518 if(avctx->coded_width == 0
519 || avctx->coded_height == 0)
521 CLog::Log(LOGWARNING,"VDPAU::Open: 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;
541 // convert FFMPEG codec ID to VDPAU profile.
542 ReadFormatOf(avctx->codec_id, profile, m_vdpauConfig.vdpChromaType);
546 VdpBool is_supported = false;
547 uint32_t max_level, max_macroblocks, max_width, max_height;
549 // query device capabilities to ensure that VDPAU can handle the requested codec
550 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_query_caps(m_vdpauConfig.context->GetDevice(),
551 profile, &is_supported, &max_level, &max_macroblocks, &max_width, &max_height);
553 // test to make sure there is a possibility the codec will work
554 if (CheckStatus(vdp_st, __LINE__))
556 CLog::Log(LOGERROR, "VDPAU::Open: error %s(%d) checking for decoder support", m_vdpauConfig.context->GetProcs().vdp_get_error_string(vdp_st), vdp_st);
560 if (max_width < avctx->coded_width || max_height < avctx->coded_height)
562 CLog::Log(LOGWARNING,"VDPAU::Open: requested picture dimensions (%i, %i) exceed hardware capabilities ( %i, %i).",
563 avctx->coded_width, avctx->coded_height, max_width, max_height);
567 if (!CDVDCodecUtils::IsVP3CompatibleWidth(avctx->coded_width))
568 CLog::Log(LOGWARNING,"VDPAU::Open width %i might not be supported because of hardware bug", avctx->width);
570 // attempt to create a decoder with this width/height, some sizes are not supported by hw
571 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_create(m_vdpauConfig.context->GetDevice(), profile, avctx->coded_width, avctx->coded_height, 5, &m_vdpauConfig.vdpDecoder);
573 if (CheckStatus(vdp_st, __LINE__))
575 CLog::Log(LOGERROR, "VDPAU::Open: error: %s(%d) checking for decoder support", m_vdpauConfig.context->GetProcs().vdp_get_error_string(vdp_st), vdp_st);
579 m_vdpauConfig.context->GetProcs().vdp_decoder_destroy(m_vdpauConfig.vdpDecoder);
580 CheckStatus(vdp_st, __LINE__);
582 // finally setup ffmpeg
583 memset(&m_hwContext, 0, sizeof(AVVDPAUContext));
584 m_hwContext.render = CDecoder::Render;
585 m_hwContext.bitstream_buffers_allocated = 0;
586 avctx->get_buffer = CDecoder::FFGetBuffer;
587 avctx->reget_buffer = CDecoder::FFGetBuffer;
588 avctx->release_buffer = CDecoder::FFReleaseBuffer;
589 avctx->draw_horiz_band = CDecoder::FFDrawSlice;
590 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD;
591 avctx->hwaccel_context = &m_hwContext;
593 g_Windowing.Register(this);
600 CDecoder::~CDecoder()
605 void CDecoder::Close()
607 CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);
609 g_Windowing.Unregister(this);
611 CSingleLock lock(m_DecoderSection);
614 m_vdpauOutput.Dispose();
616 if (m_hwContext.bitstream_buffers_allocated)
618 m_dllAvUtil.av_freep(&m_hwContext.bitstream_buffers);
621 m_dllAvUtil.Unload();
623 if (m_vdpauConfig.context)
624 m_vdpauConfig.context->Release();
625 m_vdpauConfig.context = 0;
628 long CDecoder::Release()
630 // check if we should do some pre-cleanup here
631 // a second decoder might need resources
632 if (m_vdpauConfigured == true)
634 CSingleLock lock(m_DecoderSection);
635 CLog::Log(LOGNOTICE,"CVDPAU::Release pre-cleanup");
638 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::PRECLEANUP,
642 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
646 CLog::Log(LOGERROR, "VDPAU::%s - pre-cleanup returned error", __FUNCTION__);
647 m_DisplayState = VDPAU_ERROR;
652 CLog::Log(LOGERROR, "VDPAU::%s - pre-cleanup timed out", __FUNCTION__);
653 m_DisplayState = VDPAU_ERROR;
656 VdpVideoSurface surf;
657 while((surf = m_videoSurfaces.RemoveNext(true)) != VDP_INVALID_HANDLE)
659 m_vdpauConfig.context->GetProcs().vdp_video_surface_destroy(surf);
662 return IHardwareDecoder::Release();
665 long CDecoder::ReleasePicReference()
667 return IHardwareDecoder::Release();
670 void CDecoder::SetWidthHeight(int width, int height)
672 m_vdpauConfig.upscale = g_advancedSettings.m_videoVDPAUScaling;
674 //pick the smallest dimensions, so we downscale with vdpau and upscale with opengl when appropriate
675 //this requires the least amount of gpu memory bandwidth
676 if (g_graphicsContext.GetWidth() < width || g_graphicsContext.GetHeight() < height || m_vdpauConfig.upscale >= 0)
678 //scale width to desktop size if the aspect ratio is the same or bigger than the desktop
679 if ((double)height * g_graphicsContext.GetWidth() / width <= (double)g_graphicsContext.GetHeight())
681 m_vdpauConfig.outWidth = g_graphicsContext.GetWidth();
682 m_vdpauConfig.outHeight = MathUtils::round_int((double)height * g_graphicsContext.GetWidth() / width);
684 else //scale height to the desktop size if the aspect ratio is smaller than the desktop
686 m_vdpauConfig.outHeight = g_graphicsContext.GetHeight();
687 m_vdpauConfig.outWidth = MathUtils::round_int((double)width * g_graphicsContext.GetHeight() / height);
692 m_vdpauConfig.outWidth = width;
693 m_vdpauConfig.outHeight = height;
695 CLog::Log(LOGDEBUG, "CVDPAU::SetWidthHeight Setting OutWidth: %i OutHeight: %i", m_vdpauConfig.outWidth, m_vdpauConfig.outHeight);
698 void CDecoder::OnLostDevice()
700 CLog::Log(LOGNOTICE,"CVDPAU::OnLostDevice event");
702 int count = g_graphicsContext.exit();
704 CSingleLock lock(m_DecoderSection);
706 if (m_vdpauConfig.context)
707 m_vdpauConfig.context->Release();
708 m_vdpauConfig.context = 0;
710 m_DisplayState = VDPAU_LOST;
712 m_DisplayEvent.Reset();
714 g_graphicsContext.restore(count);
717 void CDecoder::OnResetDevice()
719 CLog::Log(LOGNOTICE,"CVDPAU::OnResetDevice event");
721 int count = g_graphicsContext.exit();
723 CSingleLock lock(m_DecoderSection);
724 if (m_DisplayState == VDPAU_LOST)
726 m_DisplayState = VDPAU_RESET;
728 m_DisplayEvent.Set();
731 g_graphicsContext.restore(count);
734 int CDecoder::Check(AVCodecContext* avctx)
738 { CSingleLock lock(m_DecoderSection);
739 state = m_DisplayState;
742 if (state == VDPAU_LOST)
744 CLog::Log(LOGNOTICE,"CVDPAU::Check waiting for display reset event");
745 if (!m_DisplayEvent.WaitMSec(4000))
747 CLog::Log(LOGERROR, "CVDPAU::Check - device didn't reset in reasonable time");
752 CSingleLock lock(m_DecoderSection);
753 state = m_DisplayState;
756 if (state == VDPAU_RESET || state == VDPAU_ERROR)
758 CSingleLock lock(m_DecoderSection);
761 if (m_vdpauConfig.context)
762 m_vdpauConfig.context->Release();
763 m_vdpauConfig.context = 0;
765 if (CVDPAUContext::EnsureContext(&m_vdpauConfig.context))
767 m_DisplayState = VDPAU_OPEN;
768 m_vdpauConfigured = false;
771 if (state == VDPAU_RESET)
779 bool CDecoder::IsVDPAUFormat(PixelFormat format)
781 if (format == AV_PIX_FMT_VDPAU)
787 bool CDecoder::Supports(VdpVideoMixerFeature feature)
789 return m_vdpauConfig.context->Supports(feature);
792 bool CDecoder::Supports(EINTERLACEMETHOD method)
794 if(method == VS_INTERLACEMETHOD_VDPAU_BOB
795 || method == VS_INTERLACEMETHOD_AUTO)
798 if (method == VS_INTERLACEMETHOD_RENDER_BOB)
801 if (method == VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE)
804 for(SInterlaceMapping* p = g_interlace_mapping; p->method != VS_INTERLACEMETHOD_NONE; p++)
806 if(p->method == method)
807 return Supports(p->feature);
812 EINTERLACEMETHOD CDecoder::AutoInterlaceMethod()
814 return VS_INTERLACEMETHOD_RENDER_BOB;
817 void CDecoder::FiniVDPAUOutput()
819 if (!m_vdpauConfigured)
822 CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);
825 m_vdpauOutput.Dispose();
826 m_vdpauConfigured = false;
830 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_destroy(m_vdpauConfig.vdpDecoder);
831 if (CheckStatus(vdp_st, __LINE__))
833 m_vdpauConfig.vdpDecoder = VDP_INVALID_HANDLE;
835 CLog::Log(LOGDEBUG, "CVDPAU::FiniVDPAUOutput destroying %d video surfaces", m_videoSurfaces.Size());
837 VdpVideoSurface surf;
838 while((surf = m_videoSurfaces.RemoveNext()) != VDP_INVALID_HANDLE)
840 m_vdpauConfig.context->GetProcs().vdp_video_surface_destroy(surf);
841 if (CheckStatus(vdp_st, __LINE__))
844 m_videoSurfaces.Reset();
847 void CDecoder::ReadFormatOf( AVCodecID codec
848 , VdpDecoderProfile &vdp_decoder_profile
849 , VdpChromaType &vdp_chroma_type)
853 case AV_CODEC_ID_MPEG1VIDEO:
854 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
855 vdp_chroma_type = VDP_CHROMA_TYPE_420;
857 case AV_CODEC_ID_MPEG2VIDEO:
858 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
859 vdp_chroma_type = VDP_CHROMA_TYPE_420;
861 case AV_CODEC_ID_H264:
862 vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
863 vdp_chroma_type = VDP_CHROMA_TYPE_420;
865 case AV_CODEC_ID_WMV3:
866 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
867 vdp_chroma_type = VDP_CHROMA_TYPE_420;
869 case AV_CODEC_ID_VC1:
870 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
871 vdp_chroma_type = VDP_CHROMA_TYPE_420;
873 case AV_CODEC_ID_MPEG4:
874 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
875 vdp_chroma_type = VDP_CHROMA_TYPE_420;
878 vdp_decoder_profile = 0;
884 bool CDecoder::ConfigVDPAU(AVCodecContext* avctx, int ref_frames)
889 VdpDecoderProfile vdp_decoder_profile;
891 m_vdpauConfig.vidWidth = avctx->width;
892 m_vdpauConfig.vidHeight = avctx->height;
893 m_vdpauConfig.surfaceWidth = avctx->coded_width;
894 m_vdpauConfig.surfaceHeight = avctx->coded_height;
896 SetWidthHeight(avctx->width,avctx->height);
898 CLog::Log(LOGNOTICE, " (VDPAU) screenWidth:%i vidWidth:%i surfaceWidth:%i",m_vdpauConfig.outWidth,m_vdpauConfig.vidWidth,m_vdpauConfig.surfaceWidth);
899 CLog::Log(LOGNOTICE, " (VDPAU) screenHeight:%i vidHeight:%i surfaceHeight:%i",m_vdpauConfig.outHeight,m_vdpauConfig.vidHeight,m_vdpauConfig.surfaceHeight);
901 ReadFormatOf(avctx->codec_id, vdp_decoder_profile, m_vdpauConfig.vdpChromaType);
903 if(avctx->codec_id == AV_CODEC_ID_H264)
905 m_vdpauConfig.maxReferences = ref_frames;
906 if (m_vdpauConfig.maxReferences > 16) m_vdpauConfig.maxReferences = 16;
907 if (m_vdpauConfig.maxReferences < 5) m_vdpauConfig.maxReferences = 5;
910 m_vdpauConfig.maxReferences = 2;
912 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_create(m_vdpauConfig.context->GetDevice(),
914 m_vdpauConfig.surfaceWidth,
915 m_vdpauConfig.surfaceHeight,
916 m_vdpauConfig.maxReferences,
917 &m_vdpauConfig.vdpDecoder);
918 if (CheckStatus(vdp_st, __LINE__))
922 CSingleLock lock(g_graphicsContext);
923 m_vdpauConfig.stats = &m_bufferStats;
924 m_vdpauConfig.vdpau = this;
925 m_bufferStats.Reset();
926 m_vdpauOutput.Start();
928 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::INIT,
932 sizeof(m_vdpauConfig)))
934 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
938 CLog::Log(LOGERROR, "VDPAU::%s - vdpau output returned error", __FUNCTION__);
939 m_vdpauOutput.Dispose();
945 CLog::Log(LOGERROR, "VDPAU::%s - failed to init output", __FUNCTION__);
946 m_vdpauOutput.Dispose();
950 m_inMsgEvent.Reset();
951 m_vdpauConfigured = true;
956 int CDecoder::FFGetBuffer(AVCodecContext *avctx, AVFrame *pic)
958 //CLog::Log(LOGNOTICE,"%s",__FUNCTION__);
959 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)avctx->opaque;
960 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
962 // while we are waiting to recover we can't do anything
963 CSingleLock lock(vdp->m_DecoderSection);
965 if(vdp->m_DisplayState != VDPAU_OPEN)
967 CLog::Log(LOGWARNING, "CVDPAU::FFGetBuffer - returning due to awaiting recovery");
971 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)pic->data[3];
972 surf = vdp->m_videoSurfaces.GetFree(surf != 0 ? surf : VDP_INVALID_HANDLE);
974 VdpStatus vdp_st = VDP_STATUS_ERROR;
975 if (surf == VDP_INVALID_HANDLE)
977 // create a new surface
978 VdpDecoderProfile profile;
979 ReadFormatOf(avctx->codec_id, profile, vdp->m_vdpauConfig.vdpChromaType);
981 vdp_st = vdp->m_vdpauConfig.context->GetProcs().vdp_video_surface_create(vdp->m_vdpauConfig.context->GetDevice(),
982 vdp->m_vdpauConfig.vdpChromaType,
986 vdp->CheckStatus(vdp_st, __LINE__);
987 if (vdp_st != VDP_STATUS_OK)
989 CLog::Log(LOGERROR, "CVDPAU::FFGetBuffer - No Video surface available could be created");
992 vdp->m_videoSurfaces.AddSurface(surf);
995 pic->data[1] = pic->data[2] = NULL;
996 pic->data[0] = (uint8_t*)(uintptr_t)surf;
997 pic->data[3] = (uint8_t*)(uintptr_t)surf;
999 pic->linesize[0] = pic->linesize[1] = pic->linesize[2] = 0;
1001 pic->type= FF_BUFFER_TYPE_USER;
1003 pic->reordered_opaque= avctx->reordered_opaque;
1007 void CDecoder::FFReleaseBuffer(AVCodecContext *avctx, AVFrame *pic)
1009 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)avctx->opaque;
1010 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
1012 VdpVideoSurface surf;
1015 CSingleLock lock(vdp->m_DecoderSection);
1017 surf = (VdpVideoSurface)(uintptr_t)pic->data[3];
1019 vdp->m_videoSurfaces.ClearReference(surf);
1025 VdpStatus CDecoder::Render( VdpDecoder decoder, VdpVideoSurface target,
1026 VdpPictureInfo const *picture_info,
1027 uint32_t bitstream_buffer_count,
1028 VdpBitstreamBuffer const * bitstream_buffers)
1030 return VDP_STATUS_OK;
1033 void CDecoder::FFDrawSlice(struct AVCodecContext *s,
1034 const AVFrame *src, int offset[4],
1035 int y, int type, int height)
1037 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)s->opaque;
1038 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
1040 // while we are waiting to recover we can't do anything
1041 CSingleLock lock(vdp->m_DecoderSection);
1043 if(vdp->m_DisplayState != VDPAU_OPEN)
1046 if(src->linesize[0] || src->linesize[1] || src->linesize[2]
1047 || offset[0] || offset[1] || offset[2])
1049 CLog::Log(LOGERROR, "CVDPAU::FFDrawSlice - invalid linesizes or offsets provided");
1054 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)src->data[3];
1056 // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid
1057 if (!vdp->m_videoSurfaces.IsValid(surf))
1059 CLog::Log(LOGWARNING, "CVDPAU::FFDrawSlice - ignoring invalid buffer");
1063 uint32_t max_refs = 0;
1064 if(s->codec_id == AV_CODEC_ID_H264)
1065 max_refs = vdp->m_hwContext.info.h264.num_ref_frames;
1067 if(vdp->m_vdpauConfig.vdpDecoder == VDP_INVALID_HANDLE
1068 || vdp->m_vdpauConfigured == false
1069 || vdp->m_vdpauConfig.maxReferences < max_refs)
1071 if(!vdp->ConfigVDPAU(s, max_refs))
1075 uint64_t startTime = CurrentHostCounter();
1076 uint16_t decoded, processed, rend;
1077 vdp->m_bufferStats.Get(decoded, processed, rend);
1078 vdp_st = vdp->m_vdpauConfig.context->GetProcs().vdp_decoder_render(vdp->m_vdpauConfig.vdpDecoder,
1080 (VdpPictureInfo const *)&(vdp->m_hwContext.info),
1081 vdp->m_hwContext.bitstream_buffers_used,
1082 vdp->m_hwContext.bitstream_buffers);
1083 if (vdp->CheckStatus(vdp_st, __LINE__))
1084 vdp->m_DecoderError = true;
1086 vdp->m_DecoderError = false;
1088 uint64_t diff = CurrentHostCounter() - startTime;
1089 if (diff*1000/CurrentHostFrequency() > 30)
1090 CLog::Log(LOGDEBUG, "CVDPAU::DrawSlice - VdpDecoderRender long decoding: %d ms, dec: %d, proc: %d, rend: %d", (int)((diff*1000)/CurrentHostFrequency()), decoded, processed, rend);
1094 int CDecoder::Decode(AVCodecContext *avctx, AVFrame *pFrame)
1096 int result = Check(avctx);
1100 CSingleLock lock(m_DecoderSection);
1102 if (m_DecoderError && pFrame)
1105 if (!m_vdpauConfigured)
1109 { // we have a new frame from decoder
1111 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)pFrame->data[3];
1112 // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid
1113 if (!m_videoSurfaces.IsValid(surf))
1115 CLog::Log(LOGWARNING, "CVDPAU::Decode - ignoring invalid buffer");
1118 m_videoSurfaces.MarkRender(surf);
1120 // send frame to output for processing
1121 CVdpauDecodedPicture pic;
1122 memset(&pic.DVDPic, 0, sizeof(pic.DVDPic));
1123 ((CDVDVideoCodecFFmpeg*)avctx->opaque)->GetPictureCommon(&pic.DVDPic);
1124 pic.videoSurface = surf;
1125 pic.DVDPic.color_matrix = avctx->colorspace;
1126 m_bufferStats.IncDecoded();
1127 m_vdpauOutput.m_dataPort.SendOutMessage(COutputDataProtocol::NEWFRAME, &pic, sizeof(pic));
1130 // m_codecControl = pic.DVDPic.iFlags & (DVP_FLAG_DRAIN | DVP_FLAG_NO_POSTPROC);
1134 uint16_t decoded, processed, render;
1136 while (m_vdpauOutput.m_controlPort.ReceiveInMessage(&msg))
1138 if (msg->signal == COutputControlProtocol::ERROR)
1140 m_DisplayState = VDPAU_ERROR;
1146 m_bufferStats.Get(decoded, processed, render);
1148 uint64_t startTime = CurrentHostCounter();
1151 // first fill the buffers to keep vdpau busy
1152 // mixer will run with decoded >= 2. output is limited by number of output surfaces
1153 // In case mixer is bypassed we limit by looking at processed
1154 if (decoded < 3 && processed < 3)
1156 retval |= VC_BUFFER;
1158 else if (m_vdpauOutput.m_dataPort.ReceiveInMessage(&msg))
1160 if (msg->signal == COutputDataProtocol::PICTURE)
1162 if (m_presentPicture)
1164 m_presentPicture->ReturnUnused();
1165 m_presentPicture = 0;
1168 m_presentPicture = *(CVdpauRenderPicture**)msg->data;
1169 m_presentPicture->vdpau = this;
1170 m_bufferStats.DecRender();
1171 m_bufferStats.Get(decoded, processed, render);
1172 retval |= VC_PICTURE;
1178 else if (m_vdpauOutput.m_controlPort.ReceiveInMessage(&msg))
1180 if (msg->signal == COutputControlProtocol::STATS)
1182 m_bufferStats.Get(decoded, processed, render);
1186 m_DisplayState = VDPAU_ERROR;
1192 if (decoded < 3 && processed < 3)
1194 retval |= VC_BUFFER;
1197 if (!retval && !m_inMsgEvent.WaitMSec(2000))
1200 uint64_t diff = CurrentHostCounter() - startTime;
1201 if (retval & VC_PICTURE)
1203 m_bufferStats.SetParams(diff, m_codecControl);
1205 if (diff*1000/CurrentHostFrequency() > 50)
1206 CLog::Log(LOGDEBUG,"CVDPAU::Decode long wait: %d", (int)((diff*1000)/CurrentHostFrequency()));
1210 CLog::Log(LOGERROR, "VDPAU::%s - timed out waiting for output message", __FUNCTION__);
1211 m_DisplayState = VDPAU_ERROR;
1218 bool CDecoder::GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture)
1220 CSingleLock lock(m_DecoderSection);
1222 if (m_DisplayState != VDPAU_OPEN)
1225 *picture = m_presentPicture->DVDPic;
1226 picture->vdpau = m_presentPicture;
1231 void CDecoder::Reset()
1233 CSingleLock lock(m_DecoderSection);
1235 if (!m_vdpauConfigured)
1239 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::FLUSH,
1243 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
1247 CLog::Log(LOGERROR, "VDPAU::%s - flush returned error", __FUNCTION__);
1248 m_DisplayState = VDPAU_ERROR;
1251 m_bufferStats.Reset();
1255 CLog::Log(LOGERROR, "VDPAU::%s - flush timed out", __FUNCTION__);
1256 m_DisplayState = VDPAU_ERROR;
1260 bool CDecoder::CanSkipDeint()
1262 return m_bufferStats.CanSkipDeint();
1265 void CDecoder::ReturnRenderPicture(CVdpauRenderPicture *renderPic)
1267 m_vdpauOutput.m_dataPort.SendOutMessage(COutputDataProtocol::RETURNPIC, &renderPic, sizeof(renderPic));
1270 bool CDecoder::CheckStatus(VdpStatus vdp_st, int line)
1272 if (vdp_st != VDP_STATUS_OK)
1274 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);
1278 if(m_DisplayState == VDPAU_OPEN)
1280 if (vdp_st == VDP_STATUS_DISPLAY_PREEMPTED)
1282 m_DisplayEvent.Reset();
1283 m_DisplayState = VDPAU_LOST;
1285 else if (m_ErrorCount > 2)
1286 m_DisplayState = VDPAU_ERROR;
1295 //-----------------------------------------------------------------------------
1297 //-----------------------------------------------------------------------------
1299 CVdpauRenderPicture* CVdpauRenderPicture::Acquire()
1301 CSingleLock lock(renderPicSection);
1310 long CVdpauRenderPicture::Release()
1312 CSingleLock lock(renderPicSection);
1319 vdpau->ReturnRenderPicture(this);
1320 vdpau->ReleasePicReference();
1325 void CVdpauRenderPicture::ReturnUnused()
1327 { CSingleLock lock(renderPicSection);
1332 vdpau->ReturnRenderPicture(this);
1335 void CVdpauRenderPicture::Sync()
1338 CSingleLock lock(renderPicSection);
1343 glDeleteSync(fence);
1346 fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
1351 //-----------------------------------------------------------------------------
1353 //-----------------------------------------------------------------------------
1354 CMixer::CMixer(CEvent *inMsgEvent) :
1355 CThread("Vdpau Mixer"),
1356 m_controlPort("ControlPort", inMsgEvent, &m_outMsgEvent),
1357 m_dataPort("DataPort", inMsgEvent, &m_outMsgEvent)
1359 m_inMsgEvent = inMsgEvent;
1367 void CMixer::Start()
1372 void CMixer::Dispose()
1375 m_outMsgEvent.Set();
1378 m_controlPort.Purge();
1382 bool CMixer::IsActive()
1387 void CMixer::OnStartup()
1389 CLog::Log(LOGNOTICE, "CMixer::OnStartup: Output Thread created");
1392 void CMixer::OnExit()
1394 CLog::Log(LOGNOTICE, "CMixer::OnExit: Output Thread terminated");
1401 M_TOP_UNCONFIGURED, // 2
1402 M_TOP_CONFIGURED, // 3
1403 M_TOP_CONFIGURED_WAIT1, // 4
1404 M_TOP_CONFIGURED_STEP1, // 5
1405 M_TOP_CONFIGURED_WAIT2, // 6
1406 M_TOP_CONFIGURED_STEP2, // 7
1409 int MIXER_parentStates[] = {
1412 0, //TOP_UNCONFIGURED
1414 3, //TOP_CONFIGURED_WAIT1
1415 3, //TOP_CONFIGURED_STEP1
1416 3, //TOP_CONFIGURED_WAIT2
1417 3, //TOP_CONFIGURED_STEP2
1420 void CMixer::StateMachine(int signal, Protocol *port, Message *msg)
1422 for (int state = m_state; ; state = MIXER_parentStates[state])
1427 if (port == &m_controlPort)
1431 case CMixerControlProtocol::FLUSH:
1433 msg->Reply(CMixerControlProtocol::ACC);
1440 std::string portName = port == NULL ? "timer" : port->portName;
1441 CLog::Log(LOGWARNING, "CMixer::%s - signal: %d form port: %s not handled for state: %d", __FUNCTION__, signal, portName.c_str(), m_state);
1445 case M_TOP_ERROR: // TOP
1448 case M_TOP_UNCONFIGURED:
1449 if (port == &m_controlPort)
1453 case CMixerControlProtocol::INIT:
1455 data = (CVdpauConfig*)msg->data;
1463 m_state = M_TOP_CONFIGURED_WAIT1;
1464 msg->Reply(CMixerControlProtocol::ACC);
1468 msg->Reply(CMixerControlProtocol::ERROR);
1477 case M_TOP_CONFIGURED:
1478 if (port == &m_dataPort)
1482 case CMixerDataProtocol::FRAME:
1483 CVdpauDecodedPicture *frame;
1484 frame = (CVdpauDecodedPicture*)msg->data;
1487 m_decodedPics.push(*frame);
1491 case CMixerDataProtocol::BUFFER:
1492 VdpOutputSurface *surf;
1493 surf = (VdpOutputSurface*)msg->data;
1496 m_outputSurfaces.push(*surf);
1506 case M_TOP_CONFIGURED_WAIT1:
1507 if (port == NULL) // timeout
1511 case CMixerControlProtocol::TIMEOUT:
1512 if (!m_decodedPics.empty() && !m_outputSurfaces.empty())
1514 m_state = M_TOP_CONFIGURED_STEP1;
1515 m_bStateMachineSelfTrigger = true;
1528 case M_TOP_CONFIGURED_STEP1:
1529 if (port == NULL) // timeout
1533 case CMixerControlProtocol::TIMEOUT:
1534 m_mixerInput.push_front(m_decodedPics.front());
1535 m_decodedPics.pop();
1536 if (m_mixerInput.size() < 2)
1538 m_state = M_TOP_CONFIGURED_WAIT1;
1546 m_state = M_TOP_CONFIGURED_WAIT1;
1547 m_extTimeout = 1000;
1550 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
1551 m_outputSurfaces.pop();
1552 m_config.stats->IncProcessed();
1553 m_config.stats->DecDecoded();
1554 m_dataPort.SendInMessage(CMixerDataProtocol::PICTURE,&m_processPicture,sizeof(m_processPicture));
1555 if (m_mixersteps > 1)
1557 m_state = M_TOP_CONFIGURED_WAIT2;
1563 m_state = M_TOP_CONFIGURED_WAIT1;
1573 case M_TOP_CONFIGURED_WAIT2:
1574 if (port == NULL) // timeout
1578 case CMixerControlProtocol::TIMEOUT:
1579 if (!m_outputSurfaces.empty())
1581 m_state = M_TOP_CONFIGURED_STEP2;
1582 m_bStateMachineSelfTrigger = true;
1595 case M_TOP_CONFIGURED_STEP2:
1596 if (port == NULL) // timeout
1600 case CMixerControlProtocol::TIMEOUT:
1601 m_processPicture.outputSurface = m_outputSurfaces.front();
1606 m_state = M_TOP_CONFIGURED_WAIT1;
1607 m_extTimeout = 1000;
1610 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
1611 m_outputSurfaces.pop();
1612 m_config.stats->IncProcessed();
1613 m_dataPort.SendInMessage(CMixerDataProtocol::PICTURE,&m_processPicture,sizeof(m_processPicture));
1615 m_state = M_TOP_CONFIGURED_WAIT1;
1624 default: // we are in no state, should not happen
1625 CLog::Log(LOGERROR, "CMixer::%s - no valid state: %d", __FUNCTION__, m_state);
1631 void CMixer::Process()
1633 Message *msg = NULL;
1634 Protocol *port = NULL;
1637 m_state = M_TOP_UNCONFIGURED;
1638 m_extTimeout = 1000;
1639 m_bStateMachineSelfTrigger = false;
1645 if (m_bStateMachineSelfTrigger)
1647 m_bStateMachineSelfTrigger = false;
1648 // self trigger state machine
1649 StateMachine(msg->signal, port, msg);
1650 if (!m_bStateMachineSelfTrigger)
1657 // check control port
1658 else if (m_controlPort.ReceiveOutMessage(&msg))
1661 port = &m_controlPort;
1664 else if (m_dataPort.ReceiveOutMessage(&msg))
1672 StateMachine(msg->signal, port, msg);
1673 if (!m_bStateMachineSelfTrigger)
1682 else if (m_outMsgEvent.WaitMSec(m_extTimeout))
1689 msg = m_controlPort.GetMessage();
1690 msg->signal = CMixerControlProtocol::TIMEOUT;
1692 // signal timeout to state machine
1693 StateMachine(msg->signal, port, msg);
1694 if (!m_bStateMachineSelfTrigger)
1704 void CMixer::CreateVdpauMixer()
1706 CLog::Log(LOGNOTICE, " (VDPAU) Creating the video mixer");
1708 InitCSCMatrix(m_config.vidWidth);
1710 VdpVideoMixerParameter parameters[] = {
1711 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
1712 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
1713 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE};
1715 void const * parameter_values[] = {
1716 &m_config.surfaceWidth,
1717 &m_config.surfaceHeight,
1718 &m_config.vdpChromaType};
1720 VdpStatus vdp_st = VDP_STATUS_ERROR;
1721 vdp_st = m_config.context->GetProcs().vdp_video_mixer_create(m_config.context->GetDevice(),
1722 m_config.context->GetFeatureCount(),
1723 m_config.context->GetFeatures(),
1728 CheckStatus(vdp_st, __LINE__);
1732 void CMixer::InitCSCMatrix(int Width)
1734 m_Procamp.struct_version = VDP_PROCAMP_VERSION;
1735 m_Procamp.brightness = 0.0;
1736 m_Procamp.contrast = 1.0;
1737 m_Procamp.saturation = 1.0;
1741 void CMixer::CheckFeatures()
1743 if (m_Upscale != m_config.upscale)
1746 m_Upscale = m_config.upscale;
1748 if (m_Brightness != CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness ||
1749 m_Contrast != CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast ||
1750 m_ColorMatrix != m_mixerInput[1].DVDPic.color_matrix)
1753 m_Brightness = CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness;
1754 m_Contrast = CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast;
1755 m_ColorMatrix = m_mixerInput[1].DVDPic.color_matrix;
1757 if (m_NoiseReduction != CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction)
1759 m_NoiseReduction = CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction;
1760 SetNoiseReduction();
1762 if (m_Sharpness != CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness)
1764 m_Sharpness = CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness;
1767 if (m_DeintMode != CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode ||
1768 m_Deint != CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod)
1770 m_DeintMode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1771 m_Deint = CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod;
1776 void CMixer::SetPostProcFeatures(bool postProcEnabled)
1778 if (m_PostProc != postProcEnabled)
1780 if (postProcEnabled)
1782 SetNoiseReduction();
1789 m_PostProc = postProcEnabled;
1793 void CMixer::PostProcOff()
1797 if (m_videoMixer == VDP_INVALID_HANDLE)
1800 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL,
1801 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL,
1802 VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE};
1804 VdpBool enabled[]={0,0,0};
1805 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1806 CheckStatus(vdp_st, __LINE__);
1808 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION))
1810 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION};
1812 VdpBool enabled[]={0};
1813 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1814 CheckStatus(vdp_st, __LINE__);
1817 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_SHARPNESS))
1819 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_SHARPNESS};
1821 VdpBool enabled[]={0};
1822 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1823 CheckStatus(vdp_st, __LINE__);
1829 bool CMixer::GenerateStudioCSCMatrix(VdpColorStandard colorStandard, VdpCSCMatrix &studioCSCMatrix)
1831 // instead use studioCSCKCoeffs601[3], studioCSCKCoeffs709[3] to generate float[3][4] matrix (float studioCSC[3][4])
1832 // m00 = mRY = red: luma factor (contrast factor) (1.0)
1833 // m10 = mGY = green: luma factor (contrast factor) (1.0)
1834 // m20 = mBY = blue: luma factor (contrast factor) (1.0)
1836 // m01 = mRB = red: blue color diff coeff (0.0)
1837 // m11 = mGB = green: blue color diff coeff (-2Kb(1-Kb)/(Kg))
1838 // m21 = mBB = blue: blue color diff coeff ((1-Kb)/0.5)
1840 // m02 = mRR = red: red color diff coeff ((1-Kr)/0.5)
1841 // m12 = mGR = green: red color diff coeff (-2Kr(1-Kr)/(Kg))
1842 // m22 = mBR = blue: red color diff coeff (0.0)
1844 // m03 = mRC = red: colour zero offset (brightness factor) (-(1-Kr)/0.5 * (128/255))
1845 // m13 = mGC = green: colour zero offset (brightness factor) ((256/255) * (Kb(1-Kb) + Kr(1-Kr)) / Kg)
1846 // m23 = mBC = blue: colour zero offset (brightness factor) (-(1-Kb)/0.5 * (128/255))
1857 // colour standard coefficients for red, geen, blue
1859 // colour diff zero position (use standard 8-bit coding precision)
1860 double CDZ = 128; //256*0.5
1861 // range excursion (use standard 8-bit coding precision)
1862 double EXC = 255; //256-1
1864 if (colorStandard == VDP_COLOR_STANDARD_ITUR_BT_601)
1866 Kr = studioCSCKCoeffs601[0];
1867 Kg = studioCSCKCoeffs601[1];
1868 Kb = studioCSCKCoeffs601[2];
1870 else // assume VDP_COLOR_STANDARD_ITUR_BT_709
1872 Kr = studioCSCKCoeffs709[0];
1873 Kg = studioCSCKCoeffs709[1];
1874 Kb = studioCSCKCoeffs709[2];
1876 // we keep luma unscaled to retain the levels present in source so that 16-235 luma is converted to RGB 16-235
1877 studioCSCMatrix[R][Y] = 1.0;
1878 studioCSCMatrix[G][Y] = 1.0;
1879 studioCSCMatrix[B][Y] = 1.0;
1881 studioCSCMatrix[R][Cb] = 0.0;
1882 studioCSCMatrix[G][Cb] = (double)-2 * Kb * (1 - Kb) / Kg;
1883 studioCSCMatrix[B][Cb] = (double)(1 - Kb) / 0.5;
1885 studioCSCMatrix[R][Cr] = (double)(1 - Kr) / 0.5;
1886 studioCSCMatrix[G][Cr] = (double)-2 * Kr * (1 - Kr) / Kg;
1887 studioCSCMatrix[B][Cr] = 0.0;
1889 studioCSCMatrix[R][C] = (double)-1 * studioCSCMatrix[R][Cr] * CDZ/EXC;
1890 studioCSCMatrix[G][C] = (double)-1 * (studioCSCMatrix[G][Cb] + studioCSCMatrix[G][Cr]) * CDZ/EXC;
1891 studioCSCMatrix[B][C] = (double)-1 * studioCSCMatrix[B][Cb] * CDZ/EXC;
1896 void CMixer::SetColor()
1900 if (m_Brightness != CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness)
1901 m_Procamp.brightness = (float)((CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness)-50) / 100;
1902 if (m_Contrast != CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast)
1903 m_Procamp.contrast = (float)((CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast)+50) / 100;
1905 VdpColorStandard colorStandard;
1906 switch(m_mixerInput[1].DVDPic.color_matrix)
1908 case AVCOL_SPC_BT709:
1909 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_709;
1911 case AVCOL_SPC_BT470BG:
1912 case AVCOL_SPC_SMPTE170M:
1913 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_601;
1915 case AVCOL_SPC_SMPTE240M:
1916 colorStandard = VDP_COLOR_STANDARD_SMPTE_240M;
1919 case AVCOL_SPC_UNSPECIFIED:
1922 if(m_config.surfaceWidth > 1000)
1923 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_709;
1925 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_601;
1928 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX };
1929 if (CSettings::Get().GetBool("videoscreen.limitedrange"))
1931 float studioCSC[3][4];
1932 GenerateStudioCSCMatrix(colorStandard, studioCSC);
1933 void const * pm_CSCMatix[] = { &studioCSC };
1934 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
1938 vdp_st = m_config.context->GetProcs().vdp_generate_csc_matrix(&m_Procamp, colorStandard, &m_CSCMatrix);
1939 void const * pm_CSCMatix[] = { &m_CSCMatrix };
1940 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
1943 CheckStatus(vdp_st, __LINE__);
1946 void CMixer::SetNoiseReduction()
1948 if(!m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION))
1951 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION };
1952 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL };
1955 if (!CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction)
1957 VdpBool enabled[]= {0};
1958 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1959 CheckStatus(vdp_st, __LINE__);
1962 VdpBool enabled[]={1};
1963 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1964 CheckStatus(vdp_st, __LINE__);
1965 void* nr[] = { &CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction };
1966 CLog::Log(LOGNOTICE,"Setting Noise Reduction to %f",CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction);
1967 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, nr);
1968 CheckStatus(vdp_st, __LINE__);
1971 void CMixer::SetSharpness()
1973 if(!m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_SHARPNESS))
1976 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_SHARPNESS };
1977 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL };
1980 if (!CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness)
1982 VdpBool enabled[]={0};
1983 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1984 CheckStatus(vdp_st, __LINE__);
1987 VdpBool enabled[]={1};
1988 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1989 CheckStatus(vdp_st, __LINE__);
1990 void* sh[] = { &CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness };
1991 CLog::Log(LOGNOTICE,"Setting Sharpness to %f",CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness);
1992 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, sh);
1993 CheckStatus(vdp_st, __LINE__);
1996 EINTERLACEMETHOD CMixer::GetDeinterlacingMethod(bool log /* = false */)
1998 EINTERLACEMETHOD method = CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod;
1999 if (method == VS_INTERLACEMETHOD_AUTO)
2002 // if (m_config.outHeight >= 720)
2003 // deint = g_advancedSettings.m_videoVDPAUdeintHD;
2005 // deint = g_advancedSettings.m_videoVDPAUdeintSD;
2009 if (m_config.vdpau->Supports(EINTERLACEMETHOD(deint)))
2011 method = EINTERLACEMETHOD(deint);
2013 CLog::Log(LOGNOTICE, "CVDPAU::GetDeinterlacingMethod: set de-interlacing to %d", deint);
2018 CLog::Log(LOGWARNING, "CVDPAU::GetDeinterlacingMethod: method for de-interlacing (advanced settings) not supported");
2025 void CMixer::SetDeinterlacing()
2029 if (m_videoMixer == VDP_INVALID_HANDLE)
2032 EDEINTERLACEMODE mode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
2033 EINTERLACEMETHOD method = GetDeinterlacingMethod(true);
2035 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL,
2036 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL,
2037 VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE };
2039 if (mode == VS_DEINTERLACEMODE_OFF)
2041 VdpBool enabled[] = {0,0,0};
2042 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2046 if (method == VS_INTERLACEMETHOD_AUTO)
2048 VdpBool enabled[] = {1,0,0};
2049 if (g_advancedSettings.m_videoVDPAUtelecine)
2051 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2053 else if (method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL
2054 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF)
2056 VdpBool enabled[] = {1,0,0};
2057 if (g_advancedSettings.m_videoVDPAUtelecine)
2059 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2061 else if (method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL
2062 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF)
2064 VdpBool enabled[] = {1,1,0};
2065 if (g_advancedSettings.m_videoVDPAUtelecine)
2067 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2071 VdpBool enabled[]={0,0,0};
2072 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2075 CheckStatus(vdp_st, __LINE__);
2077 SetDeintSkipChroma();
2079 m_config.useInteropYuv = !CSettings::Get().GetBool("videoplayer.usevdpaumixer");
2082 void CMixer::SetDeintSkipChroma()
2084 VdpVideoMixerAttribute attribute[] = { VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE};
2088 if (g_advancedSettings.m_videoVDPAUdeintSkipChromaHD && m_config.outHeight >= 720)
2093 void const *values[]={&val};
2094 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attribute), attribute, values);
2096 CheckStatus(vdp_st, __LINE__);
2099 void CMixer::SetHWUpscaling()
2101 #ifdef VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
2104 VdpBool enabled[]={1};
2105 switch (m_config.upscale)
2108 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9))
2110 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9 };
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_L8))
2117 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8 };
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_L7))
2124 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7 };
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_L6))
2131 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6 };
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_L5))
2138 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5 };
2139 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2143 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4))
2145 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4 };
2146 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2150 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3))
2152 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3 };
2153 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2157 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2))
2159 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2 };
2160 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2164 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1))
2166 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 };
2167 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2174 CheckStatus(vdp_st, __LINE__);
2178 void CMixer::DisableHQScaling()
2182 if (m_videoMixer == VDP_INVALID_HANDLE)
2185 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1))
2187 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 };
2188 VdpBool enabled[]={0};
2189 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2190 CheckStatus(vdp_st, __LINE__);
2193 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2))
2195 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2 };
2196 VdpBool enabled[]={0};
2197 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2198 CheckStatus(vdp_st, __LINE__);
2201 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3))
2203 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3 };
2204 VdpBool enabled[]={0};
2205 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2206 CheckStatus(vdp_st, __LINE__);
2209 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4))
2211 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4 };
2212 VdpBool enabled[]={0};
2213 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2214 CheckStatus(vdp_st, __LINE__);
2217 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5))
2219 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5 };
2220 VdpBool enabled[]={0};
2221 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2222 CheckStatus(vdp_st, __LINE__);
2225 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6))
2227 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6 };
2228 VdpBool enabled[]={0};
2229 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2230 CheckStatus(vdp_st, __LINE__);
2233 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7))
2235 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7 };
2236 VdpBool enabled[]={0};
2237 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2238 CheckStatus(vdp_st, __LINE__);
2241 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8))
2243 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8 };
2244 VdpBool enabled[]={0};
2245 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2246 CheckStatus(vdp_st, __LINE__);
2249 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9))
2251 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9 };
2252 VdpBool enabled[]={0};
2253 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2254 CheckStatus(vdp_st, __LINE__);
2262 m_NoiseReduction = 0.0;
2267 m_SeenInterlaceFlag = false;
2272 m_config.upscale = g_advancedSettings.m_videoVDPAUScaling;
2273 m_config.useInteropYuv = !CSettings::Get().GetBool("videoplayer.usevdpaumixer");
2278 void CMixer::Uninit()
2281 while (!m_outputSurfaces.empty())
2283 m_outputSurfaces.pop();
2285 m_config.context->GetProcs().vdp_video_mixer_destroy(m_videoMixer);
2288 void CMixer::Flush()
2290 while (!m_mixerInput.empty())
2292 CVdpauDecodedPicture pic = m_mixerInput.back();
2293 m_mixerInput.pop_back();
2294 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2296 while (!m_decodedPics.empty())
2298 CVdpauDecodedPicture pic = m_decodedPics.front();
2299 m_decodedPics.pop();
2300 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2303 while (m_dataPort.ReceiveOutMessage(&msg))
2305 if (msg->signal == CMixerDataProtocol::FRAME)
2307 CVdpauDecodedPicture pic = *(CVdpauDecodedPicture*)msg->data;
2308 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2310 else if (msg->signal == CMixerDataProtocol::BUFFER)
2312 VdpOutputSurface *surf;
2313 surf = (VdpOutputSurface*)msg->data;
2314 m_outputSurfaces.push(*surf);
2320 void CMixer::InitCycle()
2325 m_config.stats->GetParams(latency, flags);
2327 if (0) //flags & DVP_FLAG_NO_POSTPROC)
2328 SetPostProcFeatures(false);
2330 SetPostProcFeatures(true);
2332 m_config.stats->SetCanSkipDeint(false);
2334 EDEINTERLACEMODE mode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
2335 EINTERLACEMETHOD method = GetDeinterlacingMethod();
2336 bool interlaced = m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_INTERLACED;
2337 m_SeenInterlaceFlag |= interlaced;
2340 if (//!(flags & DVP_FLAG_NO_POSTPROC) &&
2341 (mode == VS_DEINTERLACEMODE_FORCE ||
2342 (mode == VS_DEINTERLACEMODE_AUTO && interlaced)))
2344 if((method == VS_INTERLACEMETHOD_AUTO && interlaced)
2345 || method == VS_INTERLACEMETHOD_VDPAU_BOB
2346 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL
2347 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF
2348 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL
2349 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF
2350 || method == VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE )
2352 if(method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF
2353 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF
2354 || !g_graphicsContext.IsFullScreenVideo())
2359 m_config.stats->SetCanSkipDeint(true);
2363 if (0) //m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_DROPDEINT)
2368 if(m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_TOP_FIELD_FIRST)
2369 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
2371 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
2373 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2374 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2375 DVP_FLAG_REPEAT_TOP_FIELD |
2376 DVP_FLAG_INTERLACED);
2377 m_config.useInteropYuv = false;
2379 else if (method == VS_INTERLACEMETHOD_RENDER_BOB)
2382 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2383 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU_420;
2384 m_config.useInteropYuv = true;
2388 CLog::Log(LOGERROR, "CMixer::%s - interlace method: %d not supported, setting to AUTO", __FUNCTION__, method);
2390 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2391 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2392 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2393 DVP_FLAG_REPEAT_TOP_FIELD |
2394 DVP_FLAG_INTERLACED);
2396 CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod = VS_INTERLACEMETHOD_AUTO;
2402 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2404 if (m_config.useInteropYuv)
2405 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU_420;
2408 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2409 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2410 DVP_FLAG_REPEAT_TOP_FIELD |
2411 DVP_FLAG_INTERLACED);
2416 m_processPicture.crop = false;
2417 if (m_mixerInput[1].DVDPic.format == RENDER_FMT_VDPAU)
2419 m_processPicture.outputSurface = m_outputSurfaces.front();
2420 m_mixerInput[1].DVDPic.iWidth = m_config.outWidth;
2421 m_mixerInput[1].DVDPic.iHeight = m_config.outHeight;
2422 if (m_SeenInterlaceFlag)
2424 double ratio = (double)m_mixerInput[1].DVDPic.iDisplayHeight / m_mixerInput[1].DVDPic.iHeight;
2425 m_mixerInput[1].DVDPic.iDisplayHeight = lrint(ratio*(m_mixerInput[1].DVDPic.iHeight-NUM_CROP_PIX*2));
2426 m_processPicture.crop = true;
2431 m_mixerInput[1].DVDPic.iWidth = m_config.vidWidth;
2432 m_mixerInput[1].DVDPic.iHeight = m_config.vidHeight;
2435 m_processPicture.DVDPic = m_mixerInput[1].DVDPic;
2436 m_processPicture.videoSurface = m_mixerInput[1].videoSurface;
2439 void CMixer::FiniCycle()
2441 // Keep video surfaces for one 2 cycles longer than used
2442 // by mixer. This avoids blocking in decoder.
2443 // NVidia recommends num_ref + 5
2444 while (m_mixerInput.size() > 5)
2446 CVdpauDecodedPicture &tmp = m_mixerInput.back();
2447 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
2449 m_config.videoSurfaces->ClearRender(tmp.videoSurface);
2451 m_mixerInput.pop_back();
2455 void CMixer::ProcessPicture()
2457 if (m_processPicture.DVDPic.format == RENDER_FMT_VDPAU_420)
2462 if (m_mixerstep == 1)
2464 if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD)
2465 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
2467 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
2470 VdpVideoSurface past_surfaces[4] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
2471 VdpVideoSurface futu_surfaces[2] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
2472 uint32_t pastCount = 4;
2473 uint32_t futuCount = 2;
2475 if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME)
2477 // use only 2 past 1 future for progressive/weave
2478 // (only used for postproc anyway eg noise reduction)
2479 if (m_mixerInput.size() > 3)
2480 past_surfaces[1] = m_mixerInput[3].videoSurface;
2481 if (m_mixerInput.size() > 2)
2482 past_surfaces[0] = m_mixerInput[2].videoSurface;
2483 futu_surfaces[0] = m_mixerInput[0].videoSurface;
2489 if(m_mixerstep == 0)
2491 if (m_mixerInput.size() > 3)
2493 past_surfaces[3] = m_mixerInput[3].videoSurface;
2494 past_surfaces[2] = m_mixerInput[3].videoSurface;
2496 if (m_mixerInput.size() > 2)
2498 past_surfaces[1] = m_mixerInput[2].videoSurface;
2499 past_surfaces[0] = m_mixerInput[2].videoSurface;
2501 futu_surfaces[0] = m_mixerInput[1].videoSurface;
2502 futu_surfaces[1] = m_mixerInput[0].videoSurface;
2506 if (m_mixerInput.size() > 3)
2508 past_surfaces[3] = m_mixerInput[3].videoSurface;
2510 if (m_mixerInput.size() > 2)
2512 past_surfaces[2] = m_mixerInput[2].videoSurface;
2513 past_surfaces[1] = m_mixerInput[2].videoSurface;
2515 past_surfaces[0] = m_mixerInput[1].videoSurface;
2516 futu_surfaces[0] = m_mixerInput[0].videoSurface;
2517 futu_surfaces[1] = m_mixerInput[0].videoSurface;
2519 if (m_mixerInput[0].DVDPic.pts != DVD_NOPTS_VALUE &&
2520 m_mixerInput[1].DVDPic.pts != DVD_NOPTS_VALUE)
2522 m_processPicture.DVDPic.pts = m_mixerInput[1].DVDPic.pts +
2523 (m_mixerInput[0].DVDPic.pts -
2524 m_mixerInput[1].DVDPic.pts) / 2;
2527 m_processPicture.DVDPic.pts = DVD_NOPTS_VALUE;
2528 m_processPicture.DVDPic.dts = DVD_NOPTS_VALUE;
2530 m_processPicture.DVDPic.iRepeatPicture = 0.0;
2536 sourceRect.x1 = m_config.vidWidth;
2537 sourceRect.y1 = m_config.vidHeight;
2542 destRect.x1 = m_config.outWidth;
2543 destRect.y1 = m_config.outHeight;
2545 // start vdpau video mixer
2546 vdp_st = m_config.context->GetProcs().vdp_video_mixer_render(m_videoMixer,
2552 m_mixerInput[1].videoSurface,
2556 m_processPicture.outputSurface,
2561 CheckStatus(vdp_st, __LINE__);
2565 bool CMixer::CheckStatus(VdpStatus vdp_st, int line)
2567 if (vdp_st != VDP_STATUS_OK)
2569 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);
2576 //-----------------------------------------------------------------------------
2578 //-----------------------------------------------------------------------------
2580 VdpauBufferPool::VdpauBufferPool()
2582 CVdpauRenderPicture *pic;
2583 for (unsigned int i = 0; i < NUM_RENDER_PICS; i++)
2585 pic = new CVdpauRenderPicture(renderPicSec);
2586 allRenderPics.push_back(pic);
2590 VdpauBufferPool::~VdpauBufferPool()
2592 CVdpauRenderPicture *pic;
2593 for (unsigned int i = 0; i < NUM_RENDER_PICS; i++)
2595 pic = allRenderPics[i];
2598 allRenderPics.clear();
2601 //-----------------------------------------------------------------------------
2603 //-----------------------------------------------------------------------------
2604 COutput::COutput(CEvent *inMsgEvent) :
2605 CThread("Vdpau Output"),
2606 m_controlPort("OutputControlPort", inMsgEvent, &m_outMsgEvent),
2607 m_dataPort("OutputDataPort", inMsgEvent, &m_outMsgEvent),
2608 m_mixer(&m_outMsgEvent)
2610 m_inMsgEvent = inMsgEvent;
2612 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); ++i)
2614 m_bufferPool.freeRenderPics.push_back(i);
2618 void COutput::Start()
2627 m_bufferPool.freeRenderPics.clear();
2628 m_bufferPool.usedRenderPics.clear();
2631 void COutput::Dispose()
2633 CSingleLock lock(g_graphicsContext);
2635 m_outMsgEvent.Set();
2637 m_controlPort.Purge();
2641 void COutput::OnStartup()
2643 CLog::Log(LOGNOTICE, "COutput::OnStartup: Output Thread created");
2646 void COutput::OnExit()
2648 CLog::Log(LOGNOTICE, "COutput::OnExit: Output Thread terminated");
2655 O_TOP_UNCONFIGURED, // 2
2656 O_TOP_CONFIGURED, // 3
2657 O_TOP_CONFIGURED_IDLE, // 4
2658 O_TOP_CONFIGURED_WORK, // 5
2661 int VDPAU_OUTPUT_parentStates[] = {
2664 0, //TOP_UNCONFIGURED
2666 3, //TOP_CONFIGURED_IDLE
2667 3, //TOP_CONFIGURED_WORK
2670 void COutput::StateMachine(int signal, Protocol *port, Message *msg)
2672 for (int state = m_state; ; state = VDPAU_OUTPUT_parentStates[state])
2677 if (port == &m_controlPort)
2681 case COutputControlProtocol::FLUSH:
2682 msg->Reply(COutputControlProtocol::ACC);
2684 case COutputControlProtocol::PRECLEANUP:
2685 msg->Reply(COutputControlProtocol::ACC);
2691 else if (port == &m_dataPort)
2695 case COutputDataProtocol::RETURNPIC:
2696 CVdpauRenderPicture *pic;
2697 pic = *((CVdpauRenderPicture**)msg->data);
2698 QueueReturnPicture(pic);
2705 std::string portName = port == NULL ? "timer" : port->portName;
2706 CLog::Log(LOGWARNING, "COutput::%s - signal: %d form port: %s not handled for state: %d", __FUNCTION__, signal, portName.c_str(), m_state);
2713 case O_TOP_UNCONFIGURED:
2714 if (port == &m_controlPort)
2718 case COutputControlProtocol::INIT:
2720 data = (CVdpauConfig*)msg->data;
2727 if (m_mixer.m_controlPort.SendOutMessageSync(CMixerControlProtocol::INIT,
2728 &reply, 1000, &m_config, sizeof(m_config)))
2730 if (reply->signal != CMixerControlProtocol::ACC)
2735 // set initial number of
2736 m_bufferPool.numOutputSurfaces = 4;
2740 m_state = O_TOP_CONFIGURED_IDLE;
2741 msg->Reply(COutputControlProtocol::ACC, &m_config, sizeof(m_config));
2745 m_state = O_TOP_ERROR;
2746 msg->Reply(COutputControlProtocol::ERROR);
2755 case O_TOP_CONFIGURED:
2756 if (port == &m_controlPort)
2760 case COutputControlProtocol::FLUSH:
2762 msg->Reply(COutputControlProtocol::ACC);
2764 case COutputControlProtocol::PRECLEANUP:
2767 msg->Reply(COutputControlProtocol::ACC);
2773 else if (port == &m_dataPort)
2777 case COutputDataProtocol::NEWFRAME:
2778 CVdpauDecodedPicture *frame;
2779 frame = (CVdpauDecodedPicture*)msg->data;
2782 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::FRAME,
2783 frame,sizeof(CVdpauDecodedPicture));
2786 case COutputDataProtocol::RETURNPIC:
2787 CVdpauRenderPicture *pic;
2788 pic = *((CVdpauRenderPicture**)msg->data);
2789 QueueReturnPicture(pic);
2790 m_controlPort.SendInMessage(COutputControlProtocol::STATS);
2791 m_state = O_TOP_CONFIGURED_WORK;
2798 else if (port == &m_mixer.m_dataPort)
2802 case CMixerDataProtocol::PICTURE:
2803 CVdpauProcessedPicture *pic;
2804 pic = (CVdpauProcessedPicture*)msg->data;
2805 m_bufferPool.processedPics.push(*pic);
2806 m_state = O_TOP_CONFIGURED_WORK;
2815 case O_TOP_CONFIGURED_IDLE:
2816 if (port == NULL) // timeout
2820 case COutputControlProtocol::TIMEOUT:
2821 if (ProcessSyncPicture())
2827 m_state = O_TOP_CONFIGURED_WORK;
2837 case O_TOP_CONFIGURED_WORK:
2838 if (port == NULL) // timeout
2842 case COutputControlProtocol::TIMEOUT:
2845 CVdpauRenderPicture *pic;
2846 pic = ProcessMixerPicture();
2849 m_config.stats->DecProcessed();
2850 m_config.stats->IncRender();
2851 m_dataPort.SendInMessage(COutputDataProtocol::PICTURE, &pic, sizeof(pic));
2857 m_state = O_TOP_CONFIGURED_IDLE;
2867 default: // we are in no state, should not happen
2868 CLog::Log(LOGERROR, "COutput::%s - no valid state: %d", __FUNCTION__, m_state);
2874 void COutput::Process()
2876 Message *msg = NULL;
2877 Protocol *port = NULL;
2880 m_state = O_TOP_UNCONFIGURED;
2881 m_extTimeout = 1000;
2882 m_bStateMachineSelfTrigger = false;
2888 if (m_bStateMachineSelfTrigger)
2890 m_bStateMachineSelfTrigger = false;
2891 // self trigger state machine
2892 StateMachine(msg->signal, port, msg);
2893 if (!m_bStateMachineSelfTrigger)
2900 // check control port
2901 else if (m_controlPort.ReceiveOutMessage(&msg))
2904 port = &m_controlPort;
2907 else if (m_dataPort.ReceiveOutMessage(&msg))
2912 // check mixer data port
2913 else if (m_mixer.m_dataPort.ReceiveInMessage(&msg))
2916 port = &m_mixer.m_dataPort;
2920 StateMachine(msg->signal, port, msg);
2921 if (!m_bStateMachineSelfTrigger)
2930 else if (m_outMsgEvent.WaitMSec(m_extTimeout))
2937 msg = m_controlPort.GetMessage();
2938 msg->signal = COutputControlProtocol::TIMEOUT;
2940 // signal timeout to state machine
2941 StateMachine(msg->signal, port, msg);
2942 if (!m_bStateMachineSelfTrigger)
2953 bool COutput::Init()
2955 if (!CreateGlxContext())
2967 bool COutput::Uninit()
2971 while(ProcessSyncPicture())
2976 ReleaseBufferPool();
2977 DestroyGlxContext();
2981 void COutput::Flush()
2983 if (m_mixer.IsActive())
2986 if (m_mixer.m_controlPort.SendOutMessageSync(CMixerControlProtocol::FLUSH,
2993 CLog::Log(LOGERROR, "Coutput::%s - failed to flush mixer", __FUNCTION__);
2997 while (m_mixer.m_dataPort.ReceiveInMessage(&msg))
2999 if (msg->signal == CMixerDataProtocol::PICTURE)
3001 CVdpauProcessedPicture pic = *(CVdpauProcessedPicture*)msg->data;
3002 m_bufferPool.processedPics.push(pic);
3007 while (m_dataPort.ReceiveOutMessage(&msg))
3009 if (msg->signal == COutputDataProtocol::NEWFRAME)
3011 CVdpauDecodedPicture pic = *(CVdpauDecodedPicture*)msg->data;
3012 m_config.videoSurfaces->ClearRender(pic.videoSurface);
3014 else if (msg->signal == COutputDataProtocol::RETURNPIC)
3016 CVdpauRenderPicture *pic;
3017 pic = *((CVdpauRenderPicture**)msg->data);
3018 QueueReturnPicture(pic);
3023 while (m_dataPort.ReceiveInMessage(&msg))
3025 if (msg->signal == COutputDataProtocol::PICTURE)
3027 CVdpauRenderPicture *pic;
3028 pic = *((CVdpauRenderPicture**)msg->data);
3029 QueueReturnPicture(pic);
3033 // reset used render flag which was cleared on mixer flush
3034 std::deque<int>::iterator it;
3035 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3037 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[*it];
3038 if (pic->DVDPic.format == RENDER_FMT_VDPAU_420)
3040 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it2;
3041 it2 = m_bufferPool.glVideoSurfaceMap.find(pic->sourceIdx);
3042 if (it2 == m_bufferPool.glVideoSurfaceMap.end())
3044 CLog::Log(LOGDEBUG, "COutput::Flush - gl surface not found");
3047 m_config.videoSurfaces->MarkRender(it2->second.sourceVuv);
3051 // clear processed pics
3052 while(!m_bufferPool.processedPics.empty())
3054 CVdpauProcessedPicture procPic = m_bufferPool.processedPics.front();
3055 if (procPic.DVDPic.format == RENDER_FMT_VDPAU)
3057 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER, &procPic.outputSurface, sizeof(procPic.outputSurface));
3059 else if (procPic.DVDPic.format == RENDER_FMT_VDPAU_420)
3061 m_config.videoSurfaces->ClearRender(procPic.videoSurface);
3063 m_bufferPool.processedPics.pop();
3067 bool COutput::HasWork()
3069 if (!m_bufferPool.processedPics.empty() && !m_bufferPool.freeRenderPics.empty())
3074 CVdpauRenderPicture* COutput::ProcessMixerPicture()
3076 CVdpauRenderPicture *retPic = NULL;
3078 if (!m_bufferPool.processedPics.empty() && !m_bufferPool.freeRenderPics.empty())
3080 int idx = m_bufferPool.freeRenderPics.front();
3081 retPic = m_bufferPool.allRenderPics[idx];
3082 m_bufferPool.freeRenderPics.pop_front();
3083 m_bufferPool.usedRenderPics.push_back(idx);
3084 CVdpauProcessedPicture procPic = m_bufferPool.processedPics.front();
3085 m_bufferPool.processedPics.pop();
3087 retPic->DVDPic = procPic.DVDPic;
3088 retPic->valid = true;
3089 if (retPic->DVDPic.format == RENDER_FMT_VDPAU)
3091 m_config.useInteropYuv = false;
3092 m_bufferPool.numOutputSurfaces = NUM_RENDER_PICS;
3094 GLMapSurface(false, procPic.outputSurface);
3095 retPic->sourceIdx = procPic.outputSurface;
3096 retPic->texture[0] = m_bufferPool.glOutputSurfaceMap[procPic.outputSurface].texture[0];
3097 retPic->texWidth = m_config.outWidth;
3098 retPic->texHeight = m_config.outHeight;
3099 retPic->crop.x1 = 0;
3100 retPic->crop.y1 = procPic.crop ? NUM_CROP_PIX : 0;
3101 retPic->crop.x2 = m_config.outWidth;
3102 retPic->crop.y2 = m_config.outHeight - retPic->crop.y1;
3106 m_config.useInteropYuv = true;
3107 GLMapSurface(true, procPic.videoSurface);
3108 retPic->sourceIdx = procPic.videoSurface;
3109 for (unsigned int i=0; i<4; ++i)
3110 retPic->texture[i] = m_bufferPool.glVideoSurfaceMap[procPic.videoSurface].texture[i];
3111 retPic->texWidth = m_config.surfaceWidth;
3112 retPic->texHeight = m_config.surfaceHeight;
3113 retPic->crop.x1 = 0;
3114 retPic->crop.y1 = 0;
3115 retPic->crop.x2 = m_config.surfaceWidth - m_config.vidWidth;
3116 retPic->crop.y2 = m_config.surfaceHeight - m_config.vidHeight;
3122 void COutput::QueueReturnPicture(CVdpauRenderPicture *pic)
3124 std::deque<int>::iterator it;
3125 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3127 if (m_bufferPool.allRenderPics[*it] == pic)
3133 if (it == m_bufferPool.usedRenderPics.end())
3135 CLog::Log(LOGWARNING, "COutput::QueueReturnPicture - pic not found");
3139 // check if already queued
3140 std::deque<int>::iterator it2 = find(m_bufferPool.syncRenderPics.begin(),
3141 m_bufferPool.syncRenderPics.end(),
3143 if (it2 == m_bufferPool.syncRenderPics.end())
3145 m_bufferPool.syncRenderPics.push_back(*it);
3148 ProcessSyncPicture();
3151 bool COutput::ProcessSyncPicture()
3153 CVdpauRenderPicture *pic;
3156 std::deque<int>::iterator it;
3157 for (it = m_bufferPool.syncRenderPics.begin(); it != m_bufferPool.syncRenderPics.end(); )
3159 pic = m_bufferPool.allRenderPics[*it];
3164 if (glIsSync(pic->fence))
3168 glGetSynciv(pic->fence, GL_SYNC_STATUS, 1, &length, &state);
3169 if(state == GL_SIGNALED)
3171 glDeleteSync(pic->fence);
3184 m_bufferPool.freeRenderPics.push_back(*it);
3186 std::deque<int>::iterator it2 = find(m_bufferPool.usedRenderPics.begin(),
3187 m_bufferPool.usedRenderPics.end(),
3189 if (it2 == m_bufferPool.usedRenderPics.end())
3191 CLog::Log(LOGERROR, "COutput::ProcessSyncPicture - pic not found in queue");
3195 m_bufferPool.usedRenderPics.erase(it2);
3197 it = m_bufferPool.syncRenderPics.erase(it);
3201 ProcessReturnPicture(pic);
3205 CLog::Log(LOGDEBUG, "COutput::%s - return of invalid render pic", __FUNCTION__);
3211 void COutput::ProcessReturnPicture(CVdpauRenderPicture *pic)
3213 if (pic->DVDPic.format == RENDER_FMT_VDPAU_420)
3215 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3216 it = m_bufferPool.glVideoSurfaceMap.find(pic->sourceIdx);
3217 if (it == m_bufferPool.glVideoSurfaceMap.end())
3219 CLog::Log(LOGDEBUG, "COutput::ProcessReturnPicture - gl surface not found");
3222 #ifdef GL_NV_vdpau_interop
3223 glVDPAUUnmapSurfacesNV(1, &(it->second.glVdpauSurface));
3225 VdpVideoSurface surf = it->second.sourceVuv;
3226 m_config.videoSurfaces->ClearRender(surf);
3228 else if (pic->DVDPic.format == RENDER_FMT_VDPAU)
3230 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3231 it = m_bufferPool.glOutputSurfaceMap.find(pic->sourceIdx);
3232 if (it == m_bufferPool.glOutputSurfaceMap.end())
3234 CLog::Log(LOGDEBUG, "COutput::ProcessReturnPicture - gl surface not found");
3237 #ifdef GL_NV_vdpau_interop
3238 glVDPAUUnmapSurfacesNV(1, &(it->second.glVdpauSurface));
3240 VdpOutputSurface outSurf = it->second.sourceRgb;
3241 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER, &outSurf, sizeof(outSurf));
3245 bool COutput::EnsureBufferPool()
3249 // Creation of outputSurfaces
3250 VdpOutputSurface outputSurface;
3251 for (int i = m_bufferPool.outputSurfaces.size(); i < m_bufferPool.numOutputSurfaces; i++)
3253 vdp_st = m_config.context->GetProcs().vdp_output_surface_create(m_config.context->GetDevice(),
3254 VDP_RGBA_FORMAT_B8G8R8A8,
3258 if (CheckStatus(vdp_st, __LINE__))
3260 m_bufferPool.outputSurfaces.push_back(outputSurface);
3262 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER,
3264 sizeof(VdpOutputSurface));
3265 CLog::Log(LOGNOTICE, "VDPAU::COutput::InitBufferPool - Output Surface created");
3270 void COutput::ReleaseBufferPool()
3274 CSingleLock lock(m_bufferPool.renderPicSec);
3276 // release all output surfaces
3277 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3279 if (m_bufferPool.outputSurfaces[i] == VDP_INVALID_HANDLE)
3281 vdp_st = m_config.context->GetProcs().vdp_output_surface_destroy(m_bufferPool.outputSurfaces[i]);
3282 CheckStatus(vdp_st, __LINE__);
3284 m_bufferPool.outputSurfaces.clear();
3286 // wait for all fences
3287 XbmcThreads::EndTime timeout(1000);
3288 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); i++)
3290 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[i];
3294 while (glIsSync(pic->fence))
3298 glGetSynciv(pic->fence, GL_SYNC_STATUS, 1, &length, &state);
3299 if(state == GL_SIGNALED || timeout.IsTimePast())
3301 glDeleteSync(pic->fence);
3312 if (timeout.IsTimePast())
3314 CLog::Log(LOGERROR, "COutput::%s - timeout waiting for fence", __FUNCTION__);
3316 ProcessSyncPicture();
3318 // invalidate all used render pictures
3319 for (unsigned int i = 0; i < m_bufferPool.usedRenderPics.size(); ++i)
3321 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[m_bufferPool.usedRenderPics[i]];
3326 void COutput::PreCleanup()
3332 ProcessSyncPicture();
3334 CSingleLock lock(m_bufferPool.renderPicSec);
3335 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3337 if (m_bufferPool.outputSurfaces[i] == VDP_INVALID_HANDLE)
3340 // check if output surface is in use
3342 std::deque<int>::iterator it;
3343 CVdpauRenderPicture *pic;
3344 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3346 pic = m_bufferPool.allRenderPics[*it];
3347 if ((pic->sourceIdx == m_bufferPool.outputSurfaces[i]) && pic->valid)
3356 #ifdef GL_NV_vdpau_interop
3358 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it_map;
3359 it_map = m_bufferPool.glOutputSurfaceMap.find(m_bufferPool.outputSurfaces[i]);
3360 if (it_map == m_bufferPool.glOutputSurfaceMap.end())
3362 CLog::Log(LOGERROR, "%s - could not find gl surface", __FUNCTION__);
3365 glVDPAUUnregisterSurfaceNV(it_map->second.glVdpauSurface);
3366 glDeleteTextures(1, it_map->second.texture);
3367 m_bufferPool.glOutputSurfaceMap.erase(it_map);
3370 vdp_st = m_config.context->GetProcs().vdp_output_surface_destroy(m_bufferPool.outputSurfaces[i]);
3371 CheckStatus(vdp_st, __LINE__);
3373 m_bufferPool.outputSurfaces[i] = VDP_INVALID_HANDLE;
3375 CLog::Log(LOGDEBUG, "VDPAU::PreCleanup - released output surface");
3380 void COutput::InitMixer()
3382 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3384 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER,
3385 &m_bufferPool.outputSurfaces[i],
3386 sizeof(VdpOutputSurface));
3390 bool COutput::GLInit()
3392 #ifdef GL_NV_vdpau_interop
3393 glVDPAUInitNV = NULL;
3394 glVDPAUFiniNV = NULL;
3395 glVDPAURegisterOutputSurfaceNV = NULL;
3396 glVDPAURegisterVideoSurfaceNV = NULL;
3397 glVDPAUIsSurfaceNV = NULL;
3398 glVDPAUUnregisterSurfaceNV = NULL;
3399 glVDPAUSurfaceAccessNV = NULL;
3400 glVDPAUMapSurfacesNV = NULL;
3401 glVDPAUUnmapSurfacesNV = NULL;
3402 glVDPAUGetSurfaceivNV = NULL;
3405 #ifdef GL_NV_vdpau_interop
3407 glVDPAUInitNV = (PFNGLVDPAUINITNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUInitNV");
3409 glVDPAUFiniNV = (PFNGLVDPAUFININVPROC)glXGetProcAddress((GLubyte *) "glVDPAUFiniNV");
3410 if (!glVDPAURegisterOutputSurfaceNV)
3411 glVDPAURegisterOutputSurfaceNV = (PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAURegisterOutputSurfaceNV");
3412 if (!glVDPAURegisterVideoSurfaceNV)
3413 glVDPAURegisterVideoSurfaceNV = (PFNGLVDPAUREGISTERVIDEOSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAURegisterVideoSurfaceNV");
3414 if (!glVDPAUIsSurfaceNV)
3415 glVDPAUIsSurfaceNV = (PFNGLVDPAUISSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAUIsSurfaceNV");
3416 if (!glVDPAUUnregisterSurfaceNV)
3417 glVDPAUUnregisterSurfaceNV = (PFNGLVDPAUUNREGISTERSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAUUnregisterSurfaceNV");
3418 if (!glVDPAUSurfaceAccessNV)
3419 glVDPAUSurfaceAccessNV = (PFNGLVDPAUSURFACEACCESSNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUSurfaceAccessNV");
3420 if (!glVDPAUMapSurfacesNV)
3421 glVDPAUMapSurfacesNV = (PFNGLVDPAUMAPSURFACESNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUMapSurfacesNV");
3422 if (!glVDPAUUnmapSurfacesNV)
3423 glVDPAUUnmapSurfacesNV = (PFNGLVDPAUUNMAPSURFACESNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUUnmapSurfacesNV");
3424 if (!glVDPAUGetSurfaceivNV)
3425 glVDPAUGetSurfaceivNV = (PFNGLVDPAUGETSURFACEIVNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUGetSurfaceivNV");
3427 while (glGetError() != GL_NO_ERROR);
3428 glVDPAUInitNV(reinterpret_cast<void*>(m_config.context->GetDevice()), reinterpret_cast<void*>(m_config.context->GetProcs().vdp_get_proc_address));
3429 if (glGetError() != GL_NO_ERROR)
3431 CLog::Log(LOGERROR, "VDPAU::COutput - GLInitInterop glVDPAUInitNV failed");
3435 CLog::Log(LOGNOTICE, "VDPAU::COutput: vdpau gl interop initialized");
3439 bool hasfence = glewIsSupported("GL_ARB_sync");
3440 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); i++)
3442 m_bufferPool.allRenderPics[i]->usefence = hasfence;
3449 void COutput::GLMapSurface(bool yuv, uint32_t source)
3451 #ifdef GL_NV_vdpau_interop
3455 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3456 it = m_bufferPool.glVideoSurfaceMap.find(source);
3457 if (it == m_bufferPool.glVideoSurfaceMap.end())
3459 VdpauBufferPool::GLVideoSurface glSurface;
3460 VdpVideoSurface surf = source;
3462 if (surf == VDP_INVALID_HANDLE)
3465 glSurface.sourceVuv = surf;
3466 while (glGetError() != GL_NO_ERROR) ;
3467 glGenTextures(4, glSurface.texture);
3468 if (glGetError() != GL_NO_ERROR)
3470 CLog::Log(LOGERROR, "VDPAU::COutput error creating texture");
3473 glSurface.glVdpauSurface = glVDPAURegisterVideoSurfaceNV(reinterpret_cast<void*>(surf),
3474 GL_TEXTURE_2D, 4, glSurface.texture);
3476 if (glGetError() != GL_NO_ERROR)
3478 CLog::Log(LOGERROR, "VDPAU::COutput error register video surface");
3481 glVDPAUSurfaceAccessNV(glSurface.glVdpauSurface, GL_READ_ONLY);
3482 if (glGetError() != GL_NO_ERROR)
3484 CLog::Log(LOGERROR, "VDPAU::COutput error setting access");
3487 m_bufferPool.glVideoSurfaceMap[surf] = glSurface;
3489 CLog::Log(LOGNOTICE, "VDPAU::COutput registered surface");
3492 while (glGetError() != GL_NO_ERROR) ;
3493 glVDPAUMapSurfacesNV(1, &m_bufferPool.glVideoSurfaceMap[source].glVdpauSurface);
3494 if (glGetError() != GL_NO_ERROR)
3496 CLog::Log(LOGERROR, "VDPAU::COutput error mapping surface");
3505 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3506 it = m_bufferPool.glOutputSurfaceMap.find(source);
3507 if (it == m_bufferPool.glOutputSurfaceMap.end())
3509 unsigned int idx = 0;
3510 for (idx = 0; idx<m_bufferPool.outputSurfaces.size(); idx++)
3512 if (m_bufferPool.outputSurfaces[idx] == source)
3516 VdpauBufferPool::GLVideoSurface glSurface;
3517 glSurface.sourceRgb = m_bufferPool.outputSurfaces[idx];
3518 glGenTextures(1, glSurface.texture);
3519 glSurface.glVdpauSurface = glVDPAURegisterOutputSurfaceNV(reinterpret_cast<void*>(m_bufferPool.outputSurfaces[idx]),
3520 GL_TEXTURE_2D, 1, glSurface.texture);
3521 if (glGetError() != GL_NO_ERROR)
3523 CLog::Log(LOGERROR, "VDPAU::COutput error register output surface");
3526 glVDPAUSurfaceAccessNV(glSurface.glVdpauSurface, GL_READ_ONLY);
3527 if (glGetError() != GL_NO_ERROR)
3529 CLog::Log(LOGERROR, "VDPAU::COutput error setting access");
3532 m_bufferPool.glOutputSurfaceMap[source] = glSurface;
3533 CLog::Log(LOGNOTICE, "VDPAU::COutput registered output surfaces");
3536 while (glGetError() != GL_NO_ERROR) ;
3537 glVDPAUMapSurfacesNV(1, &m_bufferPool.glOutputSurfaceMap[source].glVdpauSurface);
3538 if (glGetError() != GL_NO_ERROR)
3540 CLog::Log(LOGERROR, "VDPAU::COutput error mapping surface");
3550 void COutput::GLUnmapSurfaces()
3552 #ifdef GL_NV_vdpau_interop
3555 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3556 for (it = m_bufferPool.glVideoSurfaceMap.begin(); it != m_bufferPool.glVideoSurfaceMap.end(); ++it)
3558 glVDPAUUnregisterSurfaceNV(it->second.glVdpauSurface);
3559 glDeleteTextures(4, it->second.texture);
3561 m_bufferPool.glVideoSurfaceMap.clear();
3564 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3565 for (it = m_bufferPool.glOutputSurfaceMap.begin(); it != m_bufferPool.glOutputSurfaceMap.end(); ++it)
3567 glVDPAUUnregisterSurfaceNV(it->second.glVdpauSurface);
3568 glDeleteTextures(1, it->second.texture);
3570 m_bufferPool.glOutputSurfaceMap.clear();
3574 CLog::Log(LOGNOTICE, "VDPAU::COutput: vdpau gl interop finished");
3579 bool COutput::CheckStatus(VdpStatus vdp_st, int line)
3581 if (vdp_st != VDP_STATUS_OK)
3583 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);
3590 bool COutput::CreateGlxContext()
3592 GLXContext glContext;
3594 m_Display = g_Windowing.GetDisplay();
3595 glContext = g_Windowing.GetGlxContext();
3596 m_Window = g_Windowing.GetWindow();
3598 // Get our window attribs.
3599 XWindowAttributes wndattribs;
3600 XGetWindowAttributes(m_Display, m_Window, &wndattribs);
3603 XVisualInfo visInfo;
3604 visInfo.visualid = wndattribs.visual->visualid;
3606 XVisualInfo* visuals = XGetVisualInfo(m_Display, VisualIDMask, &visInfo, &nvisuals);
3609 CLog::Log(LOGERROR, "VDPAU::COutput::CreateGlxContext - could not find visual");
3612 visInfo = visuals[0];
3615 m_pixmap = XCreatePixmap(m_Display,
3622 CLog::Log(LOGERROR, "VDPAU::COutput::CreateGlxContext - Unable to create XPixmap");
3627 m_glPixmap = glXCreateGLXPixmap(m_Display, &visInfo, m_pixmap);
3631 CLog::Log(LOGINFO, "VDPAU::COutput::CreateGlxContext - Could not create glPixmap");
3635 m_glContext = glXCreateContext(m_Display, &visInfo, glContext, True);
3637 if (!glXMakeCurrent(m_Display, m_glPixmap, m_glContext))
3639 CLog::Log(LOGINFO, "VDPAU::COutput::CreateGlxContext - Could not make Pixmap current");
3643 CLog::Log(LOGNOTICE, "VDPAU::COutput::CreateGlxContext - created context");
3647 bool COutput::DestroyGlxContext()
3651 glXMakeCurrent(m_Display, None, NULL);
3652 glXDestroyContext(m_Display, m_glContext);
3657 glXDestroyPixmap(m_Display, m_glPixmap);
3661 XFreePixmap(m_Display, m_pixmap);