vdr  2.0.2
channels.h
Go to the documentation of this file.
1 /*
2  * channels.h: Channel handling
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: channels.h 2.16 2012/06/17 11:21:33 kls Exp $
8  */
9 
10 #ifndef __CHANNELS_H
11 #define __CHANNELS_H
12 
13 #include "config.h"
14 #include "sources.h"
15 #include "thread.h"
16 #include "tools.h"
17 
18 #define ISTRANSPONDER(f1, f2) (abs((f1) - (f2)) < 4) //XXX
19 
20 #define CHANNELMOD_NONE 0x00
21 #define CHANNELMOD_ALL 0xFF
22 #define CHANNELMOD_NAME 0x01
23 #define CHANNELMOD_PIDS 0x02
24 #define CHANNELMOD_ID 0x04
25 #define CHANNELMOD_CA 0x10
26 #define CHANNELMOD_TRANSP 0x20
27 #define CHANNELMOD_LANGS 0x40
28 #define CHANNELMOD_RETUNE (CHANNELMOD_PIDS | CHANNELMOD_CA | CHANNELMOD_TRANSP)
29 
30 #define CHANNELSMOD_NONE 0
31 #define CHANNELSMOD_AUTO 1
32 #define CHANNELSMOD_USER 2
33 
34 #define MAXAPIDS 32 // audio
35 #define MAXDPIDS 16 // dolby (AC3 + DTS)
36 #define MAXSPIDS 32 // subtitles
37 #define MAXCAIDS 12 // conditional access
38 #define MAXTXTPAGES 8 // teletext pages
39 
40 #define MAXLANGCODE1 4 // a 3 letter language code, zero terminated
41 #define MAXLANGCODE2 8 // up to two 3 letter language codes, separated by '+' and zero terminated
42 
43 #define CA_FTA 0x0000
44 #define CA_DVB_MIN 0x0001
45 #define CA_DVB_MAX 0x000F
46 #define CA_USER_MIN 0x0010
47 #define CA_USER_MAX 0x00FF
48 #define CA_ENCRYPTED_MIN 0x0100
49 #define CA_ENCRYPTED_MAX 0xFFFF
50 
51 struct tChannelID {
52 private:
53  int source;
54  int nid;
55  int tid;
56  int sid;
57  int rid;
58 public:
59  tChannelID(void) { source = nid = tid = sid = rid = 0; }
60  tChannelID(int Source, int Nid, int Tid, int Sid, int Rid = 0) { source = Source; nid = Nid; tid = Tid; sid = Sid; rid = Rid; }
61  bool operator== (const tChannelID &arg) const { return source == arg.source && nid == arg.nid && tid == arg.tid && sid == arg.sid && rid == arg.rid; }
62  bool Valid(void) const { return (nid || tid) && sid; } // rid is optional and source may be 0//XXX source may not be 0???
63  tChannelID &ClrRid(void) { rid = 0; return *this; }
65  int Source(void) const { return source; }
66  int Nid(void) const { return nid; }
67  int Tid(void) const { return tid; }
68  int Sid(void) const { return sid; }
69  int Rid(void) const { return rid; }
70  static tChannelID FromString(const char *s);
71  cString ToString(void) const;
72  static const tChannelID InvalidID;
73  };
74 
76  tTeletextSubtitlePage(void) { ttxtPage = ttxtMagazine = 0; ttxtType = 0x02; strcpy(ttxtLanguage, "und"); }
77  tTeletextSubtitlePage(int page) { ttxtMagazine = (page / 100) & 0x7; ttxtPage = (((page % 100) / 10) << 4) + (page % 10); ttxtType = 0x02; strcpy(ttxtLanguage, "und"); }
82  int PageNumber(void) const { return BCDCHARTOINT(ttxtMagazine) * 100 + BCDCHARTOINT(ttxtPage); }
83  };
84 
85 class cChannel;
86 
87 class cLinkChannel : public cListObject {
88 private:
90 public:
92  cChannel *Channel(void) { return channel; }
93  };
94 
95 class cLinkChannels : public cList<cLinkChannel> {
96  };
97 
98 class cSchedule;
99 
100 class cChannel : public cListObject {
101  friend class cSchedules;
102  friend class cMenuEditChannel;
103  friend class cDvbSourceParam;
104 private:
105  static cString ToText(const cChannel *Channel);
106  char *name;
107  char *shortName;
108  char *provider;
109  char *portalName;
111  int frequency; // MHz
112  int source;
113  int srate;
114  int vpid;
115  int ppid;
116  int vtype;
117  int apids[MAXAPIDS + 1]; // list is zero-terminated
118  int atypes[MAXAPIDS + 1]; // list is zero-terminated
120  int dpids[MAXDPIDS + 1]; // list is zero-terminated
121  int dtypes[MAXAPIDS + 1]; // list is zero-terminated
123  int spids[MAXSPIDS + 1]; // list is zero-terminated
128  int tpid;
132  int caids[MAXCAIDS + 1]; // list is zero-terminated
133  int nid;
134  int tid;
135  int sid;
136  int rid;
137  int number; // Sequence number assigned on load
138  bool groupSep;
144  mutable const cSchedule *schedule;
147  cString TransponderDataToString(void) const;
148 public:
149  cChannel(void);
150  cChannel(const cChannel &Channel);
151  ~cChannel();
152  cChannel& operator= (const cChannel &Channel);
153  cString ToText(void) const;
154  bool Parse(const char *s);
155  bool Save(FILE *f);
156  const char *Name(void) const;
157  const char *ShortName(bool OrName = false) const;
158  const char *Provider(void) const { return provider; }
159  const char *PortalName(void) const { return portalName; }
160  int Frequency(void) const { return frequency; }
161  int Transponder(void) const;
162  static int Transponder(int Frequency, char Polarization);
163  int Source(void) const { return source; }
164  int Srate(void) const { return srate; }
165  int Vpid(void) const { return vpid; }
166  int Ppid(void) const { return ppid; }
167  int Vtype(void) const { return vtype; }
168  const int *Apids(void) const { return apids; }
169  const int *Dpids(void) const { return dpids; }
170  const int *Spids(void) const { return spids; }
171  int Apid(int i) const { return (0 <= i && i < MAXAPIDS) ? apids[i] : 0; }
172  int Dpid(int i) const { return (0 <= i && i < MAXDPIDS) ? dpids[i] : 0; }
173  int Spid(int i) const { return (0 <= i && i < MAXSPIDS) ? spids[i] : 0; }
174  const char *Alang(int i) const { return (0 <= i && i < MAXAPIDS) ? alangs[i] : ""; }
175  const char *Dlang(int i) const { return (0 <= i && i < MAXDPIDS) ? dlangs[i] : ""; }
176  const char *Slang(int i) const { return (0 <= i && i < MAXSPIDS) ? slangs[i] : ""; }
177  int Atype(int i) const { return (0 <= i && i < MAXAPIDS) ? atypes[i] : 0; }
178  int Dtype(int i) const { return (0 <= i && i < MAXDPIDS) ? dtypes[i] : 0; }
179  uchar SubtitlingType(int i) const { return (0 <= i && i < MAXSPIDS) ? subtitlingTypes[i] : uchar(0); }
180  uint16_t CompositionPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? compositionPageIds[i] : uint16_t(0); }
181  uint16_t AncillaryPageId(int i) const { return (0 <= i && i < MAXSPIDS) ? ancillaryPageIds[i] : uint16_t(0); }
182  int Tpid(void) const { return tpid; }
185  const int *Caids(void) const { return caids; }
186  int Ca(int Index = 0) const { return Index < MAXCAIDS ? caids[Index] : 0; }
187  int Nid(void) const { return nid; }
188  int Tid(void) const { return tid; }
189  int Sid(void) const { return sid; }
190  int Rid(void) const { return rid; }
191  int Number(void) const { return number; }
192  void SetNumber(int Number) { number = Number; }
193  bool GroupSep(void) const { return groupSep; }
194  const char *Parameters(void) const { return parameters; }
195  const cLinkChannels* LinkChannels(void) const { return linkChannels; }
196  const cChannel *RefChannel(void) const { return refChannel; }
197  bool IsAtsc(void) const { return cSource::IsAtsc(source); }
198  bool IsCable(void) const { return cSource::IsCable(source); }
199  bool IsSat(void) const { return cSource::IsSat(source); }
200  bool IsTerr(void) const { return cSource::IsTerr(source); }
201  bool IsSourceType(char Source) const { return cSource::IsType(source, Source); }
202  tChannelID GetChannelID(void) const { return tChannelID(source, nid, (nid || tid) ? tid : Transponder(), sid, rid); }
203  bool HasTimer(void) const;
204  int Modification(int Mask = CHANNELMOD_ALL);
205  void CopyTransponderData(const cChannel *Channel);
206  bool SetTransponderData(int Source, int Frequency, int Srate, const char *Parameters, bool Quiet = false);
207  void SetId(int Nid, int Tid, int Sid, int Rid = 0);
208  void SetName(const char *Name, const char *ShortName, const char *Provider);
209  void SetPortalName(const char *PortalName);
210  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);
211  void SetTeletextSubtitlePages(tTeletextSubtitlePage pages[], int numberOfPages);
212  void SetCaIds(const int *CaIds); // list must be zero-terminated
213  void SetCaDescriptors(int Level);
216  void SetSubtitlingDescriptors(uchar *SubtitlingTypes, uint16_t *CompositionPageIds, uint16_t *AncillaryPageIds);
217  };
218 
219 class cChannels : public cRwLock, public cConfig<cChannel> {
220 private:
224  int modified;
227  void DeleteDuplicateChannels(void);
228 public:
229  cChannels(void);
230  bool Load(const char *FileName, bool AllowComments = false, bool MustExist = false);
231  void HashChannel(cChannel *Channel);
232  void UnhashChannel(cChannel *Channel);
233  int GetNextGroup(int Idx); // Get next channel group
234  int GetPrevGroup(int Idx); // Get previous channel group
235  int GetNextNormal(int Idx); // Get next normal channel (not group)
236  int GetPrevNormal(int Idx); // Get previous normal channel (not group)
237  void ReNumber(void); // Recalculate 'number' based on channel type
238  cChannel *GetByNumber(int Number, int SkipGap = 0);
239  cChannel *GetByServiceID(int Source, int Transponder, unsigned short ServiceID);
240  cChannel *GetByChannelID(tChannelID ChannelID, bool TryWithoutRid = false, bool TryWithoutPolarization = false);
242  int BeingEdited(void) { return beingEdited; }
243  void IncBeingEdited(void) { beingEdited++; }
244  void DecBeingEdited(void) { beingEdited--; }
245  bool HasUniqueChannelID(cChannel *NewChannel, cChannel *OldChannel = NULL);
246  bool SwitchTo(int Number);
247  int MaxNumber(void) { return maxNumber; }
248  int MaxChannelNameLength(void);
249  int MaxShortChannelNameLength(void);
250  void SetModified(bool ByUser = false);
251  int Modified(void);
255  cChannel *NewChannel(const cChannel *Transponder, const char *Name, const char *ShortName, const char *Provider, int Nid, int Tid, int Sid, int Rid = 0);
256  };
257 
258 extern cChannels Channels;
259 
260 cString ChannelString(const cChannel *Channel, int Number);
261 
262 #endif //__CHANNELS_H
263