vdr  2.4.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 4.12 2017/11/02 14:47:33 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 
61  };
62 
66  ttAudioLast = ttAudioFirst + 31, // MAXAPIDS - 1
69  ttDolbyLast = ttDolbyFirst + 15, // MAXDPIDS - 1
72  ttSubtitleLast = ttSubtitleFirst + 31, // MAXSPIDS - 1
74  };
75 
76 #define IS_AUDIO_TRACK(t) (ttAudioFirst <= (t) && (t) <= ttAudioLast)
77 #define IS_DOLBY_TRACK(t) (ttDolbyFirst <= (t) && (t) <= ttDolbyLast)
78 #define IS_SUBTITLE_TRACK(t) (ttSubtitleFirst <= (t) && (t) <= ttSubtitleLast)
79 
80 struct tTrackId {
81  uint16_t id; // The PES packet id or the PID.
82  char language[MAXLANGCODE2]; // something like either "eng" or "deu+eng"
83  char description[32]; // something like "Dolby Digital 5.1"
84  };
85 
86 class cPlayer;
87 class cReceiver;
88 class cLiveSubtitle;
89 
90 class cDeviceHook : public cListObject {
91 public:
92  cDeviceHook(void);
96  virtual bool DeviceProvidesTransponder(const cDevice *Device, const cChannel *Channel) const;
98  };
99 
101 
102 #define DTV_STAT_VALID_NONE 0x0000
103 #define DTV_STAT_VALID_STRENGTH 0x0001
104 #define DTV_STAT_VALID_CNR 0x0002
105 #define DTV_STAT_VALID_BERPRE 0x0004
106 #define DTV_STAT_VALID_BERPOST 0x0008
107 #define DTV_STAT_VALID_PER 0x0010
108 #define DTV_STAT_VALID_STATUS 0x0020
109 
110 #define DTV_STAT_HAS_NONE 0x0000
111 #define DTV_STAT_HAS_SIGNAL 0x0001
112 #define DTV_STAT_HAS_CARRIER 0x0002
113 #define DTV_STAT_HAS_VITERBI 0x0004
114 #define DTV_STAT_HAS_SYNC 0x0008
115 #define DTV_STAT_HAS_LOCK 0x0010
116 
117 class cDevice : public cThread {
118  friend class cLiveSubtitle;
119  friend class cDeviceHook;
120  friend class cReceiver;
121 private:
122  static int numDevices;
123  static int useDevice;
126 public:
127  static int NumDevices(void) { return numDevices; }
129  static bool WaitForAllDevicesReady(int Timeout = 0);
135  static void SetUseDevice(int n);
139  static bool UseDevice(int n) { return useDevice == 0 || (useDevice & (1 << n)) != 0; }
142  static bool SetPrimaryDevice(int n);
146  static cDevice *PrimaryDevice(void) { return primaryDevice; }
148  static cDevice *ActualDevice(void);
151  static cDevice *GetDevice(int Index);
155  static cDevice *GetDevice(const cChannel *Channel, int Priority, bool LiveView, bool Query = false);
174  static cDevice *GetDeviceForTransponder(const cChannel *Channel, int Priority);
179  static void Shutdown(void);
182 private:
183  static int nextCardIndex;
185 protected:
186  cDevice(void);
187  virtual ~cDevice();
188  virtual bool Ready(void);
193  static int NextCardIndex(int n = 0);
205  virtual void MakePrimaryDevice(bool On);
212 public:
213  bool IsPrimaryDevice(void) const { return this == primaryDevice && HasDecoder(); }
214  int CardIndex(void) const { return cardIndex; }
216  int DeviceNumber(void) const;
218  virtual cString DeviceType(void) const;
224  virtual cString DeviceName(void) const;
227  virtual bool HasDecoder(void) const;
229  virtual bool AvoidRecording(void) const { return false; }
232 
233 // Device hooks
234 
235 private:
237 protected:
238  bool DeviceHooksProvidesTransponder(const cChannel *Channel) const;
239 
240 // SPU facilities
241 
242 private:
245 public:
246  virtual cSpuDecoder *GetSpuDecoder(void);
249 
250 // Channel facilities
251 
252 private:
255 protected:
256  static int currentChannel;
257 public:
258  virtual bool ProvidesSource(int Source) const;
260  virtual bool ProvidesTransponder(const cChannel *Channel) const;
264  virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const;
267  virtual bool ProvidesChannel(const cChannel *Channel, int Priority = IDLEPRIORITY, bool *NeedsDetachReceivers = NULL) const;
281  virtual bool ProvidesEIT(void) const;
285  virtual int NumProvidedSystems(void) const;
291  virtual const cPositioner *Positioner(void) const;
296  virtual bool SignalStats(int &Valid, double *Strength = NULL, double *Cnr = NULL, double *BerPre = NULL, double *BerPost = NULL, double *Per = NULL, int *Status = NULL) const;
313  virtual int SignalStrength(void) const;
318  virtual int SignalQuality(void) const;
323  virtual const cChannel *GetCurrentlyTunedTransponder(void) const;
328  virtual bool IsTunedToTransponder(const cChannel *Channel) const;
331  virtual bool MaySwitchTransponder(const cChannel *Channel) const;
336  bool SwitchChannel(const cChannel *Channel, bool LiveView);
339  static bool SwitchChannel(int Direction);
343 private:
344  eSetChannelResult SetChannel(const cChannel *Channel, bool LiveView);
346 protected:
347  virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
349 public:
350  static int CurrentChannel(void) { return primaryDevice ? currentChannel : 0; }
352 #ifndef DEPRECATED_SETCURRENTCHANNEL
353 #define DEPRECATED_SETCURRENTCHANNEL 1
354 #endif
355 #if DEPRECATED_SETCURRENTCHANNEL
356  static void SetCurrentChannel(const cChannel *Channel) { currentChannel = Channel ? Channel->Number() : 0; }
357 #endif
358  static void SetCurrentChannel(int ChannelNumber) { currentChannel = ChannelNumber; }
362  void ForceTransferMode(void);
364  int Occupied(void) const;
366  void SetOccupied(int Seconds);
374  virtual bool HasLock(int TimeoutMs = 0) const;
380  virtual bool HasProgramme(void) const;
383 
384 // PID handle facilities
385 
386 private:
387  mutable cMutex mutexPids;
388  virtual void Action(void);
389 protected:
390  enum ePidType { ptAudio, ptVideo, ptPcr, ptTeletext, ptDolby, ptOther };
391  class cPidHandle {
392  public:
393  int pid;
395  int handle;
396  int used;
397  cPidHandle(void) { pid = streamType = used = 0; handle = -1; }
398  };
400  bool HasPid(int Pid) const;
402  bool AddPid(int Pid, ePidType PidType = ptOther, int StreamType = 0);
404  void DelPid(int Pid, ePidType PidType = ptOther);
406  virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
414 public:
415  void DelLivePids(void);
417 
418 // Section filter facilities
419 
420 private:
426 protected:
427  void StartSectionHandler(void);
431  void StopSectionHandler(void);
435 public:
436  virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask);
440  virtual int ReadFilter(int Handle, void *Buffer, size_t Length);
444  virtual void CloseFilter(int Handle);
449  void AttachFilter(cFilter *Filter);
451  void Detach(cFilter *Filter);
453 
454 // Common Interface facilities:
455 
456 private:
458 public:
459  virtual bool HasCi(void);
461  virtual bool HasInternalCam(void) { return false; }
467  void SetCamSlot(cCamSlot *CamSlot);
469  cCamSlot *CamSlot(void) const { return camSlot; }
472 
473 // Image Grab facilities
474 
475 public:
476  virtual uchar *GrabImage(int &Size, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
488  bool GrabImageFile(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
493 
494 // Video format facilities
495 
496 public:
497  virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat);
503  virtual void SetVideoFormat(bool VideoFormat16_9);
508  virtual void GetVideoSize(int &Width, int &Height, double &VideoAspect);
515  virtual void GetOsdSize(int &Width, int &Height, double &PixelAspect);
526 
527 // Track facilities
528 
529 private:
530  tTrackId availableTracks[ttMaxTrackTypes];
539 protected:
540  virtual void SetAudioTrackDevice(eTrackType Type);
542  virtual void SetSubtitleTrackDevice(eTrackType Type);
544 public:
545  void ClrAvailableTracks(bool DescriptionsOnly = false, bool IdsOnly = false);
550  bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL);
557  const tTrackId *GetTrack(eTrackType Type);
560  int NumTracks(eTrackType FirstTrack, eTrackType LastTrack) const;
563  int NumAudioTracks(void) const;
567  int NumSubtitleTracks(void) const;
569  eTrackType GetCurrentAudioTrack(void) const { return currentAudioTrack; }
570  bool SetCurrentAudioTrack(eTrackType Type);
573  eTrackType GetCurrentSubtitleTrack(void) const { return currentSubtitleTrack; }
574  bool SetCurrentSubtitleTrack(eTrackType Type, bool Manual = false);
580  void EnsureAudioTrack(bool Force = false);
584  void EnsureSubtitleTrack(void);
587  void SetKeepTracks(bool KeepTracks) { keepTracks = KeepTracks; }
591 
592 // Audio facilities
593 
594 private:
595  bool mute;
596  int volume;
597 protected:
598  virtual int GetAudioChannelDevice(void);
601  virtual void SetAudioChannelDevice(int AudioChannel);
603  virtual void SetVolumeDevice(int Volume);
605  virtual void SetDigitalAudioDevice(bool On);
609 public:
610  bool IsMute(void) const { return mute; }
611  bool ToggleMute(void);
613  int GetAudioChannel(void);
616  void SetAudioChannel(int AudioChannel);
619  void SetVolume(int Volume, bool Absolute = false);
622  static int CurrentVolume(void) { return primaryDevice ? primaryDevice->volume : 0; }//XXX???
623 
624 // Player facilities
625 
626 private:
633 protected:
634  const cPatPmtParser *PatPmtParser(void) const { return &patPmtParser; }
637  virtual bool CanReplay(void) const;
639  virtual bool SetPlayMode(ePlayMode PlayMode);
642  virtual int PlayVideo(const uchar *Data, int Length);
649  virtual int PlayAudio(const uchar *Data, int Length, uchar Id);
657  virtual int PlaySubtitle(const uchar *Data, int Length);
664  virtual int PlayPesPacket(const uchar *Data, int Length, bool VideoOnly = false);
669  virtual int PlayTsVideo(const uchar *Data, int Length);
677  virtual int PlayTsAudio(const uchar *Data, int Length);
685  virtual int PlayTsSubtitle(const uchar *Data, int Length);
693 public:
694  virtual int64_t GetSTC(void);
705  virtual bool IsPlayingVideo(void) const { return isPlayingVideo; }
708  virtual cRect CanScaleVideo(const cRect &Rect, int Alignment = taCenter) { return cRect::Null; }
729  virtual void ScaleVideo(const cRect &Rect = cRect::Null) {}
737  virtual bool HasIBPTrickSpeed(void) { return false; }
740  virtual void TrickSpeed(int Speed, bool Forward);
751  virtual void Clear(void);
755  virtual void Play(void);
758  virtual void Freeze(void);
760  virtual void Mute(void);
764  virtual void StillPicture(const uchar *Data, int Length);
770  virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
775  virtual bool Flush(int TimeoutMs = 0);
781  virtual int PlayPes(const uchar *Data, int Length, bool VideoOnly = false);
791  virtual int PlayTs(const uchar *Data, int Length, bool VideoOnly = false);
807  bool Replaying(void) const;
809  bool Transferring(void) const;
811  void StopReplay(void);
813  bool AttachPlayer(cPlayer *Player);
815  void Detach(cPlayer *Player);
817 
818 // Receiver facilities
819 
820 private:
823 public:
824  int Priority(void) const;
827 protected:
828  virtual bool OpenDvr(void);
831  virtual void CloseDvr(void);
833  virtual bool GetTSPacket(uchar *&Data);
840 public:
841  bool Receiving(bool Dummy = false) const;
843  bool AttachReceiver(cReceiver *Receiver);
845  void Detach(cReceiver *Receiver);
847  void DetachAll(int Pid);
849  virtual void DetachAllReceivers(void);
851  };
852 
860 
861 class cTSBuffer : public cThread {
862 private:
863  int f;
867  virtual void Action(void);
868 public:
869  cTSBuffer(int File, int Size, int CardIndex);
870  virtual ~cTSBuffer();
871  uchar *Get(int *Available = NULL, bool CheckAvailable = false);
882  void Skip(int Count);
889  };
890 
891 #endif //__DEVICE_H
cEitFilter * eitFilter
Definition: device.h:422
static int nextCardIndex
Definition: device.h:183
cPatPmtParser patPmtParser
Definition: device.h:628
int cardIndex
Definition: device.h:864
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:139
unsigned char uchar
Definition: tools.h:31
int Number(void) const
Definition: channels.h:177
cNitFilter * nitFilter
Definition: device.h:425
Definition: device.h:64
friend class cDevice
Definition: receiver.h:18
cPlayer * player
Definition: device.h:627
eSetChannelResult
Definition: device.h:36
cSdtFilter * sdtFilter
Definition: device.h:424
cRingBufferLinear * ringBuffer
Definition: device.h:866
Definition: eit.h:23
char description[32]
Definition: device.h:83
int f
Definition: device.h:863
Definition: sdt.h:16
Definition: nit.h:16
bool mute
Definition: device.h:595
#define MAXDEVICES
Definition: device.h:29
int cardIndex
Definition: device.h:184
static int currentChannel
Definition: device.h:256
int volume
Definition: device.h:596
bool autoSelectPreferredSubtitleLanguage
Definition: device.h:536
Definition: device.h:63
static int NumDevices(void)
Returns the total number of devices.
Definition: device.h:127
eTrackType GetCurrentSubtitleTrack(void) const
Definition: device.h:573
cDevice * device
Definition: receiver.h:20
eTrackType
Definition: device.h:63
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:737
cTsToPes tsToPesSubtitle
Definition: device.h:631
eTrackType currentSubtitleTrack
Definition: device.h:532
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:708
Definition: filter.h:49
Definition: osd.h:158
static int CurrentVolume(void)
Definition: device.h:622
int Priority(void)
Definition: receiver.h:57
bool IsPrimaryDevice(void) const
Definition: device.h:213
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:469
int pre_1_3_19_PrivateStream
Definition: device.h:538
cPatFilter * patFilter
Definition: device.h:423
Definition: player.h:16
#define IDLEPRIORITY
Definition: config.h:47
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
Definition: device.h:350
bool isPlayingVideo
Definition: device.h:632
cMutex mutexCurrentSubtitleTrack
Definition: device.h:534
Definition: osd.h:352
virtual bool IsPlayingVideo(void) const
Returns true if the currently attached player has delivered any video packets.
Definition: device.h:705
cTsToPes tsToPesVideo
Definition: device.h:629
int delivered
Definition: device.h:865
cTsToPes tsToPesAudio
Definition: device.h:630
cCamSlot * camSlot
Definition: device.h:457
eVideoDisplayFormat
Definition: device.h:58
cMutex mutexPids
Definition: device.h:387
cMutex mutexChannel
Definition: device.h:253
Definition: ci.h:232
static void SetCurrentChannel(int ChannelNumber)
Sets the number of the current channel on the primary device, without actually switching to it...
Definition: device.h:358
static cDevice * primaryDevice
Definition: device.h:125
static int numDevices
Definition: device.h:122
cSectionHandler * sectionHandler
Definition: device.h:421
ePlayMode
Definition: device.h:39
eTrackType currentAudioTrack
Definition: device.h:531
Definition: thread.h:67
static const cRect Null
Definition: osd.h:357
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:729
#define MAXLANGCODE2
Definition: channels.h:37
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:229
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:634
int CardIndex(void) const
Returns the card index of this device (0 ... MAXDEVICES - 1).
Definition: device.h:214
Definition: device.h:67
cMutex mutexReceiver
Definition: device.h:821
Definition: pat.h:19
static int useDevice
Definition: device.h:123
static cDevice * PrimaryDevice(void)
Returns the primary device.
Definition: device.h:146
cLiveSubtitle * liveSubtitle
Definition: device.h:243
unsigned char u_char
Definition: headers.h:24
static cList< cDeviceHook > deviceHooks
Definition: device.h:236
static void SetCurrentChannel(const cChannel *Channel)
Definition: device.h:356
int currentAudioTrackMissingCount
Definition: device.h:535
Definition: thread.h:79
time_t occupiedTimeout
Definition: device.h:254
cMutex mutexCurrentAudioTrack
Definition: device.h:533
void SetKeepTracks(bool KeepTracks)
Controls whether the current audio and subtitle track settings shall be kept as they currently are...
Definition: device.h:587
char language[MAXLANGCODE2]
Definition: device.h:82
Definition: device.h:36
#define MAXPIDHANDLES
Definition: device.h:30
#define MAXRECEIVERS
Definition: device.h:31
ePidType
Definition: device.h:390
bool keepTracks
Definition: device.h:537
Definition: tools.h:393
Derived cDevice classes that can receive channels will have to provide Transport Stream (TS) packets ...
Definition: device.h:861
cDvbSubtitleConverter * dvbSubtitleConverter
Definition: device.h:244
eTrackType GetCurrentAudioTrack(void) const
Definition: device.h:569
virtual bool HasInternalCam(void)
Returns true if this device handles encrypted channels itself without VDR assistance.
Definition: device.h:461
Definition: tools.h:176
bool IsMute(void) const
Definition: device.h:610
uint16_t id
Definition: device.h:81