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  virtual ~cDevice();
178  virtual bool Ready(void);
183  static int NextCardIndex(int n = 0);
195  virtual void MakePrimaryDevice(bool On);
202 public:
203  int DeviceNumber(void) const;
205  virtual cString DeviceType(void) const;
211  virtual cString DeviceName(void) const;
214  virtual bool HasDecoder(void) const;
216  virtual bool AvoidRecording(void) const { return false; }
219 
220 // Device hooks
221 
222 private:
224 protected:
225  bool DeviceHooksProvidesTransponder(const cChannel *Channel) const;
226 
227 // SPU facilities
228 
229 private:
232 public:
233  virtual cSpuDecoder *GetSpuDecoder(void);
236 
237 // Channel facilities
238 
239 private:
241 protected:
242  static int currentChannel;
243 public:
244  virtual bool ProvidesSource(int Source) const;
246  virtual bool ProvidesTransponder(const cChannel *Channel) const;
250  virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const;
253  virtual bool ProvidesChannel(const cChannel *Channel, int Priority = IDLEPRIORITY, bool *NeedsDetachReceivers = NULL) const;
267  virtual bool ProvidesEIT(void) const;
271  virtual int NumProvidedSystems(void) const;
277  virtual const cPositioner *Positioner(void) const;
282  virtual int SignalStrength(void) const;
287  virtual int SignalQuality(void) const;
292  virtual const cChannel *GetCurrentlyTunedTransponder(void) const;
297  virtual bool IsTunedToTransponder(const cChannel *Channel) const;
300  virtual bool MaySwitchTransponder(const cChannel *Channel) const;
305  bool SwitchChannel(const cChannel *Channel, bool LiveView);
308  static bool SwitchChannel(int Direction);
312 private:
313  eSetChannelResult SetChannel(const cChannel *Channel, bool LiveView);
315 protected:
316  virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
318 public:
319  static int CurrentChannel(void) { return primaryDevice ? currentChannel : 0; }
321  static void SetCurrentChannel(const cChannel *Channel) { currentChannel = Channel ? Channel->Number() : 0; }
325  void ForceTransferMode(void);
327  int Occupied(void) const;
329  void SetOccupied(int Seconds);
337  virtual bool HasLock(int TimeoutMs = 0) const;
343  virtual bool HasProgramme(void) const;
346 
347 // PID handle facilities
348 
349 private:
350  virtual void Action(void);
351 protected:
352  enum ePidType { ptAudio, ptVideo, ptPcr, ptTeletext, ptDolby, ptOther };
353  class cPidHandle {
354  public:
355  int pid;
357  int handle;
358  int used;
359  cPidHandle(void) { pid = streamType = used = 0; handle = -1; }
360  };
362  bool HasPid(int Pid) const;
364  bool AddPid(int Pid, ePidType PidType = ptOther, int StreamType = 0);
366  void DelPid(int Pid, ePidType PidType = ptOther);
368  virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
376 public:
377  void DelLivePids(void);
379 
380 // Section filter facilities
381 
382 private:
388 protected:
389  void StartSectionHandler(void);
393  void StopSectionHandler(void);
397 public:
398  virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask);
402  virtual int ReadFilter(int Handle, void *Buffer, size_t Length);
406  virtual void CloseFilter(int Handle);
411  void AttachFilter(cFilter *Filter);
413  void Detach(cFilter *Filter);
415 
416 // Common Interface facilities:
417 
418 private:
421 public:
422  virtual bool HasCi(void);
424  virtual bool HasInternalCam(void) { return false; }
430  void SetCamSlot(cCamSlot *CamSlot);
432 
433 // Image Grab facilities
434 
435 public:
436  virtual uchar *GrabImage(int &Size, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
448  bool GrabImageFile(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
453 
454 // Video format facilities
455 
456 public:
457  virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat);
463  virtual void SetVideoFormat(bool VideoFormat16_9);
468 #ifdef DEPRECATED_VIDEOSYSTEM
469  virtual eVideoSystem GetVideoSystem(void) { return vsPAL; }
473 #endif
474  virtual void GetVideoSize(int &Width, int &Height, double &VideoAspect);
481  virtual void GetOsdSize(int &Width, int &Height, double &PixelAspect);
492 
493 // Track facilities
494 
495 private:
496  tTrackId availableTracks[ttMaxTrackTypes];
505 protected:
506  virtual void SetAudioTrackDevice(eTrackType Type);
508  virtual void SetSubtitleTrackDevice(eTrackType Type);
510 public:
511  void ClrAvailableTracks(bool DescriptionsOnly = false, bool IdsOnly = false);
516  bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL);
523  const tTrackId *GetTrack(eTrackType Type);
526  int NumTracks(eTrackType FirstTrack, eTrackType LastTrack) const;
529  int NumAudioTracks(void) const;
533  int NumSubtitleTracks(void) const;
535  eTrackType GetCurrentAudioTrack(void) const { return currentAudioTrack; }
536  bool SetCurrentAudioTrack(eTrackType Type);
539  eTrackType GetCurrentSubtitleTrack(void) const { return currentSubtitleTrack; }
540  bool SetCurrentSubtitleTrack(eTrackType Type, bool Manual = false);
546  void EnsureAudioTrack(bool Force = false);
550  void EnsureSubtitleTrack(void);
553  void SetKeepTracks(bool KeepTracks) { keepTracks = KeepTracks; }
557 
558 // Audio facilities
559 
560 private:
561  bool mute;
562  int volume;
563 protected:
564  virtual int GetAudioChannelDevice(void);
567  virtual void SetAudioChannelDevice(int AudioChannel);
569  virtual void SetVolumeDevice(int Volume);
571  virtual void SetDigitalAudioDevice(bool On);
575 public:
576  bool IsMute(void) const { return mute; }
577  bool ToggleMute(void);
579  int GetAudioChannel(void);
582  void SetAudioChannel(int AudioChannel);
585  void SetVolume(int Volume, bool Absolute = false);
588  static int CurrentVolume(void) { return primaryDevice ? primaryDevice->volume : 0; }//XXX???
589 
590 // Player facilities
591 
592 private:
599 protected:
600  virtual bool CanReplay(void) const;
602  virtual bool SetPlayMode(ePlayMode PlayMode);
605  virtual int PlayVideo(const uchar *Data, int Length);
612  virtual int PlayAudio(const uchar *Data, int Length, uchar Id);
620  virtual int PlaySubtitle(const uchar *Data, int Length);
627  virtual int PlayPesPacket(const uchar *Data, int Length, bool VideoOnly = false);
632  virtual int PlayTsVideo(const uchar *Data, int Length);
640  virtual int PlayTsAudio(const uchar *Data, int Length);
648  virtual int PlayTsSubtitle(const uchar *Data, int Length);
656 public:
657  virtual int64_t GetSTC(void);
668  virtual bool IsPlayingVideo(void) const { return isPlayingVideo; }
671  virtual cRect CanScaleVideo(const cRect &Rect, int Alignment = taCenter) { return cRect::Null; }
692  virtual void ScaleVideo(const cRect &Rect = cRect::Null) {}
700  virtual bool HasIBPTrickSpeed(void) { return false; }
703  virtual void TrickSpeed(int Speed, bool Forward);
714  virtual void Clear(void);
718  virtual void Play(void);
721  virtual void Freeze(void);
723  virtual void Mute(void);
727  virtual void StillPicture(const uchar *Data, int Length);
733  virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
738  virtual bool Flush(int TimeoutMs = 0);
744  virtual int PlayPes(const uchar *Data, int Length, bool VideoOnly = false);
754  virtual int PlayTs(const uchar *Data, int Length, bool VideoOnly = false);
770  bool Replaying(void) const;
772  bool Transferring(void) const;
774  void StopReplay(void);
776  bool AttachPlayer(cPlayer *Player);
778  void Detach(cPlayer *Player);
780 
781 // Receiver facilities
782 
783 private:
786 public:
787  int Priority(void) const;
790 protected:
791  virtual bool OpenDvr(void);
794  virtual void CloseDvr(void);
796  virtual bool GetTSPacket(uchar *&Data);
803 public:
804  bool Receiving(bool Dummy = false) const;
806  bool AttachReceiver(cReceiver *Receiver);
808  void Detach(cReceiver *Receiver);
810  void DetachAll(int Pid);
812  virtual void DetachAllReceivers(void);
814 
815 // --- dynamite subdevice patch start ---
816  friend class cDynamicDevice;
817 private:
821  bool isIdle;
822 protected:
825  cDevice(cDevice *ParentDevice = NULL);
826  const cPatPmtParser *PatPmtParser(void) const { if (parentDevice) return parentDevice->PatPmtParser(); return &patPmtParser; }
829 public:
830  bool IsPrimaryDevice(void) const { if (parentDevice) return parentDevice->IsPrimaryDevice(); return this == primaryDevice && HasDecoder(); }
831  int CardIndex(void) const { if (parentDevice) return parentDevice->cardIndex; return cardIndex; }
833  cCamSlot *CamSlot(void) const { if (parentDevice) return parentDevice->CamSlot(); return camSlot; }
836  bool IsSubDevice(void) const { return (parentDevice != NULL); }
837  bool HasSubDevice(void) const { return (subDevice != NULL); }
838  cDevice *SubDevice(void) const { return subDevice; }
839  bool IsIdle(void) const { if (parentDevice) return parentDevice->IsIdle(); return isIdle; }
840  bool SetIdle(bool Idle);
841  virtual bool SetIdleDevice(bool Idle, bool TestOnly) { return false; }
845  // --- dynamite subdevice patch end ---
846  };
847 
855 
856 class cTSBuffer : public cThread {
857 private:
858  int f;
860  bool delivered;
862  virtual void Action(void);
863 public:
864  cTSBuffer(int File, int Size, int CardIndex);
865  virtual ~cTSBuffer();
866  uchar *Get(int *Available = NULL);
873  void Skip(int Count);
880  };
881 
889 
890 #define __DYNAMIC_DEVICE_PROBE
891 
893 
895  friend class cDynamicDevice;
896 private:
898  public:
901  cDynamicDeviceProbeItem(eDynamicDeviceProbeCommand Cmd, cString *DevPath):cmd(Cmd),devpath(DevPath) {}
902  virtual ~cDynamicDeviceProbeItem() { if (devpath) delete devpath; }
903  };
908 public:
909  static void QueueDynamicDeviceCommand(eDynamicDeviceProbeCommand Cmd, const char *DevPath);
913  cDynamicDeviceProbe(void);
914  virtual ~cDynamicDeviceProbe();
915  virtual cDevice *Attach(cDevice *ParentDevice, const char *DevPath) = 0;
921  };
922 
924 
925 #endif //__DEVICE_H
cEitFilter * eitFilter
Definition: device.h:384
static int nextCardIndex
Definition: device.h:174
cPatPmtParser patPmtParser
Definition: device.h:594
virtual eVideoSystem GetVideoSystem(void)
Returns the video system of the currently displayed material (default is PAL).
Definition: device.h:469
int cardIndex
Definition: device.h:859
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
int Number(void) const
Definition: channels.h:179
cNitFilter * nitFilter
Definition: device.h:387
Definition: device.h:71
cPlayer * player
Definition: device.h:593
eSetChannelResult
Definition: device.h:36
int Index(void) const
Definition: tools.c:1989
cSdtFilter * sdtFilter
Definition: device.h:386
cRingBufferLinear * ringBuffer
Definition: device.h:861
Definition: eit.h:15
static cList< cDynamicDeviceProbeItem > commandQueue
A list where all attach/detach commands are queued so they can be processed in the MainThreadHook of ...
Definition: device.h:904
bool isIdle
Definition: device.h:821
char description[32]
Definition: device.h:90
int f
Definition: device.h:858
Definition: sdt.h:16
Definition: nit.h:19
bool mute
Definition: device.h:561
#define MAXDEVICES
Definition: device.h:29
int cardIndex
Definition: device.h:175
static int currentChannel
Definition: device.h:242
int volume
Definition: device.h:562
cList< cDynamicDeviceProbe > DynamicDeviceProbes
Definition: device.c:1893
bool autoSelectPreferredSubtitleLanguage
Definition: device.h:502
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:539
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:700
cDynamicDeviceProbeItem(eDynamicDeviceProbeCommand Cmd, cString *DevPath)
Definition: device.h:901
cTsToPes tsToPesSubtitle
Definition: device.h:597
eTrackType currentSubtitleTrack
Definition: device.h:498
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:671
Definition: filter.h:41
Definition: osd.h:158
static int CurrentVolume(void)
Definition: device.h:588
bool IsPrimaryDevice(void) const
Definition: device.h:830
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:833
int pre_1_3_19_PrivateStream
Definition: device.h:504
cPatFilter * patFilter
Definition: device.h:385
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:319
bool isPlayingVideo
Definition: device.h:598
time_t startScrambleDetection
Definition: device.h:419
cMutex mutexCurrentSubtitleTrack
Definition: device.h:500
Definition: osd.h:352
virtual bool IsPlayingVideo(void) const
Returns true if the currently attached player has delivered any video packets.
Definition: device.h:668
cTsToPes tsToPesVideo
Definition: device.h:595
cTsToPes tsToPesAudio
Definition: device.h:596
virtual bool SetIdleDevice(bool Idle, bool TestOnly)
Called by SetIdle if TestOnly, don&#39;t do anything, just return, if the device can be set to the new id...
Definition: device.h:841
cCamSlot * camSlot
Definition: device.h:420
eVideoDisplayFormat
Definition: device.h:65
bool delivered
Definition: device.h:860
bool HasSubDevice(void) const
Definition: device.h:837
Definition: ci.h:131
static cDevice * primaryDevice
Definition: device.h:116
static int numDevices
Definition: device.h:113
cSectionHandler * sectionHandler
Definition: device.h:383
ePlayMode
Definition: device.h:39
eTrackType currentAudioTrack
Definition: device.h:497
Definition: thread.h:63
static const cRect Null
Definition: osd.h:357
cDevice * parentDevice
Definition: device.h:823
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:692
static cDevice * nextParentDevice
Holds the parent device for the next subdevice so the dynamite-plugin can work with unpatched plugins...
Definition: device.h:818
#define MAXLANGCODE2
Definition: channels.h:41
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:216
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:826
int CardIndex(void) const
Returns the card index of this device (0 ... MAXDEVICES - 1).
Definition: device.h:831
cDevice * subDevice
Definition: device.h:824
Definition: device.h:74
cMutex mutexReceiver
Definition: device.h:784
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:230
bool IsSubDevice(void) const
Definition: device.h:836
unsigned char u_char
Definition: headers.h:24
static cList< cDeviceHook > deviceHooks
Definition: device.h:223
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:321
int currentAudioTrackMissingCount
Definition: device.h:501
Definition: thread.h:77
time_t occupiedTimeout
Definition: device.h:240
cMutex mutexCurrentAudioTrack
Definition: device.h:499
void SetKeepTracks(bool KeepTracks)
Controls whether the current audio and subtitle track settings shall be kept as they currently are...
Definition: device.h:553
eDynamicDeviceProbeCommand cmd
Definition: device.h:899
char language[MAXLANGCODE2]
Definition: device.h:89
Definition: device.h:36
eDynamicDeviceProbeCommand
Definition: device.h:892
cDevice * SubDevice(void) const
Definition: device.h:838
#define MAXPIDHANDLES
Definition: device.h:30
bool IsIdle(void) const
Definition: device.h:839
#define MAXRECEIVERS
Definition: device.h:31
ePidType
Definition: device.h:352
bool keepTracks
Definition: device.h:503
Definition: tools.h:357
Derived cDevice classes that can receive channels will have to provide Transport Stream (TS) packets ...
Definition: device.h:856
Definition: device.h:61
cDvbSubtitleConverter * dvbSubtitleConverter
Definition: device.h:231
eTrackType GetCurrentAudioTrack(void) const
Definition: device.h:535
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:424
Definition: tools.h:168
bool IsMute(void) const
Definition: device.h:576
uint16_t id
Definition: device.h:88