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 CDecoder::Desc decoder_profiles[] = {
46 {"MPEG1", VDP_DECODER_PROFILE_MPEG1},
47 {"MPEG2_SIMPLE", VDP_DECODER_PROFILE_MPEG2_SIMPLE},
48 {"MPEG2_MAIN", VDP_DECODER_PROFILE_MPEG2_MAIN},
49 {"H264_BASELINE",VDP_DECODER_PROFILE_H264_BASELINE},
50 {"H264_MAIN", VDP_DECODER_PROFILE_H264_MAIN},
51 {"H264_HIGH", VDP_DECODER_PROFILE_H264_HIGH},
52 {"VC1_SIMPLE", VDP_DECODER_PROFILE_VC1_SIMPLE},
53 {"VC1_MAIN", VDP_DECODER_PROFILE_VC1_MAIN},
54 {"VC1_ADVANCED", VDP_DECODER_PROFILE_VC1_ADVANCED},
55 #ifdef VDP_DECODER_PROFILE_MPEG4_PART2_ASP
56 {"MPEG4_PART2_ASP", VDP_DECODER_PROFILE_MPEG4_PART2_ASP},
59 const size_t decoder_profile_count = sizeof(decoder_profiles)/sizeof(CDecoder::Desc);
61 static struct SInterlaceMapping
63 const EINTERLACEMETHOD method;
64 const VdpVideoMixerFeature feature;
65 } g_interlace_mapping[] =
66 { {VS_INTERLACEMETHOD_VDPAU_TEMPORAL , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL}
67 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL}
68 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL , VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL}
69 , {VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF, VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL}
70 , {VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE , VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE}
71 , {VS_INTERLACEMETHOD_NONE , (VdpVideoMixerFeature)-1}
74 static float studioCSCKCoeffs601[3] = {0.299, 0.587, 0.114}; //BT601 {Kr, Kg, Kb}
75 static float studioCSCKCoeffs709[3] = {0.2126, 0.7152, 0.0722}; //BT709 {Kr, Kg, Kb}
77 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
80 CVDPAUContext *CVDPAUContext::m_context = 0;
81 CCriticalSection CVDPAUContext::m_section;
82 Display *CVDPAUContext::m_display = 0;
83 void *CVDPAUContext::m_dlHandle = 0;
85 CVDPAUContext::CVDPAUContext()
91 void CVDPAUContext::Release()
93 CSingleLock lock(m_section);
104 void CVDPAUContext::Close()
106 CLog::Log(LOGNOTICE, "VDPAU::Close - closing decoder context");
110 bool CVDPAUContext::EnsureContext(CVDPAUContext **ctx)
112 CSingleLock lock(m_section);
116 m_context->m_refCount++;
121 m_context = new CVDPAUContext();
124 CSingleLock gLock(g_graphicsContext);
125 if (!m_context->LoadSymbols() || !m_context->CreateContext())
133 m_context->m_refCount++;
139 VDPAU_procs& CVDPAUContext::GetProcs()
144 VdpVideoMixerFeature* CVDPAUContext::GetFeatures()
146 return m_vdpFeatures;
149 int CVDPAUContext::GetFeatureCount()
151 return m_featureCount;
154 bool CVDPAUContext::LoadSymbols()
158 m_dlHandle = dlopen("libvdpau.so.1", RTLD_LAZY);
161 const char* error = dlerror();
163 error = "dlerror() returned NULL";
165 CLog::Log(LOGERROR,"VDPAU::LoadSymbols: Unable to get handle to lib: %s", error);
172 dl_vdp_device_create_x11 = (VdpStatus (*)(Display*, int, VdpDevice*, VdpStatus (**)(VdpDevice, VdpFuncId, void**)))dlsym(m_dlHandle, (const char*)"vdp_device_create_x11");
176 CLog::Log(LOGERROR,"(VDPAU) - %s in %s",error,__FUNCTION__);
177 m_vdpDevice = VDP_INVALID_HANDLE;
183 bool CVDPAUContext::CreateContext()
185 CLog::Log(LOGNOTICE,"VDPAU::CreateContext - creating decoder context");
188 { CSingleLock lock(g_graphicsContext);
190 m_display = XOpenDisplay(NULL);
191 mScreen = g_Windowing.GetCurrentScreen();
196 vdp_st = dl_vdp_device_create_x11(m_display,
199 &m_vdpProcs.vdp_get_proc_address);
201 CLog::Log(LOGNOTICE,"vdp_device = 0x%08x vdp_st = 0x%08x",m_vdpDevice,vdp_st);
202 if (vdp_st != VDP_STATUS_OK)
204 CLog::Log(LOGERROR,"(VDPAU) unable to init VDPAU - vdp_st = 0x%x. Falling back.",vdp_st);
205 m_vdpDevice = VDP_INVALID_HANDLE;
210 SpewHardwareAvailable();
214 void CVDPAUContext::QueryProcs()
218 #define VDP_PROC(id, proc) \
220 vdp_st = m_vdpProcs.vdp_get_proc_address(m_vdpDevice, id, (void**)&proc); \
221 if (vdp_st != VDP_STATUS_OK) \
223 CLog::Log(LOGERROR, "CVDPAUContext::GetProcs - failed to get proc id"); \
227 VDP_PROC(VDP_FUNC_ID_GET_ERROR_STRING , m_vdpProcs.vdp_get_error_string);
228 VDP_PROC(VDP_FUNC_ID_DEVICE_DESTROY , m_vdpProcs.vdp_device_destroy);
229 VDP_PROC(VDP_FUNC_ID_GENERATE_CSC_MATRIX , m_vdpProcs.vdp_generate_csc_matrix);
230 VDP_PROC(VDP_FUNC_ID_VIDEO_SURFACE_CREATE , m_vdpProcs.vdp_video_surface_create);
231 VDP_PROC(VDP_FUNC_ID_VIDEO_SURFACE_DESTROY , m_vdpProcs.vdp_video_surface_destroy);
232 VDP_PROC(VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR , m_vdpProcs.vdp_video_surface_put_bits_y_cb_cr);
233 VDP_PROC(VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_CB_CR , m_vdpProcs.vdp_video_surface_get_bits_y_cb_cr);
234 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_Y_CB_CR , m_vdpProcs.vdp_output_surface_put_bits_y_cb_cr);
235 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE , m_vdpProcs.vdp_output_surface_put_bits_native);
236 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_CREATE , m_vdpProcs.vdp_output_surface_create);
237 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY , m_vdpProcs.vdp_output_surface_destroy);
238 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_GET_BITS_NATIVE , m_vdpProcs.vdp_output_surface_get_bits_native);
239 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE, m_vdpProcs.vdp_output_surface_render_output_surface);
240 VDP_PROC(VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED , m_vdpProcs.vdp_output_surface_put_bits_indexed);
241 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_CREATE , m_vdpProcs.vdp_video_mixer_create);
242 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES , m_vdpProcs.vdp_video_mixer_set_feature_enables);
243 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_DESTROY , m_vdpProcs.vdp_video_mixer_destroy);
244 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_RENDER , m_vdpProcs.vdp_video_mixer_render);
245 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES , m_vdpProcs.vdp_video_mixer_set_attribute_values);
246 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_QUERY_PARAMETER_SUPPORT , m_vdpProcs.vdp_video_mixer_query_parameter_support);
247 VDP_PROC(VDP_FUNC_ID_VIDEO_MIXER_QUERY_FEATURE_SUPPORT , m_vdpProcs.vdp_video_mixer_query_feature_support);
248 VDP_PROC(VDP_FUNC_ID_DECODER_CREATE , m_vdpProcs.vdp_decoder_create);
249 VDP_PROC(VDP_FUNC_ID_DECODER_DESTROY , m_vdpProcs.vdp_decoder_destroy);
250 VDP_PROC(VDP_FUNC_ID_DECODER_RENDER , m_vdpProcs.vdp_decoder_render);
251 VDP_PROC(VDP_FUNC_ID_DECODER_QUERY_CAPABILITIES , m_vdpProcs.vdp_decoder_query_caps);
255 VdpDevice CVDPAUContext::GetDevice()
260 void CVDPAUContext::DestroyContext()
262 if (!m_vdpProcs.vdp_device_destroy)
265 m_vdpProcs.vdp_device_destroy(m_vdpDevice);
266 m_vdpDevice = VDP_INVALID_HANDLE;
269 void CVDPAUContext::SpewHardwareAvailable() //CopyrighVDPAUt (c) 2008 Wladimir J. van der Laan -- VDPInfo
272 CLog::Log(LOGNOTICE,"VDPAU Decoder capabilities:");
273 CLog::Log(LOGNOTICE,"name level macbs width height");
274 CLog::Log(LOGNOTICE,"------------------------------------");
275 for(unsigned int x=0; x<decoder_profile_count; ++x)
277 VdpBool is_supported = false;
278 uint32_t max_level, max_macroblocks, max_width, max_height;
279 rv = m_vdpProcs.vdp_decoder_query_caps(m_vdpDevice, decoder_profiles[x].id,
280 &is_supported, &max_level, &max_macroblocks, &max_width, &max_height);
281 if(rv == VDP_STATUS_OK && is_supported)
283 CLog::Log(LOGNOTICE,"%-16s %2i %5i %5i %5i\n", decoder_profiles[x].name,
284 max_level, max_macroblocks, max_width, max_height);
287 CLog::Log(LOGNOTICE,"------------------------------------");
289 #define CHECK_SUPPORT(feature) \
292 if(m_vdpProcs.vdp_video_mixer_query_feature_support(m_vdpDevice, feature, &supported) == VDP_STATUS_OK && supported) { \
293 CLog::Log(LOGNOTICE, "Mixer feature: "#feature); \
294 m_vdpFeatures[m_featureCount++] = feature; \
298 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION);
299 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_SHARPNESS);
300 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL);
301 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL);
302 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE);
303 #ifdef VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
304 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1);
305 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2);
306 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3);
307 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4);
308 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5);
309 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6);
310 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7);
311 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8);
312 CHECK_SUPPORT(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9);
317 bool CVDPAUContext::Supports(VdpVideoMixerFeature feature)
319 for(int i = 0; i < m_featureCount; i++)
321 if(m_vdpFeatures[i] == feature)
327 //-----------------------------------------------------------------------------
328 // VDPAU Video Surface states
329 //-----------------------------------------------------------------------------
331 #define SURFACE_USED_FOR_REFERENCE 0x01
332 #define SURFACE_USED_FOR_RENDER 0x02
334 void CVideoSurfaces::AddSurface(VdpVideoSurface surf)
336 CSingleLock lock(m_section);
337 m_state[surf] = SURFACE_USED_FOR_REFERENCE;
340 void CVideoSurfaces::ClearReference(VdpVideoSurface surf)
342 CSingleLock lock(m_section);
343 if (m_state.find(surf) == m_state.end())
345 CLog::Log(LOGWARNING, "CVideoSurfaces::ClearReference - surface invalid");
348 m_state[surf] &= ~SURFACE_USED_FOR_REFERENCE;
349 if (m_state[surf] == 0)
351 m_freeSurfaces.push_back(surf);
355 bool CVideoSurfaces::MarkRender(VdpVideoSurface surf)
357 CSingleLock lock(m_section);
358 if (m_state.find(surf) == m_state.end())
360 CLog::Log(LOGWARNING, "CVideoSurfaces::MarkRender - surface invalid");
363 std::list<VdpVideoSurface>::iterator it;
364 it = std::find(m_freeSurfaces.begin(), m_freeSurfaces.end(), surf);
365 if (it != m_freeSurfaces.end())
367 m_freeSurfaces.erase(it);
369 m_state[surf] |= SURFACE_USED_FOR_RENDER;
373 void CVideoSurfaces::ClearRender(VdpVideoSurface surf)
375 CSingleLock lock(m_section);
376 if (m_state.find(surf) == m_state.end())
378 CLog::Log(LOGWARNING, "CVideoSurfaces::ClearRender - surface invalid");
381 m_state[surf] &= ~SURFACE_USED_FOR_RENDER;
382 if (m_state[surf] == 0)
384 m_freeSurfaces.push_back(surf);
388 bool CVideoSurfaces::IsValid(VdpVideoSurface surf)
390 CSingleLock lock(m_section);
391 if (m_state.find(surf) != m_state.end())
397 VdpVideoSurface CVideoSurfaces::GetFree(VdpVideoSurface surf)
399 CSingleLock lock(m_section);
400 if (m_state.find(surf) != m_state.end())
402 std::list<VdpVideoSurface>::iterator it;
403 it = std::find(m_freeSurfaces.begin(), m_freeSurfaces.end(), surf);
404 if (it == m_freeSurfaces.end())
406 CLog::Log(LOGWARNING, "CVideoSurfaces::GetFree - surface not free");
410 m_freeSurfaces.erase(it);
411 m_state[surf] = SURFACE_USED_FOR_REFERENCE;
416 if (!m_freeSurfaces.empty())
418 VdpVideoSurface freeSurf = m_freeSurfaces.front();
419 m_freeSurfaces.pop_front();
420 m_state[freeSurf] = SURFACE_USED_FOR_REFERENCE;
424 return VDP_INVALID_HANDLE;
427 VdpVideoSurface CVideoSurfaces::GetAtIndex(int idx)
429 if (idx >= m_state.size())
430 return VDP_INVALID_HANDLE;
432 std::map<VdpVideoSurface, int>::iterator it = m_state.begin();
433 for(int i = 0; i < idx; i++)
438 VdpVideoSurface CVideoSurfaces::RemoveNext(bool skiprender)
440 CSingleLock lock(m_section);
441 VdpVideoSurface surf;
442 std::map<VdpVideoSurface, int>::iterator it;
443 for(it = m_state.begin(); it != m_state.end(); ++it)
445 if (skiprender && it->second & SURFACE_USED_FOR_RENDER)
450 std::list<VdpVideoSurface>::iterator it2;
451 it2 = std::find(m_freeSurfaces.begin(), m_freeSurfaces.end(), surf);
452 if (it2 != m_freeSurfaces.end())
453 m_freeSurfaces.erase(it2);
456 return VDP_INVALID_HANDLE;
459 void CVideoSurfaces::Reset()
461 CSingleLock lock(m_section);
462 m_freeSurfaces.clear();
466 int CVideoSurfaces::Size()
468 CSingleLock lock(m_section);
469 return m_state.size();
472 //-----------------------------------------------------------------------------
474 //-----------------------------------------------------------------------------
476 CDecoder::CDecoder() : m_vdpauOutput(&m_inMsgEvent)
478 m_vdpauConfig.videoSurfaces = &m_videoSurfaces;
480 m_vdpauConfigured = false;
481 m_hwContext.bitstream_buffers_allocated = 0;
482 m_DisplayState = VDPAU_OPEN;
483 m_vdpauConfig.context = 0;
486 bool CDecoder::Open(AVCodecContext* avctx, const enum PixelFormat, unsigned int surfaces)
488 #ifndef GL_NV_vdpau_interop
489 CLog::Log(LOGNOTICE, "VDPAU: compilation without required extension GL_NV_vdpau_interop");
492 if (!g_Windowing.IsExtSupported("GL_NV_vdpau_interop"))
494 CLog::Log(LOGNOTICE, "VDPAU: required extension GL_NV_vdpau_interop not found");
498 if(avctx->coded_width == 0
499 || avctx->coded_height == 0)
501 CLog::Log(LOGWARNING,"(VDPAU) no width/height available, can't init");
504 m_vdpauConfig.numRenderBuffers = surfaces;
505 m_decoderThread = CThread::GetCurrentThreadId();
507 if ((avctx->codec_id == AV_CODEC_ID_MPEG4) && !g_advancedSettings.m_videoAllowMpeg4VDPAU)
510 if (!CVDPAUContext::EnsureContext(&m_vdpauConfig.context))
513 m_DisplayState = VDPAU_OPEN;
514 m_vdpauConfigured = false;
516 if (!m_dllAvUtil.Load())
519 m_presentPicture = 0;
522 VdpDecoderProfile profile = 0;
523 if(avctx->codec_id == AV_CODEC_ID_H264)
524 profile = VDP_DECODER_PROFILE_H264_HIGH;
525 #ifdef VDP_DECODER_PROFILE_MPEG4_PART2_ASP
526 else if(avctx->codec_id == AV_CODEC_ID_MPEG4)
527 profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
531 if (!CDVDCodecUtils::IsVP3CompatibleWidth(avctx->coded_width))
532 CLog::Log(LOGWARNING,"(VDPAU) width %i might not be supported because of hardware bug", avctx->width);
534 /* attempt to create a decoder with this width/height, some sizes are not supported by hw */
536 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_create(m_vdpauConfig.context->GetDevice(), profile, avctx->coded_width, avctx->coded_height, 5, &m_vdpauConfig.vdpDecoder);
538 if(vdp_st != VDP_STATUS_OK)
540 CLog::Log(LOGERROR, " (VDPAU) Error: %s(%d) checking for decoder support\n", m_vdpauConfig.context->GetProcs().vdp_get_error_string(vdp_st), vdp_st);
544 m_vdpauConfig.context->GetProcs().vdp_decoder_destroy(m_vdpauConfig.vdpDecoder);
545 CheckStatus(vdp_st, __LINE__);
548 /* finally setup ffmpeg */
549 memset(&m_hwContext, 0, sizeof(AVVDPAUContext));
550 m_hwContext.render = CDecoder::Render;
551 m_hwContext.bitstream_buffers_allocated = 0;
552 avctx->get_buffer = CDecoder::FFGetBuffer;
553 avctx->reget_buffer = CDecoder::FFGetBuffer;
554 avctx->release_buffer = CDecoder::FFReleaseBuffer;
555 avctx->draw_horiz_band = CDecoder::FFDrawSlice;
556 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD;
557 avctx->hwaccel_context = &m_hwContext;
558 avctx->thread_count = 1;
560 g_Windowing.Register(this);
566 CDecoder::~CDecoder()
571 void CDecoder::Close()
573 CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);
575 g_Windowing.Unregister(this);
577 CSingleLock lock(m_DecoderSection);
580 m_vdpauOutput.Dispose();
582 if (m_hwContext.bitstream_buffers_allocated)
584 m_dllAvUtil.av_freep(&m_hwContext.bitstream_buffers);
587 m_dllAvUtil.Unload();
589 if (m_vdpauConfig.context)
590 m_vdpauConfig.context->Release();
591 m_vdpauConfig.context = 0;
594 long CDecoder::Release()
596 // check if we should do some pre-cleanup here
597 // a second decoder might need resources
598 if (m_vdpauConfigured == true)
600 CSingleLock lock(m_DecoderSection);
601 CLog::Log(LOGNOTICE,"CVDPAU::Release pre-cleanup");
604 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::PRECLEANUP,
608 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
612 CLog::Log(LOGERROR, "VDPAU::%s - pre-cleanup returned error", __FUNCTION__);
613 m_DisplayState = VDPAU_ERROR;
618 CLog::Log(LOGERROR, "VDPAU::%s - pre-cleanup timed out", __FUNCTION__);
619 m_DisplayState = VDPAU_ERROR;
622 VdpVideoSurface surf;
623 while((surf = m_videoSurfaces.RemoveNext(true)) != VDP_INVALID_HANDLE)
625 m_vdpauConfig.context->GetProcs().vdp_video_surface_destroy(surf);
628 return IHardwareDecoder::Release();
631 long CDecoder::ReleasePicReference()
633 return IHardwareDecoder::Release();
636 void CDecoder::SetWidthHeight(int width, int height)
638 m_vdpauConfig.upscale = g_advancedSettings.m_videoVDPAUScaling;
640 //pick the smallest dimensions, so we downscale with vdpau and upscale with opengl when appropriate
641 //this requires the least amount of gpu memory bandwidth
642 if (g_graphicsContext.GetWidth() < width || g_graphicsContext.GetHeight() < height || m_vdpauConfig.upscale >= 0)
644 //scale width to desktop size if the aspect ratio is the same or bigger than the desktop
645 if ((double)height * g_graphicsContext.GetWidth() / width <= (double)g_graphicsContext.GetHeight())
647 m_vdpauConfig.outWidth = g_graphicsContext.GetWidth();
648 m_vdpauConfig.outHeight = MathUtils::round_int((double)height * g_graphicsContext.GetWidth() / width);
650 else //scale height to the desktop size if the aspect ratio is smaller than the desktop
652 m_vdpauConfig.outHeight = g_graphicsContext.GetHeight();
653 m_vdpauConfig.outWidth = MathUtils::round_int((double)width * g_graphicsContext.GetHeight() / height);
658 m_vdpauConfig.outWidth = width;
659 m_vdpauConfig.outHeight = height;
661 CLog::Log(LOGDEBUG, "CVDPAU::SetWidthHeight Setting OutWidth: %i OutHeight: %i", m_vdpauConfig.outWidth, m_vdpauConfig.outHeight);
664 void CDecoder::OnLostDevice()
666 CLog::Log(LOGNOTICE,"CVDPAU::OnLostDevice event");
668 int count = g_graphicsContext.exit();
670 CSingleLock lock(m_DecoderSection);
672 if (m_vdpauConfig.context)
673 m_vdpauConfig.context->Release();
674 m_vdpauConfig.context = 0;
676 m_DisplayState = VDPAU_LOST;
678 m_DisplayEvent.Reset();
680 g_graphicsContext.restore(count);
683 void CDecoder::OnResetDevice()
685 CLog::Log(LOGNOTICE,"CVDPAU::OnResetDevice event");
687 int count = g_graphicsContext.exit();
689 CSingleLock lock(m_DecoderSection);
690 if (m_DisplayState == VDPAU_LOST)
692 m_DisplayState = VDPAU_RESET;
694 m_DisplayEvent.Set();
697 g_graphicsContext.restore(count);
700 int CDecoder::Check(AVCodecContext* avctx)
704 { CSingleLock lock(m_DecoderSection);
705 state = m_DisplayState;
708 if (state == VDPAU_LOST)
710 CLog::Log(LOGNOTICE,"CVDPAU::Check waiting for display reset event");
711 if (!m_DisplayEvent.WaitMSec(4000))
713 CLog::Log(LOGERROR, "CVDPAU::Check - device didn't reset in reasonable time");
718 CSingleLock lock(m_DecoderSection);
719 state = m_DisplayState;
722 if (state == VDPAU_RESET || state == VDPAU_ERROR)
724 CSingleLock lock(m_DecoderSection);
727 if (m_vdpauConfig.context)
728 m_vdpauConfig.context->Release();
729 m_vdpauConfig.context = 0;
731 if (CVDPAUContext::EnsureContext(&m_vdpauConfig.context))
733 m_DisplayState = VDPAU_OPEN;
734 m_vdpauConfigured = false;
737 if (state == VDPAU_RESET)
745 bool CDecoder::IsVDPAUFormat(PixelFormat format)
747 if (format == AV_PIX_FMT_VDPAU)
753 bool CDecoder::Supports(VdpVideoMixerFeature feature)
755 return m_vdpauConfig.context->Supports(feature);
758 bool CDecoder::Supports(EINTERLACEMETHOD method)
760 if(method == VS_INTERLACEMETHOD_VDPAU_BOB
761 || method == VS_INTERLACEMETHOD_AUTO)
764 if (method == VS_INTERLACEMETHOD_RENDER_BOB)
767 if (method == VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE)
770 for(SInterlaceMapping* p = g_interlace_mapping; p->method != VS_INTERLACEMETHOD_NONE; p++)
772 if(p->method == method)
773 return Supports(p->feature);
778 EINTERLACEMETHOD CDecoder::AutoInterlaceMethod()
780 return VS_INTERLACEMETHOD_RENDER_BOB;
783 void CDecoder::FiniVDPAUOutput()
785 if (!m_vdpauConfigured)
788 CLog::Log(LOGNOTICE, " (VDPAU) %s", __FUNCTION__);
791 m_vdpauOutput.Dispose();
792 m_vdpauConfigured = false;
796 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_destroy(m_vdpauConfig.vdpDecoder);
797 if (CheckStatus(vdp_st, __LINE__))
799 m_vdpauConfig.vdpDecoder = VDP_INVALID_HANDLE;
801 CLog::Log(LOGDEBUG, "CVDPAU::FiniVDPAUOutput destroying %d video surfaces", m_videoSurfaces.Size());
803 VdpVideoSurface surf;
804 while((surf = m_videoSurfaces.RemoveNext()) != VDP_INVALID_HANDLE)
806 m_vdpauConfig.context->GetProcs().vdp_video_surface_destroy(surf);
807 if (CheckStatus(vdp_st, __LINE__))
810 m_videoSurfaces.Reset();
813 void CDecoder::ReadFormatOf( AVCodecID codec
814 , VdpDecoderProfile &vdp_decoder_profile
815 , VdpChromaType &vdp_chroma_type)
819 case AV_CODEC_ID_MPEG1VIDEO:
820 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
821 vdp_chroma_type = VDP_CHROMA_TYPE_420;
823 case AV_CODEC_ID_MPEG2VIDEO:
824 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
825 vdp_chroma_type = VDP_CHROMA_TYPE_420;
827 case AV_CODEC_ID_H264:
828 vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
829 vdp_chroma_type = VDP_CHROMA_TYPE_420;
831 case AV_CODEC_ID_WMV3:
832 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
833 vdp_chroma_type = VDP_CHROMA_TYPE_420;
835 case AV_CODEC_ID_VC1:
836 vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
837 vdp_chroma_type = VDP_CHROMA_TYPE_420;
839 case AV_CODEC_ID_MPEG4:
840 vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
841 vdp_chroma_type = VDP_CHROMA_TYPE_420;
844 vdp_decoder_profile = 0;
850 bool CDecoder::ConfigVDPAU(AVCodecContext* avctx, int ref_frames)
855 VdpDecoderProfile vdp_decoder_profile;
857 m_vdpauConfig.vidWidth = avctx->width;
858 m_vdpauConfig.vidHeight = avctx->height;
859 m_vdpauConfig.surfaceWidth = avctx->coded_width;
860 m_vdpauConfig.surfaceHeight = avctx->coded_height;
862 SetWidthHeight(avctx->width,avctx->height);
864 CLog::Log(LOGNOTICE, " (VDPAU) screenWidth:%i vidWidth:%i surfaceWidth:%i",m_vdpauConfig.outWidth,m_vdpauConfig.vidWidth,m_vdpauConfig.surfaceWidth);
865 CLog::Log(LOGNOTICE, " (VDPAU) screenHeight:%i vidHeight:%i surfaceHeight:%i",m_vdpauConfig.outHeight,m_vdpauConfig.vidHeight,m_vdpauConfig.surfaceHeight);
867 ReadFormatOf(avctx->codec_id, vdp_decoder_profile, m_vdpauConfig.vdpChromaType);
869 if(avctx->codec_id == AV_CODEC_ID_H264)
871 m_vdpauConfig.maxReferences = ref_frames;
872 if (m_vdpauConfig.maxReferences > 16) m_vdpauConfig.maxReferences = 16;
873 if (m_vdpauConfig.maxReferences < 5) m_vdpauConfig.maxReferences = 5;
876 m_vdpauConfig.maxReferences = 2;
878 vdp_st = m_vdpauConfig.context->GetProcs().vdp_decoder_create(m_vdpauConfig.context->GetDevice(),
880 m_vdpauConfig.surfaceWidth,
881 m_vdpauConfig.surfaceHeight,
882 m_vdpauConfig.maxReferences,
883 &m_vdpauConfig.vdpDecoder);
884 if (CheckStatus(vdp_st, __LINE__))
888 CSingleLock lock(g_graphicsContext);
889 m_vdpauConfig.stats = &m_bufferStats;
890 m_vdpauConfig.vdpau = this;
891 m_bufferStats.Reset();
892 m_vdpauOutput.Start();
894 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::INIT,
898 sizeof(m_vdpauConfig)))
900 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
904 CLog::Log(LOGERROR, "VDPAU::%s - vdpau output returned error", __FUNCTION__);
905 m_vdpauOutput.Dispose();
911 CLog::Log(LOGERROR, "VDPAU::%s - failed to init output", __FUNCTION__);
912 m_vdpauOutput.Dispose();
916 m_inMsgEvent.Reset();
917 m_vdpauConfigured = true;
921 int CDecoder::FFGetBuffer(AVCodecContext *avctx, AVFrame *pic)
923 //CLog::Log(LOGNOTICE,"%s",__FUNCTION__);
924 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)avctx->opaque;
925 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
927 // while we are waiting to recover we can't do anything
928 CSingleLock lock(vdp->m_DecoderSection);
930 if(vdp->m_DisplayState != VDPAU_OPEN)
932 CLog::Log(LOGWARNING, "CVDPAU::FFGetBuffer - returning due to awaiting recovery");
936 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)pic->data[3];
937 surf = vdp->m_videoSurfaces.GetFree(surf != 0 ? surf : VDP_INVALID_HANDLE);
939 VdpStatus vdp_st = VDP_STATUS_ERROR;
940 if (surf == VDP_INVALID_HANDLE)
942 // create a new surface
943 VdpDecoderProfile profile;
944 ReadFormatOf(avctx->codec_id, profile, vdp->m_vdpauConfig.vdpChromaType);
946 vdp_st = vdp->m_vdpauConfig.context->GetProcs().vdp_video_surface_create(vdp->m_vdpauConfig.context->GetDevice(),
947 vdp->m_vdpauConfig.vdpChromaType,
951 vdp->CheckStatus(vdp_st, __LINE__);
952 if (vdp_st != VDP_STATUS_OK)
954 CLog::Log(LOGERROR, "CVDPAU::FFGetBuffer - No Video surface available could be created");
957 vdp->m_videoSurfaces.AddSurface(surf);
960 pic->data[1] = pic->data[2] = NULL;
961 pic->data[0] = (uint8_t*)(uintptr_t)surf;
962 pic->data[3] = (uint8_t*)(uintptr_t)surf;
964 pic->linesize[0] = pic->linesize[1] = pic->linesize[2] = 0;
966 pic->type= FF_BUFFER_TYPE_USER;
968 pic->reordered_opaque= avctx->reordered_opaque;
972 void CDecoder::FFReleaseBuffer(AVCodecContext *avctx, AVFrame *pic)
974 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)avctx->opaque;
975 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
977 VdpVideoSurface surf;
980 CSingleLock lock(vdp->m_DecoderSection);
982 surf = (VdpVideoSurface)(uintptr_t)pic->data[3];
984 vdp->m_videoSurfaces.ClearReference(surf);
990 VdpStatus CDecoder::Render( VdpDecoder decoder, VdpVideoSurface target,
991 VdpPictureInfo const *picture_info,
992 uint32_t bitstream_buffer_count,
993 VdpBitstreamBuffer const * bitstream_buffers)
995 return VDP_STATUS_OK;
998 void CDecoder::FFDrawSlice(struct AVCodecContext *s,
999 const AVFrame *src, int offset[4],
1000 int y, int type, int height)
1002 CDVDVideoCodecFFmpeg* ctx = (CDVDVideoCodecFFmpeg*)s->opaque;
1003 CDecoder* vdp = (CDecoder*)ctx->GetHardware();
1005 // while we are waiting to recover we can't do anything
1006 CSingleLock lock(vdp->m_DecoderSection);
1008 if(vdp->m_DisplayState != VDPAU_OPEN)
1011 if(src->linesize[0] || src->linesize[1] || src->linesize[2]
1012 || offset[0] || offset[1] || offset[2])
1014 CLog::Log(LOGERROR, "CVDPAU::FFDrawSlice - invalid linesizes or offsets provided");
1019 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)src->data[3];
1021 // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid
1022 if (!vdp->m_videoSurfaces.IsValid(surf))
1024 CLog::Log(LOGWARNING, "CVDPAU::FFDrawSlice - ignoring invalid buffer");
1028 uint32_t max_refs = 0;
1029 if(s->codec_id == AV_CODEC_ID_H264)
1030 max_refs = vdp->m_hwContext.info.h264.num_ref_frames;
1032 if(vdp->m_vdpauConfig.vdpDecoder == VDP_INVALID_HANDLE
1033 || vdp->m_vdpauConfigured == false
1034 || vdp->m_vdpauConfig.maxReferences < max_refs)
1036 if(!vdp->ConfigVDPAU(s, max_refs))
1040 uint64_t startTime = CurrentHostCounter();
1041 uint16_t decoded, processed, rend;
1042 vdp->m_bufferStats.Get(decoded, processed, rend);
1043 vdp_st = vdp->m_vdpauConfig.context->GetProcs().vdp_decoder_render(vdp->m_vdpauConfig.vdpDecoder,
1045 (VdpPictureInfo const *)&(vdp->m_hwContext.info),
1046 vdp->m_hwContext.bitstream_buffers_used,
1047 vdp->m_hwContext.bitstream_buffers);
1048 vdp->CheckStatus(vdp_st, __LINE__);
1049 uint64_t diff = CurrentHostCounter() - startTime;
1050 if (diff*1000/CurrentHostFrequency() > 30)
1051 CLog::Log(LOGDEBUG, "CVDPAU::DrawSlice - VdpDecoderRender long decoding: %d ms, dec: %d, proc: %d, rend: %d", (int)((diff*1000)/CurrentHostFrequency()), decoded, processed, rend);
1055 int CDecoder::Decode(AVCodecContext *avctx, AVFrame *pFrame)
1057 int result = Check(avctx);
1061 CSingleLock lock(m_DecoderSection);
1063 if (!m_vdpauConfigured)
1067 { // we have a new frame from decoder
1069 VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)pFrame->data[3];
1070 // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid
1071 if (!m_videoSurfaces.IsValid(surf))
1073 CLog::Log(LOGWARNING, "CVDPAU::Decode - ignoring invalid buffer");
1076 m_videoSurfaces.MarkRender(surf);
1078 // send frame to output for processing
1079 CVdpauDecodedPicture pic;
1080 memset(&pic.DVDPic, 0, sizeof(pic.DVDPic));
1081 ((CDVDVideoCodecFFmpeg*)avctx->opaque)->GetPictureCommon(&pic.DVDPic);
1082 pic.videoSurface = surf;
1083 pic.DVDPic.color_matrix = avctx->colorspace;
1084 m_bufferStats.IncDecoded();
1085 m_vdpauOutput.m_dataPort.SendOutMessage(COutputDataProtocol::NEWFRAME, &pic, sizeof(pic));
1088 // m_codecControl = pic.DVDPic.iFlags & (DVP_FLAG_DRAIN | DVP_FLAG_NO_POSTPROC);
1092 uint16_t decoded, processed, render;
1094 while (m_vdpauOutput.m_controlPort.ReceiveInMessage(&msg))
1096 if (msg->signal == COutputControlProtocol::ERROR)
1098 m_DisplayState = VDPAU_ERROR;
1104 m_bufferStats.Get(decoded, processed, render);
1106 uint64_t startTime = CurrentHostCounter();
1109 // first fill the buffers to keep vdpau busy
1110 // mixer will run with decoded >= 2. output is limited by number of output surfaces
1111 // In case mixer is bypassed we limit by looking at processed
1112 if (decoded < 3 && processed < 3)
1114 retval |= VC_BUFFER;
1116 else if (m_vdpauOutput.m_dataPort.ReceiveInMessage(&msg))
1118 if (msg->signal == COutputDataProtocol::PICTURE)
1120 if (m_presentPicture)
1122 m_presentPicture->ReturnUnused();
1123 m_presentPicture = 0;
1126 m_presentPicture = *(CVdpauRenderPicture**)msg->data;
1127 m_presentPicture->vdpau = this;
1128 m_bufferStats.DecRender();
1129 m_bufferStats.Get(decoded, processed, render);
1130 retval |= VC_PICTURE;
1136 else if (m_vdpauOutput.m_controlPort.ReceiveInMessage(&msg))
1138 if (msg->signal == COutputControlProtocol::STATS)
1140 m_bufferStats.Get(decoded, processed, render);
1144 m_DisplayState = VDPAU_ERROR;
1150 if (decoded < 3 && processed < 3)
1152 retval |= VC_BUFFER;
1155 if (!retval && !m_inMsgEvent.WaitMSec(2000))
1158 uint64_t diff = CurrentHostCounter() - startTime;
1159 if (retval & VC_PICTURE)
1161 m_bufferStats.SetParams(diff, m_codecControl);
1163 if (diff*1000/CurrentHostFrequency() > 50)
1164 CLog::Log(LOGDEBUG,"CVDPAU::Decode long wait: %d", (int)((diff*1000)/CurrentHostFrequency()));
1168 CLog::Log(LOGERROR, "VDPAU::%s - timed out waiting for output message", __FUNCTION__);
1169 m_DisplayState = VDPAU_ERROR;
1176 bool CDecoder::GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture)
1178 CSingleLock lock(m_DecoderSection);
1180 if (m_DisplayState != VDPAU_OPEN)
1183 *picture = m_presentPicture->DVDPic;
1184 picture->vdpau = m_presentPicture;
1189 void CDecoder::Reset()
1191 CSingleLock lock(m_DecoderSection);
1193 if (!m_vdpauConfigured)
1197 if (m_vdpauOutput.m_controlPort.SendOutMessageSync(COutputControlProtocol::FLUSH,
1201 bool success = reply->signal == COutputControlProtocol::ACC ? true : false;
1205 CLog::Log(LOGERROR, "VDPAU::%s - flush returned error", __FUNCTION__);
1206 m_DisplayState = VDPAU_ERROR;
1209 m_bufferStats.Reset();
1213 CLog::Log(LOGERROR, "VDPAU::%s - flush timed out", __FUNCTION__);
1214 m_DisplayState = VDPAU_ERROR;
1218 bool CDecoder::CanSkipDeint()
1220 return m_bufferStats.CanSkipDeint();
1223 void CDecoder::ReturnRenderPicture(CVdpauRenderPicture *renderPic)
1225 m_vdpauOutput.m_dataPort.SendOutMessage(COutputDataProtocol::RETURNPIC, &renderPic, sizeof(renderPic));
1228 bool CDecoder::CheckStatus(VdpStatus vdp_st, int line)
1230 if (vdp_st != VDP_STATUS_OK)
1232 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);
1234 if(m_DisplayState == VDPAU_OPEN)
1236 if (vdp_st == VDP_STATUS_DISPLAY_PREEMPTED)
1238 m_DisplayEvent.Reset();
1239 m_DisplayState = VDPAU_LOST;
1242 m_DisplayState = VDPAU_ERROR;
1250 //-----------------------------------------------------------------------------
1252 //-----------------------------------------------------------------------------
1254 CVdpauRenderPicture* CVdpauRenderPicture::Acquire()
1256 CSingleLock lock(renderPicSection);
1265 long CVdpauRenderPicture::Release()
1267 CSingleLock lock(renderPicSection);
1274 vdpau->ReturnRenderPicture(this);
1275 vdpau->ReleasePicReference();
1280 void CVdpauRenderPicture::ReturnUnused()
1282 { CSingleLock lock(renderPicSection);
1287 vdpau->ReturnRenderPicture(this);
1290 void CVdpauRenderPicture::Sync()
1293 CSingleLock lock(renderPicSection);
1298 glDeleteSync(fence);
1301 fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
1306 //-----------------------------------------------------------------------------
1308 //-----------------------------------------------------------------------------
1309 CMixer::CMixer(CEvent *inMsgEvent) :
1310 CThread("Vdpau Mixer"),
1311 m_controlPort("ControlPort", inMsgEvent, &m_outMsgEvent),
1312 m_dataPort("DataPort", inMsgEvent, &m_outMsgEvent)
1314 m_inMsgEvent = inMsgEvent;
1322 void CMixer::Start()
1327 void CMixer::Dispose()
1330 m_outMsgEvent.Set();
1333 m_controlPort.Purge();
1337 bool CMixer::IsActive()
1342 void CMixer::OnStartup()
1344 CLog::Log(LOGNOTICE, "CMixer::OnStartup: Output Thread created");
1347 void CMixer::OnExit()
1349 CLog::Log(LOGNOTICE, "CMixer::OnExit: Output Thread terminated");
1356 M_TOP_UNCONFIGURED, // 2
1357 M_TOP_CONFIGURED, // 3
1358 M_TOP_CONFIGURED_WAIT1, // 4
1359 M_TOP_CONFIGURED_STEP1, // 5
1360 M_TOP_CONFIGURED_WAIT2, // 6
1361 M_TOP_CONFIGURED_STEP2, // 7
1364 int MIXER_parentStates[] = {
1367 0, //TOP_UNCONFIGURED
1369 3, //TOP_CONFIGURED_WAIT1
1370 3, //TOP_CONFIGURED_STEP1
1371 3, //TOP_CONFIGURED_WAIT2
1372 3, //TOP_CONFIGURED_STEP2
1375 void CMixer::StateMachine(int signal, Protocol *port, Message *msg)
1377 for (int state = m_state; ; state = MIXER_parentStates[state])
1382 if (port == &m_controlPort)
1386 case CMixerControlProtocol::FLUSH:
1388 msg->Reply(CMixerControlProtocol::ACC);
1395 std::string portName = port == NULL ? "timer" : port->portName;
1396 CLog::Log(LOGWARNING, "CMixer::%s - signal: %d form port: %s not handled for state: %d", __FUNCTION__, signal, portName.c_str(), m_state);
1400 case M_TOP_ERROR: // TOP
1403 case M_TOP_UNCONFIGURED:
1404 if (port == &m_controlPort)
1408 case CMixerControlProtocol::INIT:
1410 data = (CVdpauConfig*)msg->data;
1418 m_state = M_TOP_CONFIGURED_WAIT1;
1419 msg->Reply(CMixerControlProtocol::ACC);
1423 msg->Reply(CMixerControlProtocol::ERROR);
1432 case M_TOP_CONFIGURED:
1433 if (port == &m_dataPort)
1437 case CMixerDataProtocol::FRAME:
1438 CVdpauDecodedPicture *frame;
1439 frame = (CVdpauDecodedPicture*)msg->data;
1442 m_decodedPics.push(*frame);
1446 case CMixerDataProtocol::BUFFER:
1447 VdpOutputSurface *surf;
1448 surf = (VdpOutputSurface*)msg->data;
1451 m_outputSurfaces.push(*surf);
1461 case M_TOP_CONFIGURED_WAIT1:
1462 if (port == NULL) // timeout
1466 case CMixerControlProtocol::TIMEOUT:
1467 if (!m_decodedPics.empty() && !m_outputSurfaces.empty())
1469 m_state = M_TOP_CONFIGURED_STEP1;
1470 m_bStateMachineSelfTrigger = true;
1483 case M_TOP_CONFIGURED_STEP1:
1484 if (port == NULL) // timeout
1488 case CMixerControlProtocol::TIMEOUT:
1489 m_mixerInput.push_front(m_decodedPics.front());
1490 m_decodedPics.pop();
1491 if (m_mixerInput.size() < 2)
1493 m_state = M_TOP_CONFIGURED_WAIT1;
1501 m_state = M_TOP_CONFIGURED_WAIT1;
1502 m_extTimeout = 1000;
1505 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
1506 m_outputSurfaces.pop();
1507 m_config.stats->IncProcessed();
1508 m_config.stats->DecDecoded();
1509 m_dataPort.SendInMessage(CMixerDataProtocol::PICTURE,&m_processPicture,sizeof(m_processPicture));
1510 if (m_mixersteps > 1)
1512 m_state = M_TOP_CONFIGURED_WAIT2;
1518 m_state = M_TOP_CONFIGURED_WAIT1;
1528 case M_TOP_CONFIGURED_WAIT2:
1529 if (port == NULL) // timeout
1533 case CMixerControlProtocol::TIMEOUT:
1534 if (!m_outputSurfaces.empty())
1536 m_state = M_TOP_CONFIGURED_STEP2;
1537 m_bStateMachineSelfTrigger = true;
1550 case M_TOP_CONFIGURED_STEP2:
1551 if (port == NULL) // timeout
1555 case CMixerControlProtocol::TIMEOUT:
1556 m_processPicture.outputSurface = m_outputSurfaces.front();
1561 m_state = M_TOP_CONFIGURED_WAIT1;
1562 m_extTimeout = 1000;
1565 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
1566 m_outputSurfaces.pop();
1567 m_config.stats->IncProcessed();
1568 m_dataPort.SendInMessage(CMixerDataProtocol::PICTURE,&m_processPicture,sizeof(m_processPicture));
1570 m_state = M_TOP_CONFIGURED_WAIT1;
1579 default: // we are in no state, should not happen
1580 CLog::Log(LOGERROR, "CMixer::%s - no valid state: %d", __FUNCTION__, m_state);
1586 void CMixer::Process()
1588 Message *msg = NULL;
1589 Protocol *port = NULL;
1592 m_state = M_TOP_UNCONFIGURED;
1593 m_extTimeout = 1000;
1594 m_bStateMachineSelfTrigger = false;
1600 if (m_bStateMachineSelfTrigger)
1602 m_bStateMachineSelfTrigger = false;
1603 // self trigger state machine
1604 StateMachine(msg->signal, port, msg);
1605 if (!m_bStateMachineSelfTrigger)
1612 // check control port
1613 else if (m_controlPort.ReceiveOutMessage(&msg))
1616 port = &m_controlPort;
1619 else if (m_dataPort.ReceiveOutMessage(&msg))
1627 StateMachine(msg->signal, port, msg);
1628 if (!m_bStateMachineSelfTrigger)
1637 else if (m_outMsgEvent.WaitMSec(m_extTimeout))
1644 msg = m_controlPort.GetMessage();
1645 msg->signal = CMixerControlProtocol::TIMEOUT;
1647 // signal timeout to state machine
1648 StateMachine(msg->signal, port, msg);
1649 if (!m_bStateMachineSelfTrigger)
1659 void CMixer::CreateVdpauMixer()
1661 CLog::Log(LOGNOTICE, " (VDPAU) Creating the video mixer");
1663 InitCSCMatrix(m_config.vidWidth);
1665 VdpVideoMixerParameter parameters[] = {
1666 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
1667 VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
1668 VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE};
1670 void const * parameter_values[] = {
1671 &m_config.surfaceWidth,
1672 &m_config.surfaceHeight,
1673 &m_config.vdpChromaType};
1675 VdpStatus vdp_st = VDP_STATUS_ERROR;
1676 vdp_st = m_config.context->GetProcs().vdp_video_mixer_create(m_config.context->GetDevice(),
1677 m_config.context->GetFeatureCount(),
1678 m_config.context->GetFeatures(),
1683 CheckStatus(vdp_st, __LINE__);
1687 void CMixer::InitCSCMatrix(int Width)
1689 m_Procamp.struct_version = VDP_PROCAMP_VERSION;
1690 m_Procamp.brightness = 0.0;
1691 m_Procamp.contrast = 1.0;
1692 m_Procamp.saturation = 1.0;
1696 void CMixer::CheckFeatures()
1698 if (m_Upscale != m_config.upscale)
1701 m_Upscale = m_config.upscale;
1703 if (m_Brightness != CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness ||
1704 m_Contrast != CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast ||
1705 m_ColorMatrix != m_mixerInput[1].DVDPic.color_matrix)
1708 m_Brightness = CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness;
1709 m_Contrast = CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast;
1710 m_ColorMatrix = m_mixerInput[1].DVDPic.color_matrix;
1712 if (m_NoiseReduction != CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction)
1714 m_NoiseReduction = CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction;
1715 SetNoiseReduction();
1717 if (m_Sharpness != CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness)
1719 m_Sharpness = CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness;
1722 if (m_DeintMode != CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode ||
1723 m_Deint != CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod)
1725 m_DeintMode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1726 m_Deint = CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod;
1731 void CMixer::SetPostProcFeatures(bool postProcEnabled)
1733 if (m_PostProc != postProcEnabled)
1735 if (postProcEnabled)
1737 SetNoiseReduction();
1744 m_PostProc = postProcEnabled;
1748 void CMixer::PostProcOff()
1752 if (m_videoMixer == VDP_INVALID_HANDLE)
1755 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL,
1756 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL,
1757 VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE};
1759 VdpBool enabled[]={0,0,0};
1760 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1761 CheckStatus(vdp_st, __LINE__);
1763 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION))
1765 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION};
1767 VdpBool enabled[]={0};
1768 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1769 CheckStatus(vdp_st, __LINE__);
1772 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_SHARPNESS))
1774 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_SHARPNESS};
1776 VdpBool enabled[]={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__);
1784 bool CMixer::GenerateStudioCSCMatrix(VdpColorStandard colorStandard, VdpCSCMatrix &studioCSCMatrix)
1786 // instead use studioCSCKCoeffs601[3], studioCSCKCoeffs709[3] to generate float[3][4] matrix (float studioCSC[3][4])
1787 // m00 = mRY = red: luma factor (contrast factor) (1.0)
1788 // m10 = mGY = green: luma factor (contrast factor) (1.0)
1789 // m20 = mBY = blue: luma factor (contrast factor) (1.0)
1791 // m01 = mRB = red: blue color diff coeff (0.0)
1792 // m11 = mGB = green: blue color diff coeff (-2Kb(1-Kb)/(Kg))
1793 // m21 = mBB = blue: blue color diff coeff ((1-Kb)/0.5)
1795 // m02 = mRR = red: red color diff coeff ((1-Kr)/0.5)
1796 // m12 = mGR = green: red color diff coeff (-2Kr(1-Kr)/(Kg))
1797 // m22 = mBR = blue: red color diff coeff (0.0)
1799 // m03 = mRC = red: colour zero offset (brightness factor) (-(1-Kr)/0.5 * (128/255))
1800 // m13 = mGC = green: colour zero offset (brightness factor) ((256/255) * (Kb(1-Kb) + Kr(1-Kr)) / Kg)
1801 // m23 = mBC = blue: colour zero offset (brightness factor) (-(1-Kb)/0.5 * (128/255))
1812 // colour standard coefficients for red, geen, blue
1814 // colour diff zero position (use standard 8-bit coding precision)
1815 double CDZ = 128; //256*0.5
1816 // range excursion (use standard 8-bit coding precision)
1817 double EXC = 255; //256-1
1819 if (colorStandard == VDP_COLOR_STANDARD_ITUR_BT_601)
1821 Kr = studioCSCKCoeffs601[0];
1822 Kg = studioCSCKCoeffs601[1];
1823 Kb = studioCSCKCoeffs601[2];
1825 else // assume VDP_COLOR_STANDARD_ITUR_BT_709
1827 Kr = studioCSCKCoeffs709[0];
1828 Kg = studioCSCKCoeffs709[1];
1829 Kb = studioCSCKCoeffs709[2];
1831 // we keep luma unscaled to retain the levels present in source so that 16-235 luma is converted to RGB 16-235
1832 studioCSCMatrix[R][Y] = 1.0;
1833 studioCSCMatrix[G][Y] = 1.0;
1834 studioCSCMatrix[B][Y] = 1.0;
1836 studioCSCMatrix[R][Cb] = 0.0;
1837 studioCSCMatrix[G][Cb] = (double)-2 * Kb * (1 - Kb) / Kg;
1838 studioCSCMatrix[B][Cb] = (double)(1 - Kb) / 0.5;
1840 studioCSCMatrix[R][Cr] = (double)(1 - Kr) / 0.5;
1841 studioCSCMatrix[G][Cr] = (double)-2 * Kr * (1 - Kr) / Kg;
1842 studioCSCMatrix[B][Cr] = 0.0;
1844 studioCSCMatrix[R][C] = (double)-1 * studioCSCMatrix[R][Cr] * CDZ/EXC;
1845 studioCSCMatrix[G][C] = (double)-1 * (studioCSCMatrix[G][Cb] + studioCSCMatrix[G][Cr]) * CDZ/EXC;
1846 studioCSCMatrix[B][C] = (double)-1 * studioCSCMatrix[B][Cb] * CDZ/EXC;
1851 void CMixer::SetColor()
1855 if (m_Brightness != CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness)
1856 m_Procamp.brightness = (float)((CMediaSettings::Get().GetCurrentVideoSettings().m_Brightness)-50) / 100;
1857 if (m_Contrast != CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast)
1858 m_Procamp.contrast = (float)((CMediaSettings::Get().GetCurrentVideoSettings().m_Contrast)+50) / 100;
1860 VdpColorStandard colorStandard;
1861 switch(m_mixerInput[1].DVDPic.color_matrix)
1863 case AVCOL_SPC_BT709:
1864 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_709;
1866 case AVCOL_SPC_BT470BG:
1867 case AVCOL_SPC_SMPTE170M:
1868 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_601;
1870 case AVCOL_SPC_SMPTE240M:
1871 colorStandard = VDP_COLOR_STANDARD_SMPTE_240M;
1874 case AVCOL_SPC_UNSPECIFIED:
1877 if(m_config.surfaceWidth > 1000)
1878 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_709;
1880 colorStandard = VDP_COLOR_STANDARD_ITUR_BT_601;
1883 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX };
1884 if (CSettings::Get().GetBool("videoscreen.limitedrange"))
1886 float studioCSC[3][4];
1887 GenerateStudioCSCMatrix(colorStandard, studioCSC);
1888 void const * pm_CSCMatix[] = { &studioCSC };
1889 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
1893 vdp_st = m_config.context->GetProcs().vdp_generate_csc_matrix(&m_Procamp, colorStandard, &m_CSCMatrix);
1894 void const * pm_CSCMatix[] = { &m_CSCMatrix };
1895 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, pm_CSCMatix);
1898 CheckStatus(vdp_st, __LINE__);
1901 void CMixer::SetNoiseReduction()
1903 if(!m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION))
1906 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION };
1907 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL };
1910 if (!CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction)
1912 VdpBool enabled[]= {0};
1913 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1914 CheckStatus(vdp_st, __LINE__);
1917 VdpBool enabled[]={1};
1918 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1919 CheckStatus(vdp_st, __LINE__);
1920 void* nr[] = { &CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction };
1921 CLog::Log(LOGNOTICE,"Setting Noise Reduction to %f",CMediaSettings::Get().GetCurrentVideoSettings().m_NoiseReduction);
1922 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, nr);
1923 CheckStatus(vdp_st, __LINE__);
1926 void CMixer::SetSharpness()
1928 if(!m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_SHARPNESS))
1931 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_SHARPNESS };
1932 VdpVideoMixerAttribute attributes[] = { VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL };
1935 if (!CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness)
1937 VdpBool enabled[]={0};
1938 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1939 CheckStatus(vdp_st, __LINE__);
1942 VdpBool enabled[]={1};
1943 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
1944 CheckStatus(vdp_st, __LINE__);
1945 void* sh[] = { &CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness };
1946 CLog::Log(LOGNOTICE,"Setting Sharpness to %f",CMediaSettings::Get().GetCurrentVideoSettings().m_Sharpness);
1947 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attributes), attributes, sh);
1948 CheckStatus(vdp_st, __LINE__);
1951 EINTERLACEMETHOD CMixer::GetDeinterlacingMethod(bool log /* = false */)
1953 EINTERLACEMETHOD method = CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod;
1954 if (method == VS_INTERLACEMETHOD_AUTO)
1957 // if (m_config.outHeight >= 720)
1958 // deint = g_advancedSettings.m_videoVDPAUdeintHD;
1960 // deint = g_advancedSettings.m_videoVDPAUdeintSD;
1964 if (m_config.vdpau->Supports(EINTERLACEMETHOD(deint)))
1966 method = EINTERLACEMETHOD(deint);
1968 CLog::Log(LOGNOTICE, "CVDPAU::GetDeinterlacingMethod: set de-interlacing to %d", deint);
1973 CLog::Log(LOGWARNING, "CVDPAU::GetDeinterlacingMethod: method for de-interlacing (advanced settings) not supported");
1980 void CMixer::SetDeinterlacing()
1984 if (m_videoMixer == VDP_INVALID_HANDLE)
1987 EDEINTERLACEMODE mode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
1988 EINTERLACEMETHOD method = GetDeinterlacingMethod(true);
1990 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL,
1991 VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL,
1992 VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE };
1994 if (mode == VS_DEINTERLACEMODE_OFF)
1996 VdpBool enabled[] = {0,0,0};
1997 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2001 if (method == VS_INTERLACEMETHOD_AUTO)
2003 VdpBool enabled[] = {1,0,0};
2004 if (g_advancedSettings.m_videoVDPAUtelecine)
2006 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2008 else if (method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL
2009 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF)
2011 VdpBool enabled[] = {1,0,0};
2012 if (g_advancedSettings.m_videoVDPAUtelecine)
2014 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2016 else if (method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL
2017 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF)
2019 VdpBool enabled[] = {1,1,0};
2020 if (g_advancedSettings.m_videoVDPAUtelecine)
2022 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2026 VdpBool enabled[]={0,0,0};
2027 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2030 CheckStatus(vdp_st, __LINE__);
2032 SetDeintSkipChroma();
2034 m_config.useInteropYuv = !CSettings::Get().GetBool("videoplayer.usevdpaumixer");
2037 void CMixer::SetDeintSkipChroma()
2039 VdpVideoMixerAttribute attribute[] = { VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE};
2043 if (g_advancedSettings.m_videoVDPAUdeintSkipChromaHD && m_config.outHeight >= 720)
2048 void const *values[]={&val};
2049 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_attribute_values(m_videoMixer, ARSIZE(attribute), attribute, values);
2051 CheckStatus(vdp_st, __LINE__);
2054 void CMixer::SetHWUpscaling()
2056 #ifdef VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
2059 VdpBool enabled[]={1};
2060 switch (m_config.upscale)
2063 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9))
2065 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9 };
2066 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2070 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8))
2072 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8 };
2073 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2077 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7))
2079 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7 };
2080 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2084 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6))
2086 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6 };
2087 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2091 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5))
2093 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5 };
2094 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2098 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4))
2100 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4 };
2101 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2105 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3))
2107 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3 };
2108 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2112 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2))
2114 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2 };
2115 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2119 if (m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1))
2121 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 };
2122 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2129 CheckStatus(vdp_st, __LINE__);
2133 void CMixer::DisableHQScaling()
2137 if (m_videoMixer == VDP_INVALID_HANDLE)
2140 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1))
2142 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 };
2143 VdpBool enabled[]={0};
2144 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2145 CheckStatus(vdp_st, __LINE__);
2148 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2))
2150 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L2 };
2151 VdpBool enabled[]={0};
2152 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2153 CheckStatus(vdp_st, __LINE__);
2156 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3))
2158 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L3 };
2159 VdpBool enabled[]={0};
2160 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2161 CheckStatus(vdp_st, __LINE__);
2164 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4))
2166 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L4 };
2167 VdpBool enabled[]={0};
2168 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2169 CheckStatus(vdp_st, __LINE__);
2172 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5))
2174 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L5 };
2175 VdpBool enabled[]={0};
2176 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2177 CheckStatus(vdp_st, __LINE__);
2180 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6))
2182 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L6 };
2183 VdpBool enabled[]={0};
2184 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2185 CheckStatus(vdp_st, __LINE__);
2188 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7))
2190 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L7 };
2191 VdpBool enabled[]={0};
2192 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2193 CheckStatus(vdp_st, __LINE__);
2196 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8))
2198 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L8 };
2199 VdpBool enabled[]={0};
2200 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2201 CheckStatus(vdp_st, __LINE__);
2204 if(m_config.vdpau->Supports(VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9))
2206 VdpVideoMixerFeature feature[] = { VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L9 };
2207 VdpBool enabled[]={0};
2208 vdp_st = m_config.context->GetProcs().vdp_video_mixer_set_feature_enables(m_videoMixer, ARSIZE(feature), feature, enabled);
2209 CheckStatus(vdp_st, __LINE__);
2217 m_NoiseReduction = 0.0;
2222 m_SeenInterlaceFlag = false;
2227 m_config.upscale = g_advancedSettings.m_videoVDPAUScaling;
2228 m_config.useInteropYuv = !CSettings::Get().GetBool("videoplayer.usevdpaumixer");
2233 void CMixer::Uninit()
2236 while (!m_outputSurfaces.empty())
2238 m_outputSurfaces.pop();
2240 m_config.context->GetProcs().vdp_video_mixer_destroy(m_videoMixer);
2243 void CMixer::Flush()
2245 while (!m_mixerInput.empty())
2247 CVdpauDecodedPicture pic = m_mixerInput.back();
2248 m_mixerInput.pop_back();
2249 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2251 while (!m_decodedPics.empty())
2253 CVdpauDecodedPicture pic = m_decodedPics.front();
2254 m_decodedPics.pop();
2255 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2258 while (m_dataPort.ReceiveOutMessage(&msg))
2260 if (msg->signal == CMixerDataProtocol::FRAME)
2262 CVdpauDecodedPicture pic = *(CVdpauDecodedPicture*)msg->data;
2263 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2265 else if (msg->signal == CMixerDataProtocol::BUFFER)
2267 VdpOutputSurface *surf;
2268 surf = (VdpOutputSurface*)msg->data;
2269 m_outputSurfaces.push(*surf);
2275 void CMixer::InitCycle()
2280 m_config.stats->GetParams(latency, flags);
2282 if (0) //flags & DVP_FLAG_NO_POSTPROC)
2283 SetPostProcFeatures(false);
2285 SetPostProcFeatures(true);
2287 m_config.stats->SetCanSkipDeint(false);
2289 EDEINTERLACEMODE mode = CMediaSettings::Get().GetCurrentVideoSettings().m_DeinterlaceMode;
2290 EINTERLACEMETHOD method = GetDeinterlacingMethod();
2291 bool interlaced = m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_INTERLACED;
2292 m_SeenInterlaceFlag |= interlaced;
2295 if (//!(flags & DVP_FLAG_NO_POSTPROC) &&
2296 (mode == VS_DEINTERLACEMODE_FORCE ||
2297 (mode == VS_DEINTERLACEMODE_AUTO && interlaced)))
2299 if((method == VS_INTERLACEMETHOD_AUTO && interlaced)
2300 || method == VS_INTERLACEMETHOD_VDPAU_BOB
2301 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL
2302 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF
2303 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL
2304 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF
2305 || method == VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE )
2307 if(method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_HALF
2308 || method == VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL_HALF
2309 || !g_graphicsContext.IsFullScreenVideo())
2314 m_config.stats->SetCanSkipDeint(true);
2318 if (0) //m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_DROPDEINT)
2323 if(m_mixerInput[1].DVDPic.iFlags & DVP_FLAG_TOP_FIELD_FIRST)
2324 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
2326 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
2328 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2329 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2330 DVP_FLAG_REPEAT_TOP_FIELD |
2331 DVP_FLAG_INTERLACED);
2332 m_config.useInteropYuv = false;
2334 else if (method == VS_INTERLACEMETHOD_RENDER_BOB)
2337 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2338 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU_420;
2339 m_config.useInteropYuv = true;
2343 CLog::Log(LOGERROR, "CMixer::%s - interlace method: %d not supported, setting to AUTO", __FUNCTION__, method);
2345 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2346 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU;
2347 m_mixerInput[1].DVDPic.iFlags &= ~(DVP_FLAG_TOP_FIELD_FIRST |
2348 DVP_FLAG_REPEAT_TOP_FIELD |
2349 DVP_FLAG_INTERLACED);
2351 CMediaSettings::Get().GetCurrentVideoSettings().m_InterlaceMethod = VS_INTERLACEMETHOD_AUTO;
2357 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
2359 if (m_config.useInteropYuv)
2360 m_mixerInput[1].DVDPic.format = RENDER_FMT_VDPAU_420;
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);
2371 if (m_mixerInput[1].DVDPic.format == RENDER_FMT_VDPAU)
2373 m_processPicture.outputSurface = m_outputSurfaces.front();
2374 m_mixerInput[1].DVDPic.iWidth = m_config.outWidth;
2375 m_mixerInput[1].DVDPic.iHeight = m_config.outHeight;
2376 if (m_SeenInterlaceFlag)
2378 double ratio = (double)m_mixerInput[1].DVDPic.iDisplayHeight / m_mixerInput[1].DVDPic.iHeight;
2379 m_mixerInput[1].DVDPic.iHeight -= 6;
2380 m_mixerInput[1].DVDPic.iDisplayHeight = lrint(ratio*m_mixerInput[1].DVDPic.iHeight);
2385 m_mixerInput[1].DVDPic.iWidth = m_config.vidWidth;
2386 m_mixerInput[1].DVDPic.iHeight = m_config.vidHeight;
2389 m_processPicture.DVDPic = m_mixerInput[1].DVDPic;
2390 m_processPicture.videoSurface = m_mixerInput[1].videoSurface;
2393 void CMixer::FiniCycle()
2395 // Keep video surfaces for one 2 cycles longer than used
2396 // by mixer. This avoids blocking in decoder.
2397 // NVidia recommends num_ref + 5
2398 while (m_mixerInput.size() > 5)
2400 CVdpauDecodedPicture &tmp = m_mixerInput.back();
2401 if (m_processPicture.DVDPic.format != RENDER_FMT_VDPAU_420)
2403 m_config.videoSurfaces->ClearRender(tmp.videoSurface);
2405 m_mixerInput.pop_back();
2409 void CMixer::ProcessPicture()
2411 if (m_processPicture.DVDPic.format == RENDER_FMT_VDPAU_420)
2416 if (m_mixerstep == 1)
2418 if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD)
2419 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD;
2421 m_mixerfield = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
2424 VdpVideoSurface past_surfaces[4] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
2425 VdpVideoSurface futu_surfaces[2] = { VDP_INVALID_HANDLE, VDP_INVALID_HANDLE };
2426 uint32_t pastCount = 4;
2427 uint32_t futuCount = 2;
2429 if(m_mixerfield == VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME)
2431 // use only 2 past 1 future for progressive/weave
2432 // (only used for postproc anyway eg noise reduction)
2433 if (m_mixerInput.size() > 3)
2434 past_surfaces[1] = m_mixerInput[3].videoSurface;
2435 if (m_mixerInput.size() > 2)
2436 past_surfaces[0] = m_mixerInput[2].videoSurface;
2437 futu_surfaces[0] = m_mixerInput[0].videoSurface;
2443 if(m_mixerstep == 0)
2445 if (m_mixerInput.size() > 3)
2447 past_surfaces[3] = m_mixerInput[3].videoSurface;
2448 past_surfaces[2] = m_mixerInput[3].videoSurface;
2450 if (m_mixerInput.size() > 2)
2452 past_surfaces[1] = m_mixerInput[2].videoSurface;
2453 past_surfaces[0] = m_mixerInput[2].videoSurface;
2455 futu_surfaces[0] = m_mixerInput[1].videoSurface;
2456 futu_surfaces[1] = m_mixerInput[0].videoSurface;
2460 if (m_mixerInput.size() > 3)
2462 past_surfaces[3] = m_mixerInput[3].videoSurface;
2464 if (m_mixerInput.size() > 2)
2466 past_surfaces[2] = m_mixerInput[2].videoSurface;
2467 past_surfaces[1] = m_mixerInput[2].videoSurface;
2469 past_surfaces[0] = m_mixerInput[1].videoSurface;
2470 futu_surfaces[0] = m_mixerInput[0].videoSurface;
2471 futu_surfaces[1] = m_mixerInput[0].videoSurface;
2473 if (m_mixerInput[0].DVDPic.pts != DVD_NOPTS_VALUE &&
2474 m_mixerInput[1].DVDPic.pts != DVD_NOPTS_VALUE)
2476 m_processPicture.DVDPic.pts = m_mixerInput[1].DVDPic.pts +
2477 (m_mixerInput[0].DVDPic.pts -
2478 m_mixerInput[1].DVDPic.pts) / 2;
2481 m_processPicture.DVDPic.pts = DVD_NOPTS_VALUE;
2482 m_processPicture.DVDPic.dts = DVD_NOPTS_VALUE;
2484 m_processPicture.DVDPic.iRepeatPicture = 0.0;
2490 sourceRect.x1 = m_config.vidWidth;
2491 sourceRect.y1 = m_config.vidHeight;
2496 destRect.x1 = m_config.outWidth;
2497 destRect.y1 = m_config.outHeight;
2499 // start vdpau video mixer
2500 vdp_st = m_config.context->GetProcs().vdp_video_mixer_render(m_videoMixer,
2506 m_mixerInput[1].videoSurface,
2510 m_processPicture.outputSurface,
2515 CheckStatus(vdp_st, __LINE__);
2519 bool CMixer::CheckStatus(VdpStatus vdp_st, int line)
2521 if (vdp_st != VDP_STATUS_OK)
2523 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);
2530 //-----------------------------------------------------------------------------
2532 //-----------------------------------------------------------------------------
2534 VdpauBufferPool::VdpauBufferPool()
2536 CVdpauRenderPicture *pic;
2537 for (unsigned int i = 0; i < NUM_RENDER_PICS; i++)
2539 pic = new CVdpauRenderPicture(renderPicSec);
2540 allRenderPics.push_back(pic);
2544 VdpauBufferPool::~VdpauBufferPool()
2546 CVdpauRenderPicture *pic;
2547 for (unsigned int i = 0; i < NUM_RENDER_PICS; i++)
2549 pic = allRenderPics[i];
2552 allRenderPics.clear();
2555 //-----------------------------------------------------------------------------
2557 //-----------------------------------------------------------------------------
2558 COutput::COutput(CEvent *inMsgEvent) :
2559 CThread("Vdpau Output"),
2560 m_controlPort("OutputControlPort", inMsgEvent, &m_outMsgEvent),
2561 m_dataPort("OutputDataPort", inMsgEvent, &m_outMsgEvent),
2562 m_mixer(&m_outMsgEvent)
2564 m_inMsgEvent = inMsgEvent;
2566 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); ++i)
2568 m_bufferPool.freeRenderPics.push_back(i);
2572 void COutput::Start()
2581 m_bufferPool.freeRenderPics.clear();
2582 m_bufferPool.usedRenderPics.clear();
2585 void COutput::Dispose()
2587 CSingleLock lock(g_graphicsContext);
2589 m_outMsgEvent.Set();
2591 m_controlPort.Purge();
2595 void COutput::OnStartup()
2597 CLog::Log(LOGNOTICE, "COutput::OnStartup: Output Thread created");
2600 void COutput::OnExit()
2602 CLog::Log(LOGNOTICE, "COutput::OnExit: Output Thread terminated");
2609 O_TOP_UNCONFIGURED, // 2
2610 O_TOP_CONFIGURED, // 3
2611 O_TOP_CONFIGURED_IDLE, // 4
2612 O_TOP_CONFIGURED_WORK, // 5
2615 int VDPAU_OUTPUT_parentStates[] = {
2618 0, //TOP_UNCONFIGURED
2620 3, //TOP_CONFIGURED_IDLE
2621 3, //TOP_CONFIGURED_WORK
2624 void COutput::StateMachine(int signal, Protocol *port, Message *msg)
2626 for (int state = m_state; ; state = VDPAU_OUTPUT_parentStates[state])
2631 if (port == &m_controlPort)
2635 case COutputControlProtocol::FLUSH:
2636 msg->Reply(COutputControlProtocol::ACC);
2638 case COutputControlProtocol::PRECLEANUP:
2639 msg->Reply(COutputControlProtocol::ACC);
2645 else if (port == &m_dataPort)
2649 case COutputDataProtocol::RETURNPIC:
2650 CVdpauRenderPicture *pic;
2651 pic = *((CVdpauRenderPicture**)msg->data);
2652 QueueReturnPicture(pic);
2659 std::string portName = port == NULL ? "timer" : port->portName;
2660 CLog::Log(LOGWARNING, "COutput::%s - signal: %d form port: %s not handled for state: %d", __FUNCTION__, signal, portName.c_str(), m_state);
2667 case O_TOP_UNCONFIGURED:
2668 if (port == &m_controlPort)
2672 case COutputControlProtocol::INIT:
2674 data = (CVdpauConfig*)msg->data;
2681 if (m_mixer.m_controlPort.SendOutMessageSync(CMixerControlProtocol::INIT,
2682 &reply, 1000, &m_config, sizeof(m_config)))
2684 if (reply->signal != CMixerControlProtocol::ACC)
2689 // set initial number of
2690 m_bufferPool.numOutputSurfaces = 4;
2694 m_state = O_TOP_CONFIGURED_IDLE;
2695 msg->Reply(COutputControlProtocol::ACC, &m_config, sizeof(m_config));
2699 m_state = O_TOP_ERROR;
2700 msg->Reply(COutputControlProtocol::ERROR);
2709 case O_TOP_CONFIGURED:
2710 if (port == &m_controlPort)
2714 case COutputControlProtocol::FLUSH:
2716 msg->Reply(COutputControlProtocol::ACC);
2718 case COutputControlProtocol::PRECLEANUP:
2721 msg->Reply(COutputControlProtocol::ACC);
2727 else if (port == &m_dataPort)
2731 case COutputDataProtocol::NEWFRAME:
2732 CVdpauDecodedPicture *frame;
2733 frame = (CVdpauDecodedPicture*)msg->data;
2736 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::FRAME,
2737 frame,sizeof(CVdpauDecodedPicture));
2740 case COutputDataProtocol::RETURNPIC:
2741 CVdpauRenderPicture *pic;
2742 pic = *((CVdpauRenderPicture**)msg->data);
2743 QueueReturnPicture(pic);
2744 m_controlPort.SendInMessage(COutputControlProtocol::STATS);
2745 m_state = O_TOP_CONFIGURED_WORK;
2752 else if (port == &m_mixer.m_dataPort)
2756 case CMixerDataProtocol::PICTURE:
2757 CVdpauProcessedPicture *pic;
2758 pic = (CVdpauProcessedPicture*)msg->data;
2759 m_bufferPool.processedPics.push(*pic);
2760 m_state = O_TOP_CONFIGURED_WORK;
2769 case O_TOP_CONFIGURED_IDLE:
2770 if (port == NULL) // timeout
2774 case COutputControlProtocol::TIMEOUT:
2775 if (ProcessSyncPicture())
2781 m_state = O_TOP_CONFIGURED_WORK;
2791 case O_TOP_CONFIGURED_WORK:
2792 if (port == NULL) // timeout
2796 case COutputControlProtocol::TIMEOUT:
2799 CVdpauRenderPicture *pic;
2800 pic = ProcessMixerPicture();
2803 m_config.stats->DecProcessed();
2804 m_config.stats->IncRender();
2805 m_dataPort.SendInMessage(COutputDataProtocol::PICTURE, &pic, sizeof(pic));
2811 m_state = O_TOP_CONFIGURED_IDLE;
2821 default: // we are in no state, should not happen
2822 CLog::Log(LOGERROR, "COutput::%s - no valid state: %d", __FUNCTION__, m_state);
2828 void COutput::Process()
2830 Message *msg = NULL;
2831 Protocol *port = NULL;
2834 m_state = O_TOP_UNCONFIGURED;
2835 m_extTimeout = 1000;
2836 m_bStateMachineSelfTrigger = false;
2842 if (m_bStateMachineSelfTrigger)
2844 m_bStateMachineSelfTrigger = false;
2845 // self trigger state machine
2846 StateMachine(msg->signal, port, msg);
2847 if (!m_bStateMachineSelfTrigger)
2854 // check control port
2855 else if (m_controlPort.ReceiveOutMessage(&msg))
2858 port = &m_controlPort;
2861 else if (m_dataPort.ReceiveOutMessage(&msg))
2866 // check mixer data port
2867 else if (m_mixer.m_dataPort.ReceiveInMessage(&msg))
2870 port = &m_mixer.m_dataPort;
2874 StateMachine(msg->signal, port, msg);
2875 if (!m_bStateMachineSelfTrigger)
2884 else if (m_outMsgEvent.WaitMSec(m_extTimeout))
2891 msg = m_controlPort.GetMessage();
2892 msg->signal = COutputControlProtocol::TIMEOUT;
2894 // signal timeout to state machine
2895 StateMachine(msg->signal, port, msg);
2896 if (!m_bStateMachineSelfTrigger)
2907 bool COutput::Init()
2909 if (!CreateGlxContext())
2921 bool COutput::Uninit()
2925 ReleaseBufferPool();
2926 DestroyGlxContext();
2930 void COutput::Flush()
2932 if (m_mixer.IsActive())
2935 if (m_mixer.m_controlPort.SendOutMessageSync(CMixerControlProtocol::FLUSH,
2942 CLog::Log(LOGERROR, "Coutput::%s - failed to flush mixer", __FUNCTION__);
2946 while (m_mixer.m_dataPort.ReceiveInMessage(&msg))
2948 if (msg->signal == CMixerDataProtocol::PICTURE)
2950 CVdpauProcessedPicture pic = *(CVdpauProcessedPicture*)msg->data;
2951 m_bufferPool.processedPics.push(pic);
2956 while (m_dataPort.ReceiveOutMessage(&msg))
2958 if (msg->signal == COutputDataProtocol::NEWFRAME)
2960 CVdpauDecodedPicture pic = *(CVdpauDecodedPicture*)msg->data;
2961 m_config.videoSurfaces->ClearRender(pic.videoSurface);
2963 else if (msg->signal == COutputDataProtocol::RETURNPIC)
2965 CVdpauRenderPicture *pic;
2966 pic = *((CVdpauRenderPicture**)msg->data);
2967 QueueReturnPicture(pic);
2972 while (m_dataPort.ReceiveInMessage(&msg))
2974 if (msg->signal == COutputDataProtocol::PICTURE)
2976 CVdpauRenderPicture *pic;
2977 pic = *((CVdpauRenderPicture**)msg->data);
2978 QueueReturnPicture(pic);
2982 // reset used render flag which was cleared on mixer flush
2983 std::deque<int>::iterator it;
2984 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
2986 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[*it];
2987 if (pic->DVDPic.format == RENDER_FMT_VDPAU_420)
2989 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it2;
2990 it2 = m_bufferPool.glVideoSurfaceMap.find(pic->sourceIdx);
2991 if (it2 == m_bufferPool.glVideoSurfaceMap.end())
2993 CLog::Log(LOGDEBUG, "COutput::Flush - gl surface not found");
2996 m_config.videoSurfaces->MarkRender(it2->second.sourceVuv);
3000 // clear processed pics
3001 while(!m_bufferPool.processedPics.empty())
3003 CVdpauProcessedPicture procPic = m_bufferPool.processedPics.front();
3004 if (procPic.DVDPic.format == RENDER_FMT_VDPAU)
3006 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER, &procPic.outputSurface, sizeof(procPic.outputSurface));
3008 else if (procPic.DVDPic.format == RENDER_FMT_VDPAU_420)
3010 m_config.videoSurfaces->ClearRender(procPic.videoSurface);
3012 m_bufferPool.processedPics.pop();
3016 bool COutput::HasWork()
3018 if (!m_bufferPool.processedPics.empty() && !m_bufferPool.freeRenderPics.empty())
3023 CVdpauRenderPicture* COutput::ProcessMixerPicture()
3025 CVdpauRenderPicture *retPic = NULL;
3027 if (!m_bufferPool.processedPics.empty() && !m_bufferPool.freeRenderPics.empty())
3029 int idx = m_bufferPool.freeRenderPics.front();
3030 retPic = m_bufferPool.allRenderPics[idx];
3031 m_bufferPool.freeRenderPics.pop_front();
3032 m_bufferPool.usedRenderPics.push_back(idx);
3033 CVdpauProcessedPicture procPic = m_bufferPool.processedPics.front();
3034 m_bufferPool.processedPics.pop();
3036 retPic->DVDPic = procPic.DVDPic;
3037 retPic->valid = true;
3038 if (retPic->DVDPic.format == RENDER_FMT_VDPAU)
3040 m_config.useInteropYuv = false;
3041 m_bufferPool.numOutputSurfaces = NUM_RENDER_PICS;
3044 retPic->sourceIdx = procPic.outputSurface;
3045 retPic->texture[0] = m_bufferPool.glOutputSurfaceMap[procPic.outputSurface].texture[0];
3046 retPic->texWidth = m_config.outWidth;
3047 retPic->texHeight = m_config.outHeight;
3048 retPic->crop.x1 = 0;
3049 retPic->crop.y1 = (m_config.outHeight - retPic->DVDPic.iHeight) / 2;
3050 retPic->crop.x2 = m_config.outWidth;
3051 retPic->crop.y2 = m_config.outHeight - retPic->crop.y1;
3055 m_config.useInteropYuv = true;
3057 retPic->sourceIdx = procPic.videoSurface;
3058 for (unsigned int i=0; i<4; ++i)
3059 retPic->texture[i] = m_bufferPool.glVideoSurfaceMap[procPic.videoSurface].texture[i];
3060 retPic->texWidth = m_config.surfaceWidth;
3061 retPic->texHeight = m_config.surfaceHeight;
3062 retPic->crop.x1 = 0;
3063 retPic->crop.y1 = 0;
3064 retPic->crop.x2 = m_config.surfaceWidth - m_config.vidWidth;
3065 retPic->crop.y2 = m_config.surfaceHeight - m_config.vidHeight;
3071 void COutput::QueueReturnPicture(CVdpauRenderPicture *pic)
3073 std::deque<int>::iterator it;
3074 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3076 if (m_bufferPool.allRenderPics[*it] == pic)
3082 if (it == m_bufferPool.usedRenderPics.end())
3084 CLog::Log(LOGWARNING, "COutput::QueueReturnPicture - pic not found");
3088 // check if already queued
3089 std::deque<int>::iterator it2 = find(m_bufferPool.syncRenderPics.begin(),
3090 m_bufferPool.syncRenderPics.end(),
3092 if (it2 == m_bufferPool.syncRenderPics.end())
3094 m_bufferPool.syncRenderPics.push_back(*it);
3097 ProcessSyncPicture();
3100 bool COutput::ProcessSyncPicture()
3102 CVdpauRenderPicture *pic;
3105 std::deque<int>::iterator it;
3106 for (it = m_bufferPool.syncRenderPics.begin(); it != m_bufferPool.syncRenderPics.end(); )
3108 pic = m_bufferPool.allRenderPics[*it];
3113 if (glIsSync(pic->fence))
3117 glGetSynciv(pic->fence, GL_SYNC_STATUS, 1, &length, &state);
3118 if(state == GL_SIGNALED)
3120 glDeleteSync(pic->fence);
3133 m_bufferPool.freeRenderPics.push_back(*it);
3135 std::deque<int>::iterator it2 = find(m_bufferPool.usedRenderPics.begin(),
3136 m_bufferPool.usedRenderPics.end(),
3138 if (it2 == m_bufferPool.usedRenderPics.end())
3140 CLog::Log(LOGERROR, "COutput::ProcessSyncPicture - pic not found in queue");
3144 m_bufferPool.usedRenderPics.erase(it2);
3146 it = m_bufferPool.syncRenderPics.erase(it);
3150 ProcessReturnPicture(pic);
3154 CLog::Log(LOGDEBUG, "COutput::%s - return of invalid render pic", __FUNCTION__);
3160 void COutput::ProcessReturnPicture(CVdpauRenderPicture *pic)
3162 if (pic->DVDPic.format == RENDER_FMT_VDPAU_420)
3164 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3165 it = m_bufferPool.glVideoSurfaceMap.find(pic->sourceIdx);
3166 if (it == m_bufferPool.glVideoSurfaceMap.end())
3168 CLog::Log(LOGDEBUG, "COutput::ProcessReturnPicture - gl surface not found");
3171 VdpVideoSurface surf = it->second.sourceVuv;
3172 m_config.videoSurfaces->ClearRender(surf);
3174 else if (pic->DVDPic.format == RENDER_FMT_VDPAU)
3176 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3177 it = m_bufferPool.glOutputSurfaceMap.find(pic->sourceIdx);
3178 if (it == m_bufferPool.glOutputSurfaceMap.end())
3180 CLog::Log(LOGDEBUG, "COutput::ProcessReturnPicture - gl surface not found");
3183 VdpOutputSurface outSurf = it->second.sourceRgb;
3184 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER, &outSurf, sizeof(outSurf));
3188 bool COutput::EnsureBufferPool()
3192 // Creation of outputSurfaces
3193 VdpOutputSurface outputSurface;
3194 for (int i = m_bufferPool.outputSurfaces.size(); i < m_bufferPool.numOutputSurfaces; i++)
3196 vdp_st = m_config.context->GetProcs().vdp_output_surface_create(m_config.context->GetDevice(),
3197 VDP_RGBA_FORMAT_B8G8R8A8,
3201 if (CheckStatus(vdp_st, __LINE__))
3203 m_bufferPool.outputSurfaces.push_back(outputSurface);
3205 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER,
3207 sizeof(VdpOutputSurface));
3208 CLog::Log(LOGNOTICE, "VDPAU::COutput::InitBufferPool - Output Surface created");
3213 void COutput::ReleaseBufferPool()
3217 CSingleLock lock(m_bufferPool.renderPicSec);
3219 // release all output surfaces
3220 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3222 if (m_bufferPool.outputSurfaces[i] == VDP_INVALID_HANDLE)
3224 vdp_st = m_config.context->GetProcs().vdp_output_surface_destroy(m_bufferPool.outputSurfaces[i]);
3225 CheckStatus(vdp_st, __LINE__);
3227 m_bufferPool.outputSurfaces.clear();
3229 // wait for all fences
3230 XbmcThreads::EndTime timeout(1000);
3231 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); i++)
3233 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[i];
3237 while (glIsSync(pic->fence))
3241 glGetSynciv(pic->fence, GL_SYNC_STATUS, 1, &length, &state);
3242 if(state == GL_SIGNALED || timeout.IsTimePast())
3244 glDeleteSync(pic->fence);
3255 if (timeout.IsTimePast())
3257 CLog::Log(LOGERROR, "COutput::%s - timeout waiting for fence", __FUNCTION__);
3259 ProcessSyncPicture();
3261 // invalidate all used render pictures
3262 for (unsigned int i = 0; i < m_bufferPool.usedRenderPics.size(); ++i)
3264 CVdpauRenderPicture *pic = m_bufferPool.allRenderPics[m_bufferPool.usedRenderPics[i]];
3269 void COutput::PreCleanup()
3275 ProcessSyncPicture();
3277 CSingleLock lock(m_bufferPool.renderPicSec);
3278 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3280 if (m_bufferPool.outputSurfaces[i] == VDP_INVALID_HANDLE)
3283 // check if output surface is in use
3285 std::deque<int>::iterator it;
3286 CVdpauRenderPicture *pic;
3287 for (it = m_bufferPool.usedRenderPics.begin(); it != m_bufferPool.usedRenderPics.end(); ++it)
3289 pic = m_bufferPool.allRenderPics[*it];
3290 if ((pic->sourceIdx == m_bufferPool.outputSurfaces[i]) && pic->valid)
3299 #ifdef GL_NV_vdpau_interop
3301 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it_map;
3302 it_map = m_bufferPool.glOutputSurfaceMap.find(m_bufferPool.outputSurfaces[i]);
3303 if (it_map == m_bufferPool.glOutputSurfaceMap.end())
3305 CLog::Log(LOGERROR, "%s - could not find gl surface", __FUNCTION__);
3308 glVDPAUUnregisterSurfaceNV(it_map->second.glVdpauSurface);
3309 glDeleteTextures(1, it_map->second.texture);
3310 m_bufferPool.glOutputSurfaceMap.erase(it_map);
3313 vdp_st = m_config.context->GetProcs().vdp_output_surface_destroy(m_bufferPool.outputSurfaces[i]);
3314 CheckStatus(vdp_st, __LINE__);
3316 m_bufferPool.outputSurfaces[i] = VDP_INVALID_HANDLE;
3318 CLog::Log(LOGDEBUG, "VDPAU::PreCleanup - released output surface");
3323 void COutput::InitMixer()
3325 for (unsigned int i = 0; i < m_bufferPool.outputSurfaces.size(); ++i)
3327 m_mixer.m_dataPort.SendOutMessage(CMixerDataProtocol::BUFFER,
3328 &m_bufferPool.outputSurfaces[i],
3329 sizeof(VdpOutputSurface));
3333 bool COutput::GLInit()
3335 #ifdef GL_NV_vdpau_interop
3336 glVDPAUInitNV = NULL;
3337 glVDPAUFiniNV = NULL;
3338 glVDPAURegisterOutputSurfaceNV = NULL;
3339 glVDPAURegisterVideoSurfaceNV = NULL;
3340 glVDPAUIsSurfaceNV = NULL;
3341 glVDPAUUnregisterSurfaceNV = NULL;
3342 glVDPAUSurfaceAccessNV = NULL;
3343 glVDPAUMapSurfacesNV = NULL;
3344 glVDPAUUnmapSurfacesNV = NULL;
3345 glVDPAUGetSurfaceivNV = NULL;
3348 #ifdef GL_NV_vdpau_interop
3350 glVDPAUInitNV = (PFNGLVDPAUINITNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUInitNV");
3352 glVDPAUFiniNV = (PFNGLVDPAUFININVPROC)glXGetProcAddress((GLubyte *) "glVDPAUFiniNV");
3353 if (!glVDPAURegisterOutputSurfaceNV)
3354 glVDPAURegisterOutputSurfaceNV = (PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAURegisterOutputSurfaceNV");
3355 if (!glVDPAURegisterVideoSurfaceNV)
3356 glVDPAURegisterVideoSurfaceNV = (PFNGLVDPAUREGISTERVIDEOSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAURegisterVideoSurfaceNV");
3357 if (!glVDPAUIsSurfaceNV)
3358 glVDPAUIsSurfaceNV = (PFNGLVDPAUISSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAUIsSurfaceNV");
3359 if (!glVDPAUUnregisterSurfaceNV)
3360 glVDPAUUnregisterSurfaceNV = (PFNGLVDPAUUNREGISTERSURFACENVPROC)glXGetProcAddress((GLubyte *) "glVDPAUUnregisterSurfaceNV");
3361 if (!glVDPAUSurfaceAccessNV)
3362 glVDPAUSurfaceAccessNV = (PFNGLVDPAUSURFACEACCESSNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUSurfaceAccessNV");
3363 if (!glVDPAUMapSurfacesNV)
3364 glVDPAUMapSurfacesNV = (PFNGLVDPAUMAPSURFACESNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUMapSurfacesNV");
3365 if (!glVDPAUUnmapSurfacesNV)
3366 glVDPAUUnmapSurfacesNV = (PFNGLVDPAUUNMAPSURFACESNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUUnmapSurfacesNV");
3367 if (!glVDPAUGetSurfaceivNV)
3368 glVDPAUGetSurfaceivNV = (PFNGLVDPAUGETSURFACEIVNVPROC)glXGetProcAddress((GLubyte *) "glVDPAUGetSurfaceivNV");
3370 while (glGetError() != GL_NO_ERROR);
3371 glVDPAUInitNV(reinterpret_cast<void*>(m_config.context->GetDevice()), reinterpret_cast<void*>(m_config.context->GetProcs().vdp_get_proc_address));
3372 if (glGetError() != GL_NO_ERROR)
3374 CLog::Log(LOGERROR, "VDPAU::COutput - GLInitInterop glVDPAUInitNV failed");
3378 CLog::Log(LOGNOTICE, "VDPAU::COutput: vdpau gl interop initialized");
3382 bool hasfence = glewIsSupported("GL_ARB_sync");
3383 for (unsigned int i = 0; i < m_bufferPool.allRenderPics.size(); i++)
3385 m_bufferPool.allRenderPics[i]->usefence = hasfence;
3392 void COutput::GLMapSurfaces()
3394 #ifdef GL_NV_vdpau_interop
3396 if (m_config.useInteropYuv)
3398 VdpauBufferPool::GLVideoSurface glSurface;
3399 VdpVideoSurface surf;
3400 if (m_config.videoSurfaces->Size() != m_bufferPool.glVideoSurfaceMap.size())
3402 for (unsigned int i = 0; i < m_config.videoSurfaces->Size(); i++)
3404 surf = m_config.videoSurfaces->GetAtIndex(i);
3406 if (surf == VDP_INVALID_HANDLE)
3409 if (m_bufferPool.glVideoSurfaceMap.find(surf) == m_bufferPool.glVideoSurfaceMap.end())
3411 glSurface.sourceVuv = surf;
3412 while (glGetError() != GL_NO_ERROR) ;
3413 glGenTextures(4, glSurface.texture);
3414 if (glGetError() != GL_NO_ERROR)
3416 CLog::Log(LOGERROR, "VDPAU::COutput error creating texture");
3419 glSurface.glVdpauSurface = glVDPAURegisterVideoSurfaceNV(reinterpret_cast<void*>(surf),
3420 GL_TEXTURE_2D, 4, glSurface.texture);
3422 if (glGetError() != GL_NO_ERROR)
3424 CLog::Log(LOGERROR, "VDPAU::COutput error register video surface");
3427 glVDPAUSurfaceAccessNV(glSurface.glVdpauSurface, GL_READ_ONLY);
3428 if (glGetError() != GL_NO_ERROR)
3430 CLog::Log(LOGERROR, "VDPAU::COutput error setting access");
3433 glVDPAUMapSurfacesNV(1, &glSurface.glVdpauSurface);
3434 if (glGetError() != GL_NO_ERROR)
3436 CLog::Log(LOGERROR, "VDPAU::COutput error mapping surface");
3439 m_bufferPool.glVideoSurfaceMap[surf] = glSurface;
3442 CLog::Log(LOGNOTICE, "VDPAU::COutput registered surface");
3449 if (m_bufferPool.glOutputSurfaceMap.size() != m_bufferPool.numOutputSurfaces)
3451 VdpauBufferPool::GLVideoSurface glSurface;
3452 for (unsigned int i = m_bufferPool.glOutputSurfaceMap.size(); i<m_bufferPool.outputSurfaces.size(); i++)
3454 glSurface.sourceRgb = m_bufferPool.outputSurfaces[i];
3455 glGenTextures(1, glSurface.texture);
3456 glSurface.glVdpauSurface = glVDPAURegisterOutputSurfaceNV(reinterpret_cast<void*>(m_bufferPool.outputSurfaces[i]),
3457 GL_TEXTURE_2D, 1, glSurface.texture);
3458 if (glGetError() != GL_NO_ERROR)
3460 CLog::Log(LOGERROR, "VDPAU::COutput error register output surface");
3463 glVDPAUSurfaceAccessNV(glSurface.glVdpauSurface, GL_READ_ONLY);
3464 if (glGetError() != GL_NO_ERROR)
3466 CLog::Log(LOGERROR, "VDPAU::COutput error setting access");
3469 glVDPAUMapSurfacesNV(1, &glSurface.glVdpauSurface);
3470 if (glGetError() != GL_NO_ERROR)
3472 CLog::Log(LOGERROR, "VDPAU::COutput error mapping surface");
3475 m_bufferPool.glOutputSurfaceMap[m_bufferPool.outputSurfaces[i]] = glSurface;
3479 CLog::Log(LOGNOTICE, "VDPAU::COutput registered output surfaces");
3485 void COutput::GLUnmapSurfaces()
3487 #ifdef GL_NV_vdpau_interop
3490 std::map<VdpVideoSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3491 for (it = m_bufferPool.glVideoSurfaceMap.begin(); it != m_bufferPool.glVideoSurfaceMap.end(); ++it)
3493 glVDPAUUnregisterSurfaceNV(it->second.glVdpauSurface);
3494 glDeleteTextures(4, it->second.texture);
3496 m_bufferPool.glVideoSurfaceMap.clear();
3499 std::map<VdpOutputSurface, VdpauBufferPool::GLVideoSurface>::iterator it;
3500 for (it = m_bufferPool.glOutputSurfaceMap.begin(); it != m_bufferPool.glOutputSurfaceMap.end(); ++it)
3502 glVDPAUUnregisterSurfaceNV(it->second.glVdpauSurface);
3503 glDeleteTextures(1, it->second.texture);
3505 m_bufferPool.glOutputSurfaceMap.clear();
3509 CLog::Log(LOGNOTICE, "VDPAU::COutput: vdpau gl interop finished");
3514 bool COutput::CheckStatus(VdpStatus vdp_st, int line)
3516 if (vdp_st != VDP_STATUS_OK)
3518 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);
3525 bool COutput::CreateGlxContext()
3527 GLXContext glContext;
3529 m_Display = g_Windowing.GetDisplay();
3530 glContext = g_Windowing.GetGlxContext();
3531 m_Window = g_Windowing.GetWindow();
3533 // Get our window attribs.
3534 XWindowAttributes wndattribs;
3535 XGetWindowAttributes(m_Display, m_Window, &wndattribs);
3538 XVisualInfo visInfo;
3539 visInfo.visualid = wndattribs.visual->visualid;
3541 XVisualInfo* visuals = XGetVisualInfo(m_Display, VisualIDMask, &visInfo, &nvisuals);
3544 CLog::Log(LOGERROR, "VDPAU::COutput::CreateGlxContext - could not find visual");
3547 visInfo = visuals[0];
3550 m_pixmap = XCreatePixmap(m_Display,
3557 CLog::Log(LOGERROR, "VDPAU::COutput::CreateGlxContext - Unable to create XPixmap");
3562 m_glPixmap = glXCreateGLXPixmap(m_Display, &visInfo, m_pixmap);
3566 CLog::Log(LOGINFO, "VDPAU::COutput::CreateGlxContext - Could not create glPixmap");
3570 m_glContext = glXCreateContext(m_Display, &visInfo, glContext, True);
3572 if (!glXMakeCurrent(m_Display, m_glPixmap, m_glContext))
3574 CLog::Log(LOGINFO, "VDPAU::COutput::CreateGlxContext - Could not make Pixmap current");
3578 CLog::Log(LOGNOTICE, "VDPAU::COutput::CreateGlxContext - created context");
3582 bool COutput::DestroyGlxContext()
3586 glXMakeCurrent(m_Display, None, NULL);
3587 glXDestroyContext(m_Display, m_glContext);
3592 glXDestroyPixmap(m_Display, m_glPixmap);
3596 XFreePixmap(m_Display, m_pixmap);