vdr  2.4.1
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 4.4 2018/02/01 15:34:51 kls Exp $
8  */
9 
10 #ifndef __PLAYER_H
11 #define __PLAYER_H
12 
13 #include "device.h"
14 #include "osdbase.h"
15 
16 class cPlayer {
17  friend class cDevice;
18 private:
21 protected:
22  void DeviceClrAvailableTracks(bool DescriptionsOnly = false) { if (device) device->ClrAvailableTracks(DescriptionsOnly); }
23  bool DeviceSetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL) { return device ? device->SetAvailableTrack(Type, Index, Id, Language, Description) : false; }
26  bool DevicePoll(cPoller &Poller, int TimeoutMs = 0) { return device ? device->Poll(Poller, TimeoutMs) : false; }
27  bool DeviceFlush(int TimeoutMs = 0) { return device ? device->Flush(TimeoutMs) : true; }
28  bool DeviceHasIBPTrickSpeed(void) { return device ? device->HasIBPTrickSpeed() : false; }
29  bool DeviceIsPlayingVideo(void) { return device ? device->IsPlayingVideo() : false; }
30  void DeviceTrickSpeed(int Speed, bool Forward) { if (device) device->TrickSpeed(Speed, Forward); }
31  void DeviceClear(void) { if (device) device->Clear(); }
32  void DevicePlay(void) { if (device) device->Play(); }
33  void DeviceFreeze(void) { if (device) device->Freeze(); }
34  void DeviceMute(void) { if (device) device->Mute(); }
35  void DeviceSetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat) { if (device) device->SetVideoDisplayFormat(VideoDisplayFormat); }
36  void DeviceStillPicture(const uchar *Data, int Length) { if (device) device->StillPicture(Data, Length); }
37  uint64_t DeviceGetSTC(void) { return device ? device->GetSTC() : -1; }
38  void Detach(void);
39  virtual void Activate(bool On) {}
40  // This function is called right after the cPlayer has been attached to
41  // (On == true) or before it gets detached from (On == false) a cDevice.
42  // It can be used to do things like starting/stopping a thread.
43  int PlayPes(const uchar *Data, int Length, bool VideoOnly = false);
44  // Sends the given PES Data to the device and returns the number of
45  // bytes that have actually been accepted by the device (or a
46  // negative value in case of an error).
47  int PlayTs(const uchar *Data, int Length, bool VideoOnly = false) { return device ? device->PlayTs(Data, Length, VideoOnly) : -1; }
48  // Sends the given TS packet to the device and returns a positive number
49  // if the packet has been accepted by the device, or a negative value in
50  // case of an error.
51 public:
52  cPlayer(ePlayMode PlayMode = pmAudioVideo);
53  virtual ~cPlayer();
54  bool IsAttached(void) { return device != NULL; }
55  virtual double FramesPerSecond(void) { return DEFAULTFRAMESPERSECOND; }
56  // Returns the number of frames per second of the currently played material.
57  virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false) { return false; }
58  // Returns the current and total frame index, optionally snapped to the
59  // nearest I-frame.
60  virtual bool GetFrameNumber(int &Current, int &Total) { return false; }
61  // Returns the current and total frame number. In contrast to GetIndex(),
62  // this function respects the chronological order of frames, which is
63  // different from its index for streams containing B frames (e.g. H264)
64  virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed) { return false; }
65  // Returns the current replay mode (if applicable).
66  // 'Play' tells whether we are playing or pausing, 'Forward' tells whether
67  // we are going forward or backward and 'Speed' is -1 if this is normal
68  // play/pause mode, 0 if it is single speed fast/slow forward/back mode
69  // and >0 if this is multi speed mode.
70  virtual void SetAudioTrack(eTrackType Type, const tTrackId *TrackId) {}
71  // Sets the current audio track to the given value.
72  // This is just a virtual hook for players that need to do special things
73  // in order to switch audio tracks.
74  virtual void SetSubtitleTrack(eTrackType Type, const tTrackId *TrackId) {}
75  // Sets the current subtitle track to the given value.
76  // This is just a virtual hook for players that need to do special things
77  // in order to switch subtitle tracks.
78  };
79 
80 class cControl : public cOsdObject {
81 private:
82  static cControl *control;
83  static cMutex mutex;
84  bool attached;
85  bool hidden;
86 protected:
88 public:
89  cControl(cPlayer *Player, bool Hidden = false);
90  virtual ~cControl();
91  virtual void Hide(void) = 0;
92  virtual cOsdObject *GetInfo(void);
96  virtual const cRecording *GetRecording(void);
99  virtual cString GetHeader(void);
105  virtual void ClearEditingMarks(void) {}
111  bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false) const { return player ? player->GetIndex(Current, Total, SnapToIFrame) : false; }
112  bool GetFrameNumber(int &Current, int &Total) const { return player ? player->GetFrameNumber(Current, Total) : false; }
113  bool GetReplayMode(bool &Play, bool &Forward, int &Speed) const { return player ? player->GetReplayMode(Play, Forward, Speed) : false; }
114  static void Launch(cControl *Control);
115  static void Attach(void);
116  static void Shutdown(void);
117  static cControl *Control(bool Hidden = false);
121  };
122 
123 #endif //__PLAYER_H
cPlayer::Detach
void Detach(void)
Definition: player.c:34
cPlayer::DeviceHasIBPTrickSpeed
bool DeviceHasIBPTrickSpeed(void)
Definition: player.h:28
cPoller
Definition: tools.h:393
cPlayer::DeviceSetVideoDisplayFormat
void DeviceSetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat)
Definition: player.h:35
cControl::FramesPerSecond
double FramesPerSecond(void) const
Definition: player.h:110
cPlayer::DeviceSetCurrentAudioTrack
bool DeviceSetCurrentAudioTrack(eTrackType Type)
Definition: player.h:24
cControl::~cControl
virtual ~cControl()
Definition: player.c:52
cControl::ClearEditingMarks
virtual void ClearEditingMarks(void)
Clears any editing marks this player might be showing.
Definition: player.h:105
cPlayer::Activate
virtual void Activate(bool On)
Definition: player.h:39
cPlayer::GetFrameNumber
virtual bool GetFrameNumber(int &Current, int &Total)
Definition: player.h:60
cDevice::GetSTC
virtual int64_t GetSTC(void)
Gets the current System Time Counter, which can be used to synchronize audio, video and subtitles.
Definition: device.c:1215
cPlayer::DeviceIsPlayingVideo
bool DeviceIsPlayingVideo(void)
Definition: player.h:29
cPlayer::DeviceMute
void DeviceMute(void)
Definition: player.h:34
cPlayer::GetReplayMode
virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed)
Definition: player.h:64
cPlayer::DeviceSetCurrentSubtitleTrack
bool DeviceSetCurrentSubtitleTrack(eTrackType Type)
Definition: player.h:25
cDevice::SetCurrentSubtitleTrack
bool SetCurrentSubtitleTrack(eTrackType Type, bool Manual=false)
Sets the current subtitle track to the given Type.
Definition: device.c:1122
cDevice::Flush
virtual bool Flush(int TimeoutMs=0)
Returns true if the device's output buffers are empty, i.
Definition: device.c:1371
cControl::attached
bool attached
Definition: player.h:84
cControl
Definition: player.h:80
cDevice::SetCurrentAudioTrack
bool SetCurrentAudioTrack(eTrackType Type)
Sets the current audio track to the given Type.
Definition: device.c:1104
cOsdObject
Definition: osdbase.h:69
tTrackId
Definition: device.h:80
cPlayer::DeviceFreeze
void DeviceFreeze(void)
Definition: player.h:33
device.h
cControl::GetIndex
bool GetIndex(int &Current, int &Total, bool SnapToIFrame=false) const
Definition: player.h:111
cDevice::TrickSpeed
virtual void TrickSpeed(int Speed, bool Forward)
Sets the device into a mode where replay is done slower.
Definition: device.c:1220
cDevice::SetVideoDisplayFormat
virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat)
Sets the video display format to the given one (only useful if this device has an MPEG decoder).
Definition: device.c:487
cPlayer::PlayTs
int PlayTs(const uchar *Data, int Length, bool VideoOnly=false)
Definition: player.h:47
cPlayer::SetSubtitleTrack
virtual void SetSubtitleTrack(eTrackType Type, const tTrackId *TrackId)
Definition: player.h:74
cMutex
Definition: thread.h:67
cControl::player
cPlayer * player
Definition: player.h:87
cControl::Hide
virtual void Hide(void)=0
cPlayer::GetIndex
virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame=false)
Definition: player.h:57
cControl::Launch
static void Launch(cControl *Control)
Definition: player.c:79
cDevice
Definition: device.h:117
uchar
unsigned char uchar
Definition: tools.h:31
cDevice::StillPicture
virtual void StillPicture(const uchar *Data, int Length)
Displays the given I-frame as a still picture.
Definition: device.c:1250
cPlayer::FramesPerSecond
virtual double FramesPerSecond(void)
Definition: player.h:55
cPlayer::cPlayer
cPlayer(ePlayMode PlayMode=pmAudioVideo)
Definition: player.c:15
cPlayer::SetAudioTrack
virtual void SetAudioTrack(eTrackType Type, const tTrackId *TrackId)
Definition: player.h:70
cControl::hidden
bool hidden
Definition: player.h:85
cPlayer::DeviceFlush
bool DeviceFlush(int TimeoutMs=0)
Definition: player.h:27
cPlayer
Definition: player.h:16
cPlayer::DeviceClear
void DeviceClear(void)
Definition: player.h:31
cPlayer::DevicePoll
bool DevicePoll(cPoller &Poller, int TimeoutMs=0)
Definition: player.h:26
cRecording
Definition: recording.h:98
cDevice::SetAvailableTrack
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:1050
ePlayMode
ePlayMode
Definition: device.h:39
eTrackType
eTrackType
Definition: device.h:63
DEFAULTFRAMESPERSECOND
#define DEFAULTFRAMESPERSECOND
Definition: recording.h:351
cDevice::Freeze
virtual void Freeze(void)
Puts the device into "freeze frame" mode.
Definition: device.c:1238
cDevice::IsPlayingVideo
virtual bool IsPlayingVideo(void) const
Returns true if the currently attached player has delivered any video packets.
Definition: device.h:705
cControl::GetRecording
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
cPlayer::DeviceTrickSpeed
void DeviceTrickSpeed(int Speed, bool Forward)
Definition: player.h:30
cDevice::PlayTs
virtual int PlayTs(const uchar *Data, int Length, bool VideoOnly=false)
Plays the given TS packet.
Definition: device.c:1569
cPlayer::DeviceGetSTC
uint64_t DeviceGetSTC(void)
Definition: player.h:37
cPlayer::DeviceSetAvailableTrack
bool DeviceSetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language=NULL, const char *Description=NULL)
Definition: player.h:23
cPlayer::playMode
ePlayMode playMode
Definition: player.h:20
cString
Definition: tools.h:176
cDevice::Mute
virtual void Mute(void)
Turns off audio while replaying.
Definition: device.c:1245
cControl::cControl
cControl(cPlayer *Player, bool Hidden=false)
Definition: player.c:45
cControl::GetFrameNumber
bool GetFrameNumber(int &Current, int &Total) const
Definition: player.h:112
cPlayer::~cPlayer
virtual ~cPlayer()
Definition: player.c:21
cDevice::Poll
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:1366
cControl::control
static cControl * control
Definition: player.h:82
cPlayer::IsAttached
bool IsAttached(void)
Definition: player.h:54
cDevice::Clear
virtual void Clear(void)
Clears all video and audio data from the device.
Definition: device.c:1224
cDevice::Play
virtual void Play(void)
Sets the device into play mode (after a previous trick mode).
Definition: device.c:1231
cPlayer::PlayPes
int PlayPes(const uchar *Data, int Length, bool VideoOnly=false)
Definition: player.c:26
cPlayer::device
cDevice * device
Definition: player.h:19
cControl::GetReplayMode
bool GetReplayMode(bool &Play, bool &Forward, int &Speed) const
Definition: player.h:113
cDevice::HasIBPTrickSpeed
virtual bool HasIBPTrickSpeed(void)
Returns true if this device can handle all frames in 'fast forward' trick speeds.
Definition: device.h:737
eVideoDisplayFormat
eVideoDisplayFormat
Definition: device.h:58
osdbase.h
cDevice::ClrAvailableTracks
void ClrAvailableTracks(bool DescriptionsOnly=false, bool IdsOnly=false)
Clears the list of currently available tracks.
Definition: device.c:1027
cControl::GetHeader
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
cControl::mutex
static cMutex mutex
Definition: player.h:83
cControl::GetInfo
virtual cOsdObject * GetInfo(void)
Returns an OSD object that displays information about the currently played programme.
Definition: player.c:58
cPlayer::DeviceClrAvailableTracks
void DeviceClrAvailableTracks(bool DescriptionsOnly=false)
Definition: player.h:22
cPlayer::DevicePlay
void DevicePlay(void)
Definition: player.h:32
cControl::Control
static cControl * Control(bool Hidden=false)
Returns the current replay control (if any) in case it is currently visible.
Definition: player.c:73
cControl::Attach
static void Attach(void)
Definition: player.c:87
cPlayer::DeviceStillPicture
void DeviceStillPicture(const uchar *Data, int Length)
Definition: player.h:36
cControl::Shutdown
static void Shutdown(void)
Definition: player.c:100
pmAudioVideo
@ pmAudioVideo
Definition: device.h:40