From 018c1c868aa4789438776f0c48b2e84bfcbbabf8 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Thu, 9 Feb 2012 16:27:23 +0400 Subject: [PATCH] eitd: move freesatHuffmanDecode to SIutils --- src/eitd/SIevents.hpp | 3 +- src/eitd/SIsections.cpp | 8 +-- src/eitd/SIsections.hpp | 10 ++-- src/eitd/SIutils.cpp | 110 ++++++++++++++++++++++++++++++++++++++++ src/eitd/SIutils.hpp | 8 +++ src/eitd/edvbstring.cpp | 19 +++++-- 6 files changed, 142 insertions(+), 16 deletions(-) diff --git a/src/eitd/SIevents.hpp b/src/eitd/SIevents.hpp index 653db3277..a37d8e3b2 100644 --- a/src/eitd/SIevents.hpp +++ b/src/eitd/SIevents.hpp @@ -95,6 +95,7 @@ struct descr_linkage_header { } __attribute__ ((packed)) ; #endif +#if 0 struct descr_pdc_header { unsigned descriptor_tag : 8; unsigned descriptor_length : 8; @@ -102,6 +103,7 @@ struct descr_pdc_header { unsigned pil1 : 8; unsigned pil2 : 8; } __attribute__ ((packed)) ; +#endif class SIlinkage { public: @@ -393,7 +395,6 @@ class SIevent std::string getText() const; void setText(const std::string &lang, const std::string &text); - // Aus dem Extended Descriptor std::string getExtendedText() const; void appendExtendedText(const std::string &lang, const std::string &text); diff --git a/src/eitd/SIsections.cpp b/src/eitd/SIsections.cpp index 9dd0e49f5..736c2c8c6 100644 --- a/src/eitd/SIsections.cpp +++ b/src/eitd/SIsections.cpp @@ -40,7 +40,7 @@ #include #include #ifdef ENABLE_FREESATEPG -#include "FreesatTables.hpp" +//#include "FreesatTables.hpp" #endif #include @@ -398,10 +398,6 @@ void SIsectionSDT::parseServiceDescriptor(const char *buf, SIservice &s) s.serviceTyp=sv->service_typ; is_blacklisted = check_blacklisted(s.original_network_id, s.transport_stream_id); if(sv->service_provider_name_length) { - //if(*buf < 0x06) // other code table -// s.providerName=std::string(buf+1, sv->service_provider_name_length-1); -// else -// s.providerName=std::string(buf, sv->service_provider_name_length); if ((*buf > 0x05) && (is_blacklisted)) s.providerName = CDVBString(("\x05" + std::string((const char *)(buf))).c_str(), sv->service_provider_name_length+1).getContent(); else @@ -489,7 +485,7 @@ void SIsectionSDT::parse(void) parsed = 1; } -#ifdef ENABLE_FREESATEPG +#if 0 //def ENABLE_FREESATEPG std::string SIsectionEIT::freesatHuffmanDecode(std::string input) { const char *src = input.c_str(); diff --git a/src/eitd/SIsections.hpp b/src/eitd/SIsections.hpp index 2b3132df9..ef7f67170 100644 --- a/src/eitd/SIsections.hpp +++ b/src/eitd/SIsections.hpp @@ -158,6 +158,10 @@ protected: class SIsectionEIT : /*public SIsection,*/ public EventInformationSection { +protected: + SIevents evts; + int parsed; + void parse(void); public: SIsectionEIT(uint8_t *buf) : /*SIsection(buf),*/ EventInformationSection(buf) { @@ -192,10 +196,6 @@ public: return parsed; } -protected: - SIevents evts; - int parsed; - void parse(void); #if 0 void parseDescriptors(const uint8_t *desc, unsigned len, SIevent &e); void parseShortEventDescriptor(const char *buf, SIevent &e, unsigned maxlen); @@ -205,10 +205,10 @@ protected: void parseParentalRatingDescriptor(const char *buf, SIevent &e, unsigned maxlen); void parseLinkageDescriptor(const char *buf, SIevent &e, unsigned maxlen); void parsePDCDescriptor(const char *buf, SIevent &e, unsigned maxlen); -#endif #ifdef ENABLE_FREESATEPG std::string freesatHuffmanDecode(std::string input); #endif +#endif }; diff --git a/src/eitd/SIutils.cpp b/src/eitd/SIutils.cpp index b51f29fb7..5f2c7915d 100644 --- a/src/eitd/SIutils.cpp +++ b/src/eitd/SIutils.cpp @@ -81,6 +81,8 @@ // #include +#include +#include #include #include @@ -240,3 +242,111 @@ void removeControlCodes(char *string) return ; } +#ifdef ENABLE_FREESATEPG +#include "FreesatTables.hpp" +std::string freesatHuffmanDecode(std::string input) +{ + const char *src = input.c_str(); + uint size = input.length(); + + if (src[1] == 1 || src[1] == 2) + { + std::string uncompressed(size * 3, ' '); + uint p = 0; + struct hufftab *table; + unsigned table_length; + if (src[1] == 1) + { + table = fsat_huffman1; + table_length = sizeof(fsat_huffman1) / sizeof(fsat_huffman1[0]); + } + else + { + table = fsat_huffman2; + table_length = sizeof(fsat_huffman2) / sizeof(fsat_huffman2[0]); + } + unsigned value = 0, byte = 2, bit = 0; + while (byte < 6 && byte < size) + { + value |= src[byte] << ((5-byte) * 8); + byte++; + } + char lastch = START; + + do + { + bool found = false; + unsigned bitShift = 0; + if (lastch == ESCAPE) + { + found = true; + // Encoded in the next 8 bits. + // Terminated by the first ASCII character. + char nextCh = (value >> 24) & 0xff; + bitShift = 8; + if ((nextCh & 0x80) == 0) + lastch = nextCh; + if (p >= uncompressed.length()) + uncompressed.resize(p+10); + uncompressed[p++] = nextCh; + } + else + { + for (unsigned j = 0; j < table_length; j++) + { + if (table[j].last == lastch) + { + unsigned mask = 0, maskbit = 0x80000000; + for (short kk = 0; kk < table[j].bits; kk++) + { + mask |= maskbit; + maskbit >>= 1; + } + if ((value & mask) == table[j].value) + { + char nextCh = table[j].next; + bitShift = table[j].bits; + if (nextCh != STOP && nextCh != ESCAPE) + { + if (p >= uncompressed.length()) + uncompressed.resize(p+10); + uncompressed[p++] = nextCh; + } + found = true; + lastch = nextCh; + break; + } + } + } + } + if (found) + { + // Shift up by the number of bits. + for (unsigned b = 0; b < bitShift; b++) + { + value = (value << 1) & 0xfffffffe; + if (byte < size) + value |= (src[byte] >> (7-bit)) & 1; + if (bit == 7) + { + bit = 0; + byte++; + } + else bit++; + } + } + else + { + // Entry missing in table. + uncompressed.resize(p); + uncompressed.append("..."); + return uncompressed; + } + } while (lastch != STOP && value != 0); + + uncompressed.resize(p); + return uncompressed; + } + else return input; +} +#endif diff --git a/src/eitd/SIutils.hpp b/src/eitd/SIutils.hpp index e4a697968..e109a2c6c 100644 --- a/src/eitd/SIutils.hpp +++ b/src/eitd/SIutils.hpp @@ -44,7 +44,11 @@ // Alles neu macht der Mai. // // + #include +#include + +#define ENABLE_FREESATEPG //FIXME time_t changeUTCtoCtime(const unsigned char *buffer, int local_time=1); time_t parseDVBtime(uint16_t mjd, uint32_t bcd); @@ -57,4 +61,8 @@ int saveStringToXMLfile(FILE *out, const char *string, int withControlCodes=0); // Entfernt die ControlCodes aus dem String (-> String wird evtl. kuerzer) void removeControlCodes(char *string); +#ifdef ENABLE_FREESATEPG +std::string freesatHuffmanDecode(std::string input); +#endif + #endif // SIUTILS_HPP diff --git a/src/eitd/edvbstring.cpp b/src/eitd/edvbstring.cpp index 48b621a9f..f2f5b4958 100644 --- a/src/eitd/edvbstring.cpp +++ b/src/eitd/edvbstring.cpp @@ -5,6 +5,8 @@ #include #include +#include + std::map CountryCodeDefaultMapping; std::map TransponderDefaultMapping; std::set TransponderUseTwoCharMapping; @@ -666,12 +668,21 @@ std::string convertDVBUTF8(const char *data, int len, int table, int tsidonid) ++i; {} //eDebug("unsup. Big5 subset of ISO/IEC 10646-1 enc."); break; + case 0x1F: + { +#ifdef ENABLE_FREESATEPG + std::string decoded_string = freesatHuffmanDecode(std::string(data, len)); + if (!decoded_string.empty()) return decoded_string; +#endif + } + ++i; + break; case 0x0: case 0xD ... 0xF: - case 0x15 ... 0x1F: - {} //eDebug("reserved %d", data[0]); - ++i; - break; + case 0x15 ... 0x1E: + {} //eDebug("reserved %d", data[0]); + ++i; + break; } //printf("convertDVBUTF8: table %d new table %d\n", table, newtable); if(!table)