1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/*
* Copyright (C) 2005-2018 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 "DVDClock.h"
#include "DebugRenderer.h"
#include "cores/VideoPlayer/VideoRenderers/BaseRenderer.h"
#include "cores/VideoPlayer/VideoRenderers/OverlayRenderer.h"
#include "cores/VideoSettings.h"
#include "threads/CriticalSection.h"
#include "threads/Event.h"
#include "utils/Geometry.h"
#include "windowing/Resolution.h"
#include <atomic>
#include <deque>
#include <list>
#include <map>
#include "PlatformDefs.h"
class CRenderCapture;
struct VideoPicture;
class CWinRenderer;
class CMMALRenderer;
class CLinuxRenderer;
class CLinuxRendererGL;
class CLinuxRendererGLES;
class CRenderManager;
class IRenderMsg
{
friend CRenderManager;
public:
virtual ~IRenderMsg() = default;
protected:
virtual void VideoParamsChange() = 0;
virtual void GetDebugInfo(std::string &audio, std::string &video, std::string &general) = 0;
virtual void UpdateClockSync(bool enabled) = 0;
virtual void UpdateRenderInfo(CRenderInfo &info) = 0;
virtual void UpdateRenderBuffers(int queued, int discard, int free) = 0;
virtual void UpdateGuiRender(bool gui) = 0;
virtual void UpdateVideoRender(bool video) = 0;
virtual CVideoSettings GetVideoSettings() = 0;
};
class CRenderManager
{
public:
CRenderManager(CDVDClock &clock, IRenderMsg *player);
virtual ~CRenderManager();
// Functions called from render thread
void GetVideoRect(CRect &source, CRect &dest, CRect &view);
float GetAspectRatio();
void FrameMove();
void FrameWait(int ms);
void Render(bool clear, DWORD flags = 0, DWORD alpha = 255, bool gui = true);
bool IsVideoLayer();
RESOLUTION GetResolution();
void UpdateResolution();
void TriggerUpdateResolution(float fps, int width, int height, std::string &stereomode);
void SetViewMode(int iViewMode);
void PreInit();
void UnInit();
bool Flush(bool wait, bool saveBuffers);
bool IsConfigured() const;
void ToggleDebug();
unsigned int AllocRenderCapture();
void ReleaseRenderCapture(unsigned int captureId);
void StartRenderCapture(unsigned int captureId, unsigned int width, unsigned int height, int flags);
bool RenderCaptureGetPixels(unsigned int captureId, unsigned int millis, uint8_t *buffer, unsigned int size);
// Functions called from GUI
bool Supports(ERENDERFEATURE feature);
bool Supports(ESCALINGMETHOD method);
int GetSkippedFrames() { return m_QueueSkip; }
bool Configure(const VideoPicture& picture, float fps, unsigned int orientation, int buffers = 0);
bool AddVideoPicture(const VideoPicture& picture, volatile std::atomic_bool& bStop, EINTERLACEMETHOD deintMethod, bool wait);
void AddOverlay(CDVDOverlay* o, double pts);
void ShowVideo(bool enable);
/**
* If player uses buffering it has to wait for a buffer before it calls
* AddVideoPicture and AddOverlay. It waits for max 50 ms before it returns -1
* in case no buffer is available. Player may call this in a loop and decides
* by itself when it wants to drop a frame.
*/
int WaitForBuffer(volatile std::atomic_bool& bStop, int timeout = 100);
/**
* Can be called by player for lateness detection. This is done best by
* looking at the end of the queue.
*/
bool GetStats(int &lateframes, double &pts, int &queued, int &discard);
/**
* Video player call this on flush in oder to discard any queued frames
*/
void DiscardBuffer();
void SetDelay(int delay) { m_videoDelay = delay; };
int GetDelay() { return m_videoDelay; };
void SetVideoSettings(CVideoSettings settings);
protected:
void PresentSingle(bool clear, DWORD flags, DWORD alpha);
void PresentFields(bool clear, DWORD flags, DWORD alpha);
void PresentBlend(bool clear, DWORD flags, DWORD alpha);
void PrepareNextRender();
bool IsPresenting();
bool IsGuiLayer();
bool Configure();
void CreateRenderer();
void DeleteRenderer();
void ManageCaptures();
void UpdateLatencyTweak();
void CheckEnableClockSync();
CBaseRenderer *m_pRenderer = nullptr;
OVERLAY::CRenderer m_overlays;
CDebugRenderer m_debugRenderer;
mutable CCriticalSection m_statelock;
CCriticalSection m_presentlock;
CCriticalSection m_datalock;
bool m_bTriggerUpdateResolution = false;
bool m_bRenderGUI = true;
bool m_renderedOverlay = false;
bool m_renderDebug = false;
XbmcThreads::EndTime m_debugTimer;
std::atomic_bool m_showVideo = {false};
enum EPRESENTSTEP
{
PRESENT_IDLE = 0
, PRESENT_FLIP
, PRESENT_FRAME
, PRESENT_FRAME2
, PRESENT_READY
};
enum EPRESENTMETHOD
{
PRESENT_METHOD_SINGLE = 0,
PRESENT_METHOD_BLEND,
PRESENT_METHOD_BOB,
};
enum ERENDERSTATE
{
STATE_UNCONFIGURED = 0,
STATE_CONFIGURING,
STATE_CONFIGURED,
};
ERENDERSTATE m_renderState = STATE_UNCONFIGURED;
CEvent m_stateEvent;
/// Display latency tweak value from AdvancedSettings for the current refresh rate
/// in milliseconds
double m_latencyTweak = 0.0;
/// Display latency updated in PrepareNextRender in DVD clock units, includes m_latencyTweak
double m_displayLatency = 0.0;
std::atomic_int m_videoDelay = {0};
int m_QueueSize = 2;
int m_QueueSkip = 0;
struct SPresent
{
double pts;
EFIELDSYNC presentfield;
EPRESENTMETHOD presentmethod;
} m_Queue[NUM_BUFFERS];
std::deque<int> m_free;
std::deque<int> m_queued;
std::deque<int> m_discard;
std::unique_ptr<VideoPicture> m_pConfigPicture;
unsigned int m_width = 0;
unsigned int m_height = 0;
unsigned int m_dwidth = 0;
unsigned int m_dheight = 0;
float m_fps = 0.0;
unsigned int m_orientation = 0;
int m_NumberBuffers = 0;
std::string m_stereomode;
int m_lateframes = -1;
double m_presentpts = 0.0;
EPRESENTSTEP m_presentstep = PRESENT_IDLE;
XbmcThreads::EndTime m_presentTimer;
bool m_forceNext = false;
int m_presentsource = 0;
int m_presentsourcePast = -1;
XbmcThreads::ConditionVariable m_presentevent;
CEvent m_flushEvent;
CEvent m_initEvent;
CDVDClock &m_dvdClock;
IRenderMsg *m_playerPort;
struct CClockSync
{
void Reset();
double m_error;
int m_errCount;
double m_syncOffset;
bool m_enabled;
};
CClockSync m_clockSync;
void RenderCapture(CRenderCapture* capture);
void RemoveCaptures();
CCriticalSection m_captCritSect;
std::map<unsigned int, CRenderCapture*> m_captures;
static unsigned int m_nextCaptureId;
unsigned int m_captureWaitCounter = 0;
//set to true when adding something to m_captures, set to false when m_captures is made empty
//std::list::empty() isn't thread safe, using an extra bool will save a lock per render when no captures are requested
bool m_hasCaptures = false;
};
|