vdr  1.7.27
channels.h
Go to the documentation of this file.
00001 /*
00002  * channels.h: Channel handling
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: channels.h 2.15 2012/03/11 11:46:39 kls Exp $
00008  */
00009 
00010 #ifndef __CHANNELS_H
00011 #define __CHANNELS_H
00012 
00013 #include "config.h"
00014 #include "sources.h"
00015 #include "thread.h"
00016 #include "tools.h"
00017 
00018 #define ISTRANSPONDER(f1, f2)  (abs((f1) - (f2)) < 4) //XXX
00019 
00020 #define CHANNELMOD_NONE     0x00
00021 #define CHANNELMOD_ALL      0xFF
00022 #define CHANNELMOD_NAME     0x01
00023 #define CHANNELMOD_PIDS     0x02
00024 #define CHANNELMOD_ID       0x04
00025 #define CHANNELMOD_CA       0x10
00026 #define CHANNELMOD_TRANSP   0x20
00027 #define CHANNELMOD_LANGS    0x40
00028 #define CHANNELMOD_RETUNE   (CHANNELMOD_PIDS | CHANNELMOD_CA | CHANNELMOD_TRANSP)
00029 
00030 #define CHANNELSMOD_NONE    0
00031 #define CHANNELSMOD_AUTO    1
00032 #define CHANNELSMOD_USER    2
00033 
00034 #define MAXAPIDS 32 // audio
00035 #define MAXDPIDS 16 // dolby (AC3 + DTS)
00036 #define MAXSPIDS 32 // subtitles
00037 #define MAXCAIDS 12 // conditional access
00038 #define MAXTXTPAGES 8 // teletext pages
00039 
00040 #define MAXLANGCODE1 4 // a 3 letter language code, zero terminated
00041 #define MAXLANGCODE2 8 // up to two 3 letter language codes, separated by '+' and zero terminated
00042 
00043 #define CA_FTA           0x0000
00044 #define CA_DVB_MIN       0x0001
00045 #define CA_DVB_MAX       0x000F
00046 #define CA_USER_MIN      0x0010
00047 #define CA_USER_MAX      0x00FF
00048 #define CA_ENCRYPTED_MIN 0x0100
00049 #define CA_ENCRYPTED_MAX 0xFFFF
00050 
00051 struct tChannelID {
00052 private:
00053   int source;
00054   int nid; 
00055   int tid;
00056   int sid;
00057   int rid;
00058 public:
00059   tChannelID(void) { source = nid = tid = sid = rid = 0; }
00060   tChannelID(int Source, int Nid, int Tid, int Sid, int Rid = 0) { source = Source; nid = Nid; tid = Tid; sid = Sid; rid = Rid; }
00061   bool operator== (const tChannelID &arg) const { return source == arg.source && nid == arg.nid && tid == arg.tid && sid == arg.sid && rid == arg.rid; }
00062   bool Valid(void) const { return (nid || tid) && sid; } // rid is optional and source may be 0//XXX source may not be 0???
00063   tChannelID &ClrRid(void) { rid = 0; return *this; }
00064   tChannelID &ClrPolarization(void);
00065   int Source(void)  const { return source; }
00066   int Nid(void)  const { return nid; }
00067   int Tid(void)  const { return tid; }
00068   int Sid(void)  const { return sid; }
00069   int Rid(void)  const { return rid; }
00070   static tChannelID FromString(const char *s);
00071   cString ToString(void) const;
00072   static const tChannelID InvalidID;
00073   };
00074 
00075 struct tTeletextSubtitlePage {
00076   tTeletextSubtitlePage(void) { ttxtPage = ttxtMagazine = 0; ttxtType = 0x02; strcpy(ttxtLanguage, "und"); }
00077   tTeletextSubtitlePage(int page) { ttxtMagazine = (page / 100) & 0x7; ttxtPage = (((page % 100) / 10) << 4) + (page % 10); ttxtType = 0x02; strcpy(ttxtLanguage, "und"); }
00078   char ttxtLanguage[MAXLANGCODE1];
00079   uchar ttxtPage;
00080   uchar ttxtMagazine;
00081   uchar ttxtType;
00082   int PageNumber(void) const { return BCDCHARTOINT(ttxtMagazine) * 100 + BCDCHARTOINT(ttxtPage); }
00083   };
00084 
00085 class cChannel;
00086 
00087 class cLinkChannel : public cListObject {
00088 private:
00089   cChannel *channel;
00090 public:
00091   cLinkChannel(cChannel *Channel) { channel = Channel; }
00092   cChannel *Channel(void) { return channel; }
00093   };
00094 
00095 class cLinkChannels : public cList<cLinkChannel> {
00096   };
00097 
00098 class cSchedule;
00099 
00100 class cChannel : public cListObject {
00101   friend class cSchedules;
00102   friend class cMenuEditChannel;
00103   friend class cDvbSourceParam;
00104 private:
00105   static cString ToText(const cChannel *Channel);
00106   char *name;
00107   char *shortName;
00108   char *provider;
00109   char *portalName;
00110   int __BeginData__;
00111   int frequency; // MHz
00112   int source;
00113   int srate;
00114   int vpid;
00115   int ppid;
00116   int vtype;
00117   int apids[MAXAPIDS + 1]; // list is zero-terminated
00118   int atypes[MAXAPIDS + 1]; // list is zero-terminated
00119   char alangs[MAXAPIDS][MAXLANGCODE2];
00120   int dpids[MAXDPIDS + 1]; // list is zero-terminated
00121   int dtypes[MAXAPIDS + 1]; // list is zero-terminated
00122   char dlangs[MAXDPIDS][MAXLANGCODE2];
00123   int spids[MAXSPIDS + 1]; // list is zero-terminated
00124   char slangs[MAXSPIDS][MAXLANGCODE2];
00125   uchar subtitlingTypes[MAXSPIDS];
00126   uint16_t compositionPageIds[MAXSPIDS];
00127   uint16_t ancillaryPageIds[MAXSPIDS];
00128   int tpid;
00129   int fixedTtxtSubtitlePages;
00130   int totalTtxtSubtitlePages;
00131   tTeletextSubtitlePage teletextSubtitlePages[MAXTXTPAGES];
00132   int caids[MAXCAIDS + 1]; // list is zero-terminated
00133   int nid;
00134   int tid;
00135   int sid;
00136   int rid;
00137   int number;    // Sequence number assigned on load
00138   bool groupSep;
00139   int __EndData__;
00140   cString parameters;
00141   int modification;
00142   mutable const cSchedule *schedule;
00143   cLinkChannels *linkChannels;
00144   cChannel *refChannel;
00145   cString TransponderDataToString(void) const;
00146 public:
00147   cChannel(void);
00148   cChannel(const cChannel &Channel);
00149   ~cChannel();
00150   cChannel& operator= (const cChannel &Channel);
00151   cString ToText(void) const;
00152   bool Parse(const char *s);
00153   bool Save(FILE *f);
00154   const char *Name(void) const { return name; }
00155   const char *ShortName(bool OrName = false) const { return (OrName && isempty(shortName)) ? name : shortName; }
00156   const char *Provider(void) const { return provider; }
00157   const char *PortalName(void) const { return portalName; }
00158   int Frequency(void) const { return frequency; } 
00159   int Transponder(void) const;                    
00160   static int Transponder(int Frequency, char Polarization); 
00161   int Source(void) const { return source; }
00162   int Srate(void) const { return srate; }
00163   int Vpid(void) const { return vpid; }
00164   int Ppid(void) const { return ppid; }
00165   int Vtype(void) const { return vtype; }
00166   const int *Apids(void) const { return apids; }
00167   const int *Dpids(void) const { return dpids; }
00168   const int *Spids(void) const { return spids; }
00169   int Apid(int i) const { return (0 <= i && i < MAXAPIDS) ? apids[i] : 0; }
00170   int Dpid(int i) const { return (0 <= i && i < MAXDPIDS) ? dpids[i] : 0; }
00171   int Spid(int i) const { return (0 <= i && i < MAXSPIDS) ? spids[i] : 0; }
00172   const char *Alang(int i) const { return (0 <= i && i < MAXAPIDS) ? alangs[i] : ""; }
00173   const char *Dlang(int i) const { return (0 <= i && i < MAXDPIDS) ? dlangs[i] : ""; }
00174   const char *Slang(int i) const { return (0 <= i && i < MAXSPIDS) ? slangs[i] : ""; }
00175   int Atype(int i) const { return (0 <= i && i < MAXAPIDS) ? atypes[i] : 0; }
00176   int Dtype(int i) const { return (0 <= i && i < MAXDPIDS) ? dtypes[i] : 0; }
00177   uchar SubtitlingType(int i) const { return (0 <= i && i < MAXSPIDS) ? subtitlingTypes[i] : uchar(0); }
00178   uint16_t CompositionPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? compositionPageIds[i] : uint16_t(0); }
00179   uint16_t AncillaryPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? ancillaryPageIds[i] : uint16_t(0); }
00180   int Tpid(void) const { return tpid; }
00181   const tTeletextSubtitlePage *TeletextSubtitlePages() const { return teletextSubtitlePages; }
00182   int TotalTeletextSubtitlePages() const { return totalTtxtSubtitlePages; }
00183   const int *Caids(void) const { return caids; }
00184   int Ca(int Index = 0) const { return Index < MAXCAIDS ? caids[Index] : 0; }
00185   int Nid(void) const { return nid; }
00186   int Tid(void) const { return tid; }
00187   int Sid(void) const { return sid; }
00188   int Rid(void) const { return rid; }
00189   int Number(void) const { return number; }
00190   void SetNumber(int Number) { number = Number; }
00191   bool GroupSep(void) const { return groupSep; }
00192   const char *Parameters(void) const { return parameters; }
00193   const cLinkChannels* LinkChannels(void) const { return linkChannels; }
00194   const cChannel *RefChannel(void) const { return refChannel; }
00195   bool IsAtsc(void) const { return cSource::IsAtsc(source); }
00196   bool IsCable(void) const { return cSource::IsCable(source); }
00197   bool IsSat(void) const { return cSource::IsSat(source); }
00198   bool IsTerr(void) const { return cSource::IsTerr(source); }
00199   bool IsSourceType(char Source) const { return cSource::IsType(source, Source); }
00200   tChannelID GetChannelID(void) const { return tChannelID(source, nid, (nid || tid) ? tid : Transponder(), sid, rid); }
00201   bool HasTimer(void) const;
00202   int Modification(int Mask = CHANNELMOD_ALL);
00203   void CopyTransponderData(const cChannel *Channel);
00204   bool SetTransponderData(int Source, int Frequency, int Srate, const char *Parameters, bool Quiet = false);
00205   void SetId(int Nid, int Tid, int Sid, int Rid = 0);
00206   void SetName(const char *Name, const char *ShortName, const char *Provider);
00207   void SetPortalName(const char *PortalName);
00208   void SetPids(int Vpid, int Ppid, int Vtype, int *Apids, int *Atypes, char ALangs[][MAXLANGCODE2], int *Dpids, int *Dtypes, char DLangs[][MAXLANGCODE2], int *Spids, char SLangs[][MAXLANGCODE2], int Tpid);
00209   void SetTeletextSubtitlePages(tTeletextSubtitlePage pages[], int numberOfPages);
00210   void SetCaIds(const int *CaIds); // list must be zero-terminated
00211   void SetCaDescriptors(int Level);
00212   void SetLinkChannels(cLinkChannels *LinkChannels);
00213   void SetRefChannel(cChannel *RefChannel);
00214   void SetSubtitlingDescriptors(uchar *SubtitlingTypes, uint16_t *CompositionPageIds, uint16_t *AncillaryPageIds);
00215   };
00216 
00217 class cChannels : public cRwLock, public cConfig<cChannel> {
00218 private:
00219   int maxNumber;
00220   int maxChannelNameLength;
00221   int maxShortChannelNameLength;
00222   int modified;
00223   int beingEdited;
00224   cHash<cChannel> channelsHashSid;
00225   void DeleteDuplicateChannels(void);
00226 public:
00227   cChannels(void);
00228   bool Load(const char *FileName, bool AllowComments = false, bool MustExist = false);
00229   void HashChannel(cChannel *Channel);
00230   void UnhashChannel(cChannel *Channel);
00231   int GetNextGroup(int Idx);   // Get next channel group
00232   int GetPrevGroup(int Idx);   // Get previous channel group
00233   int GetNextNormal(int Idx);  // Get next normal channel (not group)
00234   int GetPrevNormal(int Idx);  // Get previous normal channel (not group)
00235   void ReNumber(void);         // Recalculate 'number' based on channel type
00236   cChannel *GetByNumber(int Number, int SkipGap = 0);
00237   cChannel *GetByServiceID(int Source, int Transponder, unsigned short ServiceID);
00238   cChannel *GetByChannelID(tChannelID ChannelID, bool TryWithoutRid = false, bool TryWithoutPolarization = false);
00239   cChannel *GetByTransponderID(tChannelID ChannelID);
00240   int BeingEdited(void) { return beingEdited; }
00241   void IncBeingEdited(void) { beingEdited++; }
00242   void DecBeingEdited(void) { beingEdited--; }
00243   bool HasUniqueChannelID(cChannel *NewChannel, cChannel *OldChannel = NULL);
00244   bool SwitchTo(int Number);
00245   int MaxNumber(void) { return maxNumber; }
00246   int MaxChannelNameLength(void);
00247   int MaxShortChannelNameLength(void);
00248   void SetModified(bool ByUser = false);
00249   int Modified(void);
00253   cChannel *NewChannel(const cChannel *Transponder, const char *Name, const char *ShortName, const char *Provider, int Nid, int Tid, int Sid, int Rid = 0);
00254   };
00255 
00256 extern cChannels Channels;
00257 
00258 cString ChannelString(const cChannel *Channel, int Number);
00259 
00260 #endif //__CHANNELS_H