diff options
-rw-r--r-- | dish.c | 149 | ||||
-rw-r--r-- | dish.h | 38 | ||||
-rw-r--r-- | eepg.c | 83 |
3 files changed, 203 insertions, 67 deletions
@@ -41,23 +41,31 @@ namespace SI DishDescriptor::DishDescriptor() { - text = NULL; + name = NULL; shortText = NULL; - decompressed = NULL; + description = NULL; + decompressedShort = NULL; + decompressedExtended = NULL; + DishTheme = 0; + DishCategory = 0; + mpaaRating = 0; + starRating = 0; } DishDescriptor::~DishDescriptor() { - delete [] decompressed; - decompressed = NULL; + delete [] decompressedShort; + decompressedShort = NULL; + delete [] decompressedExtended; + decompressedExtended = NULL; } - const char *DishDescriptor::getTheme(int contentNibleLvl2) + const char *DishDescriptor::getTheme() { const char* theme; using namespace DISH_THEMES; - switch (contentNibleLvl2) { + switch (DishTheme){ case Movie: theme = "Movie"; break; @@ -89,11 +97,11 @@ namespace SI return theme; } - const char *DishDescriptor::getCategory(int userNible) + const char *DishDescriptor::getCategory() { using namespace DISH_CATEGORIES; - switch (userNible) { + switch (DishCategory) { case Action: return "Action"; case ActionSports: return "Action Sports"; case Adults_only: return "Adults only"; @@ -251,10 +259,116 @@ namespace SI case Yoga: return "Yoga"; default: return ""; } + } + void DishDescriptor::setShortData(unsigned char Tid, CharArray data) + { + decompressedShort = Decompress(Tid, data); + if (decompressedShort) { + name = decompressedShort; + } } - void DishDescriptor::Decompress(unsigned char Tid, CharArray data) + void DishDescriptor::setExtendedtData(unsigned char Tid, CharArray data) + { + decompressedExtended = Decompress(Tid, data); + if (decompressedExtended) { + char *split = strchr((char*)((decompressedExtended)), 0x0D); // Look for carriage return + //LogD(2, prep("dLength:%d, length:%d, count:%d, decompressed: %s"), dLength, length, count, decompressed); + if(split){ + *split = 0; + shortText = (char*)decompressedExtended; + description = (split[1] == 0x20) ? split + 2 : split + 1; + }else{ + description = (char*)decompressedExtended; + } + } + } + + const char *DishDescriptor::getShortText(void) + { +// string tmp = ""; +//// if (shortText != NULL) tmp += *shortText; +// tmp += shortText; +// if(DishTheme > 0){ +// if(tmp != "") tmp += " - "; +// +// tmp += getTheme(); +// } +// if(DishCategory > 0){ +// if(tmp != "") tmp += " - "; +// +// tmp += getCategory(); +// } +// return tmp.c_str(); + return shortText?shortText:""; + } + + const char *DishDescriptor::getDescription(void) { +// string tmp = ""; +//// if (description != NULL) tmp += *description; +// tmp += description; +// const char* rating = getRating(); +// if (rating && strcmp(rating,"") != 0) { +// if(tmp != "") tmp += " ~ "; +// tmp += rating; +// } +// if (starRating > 0) { +// if(tmp != "") tmp += " ~ "; +// tmp += getStarRating(); +// } +// return tmp.c_str(); + return description; + } + + void DishDescriptor::setContent(ContentDescriptor::Nibble Nibble) + { + DishTheme = Nibble.getContentNibbleLevel2() & 0xF; + DishCategory = ((Nibble.getUserNibble1() & 0xF) << 4) | (Nibble.getUserNibble2() & 0xF); + } + + void DishDescriptor::setRating(uint16_t rating) + { + uint16_t newRating = (rating >> 10) & 0x07; + if (newRating == 0) newRating = 5; + if (newRating == 6) newRating = 0; + mpaaRating = (newRating << 10) | (rating & 0x3FF); + starRating = (rating >> 13) & 0x07; + } + + const char* DishDescriptor::getRating(){ + static const char *const ratings[8] = { "", "G", "PG", "PG-13", "R", "NR/AO", "", "NC-17" }; + + if (mpaaRating == 0) { + return ratings[mpaaRating]; + } + + char buffer[19]; + buffer[0] = 0; + strcpy(buffer, ratings[(mpaaRating >> 10) & 0x07]); + if (mpaaRating & 0x3A7F) { + strcat(buffer, " ["); + if (mpaaRating & 0x0230) + strcat(buffer, "V,"); + if (mpaaRating & 0x000A) + strcat(buffer, "L,"); + if (mpaaRating & 0x0044) + strcat(buffer, "N,"); + if (mpaaRating & 0x0101) + strcat(buffer, "SC,"); + if (char *s = strrchr(buffer, ',')) + s[0] = ']'; + } + + return isempty(buffer) ? "" : buffer; + } + + const char* DishDescriptor::getStarRating(){ + static const char *const critiques[8] = { "", "*", "*+", "**", "**+", "***", "***+", "****" }; + return critiques[starRating & 0x07]; + } + + const char *DishDescriptor::Decompress(unsigned char Tid, CharArray data) { const unsigned char *str = data.getData(); const unsigned char *cmp = NULL; @@ -270,17 +384,16 @@ namespace SI cmp = str + 3; } if(length <= 0 || !dLength) - return; + return NULL; - decompressed = new unsigned char[dLength + 1]; + char *decompressed = new unsigned char[dLength + 1]; HuffmanTable *table; unsigned int tableSize, numBits; if (Tid > 0x80) { table = Table255; tableSize = SIZE_TABLE_255; numBits = 13; - } - else { + } else { table = Table128; tableSize = SIZE_TABLE_128; numBits = 11; @@ -303,15 +416,7 @@ namespace SI } decompressed[count] = 0; - char *split = strchr((char*)(decompressed), 0x0D); // Look for carriage return - //LogD(2, prep("dLength:%d, length:%d, count:%d, decompressed: %s"), dLength, length, count, decompressed); - if(split){ - *split = 0; - shortText = (char*)(decompressed); - text = (split[1] == 0x20) ? split + 2 : split + 1; - }else{ - text = (char*)(decompressed); - } + return decompressed; } @@ -10,7 +10,7 @@ #ifndef LIBSI_DISH_H #define LIBSI_DISH_H -#include <vdr/tools.h> +#include <libsi/util.h> namespace SI { @@ -247,17 +247,35 @@ class DishDescriptor { public: DishDescriptor(); virtual ~DishDescriptor(); - const char* getText(void) const { return text; } + const char* getName(void) const { return name; } + const char* getShortText(void); + const char *getDescription(void); + // const char* getShortText(void) const { return shortText?shortText->c_str():""; } + // const char* getDescription(void) const { return description?description->c_str():""; } + const char *getTheme(); + const char *getCategory(); + const char *getRating(); + const char *getStarRating(); + bool hasTheme() {return DishTheme > 0;} + bool hasCategory() {return DishCategory > 0;} + void setShortData(unsigned char Tid, CharArray data); + void setExtendedtData(unsigned char Tid, CharArray data); + void setRating(uint16_t value); + void setContent(ContentDescriptor::Nibble Nibble); - const char* getShortText(void) const { return shortText; } - const char* getTheme(int contentNibleLvl2); - const char* getCategory(int userNible); - // Decompress the byte arrary and stores the result to a text string - void Decompress(unsigned char Tid, CharArray data); protected: - const char* text; // name or description of the event - const char* shortText; // usually the episode name - unsigned char* decompressed; + // Decompress the byte array and stores the result to a text string + const char *Decompress(unsigned char Tid, CharArray data); + const char* name; // name of the event + const char* shortText; // usually the episode name + const char* description; // description of the event + unsigned char* decompressedShort; + unsigned char* decompressedExtended; + unsigned char DishTheme; + unsigned char DishCategory; + uint16_t mpaaRating; + uint16_t starRating; + struct HuffmanTable { unsigned int startingAddress; @@ -3006,9 +3006,9 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat SI::Descriptor * d; SI::ExtendedEventDescriptors * ExtendedEventDescriptors = NULL; SI::ShortEventDescriptor * ShortEventDescriptor = NULL; - SI::DishDescriptor *DishExtendedEventDescriptor = NULL; - SI::DishDescriptor *DishShortEventDescriptor = NULL; - uchar DishTheme = 0, DishCategory = 0; + //SI::DishDescriptor *DishExtendedEventDescriptor = NULL; + SI::DishDescriptor *DishEventDescriptor = NULL; + //uchar DishTheme = 0, DishCategory = 0; cLinkChannels *LinkChannels = NULL; @@ -3060,10 +3060,8 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat Contents[NumContents] = ((Nibble.getContentNibbleLevel1() & 0xF) << 4) | (Nibble.getContentNibbleLevel2() & 0xF); NumContents++; } - if (Format == DISH_BEV && NumContents == 1) { - DishTheme = Nibble.getContentNibbleLevel2() & 0xF; - DishCategory = ((Nibble.getUserNibble1() & 0xF) << 4) | (Nibble.getUserNibble2() & 0xF); - //LogD(2, prep("EEPGDEBUG:DishTheme:%x-DishCategory:%x)"), DishTheme, DishCategory); + if (DishEventDescriptor && NumContents == 1) { + DishEventDescriptor->setContent(Nibble); } //LogD(2, prep("EEPGDEBUG:Nibble:%x-%x-%x-%x)"), Nibble.getContentNibbleLevel1(),Nibble.getContentNibbleLevel2() // , Nibble.getUserNibble1(), Nibble.getUserNibble2()); @@ -3190,29 +3188,27 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat } break; case SI::DishExtendedEventDescriptorTag: { - if (!DishExtendedEventDescriptor) { - DishExtendedEventDescriptor = new SI::DishDescriptor(); - DishExtendedEventDescriptor->Decompress(Tid, d->getData()); + SI::UnimplementedDescriptor *deed = (SI::UnimplementedDescriptor *)d; + if (!DishEventDescriptor) { + DishEventDescriptor = new SI::DishDescriptor(); } + DishEventDescriptor->setExtendedtData(Tid, deed->getData()); HasExternalData = true; } break; case SI::DishShortEventDescriptorTag: { - if (!DishShortEventDescriptor) { - DishShortEventDescriptor = new SI::DishDescriptor(); - DishShortEventDescriptor->Decompress(Tid, d->getData()); + SI::UnimplementedDescriptor *dsed = (SI::UnimplementedDescriptor *)d; + if (!DishEventDescriptor) { + DishEventDescriptor = new SI::DishDescriptor(); } + DishEventDescriptor->setShortData(Tid, dsed->getData()); HasExternalData = true; } break; case SI::DishRatingDescriptorTag: { - if (d->getLength() == 4) { + if (d->getLength() == 4 && DishEventDescriptor) { uint16_t rating = d->getData().TwoBytes(2); - uint16_t newRating = (rating >> 10) & 0x07; - if (newRating == 0) newRating = 5; - if (newRating == 6) newRating = 0; - pEvent->SetParentalRating((newRating << 10) | (rating & 0x3FF)); -// pEvent->SetStarRating((rating >> 13) & 0x07); + DishEventDescriptor->setRating(rating); } } break; @@ -3246,30 +3242,47 @@ cEIT2::cEIT2 (cSchedules * Schedules, int Source, u_char Tid, const u_char * Dat } else if (!HasExternalData) pEvent->SetDescription (NULL); - if (DishShortEventDescriptor) { - pEvent->SetTitle(DishShortEventDescriptor->getText()); + if (DishEventDescriptor) { + if (DishEventDescriptor->getName()) + pEvent->SetTitle(DishEventDescriptor->getName()); //LogD(2, prep("channelID: %s DishTitle: %s"), *channel->GetChannelID().ToString(), DishShortEventDescriptor->getText()); - } - if (DishExtendedEventDescriptor) { - pEvent->SetDescription(DishExtendedEventDescriptor->getText()); +// pEvent->SetDescription(DishExtendedEventDescriptor->getText()); char *tmp; - if (DishTheme >= 0) { - Asprintf (&tmp, "%s - %s ~ %s", DishExtendedEventDescriptor->getShortText() - , DishExtendedEventDescriptor->getTheme(DishTheme) - , DishExtendedEventDescriptor->getCategory(DishCategory)); - pEvent->SetShortText(tmp); - //LogD(2, prep("EEPGDEBUG:DishTheme:%x-DishCategory:%x)"), DishTheme, DishCategory); - free(tmp); - } else - pEvent->SetShortText(DishExtendedEventDescriptor->getShortText()); + string fmt; + fmt = "%s"; + if (0 != strcmp(DishEventDescriptor->getShortText(),"") && DishEventDescriptor->hasTheme()) { + fmt += " - "; + } + fmt += "%s"; + if (DishEventDescriptor->hasTheme() && DishEventDescriptor->hasCategory()) { + fmt += " ~ "; + } + fmt += "%s"; + + Asprintf (&tmp, fmt.c_str(), DishEventDescriptor->getShortText() + , DishEventDescriptor->getTheme() + , DishEventDescriptor->getCategory()); + pEvent->SetShortText(tmp); + //LogD(2, prep("EEPGDEBUG:DishTheme:%x-DishCategory:%x)"), DishTheme, DishCategory); + free(tmp); + + fmt = "%s"; + if (0 != strcmp(DishEventDescriptor->getDescription(),"") && (0 != strcmp(DishEventDescriptor->getRating(),"") || 0 != strcmp(DishEventDescriptor->getStarRating(),""))) { + fmt += "|"; + } + fmt += "%s %s"; + Asprintf (&tmp, fmt.c_str(), DishEventDescriptor->getDescription() + , DishEventDescriptor->getRating() + , DishEventDescriptor->getStarRating()); + pEvent->SetDescription(tmp); + free(tmp); //LogD(2, prep("DishDescription: %s"), DishExtendedEventDescriptor->getText()); //LogD(2, prep("DishShortText: %s"), DishExtendedEventDescriptor->getShortText()); } } delete ExtendedEventDescriptors; delete ShortEventDescriptor; - delete DishExtendedEventDescriptor; - delete DishShortEventDescriptor; + delete DishEventDescriptor; pEvent->SetComponents (Components); |