X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/e5f1c45c07b1ff43c0113a51128f60bd3e348aa4..daf0e9d82075e4f2bf9dc73267acc282c5d4bd1d:/lib/dvb/epgcache.cpp diff --git a/lib/dvb/epgcache.cpp b/lib/dvb/epgcache.cpp index 6adab399..47ebb355 100644 --- a/lib/dvb/epgcache.cpp +++ b/lib/dvb/epgcache.cpp @@ -21,6 +21,30 @@ descriptorMap eventData::descriptors; __u8 eventData::data[4108]; extern const uint32_t crc32_table[256]; +const eServiceReference &handleGroup(const eServiceReference &ref) +{ + if (ref.flags & eServiceReference::isGroup) + { + ePtr res; + if (!eDVBResourceManager::getInstance(res)) + { + ePtr db; + if (!res->getChannelList(db)) + { + eBouquet *bouquet=0; + if (!db->getBouquet(ref, bouquet)) + { + std::list::iterator it(bouquet->m_services.begin()); + if (it != bouquet->m_services.end()) + return *it; + } + } + } + } + return ref; +} + + eventData::eventData(const eit_event_struct* e, int size, int type) :ByteSize(size&0xFF), type(type&0xFF) { @@ -59,6 +83,7 @@ eventData::eventData(const eit_event_struct* e, int size, int type) *pdescr++=crc; descriptors_length -= descr_len; } + ASSERT(pdescr <= &descr[65]); ByteSize = 12+((pdescr-descr)*4); EITdata = new __u8[ByteSize]; CacheSize+=ByteSize; @@ -84,6 +109,7 @@ const eit_event_struct* eventData::get() const } tmp-=4; } + ASSERT(pos <= 4108); return (const eit_event_struct*)data; } @@ -109,6 +135,8 @@ eventData::~eventData() descriptors.erase(it); // remove entry from descriptor map } } + else + eFatal("[descriptor not found in descriptor cache!!!!!!"); ByteSize-=4; } delete [] EITdata; @@ -687,7 +715,7 @@ void eEPGCache::cleanLoop() content_time_tables.find( DBIt->first ); if ( x != content_time_tables.end() ) { - timeMap &tmMap = eventDB[DBIt->first].second; + timeMap &tmMap = DBIt->second.second; for ( contentMap::iterator i = x->second.begin(); i != x->second.end(); ) { for ( contentTimeMap::iterator it(i->second.begin()); @@ -754,6 +782,7 @@ void eEPGCache::gotMessage( const Message &msg ) #ifdef ENABLE_PRIVATE_EPG case Message::got_private_pid: { + singleLock s(channel_map_lock); for (channelMapIterator it(m_knownChannels.begin()); it != m_knownChannels.end(); ++it) { eDVBChannel *channel = (eDVBChannel*) it->first; @@ -1317,7 +1346,7 @@ RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, co // if t == -1 we search the current event... { singleLock s(cache_lock); - uniqueEPGKey key(service); + uniqueEPGKey key(handleGroup(service)); // check if EPG for this service is ready... eventCache::iterator It = eventDB.find( key ); @@ -1393,7 +1422,7 @@ RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, eP RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, const eventData *&result ) { singleLock s(cache_lock); - uniqueEPGKey key( service ); + uniqueEPGKey key(handleGroup(service)); eventCache::iterator It = eventDB.find( key ); if ( It != eventDB.end() && !It->second.first.empty() ) // entrys cached? @@ -1450,7 +1479,8 @@ RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, RESULT eEPGCache::startTimeQuery(const eServiceReference &service, time_t begin, int minutes) { - eventCache::iterator It = eventDB.find( service ); + Lock(); + eventCache::iterator It = eventDB.find(handleGroup(service)); if ( It != eventDB.end() && It->second.second.size() ) { m_timemap_end = minutes != -1 ? It->second.second.upper_bound(begin+minutes*60) : It->second.second.end(); @@ -1474,10 +1504,12 @@ RESULT eEPGCache::startTimeQuery(const eServiceReference &service, time_t begin, } else m_timemap_cursor = It->second.second.begin(); - const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service; + const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)handleGroup(service); currentQueryTsidOnid = (ref.getTransportStreamID().get()<<16) | ref.getOriginalNetworkID().get(); + Unlock(); return 0; } + Unlock(); return -1; } @@ -1732,7 +1764,7 @@ PyObject *eEPGCache::lookupEvent(ePyObject list, ePyObject convertFunc) break; } } - eServiceReference ref(PyString_AS_STRING(service)); + eServiceReference ref(handleGroup(eServiceReference(PyString_AS_STRING(service)))); if (ref.type != eServiceReference::idDVB) { eDebug("service reference for epg query is not valid"); @@ -2107,10 +2139,12 @@ PyObject *eEPGCache::search(ePyObject arg) return NULL; } + ASSERT(descridx <= 512); + if (descridx > -1) { int maxcount=maxmatches; - eServiceReferenceDVB ref(refstr?refstr:""); + eServiceReferenceDVB ref(refstr?(const eServiceReferenceDVB&)handleGroup(eServiceReference(refstr)):eServiceReferenceDVB("")); // ref is only valid in SIMILAR_BROADCASTING_SEARCH // in this case we start searching with the base service bool first = ref.valid() ? true : false; @@ -2216,10 +2250,7 @@ PyObject *eEPGCache::search(ePyObject arg) } if (!ret) - { - Py_INCREF(Py_None); - ret=Py_None; - } + Py_RETURN_NONE; return ret; } @@ -2418,6 +2449,7 @@ void eEPGCache::privateSectionRead(const uniqueEPGKey ¤t_service, const __ ptr += descr_len; } } + ASSERT(pdescr <= &descriptors[65]) __u8 event[4098]; eit_event_struct *ev_struct = (eit_event_struct*) event; ev_struct->running_status = 0; @@ -2431,6 +2463,7 @@ void eEPGCache::privateSectionRead(const uniqueEPGKey ¤t_service, const __ ptr+=(*d++)[1]; ptr+=2; } + ASSERT(ptr <= 4098); for ( std::map< date_time, std::list >::iterator it(start_times.begin()); it != start_times.end(); ++it ) { time_t now = eDVBLocalTimeHandler::getInstance()->nowTime(); @@ -2496,7 +2529,7 @@ void eEPGCache::channel_data::startPrivateReader() void eEPGCache::channel_data::readPrivateData( const __u8 *data) { - if ( seenPrivateSections.find( data[6] ) == seenPrivateSections.end() ) + if ( seenPrivateSections.find(data[6]) == seenPrivateSections.end() ) { cache->privateSectionRead(m_PrivateService, data); seenPrivateSections.insert(data[6]); @@ -2573,19 +2606,21 @@ void eEPGCache::channel_data::timeMHW2DVB( u_char day, u_char hours, u_char minu putenv("TZ=CET-1CEST,M3.5.0/2,M10.5.0/3"); tzset(); - tm *localnow = localtime( &dt ); + tm localnow; + localtime_r(&dt, &localnow); if (day == 7) day = 0; - if ( day + 1 < localnow->tm_wday ) // day + 1 to prevent old events to show for next week. + if ( day + 1 < localnow.tm_wday ) // day + 1 to prevent old events to show for next week. day += 7; if (local_hours <= 5) day++; - dt += 3600*24*(day - localnow->tm_wday); // Shift dt to the recording date (local time zone). - dt += 3600*(local_hours - localnow->tm_hour); // Shift dt to the recording hour. + dt += 3600*24*(day - localnow.tm_wday); // Shift dt to the recording date (local time zone). + dt += 3600*(local_hours - localnow.tm_hour); // Shift dt to the recording hour. - tm *recdate = gmtime( &dt ); // This will also take care of DST. + tm recdate; + gmtime_r( &dt, &recdate ); // This will also take care of DST. if ( old_tz == NULL ) unsetenv( "TZ" ); @@ -2595,15 +2630,15 @@ void eEPGCache::channel_data::timeMHW2DVB( u_char day, u_char hours, u_char minu // Calculate MJD according to annex in ETSI EN 300 468 int l=0; - if ( recdate->tm_mon <= 1 ) // Jan or Feb + if ( recdate.tm_mon <= 1 ) // Jan or Feb l=1; - int mjd = 14956 + recdate->tm_mday + int( (recdate->tm_year - l) * 365.25) + - int( (recdate->tm_mon + 2 + l * 12) * 30.6001); + int mjd = 14956 + recdate.tm_mday + int( (recdate.tm_year - l) * 365.25) + + int( (recdate.tm_mon + 2 + l * 12) * 30.6001); return_time[0] = (mjd & 0xFF00)>>8; return_time[1] = mjd & 0xFF; - timeMHW2DVB( recdate->tm_hour, minutes, return_time+2 ); + timeMHW2DVB( recdate.tm_hour, minutes, return_time+2 ); } void eEPGCache::channel_data::storeTitle(std::map<__u32, mhw_title_t>::iterator itTitle, std::string sumText, const __u8 *data)