X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/2b557e7ef4b0518736c5162a501cd9bc743930b3..58f7595413ff237526e5342d2346255d9396e60d:/lib/dvb/epgcache.cpp diff --git a/lib/dvb/epgcache.cpp b/lib/dvb/epgcache.cpp index 47da4101..8089afa1 100644 --- a/lib/dvb/epgcache.cpp +++ b/lib/dvb/epgcache.cpp @@ -58,7 +58,7 @@ eventData::eventData(const eit_event_struct* e, int size, int type) int ptr=10; int descriptors_length = (data[ptr++]&0x0F) << 8; descriptors_length |= data[ptr++]; - while ( descriptors_length > 0 ) + while ( descriptors_length ) { __u8 *descr = data+ptr; int descr_len = descr[1]+2; @@ -83,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; @@ -92,9 +93,11 @@ eventData::eventData(const eit_event_struct* e, int size, int type) const eit_event_struct* eventData::get() const { - int pos = 12; + int pos = 10; int tmp = ByteSize-12; memcpy(data, EITdata, 12); + int descriptors_length = (data[pos++]&0x0F) << 8; + descriptors_length |= data[pos++]; __u32 *p = (__u32*)(EITdata+12); while(tmp>0) { @@ -106,9 +109,12 @@ const eit_event_struct* eventData::get() const memcpy(data+pos, it->second.second, b ); pos += b; } + else + eFatal("LINE %d descriptor not found in descriptor cache %08x!!!!!!", __LINE__, *(p-1)); tmp-=4; } - + ASSERT(pos <= 4108); + ASSERT((pos-12) == descriptors_length); return (const eit_event_struct*)data; } @@ -117,15 +123,17 @@ eventData::~eventData() if ( ByteSize ) { CacheSize-=ByteSize; - ByteSize-=12; + int descriptors_length = (EITdata[10]&0x0F) << 8; + descriptors_length |= EITdata[11]; __u32 *d = (__u32*)(EITdata+12); - while(ByteSize) + while(descriptors_length) { descriptorMap::iterator it = descriptors.find(*d++); if ( it != descriptors.end() ) { descriptorPair &p = it->second; + descriptors_length -= (it->second.second[1]+2); if (!--p.first) // no more used descriptor { CacheSize -= it->second.second[1]; @@ -133,9 +141,11 @@ eventData::~eventData() descriptors.erase(it); // remove entry from descriptor map } } - ByteSize-=4; + else + eFatal("LINE %d descriptor not found in descriptor cache %08x!!!!!!", __LINE__, *(d-1)); } delete [] EITdata; + ASSERT(!descriptors_length); } } @@ -711,7 +721,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()); @@ -778,6 +788,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; @@ -864,7 +875,7 @@ void eEPGCache::load() } char text1[13]; fread( text1, 13, 1, f); - if ( !strncmp( text1, "ENIGMA_EPG_V5", 13) ) + if ( !strncmp( text1, "ENIGMA_EPG_V6", 13) ) { fread( &size, sizeof(int), 1, f); while(size--) @@ -967,7 +978,7 @@ void eEPGCache::save() { unsigned int magic = 0x98765432; fwrite( &magic, sizeof(int), 1, f); - const char *text = "ENIGMA_EPG_V5"; + const char *text = "ENIGMA_EPG_V6"; fwrite( text, 13, 1, f ); int size = eventDB.size(); fwrite( &size, sizeof(int), 1, f ); @@ -1474,6 +1485,7 @@ RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, RESULT eEPGCache::startTimeQuery(const eServiceReference &service, time_t begin, int minutes) { + Lock(); eventCache::iterator It = eventDB.find(handleGroup(service)); if ( It != eventDB.end() && It->second.second.size() ) { @@ -1500,8 +1512,10 @@ RESULT eEPGCache::startTimeQuery(const eServiceReference &service, time_t begin, m_timemap_cursor = It->second.second.begin(); const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)handleGroup(service); currentQueryTsidOnid = (ref.getTransportStreamID().get()<<16) | ref.getOriginalNetworkID().get(); + Unlock(); return 0; } + Unlock(); return -1; } @@ -2131,6 +2145,8 @@ PyObject *eEPGCache::search(ePyObject arg) return NULL; } + ASSERT(descridx <= 512); + if (descridx > -1) { int maxcount=maxmatches; @@ -2240,10 +2256,7 @@ PyObject *eEPGCache::search(ePyObject arg) } if (!ret) - { - Py_INCREF(Py_None); - ret=Py_None; - } + Py_RETURN_NONE; return ret; } @@ -2442,6 +2455,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; @@ -2455,6 +2469,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(); @@ -2520,7 +2535,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]); @@ -2597,19 +2612,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" ); @@ -2619,15 +2636,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)