diff options
| author | Andreas Monzner <andreas.monzner@multimedia-labs.de> | 2005-11-26 19:01:11 +0000 |
|---|---|---|
| committer | Andreas Monzner <andreas.monzner@multimedia-labs.de> | 2005-11-26 19:01:11 +0000 |
| commit | f94e2c9821eb8784ca03b7122485d4720ec6d6e6 (patch) | |
| tree | 6da2323d2220093ea1c3756dbddb8e02fded2969 /lib | |
| parent | 68271eeaf83872270f13cc01e98960367d7d553f (diff) | |
| download | enigma2-f94e2c9821eb8784ca03b7122485d4720ec6d6e6.tar.gz enigma2-f94e2c9821eb8784ca03b7122485d4720ec6d6e6.zip | |
add ability to select default encoding for dvb texts in many ways.. ( take a look in data/encodings.conf )
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/base/Makefile.am | 2 | ||||
| -rw-r--r-- | lib/base/encoding.cpp | 59 | ||||
| -rw-r--r-- | lib/base/encoding.h | 22 | ||||
| -rw-r--r-- | lib/base/estring.cpp | 22 | ||||
| -rw-r--r-- | lib/dvb/eit.cpp | 5 | ||||
| -rw-r--r-- | lib/dvb/epgcache.cpp | 10 | ||||
| -rw-r--r-- | lib/dvb/epgcache.h | 1 | ||||
| -rw-r--r-- | lib/service/event.cpp | 25 | ||||
| -rw-r--r-- | lib/service/event.h | 12 |
9 files changed, 122 insertions, 36 deletions
diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index 7c66c4db..f7176e27 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -7,4 +7,4 @@ libenigma_base_a_SOURCES = \ buffer.cpp ebase.cpp econfig.cpp eerror.cpp elock.cpp \ init.cpp message.cpp thread.cpp \ smartptr.cpp estring.cpp connection.cpp \ - filepush.cpp + filepush.cpp encoding.cpp diff --git a/lib/base/encoding.cpp b/lib/base/encoding.cpp new file mode 100644 index 00000000..e8651699 --- /dev/null +++ b/lib/base/encoding.cpp @@ -0,0 +1,59 @@ +#include <lib/base/encoding.h> +#include <lib/base/eerror.h> +#include <config.h> + +eDVBTextEncodingHandler encodingHandler; // the one and only instance + +eDVBTextEncodingHandler::eDVBTextEncodingHandler() +{ + const char * file=DATADIR "/enigma2/encoding.conf"; + FILE *f = fopen(file, "rt"); + if (f) + { + char *line = (char*) malloc(256); + size_t bufsize=256; + char countrycode[256]; + while( getline(&line, &bufsize, f) != -1 ) + { + if ( line[0] == '#' ) + continue; + int tsid, onid, encoding; + if ( sscanf( line, "%s ISO8859-%d", countrycode, &encoding ) == 2 ) + m_CountryCodeDefaultMapping[countrycode]=encoding; + else if ( (sscanf( line, "0x%x 0x%x ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) + ||(sscanf( line, "%d %d ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) ) + m_TransponderDefaultMapping[(tsid<<16)|onid]=encoding; + else if ( (sscanf( line, "0x%x 0x%x", &tsid, &onid ) == 2 ) + ||(sscanf( line, "%d %d", &tsid, &onid ) == 2 ) ) + m_TransponderUseTwoCharMapping.insert((tsid<<16)|onid); + else + eDebug("couldn't parse %s", line); + } + fclose(f); + free(line); + } + else + eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file); +} + +void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table) +{ + std::map<int, int>::iterator it = + m_TransponderDefaultMapping.find(tsidonid); + if ( it != m_TransponderDefaultMapping.end() ) + table = it->second; +} + +bool eDVBTextEncodingHandler::getTransponderUseTwoCharMapping(int tsidonid) +{ + return m_TransponderUseTwoCharMapping.find(tsidonid) != m_TransponderUseTwoCharMapping.end(); +} + +int eDVBTextEncodingHandler::getCountryCodeDefaultMapping( const std::string &country_code ) +{ + std::map<std::string, int>::iterator it = + m_CountryCodeDefaultMapping.find(country_code); + if ( it != m_CountryCodeDefaultMapping.end() ) + return it->second; + return 0; // ISO8859-1 / Latin1 +} diff --git a/lib/base/encoding.h b/lib/base/encoding.h new file mode 100644 index 00000000..3f107d66 --- /dev/null +++ b/lib/base/encoding.h @@ -0,0 +1,22 @@ +#ifndef __lib_base_encoding_h__ +#define __lib_base_encoding_h__ + +#include <string> +#include <set> +#include <map> + +class eDVBTextEncodingHandler +{ + std::map<std::string, int> m_CountryCodeDefaultMapping; + std::map<int, int> m_TransponderDefaultMapping; + std::set<int> m_TransponderUseTwoCharMapping; +public: + eDVBTextEncodingHandler(); + void getTransponderDefaultMapping(int tsidonid, int &table); + bool getTransponderUseTwoCharMapping(int tsidonid); + int getCountryCodeDefaultMapping( const std::string &country_code ); +}; + +extern eDVBTextEncodingHandler encodingHandler; + +#endif // __lib_base_encoding_h__
\ No newline at end of file diff --git a/lib/base/estring.cpp b/lib/base/estring.cpp index 4259c58f..10bfbef8 100644 --- a/lib/base/estring.cpp +++ b/lib/base/estring.cpp @@ -1,12 +1,10 @@ #include <string> #include <ctype.h> #include <limits.h> -#include <lib/base/elock.h> #include <lib/base/eerror.h> +#include <lib/base/encoding.h> #include <lib/base/estring.h> -static pthread_mutex_t lock=PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP; - std::string getNum(int val, int sys) { // Returns a string that contain the value val as string @@ -331,15 +329,8 @@ std::string convertDVBUTF8(const unsigned char *data, int len, int table, int ts int i=0, t=0; -#if 0 // FIXME if ( tsidonid ) - { - std::map<int, int>::iterator it = - std::string::TransponderDefaultMapping.find(tsidonid); - if ( it != std::string::TransponderDefaultMapping.end() ) - table = it->second; - } -#endif + encodingHandler.getTransponderDefaultMapping(tsidonid, table); switch(data[0]) { @@ -386,17 +377,18 @@ std::string convertDVBUTF8(const unsigned char *data, int len, int table, int ts break; } + bool useTwoCharMapping = + tsidonid && encodingHandler.getTransponderUseTwoCharMapping(tsidonid); + unsigned char res[2048]; while (i < len) { unsigned long code=0; -#if 0 // FIXME - if ( i+1 < len && tsidonid && - std::string::TransponderUseTwoCharMapping.find(tsidonid) != std::string::TransponderUseTwoCharMapping.end() && + if ( useTwoCharMapping && i+1 < len && (code=doVideoTexSuppl(data[i], data[i+1])) ) i+=2; -#endif + if (!code) code=recode(data[i++], table); if (!code) diff --git a/lib/dvb/eit.cpp b/lib/dvb/eit.cpp index b78b2279..cc2c29b2 100644 --- a/lib/dvb/eit.cpp +++ b/lib/dvb/eit.cpp @@ -14,10 +14,11 @@ void eDVBServiceEITHandler::EITready(int error) for (std::vector<EventInformationSection*>::const_iterator i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i) { - for (EventConstIterator ev = (*i)->getEvents()->begin(); ev != (*i)->getEvents()->end(); ++ev) + const EventInformationSection *eit = *i; + for (EventConstIterator ev = eit->getEvents()->begin(); ev != eit->getEvents()->end(); ++ev) { ePtr<eServiceEvent> evt = new eServiceEvent(); - evt->parseFrom(*ev); + evt->parseFrom(*ev,(eit->getTransportStreamId()<<16)|eit->getOriginalNetworkId()); if (!a) m_event_now = evt; else diff --git a/lib/dvb/epgcache.cpp b/lib/dvb/epgcache.cpp index 587d680c..6dea73bc 100644 --- a/lib/dvb/epgcache.cpp +++ b/lib/dvb/epgcache.cpp @@ -1066,7 +1066,8 @@ RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, eP { Event ev((uint8_t*)data->get()); result = new eServiceEvent(); - ret = result->parseFrom(&ev); + const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service; + ret = result->parseFrom(&ev, (ref.getTransportStreamID().get()<<16)|ref.getOriginalNetworkID().get()); } return ret; } @@ -1123,7 +1124,8 @@ RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, { Event ev((uint8_t*)data->get()); result = new eServiceEvent(); - ret = result->parseFrom(&ev); + const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service; + ret = result->parseFrom(&ev, (ref.getTransportStreamID().get()<<16)|ref.getOriginalNetworkID().get()); } return ret; } @@ -1147,6 +1149,8 @@ RESULT eEPGCache::startTimeQuery(const eServiceReference &service, time_t begin, } else m_timemap_cursor = It->second.second.begin(); + const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service; + currentQueryTsidOnid = (ref.getTransportStreamID().get()<<16) | ref.getOriginalNetworkID().get(); return 0; } return -1; @@ -1188,7 +1192,7 @@ RESULT eEPGCache::getNextTimeEntry(ePtr<eServiceEvent> &result) { Event ev((uint8_t*)m_timemap_cursor++->second->get()); result = new eServiceEvent(); - return result->parseFrom(&ev); + return result->parseFrom(&ev, currentQueryTsidOnid); } return -1; } diff --git a/lib/dvb/epgcache.h b/lib/dvb/epgcache.h index 3c2b612b..fe461d9d 100644 --- a/lib/dvb/epgcache.h +++ b/lib/dvb/epgcache.h @@ -221,6 +221,7 @@ private: void DVBChannelRunning(iDVBChannel *); timeMap::iterator m_timemap_cursor, m_timemap_end; + int currentQueryTsidOnid; // needed for getNextTimeEntry.. only valid until next startTimeQuery call #endif // SWIG public: static eEPGCache *getInstance() { return instance; } diff --git a/lib/service/event.cpp b/lib/service/event.cpp index 684c9e5e..cfd2ac5f 100644 --- a/lib/service/event.cpp +++ b/lib/service/event.cpp @@ -1,5 +1,6 @@ #include <lib/service/event.h> #include <lib/base/estring.h> +#include <lib/base/encoding.h> #include <lib/dvb/dvbtime.h> #include <dvbsi++/event_information_section.h> #include <dvbsi++/short_event_descriptor.h> @@ -52,7 +53,7 @@ std::string ISOtbl[MAX_LANG][2] = }; /* search for the presence of language from given EIT event descriptors*/ -bool eServiceEvent::loadLanguage(Event *evt, std::string lang) +bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid) { bool retval=0; for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc) @@ -62,10 +63,12 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang) case SHORT_EVENT_DESCRIPTOR: { const ShortEventDescriptor *sed = (ShortEventDescriptor*)*desc; - if (lang.empty() || sed->getIso639LanguageCode() == lang) + const std::string &cc = sed->getIso639LanguageCode(); + int table=encodingHandler.getCountryCodeDefaultMapping(cc); + if (lang.empty() || cc == lang) { - m_event_name = convertDVBUTF8(sed->getEventName()); - m_short_description = convertDVBUTF8(sed->getText()); + m_event_name = convertDVBUTF8(sed->getEventName(), table, tsidonid); + m_short_description = convertDVBUTF8(sed->getText(), table, tsidonid); retval=1; } break; @@ -73,9 +76,11 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang) case EXTENDED_EVENT_DESCRIPTOR: { const ExtendedEventDescriptor *eed = (ExtendedEventDescriptor*)*desc; - if (lang.empty() || eed->getIso639LanguageCode() == lang) + const std::string &cc = eed->getIso639LanguageCode(); + int table=encodingHandler.getCountryCodeDefaultMapping(cc); + if (lang.empty() || cc == lang) { - m_extended_description += convertDVBUTF8(eed->getText()); + m_extended_description += convertDVBUTF8(eed->getText(), table, tsidonid); retval=1; } #if 0 @@ -99,7 +104,7 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang) return retval; } -RESULT eServiceEvent::parseFrom(Event *evt) +RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid) { uint16_t stime_mjd = evt->getStartTimeMjd(); uint32_t stime_bcd = evt->getStartTimeBcd(); @@ -115,11 +120,11 @@ RESULT eServiceEvent::parseFrom(Event *evt) std::string country="de_DE"; // TODO use local data here for (int i=0; i < MAX_LANG; i++) if (country==ISOtbl[i][0]) - if (loadLanguage(evt,ISOtbl[i][1])) + if (loadLanguage(evt, ISOtbl[i][1], tsidonid)) return 0; - if (loadLanguage(evt,"eng")) + if (loadLanguage(evt, "eng", tsidonid)) return 0; - if (loadLanguage(evt,std::string())) + if (loadLanguage(evt, std::string(), tsidonid)) return 0; return 0; } diff --git a/lib/service/event.h b/lib/service/event.h index 7e6cf5d8..07106e40 100644 --- a/lib/service/event.h +++ b/lib/service/event.h @@ -1,7 +1,7 @@ #ifndef __lib_service_event_h #define __lib_service_event_h -#ifndef PYTHON +#ifndef SWIG #include <time.h> #include <lib/base/object.h> #include <string> @@ -11,14 +11,16 @@ class Event; class eServiceEvent: public iObject { DECLARE_REF(eServiceEvent); +#ifndef SWIG + bool loadLanguage(Event *event, std::string lang, int tsidonid); +#endif public: -#ifndef PYTHON +#ifndef SWIG time_t m_begin; int m_duration; std::string m_event_name, m_short_description, m_extended_description; // .. additional info - bool loadLanguage(Event *event, std::string lang); - RESULT parseFrom(Event *evt); + RESULT parseFrom(Event *evt, int tsidonid=0); #endif time_t getBeginTime() { return m_begin; } int getDuration() { return m_duration; } @@ -28,8 +30,8 @@ public: std::string getBeginTimeString(); }; -#ifndef PYTHON TEMPLATE_TYPEDEF(ePtr<eServiceEvent>, eServiceEventPtr); +#ifndef SWIG class eDebugClass: public iObject { |
