28 char *sourcebuf = NULL;
33 int fields = sscanf(s,
"%m[^-]-%d-%d-%d-%d", &sourcebuf, &nid, &tid, &sid, &rid);
34 if (fields == 4 || fields == 5) {
91 if (Channel->linkChannels) {
92 for (
cLinkChannel *lc = Channel->linkChannels->First(); lc; lc = Channel->linkChannels->
Next(lc)) {
93 if (lc->Channel() ==
this) {
94 Channel->linkChannels->
Del(lc);
98 if (Channel->linkChannels->Count() == 0) {
99 delete Channel->linkChannels;
100 Channel->linkChannels = NULL;
148 switch (toupper(Polarization)) {
149 case 'H': Frequency += 100000;
break;
150 case 'V': Frequency += 200000;
break;
151 case 'L': Frequency += 300000;
break;
152 case 'R': Frequency += 400000;
break;
153 default:
esyslog(
"ERROR: invalid value for Polarization '%c'", Polarization);
164 const char *p = strpbrk(
parameters,
"HVLRhvlr");
174 if (Timer->Channel() ==
this)
199 if (strchr(Parameters,
':')) {
200 esyslog(
"ERROR: parameter string '%s' contains ':'", Parameters);
212 if (abs(
srate - Srate) <= 1)
235 if (
nid != Nid ||
tid != Tid ||
sid != Sid ||
rid != Rid) {
237 dsyslog(
"changing id of channel %d (%s) from %d-%d-%d-%d to %d-%d-%d-%d",
Number(),
name,
nid,
tid,
sid,
rid, Nid, Tid, Sid, Rid);
264 bool nn = strcmp(
name, Name) != 0;
265 bool ns = strcmp(
shortName, ShortName) != 0;
266 bool np = strcmp(
provider, Provider) != 0;
267 if (nn || ns || np) {
305 for (
int i = 0; a[i] || b[i]; i++) {
306 if (!a[i] || !b[i]) {
310 if (na && nb && strcmp(na[i], nb[i]) != 0)
322 while (a[i] || i == 0) {
323 q += sprintf(q, Base == 16 ?
"%s%X" :
"%s%d", i ?
"," :
"", a[i]);
324 const char *Delim =
"=";
327 q += sprintf(q,
"%s%s", Delim, n[i]);
331 q += sprintf(q,
"%s@%d", Delim, t[i]);
341 void cChannel::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)
348 int m =
IntArraysDiffer(
apids, Apids,
alangs, ALangs) |
IntArraysDiffer(
atypes, Atypes) |
IntArraysDiffer(
dpids, Dpids,
dlangs, DLangs) |
IntArraysDiffer(
dtypes, Dtypes) |
IntArraysDiffer(
spids, Spids,
slangs, SLangs);
354 const int BufferSize = (
MAXAPIDS +
MAXDPIDS) * (5 + 1 + MAXLANGCODE2 + 5) + 10;
355 char OldApidsBuf[BufferSize];
356 char NewApidsBuf[BufferSize];
357 char *q = OldApidsBuf;
372 char OldSpidsBuf[SBufferSize];
373 char NewSpidsBuf[SBufferSize];
381 dsyslog(
"changing pids of channel %d (%s) from %d+%d=%d:%s:%s:%d to %d+%d=%d:%s:%s:%d",
Number(),
name,
vpid,
ppid,
vtype, OldApidsBuf, OldSpidsBuf,
tpid, Vpid, Ppid, Vtype, NewApidsBuf, NewSpidsBuf, Tpid);
385 for (
int i = 0; i <
MAXAPIDS; i++) {
391 for (
int i = 0; i <
MAXDPIDS; i++) {
397 for (
int i = 0; i <
MAXSPIDS; i++) {
411 if (SubtitlingTypes) {
415 if (CompositionPageIds) {
419 if (AncillaryPageIds) {
455 char OldCaIdsBuf[
MAXCAIDS * 5 + 10];
456 char NewCaIdsBuf[
MAXCAIDS * 5 + 10];
460 dsyslog(
"changing caids of channel %d (%s) from %s to %s",
Number(),
name, OldCaIdsBuf, NewCaIdsBuf);
461 for (
int i = 0; i <=
MAXCAIDS; i++) {
476 if (
Number() && Level > 1)
494 lcb = LinkChannels->
Next(lcb);
503 q += sprintf(q,
"linking channel %d (%s) from",
Number(),
name);
506 lc->Channel()->SetRefChannel(NULL);
507 q += sprintf(q,
" %d", lc->Channel()->Number());
512 q += sprintf(q,
" none");
513 q += sprintf(q,
" to");
517 lc->Channel()->SetRefChannel(
this);
518 q += sprintf(q,
" %d", lc->Channel()->Number());
523 q += sprintf(q,
" none");
542 char FullName[strlen(Channel->
name) + 1 + strlen(Channel->
shortName) + 1 + strlen(Channel->
provider) + 1 + 10];
544 q += sprintf(q,
"%s", Channel->
name);
547 q += sprintf(q,
",%s", Channel->
shortName);
548 else if (strchr(Channel->
name,
','))
549 q += sprintf(q,
",");
551 q += sprintf(q,
";%s", Channel->
provider);
565 q += snprintf(q,
sizeof(vpidbuf),
"%d", Channel->
vpid);
567 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"+%d", Channel->
ppid);
569 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"=%d", Channel->
vtype);
572 char apidbuf[ABufferSize];
575 if (Channel->
dpids[0]) {
581 char tpidbuf[TBufferSize];
583 q += snprintf(q,
sizeof(tpidbuf),
"%d", Channel->
tpid);
591 if (Channel->
spids[0]) {
599 buffer =
cString::sprintf(
"%s:%d:%s:%s:%d:%s:%s:%s:%s:%d:%d:%d:%d\n", FullName, Channel->
frequency, *Channel->
parameters, *
cSource::ToString(Channel->
source), Channel->
srate, vpidbuf, apidbuf, tpidbuf, caidbuf, Channel->
sid, Channel->
nid, Channel->
tid, Channel->
rid);
614 if (*++s ==
'@' && *++s) {
617 int n = strtol(s, &p, 10);
618 if (!errno && p != s && n > 0) {
628 char *namebuf = NULL;
629 char *sourcebuf = NULL;
630 char *parambuf = NULL;
631 char *vpidbuf = NULL;
632 char *apidbuf = NULL;
633 char *tpidbuf = NULL;
634 char *caidbuf = NULL;
635 int fields = sscanf(s,
"%m[^:]:%d :%m[^:]:%m[^:] :%d :%m[^:]:%m[^:]:%m[^:]:%m[^:]:%d :%d :%d :%d ", &namebuf, &
frequency, ¶mbuf, &sourcebuf, &
srate, &vpidbuf, &apidbuf, &tpidbuf, &caidbuf, &
sid, &
nid, &
tid, &
rid);
642 if (sscanf(tpidbuf,
"%d", &
tpid) != 1)
656 if (parambuf && sourcebuf && vpidbuf && apidbuf) {
661 if ((p = strchr(vpidbuf,
'=')) != NULL) {
663 if (sscanf(p,
"%d", &
vtype) != 1)
666 if ((p = strchr(vpidbuf,
'+')) != NULL) {
668 if (sscanf(p,
"%d", &
ppid) != 1)
671 if (sscanf(vpidbuf,
"%d", &
vpid) != 1)
678 char *dpidbuf = strchr(apidbuf,
';');
685 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
688 char *l = strchr(q,
'=');
691 char *t = strchr(l,
'@');
694 atypes[NumApids] = strtol(t, NULL, 10);
700 if ((
apids[NumApids] = strtol(q, NULL, 10)) != 0)
704 esyslog(
"ERROR: too many APIDs!");
714 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
717 char *l = strchr(q,
'=');
720 char *t = strchr(l,
'@');
723 dtypes[NumDpids] = strtol(t, NULL, 10);
729 if ((
dpids[NumDpids] = strtol(q, NULL, 10)) != 0)
733 esyslog(
"ERROR: too many DPIDs!");
740 if ((p = strchr(tpidbuf,
';')) != NULL) {
744 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
746 char *l = strchr(q,
'=');
753 spids[NumSpids++] = strtol(q, NULL, 10);
756 esyslog(
"ERROR: too many SPIDs!");
762 if ((p = strchr(tpidbuf,
'+')) != NULL) {
766 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
769 char *l = strchr(q,
'=');
772 if (sscanf(q,
"%d", &page) == 1) {
779 esyslog(
"ERROR: invalid Teletext page!");
782 esyslog(
"ERROR: too many Teletext pages!");
787 if (sscanf(tpidbuf,
"%d", &
tpid) != 1)
794 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
796 caids[NumCaIds++] = strtol(q, NULL, 16) & 0xFFFF;
801 esyslog(
"ERROR: too many CA ids!");
809 char *p = strchr(namebuf,
';');
814 p = strrchr(namebuf,
',');
831 esyslog(
"ERROR: channel data results in invalid ID!");
843 return fprintf(f,
"%s", *
ToText()) > 0;
878 if (!channel->GroupSep())
881 ChannelSorter.
Sort();
916 while (channel && !(channel->
GroupSep() && *channel->
Name()))
917 channel =
Get(++Idx);
918 return channel ? Idx : -1;
924 while (channel && !(channel->
GroupSep() && *channel->
Name()))
925 channel =
Get(--Idx);
926 return channel ? Idx : -1;
932 while (channel && channel->
GroupSep())
933 channel =
Get(++Idx);
934 return channel ? Idx : -1;
940 while (channel && channel->
GroupSep())
941 channel =
Get(--Idx);
942 return channel ? Idx : -1;
954 if (!channel->GroupSep()) {
960 for (
int i = 0; i < FoundLcn.
Size(); ++i) {
961 if (FoundLcn[i] == Number) {
971 channel->SetNumber(Number);
975 channel->SetNumber(Overflow++);
982 if (channel->GroupSep()) {
983 if (channel->Number() > Number)
984 Number = channel->Number();
989 channel->SetNumber(Number++);
999 if (!channel->GroupSep()) {
1000 if (channel->Number() == Number)
1002 else if (SkipGap && channel->Number() > Number)
1003 return SkipGap > 0 ? channel : previous;
1025 int sid = ChannelID.
Sid();
1033 if (TryWithoutRid) {
1041 if (TryWithoutPolarization) {
1054 int source = ChannelID.
Source();
1055 int nid = ChannelID.
Nid();
1056 int tid = ChannelID.
Tid();
1058 if (channel->Tid() == tid && channel->Nid() == nid && channel->Source() == source)
1068 if (!channel->GroupSep() && channel != OldChannel && channel->
GetChannelID() == NewChannelID)
1084 if (!channel->GroupSep())
1095 if (!channel->GroupSep())
1118 dsyslog(
"creating new channel '%s,%s;%s' on %s transponder %d with id %d-%d-%d-%d", Name, ShortName, Provider, *
cSource::ToString(Transponder->
Source()), Transponder->
Transponder(), Nid, Tid, Sid, Rid);
1121 NewChannel->SetId(Nid, Tid, Sid, Rid);
1122 NewChannel->SetName(Name, ShortName, Provider);
1123 NewChannel->SetSeen();
1131 #define CHANNELMARKOBSOLETE "OBSOLETE"
1132 #define CHANNELTIMEOBSOLETE 3600 // seconds to wait before declaring a channel obsolete (in case it has actually been seen before)
1137 if (time(NULL) - channel->Seen() >
CHANNELTIMEOBSOLETE && channel->Source() == Source && channel->Nid() == Nid && channel->Tid() == Tid && channel->Rid() == 0) {
1152 snprintf(buffer,
sizeof(buffer),
"%s", Channel->
Name());
1154 snprintf(buffer,
sizeof(buffer),
"%d%s %s", Channel->
Number(), Number ?
"-" :
"", Channel->
Name());
1157 snprintf(buffer,
sizeof(buffer),
"%d-", Number);
1159 snprintf(buffer,
sizeof(buffer),
"%s",
tr(
"*** Invalid Channel ***"));
static cString ToString(int Code)
void SetId(int Nid, int Tid, int Sid, int Rid=0)
int Modified(void)
Returns 0 if no channels have been modified, 1 if an automatic modification has been made...
#define CHANNELTIMEOBSOLETE
static char ToChar(int Code)
static tChannelID FromString(const char *s)
int GetPrevGroup(int Idx)
int MaxShortChannelNameLength(void)
const cLinkChannels * LinkChannels(void) const
void CopyTransponderData(const cChannel *Channel)
cList< cHashObject > * GetList(unsigned int Id) const
uint16_t compositionPageIds[MAXSPIDS]
void Add(cListObject *Object, cListObject *After=NULL)
static cString ToText(const cChannel *Channel)
uint16_t ancillaryPageIds[MAXSPIDS]
static cString sprintf(const char *fmt,...) __attribute__((format(printf
#define CHANNELMOD_TRANSP
virtual void Append(T Data)
void Del(cListObject *Object, unsigned int Id)
static bool IsTerr(int Code)
void MarkObsoleteChannels(int Source, int Nid, int Tid)
uchar subtitlingTypes[MAXSPIDS]
cChannel * Get(int Index) const
const char * ShortName(bool OrName=false) const
cChannel & operator=(const cChannel &Channel)
bool GroupSep(void) const
tChannelID & ClrPolarization(void)
int MaxChannelNameLength(void)
int nid
actually the "original" network id
cString ChannelString(const cChannel *Channel, int Number)
int Transponder(void) const
Returns the transponder frequency in MHz, plus the polarization in case of sat.
const cSchedule * schedule
int totalTtxtSubtitlePages
int maxShortChannelNameLength
const char * Parameters(void) const
bool Load(const char *FileName, bool AllowComments=false, bool MustExist=false)
bool SetTransponderData(int Source, int Frequency, int Srate, const char *Parameters, bool Quiet=false)
#define LCN_OVERFLOW_OFFSET
const char * Name(void) const
cChannel * NewChannel(const cChannel *Transponder, const char *Name, const char *ShortName, const char *Provider, int Nid, int Tid, int Sid, int Rid=0)
T * Next(const T *object) const
void SetName(const char *Name, const char *ShortName, const char *Provider)
void SetTeletextSubtitlePages(tTeletextSubtitlePage pages[], int numberOfPages)
#define ISTRANSPONDER(f1, f2)
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater", and a negative value if it is "smaller".
char alangs[MAXAPIDS][MAXLANGCODE2]
bool Parse(const char *s)
cListObject * Next(void) const
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
int GetNextNormal(int Idx)
int GetPrevNormal(int Idx)
void SetCaDescriptors(int Level)
char dlangs[MAXDPIDS][MAXLANGCODE2]
tChannelID GetChannelID(void) const
void SetModified(bool ByUser=false)
int GetNextGroup(int Idx)
cString TransponderDataToString(void) const
cChannel * GetByServiceID(int Source, int Transponder, unsigned short ServiceID)
const cChannel * RefChannel(void) const
int Frequency(void) const
Returns the actual frequency, as given in 'channels.conf'.
static int IntArrayToString(char *s, const int *a, int Base=10, const char n[][MAXLANGCODE2]=NULL, const int *t=NULL)
void SetSubtitlingDescriptors(uchar *SubtitlingTypes, uint16_t *CompositionPageIds, uint16_t *AncillaryPageIds)
cChannel * GetByChannelID(tChannelID ChannelID, bool TryWithoutRid=false, bool TryWithoutPolarization=false)
bool HasTimer(void) const
char ttxtLanguage[MAXLANGCODE1]
void SetLinkChannels(cLinkChannels *LinkChannels)
bool HasUniqueChannelID(cChannel *NewChannel, cChannel *OldChannel=NULL)
void Del(cListObject *Object, bool DeleteObject=true)
cString ToString(void) const
void SetRefChannel(cChannel *RefChannel)
int ShowChannelNamesWithSource
cChannel * GetByNumber(int Number, int SkipGap=0)
tTeletextSubtitlePage teletextSubtitlePages[MAXTXTPAGES]
int PageNumber(void) const
static cDevice * PrimaryDevice(void)
Returns the primary device.
void DeleteDuplicateChannels(void)
static int FromString(const char *s)
static int IntArraysDiffer(const int *a, const int *b, const char na[][MAXLANGCODE2]=NULL, const char nb[][MAXLANGCODE2]=NULL)
char slangs[MAXSPIDS][MAXLANGCODE2]
void Add(cListObject *Object, unsigned int Id)
cHash< cChannel > channelsHashSid
cChannel * GetByTransponderID(tChannelID ChannelID)
static const tChannelID InvalidID
int Modification(int Mask=CHANNELMOD_ALL)
bool SwitchTo(int Number)
void UnhashChannel(cChannel *Channel)
cChannelSorter(cChannel *Channel)
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)
void SetPortalName(const char *PortalName)
tChannelID & ClrRid(void)
cLinkChannels * linkChannels
#define CHANNELMARKOBSOLETE
void SetCaIds(const int *CaIds)
cString ToText(void) const
int fixedTtxtSubtitlePages
void HashChannel(cChannel *Channel)