Debian Codegraph @

xbmc/windowing/wayland/VideoSyncWpPresentation.cpp

raw
1 /*
2 * Copyright (C) 2017-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 "VideoSyncWpPresentation.h"
10
11 #include "cores/VideoPlayer/VideoReferenceClock.h"
12 #include "settings/AdvancedSettings.h"
13 #include "utils/TimeUtils.h"
14 #include "utils/log.h"
15 #include "windowing/wayland/WinSystemWayland.h"
16
17 #include <cinttypes>
18 #include <functional>
19
20 using namespace KODI::WINDOWING::WAYLAND;
21 using namespace std::placeholders;
22
23 CVideoSyncWpPresentation::CVideoSyncWpPresentation(CVideoReferenceClock* clock,
24 CWinSystemWayland& winSystem)
25 : CVideoSync(clock), m_winSystem(winSystem)
26 {
27 }
28
29 bool CVideoSyncWpPresentation::Setup()
30 {
31 m_stopEvent.Reset();
32 m_fps = m_winSystem.GetSyncOutputRefreshRate();
33
34 return true;
35 }
36
37 void CVideoSyncWpPresentation::Run(CEvent& stopEvent)
38 {
39 m_presentationHandler = m_winSystem.RegisterOnPresentationFeedback(std::bind(&CVideoSyncWpPresentation::HandlePresentation, this, _1, _2, _3, _4, _5));
40
41 XbmcThreads::CEventGroup waitGroup{&stopEvent, &m_stopEvent};
42 waitGroup.wait();
43
44 m_presentationHandler.Unregister();
45 }
46
47 void CVideoSyncWpPresentation::Cleanup()
48 {
49 }
50
51 float CVideoSyncWpPresentation::GetFps()
52 {
53 return m_fps;
54 }
55
56 void CVideoSyncWpPresentation::HandlePresentation(timespec tv, std::uint32_t refresh, std::uint32_t syncOutputID, float syncOutputRefreshRate, std::uint64_t msc)
57 {
58 auto mscDiff = msc - m_lastMsc;
59
60 CLog::Log(LOGDEBUG, LOGAVTIMING,
61 "VideoSyncWpPresentation: tv {}.{:09} s next refresh in +{} ns (fps {:f}) sync output "
62 "id {} fps {:f} msc {} mscdiff {}",
63 static_cast<std::uint64_t>(tv.tv_sec), static_cast<std::uint64_t>(tv.tv_nsec), refresh,
64 1.0e9 / refresh, syncOutputID, syncOutputRefreshRate, msc, mscDiff);
65
66 if (m_fps != syncOutputRefreshRate || (m_syncOutputID != 0 && m_syncOutputID != syncOutputID))
67 {
68 // Restart if fps changes or sync output changes (which means that the msc jumps)
69 CLog::Log(LOGDEBUG, "fps or sync output changed, restarting Wayland video sync");
70 m_stopEvent.Set();
71 }
72 m_syncOutputID = syncOutputID;
73
74 if (m_lastMsc == 0)
75 {
76 // If this is the first time or MSC is not supported, assume we moved one frame
77 mscDiff = 1;
78 }
79 m_lastMsc = msc;
80
81 // FIXME use timespec instead of currenthostcounter()? Possibly difficult
82 // due to different clock base
83 m_refClock->UpdateClock(mscDiff, CurrentHostCounter());
84 }