1 #include <lib/dvb/epgcache.h>
2 #include <lib/dvb/dvb.h>
7 #include <lib/service/event.h>
11 #include <unistd.h> // for usleep
12 #include <sys/vfs.h> // for statfs
13 // #include <libmd5sum.h>
14 #include <lib/base/eerror.h>
15 #include <lib/base/estring.h>
16 #include <lib/dvb/pmt.h>
17 #include <lib/dvb/db.h>
18 #include <lib/python/python.h>
19 #include <dvbsi++/descriptor_tag.h>
21 int eventData::CacheSize=0;
22 descriptorMap eventData::descriptors;
23 __u8 eventData::data[4108];
24 extern const uint32_t crc32_table[256];
26 const eServiceReference &handleGroup(const eServiceReference &ref)
28 if (ref.flags & eServiceReference::isGroup)
30 ePtr<eDVBResourceManager> res;
31 if (!eDVBResourceManager::getInstance(res))
33 ePtr<iDVBChannelList> db;
34 if (!res->getChannelList(db))
37 if (!db->getBouquet(ref, bouquet))
39 std::list<eServiceReference>::iterator it(bouquet->m_services.begin());
40 if (it != bouquet->m_services.end())
49 eventData::eventData(const eit_event_struct* e, int size, int type)
50 :ByteSize(size&0xFF), type(type&0xFF)
58 __u8 *data = (__u8*)e;
64 __u8 *descr = data+ptr;
65 int descr_len = descr[1];
67 if (size >= descr_len)
71 case EXTENDED_EVENT_DESCRIPTOR:
72 case SHORT_EVENT_DESCRIPTOR:
73 case LINKAGE_DESCRIPTOR:
74 case COMPONENT_DESCRIPTOR:
78 while(cnt++ < descr_len)
79 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ data[ptr++]) & 0xFF];
81 descriptorMap::iterator it =
82 descriptors.find(crc);
83 if ( it == descriptors.end() )
86 __u8 *d = new __u8[descr_len];
87 memcpy(d, descr, descr_len);
88 descriptors[crc] = descriptorPair(1, d);
95 default: // do not cache all other descriptors
104 ASSERT(pdescr <= &descr[65]);
105 ByteSize = 10+((pdescr-descr)*4);
106 EITdata = new __u8[ByteSize];
108 memcpy(EITdata, (__u8*) e, 10);
109 memcpy(EITdata+10, descr, ByteSize-10);
112 const eit_event_struct* eventData::get() const
115 int tmp = ByteSize-10;
116 memcpy(data, EITdata, 10);
117 int descriptors_length=0;
118 __u32 *p = (__u32*)(EITdata+10);
121 descriptorMap::iterator it =
122 descriptors.find(*p++);
123 if ( it != descriptors.end() )
125 int b = it->second.second[1]+2;
126 memcpy(data+pos, it->second.second, b );
128 descriptors_length += b;
131 eFatal("LINE %d descriptor not found in descriptor cache %08x!!!!!!", __LINE__, *(p-1));
135 data[10] = (descriptors_length >> 8) & 0x0F;
136 data[11] = descriptors_length & 0xFF;
137 return (eit_event_struct*)data;
140 eventData::~eventData()
144 CacheSize -= ByteSize;
145 __u32 *d = (__u32*)(EITdata+10);
149 descriptorMap::iterator it =
150 descriptors.find(*d++);
151 if ( it != descriptors.end() )
153 descriptorPair &p = it->second;
154 if (!--p.first) // no more used descriptor
156 CacheSize -= it->second.second[1];
157 delete [] it->second.second; // free descriptor memory
158 descriptors.erase(it); // remove entry from descriptor map
162 eFatal("LINE %d descriptor not found in descriptor cache %08x!!!!!!", __LINE__, *(d-1));
169 void eventData::load(FILE *f)
175 fread(&size, sizeof(int), 1, f);
178 fread(&id, sizeof(__u32), 1, f);
179 fread(&p.first, sizeof(int), 1, f);
180 fread(header, 2, 1, f);
181 int bytes = header[1]+2;
182 p.second = new __u8[bytes];
183 p.second[0] = header[0];
184 p.second[1] = header[1];
185 fread(p.second+2, bytes-2, 1, f);
192 void eventData::save(FILE *f)
194 int size=descriptors.size();
195 descriptorMap::iterator it(descriptors.begin());
196 fwrite(&size, sizeof(int), 1, f);
199 fwrite(&it->first, sizeof(__u32), 1, f);
200 fwrite(&it->second.first, sizeof(int), 1, f);
201 fwrite(it->second.second, it->second.second[1]+2, 1, f);
207 eEPGCache* eEPGCache::instance;
208 pthread_mutex_t eEPGCache::cache_lock=
209 PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
210 pthread_mutex_t eEPGCache::channel_map_lock=
211 PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
213 DEFINE_REF(eEPGCache)
215 eEPGCache::eEPGCache()
216 :messages(this,1), cleanTimer(eTimer::create(this))//, paused(0)
218 eDebug("[EPGC] Initialized EPGCache");
220 CONNECT(messages.recv_msg, eEPGCache::gotMessage);
221 CONNECT(eDVBLocalTimeHandler::getInstance()->m_timeUpdated, eEPGCache::timeUpdated);
222 CONNECT(cleanTimer->timeout, eEPGCache::cleanLoop);
224 ePtr<eDVBResourceManager> res_mgr;
225 eDVBResourceManager::getInstance(res_mgr);
227 eDebug("[eEPGCache] no resource manager !!!!!!!");
230 res_mgr->connectChannelAdded(slot(*this,&eEPGCache::DVBChannelAdded), m_chanAddedConn);
231 if (eDVBLocalTimeHandler::getInstance()->ready())
237 void eEPGCache::timeUpdated()
241 eDebug("[EPGC] time updated.. start EPG Mainloop");
244 messages.send(Message(Message::timeChanged));
247 void eEPGCache::DVBChannelAdded(eDVBChannel *chan)
251 // eDebug("[eEPGCache] add channel %p", chan);
252 channel_data *data = new channel_data(this);
253 data->channel = chan;
254 data->prevChannelState = -1;
255 #ifdef ENABLE_PRIVATE_EPG
256 data->m_PrivatePid = -1;
258 singleLock s(channel_map_lock);
259 m_knownChannels.insert( std::pair<iDVBChannel*, channel_data* >(chan, data) );
260 chan->connectStateChange(slot(*this, &eEPGCache::DVBChannelStateChanged), data->m_stateChangedConn);
264 void eEPGCache::DVBChannelRunning(iDVBChannel *chan)
266 channelMapIterator it =
267 m_knownChannels.find(chan);
268 if ( it == m_knownChannels.end() )
269 eDebug("[eEPGCache] will start non existing channel %p !!!", chan);
272 channel_data &data = *it->second;
273 ePtr<eDVBResourceManager> res_mgr;
274 if ( eDVBResourceManager::getInstance( res_mgr ) )
275 eDebug("[eEPGCache] no res manager!!");
278 ePtr<iDVBDemux> demux;
279 if ( data.channel->getDemux(demux, 0) )
281 eDebug("[eEPGCache] no demux!!");
286 RESULT res = demux->createSectionReader( this, data.m_NowNextReader );
289 eDebug("[eEPGCache] couldnt initialize nownext reader!!");
293 res = demux->createSectionReader( this, data.m_ScheduleReader );
296 eDebug("[eEPGCache] couldnt initialize schedule reader!!");
300 res = demux->createSectionReader( this, data.m_ScheduleOtherReader );
303 eDebug("[eEPGCache] couldnt initialize schedule other reader!!");
307 res = demux->createSectionReader( this, data.m_ViasatReader );
310 eDebug("[eEPGCache] couldnt initialize viasat reader!!");
313 #ifdef ENABLE_PRIVATE_EPG
314 res = demux->createSectionReader( this, data.m_PrivateReader );
317 eDebug("[eEPGCache] couldnt initialize private reader!!");
321 #ifdef ENABLE_MHW_EPG
322 res = demux->createSectionReader( this, data.m_MHWReader );
325 eDebug("[eEPGCache] couldnt initialize mhw reader!!");
328 res = demux->createSectionReader( this, data.m_MHWReader2 );
331 eDebug("[eEPGCache] couldnt initialize mhw reader!!");
335 messages.send(Message(Message::startChannel, chan));
336 // -> gotMessage -> changedService
342 void eEPGCache::DVBChannelStateChanged(iDVBChannel *chan)
344 channelMapIterator it =
345 m_knownChannels.find(chan);
346 if ( it != m_knownChannels.end() )
349 chan->getState(state);
350 if ( it->second->prevChannelState != state )
354 case iDVBChannel::state_ok:
356 eDebug("[eEPGCache] channel %p running", chan);
357 DVBChannelRunning(chan);
360 case iDVBChannel::state_release:
362 eDebug("[eEPGCache] remove channel %p", chan);
363 messages.send(Message(Message::leaveChannel, chan));
364 pthread_mutex_lock(&it->second->channel_active);
365 singleLock s(channel_map_lock);
366 m_knownChannels.erase(it);
367 pthread_mutex_unlock(&it->second->channel_active);
370 // -> gotMessage -> abortEPG
373 default: // ignore all other events
377 it->second->prevChannelState = state;
382 bool eEPGCache::FixOverlapping(std::pair<eventMap,timeMap> &servicemap, time_t TM, int duration, const timeMap::iterator &tm_it, const uniqueEPGKey &service)
385 timeMap::iterator tmp = tm_it;
386 while ((tmp->first+tmp->second->getDuration()-300) > TM)
389 #ifdef ENABLE_PRIVATE_EPG
390 && tmp->second->type != PRIVATE
393 && tmp->second->type != MHW
397 __u16 event_id = tmp->second->getEventID();
398 servicemap.first.erase(event_id);
400 Event evt((uint8_t*)tmp->second->get());
402 event.parseFrom(&evt, service.sid<<16|service.onid);
403 eDebug("(1)erase no more used event %04x %d\n%s %s\n%s",
404 service.sid, event_id,
405 event.getBeginTimeString().c_str(),
406 event.getEventName().c_str(),
407 event.getExtendedDescription().c_str());
410 if (tmp == servicemap.second.begin())
412 servicemap.second.erase(tmp);
416 servicemap.second.erase(tmp--);
421 if (tmp == servicemap.second.begin())
428 while(tmp->first < (TM+duration-300))
430 if (tmp->first != TM && tmp->second->type != PRIVATE)
432 __u16 event_id = tmp->second->getEventID();
433 servicemap.first.erase(event_id);
435 Event evt((uint8_t*)tmp->second->get());
437 event.parseFrom(&evt, service.sid<<16|service.onid);
438 eDebug("(2)erase no more used event %04x %d\n%s %s\n%s",
439 service.sid, event_id,
440 event.getBeginTimeString().c_str(),
441 event.getEventName().c_str(),
442 event.getExtendedDescription().c_str());
445 servicemap.second.erase(tmp++);
450 if (tmp == servicemap.second.end())
456 void eEPGCache::sectionRead(const __u8 *data, int source, channel_data *channel)
458 eit_t *eit = (eit_t*) data;
460 int len=HILO(eit->section_length)-1;//+3-4;
465 // This fixed the EPG on the Multichoice irdeto systems
466 // the EIT packet is non-compliant.. their EIT packet stinks
467 if ( data[ptr-1] < 0x40 )
470 // Cablecom HACK .. tsid / onid in eit data are incorrect.. so we use
471 // it from running channel (just for current transport stream eit data)
472 bool use_transponder_chid = source == SCHEDULE || (source == NOWNEXT && data[0] == 0x4E);
473 eDVBChannelID chid = channel->channel->getChannelID();
474 uniqueEPGKey service( HILO(eit->service_id),
475 use_transponder_chid ? chid.original_network_id.get() : HILO(eit->original_network_id),
476 use_transponder_chid ? chid.transport_stream_id.get() : HILO(eit->transport_stream_id));
478 eit_event_struct* eit_event = (eit_event_struct*) (data+ptr);
482 time_t TM = parseDVBtime( eit_event->start_time_1, eit_event->start_time_2, eit_event->start_time_3, eit_event->start_time_4, eit_event->start_time_5);
483 time_t now = ::time(0);
485 if ( TM != 3599 && TM > -1)
486 channel->haveData |= source;
488 singleLock s(cache_lock);
489 // hier wird immer eine eventMap zurück gegeben.. entweder eine vorhandene..
490 // oder eine durch [] erzeugte
491 std::pair<eventMap,timeMap> &servicemap = eventDB[service];
492 eventMap::iterator prevEventIt = servicemap.first.end();
493 timeMap::iterator prevTimeIt = servicemap.second.end();
497 eit_event_size = HILO(eit_event->descriptors_loop_length)+EIT_LOOP_SIZE;
499 duration = fromBCD(eit_event->duration_1)*3600+fromBCD(eit_event->duration_2)*60+fromBCD(eit_event->duration_3);
501 eit_event->start_time_1,
502 eit_event->start_time_2,
503 eit_event->start_time_3,
504 eit_event->start_time_4,
505 eit_event->start_time_5);
510 if ( TM != 3599 && (TM+duration < now || TM > now+14*24*60*60) )
513 if ( now <= (TM+duration) || TM == 3599 /*NVOD Service*/ ) // old events should not be cached
515 __u16 event_id = HILO(eit_event->event_id);
516 // eDebug("event_id is %d sid is %04x", event_id, service.sid);
519 int ev_erase_count = 0;
520 int tm_erase_count = 0;
522 // search in eventmap
523 eventMap::iterator ev_it =
524 servicemap.first.find(event_id);
526 // entry with this event_id is already exist ?
527 if ( ev_it != servicemap.first.end() )
529 if ( source > ev_it->second->type ) // update needed ?
530 goto next; // when not.. then skip this entry
532 // search this event in timemap
533 timeMap::iterator tm_it_tmp =
534 servicemap.second.find(ev_it->second->getStartTime());
536 if ( tm_it_tmp != servicemap.second.end() )
538 if ( tm_it_tmp->first == TM ) // just update eventdata
541 eventData *tmp = ev_it->second;
542 ev_it->second = tm_it_tmp->second =
543 new eventData(eit_event, eit_event_size, source);
544 if (FixOverlapping(servicemap, TM, duration, tm_it_tmp, service))
546 prevEventIt = servicemap.first.end();
547 prevTimeIt = servicemap.second.end();
552 else // event has new event begin time
555 // delete the found record from timemap
556 servicemap.second.erase(tm_it_tmp);
557 prevTimeIt=servicemap.second.end();
562 // search in timemap, for check of a case if new time has coincided with time of other event
563 // or event was is not found in eventmap
564 timeMap::iterator tm_it =
565 servicemap.second.find(TM);
567 if ( tm_it != servicemap.second.end() )
569 // event with same start time but another event_id...
570 if ( source > tm_it->second->type &&
571 ev_it == servicemap.first.end() )
572 goto next; // when not.. then skip this entry
574 // search this time in eventmap
575 eventMap::iterator ev_it_tmp =
576 servicemap.first.find(tm_it->second->getEventID());
578 if ( ev_it_tmp != servicemap.first.end() )
581 // delete the found record from eventmap
582 servicemap.first.erase(ev_it_tmp);
583 prevEventIt=servicemap.first.end();
586 evt = new eventData(eit_event, eit_event_size, source);
588 bool consistencyCheck=true;
590 if (ev_erase_count > 0 && tm_erase_count > 0) // 2 different pairs have been removed
593 delete ev_it->second;
594 delete tm_it->second;
598 else if (ev_erase_count == 0 && tm_erase_count > 0)
601 delete ev_it->second;
602 tm_it=prevTimeIt=servicemap.second.insert( prevTimeIt, std::pair<const time_t, eventData*>( TM, evt ) );
605 else if (ev_erase_count > 0 && tm_erase_count == 0)
608 delete tm_it->second;
609 ev_it=prevEventIt=servicemap.first.insert( prevEventIt, std::pair<const __u16, eventData*>( event_id, evt) );
612 else // added new eventData
615 consistencyCheck=false;
617 ev_it=prevEventIt=servicemap.first.insert( prevEventIt, std::pair<const __u16, eventData*>( event_id, evt) );
618 tm_it=prevTimeIt=servicemap.second.insert( prevTimeIt, std::pair<const time_t, eventData*>( TM, evt ) );
622 if ( consistencyCheck )
624 if ( tm_it->second != evt || ev_it->second != evt )
625 eFatal("tm_it->second != ev_it->second");
626 else if ( tm_it->second->getStartTime() != tm_it->first )
627 eFatal("event start_time(%d) non equal timemap key(%d)",
628 tm_it->second->getStartTime(), tm_it->first );
629 else if ( tm_it->first != TM )
630 eFatal("timemap key(%d) non equal TM(%d)",
632 else if ( ev_it->second->getEventID() != ev_it->first )
633 eFatal("event_id (%d) non equal event_map key(%d)",
634 ev_it->second->getEventID(), ev_it->first);
635 else if ( ev_it->first != event_id )
636 eFatal("eventmap key(%d) non equal event_id(%d)",
637 ev_it->first, event_id );
640 if (FixOverlapping(servicemap, TM, duration, tm_it, service))
642 prevEventIt = servicemap.first.end();
643 prevTimeIt = servicemap.second.end();
648 if ( servicemap.first.size() != servicemap.second.size() )
650 FILE *f = fopen("/hdd/event_map.txt", "w+");
652 for (eventMap::iterator it(servicemap.first.begin())
653 ; it != servicemap.first.end(); ++it )
654 fprintf(f, "%d(key %d) -> time %d, event_id %d, data %p\n",
655 i++, (int)it->first, (int)it->second->getStartTime(), (int)it->second->getEventID(), it->second );
657 f = fopen("/hdd/time_map.txt", "w+");
659 for (timeMap::iterator it(servicemap.second.begin())
660 ; it != servicemap.second.end(); ++it )
661 fprintf(f, "%d(key %d) -> time %d, event_id %d, data %p\n",
662 i++, (int)it->first, (int)it->second->getStartTime(), (int)it->second->getEventID(), it->second );
665 eFatal("(1)map sizes not equal :( sid %04x tsid %04x onid %04x size %d size2 %d",
666 service.sid, service.tsid, service.onid,
667 servicemap.first.size(), servicemap.second.size() );
670 ptr += eit_event_size;
671 eit_event=(eit_event_struct*)(((__u8*)eit_event)+eit_event_size);
675 void eEPGCache::flushEPG(const uniqueEPGKey & s)
677 eDebug("[EPGC] flushEPG %d", (int)(bool)s);
678 singleLock l(cache_lock);
679 if (s) // clear only this service
681 eventCache::iterator it = eventDB.find(s);
682 if ( it != eventDB.end() )
684 eventMap &evMap = it->second.first;
685 timeMap &tmMap = it->second.second;
687 for (eventMap::iterator i = evMap.begin(); i != evMap.end(); ++i)
692 // TODO .. search corresponding channel for removed service and remove this channel from lastupdated map
693 #ifdef ENABLE_PRIVATE_EPG
694 contentMaps::iterator it =
695 content_time_tables.find(s);
696 if ( it != content_time_tables.end() )
699 content_time_tables.erase(it);
704 else // clear complete EPG Cache
706 for (eventCache::iterator it(eventDB.begin());
707 it != eventDB.end(); ++it)
709 eventMap &evMap = it->second.first;
710 timeMap &tmMap = it->second.second;
711 for (eventMap::iterator i = evMap.begin(); i != evMap.end(); ++i)
717 #ifdef ENABLE_PRIVATE_EPG
718 content_time_tables.clear();
720 channelLastUpdated.clear();
721 singleLock m(channel_map_lock);
722 for (channelMapIterator it(m_knownChannels.begin()); it != m_knownChannels.end(); ++it)
723 it->second->startEPG();
725 eDebug("[EPGC] %i bytes for cache used", eventData::CacheSize);
728 void eEPGCache::cleanLoop()
730 singleLock s(cache_lock);
731 if (!eventDB.empty())
733 eDebug("[EPGC] start cleanloop");
735 time_t now = ::time(0);
737 for (eventCache::iterator DBIt = eventDB.begin(); DBIt != eventDB.end(); DBIt++)
739 bool updated = false;
740 for (timeMap::iterator It = DBIt->second.second.begin(); It != DBIt->second.second.end() && It->first < now;)
742 if ( now > (It->first+It->second->getDuration()) ) // outdated normal entry (nvod references to)
744 // remove entry from eventMap
745 eventMap::iterator b(DBIt->second.first.find(It->second->getEventID()));
746 if ( b != DBIt->second.first.end() )
748 // release Heap Memory for this entry (new ....)
749 // eDebug("[EPGC] delete old event (evmap)");
750 DBIt->second.first.erase(b);
753 // remove entry from timeMap
754 // eDebug("[EPGC] release heap mem");
756 DBIt->second.second.erase(It++);
757 // eDebug("[EPGC] delete old event (timeMap)");
763 #ifdef ENABLE_PRIVATE_EPG
766 contentMaps::iterator x =
767 content_time_tables.find( DBIt->first );
768 if ( x != content_time_tables.end() )
770 timeMap &tmMap = DBIt->second.second;
771 for ( contentMap::iterator i = x->second.begin(); i != x->second.end(); )
773 for ( contentTimeMap::iterator it(i->second.begin());
774 it != i->second.end(); )
776 if ( tmMap.find(it->second.first) == tmMap.end() )
777 i->second.erase(it++);
781 if ( i->second.size() )
784 x->second.erase(i++);
790 eDebug("[EPGC] stop cleanloop");
791 eDebug("[EPGC] %i bytes for cache used", eventData::CacheSize);
793 cleanTimer->start(CLEAN_INTERVAL,true);
796 eEPGCache::~eEPGCache()
798 messages.send(Message::quit);
799 kill(); // waiting for thread shutdown
800 singleLock s(cache_lock);
801 for (eventCache::iterator evIt = eventDB.begin(); evIt != eventDB.end(); evIt++)
802 for (eventMap::iterator It = evIt->second.first.begin(); It != evIt->second.first.end(); It++)
806 void eEPGCache::gotMessage( const Message &msg )
811 flushEPG(msg.service);
813 case Message::startChannel:
815 singleLock s(channel_map_lock);
816 channelMapIterator channel =
817 m_knownChannels.find(msg.channel);
818 if ( channel != m_knownChannels.end() )
819 channel->second->startChannel();
822 case Message::leaveChannel:
824 singleLock s(channel_map_lock);
825 channelMapIterator channel =
826 m_knownChannels.find(msg.channel);
827 if ( channel != m_knownChannels.end() )
828 channel->second->abortEPG();
834 #ifdef ENABLE_PRIVATE_EPG
835 case Message::got_private_pid:
837 singleLock s(channel_map_lock);
838 for (channelMapIterator it(m_knownChannels.begin()); it != m_knownChannels.end(); ++it)
840 eDVBChannel *channel = (eDVBChannel*) it->first;
841 channel_data *data = it->second;
842 eDVBChannelID chid = channel->getChannelID();
843 if ( chid.transport_stream_id.get() == msg.service.tsid &&
844 chid.original_network_id.get() == msg.service.onid &&
845 data->m_PrivatePid == -1 )
847 data->m_PrevVersion = -1;
848 data->m_PrivatePid = msg.pid;
849 data->m_PrivateService = msg.service;
850 int onid = chid.original_network_id.get();
851 onid |= 0x80000000; // we use highest bit as private epg indicator
852 chid.original_network_id = onid;
853 updateMap::iterator It = channelLastUpdated.find( chid );
854 int update = ( It != channelLastUpdated.end() ? ( UPDATE_INTERVAL - ( (::time(0)-It->second) * 1000 ) ) : ZAP_DELAY );
855 if (update < ZAP_DELAY)
857 data->startPrivateTimer->start(update, 1);
859 eDebug("[EPGC] next private update in %i min", update/60000);
860 else if (update >= 1000)
861 eDebug("[EPGC] next private update in %i sec", update/1000);
868 case Message::timeChanged:
872 eDebug("unhandled EPGCache Message!!");
877 void eEPGCache::thread()
887 void eEPGCache::load()
889 FILE *f = fopen("/hdd/epg.dat", "r");
892 unlink("/hdd/epg.dat");
896 unsigned char md5_saved[16];
897 unsigned char md5[16];
900 if (!md5_file("/hdd/epg.dat", 1, md5))
902 FILE *f = fopen("/hdd/epg.dat.md5", "r");
905 fread( md5_saved, 16, 1, f);
907 if ( !memcmp(md5_saved, md5, 16) )
914 unsigned int magic=0;
915 fread( &magic, sizeof(int), 1, f);
916 if (magic != 0x98765432)
918 eDebug("[EPGC] epg file has incorrect byte order.. dont read it");
923 fread( text1, 13, 1, f);
924 if ( !strncmp( text1, "ENIGMA_EPG_V7", 13) )
926 singleLock s(cache_lock);
927 fread( &size, sizeof(int), 1, f);
934 fread( &key, sizeof(uniqueEPGKey), 1, f);
935 fread( &size, sizeof(int), 1, f);
941 fread( &type, sizeof(__u8), 1, f);
942 fread( &len, sizeof(__u8), 1, f);
943 event = new eventData(0, len, type);
944 event->EITdata = new __u8[len];
945 eventData::CacheSize+=len;
946 fread( event->EITdata, len, 1, f);
947 evMap[ event->getEventID() ]=event;
948 tmMap[ event->getStartTime() ]=event;
951 eventDB[key]=std::pair<eventMap,timeMap>(evMap,tmMap);
954 eDebug("[EPGC] %d events read from /hdd/epg.dat", cnt);
955 #ifdef ENABLE_PRIVATE_EPG
957 fread( text2, 11, 1, f);
958 if ( !strncmp( text2, "PRIVATE_EPG", 11) )
961 fread( &size, sizeof(int), 1, f);
966 fread( &key, sizeof(uniqueEPGKey), 1, f);
967 eventMap &evMap=eventDB[key].first;
968 fread( &size, sizeof(int), 1, f);
973 fread( &content_id, sizeof(int), 1, f);
974 fread( &size, sizeof(int), 1, f);
979 fread( &time1, sizeof(time_t), 1, f);
980 fread( &time2, sizeof(time_t), 1, f);
981 fread( &event_id, sizeof(__u16), 1, f);
982 content_time_tables[key][content_id][time1]=std::pair<time_t, __u16>(time2, event_id);
983 eventMap::iterator it =
984 evMap.find(event_id);
985 if (it != evMap.end())
986 it->second->type = PRIVATE;
991 #endif // ENABLE_PRIVATE_EPG
994 eDebug("[EPGC] don't read old epg database");
1000 void eEPGCache::save()
1004 if (statfs("/hdd", &s)<0)
1012 // prevent writes to builtin flash
1013 if ( tmp < 1024*1024*50 ) // storage size < 50MB
1016 // check for enough free space on storage
1019 if ( tmp < (eventData::CacheSize*12)/10 ) // 20% overhead
1022 FILE *f = fopen("/hdd/epg.dat", "w");
1026 unsigned int magic = 0x98765432;
1027 fwrite( &magic, sizeof(int), 1, f);
1028 const char *text = "UNFINISHED_V7";
1029 fwrite( text, 13, 1, f );
1030 int size = eventDB.size();
1031 fwrite( &size, sizeof(int), 1, f );
1032 for (eventCache::iterator service_it(eventDB.begin()); service_it != eventDB.end(); ++service_it)
1034 timeMap &timemap = service_it->second.second;
1035 fwrite( &service_it->first, sizeof(uniqueEPGKey), 1, f);
1036 size = timemap.size();
1037 fwrite( &size, sizeof(int), 1, f);
1038 for (timeMap::iterator time_it(timemap.begin()); time_it != timemap.end(); ++time_it)
1040 __u8 len = time_it->second->ByteSize;
1041 fwrite( &time_it->second->type, sizeof(__u8), 1, f );
1042 fwrite( &len, sizeof(__u8), 1, f);
1043 fwrite( time_it->second->EITdata, len, 1, f);
1047 eDebug("[EPGC] %d events written to /hdd/epg.dat", cnt);
1049 #ifdef ENABLE_PRIVATE_EPG
1050 const char* text3 = "PRIVATE_EPG";
1051 fwrite( text3, 11, 1, f );
1052 size = content_time_tables.size();
1053 fwrite( &size, sizeof(int), 1, f);
1054 for (contentMaps::iterator a = content_time_tables.begin(); a != content_time_tables.end(); ++a)
1056 contentMap &content_time_table = a->second;
1057 fwrite( &a->first, sizeof(uniqueEPGKey), 1, f);
1058 int size = content_time_table.size();
1059 fwrite( &size, sizeof(int), 1, f);
1060 for (contentMap::iterator i = content_time_table.begin(); i != content_time_table.end(); ++i )
1062 int size = i->second.size();
1063 fwrite( &i->first, sizeof(int), 1, f);
1064 fwrite( &size, sizeof(int), 1, f);
1065 for ( contentTimeMap::iterator it(i->second.begin());
1066 it != i->second.end(); ++it )
1068 fwrite( &it->first, sizeof(time_t), 1, f);
1069 fwrite( &it->second.first, sizeof(time_t), 1, f);
1070 fwrite( &it->second.second, sizeof(__u16), 1, f);
1075 // write version string after binary data
1076 // has been written to disk.
1078 fseek(f, sizeof(int), SEEK_SET);
1079 fwrite("ENIGMA_EPG_V7", 13, 1, f);
1082 unsigned char md5[16];
1083 if (!md5_file("/hdd/epg.dat", 1, md5))
1085 FILE *f = fopen("/hdd/epg.dat.md5", "w");
1088 fwrite( md5, 16, 1, f);
1096 eEPGCache::channel_data::channel_data(eEPGCache *ml)
1098 ,abortTimer(eTimer::create(ml)), zapTimer(eTimer::create(ml)), state(0)
1099 ,isRunning(0), haveData(0)
1100 #ifdef ENABLE_PRIVATE_EPG
1101 ,startPrivateTimer(eTimer::create(ml))
1103 #ifdef ENABLE_MHW_EPG
1104 ,m_MHWTimeoutTimer(eTimer::create(ml))
1107 #ifdef ENABLE_MHW_EPG
1108 CONNECT(m_MHWTimeoutTimer->timeout, eEPGCache::channel_data::MHWTimeout);
1110 CONNECT(zapTimer->timeout, eEPGCache::channel_data::startEPG);
1111 CONNECT(abortTimer->timeout, eEPGCache::channel_data::abortNonAvail);
1112 #ifdef ENABLE_PRIVATE_EPG
1113 CONNECT(startPrivateTimer->timeout, eEPGCache::channel_data::startPrivateReader);
1115 pthread_mutex_init(&channel_active, 0);
1118 bool eEPGCache::channel_data::finishEPG()
1120 if (!isRunning) // epg ready
1122 eDebug("[EPGC] stop caching events(%ld)", ::time(0));
1123 zapTimer->start(UPDATE_INTERVAL, 1);
1124 eDebug("[EPGC] next update in %i min", UPDATE_INTERVAL / 60000);
1125 for (unsigned int i=0; i < sizeof(seenSections)/sizeof(tidMap); ++i)
1127 seenSections[i].clear();
1128 calcedSections[i].clear();
1130 singleLock l(cache->cache_lock);
1131 cache->channelLastUpdated[channel->getChannelID()] = ::time(0);
1132 #ifdef ENABLE_MHW_EPG
1140 void eEPGCache::channel_data::startEPG()
1142 eDebug("[EPGC] start caching events(%ld)", ::time(0));
1145 for (unsigned int i=0; i < sizeof(seenSections)/sizeof(tidMap); ++i)
1147 seenSections[i].clear();
1148 calcedSections[i].clear();
1151 eDVBSectionFilterMask mask;
1152 memset(&mask, 0, sizeof(mask));
1154 #ifdef ENABLE_MHW_EPG
1156 mask.data[0] = 0x91;
1157 mask.mask[0] = 0xFF;
1158 m_MHWReader->connectRead(slot(*this, &eEPGCache::channel_data::readMHWData), m_MHWConn);
1159 m_MHWReader->start(mask);
1161 memcpy(&m_MHWFilterMask, &mask, sizeof(eDVBSectionFilterMask));
1164 mask.data[0] = 0xC8;
1165 mask.mask[0] = 0xFF;
1167 mask.mask[1] = 0xFF;
1168 m_MHWReader2->connectRead(slot(*this, &eEPGCache::channel_data::readMHWData2), m_MHWConn2);
1169 m_MHWReader2->start(mask);
1171 memcpy(&m_MHWFilterMask2, &mask, sizeof(eDVBSectionFilterMask));
1177 mask.flags = eDVBSectionFilterMask::rfCRC;
1179 mask.data[0] = 0x4E;
1180 mask.mask[0] = 0xFE;
1181 m_NowNextReader->connectRead(slot(*this, &eEPGCache::channel_data::readData), m_NowNextConn);
1182 m_NowNextReader->start(mask);
1183 isRunning |= NOWNEXT;
1185 mask.data[0] = 0x50;
1186 mask.mask[0] = 0xF0;
1187 m_ScheduleReader->connectRead(slot(*this, &eEPGCache::channel_data::readData), m_ScheduleConn);
1188 m_ScheduleReader->start(mask);
1189 isRunning |= SCHEDULE;
1191 mask.data[0] = 0x60;
1192 m_ScheduleOtherReader->connectRead(slot(*this, &eEPGCache::channel_data::readData), m_ScheduleOtherConn);
1193 m_ScheduleOtherReader->start(mask);
1194 isRunning |= SCHEDULE_OTHER;
1198 mask.data[0] = 0x40;
1199 mask.mask[0] = 0x40;
1200 m_ViasatReader->connectRead(slot(*this, &eEPGCache::channel_data::readDataViasat), m_ViasatConn);
1201 m_ViasatReader->start(mask);
1202 isRunning |= VIASAT;
1204 abortTimer->start(7000,true);
1207 void eEPGCache::channel_data::abortNonAvail()
1211 if ( !(haveData&NOWNEXT) && (isRunning&NOWNEXT) )
1213 eDebug("[EPGC] abort non avail nownext reading");
1214 isRunning &= ~NOWNEXT;
1215 m_NowNextReader->stop();
1218 if ( !(haveData&SCHEDULE) && (isRunning&SCHEDULE) )
1220 eDebug("[EPGC] abort non avail schedule reading");
1221 isRunning &= ~SCHEDULE;
1222 m_ScheduleReader->stop();
1225 if ( !(haveData&SCHEDULE_OTHER) && (isRunning&SCHEDULE_OTHER) )
1227 eDebug("[EPGC] abort non avail schedule other reading");
1228 isRunning &= ~SCHEDULE_OTHER;
1229 m_ScheduleOtherReader->stop();
1230 m_ScheduleOtherConn=0;
1232 if ( !(haveData&VIASAT) && (isRunning&VIASAT) )
1234 eDebug("[EPGC] abort non avail viasat reading");
1235 isRunning &= ~VIASAT;
1236 m_ViasatReader->stop();
1239 #ifdef ENABLE_MHW_EPG
1240 if ( !(haveData&MHW) && (isRunning&MHW) )
1242 eDebug("[EPGC] abort non avail mhw reading");
1244 m_MHWReader->stop();
1246 m_MHWReader2->stop();
1250 if ( isRunning & VIASAT )
1251 abortTimer->start(300000, true);
1252 else if ( isRunning )
1253 abortTimer->start(90000, true);
1257 for (unsigned int i=0; i < sizeof(seenSections)/sizeof(tidMap); ++i)
1259 seenSections[i].clear();
1260 calcedSections[i].clear();
1267 void eEPGCache::channel_data::startChannel()
1269 pthread_mutex_lock(&channel_active);
1270 updateMap::iterator It = cache->channelLastUpdated.find( channel->getChannelID() );
1272 int update = ( It != cache->channelLastUpdated.end() ? ( UPDATE_INTERVAL - ( (::time(0)-It->second) * 1000 ) ) : ZAP_DELAY );
1274 if (update < ZAP_DELAY)
1277 zapTimer->start(update, 1);
1278 if (update >= 60000)
1279 eDebug("[EPGC] next update in %i min", update/60000);
1280 else if (update >= 1000)
1281 eDebug("[EPGC] next update in %i sec", update/1000);
1284 void eEPGCache::channel_data::abortEPG()
1286 for (unsigned int i=0; i < sizeof(seenSections)/sizeof(tidMap); ++i)
1288 seenSections[i].clear();
1289 calcedSections[i].clear();
1295 eDebug("[EPGC] abort caching events !!");
1296 if (isRunning & SCHEDULE)
1298 isRunning &= ~SCHEDULE;
1299 m_ScheduleReader->stop();
1302 if (isRunning & NOWNEXT)
1304 isRunning &= ~NOWNEXT;
1305 m_NowNextReader->stop();
1308 if (isRunning & SCHEDULE_OTHER)
1310 isRunning &= ~SCHEDULE_OTHER;
1311 m_ScheduleOtherReader->stop();
1312 m_ScheduleOtherConn=0;
1314 if (isRunning & VIASAT)
1316 isRunning &= ~VIASAT;
1317 m_ViasatReader->stop();
1320 #ifdef ENABLE_MHW_EPG
1321 if (isRunning & MHW)
1324 m_MHWReader->stop();
1326 m_MHWReader2->stop();
1331 #ifdef ENABLE_PRIVATE_EPG
1332 if (m_PrivateReader)
1333 m_PrivateReader->stop();
1337 pthread_mutex_unlock(&channel_active);
1341 void eEPGCache::channel_data::readDataViasat( const __u8 *data)
1344 memcpy(&d, &data, sizeof(__u8*));
1349 void eEPGCache::channel_data::readData( const __u8 *data)
1353 iDVBSectionReader *reader=NULL;
1357 reader=m_NowNextReader;
1362 reader=m_ScheduleReader;
1367 reader=m_ScheduleOtherReader;
1368 source=SCHEDULE_OTHER;
1375 memcpy(&d, &data, sizeof(__u8*));
1377 reader=m_ViasatReader;
1383 eDebug("[EPGC] unknown table_id !!!");
1386 tidMap &seenSections = this->seenSections[map];
1387 tidMap &calcedSections = this->calcedSections[map];
1388 if ( state == 1 && calcedSections == seenSections || state > 1 )
1390 eDebugNoNewLine("[EPGC] ");
1395 eDebugNoNewLine("nownext");
1399 eDebugNoNewLine("schedule");
1401 case SCHEDULE_OTHER:
1402 m_ScheduleOtherConn=0;
1403 eDebugNoNewLine("schedule other");
1407 eDebugNoNewLine("viasat");
1409 default: eDebugNoNewLine("unknown");break;
1411 eDebug(" finished(%ld)", ::time(0));
1414 isRunning &= ~source;
1420 eit_t *eit = (eit_t*) data;
1421 __u32 sectionNo = data[0] << 24;
1422 sectionNo |= data[3] << 16;
1423 sectionNo |= data[4] << 8;
1424 sectionNo |= eit->section_number;
1426 tidMap::iterator it =
1427 seenSections.find(sectionNo);
1429 if ( it == seenSections.end() )
1431 seenSections.insert(sectionNo);
1432 calcedSections.insert(sectionNo);
1433 __u32 tmpval = sectionNo & 0xFFFFFF00;
1434 __u8 incr = source == NOWNEXT ? 1 : 8;
1435 for ( int i = 0; i <= eit->last_section_number; i+=incr )
1437 if ( i == eit->section_number )
1439 for (int x=i; x <= eit->segment_last_section_number; ++x)
1440 calcedSections.insert(tmpval|(x&0xFF));
1443 calcedSections.insert(tmpval|(i&0xFF));
1445 cache->sectionRead(data, source, this);
1450 RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, const eventData *&result, int direction)
1451 // if t == -1 we search the current event...
1453 singleLock s(cache_lock);
1454 uniqueEPGKey key(handleGroup(service));
1456 // check if EPG for this service is ready...
1457 eventCache::iterator It = eventDB.find( key );
1458 if ( It != eventDB.end() && !It->second.first.empty() ) // entrys cached ?
1462 timeMap::iterator i = direction <= 0 ? It->second.second.lower_bound(t) : // find > or equal
1463 It->second.second.upper_bound(t); // just >
1464 if ( i != It->second.second.end() )
1466 if ( direction < 0 || (direction == 0 && i->first > t) )
1468 timeMap::iterator x = i;
1470 if ( x != It->second.second.end() )
1472 time_t start_time = x->first;
1477 if (t > (start_time+x->second->getDuration()))
1492 RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, const eit_event_struct *&result, int direction)
1494 singleLock s(cache_lock);
1495 const eventData *data=0;
1496 RESULT ret = lookupEventTime(service, t, data, direction);
1498 result = data->get();
1502 RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, Event *& result, int direction)
1504 singleLock s(cache_lock);
1505 const eventData *data=0;
1506 RESULT ret = lookupEventTime(service, t, data, direction);
1508 result = new Event((uint8_t*)data->get());
1512 RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, ePtr<eServiceEvent> &result, int direction)
1514 singleLock s(cache_lock);
1515 const eventData *data=0;
1516 RESULT ret = lookupEventTime(service, t, data, direction);
1519 Event ev((uint8_t*)data->get());
1520 result = new eServiceEvent();
1521 const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service;
1522 ret = result->parseFrom(&ev, (ref.getTransportStreamID().get()<<16)|ref.getOriginalNetworkID().get());
1527 RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, const eventData *&result )
1529 singleLock s(cache_lock);
1530 uniqueEPGKey key(handleGroup(service));
1532 eventCache::iterator It = eventDB.find( key );
1533 if ( It != eventDB.end() && !It->second.first.empty() ) // entrys cached?
1535 eventMap::iterator i( It->second.first.find( event_id ));
1536 if ( i != It->second.first.end() )
1544 eDebug("[EPGC] event %04x not found in epgcache", event_id);
1550 RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, const eit_event_struct *&result)
1552 singleLock s(cache_lock);
1553 const eventData *data=0;
1554 RESULT ret = lookupEventId(service, event_id, data);
1556 result = data->get();
1560 RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, Event *& result)
1562 singleLock s(cache_lock);
1563 const eventData *data=0;
1564 RESULT ret = lookupEventId(service, event_id, data);
1566 result = new Event((uint8_t*)data->get());
1570 RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, ePtr<eServiceEvent> &result)
1572 singleLock s(cache_lock);
1573 const eventData *data=0;
1574 RESULT ret = lookupEventId(service, event_id, data);
1577 Event ev((uint8_t*)data->get());
1578 result = new eServiceEvent();
1579 const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service;
1580 ret = result->parseFrom(&ev, (ref.getTransportStreamID().get()<<16)|ref.getOriginalNetworkID().get());
1585 RESULT eEPGCache::startTimeQuery(const eServiceReference &service, time_t begin, int minutes)
1587 singleLock s(cache_lock);
1588 const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)handleGroup(service);
1591 eventCache::iterator It = eventDB.find(ref);
1592 if ( It != eventDB.end() && It->second.second.size() )
1594 m_timemap_cursor = It->second.second.lower_bound(begin);
1595 if ( m_timemap_cursor != It->second.second.end() )
1597 if ( m_timemap_cursor->first != begin )
1599 timeMap::iterator x = m_timemap_cursor;
1601 if ( x != It->second.second.end() )
1603 time_t start_time = x->first;
1604 if ( begin > start_time && begin < (start_time+x->second->getDuration()))
1605 m_timemap_cursor = x;
1611 m_timemap_end = It->second.second.lower_bound(begin+minutes*60);
1613 m_timemap_end = It->second.second.end();
1615 currentQueryTsidOnid = (ref.getTransportStreamID().get()<<16) | ref.getOriginalNetworkID().get();
1616 return m_timemap_cursor == m_timemap_end ? -1 : 0;
1621 RESULT eEPGCache::getNextTimeEntry(const eventData *& result)
1623 if ( m_timemap_cursor != m_timemap_end )
1625 result = m_timemap_cursor++->second;
1631 RESULT eEPGCache::getNextTimeEntry(const eit_event_struct *&result)
1633 if ( m_timemap_cursor != m_timemap_end )
1635 result = m_timemap_cursor++->second->get();
1641 RESULT eEPGCache::getNextTimeEntry(Event *&result)
1643 if ( m_timemap_cursor != m_timemap_end )
1645 result = new Event((uint8_t*)m_timemap_cursor++->second->get());
1651 RESULT eEPGCache::getNextTimeEntry(ePtr<eServiceEvent> &result)
1653 if ( m_timemap_cursor != m_timemap_end )
1655 Event ev((uint8_t*)m_timemap_cursor++->second->get());
1656 result = new eServiceEvent();
1657 return result->parseFrom(&ev, currentQueryTsidOnid);
1662 void fillTuple(ePyObject tuple, const char *argstring, int argcount, ePyObject service, eServiceEvent *ptr, ePyObject nowTime, ePyObject service_name )
1667 while(spos < argcount)
1669 bool inc_refcount=false;
1670 switch((c=argstring[spos++]))
1672 case '0': // PyLong 0
1673 tmp = PyLong_FromLong(0);
1675 case 'I': // Event Id
1676 tmp = ptr ? PyLong_FromLong(ptr->getEventId()) : ePyObject();
1678 case 'B': // Event Begin Time
1679 tmp = ptr ? PyLong_FromLong(ptr->getBeginTime()) : ePyObject();
1681 case 'D': // Event Duration
1682 tmp = ptr ? PyLong_FromLong(ptr->getDuration()) : ePyObject();
1684 case 'T': // Event Title
1685 tmp = ptr ? PyString_FromString(ptr->getEventName().c_str()) : ePyObject();
1687 case 'S': // Event Short Description
1688 tmp = ptr ? PyString_FromString(ptr->getShortDescription().c_str()) : ePyObject();
1690 case 'E': // Event Extended Description
1691 tmp = ptr ? PyString_FromString(ptr->getExtendedDescription().c_str()) : ePyObject();
1693 case 'C': // Current Time
1695 inc_refcount = true;
1697 case 'R': // service reference string
1699 inc_refcount = true;
1701 case 'n': // short service name
1702 case 'N': // service name
1704 inc_refcount = true;
1709 default: // ignore unknown
1710 eDebug("fillTuple unknown '%c'... insert 'None' in result", c);
1715 inc_refcount = true;
1719 PyTuple_SET_ITEM(tuple, tpos++, tmp);
1723 int handleEvent(eServiceEvent *ptr, ePyObject dest_list, const char* argstring, int argcount, ePyObject service, ePyObject nowTime, ePyObject service_name, ePyObject convertFunc, ePyObject convertFuncArgs)
1727 fillTuple(convertFuncArgs, argstring, argcount, service, ptr, nowTime, service_name);
1728 ePyObject result = PyObject_CallObject(convertFunc, convertFuncArgs);
1732 Py_DECREF(service_name);
1735 Py_DECREF(convertFuncArgs);
1736 Py_DECREF(dest_list);
1737 PyErr_SetString(PyExc_StandardError,
1738 "error in convertFunc execute");
1739 eDebug("error in convertFunc execute");
1742 PyList_Append(dest_list, result);
1747 ePyObject tuple = PyTuple_New(argcount);
1748 fillTuple(tuple, argstring, argcount, service, ptr, nowTime, service_name);
1749 PyList_Append(dest_list, tuple);
1755 // here we get a python list
1756 // the first entry in the list is a python string to specify the format of the returned tuples (in a list)
1759 // B = Event Begin Time
1760 // D = Event Duration
1762 // S = Event Short Description
1763 // E = Event Extended Description
1765 // R = Service Reference
1767 // n = Short Service Name
1768 // X = Return a minimum of one tuple per service in the result list... even when no event was found.
1769 // The returned tuple is filled with all available infos... non avail is filled as None
1770 // The position and existence of 'X' in the format string has no influence on the result tuple... its completely ignored..
1771 // then for each service follows a tuple
1772 // first tuple entry is the servicereference (as string... use the ref.toString() function)
1773 // the second is the type of query
1775 // -1 = event before given start_time
1776 // 0 = event intersects given start_time
1777 // +1 = event after given start_time
1779 // when type is eventid it is the event_id
1780 // when type is time then it is the start_time ( -1 for now_time )
1781 // the fourth is the end_time .. ( optional .. for query all events in time range)
1783 PyObject *eEPGCache::lookupEvent(ePyObject list, ePyObject convertFunc)
1785 ePyObject convertFuncArgs;
1787 const char *argstring=NULL;
1788 if (!PyList_Check(list))
1790 PyErr_SetString(PyExc_StandardError,
1796 int listSize=PyList_Size(list);
1799 PyErr_SetString(PyExc_StandardError,
1800 "not params given");
1801 eDebug("not params given");
1806 ePyObject argv=PyList_GET_ITEM(list, 0); // borrowed reference!
1807 if (PyString_Check(argv))
1809 argstring = PyString_AS_STRING(argv);
1813 argstring = "I"; // just event id as default
1814 argcount = strlen(argstring);
1815 // eDebug("have %d args('%s')", argcount, argstring);
1818 bool forceReturnOne = strchr(argstring, 'X') ? true : false;
1824 if (!PyCallable_Check(convertFunc))
1826 PyErr_SetString(PyExc_StandardError,
1827 "convertFunc must be callable");
1828 eDebug("convertFunc is not callable");
1831 convertFuncArgs = PyTuple_New(argcount);
1834 ePyObject nowTime = strchr(argstring, 'C') ?
1835 PyLong_FromLong(::time(0)) :
1838 int must_get_service_name = strchr(argstring, 'N') ? 1 : strchr(argstring, 'n') ? 2 : 0;
1841 ePyObject dest_list=PyList_New(0);
1842 while(listSize > listIt)
1844 ePyObject item=PyList_GET_ITEM(list, listIt++); // borrowed reference!
1845 if (PyTuple_Check(item))
1847 bool service_changed=false;
1852 int tupleSize=PyTuple_Size(item);
1855 while(tupleSize > tupleIt) // parse query args
1857 ePyObject entry=PyTuple_GET_ITEM(item, tupleIt); // borrowed reference!
1862 if (!PyString_Check(entry))
1864 eDebug("tuple entry 0 is no a string");
1871 type=PyInt_AsLong(entry);
1872 if (type < -1 || type > 2)
1874 eDebug("unknown type %d", type);
1879 event_id=stime=PyInt_AsLong(entry);
1882 minutes=PyInt_AsLong(entry);
1885 eDebug("unneeded extra argument");
1890 if (minutes && stime == -1)
1893 eServiceReference ref(handleGroup(eServiceReference(PyString_AS_STRING(service))));
1894 if (ref.type != eServiceReference::idDVB)
1896 eDebug("service reference for epg query is not valid");
1900 // redirect subservice querys to parent service
1901 eServiceReferenceDVB &dvb_ref = (eServiceReferenceDVB&)ref;
1902 if (dvb_ref.getParentTransportStreamID().get()) // linkage subservice
1904 eServiceCenterPtr service_center;
1905 if (!eServiceCenter::getPrivInstance(service_center))
1907 dvb_ref.setTransportStreamID( dvb_ref.getParentTransportStreamID() );
1908 dvb_ref.setServiceID( dvb_ref.getParentServiceID() );
1909 dvb_ref.setParentTransportStreamID(eTransportStreamID(0));
1910 dvb_ref.setParentServiceID(eServiceID(0));
1912 service = PyString_FromString(dvb_ref.toString().c_str());
1913 service_changed = true;
1917 ePyObject service_name;
1918 if (must_get_service_name)
1920 ePtr<iStaticServiceInformation> sptr;
1921 eServiceCenterPtr service_center;
1922 eServiceCenter::getPrivInstance(service_center);
1925 service_center->info(ref, sptr);
1929 sptr->getName(ref, name);
1931 if (must_get_service_name == 1)
1934 // filter short name brakets
1935 while((pos = name.find("\xc2\x86")) != std::string::npos)
1937 while((pos = name.find("\xc2\x87")) != std::string::npos)
1941 name = buildShortName(name);
1944 service_name = PyString_FromString(name.c_str());
1948 service_name = PyString_FromString("<n/a>");
1952 singleLock s(cache_lock);
1953 if (!startTimeQuery(ref, stime, minutes))
1955 while ( m_timemap_cursor != m_timemap_end )
1957 Event ev((uint8_t*)m_timemap_cursor++->second->get());
1959 evt.parseFrom(&ev, currentQueryTsidOnid);
1960 if (handleEvent(&evt, dest_list, argstring, argcount, service, nowTime, service_name, convertFunc, convertFuncArgs))
1964 else if (forceReturnOne && handleEvent(0, dest_list, argstring, argcount, service, nowTime, service_name, convertFunc, convertFuncArgs))
1970 const eventData *ev_data=0;
1973 singleLock s(cache_lock);
1975 lookupEventId(ref, event_id, ev_data);
1977 lookupEventTime(ref, stime, ev_data, type);
1980 const eServiceReferenceDVB &dref = (const eServiceReferenceDVB&)ref;
1981 Event ev((uint8_t*)ev_data->get());
1982 evt.parseFrom(&ev, (dref.getTransportStreamID().get()<<16)|dref.getOriginalNetworkID().get());
1987 if (handleEvent(&evt, dest_list, argstring, argcount, service, nowTime, service_name, convertFunc, convertFuncArgs))
1990 else if (forceReturnOne && handleEvent(0, dest_list, argstring, argcount, service, nowTime, service_name, convertFunc, convertFuncArgs))
1993 if (service_changed)
1996 Py_DECREF(service_name);
2001 if (convertFuncArgs)
2002 Py_DECREF(convertFuncArgs);
2008 void fillTuple2(ePyObject tuple, const char *argstring, int argcount, eventData *evData, eServiceEvent *ptr, ePyObject service_name, ePyObject service_reference)
2012 while(pos < argcount)
2014 bool inc_refcount=false;
2015 switch(argstring[pos])
2017 case '0': // PyLong 0
2018 tmp = PyLong_FromLong(0);
2020 case 'I': // Event Id
2021 tmp = PyLong_FromLong(evData->getEventID());
2023 case 'B': // Event Begin Time
2025 tmp = ptr ? PyLong_FromLong(ptr->getBeginTime()) : ePyObject();
2027 tmp = PyLong_FromLong(evData->getStartTime());
2029 case 'D': // Event Duration
2031 tmp = ptr ? PyLong_FromLong(ptr->getDuration()) : ePyObject();
2033 tmp = PyLong_FromLong(evData->getDuration());
2035 case 'T': // Event Title
2036 tmp = ptr ? PyString_FromString(ptr->getEventName().c_str()) : ePyObject();
2038 case 'S': // Event Short Description
2039 tmp = ptr ? PyString_FromString(ptr->getShortDescription().c_str()) : ePyObject();
2041 case 'E': // Event Extended Description
2042 tmp = ptr ? PyString_FromString(ptr->getExtendedDescription().c_str()) : ePyObject();
2044 case 'R': // service reference string
2045 tmp = service_reference;
2046 inc_refcount = true;
2048 case 'n': // short service name
2049 case 'N': // service name
2051 inc_refcount = true;
2053 default: // ignore unknown
2054 eDebug("fillTuple2 unknown '%c'... insert None in Result", argstring[pos]);
2059 inc_refcount = true;
2063 PyTuple_SET_ITEM(tuple, pos++, tmp);
2067 // here we get a python tuple
2068 // the first entry in the tuple is a python string to specify the format of the returned tuples (in a list)
2070 // B = Event Begin Time
2071 // D = Event Duration
2073 // S = Event Short Description
2074 // E = Event Extended Description
2075 // R = Service Reference
2077 // n = Short Service Name
2078 // the second tuple entry is the MAX matches value
2079 // the third tuple entry is the type of query
2080 // 0 = search for similar broadcastings (SIMILAR_BROADCASTINGS_SEARCH)
2081 // 1 = search events with exactly title name (EXAKT_TITLE_SEARCH)
2082 // 2 = search events with text in title name (PARTIAL_TITLE_SEARCH)
2083 // when type is 0 (SIMILAR_BROADCASTINGS_SEARCH)
2084 // the fourth is the servicereference string
2085 // the fifth is the eventid
2086 // when type is 1 or 2 (EXAKT_TITLE_SEARCH or PARTIAL_TITLE_SEARCH)
2087 // the fourth is the search text
2089 // 0 = case sensitive (CASE_CHECK)
2090 // 1 = case insensitive (NO_CASECHECK)
2092 PyObject *eEPGCache::search(ePyObject arg)
2098 const char *argstring=0;
2102 bool needServiceEvent=false;
2104 int must_get_service_name = 0;
2105 bool must_get_service_reference = false;
2107 if (PyTuple_Check(arg))
2109 int tuplesize=PyTuple_Size(arg);
2112 ePyObject obj = PyTuple_GET_ITEM(arg,0);
2113 if (PyString_Check(obj))
2115 #if PY_VERSION_HEX < 0x02060000
2116 argcount = PyString_GET_SIZE(obj);
2118 argcount = PyString_Size(obj);
2120 argstring = PyString_AS_STRING(obj);
2121 for (int i=0; i < argcount; ++i)
2122 switch(argstring[i])
2127 needServiceEvent=true;
2130 must_get_service_name = 1;
2133 must_get_service_name = 2;
2136 must_get_service_reference = true;
2144 PyErr_SetString(PyExc_StandardError,
2146 eDebug("tuple arg 0 is not a string");
2151 maxmatches = PyLong_AsLong(PyTuple_GET_ITEM(arg, 1));
2154 querytype = PyLong_AsLong(PyTuple_GET_ITEM(arg, 2));
2155 if (tuplesize > 4 && querytype == 0)
2157 ePyObject obj = PyTuple_GET_ITEM(arg, 3);
2158 if (PyString_Check(obj))
2160 refstr = PyString_AS_STRING(obj);
2161 eServiceReferenceDVB ref(refstr);
2164 eventid = PyLong_AsLong(PyTuple_GET_ITEM(arg, 4));
2165 singleLock s(cache_lock);
2166 const eventData *evData = 0;
2167 lookupEventId(ref, eventid, evData);
2170 __u8 *data = evData->EITdata;
2171 int tmp = evData->ByteSize-10;
2172 __u32 *p = (__u32*)(data+10);
2173 // search short and extended event descriptors
2177 descriptorMap::iterator it =
2178 eventData::descriptors.find(crc);
2179 if (it != eventData::descriptors.end())
2181 __u8 *descr_data = it->second.second;
2182 switch(descr_data[0])
2185 descr[++descridx]=crc;
2194 eDebug("event not found");
2198 PyErr_SetString(PyExc_StandardError, "type error");
2199 eDebug("tuple arg 4 is not a valid service reference string");
2205 PyErr_SetString(PyExc_StandardError, "type error");
2206 eDebug("tuple arg 4 is not a string");
2210 else if (tuplesize > 4 && (querytype == 1 || querytype == 2) )
2212 ePyObject obj = PyTuple_GET_ITEM(arg, 3);
2213 if (PyString_Check(obj))
2215 int casetype = PyLong_AsLong(PyTuple_GET_ITEM(arg, 4));
2216 const char *str = PyString_AS_STRING(obj);
2217 #if PY_VERSION_HEX < 0x02060000
2218 int textlen = PyString_GET_SIZE(obj);
2220 int textlen = PyString_Size(obj);
2223 eDebug("lookup for events with '%s' as title(%s)", str, casetype?"ignore case":"case sensitive");
2225 eDebug("lookup for events with '%s' in title(%s)", str, casetype?"ignore case":"case sensitive");
2226 singleLock s(cache_lock);
2227 for (descriptorMap::iterator it(eventData::descriptors.begin());
2228 it != eventData::descriptors.end() && descridx < 511; ++it)
2230 __u8 *data = it->second.second;
2231 if ( data[0] == 0x4D ) // short event descriptor
2233 int title_len = data[5];
2234 if ( querytype == 1 )
2237 // skip DVB-Text Encoding!
2238 if (data[6] == 0x10)
2243 else if(data[6] > 0 && data[6] < 0x20)
2248 if (title_len != textlen)
2252 if ( !strncasecmp((const char*)data+offs, str, title_len) )
2254 // std::string s((const char*)data+offs, title_len);
2255 // eDebug("match1 %s %s", str, s.c_str() );
2256 descr[++descridx] = it->first;
2259 else if ( !strncmp((const char*)data+offs, str, title_len) )
2261 // std::string s((const char*)data+offs, title_len);
2262 // eDebug("match2 %s %s", str, s.c_str() );
2263 descr[++descridx] = it->first;
2269 while((title_len-idx) >= textlen)
2273 if (!strncasecmp((const char*)data+6+idx, str, textlen) )
2275 descr[++descridx] = it->first;
2276 // std::string s((const char*)data+6, title_len);
2277 // eDebug("match 3 %s %s", str, s.c_str() );
2281 else if (!strncmp((const char*)data+6+idx, str, textlen) )
2283 descr[++descridx] = it->first;
2284 // std::string s((const char*)data+6, title_len);
2285 // eDebug("match 4 %s %s", str, s.c_str() );
2296 PyErr_SetString(PyExc_StandardError,
2298 eDebug("tuple arg 4 is not a string");
2304 PyErr_SetString(PyExc_StandardError,
2306 eDebug("tuple arg 3(%d) is not a known querytype(0, 1, 2)", querytype);
2312 PyErr_SetString(PyExc_StandardError,
2314 eDebug("not enough args in tuple");
2320 PyErr_SetString(PyExc_StandardError,
2322 eDebug("arg 0 is not a tuple");
2328 int maxcount=maxmatches;
2329 eServiceReferenceDVB ref(refstr?(const eServiceReferenceDVB&)handleGroup(eServiceReference(refstr)):eServiceReferenceDVB(""));
2330 // ref is only valid in SIMILAR_BROADCASTING_SEARCH
2331 // in this case we start searching with the base service
2332 bool first = ref.valid() ? true : false;
2333 singleLock s(cache_lock);
2334 eventCache::iterator cit(ref.valid() ? eventDB.find(ref) : eventDB.begin());
2335 while(cit != eventDB.end() && maxcount)
2337 if ( ref.valid() && !first && cit->first == ref )
2339 // do not scan base service twice ( only in SIMILAR BROADCASTING SEARCH )
2343 ePyObject service_name;
2344 ePyObject service_reference;
2345 timeMap &evmap = cit->second.second;
2347 for (timeMap::iterator evit(evmap.begin()); evit != evmap.end() && maxcount; ++evit)
2349 int evid = evit->second->getEventID();
2350 if ( evid == eventid)
2352 __u8 *data = evit->second->EITdata;
2353 int tmp = evit->second->ByteSize-10;
2354 __u32 *p = (__u32*)(data+10);
2355 // check if any of our descriptor used by this event
2360 for ( int i=0; i <= descridx; ++i)
2362 if (descr[i] == crc32) // found...
2367 if ( (querytype == 0 && cnt == descridx) ||
2368 ((querytype == 1 || querytype == 2) && cnt != -1) )
2370 const uniqueEPGKey &service = cit->first;
2371 eServiceReference ref =
2372 eDVBDB::getInstance()->searchReference(service.tsid, service.onid, service.sid);
2375 // create servive event
2377 const eventData *ev_data=0;
2378 if (needServiceEvent)
2380 if (lookupEventId(ref, evid, ev_data))
2381 eDebug("event not found !!!!!!!!!!!");
2384 const eServiceReferenceDVB &dref = (const eServiceReferenceDVB&)ref;
2385 Event ev((uint8_t*)ev_data->get());
2386 ptr.parseFrom(&ev, (dref.getTransportStreamID().get()<<16)|dref.getOriginalNetworkID().get());
2389 // create service name
2390 if (must_get_service_name && !service_name)
2392 ePtr<iStaticServiceInformation> sptr;
2393 eServiceCenterPtr service_center;
2394 eServiceCenter::getPrivInstance(service_center);
2397 service_center->info(ref, sptr);
2401 sptr->getName(ref, name);
2403 if (must_get_service_name == 1)
2406 // filter short name brakets
2407 while((pos = name.find("\xc2\x86")) != std::string::npos)
2409 while((pos = name.find("\xc2\x87")) != std::string::npos)
2413 name = buildShortName(name);
2416 service_name = PyString_FromString(name.c_str());
2420 service_name = PyString_FromString("<n/a>");
2422 // create servicereference string
2423 if (must_get_service_reference && !service_reference)
2424 service_reference = PyString_FromString(ref.toString().c_str());
2427 ret = PyList_New(0);
2429 ePyObject tuple = PyTuple_New(argcount);
2431 fillTuple2(tuple, argstring, argcount, evit->second, ev_data ? &ptr : 0, service_name, service_reference);
2432 PyList_Append(ret, tuple);
2439 Py_DECREF(service_name);
2440 if (service_reference)
2441 Py_DECREF(service_reference);
2444 // now start at first service in epgcache database ( only in SIMILAR BROADCASTING SEARCH )
2446 cit=eventDB.begin();
2459 #ifdef ENABLE_PRIVATE_EPG
2460 #include <dvbsi++/descriptor_tag.h>
2461 #include <dvbsi++/unknown_descriptor.h>
2462 #include <dvbsi++/private_data_specifier_descriptor.h>
2464 void eEPGCache::PMTready(eDVBServicePMTHandler *pmthandler)
2466 ePtr<eTable<ProgramMapSection> > ptr;
2467 if (!pmthandler->getPMT(ptr) && ptr)
2469 std::vector<ProgramMapSection*>::const_iterator i;
2470 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
2472 const ProgramMapSection &pmt = **i;
2474 ElementaryStreamInfoConstIterator es;
2475 for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
2478 switch ((*es)->getType())
2480 case 0x05: // private
2481 for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin();
2482 desc != (*es)->getDescriptors()->end(); ++desc)
2484 switch ((*desc)->getTag())
2486 case PRIVATE_DATA_SPECIFIER_DESCRIPTOR:
2487 if (((PrivateDataSpecifierDescriptor*)(*desc))->getPrivateDataSpecifier() == 190)
2492 UnknownDescriptor *descr = (UnknownDescriptor*)*desc;
2493 int descr_len = descr->getLength();
2496 uint8_t data[descr_len+2];
2497 descr->writeToBuffer(data);
2498 if ( !data[2] && !data[3] && data[4] == 0xFF && data[5] == 0xFF )
2512 eServiceReferenceDVB ref;
2513 if (!pmthandler->getServiceReference(ref))
2515 int pid = (*es)->getPid();
2516 messages.send(Message(Message::got_private_pid, ref, pid));
2524 eDebug("PMTready but no pmt!!");
2531 date_time( const date_time &a )
2533 memcpy(data, a.data, 5);
2536 date_time( const __u8 data[5])
2538 memcpy(this->data, data, 5);
2539 tm = parseDVBtime(data[0], data[1], data[2], data[3], data[4]);
2544 const __u8& operator[](int pos) const
2550 struct less_datetime
2552 bool operator()( const date_time &a, const date_time &b ) const
2554 return abs(a.tm-b.tm) < 360 ? false : a.tm < b.tm;
2558 void eEPGCache::privateSectionRead(const uniqueEPGKey ¤t_service, const __u8 *data)
2560 contentMap &content_time_table = content_time_tables[current_service];
2561 singleLock s(cache_lock);
2562 std::map< date_time, std::list<uniqueEPGKey>, less_datetime > start_times;
2563 eventMap &evMap = eventDB[current_service].first;
2564 timeMap &tmMap = eventDB[current_service].second;
2566 int content_id = data[ptr++] << 24;
2567 content_id |= data[ptr++] << 16;
2568 content_id |= data[ptr++] << 8;
2569 content_id |= data[ptr++];
2571 contentTimeMap &time_event_map =
2572 content_time_table[content_id];
2573 for ( contentTimeMap::iterator it( time_event_map.begin() );
2574 it != time_event_map.end(); ++it )
2576 eventMap::iterator evIt( evMap.find(it->second.second) );
2577 if ( evIt != evMap.end() )
2579 delete evIt->second;
2582 tmMap.erase(it->second.first);
2584 time_event_map.clear();
2587 memcpy(duration, data+ptr, 3);
2590 fromBCD(duration[0])*3600+fromBCD(duration[1])*60+fromBCD(duration[2]);
2592 const __u8 *descriptors[65];
2593 const __u8 **pdescr = descriptors;
2595 int descriptors_length = (data[ptr++]&0x0F) << 8;
2596 descriptors_length |= data[ptr++];
2597 while ( descriptors_length > 1 )
2599 int descr_type = data[ptr];
2600 int descr_len = data[ptr+1];
2601 descriptors_length -= 2;
2602 if (descriptors_length >= descr_len)
2604 descriptors_length -= descr_len;
2605 if ( descr_type == 0xf2 && descr_len > 5)
2608 int tsid = data[ptr++] << 8;
2609 tsid |= data[ptr++];
2610 int onid = data[ptr++] << 8;
2611 onid |= data[ptr++];
2612 int sid = data[ptr++] << 8;
2615 // WORKAROUND for wrong transmitted epg data (01.10.2007)
2618 switch( (tsid << 16) | sid )
2620 case 0x01030b: sid = 0x1b; tsid = 4; break; // Premiere Win
2621 case 0x0300f0: sid = 0xe0; tsid = 2; break;
2622 case 0x0300f1: sid = 0xe1; tsid = 2; break;
2623 case 0x0300f5: sid = 0xdc; break;
2624 case 0x0400d2: sid = 0xe2; tsid = 0x11; break;
2625 case 0x1100d3: sid = 0xe3; break;
2626 case 0x0100d4: sid = 0xe4; tsid = 4; break;
2629 ////////////////////////////////////////////
2631 uniqueEPGKey service( sid, onid, tsid );
2633 while( descr_len > 2 )
2636 datetime[0] = data[ptr++];
2637 datetime[1] = data[ptr++];
2638 int tmp_len = data[ptr++];
2640 if (descr_len >= tmp_len)
2642 descr_len -= tmp_len;
2643 while( tmp_len > 2 )
2645 memcpy(datetime+2, data+ptr, 3);
2648 start_times[datetime].push_back(service);
2661 ASSERT(pdescr <= &descriptors[65])
2663 eit_event_struct *ev_struct = (eit_event_struct*) event;
2664 ev_struct->running_status = 0;
2665 ev_struct->free_CA_mode = 1;
2666 memcpy(event+7, duration, 3);
2668 const __u8 **d=descriptors;
2669 while ( d < pdescr )
2671 memcpy(event+ptr, *d, ((*d)[1])+2);
2675 ASSERT(ptr <= 4098);
2676 for ( std::map< date_time, std::list<uniqueEPGKey> >::iterator it(start_times.begin()); it != start_times.end(); ++it )
2678 time_t now = ::time(0);
2679 if ( (it->first.tm + duration_sec) < now )
2681 memcpy(event+2, it->first.data, 5);
2684 for (std::list<uniqueEPGKey>::iterator i(it->second.begin()); i != it->second.end(); ++i)
2686 event[bptr++] = 0x4A;
2687 __u8 *len = event+(bptr++);
2688 event[bptr++] = (i->tsid & 0xFF00) >> 8;
2689 event[bptr++] = (i->tsid & 0xFF);
2690 event[bptr++] = (i->onid & 0xFF00) >> 8;
2691 event[bptr++] = (i->onid & 0xFF);
2692 event[bptr++] = (i->sid & 0xFF00) >> 8;
2693 event[bptr++] = (i->sid & 0xFF);
2694 event[bptr++] = 0xB0;
2695 bptr += sprintf((char*)(event+bptr), "Option %d", ++cnt);
2696 *len = ((event+bptr) - len)-1;
2698 int llen = bptr - 12;
2699 ev_struct->descriptors_loop_length_hi = (llen & 0xF00) >> 8;
2700 ev_struct->descriptors_loop_length_lo = (llen & 0xFF);
2702 time_t stime = it->first.tm;
2703 while( tmMap.find(stime) != tmMap.end() )
2705 event[6] += (stime - it->first.tm);
2707 while( evMap.find(event_id) != evMap.end() )
2709 event[0] = (event_id & 0xFF00) >> 8;
2710 event[1] = (event_id & 0xFF);
2711 time_event_map[it->first.tm]=std::pair<time_t, __u16>(stime, event_id);
2712 eventData *d = new eventData( ev_struct, bptr, PRIVATE );
2713 evMap[event_id] = d;
2715 ASSERT(bptr <= 4098);
2719 void eEPGCache::channel_data::startPrivateReader()
2721 eDVBSectionFilterMask mask;
2722 memset(&mask, 0, sizeof(mask));
2723 mask.pid = m_PrivatePid;
2724 mask.flags = eDVBSectionFilterMask::rfCRC;
2725 mask.data[0] = 0xA0;
2726 mask.mask[0] = 0xFF;
2727 eDebug("[EPGC] start privatefilter for pid %04x and version %d", m_PrivatePid, m_PrevVersion);
2728 if (m_PrevVersion != -1)
2730 mask.data[3] = m_PrevVersion << 1;
2731 mask.mask[3] = 0x3E;
2732 mask.mode[3] = 0x3E;
2734 seenPrivateSections.clear();
2736 m_PrivateReader->connectRead(slot(*this, &eEPGCache::channel_data::readPrivateData), m_PrivateConn);
2737 m_PrivateReader->start(mask);
2740 void eEPGCache::channel_data::readPrivateData( const __u8 *data)
2742 if ( seenPrivateSections.find(data[6]) == seenPrivateSections.end() )
2744 cache->privateSectionRead(m_PrivateService, data);
2745 seenPrivateSections.insert(data[6]);
2747 if ( seenPrivateSections.size() == (unsigned int)(data[7] + 1) )
2749 eDebug("[EPGC] private finished");
2750 eDVBChannelID chid = channel->getChannelID();
2751 int tmp = chid.original_network_id.get();
2752 tmp |= 0x80000000; // we use highest bit as private epg indicator
2753 chid.original_network_id = tmp;
2754 cache->channelLastUpdated[chid] = ::time(0);
2755 m_PrevVersion = (data[5] & 0x3E) >> 1;
2756 startPrivateReader();
2760 #endif // ENABLE_PRIVATE_EPG
2762 #ifdef ENABLE_MHW_EPG
2763 void eEPGCache::channel_data::cleanup()
2768 m_program_ids.clear();
2771 __u8 *eEPGCache::channel_data::delimitName( __u8 *in, __u8 *out, int len_in )
2773 // Names in mhw structs are not strings as they are not '\0' terminated.
2774 // This function converts the mhw name into a string.
2775 // Constraint: "length of out" = "length of in" + 1.
2777 for ( i=0; i < len_in; i++ )
2781 while ( ( i >=0 ) && ( out[i] == 0x20 ) )
2788 void eEPGCache::channel_data::timeMHW2DVB( u_char hours, u_char minutes, u_char *return_time)
2791 return_time[0] = toBCD( hours );
2792 return_time[1] = toBCD( minutes );
2796 void eEPGCache::channel_data::timeMHW2DVB( int minutes, u_char *return_time)
2798 timeMHW2DVB( int(minutes/60), minutes%60, return_time );
2801 void eEPGCache::channel_data::timeMHW2DVB( u_char day, u_char hours, u_char minutes, u_char *return_time)
2802 // For date plus time of day
2804 // Remove offset in mhw time.
2805 __u8 local_hours = hours;
2808 else if ( hours >= 8 )
2811 // As far as we know all mhw time data is sent in central Europe time zone.
2812 // So, temporarily set timezone to western europe
2813 time_t dt = ::time(0);
2815 char *old_tz = getenv( "TZ" );
2816 putenv("TZ=CET-1CEST,M3.5.0/2,M10.5.0/3");
2820 localtime_r(&dt, &localnow);
2824 if ( day + 1 < localnow.tm_wday ) // day + 1 to prevent old events to show for next week.
2826 if (local_hours <= 5)
2829 dt += 3600*24*(day - localnow.tm_wday); // Shift dt to the recording date (local time zone).
2830 dt += 3600*(local_hours - localnow.tm_hour); // Shift dt to the recording hour.
2833 gmtime_r( &dt, &recdate ); // This will also take care of DST.
2835 if ( old_tz == NULL )
2841 // Calculate MJD according to annex in ETSI EN 300 468
2843 if ( recdate.tm_mon <= 1 ) // Jan or Feb
2845 int mjd = 14956 + recdate.tm_mday + int( (recdate.tm_year - l) * 365.25) +
2846 int( (recdate.tm_mon + 2 + l * 12) * 30.6001);
2848 return_time[0] = (mjd & 0xFF00)>>8;
2849 return_time[1] = mjd & 0xFF;
2851 timeMHW2DVB( recdate.tm_hour, minutes, return_time+2 );
2854 void eEPGCache::channel_data::storeTitle(std::map<__u32, mhw_title_t>::iterator itTitle, std::string sumText, const __u8 *data)
2855 // data is borrowed from calling proc to save memory space.
2859 // For each title a separate EIT packet will be sent to eEPGCache::sectionRead()
2860 bool isMHW2 = itTitle->second.mhw2_mjd_hi || itTitle->second.mhw2_mjd_lo ||
2861 itTitle->second.mhw2_duration_hi || itTitle->second.mhw2_duration_lo;
2863 eit_t *packet = (eit_t *) data;
2864 packet->table_id = 0x50;
2865 packet->section_syntax_indicator = 1;
2867 packet->service_id_hi = m_channels[ itTitle->second.channel_id - 1 ].channel_id_hi;
2868 packet->service_id_lo = m_channels[ itTitle->second.channel_id - 1 ].channel_id_lo;
2869 packet->version_number = 0; // eEPGCache::sectionRead() will dig this for the moment
2870 packet->current_next_indicator = 0;
2871 packet->section_number = 0; // eEPGCache::sectionRead() will dig this for the moment
2872 packet->last_section_number = 0; // eEPGCache::sectionRead() will dig this for the moment
2873 packet->transport_stream_id_hi = m_channels[ itTitle->second.channel_id - 1 ].transport_stream_id_hi;
2874 packet->transport_stream_id_lo = m_channels[ itTitle->second.channel_id - 1 ].transport_stream_id_lo;
2875 packet->original_network_id_hi = m_channels[ itTitle->second.channel_id - 1 ].network_id_hi;
2876 packet->original_network_id_lo = m_channels[ itTitle->second.channel_id - 1 ].network_id_lo;
2877 packet->segment_last_section_number = 0; // eEPGCache::sectionRead() will dig this for the moment
2878 packet->segment_last_table_id = 0x50;
2880 __u8 *title = isMHW2 ? ((__u8*)(itTitle->second.title))-4 : (__u8*)itTitle->second.title;
2881 std::string prog_title = (char *) delimitName( title, name, isMHW2 ? 33 : 23 );
2882 int prog_title_length = prog_title.length();
2884 int packet_length = EIT_SIZE + EIT_LOOP_SIZE + EIT_SHORT_EVENT_DESCRIPTOR_SIZE +
2885 prog_title_length + 1;
2887 eit_event_t *event_data = (eit_event_t *) (data + EIT_SIZE);
2888 event_data->event_id_hi = (( itTitle->first ) >> 8 ) & 0xFF;
2889 event_data->event_id_lo = ( itTitle->first ) & 0xFF;
2893 u_char *data = (u_char*) event_data;
2894 data[2] = itTitle->second.mhw2_mjd_hi;
2895 data[3] = itTitle->second.mhw2_mjd_lo;
2896 data[4] = itTitle->second.mhw2_hours;
2897 data[5] = itTitle->second.mhw2_minutes;
2898 data[6] = itTitle->second.mhw2_seconds;
2899 timeMHW2DVB( HILO(itTitle->second.mhw2_duration), data+7 );
2903 timeMHW2DVB( itTitle->second.dh.day, itTitle->second.dh.hours, itTitle->second.ms.minutes,
2904 (u_char *) event_data + 2 );
2905 timeMHW2DVB( HILO(itTitle->second.duration), (u_char *) event_data+7 );
2908 event_data->running_status = 0;
2909 event_data->free_CA_mode = 0;
2910 int descr_ll = EIT_SHORT_EVENT_DESCRIPTOR_SIZE + 1 + prog_title_length;
2912 eit_short_event_descriptor_struct *short_event_descriptor =
2913 (eit_short_event_descriptor_struct *) ( (u_char *) event_data + EIT_LOOP_SIZE);
2914 short_event_descriptor->descriptor_tag = EIT_SHORT_EVENT_DESCRIPTOR;
2915 short_event_descriptor->descriptor_length = EIT_SHORT_EVENT_DESCRIPTOR_SIZE +
2916 prog_title_length - 1;
2917 short_event_descriptor->language_code_1 = 'e';
2918 short_event_descriptor->language_code_2 = 'n';
2919 short_event_descriptor->language_code_3 = 'g';
2920 short_event_descriptor->event_name_length = prog_title_length;
2921 u_char *event_name = (u_char *) short_event_descriptor + EIT_SHORT_EVENT_DESCRIPTOR_SIZE;
2922 memcpy(event_name, prog_title.c_str(), prog_title_length);
2925 event_name[prog_title_length] = 0;
2927 if ( sumText.length() > 0 )
2928 // There is summary info
2930 unsigned int sum_length = sumText.length();
2931 if ( sum_length + short_event_descriptor->descriptor_length <= 0xff )
2932 // Store summary in short event descriptor
2934 // Increase all relevant lengths
2935 event_name[prog_title_length] = sum_length;
2936 short_event_descriptor->descriptor_length += sum_length;
2937 packet_length += sum_length;
2938 descr_ll += sum_length;
2939 sumText.copy( (char *) event_name+prog_title_length+1, sum_length );
2942 // Store summary in extended event descriptors
2944 int remaining_sum_length = sumText.length();
2945 int nbr_descr = int(remaining_sum_length/247) + 1;
2946 for ( int i=0; i < nbr_descr; i++)
2947 // Loop once per extended event descriptor
2949 eit_extended_descriptor_struct *ext_event_descriptor = (eit_extended_descriptor_struct *) (data + packet_length);
2950 sum_length = remaining_sum_length > 247 ? 247 : remaining_sum_length;
2951 remaining_sum_length -= sum_length;
2952 packet_length += 8 + sum_length;
2953 descr_ll += 8 + sum_length;
2955 ext_event_descriptor->descriptor_tag = EIT_EXTENDED_EVENT_DESCRIPOR;
2956 ext_event_descriptor->descriptor_length = sum_length + 6;
2957 ext_event_descriptor->descriptor_number = i;
2958 ext_event_descriptor->last_descriptor_number = nbr_descr - 1;
2959 ext_event_descriptor->iso_639_2_language_code_1 = 'e';
2960 ext_event_descriptor->iso_639_2_language_code_2 = 'n';
2961 ext_event_descriptor->iso_639_2_language_code_3 = 'g';
2962 u_char *the_text = (u_char *) ext_event_descriptor + 8;
2964 the_text[-1] = sum_length;
2965 sumText.copy( (char *) the_text, sum_length, sumText.length() - sum_length - remaining_sum_length );
2972 // Add content descriptor
2973 u_char *descriptor = (u_char *) data + packet_length;
2978 std::string content_descr = (char *) delimitName( m_themes[itTitle->second.theme_id].name, name, 15 );
2979 if ( content_descr.find( "FILM" ) != std::string::npos )
2981 else if ( content_descr.find( "SPORT" ) != std::string::npos )
2984 descriptor[0] = 0x54;
2986 descriptor[2] = content_id;
2990 event_data->descriptors_loop_length_hi = (descr_ll & 0xf00)>>8;
2991 event_data->descriptors_loop_length_lo = (descr_ll & 0xff);
2993 packet->section_length_hi = ((packet_length - 3)&0xf00)>>8;
2994 packet->section_length_lo = (packet_length - 3)&0xff;
2996 // Feed the data to eEPGCache::sectionRead()
2997 cache->sectionRead( data, MHW, this );
3000 void eEPGCache::channel_data::startTimeout(int msec)
3002 m_MHWTimeoutTimer->start(msec,true);
3003 m_MHWTimeoutet=false;
3006 void eEPGCache::channel_data::startMHWReader(__u16 pid, __u8 tid)
3008 m_MHWFilterMask.pid = pid;
3009 m_MHWFilterMask.data[0] = tid;
3010 m_MHWReader->start(m_MHWFilterMask);
3011 // eDebug("start 0x%02x 0x%02x", pid, tid);
3014 void eEPGCache::channel_data::startMHWReader2(__u16 pid, __u8 tid, int ext)
3016 m_MHWFilterMask2.pid = pid;
3017 m_MHWFilterMask2.data[0] = tid;
3020 m_MHWFilterMask2.data[1] = ext;
3021 m_MHWFilterMask2.mask[1] = 0xFF;
3022 // eDebug("start 0x%03x 0x%02x 0x%02x", pid, tid, ext);
3026 m_MHWFilterMask2.data[1] = 0;
3027 m_MHWFilterMask2.mask[1] = 0;
3028 // eDebug("start 0x%02x 0x%02x", pid, tid);
3030 m_MHWReader2->start(m_MHWFilterMask2);
3033 void eEPGCache::channel_data::readMHWData(const __u8 *data)
3036 m_MHWReader2->stop();
3038 if ( state > 1 || // aborted
3039 // have si data.. so we dont read mhw data
3040 (haveData & (SCHEDULE|SCHEDULE_OTHER|VIASAT)) )
3042 eDebug("[EPGC] mhw aborted %d", state);
3044 else if (m_MHWFilterMask.pid == 0xD3 && m_MHWFilterMask.data[0] == 0x91)
3047 int len = ((data[1]&0xf)<<8) + data[2] - 1;
3048 int record_size = sizeof( mhw_channel_name_t );
3049 int nbr_records = int (len/record_size);
3051 m_channels.resize(nbr_records);
3052 for ( int i = 0; i < nbr_records; i++ )
3054 mhw_channel_name_t *channel = (mhw_channel_name_t*) &data[4 + i*record_size];
3055 m_channels[i]=*channel;
3059 eDebug("[EPGC] mhw %d channels found", m_channels.size());
3061 // Channels table has been read, start reading the themes table.
3062 startMHWReader(0xD3, 0x92);
3065 else if (m_MHWFilterMask.pid == 0xD3 && m_MHWFilterMask.data[0] == 0x92)
3068 int len = ((data[1]&0xf)<<8) + data[2] - 16;
3069 int record_size = sizeof( mhw_theme_name_t );
3070 int nbr_records = int (len/record_size);
3072 __u8 next_idx = (__u8) *(data + 3 + idx_ptr);
3075 for ( int i = 0; i < nbr_records; i++ )
3077 mhw_theme_name_t *theme = (mhw_theme_name_t*) &data[19 + i*record_size];
3078 if ( i >= next_idx )
3082 next_idx = (__u8) *(data + 3 + idx_ptr);
3088 m_themes[idx+sub_idx] = *theme;
3090 eDebug("[EPGC] mhw %d themes found", m_themes.size());
3091 // Themes table has been read, start reading the titles table.
3092 startMHWReader(0xD2, 0x90);
3096 else if (m_MHWFilterMask.pid == 0xD2 && m_MHWFilterMask.data[0] == 0x90)
3099 mhw_title_t *title = (mhw_title_t*) data;
3101 if ( title->channel_id == 0xFF ) // Separator
3102 return; // Continue reading of the current table.
3105 // Create unique key per title
3106 __u32 title_id = ((title->channel_id)<<16)|((title->dh.day)<<13)|((title->dh.hours)<<8)|
3107 (title->ms.minutes);
3108 __u32 program_id = ((title->program_id_hi)<<24)|((title->program_id_mh)<<16)|
3109 ((title->program_id_ml)<<8)|(title->program_id_lo);
3111 if ( m_titles.find( title_id ) == m_titles.end() )
3114 title->mhw2_mjd_hi = 0;
3115 title->mhw2_mjd_lo = 0;
3116 title->mhw2_duration_hi = 0;
3117 title->mhw2_duration_lo = 0;
3118 m_titles[ title_id ] = *title;
3119 if ( (title->ms.summary_available) && (m_program_ids.find(program_id) == m_program_ids.end()) )
3120 // program_ids will be used to gather summaries.
3121 m_program_ids.insert(std::pair<__u32,__u32>(program_id,title_id));
3122 return; // Continue reading of the current table.
3124 else if (!checkTimeout())
3127 if ( !m_program_ids.empty())
3129 // Titles table has been read, there are summaries to read.
3130 // Start reading summaries, store corresponding titles on the fly.
3131 startMHWReader(0xD3, 0x90);
3132 eDebug("[EPGC] mhw %d titles(%d with summary) found",
3134 m_program_ids.size());
3139 else if (m_MHWFilterMask.pid == 0xD3 && m_MHWFilterMask.data[0] == 0x90)
3142 mhw_summary_t *summary = (mhw_summary_t*) data;
3144 // Create unique key per record
3145 __u32 program_id = ((summary->program_id_hi)<<24)|((summary->program_id_mh)<<16)|
3146 ((summary->program_id_ml)<<8)|(summary->program_id_lo);
3147 int len = ((data[1]&0xf)<<8) + data[2];
3149 // ugly workaround to convert const __u8* to char*
3151 memcpy(&tmp, &data, sizeof(void*));
3152 tmp[len+3] = 0; // Terminate as a string.
3154 std::multimap<__u32, __u32>::iterator itProgid( m_program_ids.find( program_id ) );
3155 if ( itProgid == m_program_ids.end() )
3156 { /* This part is to prevent to looping forever if some summaries are not received yet.
3157 There is a timeout of 4 sec. after the last successfully read summary. */
3158 if (!m_program_ids.empty() && !checkTimeout())
3159 return; // Continue reading of the current table.
3163 std::string the_text = (char *) (data + 11 + summary->nb_replays * 7);
3166 while((pos = the_text.find("\r\n")) != std::string::npos)
3167 the_text.replace(pos, 2, " ");
3169 // Find corresponding title, store title and summary in epgcache.
3170 std::map<__u32, mhw_title_t>::iterator itTitle( m_titles.find( itProgid->second ) );
3171 if ( itTitle != m_titles.end() )
3174 storeTitle( itTitle, the_text, data );
3175 m_titles.erase( itTitle );
3177 m_program_ids.erase( itProgid );
3178 if ( !m_program_ids.empty() )
3179 return; // Continue reading of the current table.
3182 eDebug("[EPGC] mhw finished(%ld) %d summaries not found",
3184 m_program_ids.size());
3185 // Summaries have been read, titles that have summaries have been stored.
3186 // Now store titles that do not have summaries.
3187 for (std::map<__u32, mhw_title_t>::iterator itTitle(m_titles.begin()); itTitle != m_titles.end(); itTitle++)
3188 storeTitle( itTitle, "", data );
3192 m_MHWReader->stop();
3197 void eEPGCache::channel_data::readMHWData2(const __u8 *data)
3199 int dataLen = (((data[1]&0xf) << 8) | data[2]) + 3;
3202 m_MHWReader->stop();
3204 if ( state > 1 || // aborted
3205 // have si data.. so we dont read mhw data
3206 (haveData & (SCHEDULE|SCHEDULE_OTHER|VIASAT)) )
3208 eDebug("[EPGC] mhw2 aborted %d", state);
3210 else if (m_MHWFilterMask2.pid == 0x231 && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 0)
3213 int num_channels = data[119];
3214 m_channels.resize(num_channels);
3217 int ptr = 120 + 8 * num_channels;
3220 for( int chid = 0; chid < num_channels; ++chid )
3222 ptr += ( data[ptr] & 0x0f ) + 1;
3232 // data seems consistent...
3233 const __u8 *tmp = data+120;
3234 for (int i=0; i < num_channels; ++i)
3236 mhw_channel_name_t channel;
3237 channel.network_id_hi = *(tmp++);
3238 channel.network_id_lo = *(tmp++);
3239 channel.transport_stream_id_hi = *(tmp++);
3240 channel.transport_stream_id_lo = *(tmp++);
3241 channel.channel_id_hi = *(tmp++);
3242 channel.channel_id_lo = *(tmp++);
3243 m_channels[i]=channel;
3246 for (int i=0; i < num_channels; ++i)
3248 mhw_channel_name_t &channel = m_channels[i];
3249 int channel_name_len=*(tmp++)&0x0f;
3251 for (; x < channel_name_len; ++x)
3252 channel.name[x]=*(tmp++);
3253 channel.name[x+1]=0;
3256 eDebug("[EPGC] mhw2 %d channels found", m_channels.size());
3258 else if (m_MHWFilterMask2.pid == 0x231 && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 1)
3261 eDebug("[EPGC] mhw2 themes nyi");
3263 else if (m_MHWFilterMask2.pid == 0x234 && m_MHWFilterMask2.data[0] == 0xe6)
3268 int len = ((data[1]&0xf)<<8) + data[2] - 16;
3270 if(data[dataLen-1] != 0xff)
3272 while( pos < dataLen )
3281 if( data[pos] > 0xc0 )
3283 pos += ( data[pos] - 0xc0 );
3287 if( data[pos] == 0xff )
3303 // data seems consistent...
3308 title.channel_id = data[pos]+1;
3309 title.program_id_ml = data[pos+1];
3310 title.program_id_lo = data[pos+2];
3311 title.mhw2_mjd_hi = data[pos+3];
3312 title.mhw2_mjd_lo = data[pos+4];
3313 title.mhw2_hours = data[pos+5];
3314 title.mhw2_minutes = data[pos+6];
3315 title.mhw2_seconds = data[pos+7];
3316 int duration = ((data[pos+8] << 8)|data[pos+9]) >> 4;
3317 title.mhw2_duration_hi = (duration&0xFF00) >> 8;
3318 title.mhw2_duration_lo = duration&0xFF;
3319 __u8 slen = data[pos+10] & 0x3f;
3320 __u8 *dest = ((__u8*)title.title)-4;
3321 memcpy(dest, &data[pos+11], slen>33 ? 33 : slen);
3322 memset(dest+slen, 0, 33-slen);
3324 // not used theme id (data[7] & 0x3f) + (data[pos] & 0x3f);
3325 __u32 summary_id = (data[pos+1] << 8) | data[pos+2];
3327 // Create unique key per title
3328 __u32 title_id = (title.channel_id<<16) | (title.program_id_ml<<8) | title.program_id_lo;
3332 std::map<__u32, mhw_title_t>::iterator it = m_titles.find( title_id );
3333 if ( it == m_titles.end() )
3336 m_titles[ title_id ] = title;
3337 if (summary_id != 0xFFFF)
3340 std::multimap<__u32, __u32>::iterator it(m_program_ids.lower_bound(summary_id));
3341 while (it != m_program_ids.end() && it->first == summary_id)
3343 if (it->second == title_id) {
3350 m_program_ids.insert(std::pair<__u32,__u32>(summary_id,title_id));
3355 if ( !checkTimeout() )
3356 continue; // Continue reading of the current table.
3364 eDebug("[EPGC] mhw2 %d titles(%d with summary) found", m_titles.size(), m_program_ids.size());
3365 if (!m_program_ids.empty())
3367 // Titles table has been read, there are summaries to read.
3368 // Start reading summaries, store corresponding titles on the fly.
3369 startMHWReader2(0x236, 0x96);
3370 startTimeout(15000);
3377 else if (m_MHWFilterMask2.pid == 0x236 && m_MHWFilterMask2.data[0] == 0x96)
3380 if (!checkTimeout())
3382 int len, loop, pos, lenline;
3391 loop = data[pos] & 0x0f;
3396 for( ; loop > 0; --loop )
3398 if( dataLen > (pos+len) )
3400 lenline = data[pos+len];
3410 return; // continue reading
3413 // data seems consistent...
3414 __u32 summary_id = (data[3]<<8)|data[4];
3416 // ugly workaround to convert const __u8* to char*
3418 memcpy(&tmp, &data, sizeof(void*));
3423 loop = tmp[pos] & 0x0f;
3425 for( ; loop > 0; loop -- )
3427 lenline = tmp[pos+len];
3436 std::multimap<__u32, __u32>::iterator itProgId( m_program_ids.lower_bound(summary_id) );
3437 if ( itProgId == m_program_ids.end() || itProgId->first != summary_id)
3438 { /* This part is to prevent to looping forever if some summaries are not received yet.
3439 There is a timeout of 4 sec. after the last successfully read summary. */
3440 if ( !m_program_ids.empty() )
3441 return; // Continue reading of the current table.
3445 startTimeout(15000);
3446 std::string the_text = (char *) (data + pos + 1);
3448 while( itProgId != m_program_ids.end() && itProgId->first == summary_id )
3450 // Find corresponding title, store title and summary in epgcache.
3451 std::map<__u32, mhw_title_t>::iterator itTitle( m_titles.find( itProgId->second ) );
3452 if ( itTitle != m_titles.end() )
3454 storeTitle( itTitle, the_text, data );
3455 m_titles.erase( itTitle );
3457 m_program_ids.erase( itProgId++ );
3459 if ( !m_program_ids.empty() )
3460 return; // Continue reading of the current table.
3464 return; // continue reading
3467 if (isRunning & eEPGCache::MHW)
3469 if ( m_MHWFilterMask2.pid == 0x231 && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 0)
3471 // Channels table has been read, start reading the themes table.
3472 startMHWReader2(0x231, 0xC8, 1);
3475 else if ( m_MHWFilterMask2.pid == 0x231 && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 1)
3477 // Themes table has been read, start reading the titles table.
3478 startMHWReader2(0x234, 0xe6);
3483 // Summaries have been read, titles that have summaries have been stored.
3484 // Now store titles that do not have summaries.
3485 for (std::map<__u32, mhw_title_t>::iterator itTitle(m_titles.begin()); itTitle != m_titles.end(); itTitle++)
3486 storeTitle( itTitle, "", data );
3487 eDebug("[EPGC] mhw2 finished(%ld) %d summaries not found",
3489 m_program_ids.size());
3496 m_MHWReader2->stop();