vdr-plugin-drmdevice 2.0.0-46418f1
device.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
13#ifndef __DRMDEVICE_OUTPUT_DEVICE_H
14#define __DRMDEVICE_OUTPUT_DEVICE_H
15
16#include <atomic>
17#include <mutex>
18
19extern "C"
20{
21#include <libavcodec/avcodec.h>
22}
23
24#include <vdr/device.h>
25#include <vdr/osd.h>
26#include <vdr/status.h>
27#include <vdr/thread.h>
28
29#include "config.h"
30#include "hardwaredevice.h"
31#include "jittertracker.h"
32#include "pes.h"
33#include "statemachine.h"
34
35class cAudioDecoder;
36class cAudioStream;
38class cDvbSpuDecoder;
39class cGrabber;
40class cOutputDevice;
41class cPipHandler;
42class cPipReceiver;
43class cSpuDecoder;
44class cStateMachine;
45class cVideoRender;
46class cVideoStream;
47
64
72class cOutputDevice : public cDevice, public cStatus {
73public:
75 virtual ~cOutputDevice(void);
76
77 //
78 // VDR cPlugin interface (wrapped by cPluginDrmDevice)
79 //
80 bool Initialize(void);
81 int Start(void);
82 void Stop(void);
83
84 //
85 // VDR cDevice interface
86 //
87protected:
88 virtual void MakePrimaryDevice(bool);
89public:
90 virtual cString DeviceName(void) const { return "drmdevice"; }
91 virtual bool HasDecoder(void) const;
92
93 // SPU facilities
94 virtual cSpuDecoder * GetSpuDecoder(void);
95
96 // Image grab facilities
97 virtual uchar *GrabImage(int &, bool, int, int, int);
98
99 // Video format facilities
101 virtual void SetVideoFormat(bool);
102 virtual void GetVideoSize(int &, int &, double &);
103 virtual void GetOsdSize(int &, int &, double &);
104
105 // Audio facilities
106protected:
107 virtual void SetVolumeDevice(int);
108
109 // Player facilities
110 virtual bool CanReplay(void) const;
111 virtual bool SetPlayMode(ePlayMode);
112 virtual int PlayVideo(const uchar *, int);
113 virtual int PlayAudio(const uchar *, int, uchar);
114public:
115 virtual int64_t GetSTC(void);
116 virtual cRect CanScaleVideo(const cRect &, int taCenter);
117 virtual void ScaleVideo(const cRect & = cRect::Null);
118 virtual void TrickSpeed(int, bool);
119 virtual void Clear(void);
120 virtual void Play(void);
121 virtual void Freeze(void);
122 virtual void StillPicture(const uchar *, int);
123 virtual bool Poll(cPoller &, int = 0);
124 virtual bool Flush(int = 0);
125#if APIVERSNUM >= 30014
126 virtual bool DrainDevice(void);
127#endif
128
129 //
130 // VDR cStatus interface
131 //
132protected:
133 virtual void ChannelSwitch(const cDevice *, int, bool);
134 virtual void Replaying(const cControl *, const char *, const char *, bool);
135
136 //
137 // cOutputDevice public API
138 //
139public:
140 cDeviceConfig *Config(void) { return m_pConfig; };
142 cVideoRender *Render(void) { return m_pRender; };
143 cAudioStream *Audio(void) { return m_pAudio; };
144
145 // Playback, display and decoder
146 void SetDisableDeint(void);
147 void SetDecoderFallbackToSw(bool);
148 void SetEnableHdr(bool);
150 void SetDisplayMode(int);
157
158 // Osd
159#ifdef USE_GLES
160 int MaxSizeGPUImageCache(void);
161 int OglOsdIsDisabled(void);
162 void SetDisableOglOsd(void);
163 void SetEnableOglOsd(void);
164#endif
165 void OsdClose(void);
166 void OsdDraw(int, int, int, int, int, const uint8_t *, int, int);
167 void SetOsdSize(int, int);
168 void SetScreenSize(int, int);
169
170 // Audio
173 void SetPassthroughMask(int);
174 void ResetChannelId(void);
175
176 // Logging, statistics
177 void GetStats(int *, int *, int *);
178
179 // Mediaplayer
182 int PlayAudioPkts(AVPacket *);
183 int PlayVideoPkts(AVPacket *);
184
185 // Detach/ attach
186 void Detach(void);
187 void Attach(void);
188 bool IsDetached(void) const;
189 void ResetOsdProvider(void) { m_pOsdProvider = nullptr; }
190 bool IsOsdProviderSet(void) const { return m_pOsdProvider != nullptr; }
191 void SetStartDetached(void) { m_forceDetached = true; };
192 bool IsDraining(void) { return m_draining; };
193
194 // Pip
195 int PlayPipVideo(const uchar *, int);
198 void ResetPipStream(void);
200 // wrapper functions
201 void SetDisablePip(void) { m_disablePip = true; };
202 bool PipIsEnabled(void);
203 void PipEnable(void);
204 void PipDisable(void);
205 void PipToggle(void);
206 void PipChannelChange(int);
207 void PipChannelSwap(bool);
208 void PipSwapPosition(void);
209 void PipSetSize(void);
210 void SetRenderPipSize(void);
211 void SetRenderPipActive(bool);
212
213 // state transitioning functions
214 void TriggerEvent(const Event&);
215
216 void LeaveState(State);
217 void EnterState(State);
218 void HandleStillPicture(const uchar *data, int size);
219 void HandleDisplayModeChange(const sDrmMode &);
220 void HaltVideoThreads(void);
221 void ResumeVideoThreads(void);
222#ifdef USE_GLES
223 bool HaltOpenGlThread(void);
224 void ResumeOpenGlThread(void);
225#endif
226 bool IsDetachForced(void);
227 void SetDetachForced(void) { m_forceDetached = true; };
228 int InitAudio(bool);
229 void ResetVideoFilter(void);
230 void SetTrickSpeed(double, bool, bool);
231 bool SchedulePlaybackStart(void);
233 void ResumeFromPause(void);
234 void PausePlayback(bool);
235 void ResumePlayback(void);
236
237private:
238 static constexpr int MIN_BUFFER_FILL_LEVEL_THRESHOLD_MS = 450;
239
240 std::unique_ptr<cStateMachine> m_pStateMachine;
241
242 bool m_initialized = false;
243 std::atomic<bool> m_draining = false;
244 std::mutex m_eventMutex;
245 bool m_needsMakePrimary = false;
259 std::atomic<ChannelSwitchMode> m_channelSwitchMode = CHANNEL_SWITCH_AVSYNC;
261
262 std::atomic<PlaybackMode> m_playbackMode = NONE;
265
269 std::mutex m_sizeMutex;
270 std::atomic<bool> m_receivedAudio = false;
271 std::atomic<bool> m_receivedVideo = false;
272 std::atomic<bool> m_receivedValidAudio = false;
273 std::atomic<bool> m_receivedValidVideo = false;
275 bool m_drmCanDisplayPip = true;
276 bool m_disablePip = false;
277 int m_volume = 0;
278
283
284 bool m_forceDetached = false;
286
287 int PlayVideoInternal(cVideoStream *, cReassemblyBufferVideo *, const uchar *, int, bool, bool);
288 void FlushAudio(void);
292 void SetDrain(bool);
293};
294
295#endif
Audio Decoder.
Definition codec_audio.h:61
Audio Interface.
Definition audio.h:51
Plugin Configuration.
Definition config.h:65
int ConfigVideoAudioDelayMs
config audio delay
Definition config.h:85
Plugin OSD provider.
Definition osdprovider.h:33
Event handler thread.
Grabbing Processor.
Definition grab.h:79
Hardware device.
Jitter Tracker.
Output Device Implementation.
Definition device.h:72
bool m_externalPlayerActive
true, if we detached for an external player
Definition device.h:285
std::mutex m_sizeMutex
mutex to lock screen size (which is accessed by different threads)
Definition device.h:269
virtual void TrickSpeed(int, bool)
Sets the device into a mode where replay is done slower.
Definition device.cpp:585
cVideoRender * m_pRender
pointer to cVideoRender object
Definition device.h:248
virtual bool CanReplay(void) const
Return true if this device can currently start a replay session.
Definition device.cpp:311
cAudioDecoder * m_pAudioDecoder
pointer to cAudioDecoder object
Definition device.h:251
bool m_initialized
true, if the plugin had a successful Initialize()
Definition device.h:242
std::unique_ptr< cStateMachine > m_pStateMachine
Definition device.h:240
void HandleStillPicture(const uchar *data, int size)
The still picture data received from VDR can contain multiple PES packets.
Definition device.cpp:1615
bool CheckAudioPlaybackStartConditions(void)
Returns true, if audio playback should start without respect to a/v-sync.
Definition device.cpp:1066
int m_audioChannelID
current audio channel ID
Definition device.h:263
void SetVideoCodec(enum AVCodecID, AVCodecParameters *, AVRational)
Open a video codec.
Definition device.cpp:1287
void HandleDisplayModeChange(const sDrmMode &)
Set the display mode.
Definition device.cpp:1647
int MaxSizeGPUImageCache(void)
Get the maximum GPU image cache size.
Definition device.cpp:1125
void SetRenderPipActive(bool)
Definition device.cpp:1469
bool m_logPlaybackStart
Definition device.h:260
void SetPassthroughMask(int)
Set the passthrough mask (called from setup menu or conf)
Definition device.cpp:1227
int PlayPipVideo(const uchar *, int)
Play a video packet of the pip videostream.
Definition device.cpp:1401
virtual int PlayAudio(const uchar *, int, uchar)
Play an audio packet.
Definition device.cpp:382
void EnterState(State)
Actions to be performed when entering a state.
Definition device.cpp:1804
void LeaveState(State)
Actions to be performed when leaving a state.
Definition device.cpp:1737
std::atomic< ChannelSwitchMode > m_channelSwitchMode
current channel switch mode
Definition device.h:259
int PlayVideoPkts(AVPacket *)
Play a video packet.
Definition device.cpp:1320
void ResumeVideoThreads(void)
Resume the rendering and decoder thread.
Definition device.cpp:1911
void TriggerEvent(const Event &)
With this wrapper function, the device can directly act as an event reveiver.
Definition device.cpp:1724
bool HaltOpenGlThread(void)
Pause the OpenGL worker thread.
Definition device.cpp:1921
cAudioStream * Audio(void)
Definition device.h:143
void SetEnableHdr(bool)
Enable HDR display mode.
Definition device.cpp:904
int OglOsdIsDisabled(void)
Is the OpenGL/ES osd disabled?
Definition device.cpp:1133
void SetDrmCanDisplayPip(bool canDisplay)
Definition device.h:196
std::atomic< bool > m_receivedAudio
flag if audio packets have been received
Definition device.h:270
std::atomic< bool > m_draining
true, if the device is in draining mode (waiting for empty buffers)
Definition device.h:243
virtual cSpuDecoder * GetSpuDecoder(void)
Get the device SPU decoder.
Definition device.cpp:163
void PipChannelChange(int)
Definition device.cpp:1452
int64_t GetFirstAudioPtsMsToPlay()
Calculate the first audio PTS that should be played during synchronized playback.
Definition device.cpp:1671
int m_osdHeight
Definition device.h:280
cDvbSpuDecoder * m_pSpuDecoder
pointer to spu decoder
Definition device.h:246
void Detach(void)
Detach the device.
Definition device.cpp:1343
void SetDecoderFallbackToSw(bool)
Force the decoder to fallback to software if the hardware decoder fails after the configured amount o...
Definition device.cpp:890
virtual bool Flush(int=0)
Return true, if the output buffers are empty, false otherwise.
Definition device.cpp:776
bool IsDraining(void)
Definition device.h:192
std::atomic< PlaybackMode > m_playbackMode
current playback mode
Definition device.h:262
void FlushAudio(void)
Clear all audio data from the decoder and ringbuffer.
Definition device.cpp:1600
bool m_drmCanDisplayPip
true, if the drm device is able to display a pip video
Definition device.h:275
virtual bool HasDecoder(void) const
Tells whether this device has an MPEG decoder.
Definition device.cpp:148
bool UsePip(void)
Definition device.h:197
int GetBufferFillLevelThresholdMs()
Returns the buffer fill level threshold in milliseconds.
Definition device.cpp:1698
bool m_needsMakePrimary
true, if device should be made a primary device after attach
Definition device.h:245
virtual uchar * GrabImage(int &, bool, int, int, int)
Grabs the currently visible screen image.
Definition device.cpp:181
void Stop(void)
Called by VDR when the plugin is stopped.
Definition device.cpp:119
void ResetChannelId(void)
Reset the channel ID (restarts audio)
Definition device.cpp:1237
cDeviceConfig * m_pConfig
pointer to cDeviceConfig object
Definition device.h:247
void SetOsdSize(int, int)
Set the OSD size.
Definition device.cpp:1200
void PipDisable(void)
Definition device.cpp:1450
void SetChannelSwitchMode(ChannelSwitchMode mode)
Definition device.h:149
virtual ~cOutputDevice(void)
Destroy the device.
Definition device.cpp:65
void ToggleRenderPipPosition(void)
Definition device.h:199
void SetEnableOglOsd(void)
Enables OpenGL/ES Osd.
Definition device.cpp:1151
virtual void SetVideoDisplayFormat(eVideoDisplayFormat)
Sets the video display format.
Definition device.cpp:218
void Attach(void)
Attach the device again.
Definition device.cpp:1365
bool Initialize(void)
Initialize the device.
Definition device.cpp:84
void OsdDraw(int, int, int, int, int, const uint8_t *, int, int)
Draw an OSD pixmap.
Definition device.cpp:1185
void ResetVideoFilter(void)
Reset the video deinterlace filter.
Definition device.cpp:1966
virtual void Freeze(void)
Puts the device into "freeze frame" mode.
Definition device.cpp:709
cAudioStream * m_pAudio
pointer to cAudioStream object
Definition device.h:250
cGrabber * m_pGrab
pointer to grabber object
Definition device.h:264
bool CheckPlaybackStartConditions(void)
Check, if all conditions are met to start the playback.
Definition device.cpp:965
void ResumePlayback(void)
Resume playback again.
Definition device.cpp:2094
cHardwareDevice * m_pHardwareDevice
pointer to hardware device description
Definition device.h:253
int GetMinBufferFillLevelThresholdMs(void)
Definition device.h:172
void PipSetSize(void)
Definition device.cpp:1455
bool IsVideoOnlyPlayback(void)
Definition device.h:155
virtual void Play(void)
Sets the device into play mode (after a previous trick mode, or pause)
Definition device.cpp:698
cEventHandler * m_pEventHandler
event handler thread
Definition device.h:254
void PipChannelSwap(bool)
Definition device.cpp:1453
void PipEnable(void)
Definition device.cpp:1449
bool IsAudioOnlyPlayback(void)
Definition device.h:156
virtual void ScaleVideo(const cRect &=cRect::Null)
Scale the currently shown video.
Definition device.cpp:561
int64_t GetFirstVideoPtsMsToPlay()
Definition device.cpp:1684
int PlayVideoInternal(cVideoStream *, cReassemblyBufferVideo *, const uchar *, int, bool, bool)
Play a video packet.
Definition device.cpp:1531
void SetDetachForced(void)
Definition device.h:227
bool FastChannelSwitchInTransferMode(void)
Definition device.h:152
void SetRenderPipSize(void)
Definition device.cpp:1460
void SetDisplayMode(int)
Trigger a display mode change event if the mode changed.
Definition device.cpp:914
std::mutex m_eventMutex
mutex to protect event queue
Definition device.h:244
cReassemblyBufferAudio m_audioReassemblyBuffer
audio pes reassembly buffer
Definition device.h:256
cJitterTracker m_videoJitterTracker
video jitter tracker
Definition device.h:258
bool m_forceDetached
start the plugin in detached state
Definition device.h:284
bool PipIsEnabled(void)
Returns true, if pip is currently enabled.
Definition device.cpp:1442
bool IsDetached(void) const
Returns true, if the device is detached.
Definition device.cpp:1380
void SetDisableDeint(void)
Disables deinterlacer (called from setup menu or conf)
Definition device.cpp:879
void SetDrain(bool)
Set and log the drain state changes.
Definition device.cpp:1708
virtual void Replaying(const cControl *, const char *, const char *, bool)
Monitor a replay start or end.
Definition device.cpp:859
static constexpr int MIN_BUFFER_FILL_LEVEL_THRESHOLD_MS
min buffering threshold in ms
Definition device.h:238
cVideoStream * m_pPipStream
pointer to pip video stream
Definition device.h:266
virtual void Clear(void)
Clears all video and audio data from the device.
Definition device.cpp:658
bool IsOsdProviderSet(void) const
Definition device.h:190
bool m_disablePip
true, if pip was disabled by the user
Definition device.h:276
int GetVideoAudioDelayMs(void)
Definition device.h:171
cPipHandler * m_pPipHandler
pointer to pip handler
Definition device.h:268
virtual bool SetPlayMode(ePlayMode)
Sets the device into the given play mode.
Definition device.cpp:325
void SetDisablePip(void)
Definition device.h:201
void SetAudioCodec(enum AVCodecID, AVCodecParameters *, AVRational)
Open an audio codec.
Definition device.cpp:1275
int m_screenWidth
Definition device.h:281
void ResetOsdProvider(void)
Definition device.h:189
std::atomic< bool > m_receivedValidVideo
flag if valid video packets have been received
Definition device.h:273
void HaltVideoThreads(void)
Pause the rendering and decoder thread.
Definition device.cpp:1902
int m_osdWidth
Definition device.h:279
bool IsDetachForced(void)
Returns true, the a detached plugin start was forced.
Definition device.cpp:1939
std::atomic< bool > m_receivedVideo
flag if video packets have been received
Definition device.h:271
cReassemblyBufferVideo m_pipReassemblyBuffer
pip pes reassembly buffer
Definition device.h:267
cReassemblyBufferVideo m_videoReassemblyBuffer
video pes reassembly buffer
Definition device.h:255
cJitterTracker m_audioJitterTracker
audio jitter tracker
Definition device.h:257
void OsdClose(void)
Close the OSD.
Definition device.cpp:1165
void ResetPipStream(void)
Resets pip stream and render pipeline.
Definition device.cpp:1418
virtual void SetVideoFormat(bool)
Set the video format.
Definition device.cpp:235
void SetTrickSpeed(double, bool, bool)
Set the trickspeed in the renderer.
Definition device.cpp:1979
virtual void GetVideoSize(int &, int &, double &)
Get the video size.
Definition device.cpp:255
virtual int64_t GetSTC(void)
Gets the current System Time Counter, which can be used to synchronize audio, video and subtitles.
Definition device.cpp:497
void GetStats(int *, int *, int *)
Get statistics from the renderer.
Definition device.cpp:1254
void SetScreenSize(int, int)
Set the screen size.
Definition device.cpp:1213
bool m_pipUseAlt
use alternative pip position
Definition device.h:274
void SetDisableOglOsd(void)
Disables OpenGL/ES Osd (called from setup menu or conf)
Definition device.cpp:1141
void PipToggle(void)
Definition device.cpp:1451
int InitAudio(bool)
Init the audio lazily.
Definition device.cpp:1952
virtual void SetVolumeDevice(int)
Sets the audio volume on this device (Volume = 0...255).
Definition device.cpp:298
virtual void MakePrimaryDevice(bool)
Informs a device that it will be the primary device.
Definition device.cpp:135
void SetStartDetached(void)
Definition device.h:191
void ResumeOpenGlThread(void)
Resume the OpenGL worker thread.
Definition device.cpp:1929
cVideoStream * VideoStream(void)
Definition device.h:141
void PausePlayback(bool)
Pause the playback.
Definition device.cpp:2080
virtual int PlayVideo(const uchar *, int)
Play a video packet of the main videostream.
Definition device.cpp:482
std::atomic< bool > m_receivedValidAudio
flag if valid audio packets have been received
Definition device.h:272
bool FastChannelSwitchAudioInTransferMode(void)
Definition device.h:151
int PlayAudioPkts(AVPacket *)
Play an audio packet.
Definition device.cpp:1300
cDeviceConfig * Config(void)
Definition device.h:140
void ScheduleResyncAtPtsMs(int64_t)
Schedule aa a/v resync in the render thread at the given pts.
Definition device.cpp:2034
cDeviceOsdProvider * m_pOsdProvider
pointer to cDeviceOsdProvider object
Definition device.h:252
virtual cString DeviceName(void) const
Definition device.h:90
virtual bool Poll(cPoller &, int=0)
Return true if the device itself or any of the file handles in poller is ready for further action.
Definition device.cpp:747
virtual cRect CanScaleVideo(const cRect &, int taCenter)
Ask the output, if it can scale video.
Definition device.cpp:526
cVideoRender * Render(void)
Definition device.h:142
void PipSwapPosition(void)
Definition device.cpp:1454
bool SchedulePlaybackStart(void)
Schedules the playback start.
Definition device.cpp:1994
void ResumeFromPause(void)
Resume playback from pause state.
Definition device.cpp:2044
int Start(void)
Called by VDR when the plugin is started.
Definition device.cpp:108
int m_screenHeight
Definition device.h:282
virtual void GetOsdSize(int &, int &, double &)
Returns the width, height and aspect ratio the OSD should have.
Definition device.cpp:278
virtual void ChannelSwitch(const cDevice *, int, bool)
Monitor a channel switch triggered by VDR (cStatus::ChannelSwitch())
Definition device.cpp:844
virtual void StillPicture(const uchar *, int)
Display the given I-frame as a still picture.
Definition device.cpp:723
cVideoStream * m_pVideoStream
pointer to main video stream
Definition device.h:249
int m_volume
track the volume in the device (for attach)
Definition device.h:277
PiP Stream Handler.
Definition pip.h:55
Receiver for PiP Stream.
Definition pip.h:31
Audio Stream Reassembly Buffer.
Definition pes.h:178
Video Stream Reassembly Buffer.
Definition pes.h:145
State Machine Implementation.
Video Renderer.
Video Input Stream.
Definition videostream.h:48
Plugin Configuration Header File.
PlaybackMode
Definition device.h:58
std::variant< PlayEvent, PauseEvent, StopEvent, TrickSpeedEvent, StillPictureEvent, DetachEvent, AttachEvent, BufferUnderrunEvent, BufferingThresholdReachedEvent, ScheduleResyncAtPtsMsEvent, ResyncEvent, DisplayChangeEvent > Event
State
ChannelSwitchMode
Channel switch modes.
Definition config.h:54
@ AUDIO_AND_VIDEO
Definition device.h:60
@ VIDEO_ONLY
Definition device.h:62
@ AUDIO_ONLY
Definition device.h:61
@ NONE
Definition device.h:59
@ CHANNEL_SWITCH_AVSYNC
Definition config.h:55
@ CHANNEL_SWITCH_FAST_AUDIO
Definition config.h:57
Describes a hardware device.
Jitter Tracking of Incoming Packets Header File.
PES Packet Parser Header File.
Device State Machine and Event Handler Header File.
Holds possible display configurations.
Definition config.h:30