vdr-plugin-softhddevice-drm-gles 1.4.0
videorender.h
Go to the documentation of this file.
1
22#ifndef __VIDEORENDER_H
23#define __VIDEORENDER_H
24
25#include <atomic>
26#include <vector>
27
28#include <xf86drm.h>
29#include <xf86drmMode.h>
30
31extern "C" {
32#include <libavutil/hwcontext_drm.h>
33}
34
35#ifdef USE_GLES
36#include <gbm.h>
37#include <EGL/egl.h>
38#include <EGL/eglext.h>
39#include <EGL/eglplatform.h>
40#include "glhelpers.h"
41
42/* Hack:
43 * xlib.h via eglplatform.h: #define Status int
44 * X.h via eglplatform.h: #define CurrentTime 0L
45 *
46 * revert it, because it conflicts with vdr variables.
47 */
48#undef Status
49#undef CurrentTime
50#endif
51
52#include <atomic>
53
54#include "logger.h"
55#include "iatomic.h"
56#include "softhddevice.h"
57#include "videostream.h"
58#include "drmbuffer.h"
59#include "drmdevice.h"
60#include "threads.h"
61#include "grab.h"
62#include "drmplane.h"
63#include "config.h"
64#include "event.h"
65#include "queue.h"
66
67// Hardware quirks, that are set depending on the hardware used
68#define QUIRK_NO_HW_DEINT 1 << 0
69#define QUIRK_CODEC_FLUSH_WORKAROUND 1 << 1
70#define QUIRK_CODEC_NEEDS_EXT_INIT 1 << 2
71#define QUIRK_CODEC_SKIP_FIRST_FRAMES 1 << 3
72#define QUIRK_CODEC_SKIP_NUM_FRAMES 2
73#define QUIRK_CODEC_DISABLE_MPEG_HW 1 << 4
74#define QUIRK_CODEC_DISABLE_H264_HW 1 << 5
75
76#define AV_SYNC_THRESHOLD_AUDIO_BEHIND_VIDEO_MS 35
77#define AV_SYNC_THRESHOLD_AUDIO_AHEAD_VIDEO_MS 5
78
79class cDrmDevice;
80
82public:
83 virtual ~cBufferStrategy() = default;
84 virtual cDrmBuffer *GetBuffer(cDrmBufferPool *, AVDRMFrameDescriptor *) = 0;
85};
86
88public:
89 cDrmBuffer *GetBuffer(cDrmBufferPool *, AVDRMFrameDescriptor *) override;
90};
91
93public:
94 cDrmBuffer *GetBuffer(cDrmBufferPool *, AVDRMFrameDescriptor *) override;
95};
96
98public:
99 cDrmBuffer *GetBuffer(cDrmBufferPool *, AVDRMFrameDescriptor *) override;
100};
101
103public:
104 virtual ~cDecodingStrategy() = default;
105 virtual AVFrame *PrepareDrmBuffer(cDrmBuffer *, int, AVFrame *) = 0;
106};
107
109public:
110 AVFrame *PrepareDrmBuffer(cDrmBuffer *, int, AVFrame *) override;
111};
112
114public:
115 AVFrame *PrepareDrmBuffer(cDrmBuffer *, int, AVFrame *) override;
116};
117
122{
123public:
125 virtual ~cVideoRender(void);
126
127 void Init(void);
128 void Exit(void);
129
130 void SetVideoOutputPosition(const cRect &);
131 void SetScreenSize(int, int, uint32_t);
132 int64_t GetVideoClock(void);
133 void GetStats(int *, int *, int *);
134 void ResetFrameCounter(void);
135 void Reset();
136 void SetPlaybackPaused(bool pause) { m_videoPlaybackPaused = pause; };
137 void SetScheduleAudioResume(bool resume) { m_resumeAudioScheduled = resume; };
138
139 void ProcessEvents(void);
142
143 // OSD
144 void OsdClear(void);
145 void OsdDrawARGB(int, int, int, int, int, const uint8_t *, int, int);
146
147 // TrickSpeed
148 void SetTrickSpeed(int, int);
149 int GetTrickSpeed(void);
150 int GetTrickForward(void);
151
152 // Grab
153 int TriggerGrab(void);
154 void ConvertVideoBufToRgb(void);
155 void ConvertOsdBufToRgb(void);
156 void ConvertPipBufToRgb(void);
157 void ClearGrab(void);
158 cSoftHdGrab *GetGrab(int *, int *, int *, int *, int *, int);
159
160 // Threads
161 void ExitDisplayThread(void);
164
165 // DRM
166 int DrmHandleEvent(void);
167
168 // Frame and buffer
169 bool DisplayFrame();
170 int GetFramesFilled(void) { return m_drmBufferQueue.Size(); };
171 void PushMainFrame(AVFrame *);
172 void PushPipFrame(AVFrame *);
173 int64_t GetOutputPtsMs(void);
174 void DisplayBlackFrame(void);
176 bool IsOutputBufferFull(void);
181
182#ifdef USE_GLES
183 // GLES
184 void DisableOglOsd(void) { m_disableOglOsd = true; };
185 void EnableOglOsd(void) { m_disableOglOsd = false; };
186 bool OglOsdDisabled(void) { return m_disableOglOsd; };
187 EGLSurface EglSurface(void) { return m_pDrmDevice->EglSurface(); };
188 EGLDisplay EglDisplay(void) { return m_pDrmDevice->EglDisplay(); };
189 EGLContext EglContext(void) { return m_pDrmDevice->EglContext(); };
190 int GlInitiated(void) { return m_pDrmDevice->GlInitiated(); };
191#endif
192
193 // PIP
194 void SetPipActive(bool on) { m_pipActive = on; };
195 bool IsPipActive(void) { return m_pipActive; };
197 void SetPipSize(bool);
198
199private:
206 std::vector<Event> m_eventQueue;
207
215
217 cCondVar m_grabCond;
223
228 AVRational m_timebase;
231
237
244 std::atomic<bool> m_videoPlaybackPaused = true;
245 std::atomic<bool> m_resumeAudioScheduled = false;
246 std::atomic<bool> m_displayOneFrameThenPause = false;
248
252 std::atomic<cBufferStrategy *> m_bufferReuseStrategy = nullptr;
253 std::atomic<cBufferStrategy *> m_pipBufferReuseStrategy = nullptr;
254 std::atomic<cDecodingStrategy *> m_decodingStrategy = nullptr;
255 std::atomic<cDecodingStrategy *> m_pipDecodingStrategy = nullptr;
256
257#ifdef USE_GLES
258 bool m_disableOglOsd;
259 struct gbm_bo *m_bo;
260 struct gbm_bo *m_pOldBo;
261 struct gbm_bo *m_pNextBo;
262#endif
263
264 std::atomic<bool> m_pipActive = false;
265
266 int GetFrameFlags(AVFrame *);
267 void SetFrameFlags(AVFrame *, int);
268 void SetVideoClock(int64_t);
269 bool PageFlip(cDrmBuffer *, cDrmBuffer *);
271 int SetOsdBuffer(drmModeAtomicReqPtr);
272 void SetPipBuffer(cDrmBuffer *);
274 void Grab(cDrmBuffer *, cDrmBuffer *);
275 void LogDroppedDuped(int64_t, int64_t, int);
276 int64_t PtsToMs(int64_t);
277 void PushFrame(AVFrame *, bool, std::atomic<cBufferStrategy*> &, std::atomic<cDecodingStrategy*> &, cQueue<cDrmBuffer> *, cDrmBufferPool *);
278};
279
280#endif
cDrmBuffer * GetBuffer(cDrmBufferPool *, AVDRMFrameDescriptor *) override
cDrmBuffer * GetBuffer(cDrmBufferPool *, AVDRMFrameDescriptor *) override
cDrmBuffer * GetBuffer(cDrmBufferPool *, AVDRMFrameDescriptor *) override
virtual cDrmBuffer * GetBuffer(cDrmBufferPool *, AVDRMFrameDescriptor *)=0
virtual ~cBufferStrategy()=default
AVFrame * PrepareDrmBuffer(cDrmBuffer *, int, AVFrame *) override
AVFrame * PrepareDrmBuffer(cDrmBuffer *, int, AVFrame *) override
virtual AVFrame * PrepareDrmBuffer(cDrmBuffer *, int, AVFrame *)=0
virtual ~cDecodingStrategy()=default
Display thread class.
Definition: threads.h:61
void Halt(void)
Definition: threads.h:66
void Resume(void)
Definition: threads.h:67
size_t Size(void)
Get the current size of the queue.
Definition: queue.h:128
cSoftHdAudio - Audio class
Definition: audio.h:45
cSoftHdGrab - Grabber class
Definition: grab.h:35
cVideoRender - Video render class
Definition: videorender.h:122
void PushPipFrame(AVFrame *)
void SetFrameFlags(AVFrame *, int)
Set frame flags.
int m_numWrongProgressive
counter for progressive frames sent in an interlaced stream (only used for logging)
Definition: videorender.h:213
int DrmHandleEvent(void)
Wrapper for drmHandleEvent()
bool IsOutputBufferFull(void)
Check, if the main render output buffer is full.
int m_framesDuped
number of frames duplicated
Definition: videorender.h:225
void SetScreenSize(int, int, uint32_t)
Wrapper to set the screen size in the device.
bool m_osdShown
set, if osd is shown currently
Definition: videorender.h:243
cCondVar m_grabCond
condition gets signalled, if renederer finished to clone the grabbed buffers
Definition: videorender.h:217
cDrmBuffer * m_pCurrentlyDisplayed
pointer to currently displayed DRM buffer
Definition: videorender.h:241
int m_pipScalePercent
scale factor for pip
Definition: videorender.h:234
int GetFramesFilled(void)
Definition: videorender.h:170
void ConvertPipBufToRgb(void)
Convert the pip drm buffer to an rgb image.
std::atomic< bool > m_resumeAudioScheduled
set, if audio resume is scheduled after a pause
Definition: videorender.h:245
void ConvertVideoBufToRgb(void)
Convert the video drm buffer to an rgb image.
void ResetBufferReuseStrategy()
Definition: videorender.h:140
std::atomic< bool > m_displayOneFrameThenPause
set, if only one frame shall be displayed and then pause playback
Definition: videorender.h:246
std::vector< Event > m_eventQueue
event queue for incoming events
Definition: videorender.h:206
cDrmBufferPool m_pipDrmBufferPool
PIP pool of drm buffers.
Definition: videorender.h:251
void ProcessEvents(void)
Process queued events and forward to event receiver.
int m_framesDropped
number of frames dropped
Definition: videorender.h:226
void OsdClear(void)
Clear the OSD (draw an empty/ transparent OSD)
cDisplayThread * m_pDisplayThread
pointer to display thread
Definition: videorender.h:203
int64_t m_pts
current video PTS
Definition: videorender.h:230
cSoftHdGrab * GetGrab(int *, int *, int *, int *, int *, int)
Get the grabbed image.
int m_trickSpeed
current trick speed
Definition: videorender.h:210
std::atomic< bool > m_pipActive
true, if pip should be displayed
Definition: videorender.h:264
cSoftHdGrab m_grabVideo
keeps the current grabbed video
Definition: videorender.h:219
int SetOsdBuffer(drmModeAtomicReqPtr)
Modesetting for osd.
void ClearDecoderToDisplayQueue(void)
Clear (empty) the decoder to display queue.
void Init(void)
Initialize the renderer.
void ResetDecodingStrategy()
Definition: videorender.h:141
std::atomic< bool > m_videoPlaybackPaused
set, if playback is frozen (used for pause)
Definition: videorender.h:244
void PushFrame(AVFrame *, bool, std::atomic< cBufferStrategy * > &, std::atomic< cDecodingStrategy * > &, cQueue< cDrmBuffer > *, cDrmBufferPool *)
Push the frame into the render ringbuffer.
void Exit(void)
Exit and cleanup the renderer.
cMutex m_trickspeedMutex
mutex used while accessing trickspeed parameters
Definition: videorender.h:204
cQueue< cDrmBuffer > m_drmBufferQueue
queue for DRM buffers to be displayed (VIDEO_SURFACES_MAX is defined in thread.h)
Definition: videorender.h:208
cRect m_lastVideoGrab
crtc rect of the last shown video frame
Definition: videorender.h:221
virtual ~cVideoRender(void)
cVideoRender destructor
cRect m_videoRect
rect of the currently displayed video
Definition: videorender.h:232
bool m_startgrab
internal flag to trigger grabbing
Definition: videorender.h:216
void GetStats(int *, int *, int *)
Get some rendering statistics.
std::atomic< cDecodingStrategy * > m_pipDecodingStrategy
strategy for decoding setup
Definition: videorender.h:255
void SetTrickSpeed(int, int)
Set the trickspeed parameters.
std::atomic< cBufferStrategy * > m_bufferReuseStrategy
strategy to select drm buffers
Definition: videorender.h:252
void DisplayBlackFrame(void)
void SetVideoClock(int64_t)
Wrapper to set the video clock (m_pts)
cSoftHdAudio * m_pAudio
pointer to cSoftHdAudio
Definition: videorender.h:201
AVRational m_timebase
timebase used for pts, set by first RenderFrame()
Definition: videorender.h:228
void PushMainFrame(AVFrame *)
void SetVideoOutputPosition(const cRect &)
Set size and position of the video on the screen.
cVideoRender(cSoftHdDevice *)
cVideoRender constructor
Definition: videorender.cpp:80
int GetFrameFlags(AVFrame *)
Get frame flags.
int m_pipTopPercent
top margin for pip
Definition: videorender.h:236
cDrmBuffer * m_pBufOsd
pointer to osd drm buffer object
Definition: videorender.h:239
int64_t GetOutputPtsMs(void)
Get the output PTS in milliseconds.
cSoftHdDevice * m_pDevice
pointer to cSoftHdDevice
Definition: videorender.h:200
int m_framePresentationCounter
number of times the current frame has to be shown (for slow motion)
Definition: videorender.h:212
void SetPipActive(bool on)
Definition: videorender.h:194
std::atomic< cBufferStrategy * > m_pipBufferReuseStrategy
strategy to select drm buffers
Definition: videorender.h:253
cSoftHdConfig * m_pConfig
pointer to cSoftHdConfig
Definition: videorender.h:202
void DisplayThreadHalt(void)
Definition: videorender.h:162
void ClearPipDecoderToDisplayQueue(void)
Clear (empty) the decoder to display queue.
void ClearGrab(void)
Clear the grab drm buffers.
bool IsPipActive(void)
Definition: videorender.h:195
cSoftHdGrab m_grabOsd
keeps the current grabbed osd
Definition: videorender.h:218
int CommitBuffer(cDrmBuffer *, cDrmBuffer *)
Commit the frame to the hardware.
int TriggerGrab(void)
Trigger a screen grab.
IEventReceiver * m_pEventReceiver
pointer to event receiver
Definition: videorender.h:249
cQueue< cDrmBuffer > m_pipDrmBufferQueue
queue for PIP DRM buffers to be displayed (VIDEO_SURFACES_MAX is defined in thread....
Definition: videorender.h:209
cQueue< cDrmBuffer > * GetPipOutputBuffer(void)
Definition: videorender.h:180
cRect m_lastPipGrab
crtc rect of the last shown pip frame
Definition: videorender.h:222
void LogDroppedDuped(int64_t, int64_t, int)
Log A/V sync debug message.
void SetPipBuffer(cDrmBuffer *)
Modesetting for pip.
bool DisplayFrame()
Display the frame (video and/or osd)
void ConvertOsdBufToRgb(void)
Convert the osd drm buffer to an rgb image.
void SchedulePlaybackStartAtPtsMs(int64_t ptsMs)
Definition: videorender.h:178
void SetVideoBuffer(cDrmBuffer *)
Modesetting for video.
cDrmBuffer * m_pCurrentlyPipDisplayed
pointer to currently displayed DRM buffer
Definition: videorender.h:242
int64_t GetVideoClock(void)
Wrapper to get the video clock (m_pts)
int GetTrickForward(void)
Get the current trickspeed direction.
void OsdDrawARGB(int, int, int, int, int, const uint8_t *, int, int)
Draw an OSD ARGB image.
void SetScheduleAudioResume(bool resume)
Definition: videorender.h:137
cDrmDevice * m_pDrmDevice
pointer cDrmDevice object
Definition: videorender.h:238
void Grab(cDrmBuffer *, cDrmBuffer *)
Grab video and osd.
cMutex m_timebaseMutex
mutex used around m_timebase
Definition: videorender.h:229
cMutex m_videoClockMutex
mutex used around m_pts
Definition: videorender.h:205
int64_t PtsToMs(int64_t)
std::atomic< cDecodingStrategy * > m_decodingStrategy
strategy for decoding setup
Definition: videorender.h:254
void SetDisplayOneFrameThenPause(bool pause)
Definition: videorender.h:177
int GetTrickSpeed(void)
Get the current trickspeed.
bool m_lastFrameWasDropped
true, if the last frame was dropped
Definition: videorender.h:227
void SetPipSize(bool)
bool PageFlip(cDrmBuffer *, cDrmBuffer *)
Do the pageflip.
int m_pipLeftPercent
left margin for pip
Definition: videorender.h:235
void SetPlaybackPaused(bool pause)
Definition: videorender.h:136
cDrmBufferPool m_drmBufferPool
pool of drm buffers
Definition: videorender.h:250
std::atomic< int64_t > m_schedulePlaybackStartAtPtsMs
if set, frames with PTS older than this will be dropped
Definition: videorender.h:247
void DisplayThreadResume(void)
Definition: videorender.h:163
void ResetFrameCounter(void)
Send start condition to video thread.
int m_startCounter
counter for displayed frames, indicates a video start
Definition: videorender.h:224
bool m_trickForward
true, if trickspeed plays forward
Definition: videorender.h:211
bool m_videoIsScaled
true, if the currently displayed video is scaled
Definition: videorender.h:233
void ExitDisplayThread(void)
Stop display thread.
cQueue< cDrmBuffer > * GetMainOutputBuffer(void)
Definition: videorender.h:179
cDrmBuffer m_bufBlack
black drm buffer object
Definition: videorender.h:240
cSoftHdGrab m_grabPip
keeps the current grabbed pip video
Definition: videorender.h:220
SoftHdDevice config header file.
DRM buffer header file.
DRM device header file.
DRM plane class header.
State machine and event header file.
Some helper functions for GL.
Grabber header file.
Atomic wrapper macros function header file.
Logger class header file.
#define AV_NOPTS_VALUE
Definition: misc.h:35
#define VIDEO_SURFACES_MAX
Definition: misc.h:38
Thread-safe queue header file.
Device class header file.
Thread classes header file.
Videostream class header file.