From 35d5843a396a5b3144e3abc2571e150c514801e4 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Thu, 22 Sep 2011 17:24:02 +0200 Subject: re-factored code added stars rating --- dish.c | 248 +++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 171 insertions(+), 77 deletions(-) (limited to 'dish.c') diff --git a/dish.c b/dish.c index 75ea611..7ea85b1 100644 --- a/dish.c +++ b/dish.c @@ -20,82 +20,92 @@ namespace SI { // returns the value of a sequence of bits in the byte array - static unsigned int getBits(int bitIndex, int bitCount, const unsigned char *byteptr, int length) - { - union { - unsigned char b[4]; - unsigned long val; - } chunk; + static unsigned int getBits(int bitIndex, int bitCount, const unsigned char *byteptr, + int length) { + union + { + unsigned char b[4]; + unsigned long val; + } chunk; - int offset = bitIndex >> 3; - int bitnum = bitIndex - (offset << 3); - int rightend = 32 - bitnum - bitCount; + int offset = bitIndex >> 3; + int bitnum = bitIndex - (offset << 3); + int rightend = 32 - bitnum - bitCount; - chunk.b[3] = byteptr[offset]; - chunk.b[2] = (offset+1 < length) ? byteptr[offset+1] : 0; - chunk.b[1] = (offset+2 < length) ? byteptr[offset+2] : 0; - chunk.b[0] = 0; // Never need to look this far ahead. + chunk.b[3] = byteptr[offset]; + chunk.b[2] = (offset + 1 < length) ? byteptr[offset + 1] : 0; + chunk.b[1] = (offset + 2 < length) ? byteptr[offset + 2] : 0; + chunk.b[0] = 0; // Never need to look this far ahead. - return (unsigned int)(((chunk.val & (0xFFFFFFFF >> bitnum)) >> rightend)); + return (unsigned int) ((((((chunk.val & (0xFFFFFFFF >> bitnum)) >> rightend))))); } - DishDescriptor::DishDescriptor(UnimplementedDescriptor *unimplementedDesc) + DishDescriptor::DishDescriptor() { - text = NULL; + name = NULL; shortText = NULL; + description = NULL; decompressed = NULL; - this->unimplementedDesc = unimplementedDesc; + DishTheme = 0; + DishCategory = 0; + mpaaRating = 0; + starRating = 0; } DishDescriptor::~DishDescriptor() { delete [] decompressed; decompressed = NULL; - delete unimplementedDesc; + delete name; + name = NULL; + delete shortText; + shortText = NULL; + delete description; + description = NULL; } - const char *DishDescriptor::getTheme(int contentNibleLvl2) + const char *DishDescriptor::getTheme() { - const char* theme; - using namespace DISH_THEMES; + const char *theme; + using namespace DISH_THEMES; - switch (contentNibleLvl2) { - case Movie: - theme = "Movie"; - break; - case Sports: - theme = "Sports"; - break; - case News_Business: - theme = "News/Business"; - break; - case Family_Children: - theme = "Family/Children"; - break; - case Education: - theme = "Education"; - break; - case Series_Special: - theme = "Series/Special"; - break; - case Music_Art: - theme = "Music/Art"; - break; - case Religious: - theme = "Religious"; - break; - default: - theme = ""; - break; - } - return theme; + switch (DishTheme){ + case Movie: + theme = "Movie"; + break; + case Sports: + theme = "Sports"; + break; + case News_Business: + theme = "News/Business"; + break; + case Family_Children: + theme = "Family/Children"; + break; + case Education: + theme = "Education"; + break; + case Series_Special: + theme = "Series/Special"; + break; + case Music_Art: + theme = "Music/Art"; + break; + case Religious: + theme = "Religious"; + break; + default: + theme = ""; + break; + } + return theme; } - const char *DishDescriptor::getCategory(int userNible) + const char *DishDescriptor::getCategory() { - using namespace DISH_CATEGORIES; + using namespace DISH_CATEGORIES; - switch (userNible) { + switch (DishCategory) { case Action: return "Action"; case ActionSports: return "Action Sports"; case Adults_only: return "Adults only"; @@ -253,13 +263,108 @@ namespace SI case Yoga: return "Yoga"; default: return ""; } + } + void DishDescriptor::setExtendedtData(unsigned char Tid, CharArray data) + { + Decompress(Tid, data); + if (decompressed) { + 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 = new string((char*)decompressed); + description = new string((split[1] == 0x20) ? split + 2 : split + 1); + }else{ + description = new string((char*)decompressed); + } + delete[] decompressed; + decompressed = NULL; + } else { + shortText = new string(); + description = new string(); + } } - void DishDescriptor::Decompress(unsigned char Tid) + const char *DishDescriptor::getShortText(void) { - const unsigned char *str = unimplementedDesc->getData().getData(); - const unsigned char *cmp = NULL; // Compressed data + string tmp = ""; + if (shortText != NULL) tmp += *shortText; + if(DishTheme > 0){ + if(tmp != "") tmp += " - "; + + tmp += getTheme(); + } + if(DishCategory > 0){ + if(tmp != "") tmp += " - "; + + tmp += getCategory(); + } + return tmp.c_str(); + } + + const char *DishDescriptor::getDescription(void) { + string tmp = ""; + if (description != NULL) tmp += *description; + char* rating = getRating(); + if (rating && rating != "") { + if(tmp != "") tmp += "|"; + tmp += rating; + } + if (starRating > 0) { + if(tmp != "") tmp += "|"; + tmp += getStarRating(); + } + return tmp.c_str(); + } + + 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" }; + 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) ? NULL : buffer; + } + + const char* DishDescriptor::getStarRating(){ + static const char *const critiques[8] = { "", "*", "*+", "**", "**+", "***", "***+", "****" }; + return critiques[starRating & 0x07]; + } + + + void DishDescriptor::Decompress(unsigned char Tid, CharArray data) + { + const unsigned char *str = data.getData(); + const unsigned char *cmp = NULL; int length = 0; // Length of compressed data unsigned int dLength = 0; // Length of decompressed data if((str[3] & 0xFC) == 0x80){ @@ -278,15 +383,14 @@ namespace SI HuffmanTable *table; unsigned int tableSize, numBits; if (Tid > 0x80) { - table = Table255; - tableSize = SIZE_TABLE_255; - numBits = 13; - } - else { - table = Table128; - tableSize = SIZE_TABLE_128; - numBits = 11; - } + table = Table255; + tableSize = SIZE_TABLE_255; + numBits = 13; + } else { + table = Table128; + tableSize = SIZE_TABLE_128; + numBits = 11; + } unsigned int bLength = length << 3; // number of bits unsigned int currentBit = 0, count = 0; while(currentBit < bLength - 1 && count < dLength){ @@ -305,18 +409,8 @@ 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); - } } - struct DishDescriptor::HuffmanTable DishDescriptor::Table128[SIZE_TABLE_128] = { { 0x0000, 0x20, 0x03 }, { 0x0100, 0x65, 0x04 }, { 0x0180, 0x74, 0x04 }, { 0x0200, 0x61, 0x04 }, { 0x0280, 0x6F, 0x04 }, { 0x0300, 0x73, 0x04 }, @@ -451,4 +545,4 @@ struct DishDescriptor::HuffmanTable DishDescriptor::Table255[SIZE_TABLE_255] = { { 0x1FFD, 0x02, 0x0D }, { 0x1FFE, 0x01, 0x0D }, { 0x1FFF, 0x00, 0x0D } }; -} //end of namespace +} //end of namespace -- cgit v1.2.3 From 3c9b4d23704e9460e7c3a0d5baa2c9d32feee116 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Thu, 22 Sep 2011 18:38:52 +0200 Subject: fix compile --- dish.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'dish.c') diff --git a/dish.c b/dish.c index 7ea85b1..d24c32f 100644 --- a/dish.c +++ b/dish.c @@ -12,9 +12,10 @@ #include "dish.h" #include -#include +//#include #include #include +#include namespace SI { @@ -306,8 +307,8 @@ namespace SI const char *DishDescriptor::getDescription(void) { string tmp = ""; if (description != NULL) tmp += *description; - char* rating = getRating(); - if (rating && rating != "") { + const char* rating = getRating(); + if (rating && strcmp(rating,"") != 0) { if(tmp != "") tmp += "|"; tmp += rating; } -- cgit v1.2.3 From d826a6882e10a69336aa6c751e6822eada604100 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Thu, 22 Sep 2011 19:48:39 +0200 Subject: added missing setShortData --- dish.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'dish.c') diff --git a/dish.c b/dish.c index d24c32f..74e53ff 100644 --- a/dish.c +++ b/dish.c @@ -266,6 +266,18 @@ namespace SI } } + void DishDescriptor::setShortData(unsigned char Tid, CharArray data) + { + Decompress(Tid, data); + if (decompressed) { + name = new string((char*)decompressed); + delete[] decompressed; + decompressed = NULL; + } else { + name = new string(); + } + } + void DishDescriptor::setExtendedtData(unsigned char Tid, CharArray data) { Decompress(Tid, data); -- cgit v1.2.3 From e228e74a720c8f0b7e48c0909a2a29ddc7620252 Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Sun, 2 Oct 2011 17:54:14 +0200 Subject: do not use member pointers --- dish.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'dish.c') diff --git a/dish.c b/dish.c index 74e53ff..4919ad8 100644 --- a/dish.c +++ b/dish.c @@ -43,9 +43,9 @@ namespace SI DishDescriptor::DishDescriptor() { - name = NULL; - shortText = NULL; - description = NULL; + name = ""; + shortText = ""; + description = ""; decompressed = NULL; DishTheme = 0; DishCategory = 0; @@ -57,12 +57,12 @@ namespace SI { delete [] decompressed; decompressed = NULL; - delete name; - name = NULL; - delete shortText; - shortText = NULL; - delete description; - description = NULL; +// delete name; +// name = NULL; +// delete shortText; +// shortText = NULL; +// delete description; +// description = NULL; } const char *DishDescriptor::getTheme() @@ -270,11 +270,11 @@ namespace SI { Decompress(Tid, data); if (decompressed) { - name = new string((char*)decompressed); + name = string((char*)decompressed); delete[] decompressed; decompressed = NULL; } else { - name = new string(); +// name = new string(); } } @@ -286,23 +286,24 @@ namespace SI //LogD(2, prep("dLength:%d, length:%d, count:%d, decompressed: %s"), dLength, length, count, decompressed); if(split){ *split = 0; - shortText = new string((char*)decompressed); - description = new string((split[1] == 0x20) ? split + 2 : split + 1); + shortText = string((char*)decompressed); + description = string((split[1] == 0x20) ? split + 2 : split + 1); }else{ - description = new string((char*)decompressed); + description = string((char*)decompressed); } delete[] decompressed; decompressed = NULL; } else { - shortText = new string(); - description = new string(); +// shortText = new string(); +// description = new string(); } } const char *DishDescriptor::getShortText(void) { string tmp = ""; - if (shortText != NULL) tmp += *shortText; +// if (shortText != NULL) tmp += *shortText; + tmp += shortText; if(DishTheme > 0){ if(tmp != "") tmp += " - "; @@ -318,14 +319,15 @@ namespace SI const char *DishDescriptor::getDescription(void) { string tmp = ""; - if (description != NULL) tmp += *description; +// if (description != NULL) tmp += *description; + tmp += description; const char* rating = getRating(); if (rating && strcmp(rating,"") != 0) { - if(tmp != "") tmp += "|"; + if(tmp != "") tmp += " ~ "; tmp += rating; } if (starRating > 0) { - if(tmp != "") tmp += "|"; + if(tmp != "") tmp += " ~ "; tmp += getStarRating(); } return tmp.c_str(); @@ -348,6 +350,11 @@ namespace SI 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]); -- cgit v1.2.3 From b4da1b8b6dfec941cb97cc14c7fc14040a7695ff Mon Sep 17 00:00:00 2001 From: Dimitar Petrovski Date: Thu, 13 Oct 2011 19:58:23 +0200 Subject: NA tests, not working --- dish.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'dish.c') diff --git a/dish.c b/dish.c index 4919ad8..7dd8c37 100644 --- a/dish.c +++ b/dish.c @@ -270,7 +270,7 @@ namespace SI { Decompress(Tid, data); if (decompressed) { - name = string((char*)decompressed); + name = string(reinterpret_cast(decompressed)); delete[] decompressed; decompressed = NULL; } else { @@ -282,14 +282,15 @@ namespace SI { Decompress(Tid, data); if (decompressed) { - char *split = strchr((char*)((decompressed)), 0x0D); // Look for carriage return + string str; + char *split = strchr(reinterpret_cast(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 = string((char*)decompressed); + shortText = string(reinterpret_cast(decompressed)); description = string((split[1] == 0x20) ? split + 2 : split + 1); }else{ - description = string((char*)decompressed); + description = string(reinterpret_cast(decompressed)); } delete[] decompressed; decompressed = NULL; @@ -301,35 +302,43 @@ namespace SI const char *DishDescriptor::getShortText(void) { - string tmp = ""; + isyslog("EEPG DISH: shortText: %s", shortText.c_str()); + string tmp = shortText; // if (shortText != NULL) tmp += *shortText; - tmp += shortText; + //if (shortText != NULL) tmp.append(shortText); if(DishTheme > 0){ if(tmp != "") tmp += " - "; - tmp += getTheme(); + tmp.append(getTheme()); + isyslog("EEPG DISH: theme: %s", getTheme()); } if(DishCategory > 0){ if(tmp != "") tmp += " - "; - tmp += getCategory(); + isyslog("EEPG DISH: category: %s", getCategory()); + tmp.append(getCategory()); } + isyslog("EEPG DISH: full shorttext: %s", tmp.c_str()); return tmp.c_str(); } const char *DishDescriptor::getDescription(void) { - string tmp = ""; + string tmp = description; // if (description != NULL) tmp += *description; tmp += description; + isyslog("EEPG DISH: description: %s", description.c_str()); const char* rating = getRating(); if (rating && strcmp(rating,"") != 0) { if(tmp != "") tmp += " ~ "; tmp += rating; + isyslog("EEPG DISH: rating: %s", rating); } if (starRating > 0) { if(tmp != "") tmp += " ~ "; tmp += getStarRating(); + isyslog("EEPG DISH: star: %s", getStarRating()); } + isyslog("EEPG DISH: full description: %s", tmp.c_str()); return tmp.c_str(); } -- cgit v1.2.3