vdr 2.8.3
player.h
Go to the documentation of this file.
1/*
2 * player.h: The basic player interface
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * $Id: player.h 5.10 2026/08/22 11:23:08 kls Exp $
8 */
9
10#ifndef __PLAYER_H
11#define __PLAYER_H
12
13#include "device.h"
14#include "osdbase.h"
15
16class cPlayer {
17 friend class cDevice;
18private:
19 std::atomic<cDevice *> device; // cleared by cDevice::Detach() while the player's threads use it
21protected:
22 void DeviceClrAvailableTracks(bool DescriptionsOnly = false) { if (cDevice *d = device) d->ClrAvailableTracks(DescriptionsOnly); }
23 bool DeviceSetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL) { cDevice *d = device; return d ? d->SetAvailableTrack(Type, Index, Id, Language, Description) : false; }
24 bool DeviceSetCurrentAudioTrack(eTrackType Type) { cDevice *d = device; return d ? d->SetCurrentAudioTrack(Type) : false; }
25 bool DeviceSetCurrentSubtitleTrack(eTrackType Type) { cDevice *d = device; return d ? d->SetCurrentSubtitleTrack(Type) : false; }
26 bool DevicePoll(cPoller &Poller, int TimeoutMs = 0) { cDevice *d = device; return d ? d->Poll(Poller, TimeoutMs) : false; }
27 [[deprecated("use DeviceDrain() instead")]]
28 bool DeviceFlush(int TimeoutMs = 0) { return DeviceDrain(); }
29 bool DeviceDrain(void) { cDevice *d = device; return d ? d->Drain() : false; }
30 bool DeviceHasIBPTrickSpeed(void) { cDevice *d = device; return d ? d->HasIBPTrickSpeed() : false; }
31 bool DeviceIsPlayingVideo(void) { cDevice *d = device; return d ? d->IsPlayingVideo() : false; }
32 void DeviceTrickSpeed(int Speed, bool Forward) { if (cDevice *d = device) d->TrickSpeed(Speed, Forward); }
33 void DeviceClear(void) { if (cDevice *d = device) d->Clear(); }
34 void DevicePlay(void) { if (cDevice *d = device) d->Play(); }
35 void DeviceFreeze(void) { if (cDevice *d = device) d->Freeze(); }
36 void DeviceMute(void) { if (cDevice *d = device) d->Mute(); }
37 void DeviceSetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat) { if (cDevice *d = device) d->SetVideoDisplayFormat(VideoDisplayFormat); }
38 void DeviceStillPicture(const uchar *Data, int Length) { if (cDevice *d = device) d->StillPicture(Data, Length); }
39 void DeviceSetTempSubtitles(void) { if (cDevice *d = device) d->SetTempSubtitles(); }
40 uint64_t DeviceGetSTC(void) { cDevice *d = device; return d ? d->GetSTC() : -1; }
41 void Detach(void);
42 virtual void Activate(bool On) {}
43 // This function is called right after the cPlayer has been attached to
44 // (On == true) or before it gets detached from (On == false) a cDevice.
45 // It can be used to do things like starting/stopping a thread.
46 int PlayPes(const uchar *Data, int Length, bool VideoOnly = false);
47 // Sends the given PES Data to the device and returns the number of
48 // bytes that have actually been accepted by the device (or a
49 // negative value in case of an error).
50 int PlayTs(const uchar *Data, int Length, bool VideoOnly = false) { cDevice *d = device; return d ? d->PlayTs(Data, Length, VideoOnly) : -1; }
51 // Sends the given TS packet to the device and returns a positive number
52 // if the packet has been accepted by the device, or a negative value in
53 // case of an error.
54public:
55 cPlayer(ePlayMode PlayMode = pmAudioVideo);
56 virtual ~cPlayer();
57 bool IsAttached(void) { return device != NULL; }
58 virtual double FramesPerSecond(void) { return DEFAULTFRAMESPERSECOND; }
59 // Returns the number of frames per second of the currently played material.
60 virtual const cErrors *GetErrors(void) { return NULL; }
61 // Returns the frame indexes of errors in the recording (if any).
62 virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false) { return false; }
63 // Returns the current and total frame index, optionally snapped to the
64 // nearest I-frame.
65 virtual bool GetFrameNumber(int &Current, int &Total) { return false; }
66 // Returns the current and total frame number. In contrast to GetIndex(),
67 // this function respects the chronological order of frames, which is
68 // different from its index for streams containing B frames (e.g. H264)
69 virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed) { return false; }
70 // Returns the current replay mode (if applicable).
71 // 'Play' tells whether we are playing or pausing, 'Forward' tells whether
72 // we are going forward or backward and 'Speed' is -1 if this is normal
73 // play/pause mode, 0 if it is single speed fast/slow forward/back mode
74 // and >0 if this is multi speed mode.
75 virtual void SetAudioTrack(eTrackType Type, const tTrackId *TrackId) {}
76 // Sets the current audio track to the given value.
77 // This is just a virtual hook for players that need to do special things
78 // in order to switch audio tracks.
79 virtual void SetSubtitleTrack(eTrackType Type, const tTrackId *TrackId) {}
80 // Sets the current subtitle track to the given value.
81 // This is just a virtual hook for players that need to do special things
82 // in order to switch subtitle tracks.
83 };
84
85class cControl : public cOsdObject {
86private:
88 static cMutex mutex;
90 bool hidden;
91protected:
93public:
94 cControl(cPlayer *Player, bool Hidden = false);
95 virtual ~cControl() override;
96 virtual void Hide(void) = 0;
97 virtual cOsdObject *GetInfo(void);
101 virtual const cRecording *GetRecording(void);
104 virtual cString GetHeader(void);
110 virtual void ClearEditingMarks(void) {}
115 void SetPlayer(cPlayer *Player) { player = Player; }
117 bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false) const { return player ? player->GetIndex(Current, Total, SnapToIFrame) : false; }
118 bool GetFrameNumber(int &Current, int &Total) const { return player ? player->GetFrameNumber(Current, Total) : false; }
119 bool GetReplayMode(bool &Play, bool &Forward, int &Speed) const { return player ? player->GetReplayMode(Play, Forward, Speed) : false; }
120 static void Launch(cControl *Control);
121 static void Attach(void);
122 static void Shutdown(void);
123 static cControl *Control(cMutexLock &MutexLock, bool Hidden = false, bool *LockedOtherwise = NULL);
133 };
134
135#endif //__PLAYER_H
static cControl * Control(cMutexLock &MutexLock, bool Hidden=false, bool *LockedOtherwise=NULL)
Returns the current replay control (if any) in case it is currently visible.
Definition player.c:75
virtual void ClearEditingMarks(void)
Clears any editing marks this player might be showing.
Definition player.h:110
virtual cString GetHeader(void)
This can be used by players that don't play a cRecording, but rather do something completely differen...
Definition player.c:68
double FramesPerSecond(void) const
Definition player.h:116
bool GetFrameNumber(int &Current, int &Total) const
Definition player.h:118
static void Shutdown(void)
Definition player.c:111
bool GetIndex(int &Current, int &Total, bool SnapToIFrame=false) const
Definition player.h:117
static cControl * control
Definition player.h:87
virtual cOsdObject * GetInfo(void)
Returns an OSD object that displays information about the currently played programme.
Definition player.c:58
static cMutex mutex
Definition player.h:88
virtual const cRecording * GetRecording(void)
Returns the cRecording that is currently being replayed, or NULL if this player is not playing a cRec...
Definition player.c:63
static void Attach(void)
Definition player.c:98
bool GetReplayMode(bool &Play, bool &Forward, int &Speed) const
Definition player.h:119
void SetPlayer(cPlayer *Player)
Definition player.h:115
bool hidden
Definition player.h:90
bool attached
Definition player.h:89
static void Launch(cControl *Control)
Definition player.c:91
cControl(cPlayer *Player, bool Hidden=false)
Definition player.c:45
virtual void Hide(void)=0
cPlayer * player
Definition player.h:92
virtual bool Poll(cPoller &Poller, int TimeoutMs=0)
Returns true if the device itself or any of the file handles in Poller is ready for further action.
Definition device.c:1508
bool SetCurrentSubtitleTrack(eTrackType Type, bool Manual=false)
Sets the current subtitle track to the given Type.
Definition device.c:1230
virtual bool IsPlayingVideo(void) const
Returns true if the currently attached player has delivered any video packets.
Definition device.h:761
virtual int64_t GetSTC(void)
Gets the current System Time Counter, which can be used to synchronize audio, video and subtitles.
Definition device.c:1349
virtual bool HasIBPTrickSpeed(void)
Returns true if this device can handle all frames in 'fast forward' trick speeds.
Definition device.h:793
bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language=NULL, const char *Description=NULL)
Sets the track of the given Type and Index to the given values.
Definition device.c:1147
bool Drain(void)
Tells the device that the last data of the current stream has been delivered and no more will follow,...
Definition device.c:1518
virtual int PlayTs(const uchar *Data, int Length, bool VideoOnly=false)
Plays the given TS packet.
Definition device.c:1744
bool SetCurrentAudioTrack(eTrackType Type)
Sets the current audio track to the given Type.
Definition device.c:1212
cOsdObject(bool FastResponse=false)
Definition osdbase.h:89
bool DeviceSetCurrentAudioTrack(eTrackType Type)
Definition player.h:24
void Detach(void)
Definition player.c:34
void DeviceStillPicture(const uchar *Data, int Length)
Definition player.h:38
uint64_t DeviceGetSTC(void)
Definition player.h:40
std::atomic< cDevice * > device
Definition player.h:19
bool DeviceSetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language=NULL, const char *Description=NULL)
Definition player.h:23
virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame=false)
Definition player.h:62
friend class cDevice
Definition player.h:17
virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed)
Definition player.h:69
virtual const cErrors * GetErrors(void)
Definition player.h:60
virtual void SetAudioTrack(eTrackType Type, const tTrackId *TrackId)
Definition player.h:75
int PlayTs(const uchar *Data, int Length, bool VideoOnly=false)
Definition player.h:50
void DevicePlay(void)
Definition player.h:34
int PlayPes(const uchar *Data, int Length, bool VideoOnly=false)
Definition player.c:26
virtual bool GetFrameNumber(int &Current, int &Total)
Definition player.h:65
bool DevicePoll(cPoller &Poller, int TimeoutMs=0)
Definition player.h:26
void DeviceClrAvailableTracks(bool DescriptionsOnly=false)
Definition player.h:22
void DeviceMute(void)
Definition player.h:36
virtual double FramesPerSecond(void)
Definition player.h:58
bool IsAttached(void)
Definition player.h:57
void DeviceSetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat)
Definition player.h:37
void DeviceFreeze(void)
Definition player.h:35
bool DeviceFlush(int TimeoutMs=0)
Definition player.h:28
void DeviceSetTempSubtitles(void)
Definition player.h:39
bool DeviceDrain(void)
Definition player.h:29
bool DeviceHasIBPTrickSpeed(void)
Definition player.h:30
ePlayMode playMode
Definition player.h:20
cPlayer(ePlayMode PlayMode=pmAudioVideo)
Definition player.c:15
bool DeviceSetCurrentSubtitleTrack(eTrackType Type)
Definition player.h:25
virtual void Activate(bool On)
Definition player.h:42
virtual void SetSubtitleTrack(eTrackType Type, const tTrackId *TrackId)
Definition player.h:79
bool DeviceIsPlayingVideo(void)
Definition player.h:31
void DeviceClear(void)
Definition player.h:33
void DeviceTrickSpeed(int Speed, bool Forward)
Definition player.h:32
eVideoDisplayFormat
Definition device.h:58
ePlayMode
Definition device.h:39
@ pmAudioVideo
Definition device.h:40
eTrackType
Definition device.h:63
#define DEFAULTFRAMESPERSECOND
Definition recording.h:408
unsigned char uchar
Definition tools.h:31