vdr  1.7.31
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 2.41 2012/08/26 13:25:44 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 "remux.h"
21 #include "ringbuffer.h"
22 #include "sdt.h"
23 #include "sections.h"
24 #include "spu.h"
25 #include "thread.h"
26 #include "tools.h"
27 
28 #define MAXDEVICES 16 // the maximum number of devices in the system
29 #define MAXPIDHANDLES 64 // the maximum number of different PIDs per device
30 #define MAXRECEIVERS 16 // the maximum number of receivers per device
31 #define MAXVOLUME 255
32 #define VOLUMEDELTA 5 // used to increase/decrease the volume
33 #define MAXOCCUPIEDTIMEOUT 99 // max. time (in seconds) a device may be occupied
34 
36 
37 enum ePlayMode { pmNone, // audio/video from decoder
38  pmAudioVideo, // audio/video from player
39  pmAudioOnly, // audio only from player, video from decoder
40  pmAudioOnlyBlack, // audio only from player, no video (black screen)
41  pmVideoOnly, // video only from player, audio from decoder
43  // external player (e.g. MPlayer), release the device
44  // WARNING: USE THIS MODE ONLY AS A LAST RESORT, IF YOU
45  // ABSOLUTELY, POSITIVELY CAN'T IMPLEMENT YOUR PLAYER
46  // THE WAY IT IS SUPPOSED TO WORK. FORCING THE DEVICE
47  // TO RELEASE ITS FILES HANDLES (OR WHATEVER RESOURCES
48  // IT MAY USE) TO ALLOW AN EXTERNAL PLAYER TO ACCESS
49  // THEM MEANS THAT SUCH A PLAYER WILL NEED TO HAVE
50  // DETAILED KNOWLEDGE ABOUT THE INTERNALS OF THE DEVICE
51  // IN USE. AS A CONSEQUENCE, YOUR PLAYER MAY NOT WORK
52  // IF A PARTICULAR VDR INSTALLATION USES A DEVICE NOT
53  // KNOWN TO YOUR PLAYER.
54  };
55 
58  };
59 
63  };
64 
68  ttAudioLast = ttAudioFirst + 31, // MAXAPIDS - 1
71  ttDolbyLast = ttDolbyFirst + 15, // MAXDPIDS - 1
74  ttSubtitleLast = ttSubtitleFirst + 31, // MAXSPIDS - 1
76  };
77 
78 #define IS_AUDIO_TRACK(t) (ttAudioFirst <= (t) && (t) <= ttAudioLast)
79 #define IS_DOLBY_TRACK(t) (ttDolbyFirst <= (t) && (t) <= ttDolbyLast)
80 #define IS_SUBTITLE_TRACK(t) (ttSubtitleFirst <= (t) && (t) <= ttSubtitleLast)
81 
82 struct tTrackId {
83  uint16_t id; // The PES packet id or the PID.
84  char language[MAXLANGCODE2]; // something like either "eng" or "deu+eng"
85  char description[32]; // something like "Dolby Digital 5.1"
86  };
87 
88 class cPlayer;
89 class cReceiver;
90 class cLiveSubtitle;
91 
92 class cDeviceHook : public cListObject {
93 public:
94  cDeviceHook(void);
98  virtual bool DeviceProvidesTransponder(const cDevice *Device, const cChannel *Channel) const;
100  };
101 
103 
104 class cDevice : public cThread {
105  friend class cLiveSubtitle;
106  friend class cDeviceHook;
107 private:
108  static int numDevices;
109  static int useDevice;
112 public:
113  static int NumDevices(void) { return numDevices; }
115  static bool WaitForAllDevicesReady(int Timeout = 0);
121  static void SetUseDevice(int n);
125  static bool UseDevice(int n) { return useDevice == 0 || (useDevice & (1 << n)) != 0; }
128  static bool SetPrimaryDevice(int n);
132  static cDevice *PrimaryDevice(void) { return primaryDevice; }
134  static cDevice *ActualDevice(void);
137  static cDevice *GetDevice(int Index);
141  static cDevice *GetDevice(const cChannel *Channel, int Priority, bool LiveView, bool Query = false);
160  static cDevice *GetDeviceForTransponder(const cChannel *Channel, int Priority);
165  static void Shutdown(void);
168 private:
169  static int nextCardIndex;
171 protected:
172  cDevice(void);
173  virtual ~cDevice();
174  virtual bool Ready(void);
179  static int NextCardIndex(int n = 0);
191  virtual void MakePrimaryDevice(bool On);
198 public:
199  bool IsPrimaryDevice(void) const { return this == primaryDevice; }
200  int CardIndex(void) const { return cardIndex; }
202  int DeviceNumber(void) const;
204  virtual cString DeviceType(void) const;
210  virtual cString DeviceName(void) const;
213  virtual bool HasDecoder(void) const;
215  virtual bool AvoidRecording(void) const { return false; }
218 
219 // Device hooks
220 
221 private:
223 protected:
224  bool DeviceHooksProvidesTransponder(const cChannel *Channel) const;
225 
226 // SPU facilities
227 
228 private:
231 public:
232  virtual cSpuDecoder *GetSpuDecoder(void);
235 
236 // Channel facilities
237 
238 private:
240 protected:
241  static int currentChannel;
242 public:
243  virtual bool ProvidesSource(int Source) const;
245  virtual bool ProvidesTransponder(const cChannel *Channel) const;
249  virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const;
252  virtual bool ProvidesChannel(const cChannel *Channel, int Priority = IDLEPRIORITY, bool *NeedsDetachReceivers = NULL) const;
266  virtual bool ProvidesEIT(void) const;
270  virtual int NumProvidedSystems(void) const;
276  virtual int SignalStrength(void) const;
281  virtual int SignalQuality(void) const;
286  virtual const cChannel *GetCurrentlyTunedTransponder(void) const;
291  virtual bool IsTunedToTransponder(const cChannel *Channel) const;
294  virtual bool MaySwitchTransponder(const cChannel *Channel) const;
299  bool SwitchChannel(const cChannel *Channel, bool LiveView);
302  static bool SwitchChannel(int Direction);
306 private:
307  eSetChannelResult SetChannel(const cChannel *Channel, bool LiveView);
309 protected:
310  virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
312 public:
313  static int CurrentChannel(void) { return primaryDevice ? currentChannel : 0; }
315  static void SetCurrentChannel(const cChannel *Channel) { currentChannel = Channel ? Channel->Number() : 0; }
319  void ForceTransferMode(void);
321  int Occupied(void) const;
323  void SetOccupied(int Seconds);
331  virtual bool HasLock(int TimeoutMs = 0);
337  virtual bool HasProgramme(void);
340 
341 // PID handle facilities
342 
343 private:
344  virtual void Action(void);
345 protected:
347  class cPidHandle {
348  public:
349  int pid;
351  int handle;
352  int used;
353  cPidHandle(void) { pid = streamType = used = 0; handle = -1; }
354  };
356  bool HasPid(int Pid) const;
358  bool AddPid(int Pid, ePidType PidType = ptOther, int StreamType = 0);
360  void DelPid(int Pid, ePidType PidType = ptOther);
362  virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
370 public:
371  void DelLivePids(void);
373 
374 // Section filter facilities
375 
376 private:
382 protected:
383  void StartSectionHandler(void);
387  void StopSectionHandler(void);
391 public:
392  virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask);
396  virtual int ReadFilter(int Handle, void *Buffer, size_t Length);
400  virtual void CloseFilter(int Handle);
405  void AttachFilter(cFilter *Filter);
407  void Detach(cFilter *Filter);
409 
410 // Common Interface facilities:
411 
412 private:
415 public:
416  virtual bool HasCi(void);
418  virtual bool HasInternalCam(void) { return false; }
424  void SetCamSlot(cCamSlot *CamSlot);
426  cCamSlot *CamSlot(void) const { return camSlot; }
429 
430 // Image Grab facilities
431 
432 public:
433  virtual uchar *GrabImage(int &Size, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
445  bool GrabImageFile(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
450 
451 // Video format facilities
452 
453 public:
454  virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat);
458  virtual void SetVideoFormat(bool VideoFormat16_9);
461  virtual eVideoSystem GetVideoSystem(void);
464  virtual void GetVideoSize(int &Width, int &Height, double &VideoAspect);
471  virtual void GetOsdSize(int &Width, int &Height, double &PixelAspect);
482 
483 // Track facilities
484 
485 private:
494 protected:
495  virtual void SetAudioTrackDevice(eTrackType Type);
497  virtual void SetSubtitleTrackDevice(eTrackType Type);
499 public:
500  void ClrAvailableTracks(bool DescriptionsOnly = false, bool IdsOnly = false);
505  bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL);
512  const tTrackId *GetTrack(eTrackType Type);
515  int NumTracks(eTrackType FirstTrack, eTrackType LastTrack) const;
518  int NumAudioTracks(void) const;
522  int NumSubtitleTracks(void) const;
525  bool SetCurrentAudioTrack(eTrackType Type);
529  bool SetCurrentSubtitleTrack(eTrackType Type, bool Manual = false);
535  void EnsureAudioTrack(bool Force = false);
539  void EnsureSubtitleTrack(void);
542 
543 // Audio facilities
544 
545 private:
546  bool mute;
547  int volume;
548 protected:
549  virtual int GetAudioChannelDevice(void);
552  virtual void SetAudioChannelDevice(int AudioChannel);
554  virtual void SetVolumeDevice(int Volume);
556  virtual void SetDigitalAudioDevice(bool On);
559 public:
560  bool IsMute(void) const { return mute; }
561  bool ToggleMute(void);
563  int GetAudioChannel(void);
566  void SetAudioChannel(int AudioChannel);
569  void SetVolume(int Volume, bool Absolute = false);
572  static int CurrentVolume(void) { return primaryDevice ? primaryDevice->volume : 0; }//XXX???
573 
574 // Player facilities
575 
576 private:
584 protected:
585  const cPatPmtParser *PatPmtParser(void) const { return &patPmtParser; }
588  virtual bool CanReplay(void) const;
590  virtual bool SetPlayMode(ePlayMode PlayMode);
593  virtual int PlayVideo(const uchar *Data, int Length);
600  virtual int PlayAudio(const uchar *Data, int Length, uchar Id);
608  virtual int PlaySubtitle(const uchar *Data, int Length);
615  virtual int PlayPesPacket(const uchar *Data, int Length, bool VideoOnly = false);
620  virtual int PlayTsVideo(const uchar *Data, int Length);
628  virtual int PlayTsAudio(const uchar *Data, int Length);
636  virtual int PlayTsSubtitle(const uchar *Data, int Length);
644 public:
645  virtual int64_t GetSTC(void);
656  virtual bool IsPlayingVideo(void) const { return isPlayingVideo; }
659  virtual bool HasIBPTrickSpeed(void) { return false; }
662  virtual void TrickSpeed(int Speed);
672  virtual void Clear(void);
676  virtual void Play(void);
679  virtual void Freeze(void);
681  virtual void Mute(void);
685  virtual void StillPicture(const uchar *Data, int Length);
691  virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
696  virtual bool Flush(int TimeoutMs = 0);
702  virtual int PlayPes(const uchar *Data, int Length, bool VideoOnly = false);
712  virtual int PlayTs(const uchar *Data, int Length, bool VideoOnly = false);
728  bool Replaying(void) const;
730  bool Transferring(void) const;
732  void StopReplay(void);
734  bool AttachPlayer(cPlayer *Player);
736  void Detach(cPlayer *Player);
738 
739 // Receiver facilities
740 
741 private:
744 public:
745  int Priority(void) const;
748 protected:
749  virtual bool OpenDvr(void);
752  virtual void CloseDvr(void);
754  virtual bool GetTSPacket(uchar *&Data);
761 public:
762  bool Receiving(bool Dummy = false) const;
764  bool AttachReceiver(cReceiver *Receiver);
766  void Detach(cReceiver *Receiver);
768  void DetachAll(int Pid);
770  virtual void DetachAllReceivers(void);
772  };
773 
781 
782 class cTSBuffer : public cThread {
783 private:
784  int f;
786  bool delivered;
788  virtual void Action(void);
789 public:
790  cTSBuffer(int File, int Size, int CardIndex);
791  ~cTSBuffer();
792  uchar *Get(void);
793  };
794 
795 #endif //__DEVICE_H