forked from xbmc/xbmc
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows use of "sync video to display" and features like resampling for smooth playback of 24fps content on 25fps display
- Loading branch information
1 parent
3fb0652
commit bd44202
Showing
5 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* 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 "windowing/GraphicContext.h" | ||
#include "windowing/WinSystem.h" | ||
#include "utils/TimeUtils.h" | ||
#include "utils/log.h" | ||
#include "threads/Thread.h" | ||
#include "xbmc/windowing/gbm/WinSystemGbm.h" | ||
|
||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include "xf86drm.h" | ||
#include "xf86drmMode.h" | ||
|
||
bool CVideoSyncGbm::Setup(PUPDATECLOCK func) | ||
{ | ||
UpdateClock = func; | ||
m_abort = false; | ||
CServiceBroker::GetWinSystem()->Register(this); | ||
CLog::Log(LOGDEBUG, "CVideoSyncGbm:{} setting up", __FUNCTION__); | ||
|
||
auto winSystem = dynamic_cast<KODI::WINDOWING::GBM::CWinSystemGbm*>(CServiceBroker::GetWinSystem()); | ||
if (!winSystem) | ||
{ | ||
CLog::Log(LOGWARNING, "CVideoSyncGbm:{}: failed to get winSystem", __FUNCTION__); | ||
return false; | ||
} | ||
auto drm = winSystem->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); | ||
if (s != 0) | ||
{ | ||
CLog::Log(LOGWARNING, "CVideoSyncGbm:{}: drmCrtcGetSequence failed (%d)", __FUNCTION__, s); | ||
return false; | ||
} | ||
CLog::Log(LOGINFO, "CVideoSyncGbm:{}: opened (fd:{} crtc:{} seq:{} ns:{})", __FUNCTION__, m_fd, m_crtcId, m_sequence, ns); | ||
return true; | ||
} | ||
|
||
void CVideoSyncGbm::Run(CEvent& stopEvent) | ||
{ | ||
/* This shouldn't be very busy and timing is important so increase priority */ | ||
CThread::GetCurrentThread()->SetPriority(CThread::GetCurrentThread()->GetPriority()+1); | ||
|
||
if (m_fd < 0) | ||
{ | ||
CLog::Log(LOGWARNING, "CVideoSyncGbm:{}: failed to open device (%d)", __FUNCTION__, m_fd); | ||
return; | ||
} | ||
CLog::Log(LOGDEBUG, "CVideoSyncGbm:{}: started (%d)", 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 (%d)", __FUNCTION__, s); | ||
break; | ||
} | ||
//CLog::Log(LOGDEBUG, "CVideoSyncGbm:{}: drmCrtcGetSequence: seq:{}:{} ns:{} s:{}", __FUNCTION__, sequence, m_sequence, ns, s); | ||
if (sequence == m_sequence) | ||
continue; | ||
UpdateClock(sequence - m_sequence, CurrentHostCounter(), m_refClock); | ||
m_sequence = sequence; | ||
} | ||
} | ||
|
||
void CVideoSyncGbm::Cleanup() | ||
{ | ||
CLog::Log(LOGDEBUG, "CVideoSyncGbm:{}: cleaning up", __FUNCTION__); | ||
CServiceBroker::GetWinSystem()->Unregister(this); | ||
} | ||
|
||
float CVideoSyncGbm::GetFps() | ||
{ | ||
m_fps = CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS(); | ||
CLog::Log(LOGDEBUG, "CVideoSyncGbm:{}: fps: %.2f", __FUNCTION__, m_fps); | ||
return m_fps; | ||
} | ||
|
||
void CVideoSyncGbm::OnResetDisplay() | ||
{ | ||
m_abort = true; | ||
} | ||
|
||
void CVideoSyncGbm::RefreshChanged() | ||
{ | ||
if (m_fps != CServiceBroker::GetWinSystem()->GetGfxContext().GetFPS()) | ||
m_abort = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "windowing/VideoSync.h" | ||
#include "guilib/DispResource.h" | ||
|
||
class CVideoSyncGbm : public CVideoSync, IDispResource | ||
{ | ||
public: | ||
CVideoSyncGbm(void *clock) : CVideoSync(clock) {}; | ||
virtual bool Setup(PUPDATECLOCK func); | ||
virtual void Run(CEvent& stopEvent); | ||
virtual void Cleanup(); | ||
virtual float GetFps(); | ||
virtual void OnResetDisplay(); | ||
virtual void RefreshChanged(); | ||
|
||
private: | ||
int m_fd = -1; | ||
uint32_t m_crtcId = 0; | ||
uint64_t m_sequence = 0; | ||
volatile bool m_abort; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters