vdr  1.7.27
device.h
Go to the documentation of this file.
00001 /*
00002  * device.h: The basic device interface
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: device.h 2.38 2012/03/13 10:17:16 kls Exp $
00008  */
00009 
00010 #ifndef __DEVICE_H
00011 #define __DEVICE_H
00012 
00013 #include "channels.h"
00014 #include "ci.h"
00015 #include "dvbsubtitle.h"
00016 #include "eit.h"
00017 #include "filter.h"
00018 #include "nit.h"
00019 #include "pat.h"
00020 #include "remux.h"
00021 #include "ringbuffer.h"
00022 #include "sdt.h"
00023 #include "sections.h"
00024 #include "spu.h"
00025 #include "thread.h"
00026 #include "tools.h"
00027 
00028 #define MAXDEVICES         16 // the maximum number of devices in the system
00029 #define MAXPIDHANDLES      64 // the maximum number of different PIDs per device
00030 #define MAXRECEIVERS       16 // the maximum number of receivers per device
00031 #define MAXVOLUME         255
00032 #define VOLUMEDELTA         5 // used to increase/decrease the volume
00033 #define MAXOCCUPIEDTIMEOUT 99 // max. time (in seconds) a device may be occupied
00034 
00035 enum eSetChannelResult { scrOk, scrNotAvailable, scrNoTransfer, scrFailed };
00036 
00037 enum ePlayMode { pmNone,           // audio/video from decoder
00038                  pmAudioVideo,     // audio/video from player
00039                  pmAudioOnly,      // audio only from player, video from decoder
00040                  pmAudioOnlyBlack, // audio only from player, no video (black screen)
00041                  pmVideoOnly,      // video only from player, audio from decoder
00042                  pmExtern_THIS_SHOULD_BE_AVOIDED
00043                  // external player (e.g. MPlayer), release the device
00044                  // WARNING: USE THIS MODE ONLY AS A LAST RESORT, IF YOU
00045                  // ABSOLUTELY, POSITIVELY CAN'T IMPLEMENT YOUR PLAYER
00046                  // THE WAY IT IS SUPPOSED TO WORK. FORCING THE DEVICE
00047                  // TO RELEASE ITS FILES HANDLES (OR WHATEVER RESOURCES
00048                  // IT MAY USE) TO ALLOW AN EXTERNAL PLAYER TO ACCESS
00049                  // THEM MEANS THAT SUCH A PLAYER WILL NEED TO HAVE
00050                  // DETAILED KNOWLEDGE ABOUT THE INTERNALS OF THE DEVICE
00051                  // IN USE. AS A CONSEQUENCE, YOUR PLAYER MAY NOT WORK
00052                  // IF A PARTICULAR VDR INSTALLATION USES A DEVICE NOT
00053                  // KNOWN TO YOUR PLAYER.
00054                };
00055 
00056 enum eVideoSystem { vsPAL,
00057                     vsNTSC
00058                   };
00059 
00060 enum eVideoDisplayFormat { vdfPanAndScan,
00061                            vdfLetterBox,
00062                            vdfCenterCutOut
00063                          };
00064 
00065 enum eTrackType { ttNone,
00066                   ttAudio,
00067                   ttAudioFirst = ttAudio,
00068                   ttAudioLast  = ttAudioFirst + 31, // MAXAPIDS - 1
00069                   ttDolby,
00070                   ttDolbyFirst = ttDolby,
00071                   ttDolbyLast  = ttDolbyFirst + 15, // MAXDPIDS - 1
00072                   ttSubtitle,
00073                   ttSubtitleFirst = ttSubtitle,
00074                   ttSubtitleLast  = ttSubtitleFirst + 31, // MAXSPIDS - 1
00075                   ttMaxTrackTypes
00076                 };
00077 
00078 #define IS_AUDIO_TRACK(t) (ttAudioFirst <= (t) && (t) <= ttAudioLast)
00079 #define IS_DOLBY_TRACK(t) (ttDolbyFirst <= (t) && (t) <= ttDolbyLast)
00080 #define IS_SUBTITLE_TRACK(t) (ttSubtitleFirst <= (t) && (t) <= ttSubtitleLast)
00081 
00082 struct tTrackId {
00083   uint16_t id;                  // The PES packet id or the PID.
00084   char language[MAXLANGCODE2];  // something like either "eng" or "deu+eng"
00085   char description[32];         // something like "Dolby Digital 5.1"
00086   };
00087 
00088 class cPlayer;
00089 class cReceiver;
00090 class cLiveSubtitle;
00091 
00092 class cDeviceHook : public cListObject {
00093 public:
00094   cDeviceHook(void);
00098   virtual bool DeviceProvidesTransponder(const cDevice *Device, const cChannel *Channel) const;
00100   };
00101 
00103 
00104 class cDevice : public cThread {
00105   friend class cLiveSubtitle;
00106   friend class cDeviceHook;
00107 private:
00108   static int numDevices;
00109   static int useDevice;
00110   static cDevice *device[MAXDEVICES];
00111   static cDevice *primaryDevice;
00112 public:
00113   static int NumDevices(void) { return numDevices; }
00115   static bool WaitForAllDevicesReady(int Timeout = 0);
00121   static void SetUseDevice(int n);
00125   static bool UseDevice(int n) { return useDevice == 0 || (useDevice & (1 << n)) != 0; }
00128   static bool SetPrimaryDevice(int n);
00132   static cDevice *PrimaryDevice(void) { return primaryDevice; }
00134   static cDevice *ActualDevice(void);
00137   static cDevice *GetDevice(int Index);
00141   static cDevice *GetDevice(const cChannel *Channel, int Priority, bool LiveView, bool Query = false);
00160   static cDevice *GetDeviceForTransponder(const cChannel *Channel, int Priority);
00165   static void Shutdown(void);
00168 private:
00169   static int nextCardIndex;
00170   int cardIndex;
00171 protected:
00172   cDevice(void);
00173   virtual ~cDevice();
00174   virtual bool Ready(void);
00179   static int NextCardIndex(int n = 0);
00191   virtual void MakePrimaryDevice(bool On);
00198 public:
00199   bool IsPrimaryDevice(void) const { return this == primaryDevice; }
00200   int CardIndex(void) const { return cardIndex; }
00202   int DeviceNumber(void) const;
00204   virtual cString DeviceName(void) const;
00207   virtual bool HasDecoder(void) const;
00209   virtual bool AvoidRecording(void) const { return false; }
00212 
00213 // Device hooks
00214 
00215 private:
00216   static cList<cDeviceHook> deviceHooks;
00217 protected:
00218   bool DeviceHooksProvidesTransponder(const cChannel *Channel) const;
00219 
00220 // SPU facilities
00221 
00222 private:
00223   cLiveSubtitle *liveSubtitle;
00224   cDvbSubtitleConverter *dvbSubtitleConverter;
00225 public:
00226   virtual cSpuDecoder *GetSpuDecoder(void);
00229 
00230 // Channel facilities
00231 
00232 private:
00233   time_t occupiedTimeout;
00234 protected:
00235   static int currentChannel;
00236 public:
00237   virtual bool ProvidesSource(int Source) const;
00239   virtual bool ProvidesTransponder(const cChannel *Channel) const;
00243   virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const;
00246   virtual bool ProvidesChannel(const cChannel *Channel, int Priority = IDLEPRIORITY, bool *NeedsDetachReceivers = NULL) const;
00260   virtual bool ProvidesEIT(void) const;
00264   virtual int NumProvidedSystems(void) const;
00270   virtual int SignalStrength(void) const;
00275   virtual int SignalQuality(void) const;
00280   virtual const cChannel *GetCurrentlyTunedTransponder(void) const;
00285   virtual bool IsTunedToTransponder(const cChannel *Channel) const;
00288   virtual bool MaySwitchTransponder(const cChannel *Channel) const;
00293   bool SwitchChannel(const cChannel *Channel, bool LiveView);
00296   static bool SwitchChannel(int Direction);
00300 private:
00301   eSetChannelResult SetChannel(const cChannel *Channel, bool LiveView);
00303 protected:
00304   virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
00306 public:
00307   static int CurrentChannel(void) { return primaryDevice ? currentChannel : 0; }
00309   static void SetCurrentChannel(const cChannel *Channel) { currentChannel = Channel ? Channel->Number() : 0; }
00313   void ForceTransferMode(void);
00315   int Occupied(void) const;
00317   void SetOccupied(int Seconds);
00325   virtual bool HasLock(int TimeoutMs = 0);
00331   virtual bool HasProgramme(void);
00334 
00335 // PID handle facilities
00336 
00337 private:
00338   virtual void Action(void);
00339 protected:
00340   enum ePidType { ptAudio, ptVideo, ptPcr, ptTeletext, ptDolby, ptOther };
00341   class cPidHandle {
00342   public:
00343     int pid;
00344     int streamType;
00345     int handle;
00346     int used;
00347     cPidHandle(void) { pid = streamType = used = 0; handle = -1; }
00348     };
00349   cPidHandle pidHandles[MAXPIDHANDLES];
00350   bool HasPid(int Pid) const;
00352   bool AddPid(int Pid, ePidType PidType = ptOther, int StreamType = 0);
00354   void DelPid(int Pid, ePidType PidType = ptOther);
00356   virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
00364 public:
00365   void DelLivePids(void);
00367 
00368 // Section filter facilities
00369 
00370 private:
00371   cSectionHandler *sectionHandler;
00372   cEitFilter *eitFilter;
00373   cPatFilter *patFilter;
00374   cSdtFilter *sdtFilter;
00375   cNitFilter *nitFilter;
00376 protected:
00377   void StartSectionHandler(void);
00381   void StopSectionHandler(void);
00385 public:
00386   virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask);
00390   virtual void CloseFilter(int Handle);
00395   void AttachFilter(cFilter *Filter);
00397   void Detach(cFilter *Filter);
00399 
00400 // Common Interface facilities:
00401 
00402 private:
00403   time_t startScrambleDetection;
00404   cCamSlot *camSlot;
00405 public:
00406   virtual bool HasCi(void);
00408   void SetCamSlot(cCamSlot *CamSlot);
00410   cCamSlot *CamSlot(void) const { return camSlot; }
00413 
00414 // Image Grab facilities
00415 
00416 public:
00417   virtual uchar *GrabImage(int &Size, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
00429   bool GrabImageFile(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
00434 
00435 // Video format facilities
00436 
00437 public:
00438   virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat);
00442   virtual void SetVideoFormat(bool VideoFormat16_9);
00445   virtual eVideoSystem GetVideoSystem(void);
00448   virtual void GetVideoSize(int &Width, int &Height, double &VideoAspect);
00455   virtual void GetOsdSize(int &Width, int &Height, double &PixelAspect);
00466 
00467 // Track facilities
00468 
00469 private:
00470   tTrackId availableTracks[ttMaxTrackTypes];
00471   eTrackType currentAudioTrack;
00472   eTrackType currentSubtitleTrack;
00473   cMutex mutexCurrentAudioTrack;
00474   cMutex mutexCurrentSubtitleTrack;
00475   int currentAudioTrackMissingCount;
00476   bool autoSelectPreferredSubtitleLanguage;
00477   int pre_1_3_19_PrivateStream;
00478 protected:
00479   virtual void SetAudioTrackDevice(eTrackType Type);
00481   virtual void SetSubtitleTrackDevice(eTrackType Type);
00483 public:
00484   void ClrAvailableTracks(bool DescriptionsOnly = false, bool IdsOnly = false);
00489   bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL);
00496   const tTrackId *GetTrack(eTrackType Type);
00499   int NumTracks(eTrackType FirstTrack, eTrackType LastTrack) const;
00502   int NumAudioTracks(void) const;
00506   int NumSubtitleTracks(void) const;
00508   eTrackType GetCurrentAudioTrack(void) const { return currentAudioTrack; }
00509   bool SetCurrentAudioTrack(eTrackType Type);
00512   eTrackType GetCurrentSubtitleTrack(void) const { return currentSubtitleTrack; }
00513   bool SetCurrentSubtitleTrack(eTrackType Type, bool Manual = false);
00519   void EnsureAudioTrack(bool Force = false);
00523   void EnsureSubtitleTrack(void);
00526 
00527 // Audio facilities
00528 
00529 private:
00530   bool mute;
00531   int volume;
00532 protected:
00533   virtual int GetAudioChannelDevice(void);
00536   virtual void SetAudioChannelDevice(int AudioChannel);
00538   virtual void SetVolumeDevice(int Volume);
00540   virtual void SetDigitalAudioDevice(bool On);
00543 public:
00544   bool IsMute(void) const { return mute; }
00545   bool ToggleMute(void);
00547   int GetAudioChannel(void);
00550   void SetAudioChannel(int AudioChannel);
00553   void SetVolume(int Volume, bool Absolute = false);
00556   static int CurrentVolume(void) { return primaryDevice ? primaryDevice->volume : 0; }//XXX???
00557 
00558 // Player facilities
00559 
00560 private:
00561   cPlayer *player;
00562   cPatPmtParser patPmtParser;
00563   cTsToPes tsToPesVideo;
00564   cTsToPes tsToPesAudio;
00565   cTsToPes tsToPesSubtitle;
00566   cTsToPes tsToPesTeletext;
00567   bool isPlayingVideo;
00568 protected:
00569   const cPatPmtParser *PatPmtParser(void) const { return &patPmtParser; }
00572   virtual bool CanReplay(void) const;
00574   virtual bool SetPlayMode(ePlayMode PlayMode);
00577   virtual int PlayVideo(const uchar *Data, int Length);
00584   virtual int PlayAudio(const uchar *Data, int Length, uchar Id);
00592   virtual int PlaySubtitle(const uchar *Data, int Length);
00599   virtual int PlayPesPacket(const uchar *Data, int Length, bool VideoOnly = false);
00604   virtual int PlayTsVideo(const uchar *Data, int Length);
00612   virtual int PlayTsAudio(const uchar *Data, int Length);
00620   virtual int PlayTsSubtitle(const uchar *Data, int Length);
00628 public:
00629   virtual int64_t GetSTC(void);
00640   virtual bool IsPlayingVideo(void) const { return isPlayingVideo; }
00643   virtual bool HasIBPTrickSpeed(void) { return false; }
00646   virtual void TrickSpeed(int Speed);
00656   virtual void Clear(void);
00660   virtual void Play(void);
00663   virtual void Freeze(void);
00665   virtual void Mute(void);
00669   virtual void StillPicture(const uchar *Data, int Length);
00675   virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
00680   virtual bool Flush(int TimeoutMs = 0);
00686   virtual int PlayPes(const uchar *Data, int Length, bool VideoOnly = false);
00696   virtual int PlayTs(const uchar *Data, int Length, bool VideoOnly = false);
00712   bool Replaying(void) const;
00714   bool Transferring(void) const;
00716   void StopReplay(void);
00718   bool AttachPlayer(cPlayer *Player);
00720   void Detach(cPlayer *Player);
00722 
00723 // Receiver facilities
00724 
00725 private:
00726   mutable cMutex mutexReceiver;
00727   cReceiver *receiver[MAXRECEIVERS];
00728 public:
00729   int Priority(void) const;
00732 protected:
00733   virtual bool OpenDvr(void);
00736   virtual void CloseDvr(void);
00738   virtual bool GetTSPacket(uchar *&Data);
00745 public:
00746   bool Receiving(bool Dummy = false) const;
00748   bool AttachReceiver(cReceiver *Receiver);
00750   void Detach(cReceiver *Receiver);
00752   void DetachAll(int Pid);
00754   virtual void DetachAllReceivers(void);
00756   };
00757 
00765 
00766 class cTSBuffer : public cThread {
00767 private:
00768   int f;
00769   int cardIndex;
00770   bool delivered;
00771   cRingBufferLinear *ringBuffer;
00772   virtual void Action(void);
00773 public:
00774   cTSBuffer(int File, int Size, int CardIndex);
00775   ~cTSBuffer();
00776   uchar *Get(void);
00777   };
00778 
00779 #endif //__DEVICE_H