vdr 2.8.3
player.c
Go to the documentation of this file.
1/*
2 * player.c: 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.c 5.4 2026/08/22 11:23:08 kls Exp $
8 */
9
10#include "player.h"
11#include "i18n.h"
12
13// --- cPlayer ---------------------------------------------------------------
14
16{
17 device = NULL;
18 playMode = PlayMode;
19}
20
22{
23 Detach();
24}
25
26int cPlayer::PlayPes(const uchar *Data, int Length, bool VideoOnly)
27{
28 if (cDevice *d = device)
29 return d->PlayPes(Data, Length, VideoOnly);
30 esyslog("ERROR: attempt to use cPlayer::PlayPes() without attaching to a cDevice!");
31 return -1;
32}
33
35{
36 if (cDevice *d = device)
37 d->Detach(this);
38}
39
40// --- cControl --------------------------------------------------------------
41
44
45cControl::cControl(cPlayer *Player, bool Hidden)
46{
47 attached = false;
48 hidden = Hidden;
49 player = Player;
50}
51
53{
54 if (this == control)
55 control = NULL;
56}
57
59{
60 return NULL;
61}
62
64{
65 return NULL;
66}
67
69{
70 return "";
71}
72
73#define CONTROL_LOCK_TIMEOUT 100 // ms
74
75cControl *cControl::Control(cMutexLock &MutexLock, bool Hidden, bool *LockedOtherwise)
76{
77 int Timeout = cThread::IsMainThread() ? 0 : CONTROL_LOCK_TIMEOUT;
78 if (LockedOtherwise)
79 *LockedOtherwise = false;
80 // Only a control needs the caller to keep the mutex locked. The main loop holds
81 // it across its key dispatch, which takes the Channels lock, while
82 // cControl::Shutdown() is called with the Channels lock held:
83 cMutexLock ControlMutexLock;
84 if (ControlMutexLock.Lock(&mutex, Timeout, LockedOtherwise)) {
85 if (control && (!control->hidden || Hidden) && MutexLock.Lock(&mutex)) // recursive, stays locked for the caller
86 return control;
87 }
88 return NULL;
89}
90
92{
93 cMutexLock MutexLock(&mutex);
94 delete control;
96}
97
99{
100 cMutexLock MutexLock(&mutex);
102 if (cDevice::PrimaryDevice()->AttachPlayer(control->player))
103 control->attached = true;
104 else {
105 Skins.QueueMessage(mtError, tr("Primary device has no MPEG decoder, can't attach player!"));
106 Shutdown();
107 }
108 }
109}
110
112{
113 cMutexLock MutexLock(&mutex);
114 cControl *c = control; // avoids recursions
115 control = NULL;
116 delete c;
117}
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 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
static void Shutdown(void)
Definition player.c:111
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 hidden
Definition player.h:90
virtual ~cControl() override
Definition player.c:52
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
cPlayer * player
Definition player.h:92
static cDevice * PrimaryDevice(void)
Returns the primary device.
Definition device.h:148
bool Lock(cMutex *Mutex, int TimeoutMs=0, bool *TimedOut=NULL)
Returns true if the mutex was successfully locked.
Definition thread.c:435
cOsdObject(bool FastResponse=false)
Definition osdbase.h:89
void Detach(void)
Definition player.c:34
std::atomic< cDevice * > device
Definition player.h:19
friend class cDevice
Definition player.h:17
int PlayPes(const uchar *Data, int Length, bool VideoOnly=false)
Definition player.c:26
bool IsAttached(void)
Definition player.h:57
virtual ~cPlayer()
Definition player.c:21
ePlayMode playMode
Definition player.h:20
cPlayer(ePlayMode PlayMode=pmAudioVideo)
Definition player.c:15
int QueueMessage(eMessageType Type, const char *s, int Seconds=0, int Timeout=0)
Like Message(), but this function may be called from a background thread.
Definition skins.c:334
static tThreadId IsMainThread(void)
Definition thread.h:140
ePlayMode
Definition device.h:39
#define tr(s)
Definition i18n.h:85
#define CONTROL_LOCK_TIMEOUT
Definition player.c:73
cSkins Skins
Definition skins.c:257
@ mtError
Definition skins.h:37
unsigned char uchar
Definition tools.h:31
#define esyslog(a...)
Definition tools.h:35