Debian Codegraph @

xbmc/windowing/X11/VideoSyncOML.cpp

raw
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "VideoSyncOML.h"
10
11 #include "cores/VideoPlayer/VideoReferenceClock.h"
12 #include "utils/TimeUtils.h"
13 #include "utils/log.h"
14 #include "windowing/GraphicContext.h"
15 #include "windowing/X11/WinSystemX11GLContext.h"
16
17 #include <unistd.h>
18
19 using namespace KODI::WINDOWING::X11;
20
21 bool CVideoSyncOML::Setup()
22 {
23 CLog::Log(LOGDEBUG, "CVideoSyncOML::{} - setting up OML", __FUNCTION__);
24
25 m_abort = false;
26
27 static_cast<CWinSystemX11*>(&m_winSystem)->Register(this);
28
29 return true;
30 }
31
32 void CVideoSyncOML::Run(CEvent& stopEvent)
33 {
34 uint64_t interval, timeSinceVblank, msc;
35
36 timeSinceVblank = m_winSystem.GetVblankTiming(msc, interval);
37
38 while (!stopEvent.Signaled() && !m_abort)
39 {
40 if (interval == 0)
41 {
42 usleep(10000);
43 }
44 else
45 {
46 usleep(interval - timeSinceVblank + 1000);
47 }
48 uint64_t newMsc;
49 timeSinceVblank = m_winSystem.GetVblankTiming(newMsc, interval);
50
51 if (newMsc == msc)
52 {
53 newMsc++;
54 }
55 else if (newMsc < msc)
56 {
57 timeSinceVblank = interval;
58 continue;
59 }
60
61 uint64_t now = CurrentHostCounter();
62 m_refClock->UpdateClock(newMsc - msc, now);
63 msc = newMsc;
64 }
65 }
66
67 void CVideoSyncOML::Cleanup()
68 {
69 m_winSystem.Unregister(this);
70 }
71
72 void CVideoSyncOML::OnResetDisplay()
73 {
74 m_abort = true;
75 }
76
77 float CVideoSyncOML::GetFps()
78 {
79 m_fps = m_winSystem.GetGfxContext().GetFPS();
80 return m_fps;
81 }
82