vdr  2.2.0
device.h
Go to the documentation of this file.
1 /*
2  * device.h: The basic device interface
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: device.h 3.10 2015/01/12 14:39:09 kls Exp $
8  */
9 
10 #ifndef __DEVICE_H
11 #define __DEVICE_H
12 
13 #include "channels.h"
14 #include "ci.h"
15 #include "dvbsubtitle.h"
16 #include "eit.h"
17 #include "filter.h"
18 #include "nit.h"
19 #include "pat.h"
20 #include "positioner.h"
21 #include "remux.h"
22 #include "ringbuffer.h"
23 #include "sdt.h"
24 #include "sections.h"
25 #include "spu.h"
26 #include "thread.h"
27 #include "tools.h"
28 
29 #define MAXDEVICES 16 // the maximum number of devices in the system
30 #define MAXPIDHANDLES 64 // the maximum number of different PIDs per device
31 #define MAXRECEIVERS 16 // the maximum number of receivers per device
32 #define MAXVOLUME 255
33 #define VOLUMEDELTA (MAXVOLUME / Setup.VolumeSteps) // used to increase/decrease the volume
34 #define MAXOCCUPIEDTIMEOUT 99 // max. time (in seconds) a device may be occupied
35 
37 
38 // Note that VDR itself always uses pmAudioVideo when replaying a recording!
39 enum ePlayMode { pmNone, // audio/video from decoder
40  pmAudioVideo, // audio/video from player
41  pmAudioOnly, // audio only from player, video from decoder
42  pmAudioOnlyBlack, // audio only from player, no video (black screen)
43  pmVideoOnly, // video only from player, audio from decoder
45  // external player (e.g. MPlayer), release the device
46  // WARNING: USE THIS MODE ONLY AS A LAST RESORT, IF YOU
47  // ABSOLUTELY, POSITIVELY CAN'T IMPLEMENT YOUR PLAYER
48  // THE WAY IT IS SUPPOSED TO WORK. FORCING THE DEVICE
49  // TO RELEASE ITS FILES HANDLES (OR WHATEVER RESOURCES
50  // IT MAY USE) TO ALLOW AN EXTERNAL PLAYER TO ACCESS
51  // THEM MEANS THAT SUCH A PLAYER WILL NEED TO HAVE
52  // DETAILED KNOWLEDGE ABOUT THE INTERNALS OF THE DEVICE
53  // IN USE. AS A CONSEQUENCE, YOUR PLAYER MAY NOT WORK
54  // IF A PARTICULAR VDR INSTALLATION USES A DEVICE NOT
55  // KNOWN TO YOUR PLAYER.
56  };
57 
58 #define DEPRECATED_VIDEOSYSTEM
59 #ifdef DEPRECATED_VIDEOSYSTEM
62  };
63 #endif
64 
68  };
69 
73  ttAudioLast = ttAudioFirst + 31, // MAXAPIDS - 1
76  ttDolbyLast = ttDolbyFirst + 15, // MAXDPIDS - 1
79  ttSubtitleLast = ttSubtitleFirst + 31, // MAXSPIDS - 1
81  };
82 
83 #define IS_AUDIO_TRACK(t) (ttAudioFirst <= (t) && (t) <= ttAudioLast)
84 #define IS_DOLBY_TRACK(t) (ttDolbyFirst <= (t) && (t) <= ttDolbyLast)
85 #define IS_SUBTITLE_TRACK(t) (ttSubtitleFirst <= (t) && (t) <= ttSubtitleLast)
86 
87 struct tTrackId {
88  uint16_t id; // The PES packet id or the PID.
89  char language[MAXLANGCODE2]; // something like either "eng" or "deu+eng"
90  char description[32]; // something like "Dolby Digital 5.1"
91  };
92 
93 class cPlayer;
94 class cReceiver;
95 class cLiveSubtitle;
96 
97 class cDeviceHook : public cListObject {
98 public:
99  cDeviceHook(void);
103  virtual bool DeviceProvidesTransponder(const cDevice *Device, const cChannel *Channel) const;
105  };
106 
108 
109 class cDevice : public cThread {
110  friend class cLiveSubtitle;
111  friend class cDeviceHook;
112 private:
113  static int numDevices;
114  static int useDevice;
115  static cDevice *device[MAXDEVICES];
117 public:
118  static int NumDevices(void) { return numDevices; }
120  static bool WaitForAllDevicesReady(int Timeout = 0);
126  static void SetUseDevice(int n);
130  static bool UseDevice(int n) { return useDevice == 0 || (useDevice & (1 << n)) != 0; }
133  static bool SetPrimaryDevice(int n);
137  static cDevice *PrimaryDevice(void) { return primaryDevice; }
139  static cDevice *ActualDevice(void);
142  static cDevice *GetDevice(int Index);
146  static cDevice *GetDevice(const cChannel *Channel, int Priority, bool LiveView, bool Query = false);
165  static cDevice *GetDeviceForTransponder(const cChannel *Channel, int Priority);
170  static void Shutdown(void);
173 private:
174  static int nextCardIndex;
176 protected:
177  cDevice(void);
178  virtual ~cDevice();
179  virtual bool Ready(void);
184  static int NextCardIndex(int n = 0);
196  virtual void MakePrimaryDevice(bool On);
203 public:
204  bool IsPrimaryDevice(void) const { return this == primaryDevice && HasDecoder(); }
205  int CardIndex(void) const { return cardIndex; }
207  int DeviceNumber(void) const;
209  virtual cString DeviceType(void) const;
215  virtual cString DeviceName(void) const;
218  virtual bool HasDecoder(void) const;
220  virtual bool AvoidRecording(void) const { return false; }
223 
224 // Device hooks
225 
226 private:
228 protected:
229  bool DeviceHooksProvidesTransponder(const cChannel *Channel) const;
230 
231 // SPU facilities
232 
233 private:
236 public:
237  virtual cSpuDecoder *GetSpuDecoder(void);
240 
241 // Channel facilities
242 
243 private:
245 protected:
246  static int currentChannel;
247 public:
248  virtual bool ProvidesSource(int Source) const;
250  virtual bool ProvidesTransponder(const cChannel *Channel) const;
254  virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const;
257  virtual bool ProvidesChannel(const cChannel *Channel, int Priority = IDLEPRIORITY, bool *NeedsDetachReceivers = NULL) const;
271  virtual bool ProvidesEIT(void) const;
275  virtual int NumProvidedSystems(void) const;
281  virtual const cPositioner *Positioner(void) const;
286  virtual int SignalStrength(void) const;
291  virtual int SignalQuality(void) const;
296  virtual const cChannel *GetCurrentlyTunedTransponder(void) const;
301  virtual bool IsTunedToTransponder(const cChannel *Channel) const;
304  virtual bool MaySwitchTransponder(const cChannel *Channel) const;
309  bool SwitchChannel(const cChannel *Channel, bool LiveView);
312  static bool SwitchChannel(int Direction);
316 private:
317  eSetChannelResult SetChannel(const cChannel *Channel, bool LiveView);
319 protected:
320  virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
322 public:
323  static int CurrentChannel(void) { return primaryDevice ? currentChannel : 0; }
325  static void SetCurrentChannel(const cChannel *Channel) { currentChannel = Channel ? Channel->Number() : 0; }
329  void ForceTransferMode(void);
331  int Occupied(void) const;
333  void SetOccupied(int Seconds);
341  virtual bool HasLock(int TimeoutMs = 0) const;
347  virtual bool HasProgramme(void) const;
350 
351 // PID handle facilities
352 
353 private:
354  virtual void Action(void);
355 protected:
356  enum ePidType { ptAudio, ptVideo, ptPcr, ptTeletext, ptDolby, ptOther };
357  class cPidHandle {
358  public:
359  int pid;
361  int handle;
362  int used;
363  cPidHandle(void) { pid = streamType = used = 0; handle = -1; }
364  };
366  bool HasPid(int Pid) const;
368  bool AddPid(int Pid, ePidType PidType = ptOther, int StreamType = 0);
370  void DelPid(int Pid, ePidType PidType = ptOther);
372  virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
380 public:
381  void DelLivePids(void);
383 
384 // Section filter facilities
385 
386 private:
392 protected:
393  void StartSectionHandler(void);
397  void StopSectionHandler(void);
401 public:
402  virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask);
406  virtual int ReadFilter(int Handle, void *Buffer, size_t Length);
410  virtual void CloseFilter(int Handle);
415  void AttachFilter(cFilter *Filter);
417  void Detach(cFilter *Filter);
419 
420 // Common Interface facilities:
421 
422 private:
425 public:
426  virtual bool HasCi(void);
428  virtual bool HasInternalCam(void) { return false; }
434  void SetCamSlot(cCamSlot *CamSlot);
436  cCamSlot *CamSlot(void) const { return camSlot; }
439 
440 // Image Grab facilities
441 
442 public:
443  virtual uchar *GrabImage(int &Size, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
455  bool GrabImageFile(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
460 
461 // Video format facilities
462 
463 public:
464  virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat);
470  virtual void SetVideoFormat(bool VideoFormat16_9);
475 #ifdef DEPRECATED_VIDEOSYSTEM
476  virtual eVideoSystem GetVideoSystem(void) { return vsPAL; }
480 #endif
481  virtual void GetVideoSize(int &Width, int &Height, double &VideoAspect);
488  virtual void GetOsdSize(int &Width, int &Height, double &PixelAspect);
499 
500 // Track facilities
501 
502 private:
503  tTrackId availableTracks[ttMaxTrackTypes];
512 protected:
513  virtual void SetAudioTrackDevice(eTrackType Type);
515  virtual void SetSubtitleTrackDevice(eTrackType Type);
517 public:
518  void ClrAvailableTracks(bool DescriptionsOnly = false, bool IdsOnly = false);
523  bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL);
530  const tTrackId *GetTrack(eTrackType Type);
533  int NumTracks(eTrackType FirstTrack, eTrackType LastTrack) const;
536  int NumAudioTracks(void) const;
540  int NumSubtitleTracks(void) const;
542  eTrackType GetCurrentAudioTrack(void) const { return currentAudioTrack; }
543  bool SetCurrentAudioTrack(eTrackType Type);
546  eTrackType GetCurrentSubtitleTrack(void) const { return currentSubtitleTrack; }
547  bool SetCurrentSubtitleTrack(eTrackType Type, bool Manual = false);
553  void EnsureAudioTrack(bool Force = false);
557  void EnsureSubtitleTrack(void);
560  void SetKeepTracks(bool KeepTracks) { keepTracks = KeepTracks; }
564 
565 // Audio facilities
566 
567 private:
568  bool mute;
569  int volume;
570 protected:
571  virtual int GetAudioChannelDevice(void);
574  virtual void SetAudioChannelDevice(int AudioChannel);
576  virtual void SetVolumeDevice(int Volume);
578  virtual void SetDigitalAudioDevice(bool On);
582 public:
583  bool IsMute(void) const { return mute; }
584  bool ToggleMute(void);
586  int GetAudioChannel(void);
589  void SetAudioChannel(int AudioChannel);
592  void SetVolume(int Volume, bool Absolute = false);
595  static int CurrentVolume(void) { return primaryDevice ? primaryDevice->volume : 0; }//XXX???
596 
597 // Player facilities
598 
599 private:
607 protected:
608  const cPatPmtParser *PatPmtParser(void) const { return &patPmtParser; }
611  virtual bool CanReplay(void) const;
613  virtual bool SetPlayMode(ePlayMode PlayMode);
616  virtual int PlayVideo(const uchar *Data, int Length);
623  virtual int PlayAudio(const uchar *Data, int Length, uchar Id);
631  virtual int PlaySubtitle(const uchar *Data, int Length);
638  virtual int PlayPesPacket(const uchar *Data, int Length, bool VideoOnly = false);
643  virtual int PlayTsVideo(const uchar *Data, int Length);
651  virtual int PlayTsAudio(const uchar *Data, int Length);
659  virtual int PlayTsSubtitle(const uchar *Data, int Length);
667 public:
668  virtual int64_t GetSTC(void);
679  virtual bool IsPlayingVideo(void) const { return isPlayingVideo; }
682  virtual cRect CanScaleVideo(const cRect &Rect, int Alignment = taCenter) { return cRect::Null; }
703  virtual void ScaleVideo(const cRect &Rect = cRect::Null) {}
711  virtual bool HasIBPTrickSpeed(void) { return false; }
714  virtual void TrickSpeed(int Speed, bool Forward);
725  virtual void Clear(void);
729  virtual void Play(void);
732  virtual void Freeze(void);
734  virtual void Mute(void);
738  virtual void StillPicture(const uchar *Data, int Length);
744  virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
749  virtual bool Flush(int TimeoutMs = 0);
755  virtual int PlayPes(const uchar *Data, int Length, bool VideoOnly = false);
765  virtual int PlayTs(const uchar *Data, int Length, bool VideoOnly = false);
781  bool Replaying(void) const;
783  bool Transferring(void) const;
785  void StopReplay(void);
787  bool AttachPlayer(cPlayer *Player);
789  void Detach(cPlayer *Player);
791 
792 // Receiver facilities
793 
794 private:
797 public:
798  int Priority(void) const;
801 protected:
802  virtual bool OpenDvr(void);
805  virtual void CloseDvr(void);
807  virtual bool GetTSPacket(uchar *&Data);
814 public:
815  bool Receiving(bool Dummy = false) const;
817  bool AttachReceiver(cReceiver *Receiver);
819  void Detach(cReceiver *Receiver);
821  void DetachAll(int Pid);
823  virtual void DetachAllReceivers(void);
825  };
826 
834 
835 class cTSBuffer : public cThread {
836 private:
837  int f;
839  bool delivered;
841  virtual void Action(void);
842 public:
843  cTSBuffer(int File, int Size, int CardIndex);
844  virtual ~cTSBuffer();
845  uchar *Get(int *Available = NULL);
852  void Skip(int Count);
859  };
860 
861 #endif //__DEVICE_H
cEitFilter * eitFilter
Definition: device.h:388
static int nextCardIndex
Definition: device.h:174
cPatPmtParser patPmtParser
Definition: device.h:601
virtual eVideoSystem GetVideoSystem(void)
Returns the video system of the currently displayed material (default is PAL).
Definition: device.h:476
int cardIndex
Definition: device.h:838
static bool UseDevice(int n)
Tells whether the device with the given card index shall be used in this instance of VDR...
Definition: device.h:130
unsigned char uchar
Definition: tools.h:30
cTsToPes tsToPesTeletext
Definition: device.h:605
int Number(void) const
Definition: channels.h:197
cNitFilter * nitFilter
Definition: device.h:391
Definition: device.h:71
cPlayer * player
Definition: device.h:600
eSetChannelResult
Definition: device.h:36
int Index(void) const
Definition: tools.c:1989
cSdtFilter * sdtFilter
Definition: device.h:390
cRingBufferLinear * ringBuffer
Definition: device.h:840
Definition: eit.h:15
char description[32]
Definition: device.h:90
int f
Definition: device.h:837
Definition: sdt.h:16
Definition: nit.h:19
bool mute
Definition: device.h:568
#define MAXDEVICES
Definition: device.h:29
int cardIndex
Definition: device.h:175
static int currentChannel
Definition: device.h:246
int volume
Definition: device.h:569
bool autoSelectPreferredSubtitleLanguage
Definition: device.h:509
Definition: device.h:70
static int NumDevices(void)
Returns the total number of devices.
Definition: device.h:118
eTrackType GetCurrentSubtitleTrack(void) const
Definition: device.h:546
eTrackType
Definition: device.h:70
Definition: device.h:39
virtual bool HasIBPTrickSpeed(void)
Returns true if this device can handle all frames in &#39;fast forward&#39; trick speeds. ...
Definition: device.h:711
cTsToPes tsToPesSubtitle
Definition: device.h:604
eTrackType currentSubtitleTrack
Definition: device.h:505
virtual cRect CanScaleVideo(const cRect &Rect, int Alignment=taCenter)
Asks the output device whether it can scale the currently shown video in such a way that it fits into...
Definition: device.h:682
Definition: filter.h:41
Definition: osd.h:158
static int CurrentVolume(void)
Definition: device.h:595
bool IsPrimaryDevice(void) const
Definition: device.h:204
A steerable satellite dish generally points to the south on the northern hemisphere, and to the north on the southern hemisphere (unless you&#39;re located directly on the equator, in which case the general direction is "up").
Definition: positioner.h:31
cCamSlot * CamSlot(void) const
Returns the CAM slot that is currently used with this device, or NULL if no CAM slot is in use...
Definition: device.h:436
int pre_1_3_19_PrivateStream
Definition: device.h:511
cPatFilter * patFilter
Definition: device.h:389
Definition: player.h:16
#define IDLEPRIORITY
Definition: config.h:43
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
Definition: device.h:323
bool isPlayingVideo
Definition: device.h:606
time_t startScrambleDetection
Definition: device.h:423
cMutex mutexCurrentSubtitleTrack
Definition: device.h:507
Definition: osd.h:352
virtual bool IsPlayingVideo(void) const
Returns true if the currently attached player has delivered any video packets.
Definition: device.h:679
cTsToPes tsToPesVideo
Definition: device.h:602
cTsToPes tsToPesAudio
Definition: device.h:603
cCamSlot * camSlot
Definition: device.h:424
eVideoDisplayFormat
Definition: device.h:65
bool delivered
Definition: device.h:839
Definition: ci.h:128
static cDevice * primaryDevice
Definition: device.h:116
static int numDevices
Definition: device.h:113
cSectionHandler * sectionHandler
Definition: device.h:387
ePlayMode
Definition: device.h:39
eTrackType currentAudioTrack
Definition: device.h:504
Definition: thread.h:63
static const cRect Null
Definition: osd.h:357
eVideoSystem
Definition: device.h:60
virtual void ScaleVideo(const cRect &Rect=cRect::Null)
Scales the currently shown video in such a way that it fits into the given Rect.
Definition: device.h:703
#define MAXLANGCODE2
Definition: channels.h:42
virtual bool AvoidRecording(void) const
Returns true if this device should only be used for recording if no other device is available...
Definition: device.h:220
const cPatPmtParser * PatPmtParser(void) const
Returns a pointer to the patPmtParser, so that a derived device can use the stream information from i...
Definition: device.h:608
int CardIndex(void) const
Returns the card index of this device (0 ... MAXDEVICES - 1).
Definition: device.h:205
Definition: device.h:74
cMutex mutexReceiver
Definition: device.h:795
Definition: pat.h:19
static int useDevice
Definition: device.h:114
Definition: device.h:60
static cDevice * PrimaryDevice(void)
Returns the primary device.
Definition: device.h:137
cLiveSubtitle * liveSubtitle
Definition: device.h:234
unsigned char u_char
Definition: headers.h:24
static cList< cDeviceHook > deviceHooks
Definition: device.h:227
static void SetCurrentChannel(const cChannel *Channel)
Sets the number of the current channel on the primary device, without actually switching to it...
Definition: device.h:325
int currentAudioTrackMissingCount
Definition: device.h:508
Definition: thread.h:77
time_t occupiedTimeout
Definition: device.h:244
cMutex mutexCurrentAudioTrack
Definition: device.h:506
void SetKeepTracks(bool KeepTracks)
Controls whether the current audio and subtitle track settings shall be kept as they currently are...
Definition: device.h:560
char language[MAXLANGCODE2]
Definition: device.h:89
Definition: device.h:36
#define MAXPIDHANDLES
Definition: device.h:30
#define MAXRECEIVERS
Definition: device.h:31
ePidType
Definition: device.h:356
bool keepTracks
Definition: device.h:510
Definition: tools.h:357
Derived cDevice classes that can receive channels will have to provide Transport Stream (TS) packets ...
Definition: device.h:835
Definition: device.h:61
cDvbSubtitleConverter * dvbSubtitleConverter
Definition: device.h:235
eTrackType GetCurrentAudioTrack(void) const
Definition: device.h:542
The cDevice class is the base from which actual devices can be derived.
Definition: device.h:109
virtual bool HasInternalCam(void)
Returns true if this device handles encrypted channels itself without VDR assistance.
Definition: device.h:428
Definition: tools.h:168
bool IsMute(void) const
Definition: device.h:583
uint16_t id
Definition: device.h:88