1 #include <lib/dvb/epgcache.h>
2 #include <lib/dvb/dvb.h>
7 #include <unistd.h> // for usleep
8 #include <sys/vfs.h> // for statfs
9 // #include <libmd5sum.h>
10 #include <lib/base/eerror.h>
11 #include <lib/dvb/pmt.h>
14 int eventData::CacheSize=0;
15 descriptorMap eventData::descriptors;
16 __u8 eventData::data[4108];
17 extern const uint32_t crc32_table[256];
19 eventData::eventData(const eit_event_struct* e, int size, int type)
20 :ByteSize(size&0xFF), type(type&0xFF)
28 __u8 *data = (__u8*)e;
30 int descriptors_length = (data[ptr++]&0x0F) << 8;
31 descriptors_length |= data[ptr++];
32 while ( descriptors_length > 0 )
34 __u8 *descr = data+ptr;
35 int descr_len = descr[1]+2;
39 while(cnt++ < descr_len)
40 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ data[ptr++]) & 0xFF];
42 descriptorMap::iterator it =
43 descriptors.find(crc);
44 if ( it == descriptors.end() )
47 __u8 *d = new __u8[descr_len];
48 memcpy(d, descr, descr_len);
49 descriptors[crc] = descriptorPair(1, d);
55 descriptors_length -= descr_len;
57 ByteSize = 12+((pdescr-descr)*4);
58 EITdata = new __u8[ByteSize];
60 memcpy(EITdata, (__u8*) e, 12);
61 memcpy(EITdata+12, descr, ByteSize-12);
64 const eit_event_struct* eventData::get() const
67 int tmp = ByteSize-12;
69 memcpy(data, EITdata, 12);
70 __u32 *p = (__u32*)(EITdata+12);
73 descriptorMap::iterator it =
74 descriptors.find(*p++);
75 if ( it != descriptors.end() )
77 int b = it->second.second[1]+2;
78 memcpy(data+pos, it->second.second, b );
84 return (const eit_event_struct*)data;
87 eventData::~eventData()
93 __u32 *d = (__u32*)(EITdata+12);
96 descriptorMap::iterator it =
97 descriptors.find(*d++);
98 if ( it != descriptors.end() )
100 descriptorPair &p = it->second;
101 if (!--p.first) // no more used descriptor
103 CacheSize -= it->second.second[1];
104 delete [] it->second.second; // free descriptor memory
105 descriptors.erase(it); // remove entry from descriptor map
114 void eventData::load(FILE *f)
120 fread(&size, sizeof(int), 1, f);
123 fread(&id, sizeof(__u32), 1, f);
124 fread(&p.first, sizeof(int), 1, f);
125 fread(header, 2, 1, f);
126 int bytes = header[1]+2;
127 p.second = new __u8[bytes];
128 p.second[0] = header[0];
129 p.second[1] = header[1];
130 fread(p.second+2, bytes-2, 1, f);
137 void eventData::save(FILE *f)
139 int size=descriptors.size();
140 descriptorMap::iterator it(descriptors.begin());
141 fwrite(&size, sizeof(int), 1, f);
144 fwrite(&it->first, sizeof(__u32), 1, f);
145 fwrite(&it->second.first, sizeof(int), 1, f);
146 fwrite(it->second.second, it->second.second[1]+2, 1, f);
152 eEPGCache* eEPGCache::instance;
153 pthread_mutex_t eEPGCache::cache_lock=
154 PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
155 pthread_mutex_t eEPGCache::channel_map_lock=
156 PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
158 DEFINE_REF(eEPGCache)
160 eEPGCache::eEPGCache()
161 :messages(this,1), cleanTimer(this)//, paused(0)
163 eDebug("[EPGC] Initialized EPGCache");
165 CONNECT(messages.recv_msg, eEPGCache::gotMessage);
166 CONNECT(eDVBLocalTimeHandler::getInstance()->m_timeUpdated, eEPGCache::timeUpdated);
167 CONNECT(cleanTimer.timeout, eEPGCache::cleanLoop);
169 ePtr<eDVBResourceManager> res_mgr;
170 eDVBResourceManager::getInstance(res_mgr);
172 eDebug("[eEPGCache] no resource manager !!!!!!!");
174 res_mgr->connectChannelAdded(slot(*this,&eEPGCache::DVBChannelAdded), m_chanAddedConn);
178 void eEPGCache::timeUpdated()
180 if ( !thread_running() )
182 eDebug("[EPGC] time updated.. start EPG Mainloop");
186 messages.send(Message(Message::timeChanged));
189 void eEPGCache::DVBChannelAdded(eDVBChannel *chan)
193 // eDebug("[eEPGCache] add channel %p", chan);
194 channel_data *data = new channel_data(this);
195 data->channel = chan;
196 data->prevChannelState = -1;
197 #ifdef ENABLE_PRIVATE_EPG
198 data->m_PrivatePid = -1;
200 singleLock s(channel_map_lock);
201 m_knownChannels.insert( std::pair<iDVBChannel*, channel_data* >(chan, data) );
202 chan->connectStateChange(slot(*this, &eEPGCache::DVBChannelStateChanged), data->m_stateChangedConn);
206 void eEPGCache::DVBChannelRunning(iDVBChannel *chan)
208 singleLock s(channel_map_lock);
209 channelMapIterator it =
210 m_knownChannels.find(chan);
211 if ( it == m_knownChannels.end() )
212 eDebug("[eEPGCache] will start non existing channel %p !!!", chan);
215 channel_data &data = *it->second;
216 ePtr<eDVBResourceManager> res_mgr;
217 if ( eDVBResourceManager::getInstance( res_mgr ) )
218 eDebug("[eEPGCache] no res manager!!");
221 ePtr<iDVBDemux> demux;
222 if ( data.channel->getDemux(demux, 0) )
224 eDebug("[eEPGCache] no demux!!");
229 RESULT res = demux->createSectionReader( this, data.m_NowNextReader );
232 eDebug("[eEPGCache] couldnt initialize nownext reader!!");
236 res = demux->createSectionReader( this, data.m_ScheduleReader );
239 eDebug("[eEPGCache] couldnt initialize schedule reader!!");
243 res = demux->createSectionReader( this, data.m_ScheduleOtherReader );
246 eDebug("[eEPGCache] couldnt initialize schedule other reader!!");
249 #ifdef ENABLE_PRIVATE_EPG
250 res = demux->createSectionReader( this, data.m_PrivateReader );
253 eDebug("[eEPGCache] couldnt initialize private reader!!");
257 messages.send(Message(Message::startChannel, chan));
258 // -> gotMessage -> changedService
264 void eEPGCache::DVBChannelStateChanged(iDVBChannel *chan)
266 channelMapIterator it =
267 m_knownChannels.find(chan);
268 if ( it != m_knownChannels.end() )
271 chan->getState(state);
272 if ( it->second->prevChannelState != state )
276 case iDVBChannel::state_ok:
278 eDebug("[eEPGCache] channel %p running", chan);
279 DVBChannelRunning(chan);
282 case iDVBChannel::state_release:
284 eDebug("[eEPGCache] remove channel %p", chan);
285 messages.send(Message(Message::leaveChannel, chan));
286 while(!it->second->can_delete)
289 m_knownChannels.erase(it);
290 // -> gotMessage -> abortEPG
293 default: // ignore all other events
296 it->second->prevChannelState = state;
301 void eEPGCache::sectionRead(const __u8 *data, int source, channel_data *channel)
303 eit_t *eit = (eit_t*) data;
305 int len=HILO(eit->section_length)-1;//+3-4;
310 // This fixed the EPG on the Multichoice irdeto systems
311 // the EIT packet is non-compliant.. their EIT packet stinks
312 if ( data[ptr-1] < 0x40 )
315 uniqueEPGKey service( HILO(eit->service_id), HILO(eit->original_network_id), HILO(eit->transport_stream_id) );
316 eit_event_struct* eit_event = (eit_event_struct*) (data+ptr);
320 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);
321 time_t now = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
323 if ( TM != 3599 && TM > -1)
324 channel->haveData |= source;
326 singleLock s(cache_lock);
327 // hier wird immer eine eventMap zurück gegeben.. entweder eine vorhandene..
328 // oder eine durch [] erzeugte
329 std::pair<eventMap,timeMap> &servicemap = eventDB[service];
330 eventMap::iterator prevEventIt = servicemap.first.end();
331 timeMap::iterator prevTimeIt = servicemap.second.end();
335 eit_event_size = HILO(eit_event->descriptors_loop_length)+EIT_LOOP_SIZE;
337 duration = fromBCD(eit_event->duration_1)*3600+fromBCD(eit_event->duration_2)*60+fromBCD(eit_event->duration_3);
339 eit_event->start_time_1,
340 eit_event->start_time_2,
341 eit_event->start_time_3,
342 eit_event->start_time_4,
343 eit_event->start_time_5);
348 if ( TM != 3599 && (TM+duration < now || TM > now+14*24*60*60) )
351 if ( now <= (TM+duration) || TM == 3599 /*NVOD Service*/ ) // old events should not be cached
353 __u16 event_id = HILO(eit_event->event_id);
354 // eDebug("event_id is %d sid is %04x", event_id, service.sid);
357 int ev_erase_count = 0;
358 int tm_erase_count = 0;
360 // search in eventmap
361 eventMap::iterator ev_it =
362 servicemap.first.find(event_id);
364 // entry with this event_id is already exist ?
365 if ( ev_it != servicemap.first.end() )
367 if ( source > ev_it->second->type ) // update needed ?
368 goto next; // when not.. the skip this entry
370 // search this event in timemap
371 timeMap::iterator tm_it_tmp =
372 servicemap.second.find(ev_it->second->getStartTime());
374 if ( tm_it_tmp != servicemap.second.end() )
376 if ( tm_it_tmp->first == TM ) // correct eventData
379 delete ev_it->second;
380 evt = new eventData(eit_event, eit_event_size, source);
382 tm_it_tmp->second=evt;
388 // delete the found record from timemap
389 servicemap.second.erase(tm_it_tmp);
390 prevTimeIt=servicemap.second.end();
395 // search in timemap, for check of a case if new time has coincided with time of other event
396 // or event was is not found in eventmap
397 timeMap::iterator tm_it =
398 servicemap.second.find(TM);
400 if ( tm_it != servicemap.second.end() )
402 // i think, if event is not found on eventmap, but found on timemap updating nevertheless demands
404 if ( source > tm_it->second->type && tm_erase_count == 0 ) // update needed ?
405 goto next; // when not.. the skip this entry
408 // search this time in eventmap
409 eventMap::iterator ev_it_tmp =
410 servicemap.first.find(tm_it->second->getEventID());
412 if ( ev_it_tmp != servicemap.first.end() )
415 // delete the found record from eventmap
416 servicemap.first.erase(ev_it_tmp);
417 prevEventIt=servicemap.first.end();
421 evt = new eventData(eit_event, eit_event_size, source);
423 bool consistencyCheck=true;
425 if (ev_erase_count > 0 && tm_erase_count > 0) // 2 different pairs have been removed
428 delete ev_it->second;
429 delete tm_it->second;
433 else if (ev_erase_count == 0 && tm_erase_count > 0)
436 delete ev_it->second;
437 tm_it=prevTimeIt=servicemap.second.insert( prevTimeIt, std::pair<const time_t, eventData*>( TM, evt ) );
440 else if (ev_erase_count > 0 && tm_erase_count == 0)
443 delete tm_it->second;
444 ev_it=prevEventIt=servicemap.first.insert( prevEventIt, std::pair<const __u16, eventData*>( event_id, evt) );
447 else // added new eventData
450 consistencyCheck=false;
452 prevEventIt=servicemap.first.insert( prevEventIt, std::pair<const __u16, eventData*>( event_id, evt) );
453 prevTimeIt=servicemap.second.insert( prevTimeIt, std::pair<const time_t, eventData*>( TM, evt ) );
456 if ( consistencyCheck )
458 if ( tm_it->second != evt || ev_it->second != evt )
459 eFatal("tm_it->second != ev_it->second");
460 else if ( tm_it->second->getStartTime() != tm_it->first )
461 eFatal("event start_time(%d) non equal timemap key(%d)",
462 tm_it->second->getStartTime(), tm_it->first );
463 else if ( tm_it->first != TM )
464 eFatal("timemap key(%d) non equal TM(%d)",
466 else if ( ev_it->second->getEventID() != ev_it->first )
467 eFatal("event_id (%d) non equal event_map key(%d)",
468 ev_it->second->getEventID(), ev_it->first);
469 else if ( ev_it->first != event_id )
470 eFatal("eventmap key(%d) non equal event_id(%d)",
471 ev_it->first, event_id );
477 if ( servicemap.first.size() != servicemap.second.size() )
479 FILE *f = fopen("/hdd/event_map.txt", "w+");
481 for (eventMap::iterator it(servicemap.first.begin())
482 ; it != servicemap.first.end(); ++it )
483 fprintf(f, "%d(key %d) -> time %d, event_id %d, data %p\n",
484 i++, (int)it->first, (int)it->second->getStartTime(), (int)it->second->getEventID(), it->second );
486 f = fopen("/hdd/time_map.txt", "w+");
488 for (timeMap::iterator it(servicemap.second.begin())
489 ; it != servicemap.second.end(); ++it )
490 fprintf(f, "%d(key %d) -> time %d, event_id %d, data %p\n",
491 i++, (int)it->first, (int)it->second->getStartTime(), (int)it->second->getEventID(), it->second );
494 eFatal("(1)map sizes not equal :( sid %04x tsid %04x onid %04x size %d size2 %d",
495 service.sid, service.tsid, service.onid,
496 servicemap.first.size(), servicemap.second.size() );
499 ptr += eit_event_size;
500 eit_event=(eit_event_struct*)(((__u8*)eit_event)+eit_event_size);
504 void eEPGCache::flushEPG(const uniqueEPGKey & s)
506 eDebug("[EPGC] flushEPG %d", (int)(bool)s);
507 singleLock l(cache_lock);
508 if (s) // clear only this service
510 eventCache::iterator it = eventDB.find(s);
511 if ( it != eventDB.end() )
513 eventMap &evMap = it->second.first;
514 timeMap &tmMap = it->second.second;
516 for (eventMap::iterator i = evMap.begin(); i != evMap.end(); ++i)
521 // TODO .. search corresponding channel for removed service and remove this channel from lastupdated map
522 #ifdef ENABLE_PRIVATE_EPG
523 contentMaps::iterator it =
524 content_time_tables.find(s);
525 if ( it != content_time_tables.end() )
528 content_time_tables.erase(it);
533 else // clear complete EPG Cache
535 for (eventCache::iterator it(eventDB.begin());
536 it != eventDB.end(); ++it)
538 eventMap &evMap = it->second.first;
539 timeMap &tmMap = it->second.second;
540 for (eventMap::iterator i = evMap.begin(); i != evMap.end(); ++i)
546 #ifdef ENABLE_PRIVATE_EPG
547 content_time_tables.clear();
549 channelLastUpdated.clear();
550 singleLock m(channel_map_lock);
551 for (channelMapIterator it(m_knownChannels.begin()); it != m_knownChannels.end(); ++it)
552 it->second->startEPG();
554 eDebug("[EPGC] %i bytes for cache used", eventData::CacheSize);
557 void eEPGCache::cleanLoop()
559 singleLock s(cache_lock);
560 if (!eventDB.empty())
562 eDebug("[EPGC] start cleanloop");
564 time_t now = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
566 for (eventCache::iterator DBIt = eventDB.begin(); DBIt != eventDB.end(); DBIt++)
568 bool updated = false;
569 for (timeMap::iterator It = DBIt->second.second.begin(); It != DBIt->second.second.end() && It->first < now;)
571 if ( now > (It->first+It->second->getDuration()) ) // outdated normal entry (nvod references to)
573 // remove entry from eventMap
574 eventMap::iterator b(DBIt->second.first.find(It->second->getEventID()));
575 if ( b != DBIt->second.first.end() )
577 // release Heap Memory for this entry (new ....)
578 // eDebug("[EPGC] delete old event (evmap)");
579 DBIt->second.first.erase(b);
582 // remove entry from timeMap
583 // eDebug("[EPGC] release heap mem");
585 DBIt->second.second.erase(It++);
586 // eDebug("[EPGC] delete old event (timeMap)");
592 #ifdef ENABLE_PRIVATE_EPG
595 contentMaps::iterator x =
596 content_time_tables.find( DBIt->first );
597 if ( x != content_time_tables.end() )
599 timeMap &tmMap = eventDB[DBIt->first].second;
600 for ( contentMap::iterator i = x->second.begin(); i != x->second.end(); )
602 for ( contentTimeMap::iterator it(i->second.begin());
603 it != i->second.end(); )
605 if ( tmMap.find(it->second.first) == tmMap.end() )
606 i->second.erase(it++);
610 if ( i->second.size() )
613 x->second.erase(i++);
619 eDebug("[EPGC] stop cleanloop");
620 eDebug("[EPGC] %i bytes for cache used", eventData::CacheSize);
622 cleanTimer.start(CLEAN_INTERVAL,true);
625 eEPGCache::~eEPGCache()
627 messages.send(Message::quit);
628 kill(); // waiting for thread shutdown
629 singleLock s(cache_lock);
630 for (eventCache::iterator evIt = eventDB.begin(); evIt != eventDB.end(); evIt++)
631 for (eventMap::iterator It = evIt->second.first.begin(); It != evIt->second.first.end(); It++)
635 void eEPGCache::gotMessage( const Message &msg )
640 flushEPG(msg.service);
642 case Message::startChannel:
644 singleLock s(channel_map_lock);
645 channelMapIterator channel =
646 m_knownChannels.find(msg.channel);
647 if ( channel != m_knownChannels.end() )
648 channel->second->startChannel();
651 case Message::leaveChannel:
653 singleLock s(channel_map_lock);
654 channelMapIterator channel =
655 m_knownChannels.find(msg.channel);
656 if ( channel != m_knownChannels.end() )
657 channel->second->abortEPG();
663 #ifdef ENABLE_PRIVATE_EPG
664 case Message::got_private_pid:
666 for (channelMapIterator it(m_knownChannels.begin()); it != m_knownChannels.end(); ++it)
668 eDVBChannel *channel = (eDVBChannel*) it->first;
669 channel_data *data = it->second;
670 eDVBChannelID chid = channel->getChannelID();
671 if ( chid.transport_stream_id.get() == msg.service.tsid &&
672 chid.original_network_id.get() == msg.service.onid &&
673 data->m_PrivatePid == -1 )
675 data->m_PrivatePid = msg.pid;
676 data->m_PrivateService = msg.service;
677 data->startPrivateReader(msg.pid, -1);
684 case Message::timeChanged:
688 eDebug("unhandled EPGCache Message!!");
693 void eEPGCache::thread()
702 void eEPGCache::load()
704 FILE *f = fopen("/hdd/epg.dat", "r");
707 unsigned char md5_saved[16];
708 unsigned char md5[16];
713 if (!md5_file("/hdd/epg.dat", 1, md5))
715 FILE *f = fopen("/hdd/epg.dat.md5", "r");
718 fread( md5_saved, 16, 1, f);
720 if ( !memcmp(md5_saved, md5, 16) )
728 fread( text1, 13, 1, f);
729 if ( !strncmp( text1, "ENIGMA_EPG_V4", 13) )
731 fread( &size, sizeof(int), 1, f);
738 fread( &key, sizeof(uniqueEPGKey), 1, f);
739 fread( &size, sizeof(int), 1, f);
745 fread( &type, sizeof(__u8), 1, f);
746 fread( &len, sizeof(__u8), 1, f);
747 event = new eventData(0, len, type);
748 event->EITdata = new __u8[len];
749 eventData::CacheSize+=len;
750 fread( event->EITdata, len, 1, f);
751 evMap[ event->getEventID() ]=event;
752 tmMap[ event->getStartTime() ]=event;
755 eventDB[key]=std::pair<eventMap,timeMap>(evMap,tmMap);
758 eDebug("%d events read from /hdd/epg.dat", cnt);
759 #ifdef ENABLE_PRIVATE_EPG
761 fread( text2, 11, 1, f);
762 if ( !strncmp( text2, "PRIVATE_EPG", 11) )
765 fread( &size, sizeof(int), 1, f);
770 fread( &key, sizeof(uniqueEPGKey), 1, f);
771 fread( &size, sizeof(int), 1, f);
776 fread( &content_id, sizeof(int), 1, f);
777 fread( &size, sizeof(int), 1, f);
782 fread( &time1, sizeof(time_t), 1, f);
783 fread( &time2, sizeof(time_t), 1, f);
784 fread( &event_id, sizeof(__u16), 1, f);
785 content_time_tables[key][content_id][time1]=std::pair<time_t, __u16>(time2, event_id);
790 #endif // ENABLE_PRIVATE_EPG
793 eDebug("[EPGC] don't read old epg database");
799 void eEPGCache::save()
803 if (statfs("/hdd", &s)<0)
811 // prevent writes to builtin flash
812 if ( tmp < 1024*1024*50 ) // storage size < 50MB
815 // check for enough free space on storage
818 if ( tmp < (eventData::CacheSize*12)/10 ) // 20% overhead
821 FILE *f = fopen("/hdd/epg.dat", "w");
825 const char *text = "ENIGMA_EPG_V4";
826 fwrite( text, 13, 1, f );
827 int size = eventDB.size();
828 fwrite( &size, sizeof(int), 1, f );
829 for (eventCache::iterator service_it(eventDB.begin()); service_it != eventDB.end(); ++service_it)
831 timeMap &timemap = service_it->second.second;
832 fwrite( &service_it->first, sizeof(uniqueEPGKey), 1, f);
833 size = timemap.size();
834 fwrite( &size, sizeof(int), 1, f);
835 for (timeMap::iterator time_it(timemap.begin()); time_it != timemap.end(); ++time_it)
837 __u8 len = time_it->second->ByteSize;
838 fwrite( &time_it->second->type, sizeof(__u8), 1, f );
839 fwrite( &len, sizeof(__u8), 1, f);
840 fwrite( time_it->second->EITdata, len, 1, f);
844 eDebug("%d events written to /hdd/epg.dat", cnt);
846 #ifdef ENABLE_PRIVATE_EPG
847 const char* text3 = "PRIVATE_EPG";
848 fwrite( text3, 11, 1, f );
849 size = content_time_tables.size();
850 fwrite( &size, sizeof(int), 1, f);
851 for (contentMaps::iterator a = content_time_tables.begin(); a != content_time_tables.end(); ++a)
853 contentMap &content_time_table = a->second;
854 fwrite( &a->first, sizeof(uniqueEPGKey), 1, f);
855 int size = content_time_table.size();
856 fwrite( &size, sizeof(int), 1, f);
857 for (contentMap::iterator i = content_time_table.begin(); i != content_time_table.end(); ++i )
859 int size = i->second.size();
860 fwrite( &i->first, sizeof(int), 1, f);
861 fwrite( &size, sizeof(int), 1, f);
862 for ( contentTimeMap::iterator it(i->second.begin());
863 it != i->second.end(); ++it )
865 fwrite( &it->first, sizeof(time_t), 1, f);
866 fwrite( &it->second.first, sizeof(time_t), 1, f);
867 fwrite( &it->second.second, sizeof(__u16), 1, f);
874 unsigned char md5[16];
875 if (!md5_file("/hdd/epg.dat", 1, md5))
877 FILE *f = fopen("/hdd/epg.dat.md5", "w");
880 fwrite( md5, 16, 1, f);
888 eEPGCache::channel_data::channel_data(eEPGCache *ml)
890 ,abortTimer(ml), zapTimer(ml)
891 ,state(0), isRunning(0), haveData(0), can_delete(1)
893 CONNECT(zapTimer.timeout, eEPGCache::channel_data::startEPG);
894 CONNECT(abortTimer.timeout, eEPGCache::channel_data::abortNonAvail);
897 bool eEPGCache::channel_data::finishEPG()
899 if (!isRunning) // epg ready
901 eDebug("[EPGC] stop caching events(%d)", time(0)+eDVBLocalTimeHandler::getInstance()->difference());
902 zapTimer.start(UPDATE_INTERVAL, 1);
903 eDebug("[EPGC] next update in %i min", UPDATE_INTERVAL / 60000);
904 for (int i=0; i < 3; ++i)
906 seenSections[i].clear();
907 calcedSections[i].clear();
909 singleLock l(cache->cache_lock);
910 cache->channelLastUpdated[channel->getChannelID()] = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
911 #ifdef ENABLE_PRIVATE_EPG
912 if (seenPrivateSections.empty())
920 void eEPGCache::channel_data::startEPG()
922 eDebug("[EPGC] start caching events(%d)", eDVBLocalTimeHandler::getInstance()->difference()+time(0));
926 for (int i=0; i < 3; ++i)
928 seenSections[i].clear();
929 calcedSections[i].clear();
932 eDVBSectionFilterMask mask;
933 memset(&mask, 0, sizeof(mask));
935 mask.flags = eDVBSectionFilterMask::rfCRC;
939 m_NowNextReader->connectRead(slot(*this, &eEPGCache::channel_data::readData), m_NowNextConn);
940 m_NowNextReader->start(mask);
941 isRunning |= NOWNEXT;
945 m_ScheduleReader->connectRead(slot(*this, &eEPGCache::channel_data::readData), m_ScheduleConn);
946 m_ScheduleReader->start(mask);
947 isRunning |= SCHEDULE;
951 m_ScheduleOtherReader->connectRead(slot(*this, &eEPGCache::channel_data::readData), m_ScheduleOtherConn);
952 m_ScheduleOtherReader->start(mask);
953 isRunning |= SCHEDULE_OTHER;
955 abortTimer.start(7000,true);
958 void eEPGCache::channel_data::abortNonAvail()
962 if ( !(haveData&eEPGCache::NOWNEXT) && (isRunning&eEPGCache::NOWNEXT) )
964 eDebug("[EPGC] abort non avail nownext reading");
965 isRunning &= ~eEPGCache::NOWNEXT;
966 m_NowNextReader->stop();
969 if ( !(haveData&eEPGCache::SCHEDULE) && (isRunning&eEPGCache::SCHEDULE) )
971 eDebug("[EPGC] abort non avail schedule reading");
972 isRunning &= ~SCHEDULE;
973 m_ScheduleReader->stop();
976 if ( !(haveData&eEPGCache::SCHEDULE_OTHER) && (isRunning&eEPGCache::SCHEDULE_OTHER) )
978 eDebug("[EPGC] abort non avail schedule_other reading");
979 isRunning &= ~SCHEDULE_OTHER;
980 m_ScheduleOtherReader->stop();
981 m_ScheduleOtherConn=0;
984 abortTimer.start(90000, true);
988 for (int i=0; i < 3; ++i)
990 seenSections[i].clear();
991 calcedSections[i].clear();
993 #ifdef ENABLE_PRIVATE_EPG
994 if (seenPrivateSections.empty())
1002 void eEPGCache::channel_data::startChannel()
1004 updateMap::iterator It = cache->channelLastUpdated.find( channel->getChannelID() );
1006 int update = ( It != cache->channelLastUpdated.end() ? ( UPDATE_INTERVAL - ( (time(0)+eDVBLocalTimeHandler::getInstance()->difference()-It->second) * 1000 ) ) : ZAP_DELAY );
1008 if (update < ZAP_DELAY)
1011 zapTimer.start(update, 1);
1012 if (update >= 60000)
1013 eDebug("[EPGC] next update in %i min", update/60000);
1014 else if (update >= 1000)
1015 eDebug("[EPGC] next update in %i sec", update/1000);
1018 void eEPGCache::channel_data::abortEPG()
1020 for (int i=0; i < 3; ++i)
1022 seenSections[i].clear();
1023 calcedSections[i].clear();
1029 eDebug("[EPGC] abort caching events !!");
1030 if (isRunning & eEPGCache::SCHEDULE)
1032 isRunning &= ~eEPGCache::SCHEDULE;
1033 m_ScheduleReader->stop();
1036 if (isRunning & eEPGCache::NOWNEXT)
1038 isRunning &= ~eEPGCache::NOWNEXT;
1039 m_NowNextReader->stop();
1042 if (isRunning & SCHEDULE_OTHER)
1044 isRunning &= ~eEPGCache::SCHEDULE_OTHER;
1045 m_ScheduleOtherReader->stop();
1046 m_ScheduleOtherConn=0;
1049 #ifdef ENABLE_PRIVATE_EPG
1050 if (m_PrivateReader)
1051 m_PrivateReader->stop();
1058 void eEPGCache::channel_data::readData( const __u8 *data)
1061 eDebug("get Null pointer from section reader !!");
1066 iDVBSectionReader *reader=NULL;
1070 reader=m_NowNextReader;
1071 source=eEPGCache::NOWNEXT;
1075 reader=m_ScheduleReader;
1076 source=eEPGCache::SCHEDULE;
1080 reader=m_ScheduleOtherReader;
1081 source=eEPGCache::SCHEDULE_OTHER;
1085 eDebug("[EPGC] unknown table_id !!!");
1088 tidMap &seenSections = this->seenSections[map];
1089 tidMap &calcedSections = this->calcedSections[map];
1090 if ( state == 1 && calcedSections == seenSections || state > 1 )
1092 eDebugNoNewLine("[EPGC] ");
1095 case eEPGCache::NOWNEXT:
1097 eDebugNoNewLine("nownext");
1099 case eEPGCache::SCHEDULE:
1101 eDebugNoNewLine("schedule");
1103 case eEPGCache::SCHEDULE_OTHER:
1104 m_ScheduleOtherConn=0;
1105 eDebugNoNewLine("schedule other");
1107 default: eDebugNoNewLine("unknown");break;
1109 eDebug(" finished(%d)", time(0)+eDVBLocalTimeHandler::getInstance()->difference());
1112 isRunning &= ~source;
1118 eit_t *eit = (eit_t*) data;
1119 __u32 sectionNo = data[0] << 24;
1120 sectionNo |= data[3] << 16;
1121 sectionNo |= data[4] << 8;
1122 sectionNo |= eit->section_number;
1124 tidMap::iterator it =
1125 seenSections.find(sectionNo);
1127 if ( it == seenSections.end() )
1129 seenSections.insert(sectionNo);
1130 calcedSections.insert(sectionNo);
1131 __u32 tmpval = sectionNo & 0xFFFFFF00;
1132 __u8 incr = source == NOWNEXT ? 1 : 8;
1133 for ( int i = 0; i <= eit->last_section_number; i+=incr )
1135 if ( i == eit->section_number )
1137 for (int x=i; x <= eit->segment_last_section_number; ++x)
1138 calcedSections.insert(tmpval|(x&0xFF));
1141 calcedSections.insert(tmpval|(i&0xFF));
1143 cache->sectionRead(data, source, this);
1149 RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, const eventData *&result, int direction)
1150 // if t == -1 we search the current event...
1152 singleLock s(cache_lock);
1153 uniqueEPGKey key(service);
1155 // check if EPG for this service is ready...
1156 eventCache::iterator It = eventDB.find( key );
1157 if ( It != eventDB.end() && !It->second.first.empty() ) // entrys cached ?
1160 t = time(0)+eDVBLocalTimeHandler::getInstance()->difference();
1161 timeMap::iterator i = direction <= 0 ? It->second.second.lower_bound(t) : // find > or equal
1162 It->second.second.upper_bound(t); // just >
1163 if ( i != It->second.second.end() )
1165 if ( direction < 0 || (direction == 0 && i->second->getStartTime() > t) )
1167 timeMap::iterator x = i;
1169 if ( x != It->second.second.end() )
1171 time_t start_time = x->second->getStartTime();
1176 if (t > (start_time+x->second->getDuration()))
1191 RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, const eit_event_struct *&result, int direction)
1193 singleLock s(cache_lock);
1194 const eventData *data=0;
1195 RESULT ret = lookupEventTime(service, t, data, direction);
1197 result = data->get();
1201 RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, Event *& result, int direction)
1203 singleLock s(cache_lock);
1204 const eventData *data=0;
1205 RESULT ret = lookupEventTime(service, t, data, direction);
1207 result = new Event((uint8_t*)data->get());
1211 RESULT eEPGCache::lookupEventTime(const eServiceReference &service, time_t t, ePtr<eServiceEvent> &result, int direction)
1213 singleLock s(cache_lock);
1214 const eventData *data=0;
1215 RESULT ret = lookupEventTime(service, t, data, direction);
1218 Event ev((uint8_t*)data->get());
1219 result = new eServiceEvent();
1220 const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service;
1221 ret = result->parseFrom(&ev, (ref.getTransportStreamID().get()<<16)|ref.getOriginalNetworkID().get());
1226 RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, const eventData *&result )
1228 singleLock s(cache_lock);
1229 uniqueEPGKey key( service );
1231 eventCache::iterator It = eventDB.find( key );
1232 if ( It != eventDB.end() && !It->second.first.empty() ) // entrys cached?
1234 eventMap::iterator i( It->second.first.find( event_id ));
1235 if ( i != It->second.first.end() )
1243 eDebug("event %04x not found in epgcache", event_id);
1249 RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, const eit_event_struct *&result)
1251 singleLock s(cache_lock);
1252 const eventData *data=0;
1253 RESULT ret = lookupEventId(service, event_id, data);
1255 result = data->get();
1259 RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, Event *& result)
1261 singleLock s(cache_lock);
1262 const eventData *data=0;
1263 RESULT ret = lookupEventId(service, event_id, data);
1265 result = new Event((uint8_t*)data->get());
1269 RESULT eEPGCache::lookupEventId(const eServiceReference &service, int event_id, ePtr<eServiceEvent> &result)
1271 singleLock s(cache_lock);
1272 const eventData *data=0;
1273 RESULT ret = lookupEventId(service, event_id, data);
1276 Event ev((uint8_t*)data->get());
1277 result = new eServiceEvent();
1278 const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service;
1279 ret = result->parseFrom(&ev, (ref.getTransportStreamID().get()<<16)|ref.getOriginalNetworkID().get());
1284 RESULT eEPGCache::startTimeQuery(const eServiceReference &service, time_t begin, int minutes)
1286 eventCache::iterator It = eventDB.find( service );
1287 if ( It != eventDB.end() && It->second.second.size() )
1289 m_timemap_end = minutes != -1 ? It->second.second.upper_bound(begin+minutes*60) : It->second.second.end();
1292 m_timemap_cursor = It->second.second.lower_bound(begin);
1293 if ( m_timemap_cursor != It->second.second.end() )
1295 if ( m_timemap_cursor->second->getStartTime() != begin )
1297 timeMap::iterator x = m_timemap_cursor;
1299 if ( x != It->second.second.end() )
1301 time_t start_time = x->second->getStartTime();
1302 if ( begin > start_time && begin < (start_time+x->second->getDuration()))
1303 m_timemap_cursor = x;
1309 m_timemap_cursor = It->second.second.begin();
1310 const eServiceReferenceDVB &ref = (const eServiceReferenceDVB&)service;
1311 currentQueryTsidOnid = (ref.getTransportStreamID().get()<<16) | ref.getOriginalNetworkID().get();
1317 RESULT eEPGCache::getNextTimeEntry(const eventData *& result)
1319 if ( m_timemap_cursor != m_timemap_end )
1321 result = m_timemap_cursor++->second;
1327 RESULT eEPGCache::getNextTimeEntry(const eit_event_struct *&result)
1329 if ( m_timemap_cursor != m_timemap_end )
1331 result = m_timemap_cursor++->second->get();
1337 RESULT eEPGCache::getNextTimeEntry(Event *&result)
1339 if ( m_timemap_cursor != m_timemap_end )
1341 result = new Event((uint8_t*)m_timemap_cursor++->second->get());
1347 RESULT eEPGCache::getNextTimeEntry(ePtr<eServiceEvent> &result)
1349 if ( m_timemap_cursor != m_timemap_end )
1351 Event ev((uint8_t*)m_timemap_cursor++->second->get());
1352 result = new eServiceEvent();
1353 return result->parseFrom(&ev, currentQueryTsidOnid);
1358 void fillTuple(PyObject *tuple, char *argstring, int argcount, PyObject *service, ePtr<eServiceEvent> &ptr, PyObject *nowTime, PyObject *service_name )
1362 while(pos < argcount)
1364 bool inc_refcount=false;
1365 switch(argstring[pos])
1367 case 'I': // Event Id
1368 tmp = ptr ? PyLong_FromLong(ptr->getEventId()) : NULL;
1370 case 'B': // Event Begin Time
1371 tmp = ptr ? PyLong_FromLong(ptr->getBeginTime()) : NULL;
1373 case 'D': // Event Duration
1374 tmp = ptr ? PyLong_FromLong(ptr->getDuration()) : NULL;
1376 case 'T': // Event Title
1377 tmp = ptr ? PyString_FromString(ptr->getEventName().c_str()) : NULL;
1379 case 'S': // Event Short Description
1380 tmp = ptr ? PyString_FromString(ptr->getShortDescription().c_str()) : NULL;
1382 case 'E': // Event Extended Description
1383 tmp = ptr ? PyString_FromString(ptr->getExtendedDescription().c_str()) : NULL;
1385 case 'C': // Current Time
1387 inc_refcount = true;
1389 case 'R': // service reference string
1391 inc_refcount = true;
1393 case 'N': // service name
1395 inc_refcount = true;
1400 inc_refcount = true;
1404 PyTuple_SET_ITEM(tuple, pos++, tmp);
1408 PyObject *handleEvent(ePtr<eServiceEvent> &ptr, PyObject *dest_list, char* argstring, int argcount, PyObject *service, PyObject *nowTime, PyObject *service_name, PyObject *convertFunc, PyObject *convertFuncArgs)
1412 fillTuple(convertFuncArgs, argstring, argcount, service, ptr, nowTime, service_name);
1413 PyObject *result = PyObject_CallObject(convertFunc, convertFuncArgs);
1417 Py_DECREF(service_name);
1420 Py_DECREF(convertFuncArgs);
1421 Py_DECREF(dest_list);
1424 PyList_Append(dest_list, result);
1429 PyObject *tuple = PyTuple_New(argcount);
1430 fillTuple(tuple, argstring, argcount, service, ptr, nowTime, service_name);
1431 PyList_Append(dest_list, tuple);
1437 // here we get a list with tuples
1438 // first tuple entry is the servicereference
1439 // the second is the type of query (0 = time, 1 = event_id)
1441 // when type is eventid it is the event_id
1442 // when type is time then it is the start_time ( 0 for now_time )
1443 // the fourth is the end_time .. ( optional )
1445 /* argv is a python string
1447 B = Event Begin Time
1450 S = Event Short Description
1451 E = Event Extended Description
1453 R = Service Reference
1457 PyObject *eEPGCache::lookupEvent(PyObject *list, PyObject *convertFunc)
1459 PyObject *convertFuncArgs=NULL;
1461 char *argstring=NULL;
1462 if (!PyList_Check(list))
1464 PyErr_SetString(PyExc_StandardError,
1470 int listSize=PyList_Size(list);
1473 PyErr_SetString(PyExc_StandardError,
1474 "not params given");
1475 eDebug("not params given");
1480 PyObject *argv=PyList_GET_ITEM(list, 0); // borrowed reference!
1481 if (PyString_Check(argv))
1483 argstring = PyString_AS_STRING(argv);
1487 argstring = "I"; // just event id as default
1488 argcount = strlen(argstring);
1489 // eDebug("have %d args('%s')", argcount, argstring);
1493 if (!PyCallable_Check(convertFunc))
1495 PyErr_SetString(PyExc_StandardError,
1496 "convertFunc must be callable");
1497 eDebug("convertFunc is not callable");
1500 convertFuncArgs = PyTuple_New(argcount);
1503 PyObject *nowTime = strchr(argstring, 'C') ?
1504 PyLong_FromLong(time(0)+eDVBLocalTimeHandler::getInstance()->difference()) :
1507 bool must_get_service_name = strchr(argstring, 'N') ? true : false;
1510 PyObject *dest_list=PyList_New(0);
1511 while(listSize > listIt)
1513 PyObject *item=PyList_GET_ITEM(list, listIt++); // borrowed reference!
1514 if (PyTuple_Check(item))
1520 int tupleSize=PyTuple_Size(item);
1522 PyObject *service=NULL;
1523 while(tupleSize > tupleIt) // parse query args
1525 PyObject *entry=PyTuple_GET_ITEM(item, tupleIt); // borrowed reference!
1530 if (!PyString_Check(entry))
1532 eDebug("tuple entry 0 is no a string");
1539 type=PyInt_AsLong(entry);
1540 if (type < -1 || type > 2)
1542 eDebug("unknown type %d", type);
1547 event_id=stime=PyInt_AsLong(entry);
1550 minutes=PyInt_AsLong(entry);
1553 eDebug("unneeded extra argument");
1557 eServiceReference ref(PyString_AS_STRING(service));
1558 if (ref.type != eServiceReference::idDVB)
1560 eDebug("service reference for epg query is not valid");
1563 PyObject *service_name=NULL;
1564 if (must_get_service_name)
1566 ePtr<iStaticServiceInformation> sptr;
1567 eServiceCenterPtr service_center;
1568 eServiceCenter::getPrivInstance(service_center);
1571 service_center->info(ref, sptr);
1575 sptr->getName(ref, name);
1577 service_name = PyString_FromString(name.c_str());
1581 service_name = PyString_FromString("<n/a>");
1586 if (!startTimeQuery(ref, stime, minutes))
1588 ePtr<eServiceEvent> ptr;
1589 while (!getNextTimeEntry(ptr))
1591 PyObject *ret = handleEvent(ptr, dest_list, argstring, argcount, service, nowTime, service_name, convertFunc, convertFuncArgs);
1600 ePtr<eServiceEvent> ptr;
1604 lookupEventId(ref, event_id, ptr);
1606 lookupEventTime(ref, stime, ptr, type);
1608 PyObject *ret = handleEvent(ptr, dest_list, argstring, argcount, service, nowTime, service_name, convertFunc, convertFuncArgs);
1613 Py_DECREF(service_name);
1616 if (convertFuncArgs)
1617 Py_DECREF(convertFuncArgs);
1623 #ifdef ENABLE_PRIVATE_EPG
1624 #include <dvbsi++/descriptor_tag.h>
1625 #include <dvbsi++/unknown_descriptor.h>
1626 #include <dvbsi++/private_data_specifier_descriptor.h>
1628 void eEPGCache::PMTready(eDVBServicePMTHandler *pmthandler)
1630 ePtr<eTable<ProgramMapSection> > ptr;
1631 if (!pmthandler->getPMT(ptr) && ptr)
1633 std::vector<ProgramMapSection*>::const_iterator i;
1634 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
1636 const ProgramMapSection &pmt = **i;
1638 ElementaryStreamInfoConstIterator es;
1639 for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
1642 switch ((*es)->getType())
1644 case 0x05: // private
1645 for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin();
1646 desc != (*es)->getDescriptors()->end(); ++desc)
1648 switch ((*desc)->getTag())
1650 case PRIVATE_DATA_SPECIFIER_DESCRIPTOR:
1651 if (((PrivateDataSpecifierDescriptor*)(*desc))->getPrivateDataSpecifier() == 190)
1656 UnknownDescriptor *descr = (UnknownDescriptor*)*desc;
1657 int descr_len = descr->getLength();
1660 uint8_t data[descr_len+2];
1661 descr->writeToBuffer(data);
1662 if ( !data[2] && !data[3] && data[4] == 0xFF && data[5] == 0xFF )
1676 eServiceReferenceDVB ref;
1677 if (!pmthandler->getService(ref))
1679 int pid = (*es)->getPid();
1680 messages.send(Message(Message::got_private_pid, ref, pid));
1688 eDebug("PMTready but no pmt!!");
1695 date_time( const date_time &a )
1697 memcpy(data, a.data, 5);
1700 date_time( const __u8 data[5])
1702 memcpy(this->data, data, 5);
1703 tm = parseDVBtime(data[0], data[1], data[2], data[3], data[4]);
1708 const __u8& operator[](int pos) const
1714 struct less_datetime
1716 bool operator()( const date_time &a, const date_time &b ) const
1718 return abs(a.tm-b.tm) < 360 ? false : a.tm < b.tm;
1722 void eEPGCache::privateSectionRead(const uniqueEPGKey ¤t_service, const __u8 *data)
1724 contentMap &content_time_table = content_time_tables[current_service];
1725 singleLock s(cache_lock);
1726 std::map< date_time, std::list<uniqueEPGKey>, less_datetime > start_times;
1727 eventMap &evMap = eventDB[current_service].first;
1728 timeMap &tmMap = eventDB[current_service].second;
1730 int content_id = data[ptr++] << 24;
1731 content_id |= data[ptr++] << 16;
1732 content_id |= data[ptr++] << 8;
1733 content_id |= data[ptr++];
1735 contentTimeMap &time_event_map =
1736 content_time_table[content_id];
1737 for ( contentTimeMap::iterator it( time_event_map.begin() );
1738 it != time_event_map.end(); ++it )
1740 eventMap::iterator evIt( evMap.find(it->second.second) );
1741 if ( evIt != evMap.end() )
1743 delete evIt->second;
1746 tmMap.erase(it->second.first);
1748 time_event_map.clear();
1751 memcpy(duration, data+ptr, 3);
1754 fromBCD(duration[0])*3600+fromBCD(duration[1])*60+fromBCD(duration[2]);
1756 const __u8 *descriptors[65];
1757 const __u8 **pdescr = descriptors;
1759 int descriptors_length = (data[ptr++]&0x0F) << 8;
1760 descriptors_length |= data[ptr++];
1761 while ( descriptors_length > 0 )
1763 int descr_type = data[ptr];
1764 int descr_len = data[ptr+1];
1765 descriptors_length -= (descr_len+2);
1766 if ( descr_type == 0xf2 )
1769 int tsid = data[ptr++] << 8;
1770 tsid |= data[ptr++];
1771 int onid = data[ptr++] << 8;
1772 onid |= data[ptr++];
1773 int sid = data[ptr++] << 8;
1775 uniqueEPGKey service( sid, onid, tsid );
1777 while( descr_len > 0 )
1780 datetime[0] = data[ptr++];
1781 datetime[1] = data[ptr++];
1782 int tmp_len = data[ptr++];
1784 while( tmp_len > 0 )
1786 memcpy(datetime+2, data+ptr, 3);
1790 start_times[datetime].push_back(service);
1802 eit_event_struct *ev_struct = (eit_event_struct*) event;
1803 ev_struct->running_status = 0;
1804 ev_struct->free_CA_mode = 1;
1805 memcpy(event+7, duration, 3);
1807 const __u8 **d=descriptors;
1808 while ( d < pdescr )
1810 memcpy(event+ptr, *d, ((*d)[1])+2);
1814 for ( std::map< date_time, std::list<uniqueEPGKey> >::iterator it(start_times.begin()); it != start_times.end(); ++it )
1816 time_t now = eDVBLocalTimeHandler::getInstance()->nowTime();
1817 if ( (it->first.tm + duration_sec) < now )
1819 memcpy(event+2, it->first.data, 5);
1822 for (std::list<uniqueEPGKey>::iterator i(it->second.begin()); i != it->second.end(); ++i)
1824 event[bptr++] = 0x4A;
1825 __u8 *len = event+(bptr++);
1826 event[bptr++] = (i->tsid & 0xFF00) >> 8;
1827 event[bptr++] = (i->tsid & 0xFF);
1828 event[bptr++] = (i->onid & 0xFF00) >> 8;
1829 event[bptr++] = (i->onid & 0xFF);
1830 event[bptr++] = (i->sid & 0xFF00) >> 8;
1831 event[bptr++] = (i->sid & 0xFF);
1832 event[bptr++] = 0xB0;
1833 bptr += sprintf((char*)(event+bptr), "Option %d", ++cnt);
1834 *len = ((event+bptr) - len)-1;
1836 int llen = bptr - 12;
1837 ev_struct->descriptors_loop_length_hi = (llen & 0xF00) >> 8;
1838 ev_struct->descriptors_loop_length_lo = (llen & 0xFF);
1840 time_t stime = it->first.tm;
1841 while( tmMap.find(stime) != tmMap.end() )
1843 event[6] += (stime - it->first.tm);
1845 while( evMap.find(event_id) != evMap.end() )
1847 event[0] = (event_id & 0xFF00) >> 8;
1848 event[1] = (event_id & 0xFF);
1849 time_event_map[it->first.tm]=std::pair<time_t, __u16>(stime, event_id);
1850 eventData *d = new eventData( ev_struct, bptr, eEPGCache::SCHEDULE );
1851 evMap[event_id] = d;
1856 void eEPGCache::channel_data::startPrivateReader(int pid, int version)
1858 eDVBSectionFilterMask mask;
1859 memset(&mask, 0, sizeof(mask));
1861 mask.flags = eDVBSectionFilterMask::rfCRC;
1862 mask.data[0] = 0xA0;
1863 mask.mask[0] = 0xFF;
1864 eDebug("start privatefilter for pid %04x and version %d", pid, version);
1867 mask.data[3] = version << 1;
1868 mask.mask[3] = 0x3E;
1869 mask.mode[3] = 0x3E;
1871 seenPrivateSections.clear();
1872 m_PrivateReader->connectRead(slot(*this, &eEPGCache::channel_data::readPrivateData), m_PrivateConn);
1873 m_PrivateReader->start(mask);
1874 #ifdef NEED_DEMUX_WORKAROUND
1875 m_PrevVersion=version;
1879 void eEPGCache::channel_data::readPrivateData( const __u8 *data)
1882 eDebug("get Null pointer from section reader !!");
1885 if ( seenPrivateSections.find( data[6] ) == seenPrivateSections.end() )
1887 #ifdef NEED_DEMUX_WORKAROUND
1888 int version = data[5];
1889 version = ((version & 0x3E) >> 1);
1891 if ( m_PrevVersion != version )
1893 cache->privateSectionRead(m_PrivateService, data);
1894 seenPrivateSections.insert(data[6]);
1900 cache->privateSectionRead(m_PrivateService, data);
1901 seenPrivateSections.insert(data[6]);
1904 if ( seenPrivateSections.size() == (unsigned int)(data[7] + 1) )
1906 eDebug("[EPGC] private finished");
1909 int version = data[5];
1910 version = ((version & 0x3E) >> 1);
1911 startPrivateReader(m_PrivatePid, version);
1916 #endif // ENABLE_PRIVATE_EPG