X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/669088fb85f6d0e6c0f7c424df2d1c5dc1141d84..a7db0579fc84bfa07c977638325b54c28d7644ce:/lib/service/event.cpp diff --git a/lib/service/event.cpp b/lib/service/event.cpp index e76ea315..949e150a 100644 --- a/lib/service/event.cpp +++ b/lib/service/event.cpp @@ -2,13 +2,28 @@ #include #include #include +#include #include #include #include #include +#include #include +#include +#include + +// static members / methods +std::string eServiceEvent::m_language = "de_DE"; + +void eServiceEvent::setEPGLanguage( const std::string language ) +{ + m_language = language; +} +/////////////////////////// + DEFINE_REF(eServiceEvent); +DEFINE_REF(eComponentData); const char MAX_LANG = 37; /* OSD language (see /share/locales/locales) to iso639 conversion table */ @@ -69,9 +84,11 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid) const ShortEventDescriptor *sed = (ShortEventDescriptor*)*desc; const std::string &cc = sed->getIso639LanguageCode(); int table=encodingHandler.getCountryCodeDefaultMapping(cc); - if (lang.empty() || cc == lang) + if (lang.empty()) + lang = cc; // use first found language + if (cc == lang) { - m_event_name = convertDVBUTF8(sed->getEventName(), table, tsidonid); + m_event_name = convertDVBUTF8(replace_all(replace_all(sed->getEventName(), "\n", " "), "\t", " "), table, tsidonid); m_short_description = convertDVBUTF8(sed->getText(), table, tsidonid); retval=1; } @@ -82,7 +99,9 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid) const ExtendedEventDescriptor *eed = (ExtendedEventDescriptor*)*desc; const std::string &cc = eed->getIso639LanguageCode(); int table=encodingHandler.getCountryCodeDefaultMapping(cc); - if (lang.empty() || cc == lang) + if (lang.empty()) + lang = cc; // use first found language + if (cc == lang) { m_extended_description += convertDVBUTF8(eed->getText(), table, tsidonid); retval=1; @@ -109,19 +128,34 @@ bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid) { switch ((*desc)->getTag()) { + case COMPONENT_DESCRIPTOR: + { + const ComponentDescriptor *cp = (ComponentDescriptor*)*desc; + eComponentData data; + data.m_streamContent = cp->getStreamContent(); + data.m_componentType = cp->getComponentType(); + data.m_componentTag = cp->getComponentTag(); + data.m_iso639LanguageCode = cp->getIso639LanguageCode(); + int table=encodingHandler.getCountryCodeDefaultMapping(data.m_iso639LanguageCode); + data.m_text = convertDVBUTF8(cp->getText(),table,tsidonid); + m_component_data.push_back(data); + break; + } case LINKAGE_DESCRIPTOR: { const LinkageDescriptor *ld = (LinkageDescriptor*)*desc; if ( ld->getLinkageType() == 0xB0 ) { - linkage_service s; - s.onid = ld->getOriginalNetworkId(); - s.tsid = ld->getTransportStreamId(); - s.sid = ld->getServiceId(); - const PrivateDataByteVector *privateData = - ld->getPrivateDataBytes(); - s.description.assign((const char*)&((*privateData)[0]), privateData->size()); - m_linkage_services.push_back(s); + eServiceReference ref; + ref.type = eServiceReference::idDVB; + eServiceReferenceDVB &dvb_ref = (eServiceReferenceDVB&) ref; + dvb_ref.setServiceType(1); + dvb_ref.setTransportStreamID(ld->getTransportStreamId()); + dvb_ref.setOriginalNetworkID(ld->getOriginalNetworkId()); + dvb_ref.setServiceID(ld->getServiceId()); + const PrivateDataByteVector *privateData = ld->getPrivateDataBytes(); + dvb_ref.name = convertDVBUTF8((const unsigned char*)&((*privateData)[0]), privateData->size(), 1, tsidonid); + m_linkage_services.push_back(ref); } break; } @@ -145,10 +179,10 @@ RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid) (stime_bcd >> 8)&0xFF, stime_bcd & 0xFF ); + m_event_id = evt->getEventId(); m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration); - std::string country="de_DE"; // TODO use local data here for (int i=0; i < MAX_LANG; i++) - if (country==ISOtbl[i][0]) + if (m_language==ISOtbl[i][0]) if (loadLanguage(evt, ISOtbl[i][1], tsidonid)) return 0; if (loadLanguage(evt, "eng", tsidonid)) @@ -158,7 +192,28 @@ RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid) return 0; } -std::string eServiceEvent::getBeginTimeString() +RESULT eServiceEvent::parseFrom(const std::string filename, int tsidonid) +{ + if (!filename.empty()) + { + int fd = ::open( filename.c_str(), O_RDONLY ); + if ( fd > -1 ) + { + __u8 buf[4096]; + int rd = ::read(fd, buf, 4096); + ::close(fd); + if ( rd > 12 /*EIT_LOOP_SIZE*/ ) + { + Event ev(buf); + parseFrom(&ev, tsidonid); + return 0; + } + } + } + return -1; +} + +std::string eServiceEvent::getBeginTimeString() const { tm t; localtime_r(&m_begin, &t); @@ -169,4 +224,76 @@ std::string eServiceEvent::getBeginTimeString() return std::string(tmp, 12); } +RESULT eServiceEvent::getComponentData(ePtr &dest, int tagnum) const +{ + std::list::const_iterator it = + m_component_data.begin(); + for(;it != m_component_data.end(); ++it) + { + if ( it->m_componentTag == tagnum ) + { + dest=new eComponentData(*it); + return 0; + } + } + dest=0; + return -1; +} + +PyObject *eServiceEvent::getComponentData() const +{ + ePyObject ret = PyList_New(m_component_data.size()); + int cnt=0; + for (std::list::const_iterator it(m_component_data.begin()); it != m_component_data.end(); ++it) + { + ePyObject tuple = PyTuple_New(5); + PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(it->m_componentTag)); + PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(it->m_componentType)); + PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(it->m_streamContent)); + PyTuple_SET_ITEM(tuple, 3, PyString_FromString(it->m_iso639LanguageCode.c_str())); + PyTuple_SET_ITEM(tuple, 4, PyString_FromString(it->m_text.c_str())); + PyList_SET_ITEM(ret, cnt++, tuple); + } + return ret; +} + +RESULT eServiceEvent::getLinkageService(eServiceReference &service, eServiceReference &parent, int num) const +{ + std::list::const_iterator it = + m_linkage_services.begin(); + while( it != m_linkage_services.end() && num-- ) + ++it; + if ( it != m_linkage_services.end() ) + { + service = *it; + eServiceReferenceDVB &subservice = (eServiceReferenceDVB&) service; + eServiceReferenceDVB ¤t = (eServiceReferenceDVB&) parent; + subservice.setDVBNamespace(current.getDVBNamespace()); + if ( current.getParentTransportStreamID().get() ) + { + subservice.setParentTransportStreamID( current.getParentTransportStreamID() ); + subservice.setParentServiceID( current.getParentServiceID() ); + } + else + { + subservice.setParentTransportStreamID( current.getTransportStreamID() ); + subservice.setParentServiceID( current.getServiceID() ); + } + if ( subservice.getParentTransportStreamID() == subservice.getTransportStreamID() && + subservice.getParentServiceID() == subservice.getServiceID() ) + { + subservice.setParentTransportStreamID( eTransportStreamID(0) ); + subservice.setParentServiceID( eServiceID(0) ); + } + return 0; + } + service.type = eServiceReference::idInvalid; + return -1; +} + +void setServiceEventLanguage(const std::string language) +{ + eServiceEvent::setEPGLanguage(language); +} + DEFINE_REF(eDebugClass);