diff options
author | Dimitar Petrovski <dimeptr@gmail.com> | 2011-07-20 02:15:36 +0200 |
---|---|---|
committer | Dimitar Petrovski <dimeptr@gmail.com> | 2011-07-20 02:15:36 +0200 |
commit | 10db998ab768cffb7217b742b5e119351ed3635c (patch) | |
tree | ebb1b25fbfed45bd9013fcd947b75c094be9eae8 /eepg.c | |
parent | c030237380d362702670105982fa3e652681b40e (diff) | |
download | vdr-plugin-eepg-10db998ab768cffb7217b742b5e119351ed3635c.tar.gz vdr-plugin-eepg-10db998ab768cffb7217b742b5e119351ed3635c.tar.bz2 |
Modified formating and comments
Diffstat (limited to 'eepg.c')
-rw-r--r-- | eepg.c | 968 |
1 files changed, 522 insertions, 446 deletions
@@ -67,8 +67,8 @@ #define d2(x) ; #endif*/ -#define PMT_SCAN_TIMEOUT 10 // seconds -#define PMT_SCAN_IDLE 3600 // seconds +#define PMT_SCAN_TIMEOUT 10 // seconds +#define PMT_SCAN_IDLE 3600 // seconds static const char *VERSION = "0.0.6pre"; static const char *DESCRIPTION = trNOOP ("Parses Extended EPG data"); @@ -238,7 +238,7 @@ void LogVsyslog(int errLevel, int const& lineNum, const char * function, const c // --- CRC16 ------------------------------------------------------------------- -#define POLY 0xA001 // CRC16 +#define POLY 0xA001 // CRC16 unsigned int crc16 (unsigned int crc, unsigned char const *p, int len) { @@ -256,29 +256,29 @@ unsigned int crc16 (unsigned int crc, unsigned char const *p, int len) static int AvailableSources[32]; static int NumberOfAvailableSources = 0; -static int LastVersionNagra = -1; //currently only used for Nagra, should be stored per transponder, per system +static int LastVersionNagra = -1; //currently only used for Nagra, should be stored per transponder, per system class cFilterEEPG:public cFilter { private: int pmtpid, pmtsid, pmtidx, pmtnext; - int UnprocessedFormat[HIGHEST_FORMAT + 1]; //stores the pid when a format is detected on this transponder, and that are not processed yet + int UnprocessedFormat[HIGHEST_FORMAT + 1]; //stores the pid when a format is detected on this transponder, and that are not processed yet int nEquivChannels, nChannels, nThemes, nTitles, nSummaries, NumberOfTables, Version; int TitleCounter, SummaryCounter, NoSummaryCounter, RejectTableId; - bool EndChannels, EndThemes; //only used for ?? - int MHWStartTime; //only used for MHW1 + bool EndChannels, EndThemes; //only used for ?? + int MHWStartTime; //only used for MHW1 bool ChannelsOk; - int Format; //the format that this filter currently is processing - std::map < int, int >ChannelSeq; // ChannelSeq[ChannelId] returns the recordnumber of the channel + int Format; //the format that this filter currently is processing + std::map < int, int >ChannelSeq; // ChannelSeq[ChannelId] returns the recordnumber of the channel Summary_t *Summaries[MAX_TITLES]; Title_t *Titles[MAX_TITLES]; sChannel sChannels[MAX_CHANNELS]; unsigned char Themes[MAX_THEMES][64]; - std::map < unsigned short int, unsigned char *>buffer; //buffer[Table_Extension_Id] returns the pointer to the buffer for this TEI - std::map < unsigned short int, int >bufsize; //bufsize[Table_Extension_Id] returns the buffersize of the buffer for this TEI - unsigned short int NagraTIE[64]; //at this moment a max of 31 table_ids could be used, so 64 should be enough ....stores the Table_Extension_Id's of summaries received, so they can be processed. Processing while receiving somehow drops sections, the 0x0000 marker will be missed ... + std::map < unsigned short int, unsigned char *>buffer; //buffer[Table_Extension_Id] returns the pointer to the buffer for this TEI + std::map < unsigned short int, int >bufsize; //bufsize[Table_Extension_Id] returns the buffersize of the buffer for this TEI + unsigned short int NagraTIE[64]; //at this moment a max of 31 table_ids could be used, so 64 should be enough ....stores the Table_Extension_Id's of summaries received, so they can be processed. Processing while receiving somehow drops sections, the 0x0000 marker will be missed ... unsigned short int NagraCounter; unsigned char InitialChannel[8]; @@ -296,10 +296,10 @@ protected: virtual void ProcessNextFormat (bool FirstTime); virtual int GetChannelsSKYBOX (const u_char * Data, int Length); virtual bool GetThemesSKYBOX (void); - virtual bool ReadFileDictionary (void); //Reads Huffman tables for SKY + virtual bool ReadFileDictionary (void); //Reads Huffman tables for SKY virtual int GetTitlesSKYBOX (const u_char * Data, int Length); virtual int GetSummariesSKYBOX (const u_char * Data, int Length); - virtual int GetChannelsMHW (const u_char * Data, int Length, int MHW); //TODO replace MHW by Format? + virtual int GetChannelsMHW (const u_char * Data, int Length, int MHW); //TODO replace MHW by Format? virtual int GetThemesMHW1 (const u_char * Data, int Length); virtual int GetNagra (const u_char * Data, int Length); virtual void ProcessNagra (void); @@ -314,12 +314,12 @@ protected: virtual int GetSummariesMHW2 (const u_char * Data, int Length); virtual void FreeSummaries (void); virtual void FreeTitles (void); - virtual void PrepareToWriteToSchedule (sChannel * C, cSchedules * s, cSchedule * ps[MAX_EQUIVALENCES]); //gets a channel and returns an array of schedules that WriteToSchedule can write to. Call this routine before a batch of titles with the same ChannelId will be WriteToScheduled; batchsize can be 1 + virtual void PrepareToWriteToSchedule (sChannel * C, cSchedules * s, cSchedule * ps[MAX_EQUIVALENCES]); //gets a channel and returns an array of schedules that WriteToSchedule can write to. Call this routine before a batch of titles with the same ChannelId will be WriteToScheduled; batchsize can be 1 virtual void FinishWriteToSchedule (sChannel * C, cSchedules * s, cSchedule * ps[MAX_EQUIVALENCES]); virtual void WriteToSchedule (cSchedule * ps[MAX_EQUIVALENCES], unsigned short int NumberOfEquivalences, - unsigned int EventId, unsigned int StartTime, unsigned int Duration, char *Text, - char *SummText, unsigned short int ThemeId, unsigned short int TableId, - unsigned short int Version, char Rating = 0x00); + unsigned int EventId, unsigned int StartTime, unsigned int Duration, char *Text, + char *SummText, unsigned short int ThemeId, unsigned short int TableId, + unsigned short int Version, char Rating = 0x00); virtual void LoadIntoSchedule (void); virtual void LoadEquivalentChannels (void); public: @@ -354,7 +354,7 @@ void cFilterEEPG::SetStatus (bool On) } else { //Set(0x00,0x00); for (int i = 0; i <= HIGHEST_FORMAT; i++) - UnprocessedFormat[i] = 0; //pid 0 is assumed to be nonvalid for EEPG transfers + UnprocessedFormat[i] = 0; //pid 0 is assumed to be nonvalid for EEPG transfers AddFilter (0, 0); } cFilter::SetStatus (On); @@ -426,7 +426,7 @@ struct hufftab { #define ESCAPE '\1' -int freesat_decode_error = 0; /* If set an error has occurred during decoding */ +int freesat_decode_error = 0; /* If set an error has occurred during decoding */ static struct hufftab *tables[2][256]; static int table_size[2][256]; @@ -628,7 +628,7 @@ int YesterdayEpoch; int YesterdayEpochUTC; /* - * Convert local time to UTC + * Convert local time to UTC */ time_t LocalTime2UTC (time_t t) { @@ -640,7 +640,7 @@ time_t LocalTime2UTC (time_t t) } /* - * Convert UTC to local time + * Convert UTC to local time */ time_t UTC2LocalTime (time_t t) { @@ -676,10 +676,10 @@ void CleanString (unsigned char *String) pC = 0; while (*Src) { // corrections - if (*Src == 0x8c) { // iso-8859-2 LATIN CAPITAL LETTER S WITH ACUTE + if (*Src == 0x8c) { // iso-8859-2 LATIN CAPITAL LETTER S WITH ACUTE *Src = 0xa6; } - if (*Src == 0x8f) { // iso-8859-2 LATIN CAPITAL LETTER Z WITH ACUTE + if (*Src == 0x8f) { // iso-8859-2 LATIN CAPITAL LETTER Z WITH ACUTE *Src = 0xac; } @@ -709,7 +709,7 @@ void CleanString (unsigned char *String) } } -bool cFilterEEPG::GetThemesSKYBOX (void) //TODO can't we read this from the DVB stream? +bool cFilterEEPG::GetThemesSKYBOX (void) //TODO can't we read this from the DVB stream? { string FileName = ConfDir; FILE *FileThemes; @@ -777,7 +777,7 @@ bool cFilterEEPG::ReadFileDictionary (void) LogE (0 ,prep("Error, wrong format detected in ReadFileDictionary. Format = %i."), Format); return false; } - if ((Format == SKY_IT) || (Format == SKY_UK)) { //SKY + if ((Format == SKY_IT) || (Format == SKY_UK)) { //SKY FileDict = fopen (FileName.c_str(), "r"); if (FileDict == NULL) { LogE (0, prep("Error opening file '%s'. %s"), FileName.c_str(), strerror (errno)); @@ -889,7 +889,7 @@ bool cFilterEEPG::ReadFileDictionary (void) } fclose (FileDict); } - } //if Format == 3 || Format == 4 + } //if Format == 3 || Format == 4 return true; } @@ -990,12 +990,12 @@ void decodeText2 (const unsigned char *from, int len, char *buffer, int buffsize if (from[0] == 0x1f) { char *temp = freesat_huffman_decode (from, len); if (temp) { - len = strlen (temp); - len = len < buffsize - 1 ? len : buffsize - 1; - strncpy (buffer, temp, len); - buffer[len] = 0; - free (temp); - return; + len = strlen (temp); + len = len < buffsize - 1 ? len : buffsize - 1; + strncpy (buffer, temp, len); + buffer[len] = 0; + free (temp); + return; } } @@ -1030,7 +1030,7 @@ void cFilterEEPG::LoadEquivalentChannels (void) if (!isempty (Line)) { if (sscanf (Line, "%[^ ] %[^ ] %[^\n]\n", string1, string2, string3) == 3) { if (string1[0] != '#' && string1[0] != ';') { - int1 = 0; //TODO: this could be made more readable + int1 = 0; //TODO: this could be made more readable int2 = 0; int3 = 0; int4 = 0; @@ -1057,14 +1057,14 @@ void cFilterEEPG::LoadEquivalentChannels (void) } else { cChannel *OriginalChannel = Channels.GetByChannelID (OriginalChID, false); if (!OriginalChannel) - LogI(2, prep("Warning, not found epg channel \'%s\' in channels.conf. Equivalency is assumed to be valid, but perhaps you should check the entry in the equivalents file"), string1); //TODO: skip this ing? + LogI(2, prep("Warning, not found epg channel \'%s\' in channels.conf. Equivalency is assumed to be valid, but perhaps you should check the entry in the equivalents file"), string1); //TODO: skip this ing? if (sscanf (string2, "%[^-]-%i -%i -%i ", string3, &int1, &int2, &int3) == 4) { if (sscanf (string2, "%[^-]-%i -%i -%i -%i ", string3, &int1, &int2, &int3, &int4) != 5) { int4 = 0; } tChannelID EquivChID = tChannelID (cSource::FromString (string3), int1, int2, int3, int4); - cChannel *EquivChannel = Channels.GetByChannelID (EquivChID, false); //TODO use valid function? + cChannel *EquivChannel = Channels.GetByChannelID (EquivChID, false); //TODO use valid function? if (EquivChannel) { if (C->NumberOfEquivalences < MAX_EQUIVALENCES) { C->Src[C->NumberOfEquivalences] = EquivChannel->Source (); @@ -1083,19 +1083,24 @@ void cFilterEEPG::LoadEquivalentChannels (void) } else LogI(0, prep("Warning, not found equivalent channel \'%s\' in channels.conf"), string2); } - } //else !found - } //if scanf string1 - } //if string1 - } //if scanf - } //if isempty - } //while + } //else !found + } //if scanf string1 + } //if string1 + } //if scanf + } //if isempty + } //while fclose (File); - } //if file -} //end of loadequiv + } //if file +} //end of loadequiv -int cFilterEEPG::GetChannelsMHW (const u_char * Data, int Length, int MHW) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get MHW channels + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetChannelsMHW (const u_char * Data, int Length, int MHW) { - if ((MHW == 1) || (nChannels == 0)) { //prevents MHW2 from reading channels twice while waiting for themes on same filter + if ((MHW == 1) || (nChannels == 0)) { //prevents MHW2 from reading channels twice while waiting for themes on same filter sChannelMHW1 *Channel; int Size, Off; Size = sizeof (sChannelMHW1); @@ -1114,8 +1119,8 @@ int cFilterEEPG::GetChannelsMHW (const u_char * Data, int Length, int MHW) //ret int pName = ((nChannels * 8) + 121); if (Length > pName) { //Channel = (sChannelMHW1 *) (Data + 120); - Size -= 14; //MHW2 is 14 bytes shorter - Off = 121; //and offset differs + Size -= 14; //MHW2 is 14 bytes shorter + Off = 121; //and offset differs } else { LogE(0, prep("Error, channels length does not match pname.")); return 0; @@ -1129,38 +1134,38 @@ int cFilterEEPG::GetChannelsMHW (const u_char * Data, int Length, int MHW) //ret LogI(1, "| ID | %-26.26s | %-22.22s | FND | %-8.8s |\n", "Channel ID", "Channel Name", "Sky Num."); LogI(1, "|------|-%-26.26s-|-%-22.22s-|-----|-%-8.8s-|\n", "------------------------------", "-----------------------------", "--------------------"); - int pName = ((nChannels * 8) + 121); //TODO double ... + int pName = ((nChannels * 8) + 121); //TODO double ... for (int i = 0; i < nChannels; i++) { Channel = (sChannelMHW1 *) (Data + Off); sChannel *C = &sChannels[i]; C->ChannelId = i; - ChannelSeq[C->ChannelId] = i; //fill lookup table to go from channel-id to sequence nr in table + ChannelSeq[C->ChannelId] = i; //fill lookup table to go from channel-id to sequence nr in table C->SkyNumber = 0; if (MHW == 1) - memcpy (C->Name, &Channel->Name, 16); //MHW1 - else { //MHW2 + memcpy (C->Name, &Channel->Name, 16); //MHW1 + else { //MHW2 int lenName = Data[pName] & 0x0f; - if (lenName < 256) //TODO impossible, after & 0x0f lenName is always < 0x0f !! + if (lenName < 256) //TODO impossible, after & 0x0f lenName is always < 0x0f !! decodeText2(&Data[pName+1],lenName,(char*)C->Name,256); //memcpy (C->Name, &Data[pName + 1], lenName); //else //memcpy (C->Name, &Data[pName + 1], 256); pName += (lenName + 1); } - C->NumberOfEquivalences = 1; //there is always an original channel. every equivalence adds 1 - C->Src[0] = Source (); //assume all EPG channels are on same satellite, if not, manage this via equivalents!!! + C->NumberOfEquivalences = 1; //there is always an original channel. every equivalence adds 1 + C->Src[0] = Source (); //assume all EPG channels are on same satellite, if not, manage this via equivalents!!! C->Nid[0] = HILO16 (Channel->NetworkId); C->Tid[0] = HILO16 (Channel->TransportId); C->Sid[0] = HILO16 (Channel->ServiceId); tChannelID channelID = tChannelID (C->Src[0], C->Nid[0], C->Tid[0], C->Sid[0]); cChannel *VC = Channels.GetByChannelID (channelID, true); bool IsFound = (VC); - if (!IsFound) { //look on other satpositions + if (!IsFound) { //look on other satpositions for (int i = 0; i < NumberOfAvailableSources; i++) { channelID = tChannelID (AvailableSources[i], C->Nid[0], C->Tid[0], C->Sid[0]); VC = Channels.GetByChannelID (channelID, true); IsFound = (VC); - if (IsFound) { //found this actually on satellite nextdoor... + if (IsFound) { //found this actually on satellite nextdoor... C->Src[0] = AvailableSources[i]; break; } @@ -1173,19 +1178,24 @@ int cFilterEEPG::GetChannelsMHW (const u_char * Data, int Length, int MHW) //ret , C->Name, IsFound ? "YES" : "NO", C->SkyNumber); Off += Size; - } //for loop - } //else nChannels > MAX_CHANNELS + } //for loop + } //else nChannels > MAX_CHANNELS LoadEquivalentChannels (); - GetLocalTimeOffset (); //reread timing variables, only used for MHW - return 2; //obviously, when you get here, channels are read succesfully, but since all channels are sent at once, you can stop now - } //if nChannels == 0 + GetLocalTimeOffset (); //reread timing variables, only used for MHW + return 2; //obviously, when you get here, channels are read succesfully, but since all channels are sent at once, you can stop now + } //if nChannels == 0 LogE (0, prep("Warning: Trying to read Channels more than once!")); //you will only get here when GetChannelsMHW is called, and nChannels !=0, e.g. when multiple citpids cause channels to be read multiple times. Second time, do nothing, give error so that the rest of the chain is not restarted also. return 0; } -int cFilterEEPG::GetThemesMHW1 (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed -{ //MHW1 Themes +/** + * \brief Get MHW1 Themes + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetThemesMHW1 (const u_char * Data, int Length) +{ //MHW1 Themes if (Length > 19) { sThemeMHW1 *Theme = (sThemeMHW1 *) (Data + 19); nThemes = (Length - 19) / 15; @@ -1199,11 +1209,11 @@ int cFilterEEPG::GetThemesMHW1 (const u_char * Data, int Length) //return code 0 const u_char *ThemesIndex = (Data + 3); for (int i = 0; i < nThemes; i++) { if (ThemesIndex[ThemeId] == i) { - Offset = (Offset + 15) & 0xf0; //TODO do not understand this + Offset = (Offset + 15) & 0xf0; //TODO do not understand this ThemeId++; } memcpy (&Themes[Offset][0], &Theme->Name, 15); - Themes[Offset][15] = NULL; //trailing null + Themes[Offset][15] = NULL; //trailing null CleanString (Themes[Offset]); LogI(1, prep("%.15s"), Themes[Offset]); Offset++; @@ -1219,9 +1229,14 @@ int cFilterEEPG::GetThemesMHW1 (const u_char * Data, int Length) //return code 0 return 1; } -int cFilterEEPG::GetThemesMHW2 (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get MHW2 Themes + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetThemesMHW2 (const u_char * Data, int Length) { - if (!EndThemes) { //only proces if not processed + if (!EndThemes) { //only proces if not processed int p1; int p2; int pThemeName = 0; @@ -1249,7 +1264,7 @@ int cFilterEEPG::GetThemesMHW2 (const u_char * Data, int Length) //return code 0 pThemeId = ((i & 0x3f) << 6) | (ii & 0x3f); if (pThemeId > MAX_THEMES) { LogE(1, prep("Error, something wrong with themes id calculation MaxThemes: %i pThemeID:%d"), MAX_THEMES, pThemeId); - return 0; //fatal error + return 0; //fatal error } if ((lenThemeName + 2) < 256) { decodeText2(&Data[pThemeName],lenThemeName,(char*)Themes[pThemeId],256); @@ -1267,26 +1282,32 @@ int cFilterEEPG::GetThemesMHW2 (const u_char * Data, int Length) //return code 0 nThemes++; if (nThemes > MAX_THEMES) { LogE(1, prep("Error, %i themes found more than %i"), nThemes, MAX_THEMES); - return 0; //fatal error + return 0; //fatal error } } } else - return 1; //I assume non fatal error or success + return 1; //I assume non fatal error or success } else - return 1; //I assume non fatal error or success + return 1; //I assume non fatal error or success } } else - return 1; //I assume non fatal error or success - } //for loop + return 1; //I assume non fatal error or success + } //for loop //Del (Pid, Tid); EndThemes = true; - return 2; //all themes read - } //if length - } //if !EndThemes - return 1; //non fatal or success + return 2; //all themes read + } //if length + } //if !EndThemes + return 1; //non fatal or success } -char *cFilterEEPG::GetSummaryTextNagra (const u_char * DataStart, long int Offset, unsigned int TitleEventId) //this function returns pointer to reserved part of memory with summary text in it, terminated by NULL +/** + * \brief Get Nagra Summary text + * + * \param TitleEventId EventId passed from title, to check it against the eventId of the summary + * \return pointer to reserved part of memory with summary text in it, terminated by NULL + */ +char *cFilterEEPG::GetSummaryTextNagra (const u_char * DataStart, long int Offset, unsigned int TitleEventId) //EventId is passed from title, to check it against the eventid of the summary { u_char *p = (u_char *) DataStart + Offset; @@ -1295,7 +1316,7 @@ char *cFilterEEPG::GetSummaryTextNagra (const u_char * DataStart, long int Offse if (TitleEventId != HILO32 (SD->EventId)) { LogI(0, prep("ERROR, Title has EventId %08x and points to Summary with EventId %08x."), TitleEventId, HILO32 (SD->EventId)); - return 0; //return empty string + return 0; //return empty string } if (CheckLevel(3)) { @@ -1318,7 +1339,7 @@ char *cFilterEEPG::GetSummaryTextNagra (const u_char * DataStart, long int Offse if (SD->AlwaysZero9 != 0) isyslog ("EEPGDEBUG: SummAlwaysZero9 is NOT ZERO:%x.", SD->AlwaysZero9); - if (SD->Always1 != 0x31) //1970 + if (SD->Always1 != 0x31) //1970 isyslog ("EEPGDEBUG: SummAlways1:%02x.", SD->Always1); if (SD->Always9 != 0x39) isyslog ("EEPGDEBUG: SummAlways9:%02x.", SD->Always9); @@ -1327,7 +1348,7 @@ char *cFilterEEPG::GetSummaryTextNagra (const u_char * DataStart, long int Offse if (SD->Always0 != 0x30) isyslog ("EEPGDEBUG: SummAlways0:%02x.", SD->Always0); - if (SD->Always0x01 != 0x01) // 0x01 byte + if (SD->Always0x01 != 0x01) // 0x01 byte isyslog ("EEPGDEBUG: Summ0x01 byte:%02x.", SD->Always0x01); } u_char *p2 = (u_char *) DataStart + HILO32 (SD->SummTxtOffset); @@ -1336,22 +1357,22 @@ char *cFilterEEPG::GetSummaryTextNagra (const u_char * DataStart, long int Offse HILO32 (SD->EventId), SD->NumberOfBlocks, HILO32 (SD->BlockId), HILO32 (SD->SummTxtOffset), *p2, SD->Unknown1, SD->Unknown2); */ - unsigned char *Text = NULL; //makes first realloc work like malloc - int TotLength = 0; //and also makes empty summaries if *p2 != 0x4e + unsigned char *Text = NULL; //makes first realloc work like malloc + int TotLength = 0; //and also makes empty summaries if *p2 != 0x4e if (SD->NumberOfBlocks > 1) { switch (*p2) { - case 0x4e: //valid summary text follows - { //prevents compiler from complaining + case 0x4e: //valid summary text follows + { bool LastTextBlock = false; - do { //for all text parts + do { //for all text parts sSummaryTextNagraGuide *ST = (sSummaryTextNagraGuide *) p2; - p2 += 8; //skip fixed block + p2 += 8; //skip fixed block if (ST->AlwaysZero1 != 0) LogD(3, prep("DEBUG: ST AlwaysZero1 is NOT ZERO:%x."), ST->AlwaysZero1); if (ST->Always0x4e != 0x4e) { LogI(0, prep("DEBUG: ST Always0x4e is NOT 0x4e:%x."), ST->AlwaysZero1); - return 0; //fatal error, empty text + return 0; //fatal error, empty text } LogI(5, prep("DEBUG: Textnr %i, Lasttxt %i."), ST->TextNr, ST->LastTextNr); int SummaryLength = ST->Textlength; @@ -1359,25 +1380,25 @@ char *cFilterEEPG::GetSummaryTextNagra (const u_char * DataStart, long int Offse Text = (unsigned char *) realloc (Text, SummaryLength + TotLength); if (Text == NULL) { LogI(0, prep("Summaries memory allocation error.")); - return 0; //empty text + return 0; //empty text } - memcpy (Text + TotLength, p2, SummaryLength); //append new textpart + memcpy (Text + TotLength, p2, SummaryLength); //append new textpart TotLength += SummaryLength; - p2 += ST->Textlength; //skip text + p2 += ST->Textlength; //skip text LastTextBlock = ((ST->LastTextNr == 0) || (ST->TextNr >= ST->LastTextNr)); } while (!LastTextBlock); - Text = (unsigned char *) realloc (Text, 1 + TotLength); //allocate 1 extra byte - Text[TotLength] = NULL; //terminate string by NULL char + Text = (unsigned char *) realloc (Text, 1 + TotLength); //allocate 1 extra byte + Text[TotLength] = NULL; //terminate string by NULL char LogD(5, prep("DEBUG: Full Text:%s."), Text); break; - } //prevents compiler from complaining - case 0x8c: //"Geen uitzending" "Geen informatie beschikbaar" e.d. - { //prevents compiler from complaining + } + case 0x8c: //"Geen uitzending" "Geen informatie beschikbaar" e.d. + { sSummaryGBRNagraGuide *GBR = (sSummaryGBRNagraGuide *) p2; - p2 += 16; //skip fixed part, point to byte after Nextlength + p2 += 16; //skip fixed part, point to byte after Nextlength if (CheckLevel(3)) { if (GBR->AlwaysZero1 != 0) isyslog ("EEPGDEBUG: GBR AlwaysZero1 is NOT ZERO:%x.", GBR->AlwaysZero1); @@ -1393,39 +1414,39 @@ char *cFilterEEPG::GetSummaryTextNagra (const u_char * DataStart, long int Offse for (int i = 0; i < GBR->Nextlength; i += 2) isyslog ("GBR Extradata %02x %02x.", *(p2 + i), *(p2 + i + 1)); } - } //prevents compiler from complaining + } break; default: LogE(0, prep("ERROR *p2 has strange value: EventId %08x NumberOfBlocks %02x BlockId %08x SummTxtOffset %08x *p2: %02x Unkn1:%02x, Unkn2:%02x."), HILO32 (SD->EventId), SD->NumberOfBlocks, HILO32 (SD->BlockId), HILO32 (SD->SummTxtOffset), *p2, SD->Unknown1, SD->Unknown2); break; - } //end of switch - } //NrOfBlocks > 1 + } //end of switch + } //NrOfBlocks > 1 if (TotLength == 0) Text = NULL; - p += 29; //skip fixed part of block + p += 29; //skip fixed part of block if (SD->NumberOfBlocks == 1) - p -= 4; //in this case there is NO summarytext AND no GBR??!! + p -= 4; //in this case there is NO summarytext AND no GBR??!! for (int i = 1; i < (SD->NumberOfBlocks - 1); i++) { LogD(3, prep("DEBUG: Extra Blockinfo: %02x %02x %02x %02x."), *p, *(p + 1), *(p + 2), *(p + 3)); - p += 4; //skip this extra blockinfo + p += 4; //skip this extra blockinfo } return (char *) Text; } -void cFilterEEPG::PrepareToWriteToSchedule (sChannel * C, cSchedules * s, cSchedule * ps[MAX_EQUIVALENCES]) //gets a channel and returns an array of schedules that WriteToSchedule can write to. Call this routine before a batch of titles with the same ChannelId will be WriteToScheduled; batchsize can be 1 +void cFilterEEPG::PrepareToWriteToSchedule (sChannel * C, cSchedules * s, cSchedule * ps[MAX_EQUIVALENCES]) //gets a channel and returns an array of schedules that WriteToSchedule can write to. Call this routine before a batch of titles with the same ChannelId will be WriteToScheduled; batchsize can be 1 { for (int eq = 0; eq < C->NumberOfEquivalences; eq++) { tChannelID channelID = tChannelID (C->Src[eq], C->Nid[eq], C->Tid[eq], C->Sid[eq]); #ifdef USE_NOEPG if (allowedEPG (channelID) && (channelID.Valid ())) #else - if (channelID.Valid ()) //only add channels that are known to vdr + if (channelID.Valid ()) //only add channels that are known to vdr #endif /* NOEPG */ - ps[eq] = s->AddSchedule (channelID); //open a a schedule for each equivalent channel + ps[eq] = s->AddSchedule (channelID); //open a a schedule for each equivalent channel else { ps[eq] = NULL; LogE(5, prep("ERROR: Titleblock has invalid (equivalent) channel ID: Equivalence: %i, Source:%x, C->Nid:%x,C->Tid:%x,C->Sid:%x."), @@ -1443,8 +1464,13 @@ void cFilterEEPG::FinishWriteToSchedule (sChannel * C, cSchedules * s, cSchedule } } -void cFilterEEPG::WriteToSchedule (cSchedule * ps[MAX_EQUIVALENCES], unsigned short int NumberOfEquivalences, unsigned int EventId, unsigned int StartTime, unsigned int Duration, char *Text, char *SummText, unsigned short int ThemeId, unsigned short int TableId, unsigned short int Version, char Rating) //ps points to array of schedules ps[eq], where eq is equivalence number of the channel. If channelId is invalid then ps[eq]=NULL -//Duration in minutes +/** + * \brief write event to schedule + * + * \param Duration the Duration of the event in minutes + * \param ps points to array of schedules ps[eq], where eq is equivalence number of the channel. If channelId is invalid then ps[eq]=NULL + */ +void cFilterEEPG::WriteToSchedule (cSchedule * ps[MAX_EQUIVALENCES], unsigned short int NumberOfEquivalences, unsigned int EventId, unsigned int StartTime, unsigned int Duration, char *Text, char *SummText, unsigned short int ThemeId, unsigned short int TableId, unsigned short int Version, char Rating) { bool WrittenTitle = false; bool WrittenSummary = false; @@ -1452,18 +1478,18 @@ void cFilterEEPG::WriteToSchedule (cSchedule * ps[MAX_EQUIVALENCES], unsigned sh if (ps[eq]) { cEvent *Event = NULL; - Event = (cEvent *) ps[eq]->GetEvent (EventId); //since Nagra uses consistent EventIds, try this first + Event = (cEvent *) ps[eq]->GetEvent (EventId); //since Nagra uses consistent EventIds, try this first bool TableIdMatches = false; if (Event) TableIdMatches = (Event->TableID() == TableId); - if (!Event || !TableIdMatches || abs(Event->StartTime() - (time_t) StartTime) > Duration * 60) //if EventId does not match, or it matched with wrong TableId, then try with StartTime + if (!Event || !TableIdMatches || abs(Event->StartTime() - (time_t) StartTime) > Duration * 60) //if EventId does not match, or it matched with wrong TableId, then try with StartTime Event = (cEvent *) ps[eq]->GetEvent (EventId, StartTime); cEvent *newEvent = NULL; - if (!Event) { //event is new + if (!Event) { //event is new Event = newEvent = new cEvent (EventId); Event->SetSeen (); - } else if (Event->TableID() < TableId) { //existing table may not be overwritten + } else if (Event->TableID() < TableId) { //existing table may not be overwritten RejectTableId++; //esyslog ("EEPGDEBUG: Rejecting Event, existing TableID:%x, new TableID:%x.", Event->TableID (), // TableId); @@ -1471,9 +1497,9 @@ void cFilterEEPG::WriteToSchedule (cSchedule * ps[MAX_EQUIVALENCES], unsigned sh } if (Event) { - Event->SetEventID (EventId); //otherwise the summary cannot be added later - Event->SetTableID (TableId); //TableID 0 is reserved for external epg, will not be overwritten; the lower the TableID, the more actual it is - Event->SetVersion (Version); //TODO use version and tableID to decide whether to update; TODO add language code + Event->SetEventID (EventId); //otherwise the summary cannot be added later + Event->SetTableID (TableId); //TableID 0 is reserved for external epg, will not be overwritten; the lower the TableID, the more actual it is + Event->SetVersion (Version); //TODO use version and tableID to decide whether to update; TODO add language code Event->SetStartTime (StartTime); Event->SetDuration (Duration * 60); if (Rating) { @@ -1509,32 +1535,37 @@ void cFilterEEPG::WriteToSchedule (cSchedule * ps[MAX_EQUIVALENCES], unsigned sh isyslog ("D %s\n", SummText); isyslog ("e\nc\n.\n"); } - } //if ps[eq] - } //for eq + } //if ps[eq] + } //for eq if (WrittenTitle) TitleCounter++; if (WrittenSummary) SummaryCounter++; } -void cFilterEEPG::GetTitlesNagra (const u_char * Data, int Length, unsigned short TableIdExtension) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed -{ //TableIdExtension is the TIE from the relevant summary sections! +/** + * \brief Get Nagra titles + * + * \param TableIdExtension the TIE from the relevant summary sections! + */ +void cFilterEEPG::GetTitlesNagra (const u_char * Data, int Length, unsigned short TableIdExtension) +{ u_char *p = (u_char *) Data; u_char *DataEnd = (u_char *) Data + Length; u_char *next_p; - unsigned short int MonthdayTitles = ((TableIdExtension & 0x1ff) >> 4); //Day is coded in day of the month + unsigned short int MonthdayTitles = ((TableIdExtension & 0x1ff) >> 4); //Day is coded in day of the month time_t timeLocal; struct tm *tmCurrent; timeLocal = time (NULL); - tmCurrent = gmtime (&timeLocal); //gmtime gives UTC; only used for getting current year and current day of the month... + tmCurrent = gmtime (&timeLocal); //gmtime gives UTC; only used for getting current year and current day of the month... unsigned short int CurrentMonthday = tmCurrent->tm_mday; unsigned short int CurrentYear = tmCurrent->tm_year; unsigned short int CurrentMonth = tmCurrent->tm_mon; //esyslog("EEPGDEBUG: CurrentMonthday=%i, TableIdExtension:%04x, MonthdayTitles=%i.",CurrentMonthday,TableIdExtension, MonthdayTitles); cSchedulesLock SchedulesLock (true); cSchedules *s = (cSchedules *) cSchedules::Schedules (SchedulesLock); - do { //process each block of titles + do { //process each block of titles sTitleBlockNagraGuide *TB = (sTitleBlockNagraGuide *) p; int ChannelId = HILO16 (TB->ChannelId); int Blocklength = HILO16 (TB->Blocklength); @@ -1542,19 +1573,19 @@ void cFilterEEPG::GetTitlesNagra (const u_char * Data, int Length, unsigned shor LogD(3, prep("DEBUG: ChannelId %04x, Blocklength %04x, NumberOfTitles %lu."), ChannelId, Blocklength, NumberOfTitles); - p += 4; //skip ChannelId and Blocklength + p += 4; //skip ChannelId and Blocklength next_p = p + Blocklength; - if (next_p > DataEnd) { //only process if block is complete + if (next_p > DataEnd) { //only process if block is complete LogE(0, prep("ERROR, Block exceeds end of Data. p:%p, Blocklength:%x,DataEnd:%p."), p, Blocklength, DataEnd); - return; //fatal error, this should never happen + return; //fatal error, this should never happen } - p += 4; //skip Titlenumber + p += 4; //skip Titlenumber - sChannel *C = &sChannels[ChannelSeq[ChannelId]]; //find channel + sChannel *C = &sChannels[ChannelSeq[ChannelId]]; //find channel cSchedule *ps[MAX_EQUIVALENCES]; PrepareToWriteToSchedule (C, s, ps); - for (int i = 0; i < NumberOfTitles; i++) { //process each title within block + for (int i = 0; i < NumberOfTitles; i++) { //process each title within block sTitleNagraGuide *Title = (sTitleNagraGuide *) p; unsigned int EventId = HILO32 (Title->EventId); @@ -1567,14 +1598,14 @@ void cFilterEEPG::GetTitlesNagra (const u_char * Data, int Length, unsigned shor tmCurrent->tm_mon = CurrentMonth; tmCurrent->tm_mday = MonthdayTitles; tmCurrent->tm_hour = 0; - tmCurrent->tm_min = StartTime; //if starttime is bigger than 1 hour, mktime will correct this! + tmCurrent->tm_min = StartTime; //if starttime is bigger than 1 hour, mktime will correct this! tmCurrent->tm_sec = 0; - tmCurrent->tm_isdst = -1; //now correct with daylight savings - if (MonthdayTitles < CurrentMonthday - 7) //the titles that are older than one week are not from the past, but from next month! + tmCurrent->tm_isdst = -1; //now correct with daylight savings + if (MonthdayTitles < CurrentMonthday - 7) //the titles that are older than one week are not from the past, but from next month! //at first this was set at -1 day (= yesterday), but sometimes providers send old data which then //end up in next months schedule ... - tmCurrent->tm_mon++; //if a year border is passed, mktime will take care of this! - StartTime = UTC2LocalTime (mktime (tmCurrent)); //VDR stores its times in UTC, but wants its input in local time... + tmCurrent->tm_mon++; //if a year border is passed, mktime will take care of this! + StartTime = UTC2LocalTime (mktime (tmCurrent)); //VDR stores its times in UTC, but wants its input in local time... char *Text = NULL; u_char *t = (u_char *) Data + HILO32 (Title->OffsetToText); @@ -1583,7 +1614,7 @@ void cFilterEEPG::GetTitlesNagra (const u_char * Data, int Length, unsigned shor LogE(0, prep("ERROR, Title Text out of range: t:%p, DataEnd:%p, Data:%p, Length:%i."), t, DataEnd, Data, Length); else { - Asprintf (&Text, "%.*s", *t, t + 1); //FIXME second text string is not processed right now + Asprintf (&Text, "%.*s", *t, t + 1); //FIXME second text string is not processed right now //asprintf (&Text, "%.*s %.*s", *t, t + 1, *t2, t2 + 1); //now get summary texts @@ -1600,7 +1631,7 @@ void cFilterEEPG::GetTitlesNagra (const u_char * Data, int Length, unsigned shor HILO32 (Title->OffsetToText), HILO32 (Title->OffsetToText2), HILO32 (Title->SumDataOffset), Title->ThemeId, Text, SummText); - if (Themes[Title->ThemeId][0] == 0x00) //if detailed themeid is not known, get global themeid + if (Themes[Title->ThemeId][0] == 0x00) //if detailed themeid is not known, get global themeid Title->ThemeId &= 0xf0; WriteToSchedule (ps, C->NumberOfEquivalences, EventId, StartTime, Title->Duration, Text, SummText, Title->ThemeId, NAGRA_TABLE_ID, Version); @@ -1637,18 +1668,18 @@ void cFilterEEPG::GetTitlesNagra (const u_char * Data, int Length, unsigned shor if (Title->AlwaysZero11 != 0) isyslog ("EEPGDEBUG: TitleAlwaysZero11 is NOT ZERO:%x.", Title->AlwaysZero11); } - p += 30; //next title - } //end for titles + p += 30; //next title + } //end for titles FinishWriteToSchedule (C, s, ps); p = next_p; - } while (p < DataEnd); //end of TitleBlock + } while (p < DataEnd); //end of TitleBlock } -int cFilterEEPG::GetThemesNagra (const u_char * Data, int Length, unsigned short TableIdExtension) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +int cFilterEEPG::GetThemesNagra (const u_char * Data, int Length, unsigned short TableIdExtension) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed { u_char *DataStart = (u_char *) Data; - u_char *p = DataStart; //TODO Language code terminated by 0 is ignored + u_char *p = DataStart; //TODO Language code terminated by 0 is ignored u_char *DataEnd = DataStart + Length; u_char *DataStartTitles = buffer[TableIdExtension] + 4; u_char *DataEndTitles = DataStartTitles + bufsize[TableIdExtension] - 4; @@ -1658,7 +1689,7 @@ int cFilterEEPG::GetThemesNagra (const u_char * Data, int Length, unsigned short } int NumberOfThemes = (*p << 24) | *(p + 1) << 16 | *(p + 2) << 8 | *(p + 3); - p += 4; //skip number of themes block + p += 4; //skip number of themes block //isyslog ("EEPG: found %i themes.", NumberOfThemes); if ((nThemes == 0)) @@ -1666,40 +1697,40 @@ int cFilterEEPG::GetThemesNagra (const u_char * Data, int Length, unsigned short for (int i = 0; i < NumberOfThemes; i++) { int Textlength = *p; - p++; //skip textlength byte + p++; //skip textlength byte u_char *Text = p; u_char ThemeId = 0; - p += Textlength; //skip text + p += Textlength; //skip text int NrOfBlocks = (*p << 8) | *(p + 1); - p += 2; //skip nrofblocks + p += 2; //skip nrofblocks bool AnyDoubt = false; u_char *p2 = p; p += NrOfBlocks * 8; for (int j = 0; j < NrOfBlocks; j++) { sThemesTitlesNagraGuide *TT = (sThemesTitlesNagraGuide *) p2; - p2 += 8; //skip block + p2 += 8; //skip block u_char *NewThemeId = DataStartTitles + HILO32 (TT->TitleOffset) + 28; if (NewThemeId >= DataEndTitles) LogE(0, prep("ERROR, ThemeId out of range: NewThemeId:%p, DataEndTitles:%p, DataStartTitles:%p."), NewThemeId, DataEndTitles, DataStartTitles); else { //esyslog("EEPGDEBUG: NewThemeId:%02x, Text:%s.",*NewThemeId, Text); - if (Themes[*NewThemeId][0] != 0x00) { //theme is already filled, break off + if (Themes[*NewThemeId][0] != 0x00) { //theme is already filled, break off AnyDoubt = true; break; } - if (j == 0) //first block + if (j == 0) //first block ThemeId = *NewThemeId; - else if (ThemeId != *NewThemeId) { //different theme ids in block - if ((ThemeId & 0xf0) != (*NewThemeId & 0xf0)) { //major nible of themeid does not correspond + else if (ThemeId != *NewThemeId) { //different theme ids in block + if ((ThemeId & 0xf0) != (*NewThemeId & 0xf0)) { //major nible of themeid does not correspond LogE(3, prep("ERROR, Theme has multiple indices which differ in major nibble, old index = %x, new index = %x. Ignoring both indices."), ThemeId, *NewThemeId); AnyDoubt = true; break; - } else if ((ThemeId & 0x0f) != 0) //ThemeId is like 1a, 2a, not like 10,20. So it is minor in tree-structure, and it should be labeled in major part of tree - ThemeId = *NewThemeId; //lets hope new themeid is major, if not, it has not worsened.... + } else if ((ThemeId & 0x0f) != 0) //ThemeId is like 1a, 2a, not like 10,20. So it is minor in tree-structure, and it should be labeled in major part of tree + ThemeId = *NewThemeId; //lets hope new themeid is major, if not, it has not worsened.... } - } //else NewThemeId >= DataEndTitles + } //else NewThemeId >= DataEndTitles if (CheckLevel(3)) { if (TT->Always1 != 1) isyslog ("EEPGDEBUG: TT Always1 is NOT 1:%x.", TT->Always1); @@ -1708,23 +1739,23 @@ int cFilterEEPG::GetThemesNagra (const u_char * Data, int Length, unsigned short if (TT->AlwaysZero2 != 0) isyslog ("EEPGDEBUG: TT AlwaysZero2 is NOT ZERO:%x.", TT->AlwaysZero2); } - } //for nrofblocks + } //for nrofblocks // esyslog("EEPGDEBUG: AnyDoubt:%x.",AnyDoubt); if (!AnyDoubt) { if (Textlength > 63) - Textlength = 63; //leave room for trailing NULL + Textlength = 63; //leave room for trailing NULL if (Themes[ThemeId][0] != 0) { LogE(0, prep("Trying to add new theme, but Id already exists. ThemeId = %x, Old theme with this Id:%s, new theme: %s."), ThemeId, Themes[ThemeId], Text); continue; } memcpy (&Themes[ThemeId], Text, Textlength); - Themes[ThemeId][Textlength] = NULL; //trailing NULL + Themes[ThemeId][Textlength] = NULL; //trailing NULL CleanString (Themes[ThemeId]); nThemes++; LogI(1, prep("%02x %s"), ThemeId, Themes[ThemeId]); } - } //for NumberOfThemes + } //for NumberOfThemes if (p != DataEnd) { LogE(0, prep("Themes error: buffer is smaller or bigger than sum of entries. p:%p,DataEnd:%p"), p, DataEnd); return 0; @@ -1732,14 +1763,19 @@ int cFilterEEPG::GetThemesNagra (const u_char * Data, int Length, unsigned short return 2; } -int cFilterEEPG::GetChannelsNagra (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get Nagra channels + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetChannelsNagra (const u_char * Data, int Length) { u_char *DataStart = (u_char *) Data; u_char *p = DataStart; u_char *DataEnd = DataStart + Length; nChannels = (*p << 24) | *(p + 1) << 16 | *(p + 2) << 8 | *(p + 3); - p += 4; //skip numberofchannels + p += 4; //skip numberofchannels if (CheckLevel(1)) { isyslog ("| ID | %-26.26s | %-22.22s | FND | %-8.8s |\n", "Channel ID", "Channel Name", "Sky Num."); isyslog ("|------|-%-26.26s-|-%-22.22s-|-----|-%-8.8s-|\n", "------------------------------", @@ -1749,11 +1785,11 @@ int cFilterEEPG::GetChannelsNagra (const u_char * Data, int Length) //return cod for (int j = 0; j < nChannels; j++) { sChannelsNagraGuide *Channel = (sChannelsNagraGuide *) p; sChannel *C = &sChannels[j]; - C->ChannelId = j + 1; //Nagra starts numbering at 1 - ChannelSeq[C->ChannelId] = j; //fill lookup table to go from channel-id to sequence nr in table; lookuptable starts with 0 + C->ChannelId = j + 1; //Nagra starts numbering at 1 + ChannelSeq[C->ChannelId] = j; //fill lookup table to go from channel-id to sequence nr in table; lookuptable starts with 0 C->SkyNumber = 0; - C->NumberOfEquivalences = 1; //there is always an original channel. every equivalence adds 1 - C->Src[0] = Source (); //assume all EPG channels are on same satellite, if not, manage this via equivalents!!! + C->NumberOfEquivalences = 1; //there is always an original channel. every equivalence adds 1 + C->Src[0] = Source (); //assume all EPG channels are on same satellite, if not, manage this via equivalents!!! C->Nid[0] = HILO16 (Channel->NetworkId); C->Tid[0] = HILO16 (Channel->TransportId); C->Sid[0] = HILO16 (Channel->ServiceId); @@ -1761,12 +1797,12 @@ int cFilterEEPG::GetChannelsNagra (const u_char * Data, int Length) //return cod cChannel *VC = Channels.GetByChannelID (channelID, true); bool IsFound = (VC); - if (!IsFound) { //look on other satpositions + if (!IsFound) { //look on other satpositions for (int i = 0; i < NumberOfAvailableSources; i++) { channelID = tChannelID (AvailableSources[i], C->Nid[0], C->Tid[0], C->Sid[0]); VC = Channels.GetByChannelID (channelID, true); IsFound = (VC); - if (IsFound) { //found this actually on satellite nextdoor... + if (IsFound) { //found this actually on satellite nextdoor... C->Src[0] = AvailableSources[i]; break; } @@ -1775,7 +1811,7 @@ int cFilterEEPG::GetChannelsNagra (const u_char * Data, int Length) //return cod if (IsFound) strncpy ((char *) C->Name, VC->Name (), 64); else - C->Name[0] = NULL; //empty string + C->Name[0] = NULL; //empty string CleanString (C->Name); LogI(1, "|% 5d | %-26.26s | %-22.22s | %-3.3s | % 6d |\n", C->ChannelId @@ -1783,26 +1819,26 @@ int cFilterEEPG::GetChannelsNagra (const u_char * Data, int Length) //return cod LogD(4, prep("DEBUG: start : %s"), cs_hexdump (0, p, 9)); - p += 8; //skip to first 0x8c if non-FTA, or 0x00 if FTA + p += 8; //skip to first 0x8c if non-FTA, or 0x00 if FTA for (int i = 0; i < Channel->Nr8cBlocks; i++) { if (*p != 0x8c) { LogD(0, prep("DEBUG: ERROR in Channel Table, expected value of 0x8c is %02x"), *p); - return 0; //fatal error + return 0; //fatal error } - p++; //skip 8c byte + p++; //skip 8c byte LogD(4, prep("DEBUG: 8c string: %s"), cs_hexdump (0, p + 1, *p)); - p += *p; //skip 8c block - p++; //forgot to skip length byte + p += *p; //skip 8c block + p++; //forgot to skip length byte } //start last non 8c block here if (*p != 0x00) { LogE(0, prep("ERROR in Channel Table, expected value of 0x00 is %02x"), *p); - return 0; //fatal error + return 0; //fatal error } - p++; //skip 0x00 byte + p++; //skip 0x00 byte LogD(4, prep("DEBUG: endstring: %s"), cs_hexdump (0, p + 1, *p * 4)); - p += (*p * 4); //p points to nrofblocks, each block is 4 bytes - p++; //forgot to skip nrofblocks byte + p += (*p * 4); //p points to nrofblocks, each block is 4 bytes + p++; //forgot to skip nrofblocks byte /* if (Channel->AlwaysZero1 != 0) @@ -1831,14 +1867,19 @@ int cFilterEEPG::GetChannelsNagra (const u_char * Data, int Length) //return cod if (p != DataEnd) LogE(0, prep("Warning, possible problem at end of channel table; p = %p, DataEnd = %p"), p, DataEnd); LoadEquivalentChannels (); - return 2; //obviously, when you get here, channels are read succesfully, but since all channels are sent at once, you can stop now + return 2; //obviously, when you get here, channels are read succesfully, but since all channels are sent at once, you can stop now } -int cFilterEEPG::GetNagra (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get Nagra extended EPG + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetNagra (const u_char * Data, int Length) { sTitleBlockHeaderNagraGuide *TBH = (sTitleBlockHeaderNagraGuide *) Data; - if (InitialTitle[0] == 0x00) { //InitialTitle is empty, so we are waiting for the start marker - if (TBH->TableIdExtensionHigh == 0x00 && TBH->TableIdExtensionLow == 0x00) { //this is the start of the data + if (InitialTitle[0] == 0x00) { //InitialTitle is empty, so we are waiting for the start marker + if (TBH->TableIdExtensionHigh == 0x00 && TBH->TableIdExtensionLow == 0x00) { //this is the start of the data if (TBH->VersionNumber == LastVersionNagra) { LogI(0, prep("Nagra EEPG already up-to-date with version %i"), LastVersionNagra); return 2; @@ -1850,25 +1891,25 @@ int cFilterEEPG::GetNagra (const u_char * Data, int Length) //return code 0 = fa if (*p != 0x01) { LogE(0, prep("Error, Nagra first byte in table_id_extension 0x00 is not 0x01 but %02x. Format unknown, exiting."), *p); - return 0; //fatal error + return 0; //fatal error } - p++; //skip 0x01 byte + p++; //skip 0x01 byte unsigned short int l = ((*p << 8) | *(p + 1)); - u_char *p_end = p + l - 3; //this ensures a full block of 4 bytes is there to process - p += 2; //skip length bytes + u_char *p_end = p + l - 3; //this ensures a full block of 4 bytes is there to process + p += 2; //skip length bytes while (p < p_end) { sSection0000BlockNagraGuide *S = (sSection0000BlockNagraGuide *) p; int TTT = ((S->TableIdExtensionHigh << 10) | (S->TableIdExtensionLow << 3) | (S->TIE200 << 9)); LogD(4, prep("DEBUG: TableIdExtension %04x, Unknown1 %02x Version %02x Always 0xd6 %02x DayCounter %02x"), TTT, S->Unknown1, S->VersionNumber, S->Always0xd6, S->DayCounter); - if ((TTT > 0x0400) && (TTT < 0x0600)) //take high byte and compare with summarie tables in 0x0400 and 0x0500 range; - NagraTIE[NagraCounter++] = TTT; //only store TIEs of titlessummaries, all others can be derived; they are stored in the order of the 0x0000 index table, + if ((TTT > 0x0400) && (TTT < 0x0600)) //take high byte and compare with summarie tables in 0x0400 and 0x0500 range; + NagraTIE[NagraCounter++] = TTT; //only store TIEs of titlessummaries, all others can be derived; they are stored in the order of the 0x0000 index table, //lets hope first entry corresponds with today, next with tomorrow etc. p += 4; } - buffer.clear (); //clear buffer maps - bufsize.clear (); //clear buffer maps - InitialTitle[0] = 0xff; //copy data into initial title + buffer.clear (); //clear buffer maps + bufsize.clear (); //clear buffer maps + InitialTitle[0] = 0xff; //copy data into initial title } return (1); } @@ -1876,7 +1917,7 @@ int cFilterEEPG::GetNagra (const u_char * Data, int Length) //return code 0 = fa unsigned short TableIdExtension = HILO16 (TBH->TableIdExtension); if (TableIdExtension == 0x0000) { LastVersionNagra = Version; - return (2); //done + return (2); //done } /* Table_id_extensions: @@ -1900,11 +1941,11 @@ int cFilterEEPG::GetNagra (const u_char * Data, int Length) //return code 0 = fa (0x09f0) same day 31 of the month */ - if (!(TBH->TableIdExtensionHigh >= 0x02 && TBH->TableIdExtensionHigh <= 0x07)) //here we regulate which tables we are testing + if (!(TBH->TableIdExtensionHigh >= 0x02 && TBH->TableIdExtensionHigh <= 0x07)) //here we regulate which tables we are testing return (1); - if (TableIdExtension == 0x0200) //table 0x0200 only contains language code, because it is for day 0 of the month, and 0x0400 is used for channels + if (TableIdExtension == 0x0200) //table 0x0200 only contains language code, because it is for day 0 of the month, and 0x0400 is used for channels return 1; - if (TBH->SectionNumber == 0) { //first section, create a table + if (TBH->SectionNumber == 0) { //first section, create a table buffer[TableIdExtension] = NULL; bufsize[TableIdExtension] = 0; NumberOfTables++; @@ -1914,48 +1955,48 @@ int cFilterEEPG::GetNagra (const u_char * Data, int Length) //return code 0 = fa //GetEventId only works for a specific Schedule for a specific ChannelId.... buffer[TableIdExtension] = (unsigned char *) realloc (buffer[TableIdExtension], SectionLength - 9 + bufsize[TableIdExtension]); - memcpy (buffer[TableIdExtension] + bufsize[TableIdExtension], Data + 8, SectionLength - 9); //append new section + memcpy (buffer[TableIdExtension] + bufsize[TableIdExtension], Data + 8, SectionLength - 9); //append new section bufsize[TableIdExtension] += SectionLength - 9; if (TBH->SectionNumber >= TBH->LastSectionNumber) { LogI(1, prep("found %04x lastsection nr:%i."), TableIdExtension, TBH->SectionNumber); // if (TBH->TableIdExtensionHigh == 0x04 || TBH->TableIdExtensionHigh == 0x05) { if (TableIdExtension == 0x0400) { - int Result = GetChannelsNagra (buffer[TableIdExtension] + 4, bufsize[TableIdExtension] - 4); //TODO language code terminated by 0 is ignored + int Result = GetChannelsNagra (buffer[TableIdExtension] + 4, bufsize[TableIdExtension] - 4); //TODO language code terminated by 0 is ignored free (buffer[TableIdExtension]); buffer[TableIdExtension] = NULL; NumberOfTables--; if (Result == 0) - return 0; //fatal error; TODO this exit should also free all other, non-Channel sections that are stored! + return 0; //fatal error; TODO this exit should also free all other, non-Channel sections that are stored! } - } //if lastsection read - return (1); //return and continue, nonfatal + } //if lastsection read + return (1); //return and continue, nonfatal } void cFilterEEPG::ProcessNagra () { - for (int i = 0; i < MAX_THEMES; i++) //clear all themes + for (int i = 0; i < MAX_THEMES; i++) //clear all themes Themes[i][0] = NULL; - for (int i = 0; i < NagraCounter; i++) { //first prcoess all themes, since they all use the same codes + for (int i = 0; i < NagraCounter; i++) { //first prcoess all themes, since they all use the same codes unsigned short int TableIdExtension = NagraTIE[i]; - int TIE = TableIdExtension + 0x0200; //from 0x0400 to 0x0600 -> themes + int TIE = TableIdExtension + 0x0200; //from 0x0400 to 0x0600 -> themes LogI(3, prep("Processing Theme with TableIdExtension:%04x"), TIE); - GetThemesNagra (buffer[TIE] + 4, bufsize[TIE] - 4, TableIdExtension - 0x0200); //assume theme is completed //TODO Language code terminatd by 0 is ignored + GetThemesNagra (buffer[TIE] + 4, bufsize[TIE] - 4, TableIdExtension - 0x0200); //assume theme is completed //TODO Language code terminatd by 0 is ignored free (buffer[TIE]); buffer[TIE] = NULL; NumberOfTables--; } - for (int i = 0; i < NagraCounter; i++) { //first prcoess all themes, since they all use the same codes + for (int i = 0; i < NagraCounter; i++) { //first prcoess all themes, since they all use the same codes unsigned short int TableIdExtension = NagraTIE[i]; - int TIE = TableIdExtension - 0x0200; //from 0x0400 to 0x0200 -> titles + int TIE = TableIdExtension - 0x0200; //from 0x0400 to 0x0200 -> titles LogI(0, prep("Processing TableIdExtension:%04x"), TableIdExtension); - GetTitlesNagra (buffer[TIE] + 4, bufsize[TIE] - 4, TableIdExtension); //assume title-reading is completed //TODO Language code terminatd by 0 is ignored + GetTitlesNagra (buffer[TIE] + 4, bufsize[TIE] - 4, TableIdExtension); //assume title-reading is completed //TODO Language code terminatd by 0 is ignored free (buffer[TIE]); buffer[TIE] = NULL; NumberOfTables--; - free (buffer[TableIdExtension]); //summaries + free (buffer[TableIdExtension]); //summaries buffer[TableIdExtension] = NULL; NumberOfTables--; } @@ -1964,17 +2005,22 @@ void cFilterEEPG::ProcessNagra () NumberOfTables); } -int cFilterEEPG::GetTitlesMHW1 (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get MHW1 Titles + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetTitlesMHW1 (const u_char * Data, int Length) { if (Length >= 42) { sTitleMHW1 *Title = (sTitleMHW1 *) Data; - if (Title->ChannelId == 0xff) { //FF is separator packet - if (memcmp (InitialTitle, Data, 46) == 0) { //data is the same as initial title //TODO use easier notation + if (Title->ChannelId == 0xff) { //FF is separator packet + if (memcmp (InitialTitle, Data, 46) == 0) { //data is the same as initial title //TODO use easier notation LogD(1, prep("End procesing titles")); return 2; } if (nTitles == 0) - memcpy (InitialTitle, Data, 46); //copy data into initial title + memcpy (InitialTitle, Data, 46); //copy data into initial title int Day = Title->Day; int Hours = Title->Hours; if (Hours > 15) @@ -1994,7 +2040,7 @@ int cFilterEEPG::GetTitlesMHW1 (const u_char * Data, int Length) //return code 0 //Day = 8; MHWStartTime = (Day * 86400) + (Hours * 3600) + YesterdayEpochUTC; LogI(3, prep("Titles: FF PACKET, seqnr:%02x."), Data[5]); - } else if (InitialTitle[0] != 0x00) { //if initialized this should always be 0x90 = tableid! + } else if (InitialTitle[0] != 0x00) { //if initialized this should always be 0x90 = tableid! if (nTitles < MAX_TITLES) { Title_t *T; T = (Title_t *) malloc (sizeof (Title_t)); @@ -2004,9 +2050,9 @@ int cFilterEEPG::GetTitlesMHW1 (const u_char * Data, int Length) //return code 0 T->ChannelId = Title->ChannelId - 1; T->ThemeId = Title->ThemeId; T->TableId = Title->TableId; - T->MjdTime = 0; //only used at MHW2 and SKY + T->MjdTime = 0; //only used at MHW2 and SKY T->EventId = HILO32 (Title->ProgramId); - T->StartTime = LocalTime2UTC (StartTime); //here also Daylight Savings correction is done + T->StartTime = LocalTime2UTC (StartTime); //here also Daylight Savings correction is done T->Duration = HILO16 (Title->Duration) * 60; T->SummaryAvailable = Title->SummaryAvailable; T->Text = (unsigned char *) malloc (47); @@ -2014,29 +2060,34 @@ int cFilterEEPG::GetTitlesMHW1 (const u_char * Data, int Length) //return code 0 LogE(0, prep("Titles memory allocation error.")); return 0; } - T->Text[46] = NULL; //end string with NULL character + T->Text[46] = NULL; //end string with NULL character //memcpy (T->Text, &Title->Title, 23); decodeText2((unsigned char *)&Title->Title, 23, (char*)T->Text, 47); CleanString (T->Text); LogI(3, prep("EvId:%08x,ChanId:%x, Titlenr:%d:, StartTime(epoch):%i, SummAv:%x,Name:%s."), T->EventId, T->ChannelId, nTitles, T->StartTime, T->SummaryAvailable, T->Text); nTitles++; - } //nTitles < MaxTitles + } //nTitles < MaxTitles else { LogE(0, prep("Error, %i titles found more than %i"), nTitles, MAX_TITLES); return 0; } - } //else if InitialTitle - } //Length==46 + } //else if InitialTitle + } //Length==46 else { LogE(0, prep("Error, length of title package < 42.")); - return 1; //non fatal + return 1; //non fatal } return 1; } -int cFilterEEPG::GetTitlesMHW2 (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get MHW2 Titles + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetTitlesMHW2 (const u_char * Data, int Length) { if (Length > 18) { int Pos = 18; @@ -2053,22 +2104,22 @@ int cFilterEEPG::GetTitlesMHW2 (const u_char * Data, int Length) //return code 0 Pos += 4; if (Pos < Length) { if (Data[Pos] == 0xff) { - Pos += 1; - Check = true; + Pos += 1; + Check = true; } } } } if (Check == false){ isyslog ("EEPGDebug: Check==false"); - return 1; // I assume nonfatal error or success + return 1; // I assume nonfatal error or success } }*/ - if (memcmp (InitialTitle, Data, 16) == 0) { //data is the same as initial title - return 2; //last item processed + if (memcmp (InitialTitle, Data, 16) == 0) { //data is the same as initial title + return 2; //last item processed } else { if (nTitles == 0) - memcpy (InitialTitle, Data, 16); //copy data into initial title + memcpy (InitialTitle, Data, 16); //copy data into initial title //Pos = 18; while (Pos < Length) { Title_t *T; @@ -2078,7 +2129,7 @@ int cFilterEEPG::GetTitlesMHW2 (const u_char * Data, int Length) //return code 0 Pos+=11;//The date time starts here //isyslog ("EEPGDebug: ChannelID:%d", T->ChannelId); unsigned int MjdTime = (Data[Pos] << 8) | Data[Pos + 1]; - T->MjdTime = 0; //not used for matching MHW2 + T->MjdTime = 0; //not used for matching MHW2 T->StartTime = ((MjdTime - 40587) * 86400) + (((((Data[Pos + 2] & 0xf0) >> 4) * 10) + (Data[Pos + 2] & 0x0f)) * 3600) + (((((Data[Pos + 3] & 0xf0) >> 4) * 10) + (Data[Pos + 3] & 0x0f)) * 60); @@ -2088,9 +2139,9 @@ int cFilterEEPG::GetTitlesMHW2 (const u_char * Data, int Length) //return code 0 T->Text = (unsigned char *) malloc (Len + 2); if (T->Text == NULL) { LogE(0, prep("Titles memory allocation error.")); - return 0; //fatal error + return 0; //fatal error } - T->Text[Len] = NULL; //end string with NULL character + T->Text[Len] = NULL; //end string with NULL character decodeText2(&Data[Pos + 8],Len,(char*)T->Text,Len+1); //memcpy (T->Text, &Data[Pos + 8], Len); CleanString (T->Text); @@ -2104,27 +2155,32 @@ int cFilterEEPG::GetTitlesMHW2 (const u_char * Data, int Length) //return code 0 nTitles++; if (nTitles > MAX_TITLES) { LogE(0, prep("Error, %i titles found more than %i"), nTitles, MAX_TITLES); - return 0; //fatal error + return 0; //fatal error } } - return 1; //success - } //else memcmp - } //if length - return 1; //non fatal error + return 1; //success + } //else memcmp + } //if length + return 1; //non fatal error } -int cFilterEEPG::GetSummariesMHW1 (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get MHW1 Summaries + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetSummariesMHW1 (const u_char * Data, int Length) { sSummaryMHW1 *Summary = (sSummaryMHW1 *) Data; if (Length >= 11) { - if (Summary->NumReplays < 10) { //Why limit this at 10? + if (Summary->NumReplays < 10) { //Why limit this at 10? if (Length >= (11 + (Summary->NumReplays * 7))) { if (Summary->Byte7 == 0xff && Summary->Byte8 == 0xff && Summary->Byte9 == 0xff) { - if (memcmp (InitialSummary, Data, 20) == 0) { //data is equal to initial buffer + if (memcmp (InitialSummary, Data, 20) == 0) { //data is equal to initial buffer return 2; } else if (nSummaries < MAX_TITLES) { if (nSummaries == 0) - memcpy (InitialSummary, Data, 20); //copy this data in initial buffer + memcpy (InitialSummary, Data, 20); //copy this data in initial buffer int SummaryOffset = 11 + (Summary->NumReplays * 7); int SummaryLength = Length - SummaryOffset; unsigned char *Text = (unsigned char *) malloc (2*SummaryLength + 1); @@ -2132,10 +2188,10 @@ int cFilterEEPG::GetSummariesMHW1 (const u_char * Data, int Length) //return cod LogE(0, prep("Summaries memory allocation error.")); return 0; } - Text[SummaryLength+1] = NULL; //end string with NULL character + Text[SummaryLength+1] = NULL; //end string with NULL character //memcpy (Text, &Data[SummaryOffset], SummaryLength); decodeText2(&Data[SummaryOffset], SummaryLength, (char*)Text, 2*SummaryLength + 1); -// CleanString (Text); +// CleanString (Text); // if (Summary->NumReplays != 0) // esyslog ("EEPG: Number of replays:%i.", Summary->NumReplays); //int Replays = Summary->NumReplays; @@ -2148,9 +2204,9 @@ int cFilterEEPG::GetSummariesMHW1 (const u_char * Data, int Length) //return cod S->Text = Text; int i = 0; do { - S->Replays[i].MjdTime = 0; //only used for SKY + S->Replays[i].MjdTime = 0; //only used for SKY //if (Summary->NumReplays == 0) { - //S->ChannelId = 0xFFFF; //signal that ChannelId is not known; 0 is bad signal value because it is a valid ChannelId... + //S->ChannelId = 0xFFFF; //signal that ChannelId is not known; 0 is bad signal value because it is a valid ChannelId... //S->StartTime = 0; //} //else { @@ -2160,8 +2216,8 @@ int cFilterEEPG::GetSummariesMHW1 (const u_char * Data, int Length) //return cod unsigned short int Hour = Data[ReplayOffset++]; unsigned short int Minute = Data[ReplayOffset++]; unsigned short int Sec = Data[ReplayOffset++]; - ReplayOffset++; //makes total of 7 bytes - + ReplayOffset++; //makes total of 7 bytes + LogI(4, prep("EvId:%08x ChanId:%x, ChanName %s, Time: %02d:%02d:%02d."), S->EventId, S->Replays[i].ChannelId, sChannels[ChannelSeq[S->Replays[i].ChannelId]].Name, Hour, Minute, Sec); @@ -2175,45 +2231,50 @@ int cFilterEEPG::GetSummariesMHW1 (const u_char * Data, int Length) //return cod i++; } while (i < Summary->NumReplays); //} while (Replays-- >= 0); - LogI(3, prep("EvId:%08x ChanId:%x, Replays:%d, Summnr %d:%.35s."), S->EventId, + LogI(3, prep("EvId:%08x ChanId:%x, Replays:%d, Summnr %d:%.35s."), S->EventId, S->Replays[0].ChannelId, S->NumReplays, nSummaries, S->Text); nSummaries++; } else { LogE(0, prep("Error, %i summaries found more than %i"), nSummaries, MAX_TITLES); return 0; } - } //0xff + } //0xff else { LogE(0, prep("Warning, Summary bytes not as expected.")); - return 1; //it is not a success, but error is not fatal + return 1; //it is not a success, but error is not fatal } - } //numreplays length + } //numreplays length else { LogE(0, prep("Warning, number of replays is not conforming to length.")); - return 1; //nonfatal error + return 1; //nonfatal error } - } //numreplays <10 + } //numreplays <10 else { LogE(0, prep("Warning, number of replays %d > 10, cannot process."), Summary->NumReplays); - return 1; //nonfatal error + return 1; //nonfatal error } - } //length >11 + } //length >11 else { LogE(0, prep("Summary length too small:%s"), cs_hexdump (0, Data, Length)); - return 1; //nonfatal error + return 1; //nonfatal error } - return 1; //success + return 1; //success } -int cFilterEEPG::GetSummariesMHW2 (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get MHW2 Summaries + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetSummariesMHW2 (const u_char * Data, int Length) { if (Length > (Data[14] + 17)) { - if (memcmp (InitialSummary, Data, 16) == 0) //data is equal to initial buffer + if (memcmp (InitialSummary, Data, 16) == 0) //data is equal to initial buffer return 2; else { if (nSummaries == 0) - memcpy (InitialSummary, Data, 16); //copy this data in initial buffer + memcpy (InitialSummary, Data, 16); //copy this data in initial buffer if (nSummaries < MAX_TITLES) { int lenText = Data[14]; int SummaryLength = lenText; @@ -2223,12 +2284,12 @@ int cFilterEEPG::GetSummariesMHW2 (const u_char * Data, int Length) //return cod S = (Summary_t *) malloc (sizeof (Summary_t)); Summaries[nSummaries] = S; - S->Replays[0].ChannelId = 0xFFFF; //signal that ChannelId is not known; 0 is bad signal value because it is a valid ChannelId... - S->Replays[0].StartTime = 0; //not used - S->Replays[0].MjdTime = 0; //not used - S->NumReplays = 0; //not used + S->Replays[0].ChannelId = 0xFFFF; //signal that ChannelId is not known; 0 is bad signal value because it is a valid ChannelId... + S->Replays[0].StartTime = 0; //not used + S->Replays[0].MjdTime = 0; //not used + S->NumReplays = 0; //not used S->EventId = (Data[3] << 8) | Data[4]; - unsigned char tmp[4096]; //TODO do this smarter + unsigned char tmp[4096]; //TODO do this smarter memcpy (tmp, &Data[Pos], lenText); tmp[SummaryLength] = '\n'; SummaryLength += 1; @@ -2251,10 +2312,10 @@ int cFilterEEPG::GetSummariesMHW2 (const u_char * Data, int Length) //return cod } } S->Text = (unsigned char *) malloc (SummaryLength + 2); - S->Text[SummaryLength] = NULL; //end string with NULL character + S->Text[SummaryLength] = NULL; //end string with NULL character if (S->Text == NULL) { LogE(0, prep("Summaries memory allocation error.")); - return 0; //fatal error + return 0; //fatal error } //memcpy (S->Text, tmp, SummaryLength); decodeText2(tmp,SummaryLength,(char*)S->Text,SummaryLength + 1); @@ -2263,22 +2324,27 @@ int cFilterEEPG::GetSummariesMHW2 (const u_char * Data, int Length) //return cod nSummaries++; } else { LogE(0, prep("Error, %i summaries found more than %i"), nSummaries, MAX_TITLES); - return 0; //fatal error + return 0; //fatal error } - } //else - } //if length - return 1; //succes or nonfatal error + } //else + } //if length + return 1; //succes or nonfatal error } -int cFilterEEPG::GetChannelsSKYBOX (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get SKYBOX Channels + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetChannelsSKYBOX (const u_char * Data, int Length) { - if (memcmp (InitialChannel, Data, 8) == 0) { //data is the same as initial title + if (memcmp (InitialChannel, Data, 8) == 0) { //data is the same as initial title LoadEquivalentChannels (); return 2; } else { if (nChannels == 0) - memcpy (InitialChannel, Data, 8); //copy data into initial title + memcpy (InitialChannel, Data, 8); //copy data into initial title if (nChannels == 0) { LogI(1, "| ID | %-26.26s | %-22.22s | FND | %-8.8s |\n", "Channel ID", "Channel Name", "Sky Num."); LogI(1, "|------|-%-26.26s-|-%-22.22s-|-----|-%-8.8s-|\n", "------------------------------", @@ -2302,7 +2368,7 @@ int cFilterEEPG::GetChannelsSKYBOX (const u_char * Data, int Length) //return co int p3 = (p2 + 2); p2 += (DescriptorLength + 2); TransportDescriptorsLength -= (DescriptorLength + 2); - switch (DescriptorTag) { //TODO switch with only 1 case??? replace this by template + switch (DescriptorTag) { //TODO switch with only 1 case??? replace this by template case 0xb1: p3 += 2; DescriptorLength -= 2; @@ -2318,11 +2384,11 @@ int cFilterEEPG::GetChannelsSKYBOX (const u_char * Data, int Length) //return co if (SkyNumber > 100 && SkyNumber < 1000) { if (ChannelId > 0) { sChannel *C; - if (ChannelSeq.count (ChannelId) == 0) { //not found + if (ChannelSeq.count (ChannelId) == 0) { //not found C = &sChannels[nChannels]; C->ChannelId = ChannelId; - C->NumberOfEquivalences = 1; //there is always an original channel. every equivalence adds 1 - C->Src[0] = Source (); //assume all EPG channels are on same satellite, if not, manage this via equivalents!!! + C->NumberOfEquivalences = 1; //there is always an original channel. every equivalence adds 1 + C->Src[0] = Source (); //assume all EPG channels are on same satellite, if not, manage this via equivalents!!! C->Nid[0] = Nid; C->Tid[0] = Tid; C->Sid[0] = Sid; @@ -2333,12 +2399,12 @@ int cFilterEEPG::GetChannelsSKYBOX (const u_char * Data, int Length) //return co if (IsFound) strncpy ((char *) C->Name, VC->Name (), 64); else - C->Name[0] = NULL; //empty string + C->Name[0] = NULL; //empty string LogI(1, "|% 5d | %-26.26s | %-22.22s | %-3.3s | % 6d |\n", C->ChannelId , *channelID.ToString(), C->Name, IsFound ? "YES" : "NO", C->SkyNumber); - ChannelSeq[C->ChannelId] = nChannels; //fill lookup table to go from channel-id to sequence nr in table + ChannelSeq[C->ChannelId] = nChannels; //fill lookup table to go from channel-id to sequence nr in table nChannels++; if (nChannels >= MAX_CHANNELS) { LogE(0, prep("Error, %i channels found more than %i"), nChannels, MAX_CHANNELS); @@ -2353,14 +2419,19 @@ int cFilterEEPG::GetChannelsSKYBOX (const u_char * Data, int Length) //return co break; default: break; - } //switch descriptortag + } //switch descriptortag } - } //while + } //while return 1; - } //else part of memcmp + } //else part of memcmp } -int cFilterEEPG::GetTitlesSKYBOX (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get SKYBOX Titles + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetTitlesSKYBOX (const u_char * Data, int Length) { int p; unsigned short int ChannelId; @@ -2369,12 +2440,12 @@ int cFilterEEPG::GetTitlesSKYBOX (const u_char * Data, int Length) //return code int Len2; if (Length < 20) - return 1; //nonfatal error - if (memcmp (InitialTitle, Data, 20) == 0) //data is the same as initial title + return 1; //nonfatal error + if (memcmp (InitialTitle, Data, 20) == 0) //data is the same as initial title return 2; else { if (nTitles == 0) - memcpy (InitialTitle, Data, 20); //copy data into initial title + memcpy (InitialTitle, Data, 20); //copy data into initial title ChannelId = (Data[3] << 8) | Data[4]; MjdTime = ((Data[8] << 8) | Data[9]); if (ChannelId > 0) { @@ -2385,7 +2456,7 @@ int cFilterEEPG::GetTitlesSKYBOX (const u_char * Data, int Length) //return code T = (Title_t *) malloc (sizeof (Title_t)); Titles[nTitles] = T; T->ChannelId = ChannelId; - T->MjdTime = MjdTime; //only date, no time. Is used to match titles and summaries, SKYBOX only + T->MjdTime = MjdTime; //only date, no time. Is used to match titles and summaries, SKYBOX only T->EventId = (Data[p] << 8) | Data[p + 1]; Len1 = ((Data[p + 2] & 0x0f) << 8) | Data[p + 3]; if (Data[p + 4] != 0xb5) { @@ -2423,24 +2494,24 @@ int cFilterEEPG::GetTitlesSKYBOX (const u_char * Data, int Length) //return code T->Rating = 0x00; //"-" break; } - T->Unknown1 = Data[p + 4 - 13]; //FIXME - T->Unknown2 = Data[p + 4 - 12]; //FIXME - T->Unknown3 = Data[p + 4 - 11]; //FIXME - unsigned char tmp[4096]; //TODO smarter + T->Unknown1 = Data[p + 4 - 13]; //FIXME + T->Unknown2 = Data[p + 4 - 12]; //FIXME + T->Unknown3 = Data[p + 4 - 11]; //FIXME + unsigned char tmp[4096]; //TODO smarter Len2 = DecodeHuffmanCode (&Data[p + 9], Len2, tmp); if (Len2 == 0) { LogE(0, prep("Warning, could not huffman-decode title-text, skipping title.")); - return 1; //non-fatal error + return 1; //non-fatal error } T->Text = (unsigned char *) malloc (Len2 + 1); if (T->Text == NULL) { LogE(0, prep("Titles memory allocation error.")); return 0; } - T->Text[Len2] = NULL; //end string with NULL character + T->Text[Len2] = NULL; //end string with NULL character memcpy (T->Text, tmp, Len2); CleanString (T->Text); - T->SummaryAvailable = 1; //TODO I assume this is true? + T->SummaryAvailable = 1; //TODO I assume this is true? LogI(3, prep("EventId %08x Titlenr %d,Unknown1:%x,Unknown2:%x,Un3:%x,Name:%s."), T->EventId, nTitles, T->Unknown1, T->Unknown2, T->Unknown3, T->Text); @@ -2449,16 +2520,21 @@ int cFilterEEPG::GetTitlesSKYBOX (const u_char * Data, int Length) //return code nTitles++; if (nTitles >= MAX_TITLES) { LogE(0, prep("Error, %i titles found more than %i"), nTitles, MAX_TITLES); - return 0; //fatal error + return 0; //fatal error } } while (p < Length); } } } - return 1; //success + return 1; //success } -int cFilterEEPG::GetSummariesSKYBOX (const u_char * Data, int Length) //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed +/** + * \brief Get SKYBOX Summaries + * + * \return 0 = fatal error, code 1 = success, code 2 = last item processed + */ +int cFilterEEPG::GetSummariesSKYBOX (const u_char * Data, int Length) { int p; unsigned short int ChannelId; @@ -2467,14 +2543,14 @@ int cFilterEEPG::GetSummariesSKYBOX (const u_char * Data, int Length) //return c int Len2; if (Length < 20) { - return 1; //non fatal error I assume + return 1; //non fatal error I assume } - if (memcmp (InitialSummary, Data, 20) == 0) //data is equal to initial buffer + if (memcmp (InitialSummary, Data, 20) == 0) //data is equal to initial buffer return 2; // else if (nSummaries < MAX_SUMMARIES) { else { if (nSummaries == 0) - memcpy (InitialSummary, Data, 20); //copy this data in initial buffer + memcpy (InitialSummary, Data, 20); //copy this data in initial buffer ChannelId = (Data[3] << 8) | Data[4]; MjdTime = ((Data[8] << 8) | Data[9]); if (ChannelId > 0) { @@ -2486,7 +2562,7 @@ int cFilterEEPG::GetSummariesSKYBOX (const u_char * Data, int Length) //return c Summaries[nSummaries] = S; S->Replays[0].ChannelId = ChannelId; S->Replays[0].MjdTime = MjdTime; - S->NumReplays = 0; //not used + S->NumReplays = 0; //not used S->EventId = (Data[p] << 8) | Data[p + 1]; Len1 = ((Data[p + 2] & 0x0f) << 8) | Data[p + 3]; if (Data[p + 4] != 0xb9) { @@ -2499,11 +2575,11 @@ int cFilterEEPG::GetSummariesSKYBOX (const u_char * Data, int Length) //return c } p += 4; Len2 = Data[p + 1]; - unsigned char tmp[4096]; //TODO can this be done better? + unsigned char tmp[4096]; //TODO can this be done better? Len2 = DecodeHuffmanCode (&Data[p + 2], Len2, tmp); if (Len2 == 0) { LogE(0, prep("Warning, could not huffman-decode text, skipping summary.")); - return 1; //non-fatal error + return 1; //non-fatal error } S->Text = (unsigned char *) malloc (Len2 + 1); if (S->Text == NULL) { @@ -2511,7 +2587,7 @@ int cFilterEEPG::GetSummariesSKYBOX (const u_char * Data, int Length) //return c return 0; } memcpy (S->Text, tmp, Len2); - S->Text[Len2] = NULL; //end string with NULL character + S->Text[Len2] = NULL; //end string with NULL character CleanString (S->Text); LogI(3, prep("EventId %08x Summnr %d:%.30s."), S->EventId, nSummaries, S->Text); p += Len1; @@ -2530,13 +2606,13 @@ int cFilterEEPG::GetSummariesSKYBOX (const u_char * Data, int Length) //return c void cFilterEEPG::FreeSummaries (void) { if (Format == MHW1 || Format == MHW2 || Format == SKY_IT || Format == SKY_UK) { - Summary_t *S; //TODO do I need this? - Summary_t *S2; //TODO do I need this? + Summary_t *S; //TODO do I need this? + Summary_t *S2; //TODO do I need this? for (int i = 0; i < nSummaries; i++) { S = Summaries[i]; if (i < nSummaries - 1) { - S2 = Summaries[i + 1]; //look at next summary - if (S->Text != S2->Text && S->Text != 0x00) //this is the last summary that points to this textblock; needed in case NumReplays > 1, multiple pointers to same textblock + S2 = Summaries[i + 1]; //look at next summary + if (S->Text != S2->Text && S->Text != 0x00) //this is the last summary that points to this textblock; needed in case NumReplays > 1, multiple pointers to same textblock free (S->Text); } else if (S->Text != 0x00) free (S->Text); @@ -2586,7 +2662,7 @@ void cFilterEEPG::LoadIntoSchedule (void) S = Summaries[j]; foundtitle = false; - while ((i < nTitles) && (!foundtitle)) { //find next title that has summary + while ((i < nTitles) && (!foundtitle)) { //find next title that has summary T = Titles[i]; if (T->SummaryAvailable) foundtitle = true; @@ -2597,13 +2673,13 @@ void cFilterEEPG::LoadIntoSchedule (void) } //esyslog("foundtitle %x for next title that has a summary:%d",foundtitle,i); - if (!foundtitle) //no more titles with summaries - break; //TODO: does this work??? - if ((T->EventId == S->EventId) && (T->MjdTime == S->Replays[0].MjdTime) && ((T->ChannelId == S->Replays[0].ChannelId) || ((Format != SKY_IT) && (Format != SKY_UK)))) { //should always be true, titles and summaries are broadcasted in order... + if (!foundtitle) //no more titles with summaries + break; //TODO: does this work??? + if ((T->EventId == S->EventId) && (T->MjdTime == S->Replays[0].MjdTime) && ((T->ChannelId == S->Replays[0].ChannelId) || ((Format != SKY_IT) && (Format != SKY_UK)))) { //should always be true, titles and summaries are broadcasted in order... LogD(3, prep("T->EventId == S->EventId")); //MjdTime = 0 for all but SKY //S->ChannelId must be equal to T->ChannelId only for SKY; in MHW1 S->ChannelId overrides T->ChannelId when NumReplays > 1 - remembersummary = -1; //reset summary searcher + remembersummary = -1; //reset summary searcher //int Replays = S->NumReplays; int index = 0; @@ -2619,7 +2695,7 @@ void cFilterEEPG::LoadIntoSchedule (void) } //channelids are sequentially numbered and sent in MHW1 and MHW2, but not in SKY, so we need to lookup the table index - sChannel *C = &sChannels[ChannelSeq[ChannelId]]; //find channel + sChannel *C = &sChannels[ChannelSeq[ChannelId]]; //find channel cSchedule *p[MAX_EQUIVALENCES]; PrepareToWriteToSchedule (C, s, p); @@ -2637,37 +2713,37 @@ void cFilterEEPG::LoadIntoSchedule (void) FinishWriteToSchedule (C, s, p); //Replays--; - //if ((S->NumReplays != 0) && (Replays > 0)) { //when replays are used, all summaries of the replays are stored consecutively; currently only CSAT - //j++; //move to next summary - //if (j >= nSummaries) //do not forget to look in beginning of (ring)buffer + //if ((S->NumReplays != 0) && (Replays > 0)) { //when replays are used, all summaries of the replays are stored consecutively; currently only CSAT + //j++; //move to next summary + //if (j >= nSummaries) //do not forget to look in beginning of (ring)buffer //j = 0; - //S = Summaries[j]; //next summary within replay range + //S = Summaries[j]; //next summary within replay range //} index++; - } //while + } //while while (index < S->NumReplays); //TODO: why load events that have already past, and then run Cleanup //end of putting title and summary in schedule - i++; //move to next title - } //if T->EventId == S->EventId + i++; //move to next title + } //if T->EventId == S->EventId else { // esyslog("EEPG ERROR: ProgramIds not matching, title:%d,summary%d, T->EventId:%u, S->Eventid:%u.",i,j,T->EventId,S->EventId); NotMatching++; - if (remembersummary == -1) { //I am not in search loop yet + if (remembersummary == -1) { //I am not in search loop yet remembersummary = j; if (remembersummary == 0) - remembersummary = nSummaries; //or next test will never be succesfull for remembersummary = 0 + remembersummary = nSummaries; //or next test will never be succesfull for remembersummary = 0 LostSync++; // esyslog("EEPG Error: lost sync at title %d, summary %d.",i,j); - } else if (j == (remembersummary - 1)) { //the last summary to be checked has failed also + } else if (j == (remembersummary - 1)) { //the last summary to be checked has failed also //esyslog ("EEPG Error: could not find summary for summary-available Title %d.", i); esyslog ("EEPG: Error, summary not found for EventId %08x Titlenr %d:SummAv:%x,Unknown1:%x,Unknown2:%x,Un3:%x,Name:%s.", T->EventId, i, T->SummaryAvailable, T->Unknown1, T->Unknown2, T->Unknown3, T->Text); /* write Title info to schedule */ - sChannel *C = &sChannels[ChannelSeq[T->ChannelId]]; //find channel + sChannel *C = &sChannels[ChannelSeq[T->ChannelId]]; //find channel cSchedule *p[MAX_EQUIVALENCES]; PrepareToWriteToSchedule (C, s, p); char rating = 0x00; @@ -2679,20 +2755,20 @@ void cFilterEEPG::LoadIntoSchedule (void) FinishWriteToSchedule (C, s, p); SummariesNotFound++; - i++; //move to next title, for this one no summary can be found + i++; //move to next title, for this one no summary can be found } // esyslog("Trying again for this title %d, remember summary %d, but advancing one Summary to %d.",i,remembersummary,j); } - j++; //move to next summary - if (j >= nSummaries) //do not forget to look in beginning of (ring)buffer + j++; //move to next summary + if (j >= nSummaries) //do not forget to look in beginning of (ring)buffer j = 0; - } //while title - } // if s + } //while title + } // if s else esyslog ("EEPG Error: could not lock schedules."); - cSchedules::Cleanup (true); //deletes all past events + cSchedules::Cleanup (true); //deletes all past events isyslog ("EEPG: found %i equivalents channels", nEquivChannels); isyslog ("EEPG: found %i themes", nThemes); @@ -2706,9 +2782,9 @@ void cFilterEEPG::LoadIntoSchedule (void) LogI (0, prep("Warning: lost sync %i times, summary did not match %i times."), LostSync, NotMatching); - FreeSummaries (); //do NOT free channels, themes and bouquets here because they will be reused in SKY! + FreeSummaries (); //do NOT free channels, themes and bouquets here because they will be reused in SKY! FreeTitles (); - if (!((Format == SKY_IT) || (Format == SKY_UK))) { //everything but SKY; SKY is the only protocol where LoadIntoSchedule is called repeatedly + if (!((Format == SKY_IT) || (Format == SKY_UK))) { //everything but SKY; SKY is the only protocol where LoadIntoSchedule is called repeatedly ChannelSeq.clear (); } } @@ -2774,7 +2850,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat tChannelID channelID (Source, getOriginalNetworkId (), getTransportStreamId (), getServiceId ()); cChannel *channel = Channels.GetByChannelID (channelID, true); if (!channel) - return; // only collect data for known channels + return; // only collect data for known channels #ifdef USE_NOEPG // only use epg from channels not blocked by noEPG-patch @@ -2842,7 +2918,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat || !ShortEventDescriptor) { delete ShortEventDescriptor; ShortEventDescriptor = sed; - d = NULL; // so that it is not deleted + d = NULL; // so that it is not deleted } } else if (d->getDescriptorTag () == SI::ExtendedEventDescriptorTag) { int LanguagePreferenceExt = -1; @@ -2856,7 +2932,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat } if (UseExtendedEventDescriptor) { ExtendedEventDescriptors->Add (eed); - d = NULL; // so that it is not deleted + d = NULL; // so that it is not deleted } if (eed->getDescriptorNumber () == eed->getLastDescriptorNumber ()) UseExtendedEventDescriptor = false; @@ -2909,14 +2985,14 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat continue; } if (!ExternalData) { - pEvent->SetEventID (SiEitEvent.getEventId ()); // unfortunately some stations use different event ids for the same event in different tables :-( + pEvent->SetEventID (SiEitEvent.getEventId ()); // unfortunately some stations use different event ids for the same event in different tables :-( pEvent->SetTableID (Tid); pEvent->SetStartTime (SiEitEvent.getStartTime ()); pEvent->SetDuration (SiEitEvent.getDuration ()); } if (newEvent) pSchedule->AddEvent (newEvent); - if (Tid == 0x4E) { // we trust only the present/following info on the actual TS + if (Tid == 0x4E) { // we trust only the present/following info on the actual TS #ifdef USE_DDEPGENTRY if (Setup.DisableVPS == 0 && SiEitEvent.getRunningStatus () >= SI::RunningStatusNotRunning) #else @@ -2925,7 +3001,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat pSchedule->SetRunningStatus (pEvent, SiEitEvent.getRunningStatus (), channel); } if (OnlyRunningStatus) - continue; // do this before setting the version, so that the full update can be done later + continue; // do this before setting the version, so that the full update can be done later pEvent->SetVersion (getVersionNumber ()); int LanguagePreferenceShort = -1; @@ -2952,7 +3028,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat } if (UseExtendedEventDescriptor) { ExtendedEventDescriptors->Add (eed); - d = NULL; // so that it is not deleted + d = NULL; // so that it is not deleted } if (eed->getDescriptorNumber () == eed->getLastDescriptorNumber ()) UseExtendedEventDescriptor = false; @@ -2964,7 +3040,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat || !ShortEventDescriptor) { delete ShortEventDescriptor; ShortEventDescriptor = sed; - d = NULL; // so that it is not deleted + d = NULL; // so that it is not deleted } } break; @@ -3018,17 +3094,17 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat SI::PDCDescriptor * pd = (SI::PDCDescriptor *) d; time_t now = time (NULL); struct tm tm_r; - struct tm t = *localtime_r (&now, &tm_r); // this initializes the time zone in 't' - t.tm_isdst = -1; // makes sure mktime() will determine the correct DST setting + struct tm t = *localtime_r (&now, &tm_r); // this initializes the time zone in 't' + t.tm_isdst = -1; // makes sure mktime() will determine the correct DST setting int month = t.tm_mon; t.tm_mon = pd->getMonth () - 1; t.tm_mday = pd->getDay (); t.tm_hour = pd->getHour (); t.tm_min = pd->getMinute (); t.tm_sec = 0; - if (month == 11 && t.tm_mon == 0) // current month is dec, but event is in jan + if (month == 11 && t.tm_mon == 0) // current month is dec, but event is in jan t.tm_year++; - else if (month == 0 && t.tm_mon == 11) // current month is jan, but event is in dec + else if (month == 0 && t.tm_mon == 11) // current month is jan, but event is in dec t.tm_year--; time_t vps = mktime (&t); pEvent->SetVps (vps); @@ -3052,7 +3128,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat case SI::LinkageDescriptorTag: { SI::LinkageDescriptor * ld = (SI::LinkageDescriptor *) d; tChannelID linkID (Source, ld->getOriginalNetworkId (), ld->getTransportStreamId (), ld->getServiceId ()); - if (ld->getLinkageType () == 0xB0) { // Premiere World + if (ld->getLinkageType () == 0xB0) { // Premiere World time_t now = time (NULL); bool hit = SiEitEvent.getStartTime () <= now && now < SiEitEvent.getStartTime () + SiEitEvent.getDuration (); @@ -3061,7 +3137,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat strn0cpy (linkName, (const char *) ld->privateData.getData (), sizeof (linkName)); // TODO is there a standard way to determine the character set of this string? cChannel *link = Channels.GetByChannelID (linkID); - if (link != channel) { // only link to other channels, not the same one + if (link != channel) { // only link to other channels, not the same one //fprintf(stderr, "Linkage %s %4d %4d %5d %5d %5d %5d %02X '%s'\n", hit ? "*" : "", channel->Number(), link ? link->Number() : -1, SiEitEvent.getEventId(), ld->getOriginalNetworkId(), ld->getTransportStreamId(), ld->getServiceId(), ld->getLinkageType(), linkName);//XXX if (link) { if (Setup.UpdateChannels == 1 || Setup.UpdateChannels >= 3) @@ -3090,7 +3166,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat SI::ComponentDescriptor * cd = (SI::ComponentDescriptor *) d; uchar Stream = cd->getStreamContent (); uchar Type = cd->getComponentType (); - //if (1 <= Stream && Stream <= 3 && Type != 0) { // 1=video, 2=audio, 3=subtitles + //if (1 <= Stream && Stream <= 3 && Type != 0) { // 1=video, 2=audio, 3=subtitles if (1 <= Stream && Stream <= 6 && Type != 0) { // 1=MPEG2-video, 2=MPEG1-audio, 3=subtitles, 4=AC3-audio, 5=H.264-video, 6=HEAAC-audio if (!Components) Components = new cComponents; @@ -3217,7 +3293,7 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat } } //end of cEIT2 -} //end namespace SI +} //end namespace SI void cFilterEEPG::ProcessNextFormat (bool FirstTime = false) { @@ -3247,7 +3323,7 @@ void cFilterEEPG::ProcessNextFormat (bool FirstTime = false) esyslog ("EEPG: %i summaries not found", SummariesNotFound); else if (VERBOSE >= 1) isyslog ("EEPG: %i summaries not found", SummariesNotFound); */ - UnprocessedFormat[Format] = 0; //clear previously processed format + UnprocessedFormat[Format] = 0; //clear previously processed format //Next few lines prevent eepg from reading multiple eepg-systems on one transponder e.g. CDNL //isyslog ("EEPG: Ended all processing"); @@ -3265,25 +3341,25 @@ void cFilterEEPG::ProcessNextFormat (bool FirstTime = false) //now start looking for next format to process int pid; - Format = -1; //unused value - for (int i = 0; i <= HIGHEST_FORMAT; i++) //find first format that is detected + Format = -1; //unused value + for (int i = 0; i <= HIGHEST_FORMAT; i++) //find first format that is detected if (UnprocessedFormat[i]) { isyslog ("EEPG: %s Extended EPG detected on pid %x.", FormatName[i], UnprocessedFormat[i]); Format = i; - } //highest format is processed first this way;; TODO make sure that CONT protocols like Premiere, Freesat are processed AFTER ONCE protocols like MHW, SKY and NAGRA + } //highest format is processed first this way;; TODO make sure that CONT protocols like Premiere, Freesat are processed AFTER ONCE protocols like MHW, SKY and NAGRA - if (Format == -1) { //there are no formats left to process + if (Format == -1) { //there are no formats left to process isyslog ("EEPG: Ended all processing"); return; } - pid = UnprocessedFormat[Format]; //and reinstall its pid + pid = UnprocessedFormat[Format]; //and reinstall its pid memset (&InitialChannel, 0, 8); memset (&InitialTitle, 0, 64); memset (&InitialSummary, 0, 64); NagraCounter = 0; - Version = -1; //because 0 can be a valid version number... + Version = -1; //because 0 can be a valid version number... nEquivChannels = 0; nChannels = 0; nThemes = 0; @@ -3295,25 +3371,25 @@ void cFilterEEPG::ProcessNextFormat (bool FirstTime = false) Add (pid, 0xA0); break; case MHW1: - AddFilter (0xd3, 0x92); //ThemesMHW1//TODO: all filters are serialized, strictly speaking Themes is non-fatal... + AddFilter (0xd3, 0x92); //ThemesMHW1//TODO: all filters are serialized, strictly speaking Themes is non-fatal... break; case MHW2: - AddFilter (0x231, 0xc8); //MHW2 Channels & Themes + AddFilter (0x231, 0xc8); //MHW2 Channels & Themes break; case SKY_IT: case SKY_UK: - AddFilter (0x11, 0x4a); //Sky Channels + AddFilter (0x11, 0x4a); //Sky Channels break; - case FREEVIEW: //Freeview, CONT mode //TODO streamline this for other modes + case FREEVIEW: //Freeview, CONT mode //TODO streamline this for other modes ReadFileDictionary (); - AddFilter (pid, 0x4e, 0xfe); //event info, actual(0x4e)/other(0x4f) TS, present/following - AddFilter (pid, 0x50, 0xf0); //event info, actual TS, schedule(0x50)/schedule for future days(0x5X) - AddFilter (pid, 0x60, 0xf0); //event info, other TS, schedule(0x60)/schedule for future days(0x6X) - AddFilter (0x39, 0x50, 0xf0); //event info, actual TS, Viasat - AddFilter (0x39, 0x60, 0xf0); //event info, other TS, Viasat + AddFilter (pid, 0x4e, 0xfe); //event info, actual(0x4e)/other(0x4f) TS, present/following + AddFilter (pid, 0x50, 0xf0); //event info, actual TS, schedule(0x50)/schedule for future days(0x5X) + AddFilter (pid, 0x60, 0xf0); //event info, other TS, schedule(0x60)/schedule for future days(0x6X) + AddFilter (0x39, 0x50, 0xf0); //event info, actual TS, Viasat + AddFilter (0x39, 0x60, 0xf0); //event info, other TS, Viasat case NAGRA: // isyslog ("EEPG: NagraGuide Extended EPG detected."); - AddFilter (pid, 0xb0); //perhaps TID is equal to first data byte? + AddFilter (pid, 0xb0); //perhaps TID is equal to first data byte? break; default: break; @@ -3351,10 +3427,10 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len pmtnext = now + PMT_SCAN_IDLE; LogI(1, prep("PMT scan idle\n")); - Del (0, 0); //this effectively kills the PMT_SCAN_IDLE functionality + Del (0, 0); //this effectively kills the PMT_SCAN_IDLE functionality //now after the scan is completed, start processing - ProcessNextFormat (true); //FirstTime flag is set + ProcessNextFormat (true); //FirstTime flag is set } } } @@ -3365,7 +3441,7 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len SI::PMT::Stream stream; for (SI::Loop::Iterator it; pmt.streamLoop.getNext (stream, it);) { // if(stream.getStreamType()==0x05) { - if (stream.getStreamType () == 0x05 || stream.getStreamType () == 0xc1) { //0x05 = Premiere, SKY, Freeview, Nagra 0xc1 = MHW1,MHW2 + if (stream.getStreamType () == 0x05 || stream.getStreamType () == 0xc1) { //0x05 = Premiere, SKY, Freeview, Nagra 0xc1 = MHW1,MHW2 SI::CharArray data = stream.getData (); if ((data[1] & 0xE0) == 0xE0 && (data[3] & 0xF0) == 0xF0) { bool prvData = false, usrData = false; @@ -3384,9 +3460,9 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len //esyslog ("prv: %d %08x\n", d->getLength (), d->getData ().FourBytes (2)); if (d->getLength () == 6 && d->getData ().FourBytes (2) == 0x000000be) prvData = true; - if (d->getLength () == 6 && d->getData ().FourBytes (2) == 0x4f545600) //OpenTV + if (d->getLength () == 6 && d->getData ().FourBytes (2) == 0x4f545600) //OpenTV prvOTV = true; - if (d->getLength () == 6 && d->getData ().FourBytes (2) == 0x46534154) //Freeview + if (d->getLength () == 6 && d->getData ().FourBytes (2) == 0x46534154) //Freeview prvFRV = true; break; case 0x52: @@ -3399,30 +3475,30 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len //esyslog ("usr: %d %08x\n", d->getLength (), d->getData ().FourBytes (2)); if (d->getLength () == 6 && d->getData ().FourBytes (2) == 0x0000ffff) usrData = true; - if (d->getLength () == 3 && ((d->getData ().TwoBytes (2) & 0xff00) == 0xb600)) //SKY IT //TODO ugly! + if (d->getLength () == 3 && ((d->getData ().TwoBytes (2) & 0xff00) == 0xb600)) //SKY IT //TODO ugly! //if (d->getLength () == 3 && (d->getData ().TwoBytes (2) == 0xb6a5)) //SKY IT //TODO ugly! usrOTV = SKY_IT; //Format = SKY_IT; if (d->getLength () == 3 && d->getData ().FourBytes (2) == 0xc004e288) //SKY UK - //if (d->getLength () == 3 && ((d->getData ().TwoBytes (2) & 0xff00) == 0x9d00)) //SKY UK //TODO ugly! + //if (d->getLength () == 3 && ((d->getData ().TwoBytes (2) & 0xff00) == 0x9d00)) //SKY UK //TODO ugly! usrOTV = SKY_UK; //Format = SKY_UK; break; - case 0xc1: //MHW1, MHW2 + case 0xc1: //MHW1, MHW2 // esyslog("EEPGDEBUG:d->getDescriptorTAG:%d %08x\n",d->getLength(),d->getData().FourBytes(2)); - if (d->getLength () == 10 && d->getData ().FourBytes (2) == 0x50555348) //MHw1 Cyfra + if (d->getLength () == 10 && d->getData ().FourBytes (2) == 0x50555348) //MHw1 Cyfra UnprocessedFormat[MHW1] = stream.getPid (); break; - case 0xc2: //MHW1, MHW2 - if (d->getLength () == 10 && d->getData ().FourBytes (2) == 0x45504700) //MHw1 CanDigNL and CSat + case 0xc2: //MHW1, MHW2 + if (d->getLength () == 10 && d->getData ().FourBytes (2) == 0x45504700) //MHw1 CanDigNL and CSat UnprocessedFormat[MHW1] = stream.getPid (); //int nop;//FIXME - else if (d->getLength () == 10 && d->getData ().FourBytes (2) == 0x46494348) { //MHW2 + else if (d->getLength () == 10 && d->getData ().FourBytes (2) == 0x46494348) { //MHW2 UnprocessedFormat[MHW2] = stream.getPid (); } break; - case 0xd1: //Freeview + case 0xd1: //Freeview if (d->getLength () == 3 && ((d->getData ().TwoBytes (2) & 0xff00) == 0x0100)) usrFRV = 0x01; //01 = EIT pid 3842 @@ -3432,11 +3508,11 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len //05 06 = TOT Time Offset Table pid 3844 break; - /* case 0xfe: //SKY_IT - if (d->getLength () == 6 && d->getData ().FourBytes (2) == 0x534b5900) { //SKY_IT - Format = SKY_IT; - } - break;*/ + /* case 0xfe: //SKY_IT + if (d->getLength () == 6 && d->getData ().FourBytes (2) == 0x534b5900) { //SKY_IT + Format = SKY_IT; + } + break;*/ default: break; } @@ -3449,24 +3525,24 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len UnprocessedFormat[FREEVIEW] = stream.getPid (); if (prvData && usrData) UnprocessedFormat[PREMIERE] = stream.getPid (); - } //if data[1] && data [3] - } //if streamtype + } //if data[1] && data [3] + } //if streamtype /*if (Format != PREMIERE) //any format found break; //break out for loop */ - } //for loop that walks through streams + } //for loop that walks through streams // if (Format == PREMIERE) { //FIXME for Premiere you should also stop scanning when found... NextPmt (); pmtnext = 0; /* } else { - Del (pmtpid, 0x02); - Del (0, 0); - pmtidx = 0; - pmtnext = now + PMT_SCAN_IDLE; - isyslog ("PMT scan forced idle\n"); + Del (pmtpid, 0x02); + Del (0, 0); + pmtidx = 0; + pmtnext = now + PMT_SCAN_IDLE; + isyslog ("PMT scan forced idle\n"); }*/ - } //checkCRC - } //if pmtpid + } //checkCRC + } //if pmtpid else if (Source ()) { int Result; switch (Tid) { @@ -3490,7 +3566,7 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len int LanguagePreferenceExt = -1; for (SI::Loop::Iterator it; (d = cit.eventDescriptors.getNext (it));) { switch (d->getDescriptorTag ()) { - case 0xF0: // order information + case 0xF0: // order information if (SetupPE.OrderInfo) { static const char *text[] = { trNOOP ("Ordernumber"), @@ -3512,7 +3588,7 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len order = strdup (buff); } break; - case 0xF1: // parental rating + case 0xF1: // parental rating if (SetupPE.RatingInfo) { char buff[512]; int p = 0; @@ -3556,7 +3632,7 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len } if (UseExtendedEventDescriptor) { ExtendedEventDescriptors->Add (eed); - d = NULL; // so that it is not deleted + d = NULL; // so that it is not deleted } if (eed->getDescriptorNumber () == eed->getLastDescriptorNumber ()) UseExtendedEventDescriptor = false; @@ -3568,7 +3644,7 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len || !ShortEventDescriptor) { delete ShortEventDescriptor; ShortEventDescriptor = sed; - d = NULL; // so that it is not deleted + d = NULL; // so that it is not deleted } } break; @@ -3736,55 +3812,55 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len free (order); free (rating); } - } //if checkcrcandpars + } //if checkcrcandpars break; - } //if citpid == 0xb11 Premiere + } //if citpid == 0xb11 Premiere case 0xa1: case 0xa2: case 0xa3: Result = GetTitlesSKYBOX (Data, Length - 4); - if (Result != 1) //when fatal error or finished - Del (Pid, 0xa0, 0xfc); //kill filter - if (Result == 0) { //fatal error + if (Result != 1) //when fatal error or finished + Del (Pid, 0xa0, 0xfc); //kill filter + if (Result == 0) { //fatal error esyslog ("EEPG: Fatal error reading titles."); - ProcessNextFormat (); //and go process other formats + ProcessNextFormat (); //and go process other formats } if (Result == 2) - AddFilter (Pid + 0x10, 0xa8, 0xfc); //Set filter that processes summaries of this batch + AddFilter (Pid + 0x10, 0xa8, 0xfc); //Set filter that processes summaries of this batch break; case 0xa8: case 0xa9: case 0xaa: case 0xab: Result = GetSummariesSKYBOX (Data, Length - 4); - if (Result != 1) //when fatal error or finished - Del (Pid, 0xa8, 0xfc); //kill filter + if (Result != 1) //when fatal error or finished + Del (Pid, 0xa8, 0xfc); //kill filter if (Result == 0) { esyslog ("EEPG: Fatal error reading summaries."); ProcessNextFormat (); } if (Result == 2) { LoadIntoSchedule (); - if (Pid < 0x47) //this is not the last batch//FIXME chaining is easy on the PIDs and the CPU, but error when Pid,Tid is not used at the moment... - AddFilter (Pid - 0x0F, 0xa0, 0xfc); //next pid, first tid - else //last pid was processed + if (Pid < 0x47) //this is not the last batch//FIXME chaining is easy on the PIDs and the CPU, but error when Pid,Tid is not used at the moment... + AddFilter (Pid - 0x0F, 0xa0, 0xfc); //next pid, first tid + else //last pid was processed ProcessNextFormat (); } break; case 0x90: if (Pid == 0xd2) { Result = GetTitlesMHW1 (Data, Length); - if (Result != 1) //fatal error or last processed + if (Result != 1) //fatal error or last processed Del (Pid, Tid); if (Result == 0) { esyslog ("EEPG: Fatal error reading titles."); ProcessNextFormat (); } if (Result == 2) - AddFilter (0xd3, 0x90); //SummariesMHW1 + AddFilter (0xd3, 0x90); //SummariesMHW1 } else if (Pid == 0xd3) { Result = GetSummariesMHW1 (Data, Length); - if (Result != 1) //fatal error or last processed + if (Result != 1) //fatal error or last processed Del (Pid, Tid); if (Result == 0) { esyslog ("EEPG: Fatal error reading summaries."); @@ -3797,55 +3873,55 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len } } break; - case 0xc8: //GetChannelsMHW2 or GetThemesMHW2 + case 0xc8: //GetChannelsMHW2 or GetThemesMHW2 if (Pid == 0x231) { - if (Data[3] == 0x01) { //Themes it will be - Result = GetThemesMHW2 (Data, Length); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed + if (Data[3] == 0x01) { //Themes it will be + Result = GetThemesMHW2 (Data, Length); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed //break; if (Result != 1) - EndThemes = true; //also set Endthemes on true on fatal error - } //if Data - else if (Data[3] == 0x00) { //Channels it will be - Result = GetChannelsMHW (Data, Length, 2); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed + EndThemes = true; //also set Endthemes on true on fatal error + } //if Data + else if (Data[3] == 0x00) { //Channels it will be + Result = GetChannelsMHW (Data, Length, 2); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed if (Result != 1) - EndChannels = true; //always remove filter, code 1 should never be returned since MHW2 always reads all channels.. + EndChannels = true; //always remove filter, code 1 should never be returned since MHW2 always reads all channels.. ChannelsOk = (Result == 2); } - if (EndChannels && EndThemes) { //those are only set withing MHW2 - Del (0x231, 0xc8); //stop reading MHW2 themes and channels - if (ChannelsOk) //No channels = fatal, no themes = nonfatal - AddFilter (0x234, 0xe6); //start reading MHW2 titles + if (EndChannels && EndThemes) { //those are only set withing MHW2 + Del (0x231, 0xc8); //stop reading MHW2 themes and channels + if (ChannelsOk) //No channels = fatal, no themes = nonfatal + AddFilter (0x234, 0xe6); //start reading MHW2 titles else { esyslog ("EEPG: Fatal error reading channels."); ProcessNextFormat (); } } - } //if Pid == 0x231 + } //if Pid == 0x231 break; case 0x91: - Result = GetChannelsMHW (Data, Length, 1); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed - Del (Pid, Tid); //always remove filter, code 1 should never be returned since MHW1 always reads all channels... + Result = GetChannelsMHW (Data, Length, 1); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed + Del (Pid, Tid); //always remove filter, code 1 should never be returned since MHW1 always reads all channels... if (Result == 2) - AddFilter (0xd2, 0x90); //TitlesMHW1 + AddFilter (0xd2, 0x90); //TitlesMHW1 else { esyslog ("EEPG: Fatal error reading channels."); ProcessNextFormat (); } break; case 0x92: - Result = GetThemesMHW1 (Data, Length); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed + Result = GetThemesMHW1 (Data, Length); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed if (Result != 1) Del (Pid, Tid); if (Result == 2) - AddFilter (0xd3, 0x91); //ChannelsMHW1 + AddFilter (0xd3, 0x91); //ChannelsMHW1 else { - esyslog ("EEPG: Fatal error reading themes."); //doesnt have to be fatal... + esyslog ("EEPG: Fatal error reading themes."); //doesnt have to be fatal... ProcessNextFormat (); } break; - case 0xe6: //TitlesMHW2 + case 0xe6: //TitlesMHW2 if (Pid == 0x234) { - Result = GetTitlesMHW2 (Data, Length); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed + Result = GetTitlesMHW2 (Data, Length); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed if (Result != 1) Del (Pid, Tid); if (Result == 0) { @@ -3853,12 +3929,12 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len ProcessNextFormat (); } if (Result == 2) - AddFilter (0x236, 0x96); //start reading MHW2 summaries.... + AddFilter (0x236, 0x96); //start reading MHW2 summaries.... } break; - case 0x96: //Summaries MHW2 + case 0x96: //Summaries MHW2 if (Pid == 0x236) { - Result = GetSummariesMHW2 (Data, Length); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed + Result = GetSummariesMHW2 (Data, Length); //return code 0 = fatal error, code 1 = sucess, code 2 = last item processed if (Result != 1) Del (Pid, Tid); if (Result == 0) { @@ -3869,26 +3945,26 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len if (Result != 1) { ProcessNextFormat (); } - } //if pid + } //if pid break; - case 0x4a: //Sky channels + case 0x4a: //Sky channels if (Pid == 0x11) { Result = GetChannelsSKYBOX (Data, Length - 4); - if (Result != 1) //only breakoff on completion or error; do NOT clean up after success, because then not all bouquets will be read - Del (Pid, Tid); //Read all channels, clean up filter + if (Result != 1) //only breakoff on completion or error; do NOT clean up after success, because then not all bouquets will be read + Del (Pid, Tid); //Read all channels, clean up filter if (Result == 2) { - GetThemesSKYBOX (); //Sky Themes from file; must be called AFTER first channels to have lThemes initialized FIXME + GetThemesSKYBOX (); //Sky Themes from file; must be called AFTER first channels to have lThemes initialized FIXME if (ReadFileDictionary ()) - AddFilter (0x30, 0xa0, 0xfc); //SKY Titles batch 0 of 7 + AddFilter (0x30, 0xa0, 0xfc); //SKY Titles batch 0 of 7 else { esyslog ("EEPG: Fatal error reading huffman table."); ProcessNextFormat (); } } - } //if Pid == 0x11 + } //if Pid == 0x11 break; - case 0xb0: //NagraGuide + case 0xb0: //NagraGuide if (Pid == 0xc8) { Result = GetNagra (Data, Length); if (Result != 1) @@ -3898,7 +3974,7 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len } if (Result == 2) { ProcessNagra (); - cSchedules::Cleanup (true); //deletes all past events + cSchedules::Cleanup (true); //deletes all past events isyslog ("EEPG: Ended processing Nagra"); } if (Result != 1) { @@ -3973,9 +4049,9 @@ void cFilterEEPG::Process (u_short Pid, u_char Tid, const u_char * Data, int Len default: break; - } //end switch - } //closes SOURCE() -} //end of closing + } //end switch + } //closes SOURCE() +} //end of closing // --- cPluginEEPG ------------------------------------------------------ @@ -4142,4 +4218,4 @@ bool cPluginEEPG::SetupParse (const char *Name, const char *Value) return true; } -VDRPLUGINCREATOR (cPluginEEPG); // Don't touch this! +VDRPLUGINCREATOR (cPluginEEPG); // Don't touch this! |