|
SASC-NG
DVBSoftCAM
|
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 1.81 2007/01/13 11:33:57 kls Exp $ 00008 */ 00009 00010 #ifndef __DEVICE_H 00011 #define __DEVICE_H 00012 00013 #include "channels.h" 00014 #include "ci.h" 00015 #include "eit.h" 00016 #include "filter.h" 00017 #include "nit.h" 00018 #include "pat.h" 00019 //#include "ringbuffer.h" 00020 #include "sdt.h" 00021 #include "sections.h" 00022 #include "spu.h" 00023 #include "thread.h" 00024 #include "tools.h" 00025 00026 #define MAXDEVICES 16 // the maximum number of devices in the system 00027 #define MAXPIDHANDLES 64 // the maximum number of different PIDs per device 00028 #define MAXRECEIVERS 16 // the maximum number of receivers per device 00029 #define MAXVOLUME 255 00030 #define VOLUMEDELTA 5 // used to increase/decrease the volume 00031 00032 #define TS_SIZE 188 00033 #define TS_SYNC_BYTE 0x47 00034 #define PID_MASK_HI 0x1F 00035 00036 enum eSetChannelResult { scrOk, scrNotAvailable, scrNoTransfer, scrFailed }; 00037 00038 enum ePlayMode { pmNone, // audio/video from decoder 00039 pmAudioVideo, // audio/video from player 00040 pmAudioOnly, // audio only from player, video from decoder 00041 pmAudioOnlyBlack, // audio only from player, no video (black screen) 00042 pmVideoOnly, // video only from player, audio from decoder 00043 pmExtern_THIS_SHOULD_BE_AVOIDED 00044 // external player (e.g. MPlayer), release the device 00045 // WARNING: USE THIS MODE ONLY AS A LAST RESORT, IF YOU 00046 // ABSOLUTELY, POSITIVELY CAN'T IMPLEMENT YOUR PLAYER 00047 // THE WAY IT IS SUPPOSED TO WORK. FORCING THE DEVICE 00048 // TO RELEASE ITS FILES HANDLES (OR WHATEVER RESOURCES 00049 // IT MAY USE) TO ALLOW AN EXTERNAL PLAYER TO ACCESS 00050 // THEM MEANS THAT SUCH A PLAYER WILL NEED TO HAVE 00051 // DETAILED KNOWLEDGE ABOUT THE INTERNALS OF THE DEVICE 00052 // IN USE. AS A CONSEQUENCE, YOUR PLAYER MAY NOT WORK 00053 // IF A PARTICULAR VDR INSTALLATION USES A DEVICE NOT 00054 // KNOWN TO YOUR PLAYER. 00055 }; 00056 00057 enum eVideoSystem { vsPAL, 00058 vsNTSC 00059 }; 00060 00061 enum eVideoDisplayFormat { vdfPanAndScan, 00062 vdfLetterBox, 00063 vdfCenterCutOut 00064 }; 00065 00066 enum eTrackType { ttNone, 00067 ttAudio, 00068 ttAudioFirst = ttAudio, 00069 ttAudioLast = ttAudioFirst + 31, // MAXAPIDS - 1 00070 ttDolby, 00071 ttDolbyFirst = ttDolby, 00072 ttDolbyLast = ttDolbyFirst + 15, // MAXDPIDS - 1 00073 /* future... 00074 ttSubtitle, 00075 ttSubtitleFirst = ttSubtitle, 00076 ttSubtitleLast = ttSubtitleFirst + 7, // MAXSPIDS - 1 00077 */ 00078 ttMaxTrackTypes 00079 }; 00080 00081 #define IS_AUDIO_TRACK(t) (ttAudioFirst <= (t) && (t) <= ttAudioLast) 00082 #define IS_DOLBY_TRACK(t) (ttDolbyFirst <= (t) && (t) <= ttDolbyLast) 00083 00084 struct tTrackId { 00085 uint16_t id; // The PES packet id or the PID. 00086 char language[MAXLANGCODE2]; // something like either "eng" or "deu+eng" 00087 char description[32]; // something like "Dolby Digital 5.1" 00088 }; 00089 00090 class cPlayer; 00091 class cReceiver; 00092 class cPesAssembler; 00093 00095 00096 class cDevice : public cThread { 00097 private: 00098 static int numDevices; 00099 static int useDevice; 00100 static cDevice *device[MAXDEVICES]; 00101 static cDevice *primaryDevice; 00102 public: 00103 static int NumDevices(void) { return numDevices; } 00105 static bool WaitForAllDevicesReady(int Timeout = 0); 00111 static void SetUseDevice(int n); 00115 static bool UseDevice(int n) { return useDevice == 0 || (useDevice & (1 << n)) != 0; } 00118 static bool SetPrimaryDevice(int n); 00122 static cDevice *PrimaryDevice(void) { return primaryDevice; } 00124 static cDevice *ActualDevice(void); 00127 static cDevice *GetDevice(int Index); 00131 static cDevice *GetDevice(const cChannel *Channel, int Priority, bool LiveView); 00146 static void Shutdown(void); 00149 private: 00150 static int nextCardIndex; 00151 protected: 00152 int cardIndex; 00153 cDevice(void); 00154 virtual ~cDevice(); 00155 virtual bool Ready(void); 00160 static int NextCardIndex(int n = 0); 00172 virtual void MakePrimaryDevice(bool On); 00177 public: 00178 bool IsPrimaryDevice(void) const { return this == primaryDevice; } 00179 int CardIndex(void) const { return cardIndex; } 00181 int DeviceNumber(void) const; 00183 virtual bool HasDecoder(void) const; 00185 00186 // SPU facilities 00187 00188 public: 00189 virtual cSpuDecoder *GetSpuDecoder(void); 00192 00193 // Channel facilities 00194 00195 protected: 00196 static int currentChannel; 00197 public: 00198 virtual bool ProvidesSource(int Source) const; 00200 virtual bool ProvidesTransponder(const cChannel *Channel) const; 00204 virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const; 00207 virtual bool ProvidesChannel(const cChannel *Channel, int Priority = -1, bool *NeedsDetachReceivers = NULL) const; 00222 virtual bool IsTunedToTransponder(const cChannel *Channel); 00225 virtual bool MaySwitchTransponder(void); 00228 bool SwitchChannel(const cChannel *Channel, bool LiveView); 00231 static bool SwitchChannel(int Direction); 00235 private: 00236 eSetChannelResult SetChannel(const cChannel *Channel, bool LiveView); 00238 protected: 00239 virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView); 00241 public: 00242 static int CurrentChannel(void) { return primaryDevice ? currentChannel : 0; } 00244 static void SetCurrentChannel(const cChannel *Channel) { currentChannel = Channel ? Channel->Number() : 0; } 00248 void ForceTransferMode(void); 00250 virtual bool HasLock(int TimeoutMs = 0); 00256 virtual bool HasProgramme(void); 00259 00260 // PID handle facilities 00261 00262 private: 00263 virtual void Action(void); 00264 public: 00265 enum ePidType { ptAudio, ptVideo, ptPcr, ptTeletext, ptDolby, ptOther }; 00266 protected: 00267 class cPidHandle { 00268 public: 00269 int pid; 00270 int handle; 00271 int used; 00272 cPidHandle(void) { pid = used = 0; handle = -1; } 00273 }; 00274 cPidHandle pidHandles[MAXPIDHANDLES]; 00275 bool HasPid(int Pid) const; 00277 public: 00278 bool AddPid(int Pid, ePidType PidType = ptOther); 00280 protected: 00281 void DelPid(int Pid, ePidType PidType = ptOther); 00283 virtual bool SetPid(cPidHandle *Handle, int Type, bool On); 00291 00292 // Section filter facilities 00293 00294 private: 00295 cSectionHandler *sectionHandler; 00296 cEitFilter *eitFilter; 00297 cPatFilter *patFilter; 00298 cSdtFilter *sdtFilter; 00299 cNitFilter *nitFilter; 00300 protected: 00301 void StartSectionHandler(void); 00304 public: 00305 virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask); 00309 virtual void CloseFilter(int Handle); 00314 void AttachFilter(cFilter *Filter); 00316 void Detach(cFilter *Filter); 00318 00319 // Common Interface facilities: 00320 00321 private: 00322 time_t startScrambleDetection; 00323 cCamSlot *camSlot; 00324 public: 00325 virtual bool HasCi(void); 00327 void SetCamSlot(cCamSlot *CamSlot); 00329 cCamSlot *CamSlot(void) const { return camSlot; } 00332 00333 // Image Grab facilities 00334 00335 public: 00336 virtual uchar *GrabImage(int &Size, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1); 00348 bool GrabImageFile(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1); 00353 00354 // Video format facilities 00355 00356 public: 00357 virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat); 00361 virtual void SetVideoFormat(bool VideoFormat16_9); 00364 virtual eVideoSystem GetVideoSystem(void); 00367 00368 // Track facilities 00369 00370 private: 00371 tTrackId availableTracks[ttMaxTrackTypes]; 00372 eTrackType currentAudioTrack; 00373 cMutex mutexCurrentAudioTrack; 00374 int currentAudioTrackMissingCount; 00375 bool pre_1_3_19_PrivateStream; 00376 protected: 00377 virtual void SetAudioTrackDevice(eTrackType Type); 00379 public: 00380 void ClrAvailableTracks(bool DescriptionsOnly = false, bool IdsOnly = false); 00385 bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL); 00392 const tTrackId *GetTrack(eTrackType Type); 00395 int NumAudioTracks(void) const; 00399 eTrackType GetCurrentAudioTrack(void) { return currentAudioTrack; } 00400 bool SetCurrentAudioTrack(eTrackType Type); 00403 void EnsureAudioTrack(bool Force = false); 00407 00408 // Audio facilities 00409 00410 private: 00411 bool mute; 00412 int volume; 00413 protected: 00414 virtual int GetAudioChannelDevice(void); 00417 virtual void SetAudioChannelDevice(int AudioChannel); 00419 virtual void SetVolumeDevice(int Volume); 00421 virtual void SetDigitalAudioDevice(bool On); 00424 public: 00425 bool IsMute(void) const { return mute; } 00426 bool ToggleMute(void); 00428 int GetAudioChannel(void); 00431 void SetAudioChannel(int AudioChannel); 00434 void SetVolume(int Volume, bool Absolute = false); 00437 static int CurrentVolume(void) { return primaryDevice ? primaryDevice->volume : 0; }//XXX??? 00438 00439 // Player facilities 00440 00441 private: 00442 cPlayer *player; 00443 cPesAssembler *pesAssembler; 00444 protected: 00445 virtual bool CanReplay(void) const; 00447 virtual bool SetPlayMode(ePlayMode PlayMode); 00450 virtual int PlayVideo(const uchar *Data, int Length); 00457 virtual int PlayAudio(const uchar *Data, int Length, uchar Id); 00465 virtual int PlayPesPacket(const uchar *Data, int Length, bool VideoOnly = false); 00470 public: 00471 virtual int64_t GetSTC(void); 00475 virtual void TrickSpeed(int Speed); 00479 virtual void Clear(void); 00483 virtual void Play(void); 00486 virtual void Freeze(void); 00488 virtual void Mute(void); 00492 virtual void StillPicture(const uchar *Data, int Length); 00494 virtual bool Poll(cPoller &Poller, int TimeoutMs = 0); 00499 virtual bool Flush(int TimeoutMs = 0); 00505 virtual int PlayPes(const uchar *Data, int Length, bool VideoOnly = false); 00515 bool Replaying(void) const; 00517 bool Transferring(void) const; 00519 void StopReplay(void); 00521 bool AttachPlayer(cPlayer *Player); 00523 void Detach(cPlayer *Player); 00525 00526 // Receiver facilities 00527 00528 private: 00529 cMutex mutexReceiver; 00530 cReceiver *receiver[MAXRECEIVERS]; 00531 public: 00532 int Priority(void) const; 00536 protected: 00537 virtual bool OpenDvr(void); 00540 virtual void CloseDvr(void); 00542 virtual bool GetTSPacket(uchar *&Data); 00549 public: 00550 bool Receiving(bool CheckAny = false) const; 00552 bool AttachReceiver(cReceiver *Receiver); 00554 void Detach(cReceiver *Receiver); 00556 void DetachAll(int Pid); 00558 void DetachAllReceivers(void); 00560 }; 00561 00569 00570 class cTSBuffer : public cThread { 00571 private: 00572 int f; 00573 int cardIndex; 00574 bool delivered; 00575 //cRingBufferLinear *ringBuffer; 00576 virtual void Action(void); 00577 public: 00578 cTSBuffer(int File, int Size, int CardIndex); 00579 ~cTSBuffer(); 00580 uchar *Get(void); 00581 }; 00582 00583 #endif //__DEVICE_H