forked from xbmc/xbmc
-
Notifications
You must be signed in to change notification settings - Fork 24
/
RenderManager.h
261 lines (224 loc) · 7.6 KB
/
RenderManager.h
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#pragma once
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include <list>
#include "cores/VideoPlayer/VideoRenderers/BaseRenderer.h"
#include "cores/VideoPlayer/VideoRenderers/OverlayRenderer.h"
#include "guilib/Geometry.h"
#include "guilib/Resolution.h"
#include "threads/CriticalSection.h"
#include "settings/VideoSettings.h"
#include "OverlayRenderer.h"
#include <deque>
#include <map>
#include "PlatformDefs.h"
#include "threads/Event.h"
#include "DVDClock.h"
class CRenderCapture;
namespace DXVA { class CProcessor; }
namespace VAAPI { class CSurfaceHolder; }
namespace VDPAU { class CVdpauRenderPicture; }
struct DVDVideoPicture;
#define ERRORBUFFSIZE 30
class CWinRenderer;
class CMMALRenderer;
class CLinuxRenderer;
class CLinuxRendererGL;
class CLinuxRendererGLES;
class CRenderManager;
class IRenderMsg
{
friend CRenderManager;
protected:
virtual void VideoParamsChange() = 0;
};
class CRenderManager
{
public:
CRenderManager(CDVDClock &clock, IRenderMsg *player);
~CRenderManager();
// Functions called from render thread
void GetVideoRect(CRect &source, CRect &dest, CRect &view);
float GetAspectRatio();
void FrameMove();
void FrameFinish();
void FrameWait(int ms);
bool HasFrame();
void Render(bool clear, DWORD flags = 0, DWORD alpha = 255, bool gui = true);
bool IsGuiLayer();
bool IsVideoLayer();
RESOLUTION GetResolution();
void UpdateResolution();
void TriggerUpdateResolution(float fps, int width, int flags);
void SetViewMode(int iViewMode);
void PreInit();
void UnInit();
bool Flush();
bool IsConfigured() const;
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(EDEINTERLACEMODE method);
bool Supports(EINTERLACEMETHOD method);
bool Supports(ESCALINGMETHOD method);
EINTERLACEMETHOD AutoInterlaceMethod(EINTERLACEMETHOD mInt);
static float GetMaximumFPS();
double GetDisplayLatency() { return m_displayLatency; }
int GetSkippedFrames() { return m_QueueSkip; }
std::string GetVSyncState();
// Functions called from mplayer
/**
* Called by video player to configure renderer
* @param picture
* @param fps frames per second of video
* @param flags see RenderFlags.h
* @param orientation
* @param numbers of kept buffer references
*/
bool Configure(DVDVideoPicture& picture, float fps, unsigned flags, unsigned int orientation, int buffers = 0);
int AddVideoPicture(DVDVideoPicture& picture);
/**
* Called by video player to flip render buffers
* If buffering is enabled this method does not block. In case of disabled buffering
* this method blocks waiting for the render thread to pass by.
* When buffering is used there might be no free buffer available after the call to
* this method. Player has to call WaitForBuffer. A free buffer will become
* available after the main thread has flipped front / back buffers.
*
* @param bStop reference to stop flag of calling thread
* @param timestamp of frame delivered with AddVideoPicture
* @param pts used for lateness detection
* @param source depreciated
* @param sync signals frame, top, or bottom field
*/
void FlipPage(volatile bool& bStop, double timestamp = 0.0, double pts = 0.0, int source = -1, EFIELDSYNC sync = FS_NONE);
void AddOverlay(CDVDOverlay* o, double pts);
// Get renderer info, can be called before configure
CRenderInfo GetRenderInfo();
/**
* 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.
* If no buffering is requested in Configure, player does not need to call this,
* because FlipPage will block.
*/
int WaitForBuffer(volatile 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(double &sleeptime, double &pts, int &queued, int &discard);
/**
* Video player call this on flush in oder to discard any queued frames
*/
void DiscardBuffer();
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();
static double GetPresentTime();
void WaitPresentTime(double presenttime);
EINTERLACEMETHOD AutoInterlaceMethodInternal(EINTERLACEMETHOD mInt);
bool Configure();
void CreateRenderer();
void DeleteRenderer();
void ManageCaptures();
CBaseRenderer *m_pRenderer;
OVERLAY::CRenderer m_overlays;
CCriticalSection m_statelock;
CCriticalSection m_presentlock;
CCriticalSection m_datalock;
bool m_bTriggerUpdateResolution;
bool m_bRenderGUI;
int m_waitForBufferCount;
int m_rendermethod;
bool m_renderedOverlay;
enum EPRESENTSTEP
{
PRESENT_IDLE = 0
, PRESENT_FLIP
, PRESENT_FRAME
, PRESENT_FRAME2
, PRESENT_READY
};
enum EPRESENTMETHOD
{
PRESENT_METHOD_SINGLE = 0,
PRESENT_METHOD_BLEND,
PRESENT_METHOD_WEAVE,
PRESENT_METHOD_BOB,
};
enum ERENDERSTATE
{
STATE_UNCONFIGURED = 0,
STATE_CONFIGURING,
STATE_CONFIGURED,
};
ERENDERSTATE m_renderState;
CEvent m_stateEvent;
double m_displayLatency;
void UpdateDisplayLatency();
int m_QueueSize;
int m_QueueSkip;
struct SPresent
{
double pts;
double timestamp;
EFIELDSYNC presentfield;
EPRESENTMETHOD presentmethod;
} m_Queue[NUM_BUFFERS];
std::deque<int> m_free;
std::deque<int> m_queued;
std::deque<int> m_discard;
ERenderFormat m_format;
unsigned int m_width, m_height, m_dwidth, m_dheight;
unsigned int m_flags;
float m_fps;
unsigned int m_extended_format;
unsigned int m_orientation;
int m_NumberBuffers;
double m_sleeptime;
double m_presentpts;
double m_presentcorr;
double m_presenterr;
double m_errorbuff[ERRORBUFFSIZE];
int m_errorindex;
EPRESENTSTEP m_presentstep;
int m_presentsource;
XbmcThreads::ConditionVariable m_presentevent;
CEvent m_flushEvent;
double m_clock_framefinish;
CDVDClock &m_dvdClock;
IRenderMsg *m_playerPort;
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;
//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;
};