27 char *sourcebuf = NULL;
32 int fields = sscanf(s,
"%m[^-]-%d-%d-%d-%d", &sourcebuf, &nid, &tid, &sid, &rid);
33 if (fields == 4 || fields == 5) {
61 shortName = strdup(
"");
62 provider = strdup(
"");
63 portalName = strdup(
"");
64 memset(&__BeginData__, 0, (
char *)&__EndData__ - (
char *)&__BeginData__);
90 if (Channel->linkChannels) {
91 for (
cLinkChannel *lc = Channel->linkChannels->First(); lc; lc = Channel->linkChannels->
Next(lc)) {
92 if (lc->Channel() ==
this) {
93 Channel->linkChannels->Del(lc);
97 if (Channel->linkChannels->Count() == 0) {
98 delete Channel->linkChannels;
99 Channel->linkChannels = NULL;
117 shortNameSource = NULL;
134 if (OrName &&
isempty(shortName))
139 return shortNameSource;
147 switch (toupper(Polarization)) {
148 case 'H': Frequency += 100000;
break;
149 case 'V': Frequency += 200000;
break;
150 case 'L': Frequency += 300000;
break;
151 case 'R': Frequency += 400000;
break;
152 default:
esyslog(
"ERROR: invalid value for Polarization '%c'", Polarization);
163 const char *p = strpbrk(parameters,
"HVLRhvlr");
165 tf = Transponder(tf, *p);
173 if (Timer->Channel() ==
this)
181 int Result = modification & Mask;
191 srate = Channel->
srate;
198 if (strchr(Parameters,
':')) {
199 esyslog(
"ERROR: parameter string '%s' contains ':'", Parameters);
205 if (abs(frequency - Frequency) <= 1)
206 Frequency = frequency;
211 if (abs(srate - Srate) <= 1)
214 if (
source != Source || frequency != Frequency || srate != Srate || strcmp(parameters, Parameters)) {
215 cString OldTransponderData = TransponderDataToString();
217 frequency = Frequency;
219 parameters = Parameters;
222 shortNameSource = NULL;
223 if (Number() && !Quiet) {
224 dsyslog(
"changing transponder data of channel %d (%s) from %s to %s", Number(), name, *OldTransponderData, *TransponderDataToString());
234 if (
nid != Nid ||
tid != Tid ||
sid != Sid ||
rid != Rid) {
236 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);
255 dsyslog(
"changing lcn of channel %d (%s) from %d to %d\n", Number(), name, lcn, Lcn);
263 bool nn = strcmp(name, Name) != 0;
264 bool ns = strcmp(shortName, ShortName) != 0;
265 bool np = strcmp(provider, Provider) != 0;
266 if (nn || ns || np) {
268 dsyslog(
"changing name of channel %d from '%s,%s;%s' to '%s,%s;%s'", Number(), name, shortName, provider, Name, ShortName, Provider);
278 shortNameSource = NULL;
288 if (!
isempty(PortalName) && strcmp(portalName, PortalName) != 0) {
290 dsyslog(
"changing portal name of channel %d (%s) from '%s' to '%s'", Number(), name, portalName, PortalName);
304 for (
int i = 0; a[i] || b[i]; i++) {
305 if (!a[i] || !b[i]) {
309 if (na && nb && strcmp(na[i], nb[i]) != 0)
321 while (a[i] || i == 0) {
322 q += sprintf(q, Base == 16 ?
"%s%X" :
"%s%d", i ?
"," :
"", a[i]);
323 const char *Delim =
"=";
326 q += sprintf(q,
"%s%s", Delim, n[i]);
330 q += sprintf(q,
"%s@%d", Delim, t[i]);
340 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)
343 if (vpid != Vpid || ppid != Ppid || vtype != Vtype)
347 int m =
IntArraysDiffer(apids, Apids, alangs, ALangs) |
IntArraysDiffer(atypes, Atypes) |
IntArraysDiffer(dpids, Dpids, dlangs, DLangs) |
IntArraysDiffer(dtypes, Dtypes) |
IntArraysDiffer(spids, Spids, slangs, SLangs);
353 const int BufferSize = (
MAXAPIDS +
MAXDPIDS) * (5 + 1 + MAXLANGCODE2 + 5) + 10;
354 char OldApidsBuf[BufferSize];
355 char NewApidsBuf[BufferSize];
356 char *q = OldApidsBuf;
371 char OldSpidsBuf[SBufferSize];
372 char NewSpidsBuf[SBufferSize];
380 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);
384 for (
int i = 0; i <
MAXAPIDS; i++) {
386 atypes[i] = Atypes[i];
387 strn0cpy(alangs[i], ALangs[i], MAXLANGCODE2);
390 for (
int i = 0; i <
MAXDPIDS; i++) {
392 dtypes[i] = Dtypes[i];
393 strn0cpy(dlangs[i], DLangs[i], MAXLANGCODE2);
396 for (
int i = 0; i <
MAXSPIDS; i++) {
398 strn0cpy(slangs[i], SLangs[i], MAXLANGCODE2);
410 if (SubtitlingTypes) {
412 subtitlingTypes[i] = SubtitlingTypes[i];
414 if (CompositionPageIds) {
416 compositionPageIds[i] = CompositionPageIds[i];
418 if (AncillaryPageIds) {
420 ancillaryPageIds[i] = AncillaryPageIds[i];
434 char OldCaIdsBuf[
MAXCAIDS * 5 + 10];
435 char NewCaIdsBuf[
MAXCAIDS * 5 + 10];
439 dsyslog(
"changing caids of channel %d (%s) from %s to %s", Number(), name, OldCaIdsBuf, NewCaIdsBuf);
440 for (
int i = 0; i <=
MAXCAIDS; i++) {
455 if (Number() && Level > 1)
456 dsyslog(
"changing ca descriptors of channel %d (%s)", Number(), name);
462 if (!linkChannels && !LinkChannels)
464 if (linkChannels && LinkChannels) {
472 lca = linkChannels->
Next(lca);
473 lcb = LinkChannels->
Next(lcb);
480 char buffer[((linkChannels ? linkChannels->Count() : 0) + (LinkChannels ? LinkChannels->
Count() : 0)) * 6 + 256];
482 q += sprintf(q,
"linking channel %d (%s) from", Number(), name);
484 for (
cLinkChannel *lc = linkChannels->First(); lc; lc = linkChannels->
Next(lc)) {
485 lc->Channel()->SetRefChannel(NULL);
486 q += sprintf(q,
" %d", lc->Channel()->Number());
491 q += sprintf(q,
" none");
492 q += sprintf(q,
" to");
493 linkChannels = LinkChannels;
495 for (
cLinkChannel *lc = linkChannels->First(); lc; lc = linkChannels->
Next(lc)) {
496 lc->Channel()->SetRefChannel(
this);
497 q += sprintf(q,
" %d", lc->Channel()->Number());
502 q += sprintf(q,
" none");
509 refChannel = RefChannel;
521 char FullName[strlen(Channel->
name) + 1 + strlen(Channel->
shortName) + 1 + strlen(Channel->
provider) + 1 + 10];
523 q += sprintf(q,
"%s", Channel->
name);
526 q += sprintf(q,
",%s", Channel->
shortName);
527 else if (strchr(Channel->
name,
','))
528 q += sprintf(q,
",");
530 q += sprintf(q,
";%s", Channel->
provider);
544 q += snprintf(q,
sizeof(vpidbuf),
"%d", Channel->
vpid);
546 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"+%d", Channel->
ppid);
548 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"=%d", Channel->
vtype);
551 char apidbuf[ABufferSize];
554 if (Channel->
dpids[0]) {
560 char tpidbuf[TBufferSize];
562 q += snprintf(q,
sizeof(tpidbuf),
"%d", Channel->
tpid);
563 if (Channel->
spids[0]) {
571 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);
586 if (*++s ==
'@' && *++s) {
589 int n = strtol(s, &p, 10);
590 if (!errno && p != s && n > 0) {
600 char *namebuf = NULL;
601 char *sourcebuf = NULL;
602 char *parambuf = NULL;
603 char *vpidbuf = NULL;
604 char *apidbuf = NULL;
605 char *tpidbuf = NULL;
606 char *caidbuf = NULL;
607 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);
614 if (sscanf(tpidbuf,
"%d", &tpid) != 1)
628 if (parambuf && sourcebuf && vpidbuf && apidbuf) {
629 parameters = parambuf;
633 if ((p = strchr(vpidbuf,
'=')) != NULL) {
635 if (sscanf(p,
"%d", &vtype) != 1)
638 if ((p = strchr(vpidbuf,
'+')) != NULL) {
640 if (sscanf(p,
"%d", &ppid) != 1)
643 if (sscanf(vpidbuf,
"%d", &vpid) != 1)
650 char *dpidbuf = strchr(apidbuf,
';');
657 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
659 atypes[NumApids] = 4;
660 char *l = strchr(q,
'=');
663 char *t = strchr(l,
'@');
666 atypes[NumApids] = strtol(t, NULL, 10);
671 *alangs[NumApids] = 0;
672 if ((apids[NumApids] = strtol(q, NULL, 10)) != 0)
676 esyslog(
"ERROR: too many APIDs!");
680 atypes[NumApids] = 0;
686 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
689 char *l = strchr(q,
'=');
692 char *t = strchr(l,
'@');
695 dtypes[NumDpids] = strtol(t, NULL, 10);
700 *dlangs[NumDpids] = 0;
701 if ((dpids[NumDpids] = strtol(q, NULL, 10)) != 0)
705 esyslog(
"ERROR: too many DPIDs!");
709 dtypes[NumDpids] = 0;
712 if ((p = strchr(tpidbuf,
';')) != NULL) {
716 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
718 char *l = strchr(q,
'=');
724 *slangs[NumSpids] = 0;
725 spids[NumSpids++] = strtol(q, NULL, 10);
728 esyslog(
"ERROR: too many SPIDs!");
733 if (sscanf(tpidbuf,
"%d", &tpid) != 1)
740 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
742 caids[NumCaIds++] = strtol(q, NULL, 16) & 0xFFFF;
747 esyslog(
"ERROR: too many CA ids!");
755 char *p = strchr(namebuf,
';');
760 p = strrchr(namebuf,
',');
775 shortNameSource = NULL;
776 if (!GetChannelID().
Valid()) {
777 esyslog(
"ERROR: channel data results in invalid ID!");
789 return fprintf(f,
"%s", *ToText()) > 0;
804 return memcmp(&channelID, &cs->
channelID,
sizeof(channelID));
815 maxChannelNameLength = 0;
816 maxShortChannelNameLength = 0;
823 for (
cChannel *channel = First(); channel; channel = Next(channel)) {
824 if (!channel->GroupSep())
827 ChannelSorter.
Sort();
842 DeleteDuplicateChannels();
851 channelsHashSid.Add(Channel, Channel->
Sid());
856 channelsHashSid.Del(Channel, Channel->
Sid());
862 while (channel && !(channel->
GroupSep() && *channel->
Name()))
863 channel = Get(++Idx);
864 return channel ? Idx : -1;
870 while (channel && !(channel->
GroupSep() && *channel->
Name()))
871 channel = Get(--Idx);
872 return channel ? Idx : -1;
878 while (channel && channel->
GroupSep())
879 channel = Get(++Idx);
880 return channel ? Idx : -1;
886 while (channel && channel->
GroupSep())
887 channel = Get(--Idx);
888 return channel ? Idx : -1;
893 channelsHashSid.Clear();
896 for (
cChannel *channel = First(); channel; channel = Next(channel)) {
897 if (channel->GroupSep()) {
898 if (channel->Number() > Number)
899 Number = channel->Number();
902 HashChannel(channel);
904 channel->SetNumber(Number++);
912 for (
cChannel *channel = First(); channel; channel = Next(channel)) {
913 if (!channel->GroupSep()) {
914 if (channel->Number() == Number)
916 else if (SkipGap && channel->Number() > Number)
917 return SkipGap > 0 ? channel : previous;
939 int sid = ChannelID.
Sid();
955 if (TryWithoutPolarization) {
969 int nid = ChannelID.
Nid();
970 int tid = ChannelID.
Tid();
971 for (
cChannel *channel = First(); channel; channel = Next(channel)) {
972 if (channel->Tid() == tid && channel->Nid() == nid && channel->Source() ==
source)
981 for (
cChannel *channel = First(); channel; channel = Next(channel)) {
982 if (!channel->GroupSep() && channel != OldChannel && channel->
GetChannelID() == NewChannelID)
990 cChannel *channel = GetByNumber(Number);
996 if (!maxChannelNameLength) {
997 for (
cChannel *channel = First(); channel; channel = Next(channel)) {
998 if (!channel->GroupSep())
999 maxChannelNameLength =
max(
Utf8StrLen(channel->Name()), maxChannelNameLength);
1002 return maxChannelNameLength;
1007 if (!maxShortChannelNameLength) {
1008 for (
cChannel *channel = First(); channel; channel = Next(channel)) {
1009 if (!channel->GroupSep())
1010 maxShortChannelNameLength =
max(
Utf8StrLen(channel->ShortName(
true)), maxShortChannelNameLength);
1013 return maxShortChannelNameLength;
1019 maxChannelNameLength = maxShortChannelNameLength = 0;
1024 int Result = modified;
1032 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);
1035 NewChannel->SetId(Nid, Tid, Sid, Rid);
1036 NewChannel->SetName(Name, ShortName, Provider);
1037 NewChannel->SetSeen();
1045 #define CHANNELMARKOBSOLETE "OBSOLETE" 1046 #define CHANNELTIMEOBSOLETE 3600 // seconds to wait before declaring a channel obsolete (in case it has actually been seen before) 1050 for (
cChannel *channel = First(); channel; channel = Next(channel)) {
1051 if (time(NULL) - channel->Seen() >
CHANNELTIMEOBSOLETE && channel->Source() == Source && channel->Nid() == Nid && channel->Tid() == Tid && channel->Rid() == 0) {
1066 snprintf(buffer,
sizeof(buffer),
"%s", Channel->
Name());
1068 snprintf(buffer,
sizeof(buffer),
"%d%s %s", Channel->
Number(), Number ?
"-" :
"", Channel->
Name());
1071 snprintf(buffer,
sizeof(buffer),
"%d-", Number);
1073 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)
void CopyTransponderData(const cChannel *Channel)
void Add(cListObject *Object, cListObject *After=NULL)
static cString ToText(const cChannel *Channel)
static cString sprintf(const char *fmt,...) __attribute__((format(printf
#define CHANNELMOD_TRANSP
static bool IsTerr(int Code)
void MarkObsoleteChannels(int Source, int Nid, int Tid)
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.
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)
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)
#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)
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
void SetLinkChannels(cLinkChannels *LinkChannels)
bool HasUniqueChannelID(cChannel *NewChannel, cChannel *OldChannel=NULL)
cString ToString(void) const
void SetRefChannel(cChannel *RefChannel)
int ShowChannelNamesWithSource
cChannel * GetByNumber(int Number, int SkipGap=0)
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]
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)
#define CHANNELMARKOBSOLETE
void SetCaIds(const int *CaIds)
cString ToText(void) const
void HashChannel(cChannel *Channel)