diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/windowing/gbm/VideoSyncGbm.cpp | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/windowing/gbm/VideoSyncGbm.cpp')
-rw-r--r-- | xbmc/windowing/gbm/VideoSyncGbm.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/xbmc/windowing/gbm/VideoSyncGbm.cpp b/xbmc/windowing/gbm/VideoSyncGbm.cpp new file mode 100644 index 0000000..d113c90 --- /dev/null +++ b/xbmc/windowing/gbm/VideoSyncGbm.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2005-2021 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "VideoSyncGbm.h" + +#include "ServiceBroker.h" +#include "threads/Thread.h" +#include "utils/TimeUtils.h" +#include "utils/log.h" +#include "windowing/GraphicContext.h" +#include "windowing/WinSystem.h" +#include "windowing/gbm/WinSystemGbm.h" +#include "xf86drm.h" +#include "xf86drmMode.h" + +#include <assert.h> +#include <stdint.h> +#include <stdlib.h> + +#include <unistd.h> + +CVideoSyncGbm::CVideoSyncGbm(void* clock) + : CVideoSync(clock), m_winSystem(CServiceBroker::GetWinSystem()) +{ + if (!m_winSystem) + throw std::runtime_error("window system not available"); +} + +bool CVideoSyncGbm::Setup(PUPDATECLOCK func) +{ + UpdateClock = func; + m_abort = false; + m_winSystem->Register(this); + CLog::Log(LOGDEBUG, "CVideoSyncGbm::{} setting up", __FUNCTION__); + + auto winSystemGbm = dynamic_cast<KODI::WINDOWING::GBM::CWinSystemGbm*>(m_winSystem); + if (!winSystemGbm) + { + CLog::Log(LOGWARNING, "CVideoSyncGbm::{}: failed to get winSystem", __FUNCTION__); + return false; + } + + auto drm = winSystemGbm->GetDrm(); + if (!drm) + { + CLog::Log(LOGWARNING, "CVideoSyncGbm::{}: failed to get drm", __FUNCTION__); + return false; + } + + auto crtc = drm->GetCrtc(); + if (!crtc) + { + CLog::Log(LOGWARNING, "CVideoSyncGbm::{}: failed to get crtc", __FUNCTION__); + return false; + } + + uint64_t ns = 0; + m_crtcId = crtc->GetCrtcId(); + m_fd = drm->GetFileDescriptor(); + int s = drmCrtcGetSequence(m_fd, m_crtcId, &m_sequence, &ns); + m_offset = CurrentHostCounter() - ns; + if (s != 0) + { + CLog::Log(LOGWARNING, "CVideoSyncGbm::{}: drmCrtcGetSequence failed ({})", __FUNCTION__, s); + return false; + } + + CLog::Log(LOGINFO, "CVideoSyncGbm::{}: opened (fd:{} crtc:{} seq:{} ns:{}:{})", __FUNCTION__, + m_fd, m_crtcId, m_sequence, ns, m_offset + ns); + return true; +} + +void CVideoSyncGbm::Run(CEvent& stopEvent) +{ + /* This shouldn't be very busy and timing is important so increase priority */ + CThread::GetCurrentThread()->SetPriority(ThreadPriority::ABOVE_NORMAL); + + if (m_fd < 0) + { + CLog::Log(LOGWARNING, "CVideoSyncGbm::{}: failed to open device ({})", __FUNCTION__, m_fd); + return; + } + CLog::Log(LOGDEBUG, "CVideoSyncGbm::{}: started {}", __FUNCTION__, m_fd); + + while (!stopEvent.Signaled() && !m_abort) + { + uint64_t sequence = 0, ns = 0; + usleep(1000); + int s = drmCrtcGetSequence(m_fd, m_crtcId, &sequence, &ns); + if (s != 0) + { + CLog::Log(LOGWARNING, "CVideoSyncGbm::{}: drmCrtcGetSequence failed ({})", __FUNCTION__, s); + break; + } + + if (sequence == m_sequence) + continue; + + UpdateClock(sequence - m_sequence, m_offset + ns, m_refClock); + m_sequence = sequence; + } +} + +void CVideoSyncGbm::Cleanup() +{ + CLog::Log(LOGDEBUG, "CVideoSyncGbm::{}: cleaning up", __FUNCTION__); + m_winSystem->Unregister(this); +} + +float CVideoSyncGbm::GetFps() +{ + m_fps = m_winSystem->GetGfxContext().GetFPS(); + CLog::Log(LOGDEBUG, "CVideoSyncGbm::{}: fps:{}", __FUNCTION__, m_fps); + return m_fps; +} + +void CVideoSyncGbm::OnResetDisplay() +{ + m_abort = true; +} + +void CVideoSyncGbm::RefreshChanged() +{ + if (m_fps != m_winSystem->GetGfxContext().GetFPS()) + m_abort = true; +} |