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 <dvbsi++/event_information_section.h>
6 #include <dvbsi++/short_event_descriptor.h>
7 #include <dvbsi++/extended_event_descriptor.h>
8 #include <dvbsi++/linkage_descriptor.h>
9 #include <dvbsi++/descriptor_tag.h>
11 DEFINE_REF(eServiceEvent);
13 const char MAX_LANG = 37;
14 /* OSD language (see /share/locales/locales) to iso639 conversion table */
15 std::string ISOtbl[MAX_LANG][2] =
19 {"cs_CZ","ces"}, /* or 'cze' */
22 {"de_DE","deu"}, /* also 'ger' is valid iso639 code!! */
24 {"el_GR","gre"}, /* also 'ell' is valid */
26 {"es_ES","esl"}, /* also 'spa' is ok */
31 {"hr_HR","hrv"}, /* or 'scr' */
34 {"is_IS","isl"}, /* or 'ice' */
38 {"nl_NL","nld"}, /* or 'dut' */
43 {"ro_RO","ron"}, /* or 'rum' */
46 {"sk_SK","slk"}, /* or 'slo' */
49 {"sr_YU","srp"}, /* or 'scc' */
56 /* search for the presence of language from given EIT event descriptors*/
57 bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid)
60 for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
62 switch ((*desc)->getTag())
64 case LINKAGE_DESCRIPTOR:
65 m_linkage_services.clear();
67 case SHORT_EVENT_DESCRIPTOR:
69 const ShortEventDescriptor *sed = (ShortEventDescriptor*)*desc;
70 const std::string &cc = sed->getIso639LanguageCode();
71 int table=encodingHandler.getCountryCodeDefaultMapping(cc);
72 if (lang.empty() || cc == lang)
74 m_event_name = convertDVBUTF8(sed->getEventName(), table, tsidonid);
75 m_short_description = convertDVBUTF8(sed->getText(), table, tsidonid);
80 case EXTENDED_EVENT_DESCRIPTOR:
82 const ExtendedEventDescriptor *eed = (ExtendedEventDescriptor*)*desc;
83 const std::string &cc = eed->getIso639LanguageCode();
84 int table=encodingHandler.getCountryCodeDefaultMapping(cc);
85 if (lang.empty() || cc == lang)
87 m_extended_description += convertDVBUTF8(eed->getText(), table, tsidonid);
91 const ExtendedEventList *itemlist = eed->getItems();
92 for (ExtendedEventConstIterator it = itemlist->begin(); it != itemlist->end(); ++it)
94 m_extended_description += '\n';
95 m_extended_description += convertDVBUTF8((*it)->getItemDescription());
96 m_extended_description += ' ';
97 m_extended_description += convertDVBUTF8((*it)->getItem());
108 for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
110 switch ((*desc)->getTag())
112 case LINKAGE_DESCRIPTOR:
114 const LinkageDescriptor *ld = (LinkageDescriptor*)*desc;
115 if ( ld->getLinkageType() == 0xB0 )
118 s.onid = ld->getOriginalNetworkId();
119 s.tsid = ld->getTransportStreamId();
120 s.sid = ld->getServiceId();
121 const PrivateDataByteVector *privateData =
122 ld->getPrivateDataBytes();
123 s.description.assign((const char*)&((*privateData)[0]), privateData->size());
124 m_linkage_services.push_back(s);
131 if ( m_extended_description.find(m_short_description) == 0 )
132 m_short_description="";
136 RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid)
138 uint16_t stime_mjd = evt->getStartTimeMjd();
139 uint32_t stime_bcd = evt->getStartTimeBcd();
140 uint32_t duration = evt->getDuration();
141 m_begin = parseDVBtime(
145 (stime_bcd >> 8)&0xFF,
148 m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration);
149 std::string country="de_DE"; // TODO use local data here
150 for (int i=0; i < MAX_LANG; i++)
151 if (country==ISOtbl[i][0])
152 if (loadLanguage(evt, ISOtbl[i][1], tsidonid))
154 if (loadLanguage(evt, "eng", tsidonid))
156 if (loadLanguage(evt, std::string(), tsidonid))
161 std::string eServiceEvent::getBeginTimeString()
164 localtime_r(&m_begin, &t);
166 snprintf(tmp, 13, "%02d.%02d, %02d:%02d",
167 t.tm_mday, t.tm_mon+1,
168 t.tm_hour, t.tm_min);
169 return std::string(tmp, 12);
172 DEFINE_REF(eDebugClass);