vdr-plugin-softhddevice-drm-gles 1.5.9-20e15de
softhddevice.h
Go to the documentation of this file.
1
21#ifndef __SOFTHDDEVICE_H
22#define __SOFTHDDEVICE_H
23
24#if __cplusplus < 201703L
25#error "C++17 or higher is required"
26#endif
27
28#include <atomic>
29#include <mutex>
30
31extern "C"
32{
33#include <libavcodec/avcodec.h>
34}
35
36#include <vdr/device.h>
37#include <vdr/osd.h>
38
39#include "config.h"
40#include "event.h"
41#include "jittertracker.h"
42#include "pes.h"
43
44// State machine definitions
45// Implementing C++17 visitor pattern
46
47template<class... Ts>
48struct overload : Ts... { using Ts::operator()...; };
49template<class... Ts> overload(Ts...) -> overload<Ts...>;
50
58
59inline const char* EventToString(const Event& e) {
60 return std::visit(overload{
61 [](const PlayEvent&) -> const char* { return "PlayEvent"; },
62 [](const PauseEvent&) -> const char* { return "PauseEvent"; },
63 [](const StopEvent&) -> const char* { return "StopEvent"; },
64 [](const TrickSpeedEvent&) -> const char* { return "TrickSpeedEvent"; },
65 [](const StillPictureEvent&) -> const char* { return "StillPictureEvent"; },
66 [](const DetachEvent&) -> const char* { return "DetachEvent"; },
67 [](const AttachEvent&) -> const char* { return "AttachEvent"; },
68 [](const BufferUnderrunEvent& e) -> const char* { return e.type == AUDIO ? "BufferUnderrunEvent: Audio" : "BufferUnderrunEvent: Video"; },
69 [](const BufferingThresholdReachedEvent&) -> const char* { return "BufferingThresholdReachedEvent"; },
70 [](const PipEvent&) -> const char* { return "PipEvent"; },
71 [](const ScheduleResyncAtPtsMsEvent&) -> const char* { return "ScheduleResyncAtPtsMsEvent"; },
72 [](const ResyncEvent&) -> const char* { return "ResyncEvent"; },
73 }, e);
74}
75
76inline const char* StateToString(State s) {
77 switch(s) {
78 case State::STOP: return "STOP";
79 case State::BUFFERING: return "BUFFERING";
80 case State::PLAY: return "PLAY";
81 case State::TRICK_SPEED: return "TRICK_SPEED";
82 case State::DETACHED: return "DETACHED";
83 }
84 return "Unknown";
85}
86
93
94class cAudioDecoder;
95class cDvbSpuDecoder;
96class cPipHandler;
97class cPipReceiver;
98class cSpuDecoder;
99class cSoftHdAudio;
100class cSoftHdGrab;
101class cSoftOsdProvider;
102class cVideoRender;
103class cVideoStream;
104
105/*****************************************************************************
106 * cSoftHdDevice - cDevice class
107 ****************************************************************************/
108
109class cSoftHdDevice : public cDevice, public IEventReceiver
110{
111public:
113 virtual ~cSoftHdDevice(void);
114
115 //
116 // virtual cDevice
117 //
118protected:
119 virtual void MakePrimaryDevice(bool);
120
121public:
122 virtual cString DeviceName(void) const { return "softhddevice-drm-gles"; }
123 virtual bool HasDecoder(void) const;
124
125 // SPU facilities
126 virtual cSpuDecoder * GetSpuDecoder(void);
127
128 // player facilities
129 virtual bool CanReplay(void) const;
130 virtual bool SetPlayMode(ePlayMode);
131 virtual int PlayVideo(const uchar *, int);
132 virtual int PlayAudio(const uchar *, int, uchar);
133 virtual int64_t GetSTC(void);
134 virtual cRect CanScaleVideo(const cRect &, int taCenter);
135 virtual void ScaleVideo(const cRect & = cRect::Null);
136 virtual void TrickSpeed(int, bool);
137 virtual void Clear(void);
138 virtual void Play(void);
139 virtual void Freeze(void);
140 virtual void StillPicture(const uchar *, int);
141 virtual bool Poll(cPoller &, int = 0);
142 virtual bool Flush(int = 0);
143
144 // Image Grab facilities
145 virtual uchar *GrabImage(int &, bool, int, int, int);
146
147 // video format facilities
148 virtual void SetVideoDisplayFormat(eVideoDisplayFormat);
149 virtual void SetVideoFormat(bool);
150 virtual void GetVideoSize(int &, int &, double &);
151 virtual void GetOsdSize(int &, int &, double &);
152
153 // track facilities
154 virtual void SetAudioTrackDevice(eTrackType);
155
156 // audio facilities
157 virtual int GetAudioChannelDevice(void);
158 virtual void SetAudioChannelDevice(int);
159 virtual void SetVolumeDevice(int);
160 virtual void SetDigitalAudioDevice(bool);
161
162 //
163 // wrapped by cPluginSoftHdDevice
164 //
165 const char *CommandLineHelp(void); // wrapped by cPluginSoftHdDevice::CommandLineHelp()
166 int ProcessArgs(int, char *[]); // wrapped by cPluginSoftHdDevice::ProcessArgs()
167 int Start(void);
168 void Stop(void);
169
170 //
171 // cSoftHdDevice public methods
172 //
173 cSoftHdConfig *Config(void) { return m_pConfig; };
175 cVideoRender *Render(void) { return m_pRender; };
176 cSoftHdAudio *Audio(void) { return m_pAudio; };
177
178 void SetDisableDeint(void);
179 void SetDecoderNeedsIFrame(void);
180 void SetParseH264Dimensions(void);
181 void SetDecoderFallbackToSw(bool enable);
182
183 // osd
184#ifdef USE_GLES
185 int MaxSizeGPUImageCache(void);
186 int OglOsdIsDisabled(void);
187 void SetDisableOglOsd(void);
188 void SetEnableOglOsd(void);
189#endif
190 void OsdClose(void);
191 void OsdDrawARGB(int, int, int, int, int, const uint8_t *, int, int);
192 void SetScreenSize(int, int, double);
193
194 // audio
196 void SetPassthrough(int);
197 void ResetChannelId(void);
198
199 // Logging, statistics
200 void GetStats(int *, int *, int *);
201
202 // Mediaplayer
203 void SetAudioCodec(enum AVCodecID, AVCodecParameters *, AVRational);
204 void SetVideoCodec(enum AVCodecID, AVCodecParameters *, AVRational);
205 int PlayAudioPkts(AVPacket *);
206 int PlayVideoPkts(AVPacket *);
207
208 // detach/ attach
209 void Detach(void);
210 void Attach(void);
211 bool IsDetached(void) const;
212 void ResetOsdProvider(void) { m_pOsdProvider = nullptr; }
213 bool IsOsdProviderSet(void) const { return m_pOsdProvider != nullptr; }
214
216
217 // pip wrapper functions
218 bool PipIsEnabled(void);
219 void PipEnable(void);
220 void PipDisable(void);
221 void PipToggle(void);
222 void PipChannelChange(int);
223 void PipChannelSwap(bool);
224 void PipSwapPosition(void);
225 void PipSetSize(void);
226 void SetRenderPipSize(void);
227 void SetRenderPipActive(bool);
228
229 // pip functions
230 int PlayPipVideo(const uchar *, int);
231 void SetDrmCanDisplayPip(bool canDisplay) { m_drmCanDisplayPip = canDisplay; };
233 void ResetPipStream(void);
235
236private:
237 static constexpr int MIN_BUFFER_FILL_LEVEL_THRESHOLD_MS = 450;
238
239 std::atomic<State> m_state = DETACHED;
240 std::mutex m_eventMutex;
241 bool m_needsMakePrimary = false;
242 cDvbSpuDecoder *m_pSpuDecoder;
253
254 std::atomic<PlaybackMode> m_playbackMode = NONE;
257
261 mutable std::mutex m_mutex;
262 std::mutex m_sizeMutex;
263 std::atomic<bool> m_receivedAudio = false;
264 std::atomic<bool> m_receivedVideo = false;
266 bool m_drmCanDisplayPip = true;
267 bool m_disablePip = false;
268
272
273 bool m_forceDetached = false;
274
275 int PlayVideoInternal(cVideoStream *, cReassemblyBufferVideo *, const uchar *, int, bool);
276 void ClearAudio(void);
277 void OnEventReceived(const Event&);
278 void HandleStillPicture(const uchar *data, int size);
279 int64_t GetFirstAudioPtsMsToPlay();
280 int64_t GetFirstVideoPtsMsToPlay();
281
283
284 // State machine
285 void SetState(State);
287 void OnLeavingState(State);
288};
289
290#endif
cAudioDecoder - Audio decoder class
Definition codec_audio.h:76
cPipHandler - class for pip
Definition pipreceiver.h:56
cPipReceiver - receiver class for pip
Definition pipreceiver.h:33
Audio stream reassembly buffer.
Definition pes.h:170
Video stream reassembly buffer.
Definition pes.h:141
cSoftHdAudio - Audio class
Definition audio.h:51
int ConfigVideoAudioDelayMs
config audio delay
Definition config.h:42
void SetState(State)
Sets the device into the given state.
void OsdDrawARGB(int, int, int, int, int, const uint8_t *, int, int)
Draw an OSD pixmap.
cReassemblyBufferVideo m_videoReassemblyBuffer
video pes reassembly buffer
void Stop(void)
Called by VDR when the plugin is stopped.
bool m_pipUseAlt
use alternative pip position
cReassemblyBufferVideo m_pipReassemblyBuffer
pip pes reassembly buffer
void PipChannelSwap(bool)
cVideoStream * m_pPipStream
pointer to pip video stream
void SetDecoderFallbackToSw(bool enable)
Force the decoder to fallback to software if the hardware decoder fails after the configured amount o...
void PipSwapPosition(void)
static constexpr int MIN_BUFFER_FILL_LEVEL_THRESHOLD_MS
min buffering threshold in ms
virtual void StillPicture(const uchar *, int)
Display the given I-frame as a still picture.
void PipSetSize(void)
cSoftOsdProvider * m_pOsdProvider
pointer to cSoftOsdProvider object
cVideoStream * m_pVideoStream
pointer to main video stream
cReassemblyBufferAudio m_audioReassemblyBuffer
audio pes reassembly buffer
std::atomic< bool > m_receivedAudio
flag if audio packets have been received
void SetRenderPipSize(void)
Wrapper functions for cVideoRender and cPipHandler.
cDvbSpuDecoder * m_pSpuDecoder
pointer to spu decoder
void OnEnteringState(State)
Actions to be performed when entering a state.
int Start(void)
Called by VDR when the plugin is started.
virtual void GetVideoSize(int &, int &, double &)
Get the video size.
bool IsOsdProviderSet(void) const
int PlayAudioPkts(AVPacket *)
Play an audio packet.
virtual void GetOsdSize(int &, int &, double &)
Returns the width, height and aspect ratio the OSD.
void SetRenderPipActive(bool)
void GetStats(int *, int *, int *)
Get statistics from the renderer.
void ClearAudio(void)
Clear all audio data from the decoder and ringbuffer.
void ResetChannelId(void)
Reset the channel ID (restarts audio)
virtual bool CanReplay(void) const
Returns true if this device can currently start a replay session.
virtual void SetDigitalAudioDevice(bool)
bool UsePip(void)
std::mutex m_mutex
mutex to lock the state machine
virtual bool HasDecoder(void) const
Tells whether this device has an MPEG decoder.
virtual void Clear(void)
Clears all video and audio data from the device.
void OnEventReceived(const Event &)
Event handler for playback state transitions.
cPipHandler * m_pPipHandler
pointer to pip handler
void Detach(void)
Detach the device.
virtual int PlayVideo(const uchar *, int)
Play a video packet of the main videostream.
void ResetPipStream(void)
Resets pip stream and render pipeline.
int GetVideoAudioDelayMs(void)
double m_screenRefreshRateHz
std::atomic< State > m_state
current plugin state, normal plugin start sets detached state
void OnLeavingState(State)
Actions to be performed when leaving a state.
virtual bool SetPlayMode(ePlayMode)
Sets the device into the given play mode.
cAudioDecoder * m_pAudioDecoder
pointer to cAudioDecoder object
void SetDrmCanDisplayPip(bool canDisplay)
void SetAudioCodec(enum AVCodecID, AVCodecParameters *, AVRational)
Open an audio codec.
virtual void Play(void)
Sets the device into play mode (after a previous trick mode, or pause)
bool IsBufferingThresholdReached(void)
Check if the buffering threshold has been reached.
cVideoRender * m_pRender
pointer to cVideoRender object
virtual void SetAudioChannelDevice(int)
cSoftHdGrab * m_pGrab
pointer to grabber object
const char * CommandLineHelp(void)
Return command line help string.
int PlayPipVideo(const uchar *, int)
Play a video packet of the pip videostream.
bool m_needsMakePrimary
cSoftHdAudio * m_pAudio
pointer to cSoftHdAudio object
cSoftHdConfig * m_pConfig
pointer to cSoftHdConfig object
void ResetOsdProvider(void)
virtual cRect CanScaleVideo(const cRect &, int taCenter)
Ask the output, if it can scale video.
bool m_disablePip
true, if pip was disabled by the user
virtual void SetVolumeDevice(int)
Sets the audio volume on this device (Volume = 0...255).
virtual int64_t GetSTC(void)
Gets the current System Time Counter, which can be used to synchronize audio, video and subtitles.
virtual bool Flush(int=0)
Flush the device output buffers.
bool IsDetached(void) const
Returns true, if the device is detached.
cVideoRender * Render(void)
virtual void TrickSpeed(int, bool)
Sets the device into a mode where replay is done slower.
cVideoStream * VideoStream(void)
virtual int PlayAudio(const uchar *, int, uchar)
Play an audio packet.
void PipToggle(void)
bool PipIsEnabled(void)
Returns true, if pip is currently enabled.
std::mutex m_sizeMutex
mutex to lock screen size (which is accessed by different threads)
std::atomic< bool > m_receivedVideo
flag if video packets have been received
void SetDecoderNeedsIFrame(void)
Forces the h264 decoder to wait for an I-Frame to start.
int PlayVideoInternal(cVideoStream *, cReassemblyBufferVideo *, const uchar *, int, bool)
Play a video packet.
virtual int GetAudioChannelDevice(void)
int PlayVideoPkts(AVPacket *)
Play a video packet.
void SetScreenSize(int, int, double)
Set the screen size.
cJitterTracker m_audioJitterTracker
audio jitter tracker
virtual cString DeviceName(void) const
int GetBufferFillLevelThresholdMs()
Returns the buffer fill level threshold in milliseconds.
void SetPassthrough(int)
Set the passthrough mask (called from setup menu or conf)
void HandleStillPicture(const uchar *data, int size)
The still picture data received from VDR can contain multiple PES packets.
std::mutex m_eventMutex
mutex to protect event queue
virtual void SetVideoDisplayFormat(eVideoDisplayFormat)
Sets the video display format.
virtual void Freeze(void)
Puts the device into "freeze frame" mode.
void SetParseH264Dimensions(void)
Parse the h264 stream width and height before starting the decoder.
cSoftHdConfig * Config(void)
bool m_forceDetached
start the plugin in detached state
virtual ~cSoftHdDevice(void)
cSoftHdDevice destructor
int m_audioChannelID
current audio channel ID
void PipDisable(void)
virtual void SetVideoFormat(bool)
Set the video format.
virtual void MakePrimaryDevice(bool)
Informs a device that it will be the primary device.
void SetVideoCodec(enum AVCodecID, AVCodecParameters *, AVRational)
Open a video codec.
void PipEnable(void)
void SetDisableDeint(void)
Disables deinterlacer (called from setup menu or conf)
virtual uchar * GrabImage(int &, bool, int, int, int)
Grabs the currently visible screen image.
virtual cSpuDecoder * GetSpuDecoder(void)
Get the device SPU decoder.
cJitterTracker m_videoJitterTracker
video jitter tracker
virtual void SetAudioTrackDevice(eTrackType)
bool m_drmCanDisplayPip
true, if the drm device is able to display a pip video
std::atomic< PlaybackMode > m_playbackMode
current playback mode
void OsdClose(void)
Close the OSD.
int64_t GetFirstAudioPtsMsToPlay()
Calculate the first audio PTS that should be played during synchronized playback.
virtual void ScaleVideo(const cRect &=cRect::Null)
Scale the currently shown video.
int64_t GetFirstVideoPtsMsToPlay()
int ProcessArgs(int, char *[])
Process the command line arguments.
cSoftHdAudio * Audio(void)
void PipChannelChange(int)
virtual bool Poll(cPoller &, int=0)
Returns true if the device itself or any of the file handles in Poller is ready for further action.
void Attach(void)
Attach the device again.
void ToggleRenderPipPosition(void)
cSoftHdGrab - Grabber class
Definition grab.h:82
cSoftOsdProvider - SoftHdDevice plugin OSD provider class
Definition softhdosd.h:67
cVideoRender - Video render class
cVideoStream - Video stream class
Definition videostream.h:55
SoftHdDevice config header file.
State machine and event header file.
std::variant< PlayEvent, PauseEvent, StopEvent, TrickSpeedEvent, StillPictureEvent, DetachEvent, AttachEvent, BufferUnderrunEvent, BufferingThresholdReachedEvent, PipEvent, ScheduleResyncAtPtsMsEvent, ResyncEvent > Event
Definition event.h:79
@ AUDIO
Definition event.h:26
Tracks the jitter of incoming packets (currently only for logging purposes)
PES packet parser header.
PlaybackMode
@ AUDIO_AND_VIDEO
@ VIDEO_ONLY
@ AUDIO_ONLY
@ NONE
const char * EventToString(const Event &e)
State
@ PLAY
@ STOP
@ BUFFERING
@ TRICK_SPEED
@ DETACHED
const char * StateToString(State s)