vdr-plugin-softhddevice-drm-gles 1.4.0
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 <mutex>
29#include <atomic>
30
31#include <vdr/dvbspu.h>
32
33extern "C"
34{
35#include <libavcodec/avcodec.h>
36}
37
38#include "config.h"
39#include "codec_audio.h"
40#include "videostream.h"
41#include "audio.h"
42#include "videorender.h"
43#include "softhdosd.h"
44#include "pipreceiver.h"
45#include "event.h"
46
47// State machine definitions
48// Implementing C++17 visitor pattern
49
50template<class... Ts>
51struct overload : Ts... { using Ts::operator()...; };
52template<class... Ts> overload(Ts...) -> overload<Ts...>;
53
54enum State {
61};
62
63inline const char* EventToString(const Event& e) {
64 return std::visit(overload{
65 [](const PlayEvent&) -> const char* { return "PlayEvent"; },
66 [](const PauseEvent&) -> const char* { return "PauseEvent"; },
67 [](const StopEvent&) -> const char* { return "StopEvent"; },
68 [](const TrickSpeedEvent&) -> const char* { return "TrickSpeedEvent"; },
69 [](const StillPictureEvent&) -> const char* { return "StillPictureEvent"; },
70 [](const DetachEvent&) -> const char* { return "DetachEvent"; },
71 [](const AttachEvent&) -> const char* { return "AttachEvent"; },
72 [](const BufferUnderrunEvent& e) -> const char* { return e.type == AUDIO ? "BufferUnderrunEvent: Audio" : "BufferUnderrunEvent: Video"; },
73 [](const BufferingThresholdReachedEvent&) -> const char* { return "BufferingThresholdReachedEvent"; },
74 [](const PipEvent&) -> const char* { return "PipEvent"; },
75 }, e);
76}
77
78inline const char* StateToString(State s) {
79 switch(s) {
80 case State::STOP: return "STOP";
81 case State::BUFFERING: return "BUFFERING";
82 case State::PLAY: return "PLAY";
83 case State::TRICK_SPEED: return "TRICK_SPEED";
84 case State::STILL_PICTURE: return "STILL_PICTURE";
85 case State::DETACHED: return "DETACHED";
86 }
87 return "Unknown";
88}
89
95};
96
97class cAudioDecoder;
98
99
100/*****************************************************************************
101 * cSoftHdDevice - cDevice class
102 ****************************************************************************/
103
104class cAudioDecoder;
105class cVideoRender;
106class cSoftHdAudio;
107class cSoftHdConfig;
108class cPipReceiver;
109
110class cSoftHdDevice : public cDevice, public IEventReceiver
111{
112public:
114 virtual ~cSoftHdDevice(void);
115
116 //
117 // virtual cDevice
118 //
119protected:
120 virtual void MakePrimaryDevice(bool);
121
122public:
123 virtual cString DeviceName(void) const { return "softhddevice-drm-gles"; }
124 virtual bool HasDecoder(void) const;
125
126 // SPU facilities
127 virtual cSpuDecoder * GetSpuDecoder(void);
128
129 // player facilities
130 virtual bool CanReplay(void) const;
131 virtual bool SetPlayMode(ePlayMode);
132 virtual int PlayVideo(const uchar *, int);
133 virtual int PlayAudio(const uchar *, int, uchar);
134 virtual int64_t GetSTC(void);
135 virtual cRect CanScaleVideo(const cRect &, int taCenter);
136 virtual void ScaleVideo(const cRect & = cRect::Null);
137 virtual void TrickSpeed(int, bool);
138 virtual void Clear(void);
139 virtual void Play(void);
140 virtual void Freeze(void);
141 virtual void StillPicture(const uchar *, int);
142 virtual bool Poll(cPoller &, int = 0);
143 virtual bool Flush(int = 0);
144
145 // Image Grab facilities
146 virtual uchar *GrabImage(int &, bool, int, int, int);
147
148 // video format facilities
149 virtual void SetVideoDisplayFormat(eVideoDisplayFormat);
150 virtual void SetVideoFormat(bool);
151 virtual void GetVideoSize(int &, int &, double &);
152 virtual void GetOsdSize(int &, int &, double &);
153
154 // track facilities
155 virtual void SetAudioTrackDevice(eTrackType);
156
157 // audio facilities
158 virtual int GetAudioChannelDevice(void);
159 virtual void SetAudioChannelDevice(int);
160 virtual void SetVolumeDevice(int);
161 virtual void SetDigitalAudioDevice(bool);
162
163 //
164 // wrapped by cPluginSoftHdDevice
165 //
166 const char *CommandLineHelp(void); // wrapped by cPluginSoftHdDevice::CommandLineHelp()
167 int ProcessArgs(int, char *[]); // wrapped by cPluginSoftHdDevice::ProcessArgs()
168 int Start(void);
169 void Stop(void);
170
171 //
172 // cSoftHdDevice public methods
173 //
174 cSoftHdConfig *Config(void) { return m_pConfig; };
176 cVideoRender *Render(void) { return m_pRender; };
177 cSoftHdAudio *Audio(void) { return m_pAudio; };
178
179 // osd
180#ifdef USE_GLES
181#ifdef WRITE_PNG
182 char WritePngs(void);
183#endif
184 int MaxSizeGPUImageCache(void);
185 int OglOsdIsDisabled(void);
186 void SetDisableOglOsd(void);
187 void SetEnableOglOsd(void);
188#endif
189 void SetDisableDeint(void);
190 void OsdClose(void);
191 void OsdDrawARGB(int, int, int, int, int, const uint8_t *, int, int);
192 void SetScreenSize(int, int, uint32_t);
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
218 void PipEnable(void);
219 void PipDisable(void);
220 void PipToggle(void);
221 void PipChannelChange(int);
222 void PipChannelSwap(void);
223 bool PipIsEnabled(void);
224 int PlayPipVideo(const uchar *, int);
225 void PipSetSize(void);
226 void PipSwapPosition(void);
227
228private:
229 static constexpr int MIN_BUFFER_FILL_LEVEL_THRESHOLD_MS = 450;
230
231 std::atomic<State> m_state = DETACHED;
232 std::mutex m_eventMutex;
233 bool m_needsMakePrimary = false;
234 cDvbSpuDecoder *m_pSpuDecoder;
243
244 std::atomic<PlaybackMode> m_playbackMode = NONE;
248
251 const cChannel *m_pPipChannel;
255 mutable std::mutex m_mutex;
256 std::mutex m_sizeMutex;
257 std::atomic<bool> m_receivedAudio = false;
258 std::atomic<bool> m_receivedVideo = false;
260
264
265 int PlayVideoInternal(cVideoStream *, cReassemblyBufferVideo *, const uchar *, int);
266 void ClearAudio(void);
267 void OnEventReceived(const Event&);
268 void HandleStillPicture(const uchar *data, int size);
269 int64_t GetFirstAudioPtsMsToPlay();
270 int64_t GetFirstVideoPtsMsToPlay();
271
273
274 // State machine
275 void SetState(State);
277 void OnLeavingState(State);
278
279 // PIP
280 void SetEnablePip(bool);
281 void TogglePip(void);
282 void ChangePipChannel(int);
283 void ResetPipChannel(void);
284 void DelPip(void);
285 void NewPip(int);
286 void HandlePip(enum PipState);
287 void SetPipSize(void);
288 void SwapPipPosition(void);
289};
290
291#endif
Audio and alsa module header file.
cAudioDecoder - Audio decoder class
Definition: codec_audio.h:74
cPipReceiver - receiver class for pip
Definition: pipreceiver.h:31
Audio stream reassembly buffer.
Definition: pes.h:172
Video stream reassembly buffer.
Definition: pes.h:143
cSoftHdAudio - Audio class
Definition: audio.h:45
int ConfigVideoAudioDelayMs
config audio delay
Definition: config.h:43
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
Definition: softhddevice.h:241
void Stop(void)
Called by VDR when the plugin is stopped.
bool m_pipUseAlt
use alternative pip position
Definition: softhddevice.h:259
cReassemblyBufferVideo m_pipReassemblyBuffer
pip pes reassembly buffer
Definition: softhddevice.h:254
cVideoStream * m_pPipStream
pointer to pip video stream
Definition: softhddevice.h:253
void PipSwapPosition(void)
Swap pip between normal and alternative position.
static constexpr int MIN_BUFFER_FILL_LEVEL_THRESHOLD_MS
min buffering threshold in ms
Definition: softhddevice.h:229
virtual void StillPicture(const uchar *, int)
Display the given I-frame as a still picture.
void PipSetSize(void)
Set size and position for the pip window.
cSoftOsdProvider * m_pOsdProvider
pointer to cSoftOsdProvider object
Definition: softhddevice.h:240
cVideoStream * m_pVideoStream
pointer to main video stream
Definition: softhddevice.h:237
cReassemblyBufferAudio m_audioReassemblyBuffer
audio pes reassembly buffer
Definition: softhddevice.h:242
std::atomic< bool > m_receivedAudio
flag if audio packets have been received
Definition: softhddevice.h:257
void HandlePip(enum PipState)
Handle the pip event.
cDvbSpuDecoder * m_pSpuDecoder
pointer to spu decoder
Definition: softhddevice.h:234
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
Definition: softhddevice.h:213
int PlayAudioPkts(AVPacket *)
Play an audio packet.
virtual void GetOsdSize(int &, int &, double &)
Returns the width, height and aspect ratio the OSD.
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)
void SwapPipPosition(void)
Swap pip between normal and alternative position.
std::mutex m_mutex
mutex to lock the state machine
Definition: softhddevice.h:255
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.
void ResetPipChannel(void)
Resets the pip channel to the current live stream channel.
void Detach(void)
Detach the device.
virtual int PlayVideo(const uchar *, int)
Play a video packet of the main videostream.
void TogglePip(void)
Toggle picture-in-picture.
int GetVideoAudioDelayMs(void)
Definition: softhddevice.h:195
uint32_t m_screenRefreshRate
Definition: softhddevice.h:263
std::atomic< State > m_state
current plugin state, normal plugin start sets detached state
Definition: softhddevice.h:231
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
Definition: softhddevice.h:239
void SetAudioCodec(enum AVCodecID, AVCodecParameters *, AVRational)
Open an audio codec.
cPipReceiver * m_pPipReceiver
cReceiver for pip stream
Definition: softhddevice.h:252
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.
bool m_grabActive
simple lock variable skips a new grab request if the last one is still active
Definition: softhddevice.h:246
void DelPip(void)
Delete the pip receiver, clear decoder and display buffers and disable rendering the pip window.
cVideoRender * m_pRender
pointer to cVideoRender object
Definition: softhddevice.h:236
virtual void SetAudioChannelDevice(int)
const char * CommandLineHelp(void)
Return command line help string.
cSoftHdDevice(cSoftHdConfig *)
cSoftHdDevice constructor
int PlayPipVideo(const uchar *, int)
Play a video packet of the pip videostream.
bool m_needsMakePrimary
Definition: softhddevice.h:233
cSoftHdAudio * m_pAudio
pointer to cSoftHdAudio object
Definition: softhddevice.h:238
cSoftHdConfig * m_pConfig
pointer to cSoftHdConfig object
Definition: softhddevice.h:235
void ResetOsdProvider(void)
Definition: softhddevice.h:212
virtual cRect CanScaleVideo(const cRect &, int taCenter)
Ask the output, if it can scale video.
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)
Definition: softhddevice.h:176
virtual void TrickSpeed(int, bool)
Set trick play speed.
cVideoStream * VideoStream(void)
Definition: softhddevice.h:175
virtual int PlayAudio(const uchar *, int, uchar)
Play an audio packet.
void SetPipSize(void)
Set size and position for the pip window.
void PipToggle(void)
Toggle picture-in-picture.
bool PipIsEnabled(void)
Returns true, if picture-in-picture is running.
std::mutex m_sizeMutex
mutex to lock screen size (which is accessed by different threads)
Definition: softhddevice.h:256
std::atomic< bool > m_receivedVideo
flag if video packets have been received
Definition: softhddevice.h:258
virtual int GetAudioChannelDevice(void)
int PlayVideoPkts(AVPacket *)
Play a video packet.
int m_pipChannelNum
current pip channel number
Definition: softhddevice.h:250
virtual cString DeviceName(void) const
Definition: softhddevice.h:123
int GetBufferFillLevelThresholdMs()
Returns the buffer fill level threshold in milliseconds.
void SetPassthrough(int)
Set the passthrough mask (called from setup menu or conf)
int PlayVideoInternal(cVideoStream *, cReassemblyBufferVideo *, const uchar *, int)
Play a video packet.
const cChannel * m_pPipChannel
current pip channel
Definition: softhddevice.h:251
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
Definition: softhddevice.h:232
virtual void SetVideoDisplayFormat(eVideoDisplayFormat)
Sets the video display format.
virtual void Freeze(void)
Puts the device into "freeze frame" mode.
void ChangePipChannel(int)
Change the pip channel.
cSoftHdConfig * Config(void)
Definition: softhddevice.h:174
virtual ~cSoftHdDevice(void)
cSoftHdDevice destructor
int m_audioChannelID
current audio channel ID
Definition: softhddevice.h:245
void PipDisable(void)
Stop picture-in-picture.
virtual void SetVideoFormat(bool)
Set the video format.
void SetScreenSize(int, int, uint32_t)
Set the screen size.
virtual void MakePrimaryDevice(bool)
Informs a device that it will be the primary device.
void SetVideoCodec(enum AVCodecID, AVCodecParameters *, AVRational)
Open a video codec.
bool m_pipActive
true, if pip is active
Definition: softhddevice.h:249
void PipEnable(void)
Start picture-in-picture.
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.
virtual void SetAudioTrackDevice(eTrackType)
void PipChannelSwap(void)
Swap the pip channel with main live channel.
std::atomic< PlaybackMode > m_playbackMode
current playback mode
Definition: softhddevice.h:244
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)
Definition: softhddevice.h:177
void SetEnablePip(bool)
Enable/ disable picture-in-picture.
void PipChannelChange(int)
Change the pip channel.
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 NewPip(int)
Create a new pip receiver and render the pip stream.
cSoftOsdProvider - SoftHdDevice plugin OSD provider class
Definition: softhdosd.h:65
cVideoRender - Video render class
Definition: videorender.h:122
cVideoStream - Video stream class
Definition: videostream.h:51
Audio decoder header file.
SoftHdDevice config header file.
State machine and event header file.
PipState
Definition: event.h:29
std::variant< PlayEvent, PauseEvent, StopEvent, TrickSpeedEvent, StillPictureEvent, DetachEvent, AttachEvent, BufferUnderrunEvent, BufferingThresholdReachedEvent, PipEvent > Event
Definition: event.h:72
@ AUDIO
Definition: event.h:26
Pip receiver header file.
PlaybackMode
Definition: softhddevice.h:90
@ AUDIO_AND_VIDEO
Definition: softhddevice.h:92
@ VIDEO_ONLY
Definition: softhddevice.h:94
@ AUDIO_ONLY
Definition: softhddevice.h:93
@ NONE
Definition: softhddevice.h:91
const char * EventToString(const Event &e)
Definition: softhddevice.h:63
State
Definition: softhddevice.h:54
@ PLAY
Definition: softhddevice.h:57
@ STOP
Definition: softhddevice.h:55
@ STILL_PICTURE
Definition: softhddevice.h:59
@ BUFFERING
Definition: softhddevice.h:56
@ TRICK_SPEED
Definition: softhddevice.h:58
@ DETACHED
Definition: softhddevice.h:60
overload(Ts...) -> overload< Ts... >
const char * StateToString(State s)
Definition: softhddevice.h:78
Softhddevice osd header file.
Definition: event.h:57
Rendering class header file.
Videostream class header file.