X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/fbc502b7b96b5b2f0f5149a2ec7cfb6355a410ff..7709c1d61e799fa06a257f1d6b9c23ae205fe0c9:/lib/dvb/epgcache.cpp diff --git a/lib/dvb/epgcache.cpp b/lib/dvb/epgcache.cpp index 9abd554e..2b688c29 100644 --- a/lib/dvb/epgcache.cpp +++ b/lib/dvb/epgcache.cpp @@ -232,6 +232,30 @@ eEPGCache::eEPGCache() timeUpdated(); } instance=this; + + memset(m_filename, 0, sizeof(m_filename)); + + FILE *f = fopen("/etc/enigma2/epg.dat.src", "r"); + if (f) + { + int rd = fread(m_filename, 1, 255, f); + if (rd > 0) + { + m_filename[rd] = 0; + char *p=strchr(m_filename, '\n'); + if (p) + m_filename[p-m_filename] = 0; + p=strchr(m_filename, '\t'); + if (p) + m_filename[p-m_filename] = 0; + } + fclose(f); + } + + if (!strlen(m_filename)) + strcpy(m_filename, "/hdd/epg.dat"); + + eDebug("[EPGC] read/write epg data from/to '%s'", m_filename); } void eEPGCache::timeUpdated() @@ -254,6 +278,11 @@ void eEPGCache::DVBChannelAdded(eDVBChannel *chan) data->prevChannelState = -1; #ifdef ENABLE_PRIVATE_EPG data->m_PrivatePid = -1; +#endif +#ifdef ENABLE_MHW_EPG + data->m_mhw2_channel_pid = 0x231; // defaults for astra 19.2 D+ + data->m_mhw2_title_pid = 0x234; // defaults for astra 19.2 D+ + data->m_mhw2_summary_pid = 0x236; // defaults for astra 19.2 D+ #endif singleLock s(channel_map_lock); m_knownChannels.insert( std::pair(chan, data) ); @@ -879,6 +908,62 @@ void eEPGCache::gotMessage( const Message &msg ) } break; } +#endif +#ifdef ENABLE_MHW_EPG + case Message::got_mhw2_channel_pid: + { + singleLock s(channel_map_lock); + for (channelMapIterator it(m_knownChannels.begin()); it != m_knownChannels.end(); ++it) + { + eDVBChannel *channel = (eDVBChannel*) it->first; + channel_data *data = it->second; + eDVBChannelID chid = channel->getChannelID(); + if ( chid.transport_stream_id.get() == msg.service.tsid && + chid.original_network_id.get() == msg.service.onid ) + { + data->m_mhw2_channel_pid = msg.pid; + eDebug("[EPGC] got mhw2 channel pid %04x", msg.pid); + break; + } + } + break; + } + case Message::got_mhw2_title_pid: + { + singleLock s(channel_map_lock); + for (channelMapIterator it(m_knownChannels.begin()); it != m_knownChannels.end(); ++it) + { + eDVBChannel *channel = (eDVBChannel*) it->first; + channel_data *data = it->second; + eDVBChannelID chid = channel->getChannelID(); + if ( chid.transport_stream_id.get() == msg.service.tsid && + chid.original_network_id.get() == msg.service.onid ) + { + data->m_mhw2_title_pid = msg.pid; + eDebug("[EPGC] got mhw2 title pid %04x", msg.pid); + break; + } + } + break; + } + case Message::got_mhw2_summary_pid: + { + singleLock s(channel_map_lock); + for (channelMapIterator it(m_knownChannels.begin()); it != m_knownChannels.end(); ++it) + { + eDVBChannel *channel = (eDVBChannel*) it->first; + channel_data *data = it->second; + eDVBChannelID chid = channel->getChannelID(); + if ( chid.transport_stream_id.get() == msg.service.tsid && + chid.original_network_id.get() == msg.service.onid ) + { + data->m_mhw2_summary_pid = msg.pid; + eDebug("[EPGC] got mhw2 summary pid %04x", msg.pid); + break; + } + } + break; + } #endif case Message::timeChanged: cleanLoop(); @@ -901,30 +986,13 @@ void eEPGCache::thread() void eEPGCache::load() { - FILE *f = fopen("/hdd/epg.dat", "r"); + FILE *f = fopen(m_filename, "r"); if (f) { - unlink("/hdd/epg.dat"); + unlink(m_filename); int size=0; int cnt=0; -#if 0 - unsigned char md5_saved[16]; - unsigned char md5[16]; - bool md5ok=false; - if (!md5_file("/hdd/epg.dat", 1, md5)) - { - FILE *f = fopen("/hdd/epg.dat.md5", "r"); - if (f) - { - fread( md5_saved, 16, 1, f); - fclose(f); - if ( !memcmp(md5_saved, md5, 16) ) - md5ok=true; - } - } - if ( md5ok ) -#endif { unsigned int magic=0; fread( &magic, sizeof(int), 1, f); @@ -966,7 +1034,7 @@ void eEPGCache::load() eventDB[key]=std::pair(evMap,tmMap); } eventData::load(f); - eDebug("[EPGC] %d events read from /hdd/epg.dat", cnt); + eDebug("[EPGC] %d events read from %s", cnt, m_filename); #ifdef ENABLE_PRIVATE_EPG char text2[11]; fread( text2, 11, 1, f); @@ -1014,9 +1082,15 @@ void eEPGCache::load() void eEPGCache::save() { + char *buf = realpath(m_filename, NULL); + if (!buf) + return; + + eDebug("[EPGC] store epg to '%s'", buf); + struct statfs s; off64_t tmp; - if (statfs("/hdd", &s)<0) + if (statfs(buf, &s)<0) tmp=0; else { @@ -1024,6 +1098,8 @@ void eEPGCache::save() tmp*=s.f_bsize; } + free(buf); + // prevent writes to builtin flash if ( tmp < 1024*1024*50 ) // storage size < 50MB return; @@ -1034,7 +1110,7 @@ void eEPGCache::save() if ( tmp < (eventData::CacheSize*12)/10 ) // 20% overhead return; - FILE *f = fopen("/hdd/epg.dat", "w"); + FILE *f = fopen(m_filename, "w"); int cnt=0; if ( f ) { @@ -1059,7 +1135,7 @@ void eEPGCache::save() ++cnt; } } - eDebug("[EPGC] %d events written to /hdd/epg.dat", cnt); + eDebug("[EPGC] %d events written to %s", cnt, m_filename); eventData::save(f); #ifdef ENABLE_PRIVATE_EPG const char* text3 = "PRIVATE_EPG"; @@ -1093,18 +1169,6 @@ void eEPGCache::save() fseek(f, sizeof(int), SEEK_SET); fwrite("ENIGMA_EPG_V7", 13, 1, f); fclose(f); -#if 0 - unsigned char md5[16]; - if (!md5_file("/hdd/epg.dat", 1, md5)) - { - FILE *f = fopen("/hdd/epg.dat.md5", "w"); - if (f) - { - fwrite( md5, 16, 1, f); - fclose(f); - } - } -#endif } } @@ -1175,7 +1239,7 @@ void eEPGCache::channel_data::startEPG() isRunning |= MHW; memcpy(&m_MHWFilterMask, &mask, sizeof(eDVBSectionFilterMask)); - mask.pid = 0x231; + mask.pid = m_mhw2_channel_pid; mask.data[0] = 0xC8; mask.mask[0] = 0xFF; mask.data[1] = 0; @@ -1186,6 +1250,7 @@ void eEPGCache::channel_data::startEPG() memcpy(&m_MHWFilterMask2, &mask, sizeof(eDVBSectionFilterMask)); mask.data[1] = 0; mask.mask[1] = 0; + m_MHWTimeoutet=false; #endif mask.pid = 0x12; @@ -1395,7 +1460,7 @@ void eEPGCache::channel_data::readData( const __u8 *data) } tidMap &seenSections = this->seenSections[map]; tidMap &calcedSections = this->calcedSections[map]; - if ( state == 1 && calcedSections == seenSections || state > 1 ) + if ( (state == 1 && calcedSections == seenSections) || state > 1 ) { eDebugNoNewLine("[EPGC] "); switch (source) @@ -1717,6 +1782,7 @@ void fillTuple(ePyObject tuple, const char *argstring, int argcount, ePyObject s ++argcount; continue; default: // ignore unknown + tmp = ePyObject(); eDebug("fillTuple unknown '%c'... insert 'None' in result", c); } if (!tmp) @@ -2061,6 +2127,7 @@ void fillTuple2(ePyObject tuple, const char *argstring, int argcount, eventData inc_refcount = true; break; default: // ignore unknown + tmp = ePyObject(); eDebug("fillTuple2 unknown '%c'... insert None in Result", argstring[pos]); } if (!tmp) @@ -2487,6 +2554,50 @@ void eEPGCache::PMTready(eDVBServicePMTHandler *pmthandler) int tmp=0; switch ((*es)->getType()) { + case 0xC1: // user private + for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin(); + desc != (*es)->getDescriptors()->end(); ++desc) + { + switch ((*desc)->getTag()) + { + case 0xC2: // user defined + if ((*desc)->getLength() == 8) + { + __u8 buffer[10]; + (*desc)->writeToBuffer(buffer); + if (!strncmp((const char *)buffer+2, "EPGDATA", 7)) + { + eServiceReferenceDVB ref; + if (!pmthandler->getServiceReference(ref)) + { + int pid = (*es)->getPid(); + messages.send(Message(Message::got_mhw2_channel_pid, ref, pid)); + } + } + else if(!strncmp((const char *)buffer+2, "FICHAS", 6)) + { + eServiceReferenceDVB ref; + if (!pmthandler->getServiceReference(ref)) + { + int pid = (*es)->getPid(); + messages.send(Message(Message::got_mhw2_summary_pid, ref, pid)); + } + } + else if(!strncmp((const char *)buffer+2, "GENEROS", 7)) + { + eServiceReferenceDVB ref; + if (!pmthandler->getServiceReference(ref)) + { + int pid = (*es)->getPid(); + messages.send(Message(Message::got_mhw2_title_pid, ref, pid)); + } + } + } + break; + default: + break; + } + } case 0x05: // private for (DescriptorConstIterator desc = (*es)->getDescriptors()->begin(); desc != (*es)->getDescriptors()->end(); ++desc) @@ -2668,7 +2779,7 @@ void eEPGCache::privateSectionRead(const uniqueEPGKey ¤t_service, const __ } } } - ASSERT(pdescr <= &descriptors[65]) + ASSERT(pdescr <= &descriptors[65]); __u8 event[4098]; eit_event_struct *ev_struct = (eit_event_struct*) event; ev_struct->running_status = 0; @@ -2811,6 +2922,7 @@ void eEPGCache::channel_data::timeMHW2DVB( int minutes, u_char *return_time) void eEPGCache::channel_data::timeMHW2DVB( u_char day, u_char hours, u_char minutes, u_char *return_time) // For date plus time of day { + char tz_saved[1024]; // Remove offset in mhw time. __u8 local_hours = hours; if ( hours >= 16 ) @@ -2823,6 +2935,8 @@ void eEPGCache::channel_data::timeMHW2DVB( u_char day, u_char hours, u_char minu time_t dt = ::time(0); char *old_tz = getenv( "TZ" ); + if (old_tz) + strcpy(tz_saved, old_tz); putenv("TZ=CET-1CEST,M3.5.0/2,M10.5.0/3"); tzset(); @@ -2845,7 +2959,7 @@ void eEPGCache::channel_data::timeMHW2DVB( u_char day, u_char hours, u_char minu if ( old_tz == NULL ) unsetenv( "TZ" ); else - putenv( old_tz ); + setenv("TZ", tz_saved, 1); tzset(); // Calculate MJD according to annex in ETSI EN 300 468 @@ -2888,7 +3002,7 @@ void eEPGCache::channel_data::storeTitle(std::map<__u32, mhw_title_t>::iterator packet->segment_last_table_id = 0x50; __u8 *title = isMHW2 ? ((__u8*)(itTitle->second.title))-4 : (__u8*)itTitle->second.title; - std::string prog_title = (char *) delimitName( title, name, isMHW2 ? 33 : 23 ); + std::string prog_title = (char *) delimitName( title, name, isMHW2 ? 35 : 23 ); int prog_title_length = prog_title.length(); int packet_length = EIT_SIZE + EIT_LOOP_SIZE + EIT_SHORT_EVENT_DESCRIPTOR_SIZE + @@ -3217,14 +3331,14 @@ void eEPGCache::channel_data::readMHWData2(const __u8 *data) { eDebug("[EPGC] mhw2 aborted %d", state); } - else if (m_MHWFilterMask2.pid == 0x231 && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 0) + else if (m_MHWFilterMask2.pid == m_mhw2_channel_pid && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 0) // Channels table { - int num_channels = data[119]; + int num_channels = data[120]; m_channels.resize(num_channels); - if(dataLen > 119) + if(dataLen > 120) { - int ptr = 120 + 8 * num_channels; + int ptr = 121 + 8 * num_channels; if( dataLen > ptr ) { for( int chid = 0; chid < num_channels; ++chid ) @@ -3240,7 +3354,7 @@ void eEPGCache::channel_data::readMHWData2(const __u8 *data) else goto abort; // data seems consistent... - const __u8 *tmp = data+120; + const __u8 *tmp = data+121; for (int i=0; i < num_channels; ++i) { mhw_channel_name_t channel; @@ -3251,6 +3365,7 @@ void eEPGCache::channel_data::readMHWData2(const __u8 *data) channel.channel_id_hi = *(tmp++); channel.channel_id_lo = *(tmp++); m_channels[i]=channel; +// eDebug("%d(%02x) %04x: %02x %02x", i, i, (channel.channel_id_hi << 8) | channel.channel_id_lo, *tmp, *(tmp+1)); tmp+=2; } for (int i=0; i < num_channels; ++i) @@ -3261,83 +3376,86 @@ void eEPGCache::channel_data::readMHWData2(const __u8 *data) for (; x < channel_name_len; ++x) channel.name[x]=*(tmp++); channel.name[x+1]=0; +// eDebug("%d(%02x) %s", i, i, channel.name); } haveData |= MHW; eDebug("[EPGC] mhw2 %d channels found", m_channels.size()); } - else if (m_MHWFilterMask2.pid == 0x231 && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 1) + else if (m_MHWFilterMask2.pid == m_mhw2_channel_pid && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 1) { // Themes table eDebug("[EPGC] mhw2 themes nyi"); } - else if (m_MHWFilterMask2.pid == 0x234 && m_MHWFilterMask2.data[0] == 0xe6) + else if (m_MHWFilterMask2.pid == m_mhw2_title_pid && m_MHWFilterMask2.data[0] == 0xe6) // Titles table { int pos=18; - bool valid=true; - int len = ((data[1]&0xf)<<8) + data[2] - 16; + bool valid=false; bool finish=false; - if(data[dataLen-1] != 0xff) - return; - while( pos < dataLen ) + +// eDebug("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", +// data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], +// data[11], data[12], data[13], data[14], data[15], data[16], data[17] ); + + while( pos < dataLen && !valid) { - valid = false; - pos += 7; - if( pos < dataLen ) - { - pos += 3; - if( pos < dataLen ) - { - if( data[pos] > 0xc0 ) - { - pos += ( data[pos] - 0xc0 ); - pos += 4; - if( pos < dataLen ) - { - if( data[pos] == 0xff ) - { - ++pos; - valid = true; - } - } - } - } - } - if( !valid ) - { - if (checkTimeout()) - goto start_summary; - return; - } + pos += 18; + pos += (data[pos] & 0x3F) + 4; + if( pos == dataLen ) + valid = true; + } + + if (!valid) + { + if (dataLen > 18) + eDebug("mhw2 title table invalid!!"); + if (checkTimeout()) + goto abort; + if (!m_MHWTimeoutTimer->isActive()) + startTimeout(5000); + return; // continue reading } + // data seems consistent... mhw_title_t title; pos = 18; - while (pos < len) + while (pos < dataLen) { +// eDebugNoNewLine(" [%02x] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x [%02x %02x %02x %02x %02x %02x %02x] LL - DESCR - ", +// data[pos], data[pos+1], data[pos+2], data[pos+3], data[pos+4], data[pos+5], data[pos+6], data[pos+7], +// data[pos+8], data[pos+9], data[pos+10], data[pos+11], data[pos+12], data[pos+13], data[pos+14], data[pos+15], data[pos+16], data[pos+17]); title.channel_id = data[pos]+1; - title.program_id_ml = data[pos+1]; - title.program_id_lo = data[pos+2]; - title.mhw2_mjd_hi = data[pos+3]; - title.mhw2_mjd_lo = data[pos+4]; - title.mhw2_hours = data[pos+5]; - title.mhw2_minutes = data[pos+6]; - title.mhw2_seconds = data[pos+7]; - int duration = ((data[pos+8] << 8)|data[pos+9]) >> 4; + title.mhw2_mjd_hi = data[pos+11]; + title.mhw2_mjd_lo = data[pos+12]; + title.mhw2_hours = data[pos+13]; + title.mhw2_minutes = data[pos+14]; + title.mhw2_seconds = data[pos+15]; + int duration = ((data[pos+16] << 8)|data[pos+17]) >> 4; title.mhw2_duration_hi = (duration&0xFF00) >> 8; title.mhw2_duration_lo = duration&0xFF; - __u8 slen = data[pos+10] & 0x3f; + + // Create unique key per title + __u32 title_id = (data[pos+7] << 24) | (data[pos+8] << 16) | (data[pos+9] << 8) | data[pos+10]; + + __u8 slen = data[pos+18] & 0x3f; __u8 *dest = ((__u8*)title.title)-4; - memcpy(dest, &data[pos+11], slen>33 ? 33 : slen); - memset(dest+slen, 0, 33-slen); - pos += 11 + slen; + memcpy(dest, &data[pos+19], slen>35 ? 35 : slen); + memset(dest+slen, 0, 35-slen); + pos += 19 + slen; +// eDebug("%02x [%02x %02x]: %s", data[pos], data[pos+1], data[pos+2], dest); + // not used theme id (data[7] & 0x3f) + (data[pos] & 0x3f); __u32 summary_id = (data[pos+1] << 8) | data[pos+2]; - // Create unique key per title - __u32 title_id = (title.channel_id<<16) | (title.program_id_ml<<8) | title.program_id_lo; +// if (title.channel_id > m_channels.size()) +// eDebug("channel_id(%d %02x) to big!!", title.channel_id); - pos += 4; +// eDebug("pos %d prog_id %02x %02x chid %02x summary_id %04x dest %p len %d\n", +// pos, title.program_id_ml, title.program_id_lo, title.channel_id, summary_id, dest, slen); + +// eDebug("title_id %08x -> summary_id %04x\n", title_id, summary_id); + + pos += 3; std::map<__u32, mhw_title_t>::iterator it = m_titles.find( title_id ); if ( it == m_titles.end() ) @@ -3376,7 +3494,7 @@ start_summary: { // Titles table has been read, there are summaries to read. // Start reading summaries, store corresponding titles on the fly. - startMHWReader2(0x236, 0x96); + startMHWReader2(m_mhw2_summary_pid, 0x96); startTimeout(15000); return; } @@ -3384,7 +3502,7 @@ start_summary: else return; } - else if (m_MHWFilterMask2.pid == 0x236 && m_MHWFilterMask2.data[0] == 0x96) + else if (m_MHWFilterMask2.pid == m_mhw2_summary_pid && m_MHWFilterMask2.data[0] == 0x96) // Summaries table { if (!checkTimeout()) @@ -3418,10 +3536,13 @@ start_summary: } else return; // continue reading + if (valid) { // data seems consistent... __u32 summary_id = (data[3]<<8)|data[4]; +// eDebug ("summary id %04x\n", summary_id); +// eDebug("[%02x %02x] %02x %02x %02x %02x %02x %02x %02x %02x XX\n", data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13] ); // ugly workaround to convert const __u8* to char* char *tmp=0; @@ -3439,7 +3560,7 @@ start_summary: len += lenline + 1; } if( len > 0 ) - tmp[pos+len] = 0; + tmp[pos+len] = 0; else tmp[pos+1] = 0; @@ -3455,8 +3576,11 @@ start_summary: startTimeout(15000); std::string the_text = (char *) (data + pos + 1); +// eDebug ("summary id %04x : %s\n", summary_id, data+pos+1); + while( itProgId != m_program_ids.end() && itProgId->first == summary_id ) { +// eDebug("."); // Find corresponding title, store title and summary in epgcache. std::map<__u32, mhw_title_t>::iterator itTitle( m_titles.find( itProgId->second ) ); if ( itTitle != m_titles.end() ) @@ -3476,16 +3600,16 @@ start_summary: } if (isRunning & eEPGCache::MHW) { - if ( m_MHWFilterMask2.pid == 0x231 && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 0) + if ( m_MHWFilterMask2.pid == m_mhw2_channel_pid && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 0) { // Channels table has been read, start reading the themes table. - startMHWReader2(0x231, 0xC8, 1); + startMHWReader2(m_mhw2_channel_pid, 0xC8, 1); return; } - else if ( m_MHWFilterMask2.pid == 0x231 && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 1) + else if ( m_MHWFilterMask2.pid == m_mhw2_channel_pid && m_MHWFilterMask2.data[0] == 0xC8 && m_MHWFilterMask2.data[1] == 1) { // Themes table has been read, start reading the titles table. - startMHWReader2(0x234, 0xe6); + startMHWReader2(m_mhw2_title_pid, 0xe6); return; } else