24#include <libavcodec/avcodec.h>
27#include <vdr/dvbspu.h>
29#include <vdr/status.h>
62 m_pipUseAlt(m_pConfig->ConfigPipUseAlt)
124 cDevice::MakePrimaryDevice(
on);
135 if (device != cDevice::PrimaryDevice())
313 LOGDEBUG(
"device: audio only detected");
317 LOGDEBUG(
"device: video only detected");
321 LOGFATAL(
"device: buffering threshold reached and no a/v available. This is a bug.");
360 LOGFATAL(
"device: play event in PLAY state with NONE playback mode. This is a bug.");
815 if (data[0] == 0x47) {
816 cDevice::StillPicture(data, size);
1008 LOGDEBUG2(
L_CODEC,
"Stream: %02X%02X%02X | %02X | %02X%02X | %02X%02X%02X | %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X",
1057 auto now = std::chrono::steady_clock::now();
1112 }
while (
avpkt !=
nullptr);
1175 auto now = std::chrono::steady_clock::now();
1225 if (
stream->IsInputBufferFull())
1335 LOGDEBUG2(
L_AV_SYNC,
"First received PTS: %s (audio), %s (video) buffer fill levels: %ldms (audio) %ldms (video)",
1399 LOGDEBUG2(
L_GRAB,
"device: %s: %d, %d, %d, %dx%d",
__FUNCTION__, size,
jpeg,
quality, width, height);
1451 return " -a device\taudio device (fe. alsa: hw:0,0)\n"
1452 " -p device\taudio device for pass-through (hw:0,1)\n"
1453 " -c channel\taudio mixer channel name (fe. PCM)\n"
1454 " -d resolution\tdisplay resolution (fe. 1920x1080@50)\n"
1455 " -D start in detached state\n"
1456 " -w workaround\tenable/disable workarounds\n"
1458 "\tdisable-ogl-osd disable openGL osd\n"
1460 "\tdisable-pip disable picture-in-picture\n"
1760 if (cDevice::Replaying()) {
Audio and Alsa Interface Header File.
AVCodecID GetCodecId() const
int GetShortTermMaxJitterMs(void)
int GetLongTermMaxJitterMs(void)
Video Stream Reassembly Buffer.
AVPacket * PopAvPacket(void) override
virtual void Push(const uint8_t *data, int size, int64_t pts)
int64_t GetInputPtsMs(void)
bool ConfigParseH264Dimensions
parse h264 stream for width and height for decoder init
int ConfigVideoAudioDelayMs
config audio delay
const char * ConfigDisplayResolution
display resolution (syntax: "1920x1080@50")
std::atomic< int > StatMaxLongTermAudioJitterMs
logged max overall audio jitter since stream start
int ConfigMaxSizeGPUImageCache
config max gpu image cache size
std::atomic< int > StatMaxShortTermAudioJitterMs
logged max audio jitter of the last 1000 packets
int ConfigDecoderFallbackToSwNumPkts
maximum number of packets sent before fallback to sw decoder
const char * ConfigAudioPCMDevice
audio PCM device
bool ConfigDisableDeint
disable deinterlacer
int ConfigDisableOglOsd
config disable ogl osd
int ConfigAdditionalBufferLengthMs
config size ms of a/v buffer
const char * ConfigAudioMixerChannel
audio mixer channel name
std::atomic< int > StatMaxShortTermVideoJitterMs
logged max video jitter of the last 1000 packets
bool ConfigDecoderNeedsIFrame
start h264 decoder only when an I-Frame arrives
std::atomic< int > StatMaxLongTermVideoJitterMs
logged max overall video jitter since stream start
const char * ConfigAudioPassthroughDevice
audio passthrough device
cReassemblyBufferVideo m_videoReassemblyBuffer
video pes reassembly buffer
bool m_pipUseAlt
use alternative pip position
cReassemblyBufferVideo m_pipReassemblyBuffer
pip pes reassembly buffer
cVideoStream * m_pPipStream
pointer to pip video stream
static constexpr int MIN_BUFFER_FILL_LEVEL_THRESHOLD_MS
min buffering threshold in ms
int m_volume
track the volume in the device (for attach)
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
cDvbSpuDecoder * m_pSpuDecoder
pointer to spu decoder
std::mutex m_mutex
mutex to lock the state machine
cPipHandler * m_pPipHandler
pointer to pip handler
double m_screenRefreshRateHz
std::chrono::steady_clock::time_point m_dataReceivedTime
timestamp, when the first audio or video data after a channel switch arrives in Play*()
std::atomic< State > m_state
current plugin state, normal plugin start sets detached state
cAudioDecoder * m_pAudioDecoder
pointer to cAudioDecoder object
cVideoRender * m_pRender
pointer to cVideoRender object
cSoftHdGrab * m_pGrab
pointer to grabber object
cSoftHdAudio * m_pAudio
pointer to cSoftHdAudio object
cSoftHdConfig * m_pConfig
pointer to cSoftHdConfig object
bool m_disablePip
true, if pip was disabled by the user
std::chrono::steady_clock::time_point m_channelSwitchStartTime
timestamp, when VDR triggered a channel switch
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
cJitterTracker m_audioJitterTracker
audio jitter tracker
bool m_forceDetached
start the plugin in detached state
int m_audioChannelID
current audio channel ID
cJitterTracker m_videoJitterTracker
video jitter tracker
std::atomic< PlaybackMode > m_playbackMode
current playback mode
void SetEnableHdr(bool enable)
void ResetBufferReuseStrategy()
void ScheduleVideoPlaybackPauseAt(int64_t ptsMs)
void ScheduleResyncAtPtsMs(int64_t ptsMs)
void ResetDecodingStrategy()
void ResetPipBufferReuseStrategy()
void SetPipActive(bool on)
cQueue< cDrmBuffer > * GetPipOutputBuffer(void)
void SetStillpicture(bool active)
void SchedulePlaybackStartAtPtsMs(int64_t ptsMs)
int64_t GetVideoClock(void)
void SetScheduleAudioResume(bool resume)
void SetDisplayOneFrameThenPause(bool pause)
void SetPlaybackPaused(bool pause)
void ResetPipDecodingStrategy()
cQueue< cDrmBuffer > * GetMainOutputBuffer(void)
void SetDecoderFallbackToSwNumPkts(int numPackets)
int GetVideoPacketMax(void)
void SetStartDecodingWithIFrame(bool enable)
size_t GetAvPacketsFilled(void)
void DisableDeint(bool disable)
bool IsInputBufferFull(void)
void ResetFilterThreadNeededCheck()
void SetParseH264Dimensions(bool enable)
virtual void SetDeinterlacerDeactivated(bool deactivate)
void ResetTrickSpeedFramesSentCounter(void)
Audio Decoder Header File.
Plugin Configuration Header File.
State Machine and Event Header File.
std::variant< PlayEvent, PauseEvent, StopEvent, TrickSpeedEvent, StillPictureEvent, DetachEvent, AttachEvent, BufferUnderrunEvent, BufferingThresholdReachedEvent, PipEvent, ScheduleResyncAtPtsMsEvent, ResyncEvent > Event
Grabbing Interface Header File.
void LazyInit(void)
Initialize audio output module (alsa)
void ResetHwDelayBaseline(void)
Reset the hw delay baseline.
void SetPassthroughMask(int)
Set audio passthrough mask.
void SetHwDelayBaseline(void)
Set the hw delay baseline.
int64_t GetHardwareOutputPtsTimebaseUnits(void)
Get the hardware output PTS in timebase units.
void SetVolume(int)
Set mixer volume (0-1000)
void DropSamplesOlderThanPtsMs(int64_t)
Drop samples older than the given PTS.
int64_t GetOutputPtsMs(void)
Get the output PTS of the ringbuffer.
void ClockDriftCompensation(void)
Calculate clock drift compensation.
void Exit(void)
Cleanup audio output module (alsa)
void SetPaused(bool)
Set audio playback pause state.
void FlushBuffers(void)
Flush audio buffers.
void FlushBuffers(void)
Flush the audio decoder buffers.
void Decode(const AVPacket *)
Decode an audio packet.
void SetPassthroughMask(int)
Set audio pass-through mask.
void Open(AVCodecID, AVCodecParameters *=nullptr, AVRational={ .num=1,.den=90000 })
Open and initiate the audio decoder.
void Close(void)
Close the audio decoder.
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.
void Stop(void)
Called by VDR when the plugin is stopped.
void PipChannelSwap(bool)
void FlushAudio(void)
Clear all audio data from the decoder and ringbuffer.
void PipSwapPosition(void)
virtual void StillPicture(const uchar *, int)
Display the given I-frame as a still picture.
int MaxSizeGPUImageCache(void)
Get the maximum GPU image cache size.
void SetRenderPipSize(void)
Wrapper functions for cVideoRender and cPipHandler.
void OnEnteringState(State)
Actions to be performed when entering a state.
int Start(void)
Called by VDR when the plugin is started.
void SetEnableOglOsd(void)
Enables OpenGL/ES Osd.
virtual void GetVideoSize(int &, int &, double &)
Get the video size.
const char * EventToString(const Event &e)
int PlayAudioPkts(AVPacket *)
Play an audio packet.
virtual void GetOsdSize(int &, int &, double &)
Returns the width, height and aspect ratio the OSD.
void SetEnableHdr(bool)
Enable HDR display mode.
void SetRenderPipActive(bool)
void GetStats(int *, int *, int *)
Get statistics from the renderer.
void ResetChannelId(void)
Reset the channel ID (restarts audio)
virtual bool CanReplay(void) const
Return true if this device can currently start a replay session.
virtual void SetDigitalAudioDevice(bool)
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 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.
void OnLeavingState(State)
Actions to be performed when leaving a state.
virtual bool SetPlayMode(ePlayMode)
Sets the device into the given play mode.
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.
virtual void SetAudioChannelDevice(int)
const char * CommandLineHelp(void)
Return command line help string.
int OglOsdIsDisabled(void)
Is the OpenGL/ES osd disabled?
cSoftHdDevice(cSoftHdConfig *)
Create the device.
int PlayPipVideo(const uchar *, int)
Play a video packet of the pip videostream.
virtual void ChannelSwitch(const cDevice *, int, bool)
Monitor a channel switch triggered by VDR (cStatus::ChannelSwitch())
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.
virtual void TrickSpeed(int, bool)
Sets the device into a mode where replay is done slower.
void SetDecoderFallbackToSw(bool)
Force the decoder to fallback to software if the hardware decoder fails after the configured amount o...
virtual int PlayAudio(const uchar *, int, uchar)
Play an audio packet.
bool PipIsEnabled(void)
Returns true, if pip is currently enabled.
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.
const char * StateToString(State s)
int GetBufferFillLevelThresholdMs()
Returns the buffer fill level threshold in milliseconds.
void HandleStillPicture(const uchar *data, int size)
The still picture data received from VDR can contain multiple PES packets.
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.
void SetDisableOglOsd(void)
Disables OpenGL/ES Osd (called from setup menu or conf)
virtual ~cSoftHdDevice(void)
Destroy the device.
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 SetPassthroughMask(int)
Set the passthrough mask (called from setup menu or conf)
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 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.
void PipChannelChange(int)
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.
void Attach(void)
Attach the device again.
static void PrintStreamData(const uchar *payload)
Print the start code, stream id, length, first three bytes (start code) of the payload,...
__attribute__((weak)) union gbm_bo_handle gbm_bo_get_handle_for_plane(struct gbm_bo *bo
#define LOGDEBUG2
log to LOG_DEBUG and add a prefix
#define LOGDEBUG
log to LOG_DEBUG
#define LOGERROR
log to LOG_ERR
void Reset(void)
Reset the reassembly buffer.
bool Start(bool, int, int, int, int, int)
Start a grab in the video renderer.
bool HasLeadingZero(const uint8_t *, int)
Check if video data has a leading zero byte before the start code.
#define LOGWARNING
log to LOG_WARN
void PacketReceived(void)
Called each time a packet is received.
void Reset(void)
Resets the jitter tracker.
#define LOGFATAL
log to LOG_ERR and abort
AVPacket * PopAvPacket(void) override
Pop an audio AVPacket from the reassembly buffer.
bool ParseCodecHeader(const uint8_t *, int)
Parse video codec header to detect codec type.
static const char * Timestamp2String(int64_t ts, uint8_t divisor)
Nice time-stamp string.
@ L_AV_SYNC
audio/video sync logs
void RequestStopOpenGlThread(void)
Initiate a stop of the OpenGL thread without waiting.
void StopOpenGlThread(void)
Stop the OpenGL thread and cancel it if necessary.
void UnlockOpenGlThread(void)
Unlock the OpenGL thread.
bool LockOpenGlThread(void)
Lock the OpenGL thread.
void ChannelChange(int)
Change the pip channel.
void SwapPosition(void)
Swap pip between normal and alternative position.
void Toggle(void)
Toggle picture-in-picture.
void HandleEvent(enum PipState)
Handle a pip event.
void Disable(void)
Stop picture-in-picture.
void ChannelSwap(bool)
Swap the pip channel with main live channel.
void Enable(void)
Start picture-in-picture.
void SetSize(void)
Set size and position for the pip window.
void PushPipFrame(AVFrame *)
Push a PiP frame into the render ringbuffer.
bool IsOutputBufferFull(void)
Check, if the main render output buffer is full.
void Reset()
Reset the renderer.
void OsdClear(void)
Clear the OSD (draw an empty/ transparent OSD)
void ClearDecoderToDisplayQueue(void)
Clear (empty) the decoder to display queue.
void Init(void)
Initialize the renderer.
void Exit(void)
Exit and cleanup the renderer.
void GetStats(int *, int *, int *)
Get some rendering statistics.
void DisplayBlackFrame(void)
void PushMainFrame(AVFrame *)
Push a main frame into the render ringbuffer.
void SetVideoOutputPosition(const cRect &)
Set size and position of the video on the screen.
int64_t GetOutputPtsMs(void)
Get the output PTS in milliseconds.
void ClearPipDecoderToDisplayQueue(void)
Clear (empty) the decoder to display queue.
void OsdDrawARGB(int, int, int, int, int, const uint8_t *, int, int)
Draw an OSD ARGB image.
void SetPipSize(bool)
Set the size and position of the pip window.
void ResetFrameCounter(void)
Send start condition to video thread.
void SetTrickSpeed(double, bool, bool)
Set the trickspeed parameters.
void GetVideoSize(int *, int *, double *)
Get video size and aspect ratio.
void Flush(void)
Flushes the video stream by finalizing any pending data.
void StartDecoder()
Start the decoder.
void ClearVdrCoreToDecoderQueue(void)
Clears all video stream data, which is buffered to be decoded.
void CloseDecoder(void)
Close the decoder.
void Exit(void)
Exit video stream.
void CancelFilterThread(void)
Stop filter thread.
void FlushDecoder(void)
Flush the decoder.
void Open(AVCodecID, AVCodecParameters *=nullptr, AVRational={ .num=1,.den=90000 })
Open a video codec.
bool PushAvPacket(AVPacket *avpkt)
Pushes a pre-assembled AVPacket directly to the processing queue.
int64_t GetInputPtsMs(void)
Jitter Tracking of Incoming Packets Header File.
PES Packet Parser Header File.
PiP (Picture-in-Picture) Interface Header File.
Output Device Header File.
OSD Provider Header File.
Video Renderer (Display) Header File.
Video Input Stream Header File.