1 #include <lib/service/event.h>
2 #include <lib/base/estring.h>
3 #include <lib/base/encoding.h>
4 #include <lib/dvb/dvbtime.h>
5 #include <lib/dvb/idvb.h>
6 #include <dvbsi++/event_information_section.h>
7 #include <dvbsi++/short_event_descriptor.h>
8 #include <dvbsi++/extended_event_descriptor.h>
9 #include <dvbsi++/linkage_descriptor.h>
10 #include <dvbsi++/component_descriptor.h>
11 #include <dvbsi++/descriptor_tag.h>
13 #include <sys/types.h>
16 // static members / methods
17 std::string eServiceEvent::m_language = "de_DE";
19 void eServiceEvent::setEPGLanguage( const std::string language )
21 m_language = language;
23 ///////////////////////////
25 DEFINE_REF(eServiceEvent);
26 DEFINE_REF(eComponentData);
28 const char MAX_LANG = 37;
29 /* OSD language (see /share/locales/locales) to iso639 conversion table */
30 std::string ISOtbl[MAX_LANG][2] =
34 {"cs_CZ","ces"}, /* or 'cze' */
37 {"de_DE","deu"}, /* also 'ger' is valid iso639 code!! */
39 {"el_GR","gre"}, /* also 'ell' is valid */
41 {"es_ES","esl"}, /* also 'spa' is ok */
46 {"hr_HR","hrv"}, /* or 'scr' */
49 {"is_IS","isl"}, /* or 'ice' */
53 {"nl_NL","nld"}, /* or 'dut' */
58 {"ro_RO","ron"}, /* or 'rum' */
61 {"sk_SK","slk"}, /* or 'slo' */
64 {"sr_YU","srp"}, /* or 'scc' */
71 /* search for the presence of language from given EIT event descriptors*/
72 bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid)
75 for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
77 switch ((*desc)->getTag())
79 case LINKAGE_DESCRIPTOR:
80 m_linkage_services.clear();
82 case SHORT_EVENT_DESCRIPTOR:
84 const ShortEventDescriptor *sed = (ShortEventDescriptor*)*desc;
85 const std::string &cc = sed->getIso639LanguageCode();
86 int table=encodingHandler.getCountryCodeDefaultMapping(cc);
88 lang = cc; // use first found language
91 m_event_name = convertDVBUTF8(replace_all(replace_all(sed->getEventName(), "\n", " "), "\t", " "), table, tsidonid);
92 m_short_description = convertDVBUTF8(sed->getText(), table, tsidonid);
97 case EXTENDED_EVENT_DESCRIPTOR:
99 const ExtendedEventDescriptor *eed = (ExtendedEventDescriptor*)*desc;
100 const std::string &cc = eed->getIso639LanguageCode();
101 int table=encodingHandler.getCountryCodeDefaultMapping(cc);
103 lang = cc; // use first found language
106 m_extended_description += convertDVBUTF8(eed->getText(), table, tsidonid);
110 const ExtendedEventList *itemlist = eed->getItems();
111 for (ExtendedEventConstIterator it = itemlist->begin(); it != itemlist->end(); ++it)
113 m_extended_description += '\n';
114 m_extended_description += convertDVBUTF8((*it)->getItemDescription());
115 m_extended_description += ' ';
116 m_extended_description += convertDVBUTF8((*it)->getItem());
127 for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
129 switch ((*desc)->getTag())
131 case COMPONENT_DESCRIPTOR:
133 const ComponentDescriptor *cp = (ComponentDescriptor*)*desc;
135 data.m_streamContent = cp->getStreamContent();
136 data.m_componentType = cp->getComponentType();
137 data.m_componentTag = cp->getComponentTag();
138 data.m_iso639LanguageCode = cp->getIso639LanguageCode();
139 int table=encodingHandler.getCountryCodeDefaultMapping(data.m_iso639LanguageCode);
140 data.m_text = convertDVBUTF8(cp->getText(),table,tsidonid);
141 m_component_data.push_back(data);
144 case LINKAGE_DESCRIPTOR:
146 const LinkageDescriptor *ld = (LinkageDescriptor*)*desc;
147 if ( ld->getLinkageType() == 0xB0 )
149 eServiceReference ref;
150 ref.type = eServiceReference::idDVB;
151 eServiceReferenceDVB &dvb_ref = (eServiceReferenceDVB&) ref;
152 dvb_ref.setServiceType(1);
153 dvb_ref.setTransportStreamID(ld->getTransportStreamId());
154 dvb_ref.setOriginalNetworkID(ld->getOriginalNetworkId());
155 dvb_ref.setServiceID(ld->getServiceId());
156 const PrivateDataByteVector *privateData = ld->getPrivateDataBytes();
157 dvb_ref.name = convertDVBUTF8((const unsigned char*)&((*privateData)[0]), privateData->size(), 0, tsidonid);
158 m_linkage_services.push_back(ref);
165 if ( m_extended_description.find(m_short_description) == 0 )
166 m_short_description="";
170 RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid)
172 uint16_t stime_mjd = evt->getStartTimeMjd();
173 uint32_t stime_bcd = evt->getStartTimeBcd();
174 uint32_t duration = evt->getDuration();
175 m_begin = parseDVBtime(
179 (stime_bcd >> 8)&0xFF,
182 m_event_id = evt->getEventId();
183 m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration);
184 for (int i=0; i < MAX_LANG; i++)
185 if (m_language==ISOtbl[i][0])
186 if (loadLanguage(evt, ISOtbl[i][1], tsidonid))
188 if (loadLanguage(evt, "eng", tsidonid))
190 if (loadLanguage(evt, std::string(), tsidonid))
195 RESULT eServiceEvent::parseFrom(const std::string filename, int tsidonid)
197 if (!filename.empty())
199 int fd = ::open( filename.c_str(), O_RDONLY );
203 int rd = ::read(fd, buf, 4096);
205 if ( rd > 12 /*EIT_LOOP_SIZE*/ )
208 parseFrom(&ev, tsidonid);
216 std::string eServiceEvent::getBeginTimeString() const
219 localtime_r(&m_begin, &t);
221 snprintf(tmp, 13, "%02d.%02d, %02d:%02d",
222 t.tm_mday, t.tm_mon+1,
223 t.tm_hour, t.tm_min);
224 return std::string(tmp, 12);
227 RESULT eServiceEvent::getComponentData(ePtr<eComponentData> &dest, int tagnum) const
229 std::list<eComponentData>::const_iterator it =
230 m_component_data.begin();
231 for(;it != m_component_data.end(); ++it)
233 if ( it->m_componentTag == tagnum )
235 dest=new eComponentData(*it);
243 PyObject *eServiceEvent::getComponentData() const
245 ePyObject ret = PyList_New(m_component_data.size());
247 for (std::list<eComponentData>::const_iterator it(m_component_data.begin()); it != m_component_data.end(); ++it)
249 ePyObject tuple = PyTuple_New(5);
250 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(it->m_componentTag));
251 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(it->m_componentType));
252 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(it->m_streamContent));
253 PyTuple_SET_ITEM(tuple, 3, PyString_FromString(it->m_iso639LanguageCode.c_str()));
254 PyTuple_SET_ITEM(tuple, 4, PyString_FromString(it->m_text.c_str()));
255 PyList_SET_ITEM(ret, cnt++, tuple);
260 RESULT eServiceEvent::getLinkageService(eServiceReference &service, eServiceReference &parent, int num) const
262 std::list<eServiceReference>::const_iterator it =
263 m_linkage_services.begin();
264 while( it != m_linkage_services.end() && num-- )
266 if ( it != m_linkage_services.end() )
269 eServiceReferenceDVB &subservice = (eServiceReferenceDVB&) service;
270 eServiceReferenceDVB ¤t = (eServiceReferenceDVB&) parent;
271 subservice.setDVBNamespace(current.getDVBNamespace());
272 if ( current.getParentTransportStreamID().get() )
274 subservice.setParentTransportStreamID( current.getParentTransportStreamID() );
275 subservice.setParentServiceID( current.getParentServiceID() );
279 subservice.setParentTransportStreamID( current.getTransportStreamID() );
280 subservice.setParentServiceID( current.getServiceID() );
282 if ( subservice.getParentTransportStreamID() == subservice.getTransportStreamID() &&
283 subservice.getParentServiceID() == subservice.getServiceID() )
285 subservice.setParentTransportStreamID( eTransportStreamID(0) );
286 subservice.setParentServiceID( eServiceID(0) );
290 service.type = eServiceReference::idInvalid;
294 void setServiceEventLanguage(const std::string language)
296 eServiceEvent::setEPGLanguage(language);
299 DEFINE_REF(eDebugClass);