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 DEFINE_REF(eServiceEvent);
14 DEFINE_REF(eComponentData);
16 const char MAX_LANG = 37;
17 /* OSD language (see /share/locales/locales) to iso639 conversion table */
18 std::string ISOtbl[MAX_LANG][2] =
22 {"cs_CZ","ces"}, /* or 'cze' */
25 {"de_DE","deu"}, /* also 'ger' is valid iso639 code!! */
27 {"el_GR","gre"}, /* also 'ell' is valid */
29 {"es_ES","esl"}, /* also 'spa' is ok */
34 {"hr_HR","hrv"}, /* or 'scr' */
37 {"is_IS","isl"}, /* or 'ice' */
41 {"nl_NL","nld"}, /* or 'dut' */
46 {"ro_RO","ron"}, /* or 'rum' */
49 {"sk_SK","slk"}, /* or 'slo' */
52 {"sr_YU","srp"}, /* or 'scc' */
59 /* search for the presence of language from given EIT event descriptors*/
60 bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid)
63 for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
65 switch ((*desc)->getTag())
67 case LINKAGE_DESCRIPTOR:
68 m_linkage_services.clear();
70 case SHORT_EVENT_DESCRIPTOR:
72 const ShortEventDescriptor *sed = (ShortEventDescriptor*)*desc;
73 const std::string &cc = sed->getIso639LanguageCode();
74 int table=encodingHandler.getCountryCodeDefaultMapping(cc);
75 if (lang.empty() || cc == lang)
77 m_event_name = convertDVBUTF8(sed->getEventName(), table, tsidonid);
78 m_short_description = convertDVBUTF8(sed->getText(), table, tsidonid);
83 case EXTENDED_EVENT_DESCRIPTOR:
85 const ExtendedEventDescriptor *eed = (ExtendedEventDescriptor*)*desc;
86 const std::string &cc = eed->getIso639LanguageCode();
87 int table=encodingHandler.getCountryCodeDefaultMapping(cc);
88 if (lang.empty() || cc == lang)
90 m_extended_description += convertDVBUTF8(eed->getText(), table, tsidonid);
94 const ExtendedEventList *itemlist = eed->getItems();
95 for (ExtendedEventConstIterator it = itemlist->begin(); it != itemlist->end(); ++it)
97 m_extended_description += '\n';
98 m_extended_description += convertDVBUTF8((*it)->getItemDescription());
99 m_extended_description += ' ';
100 m_extended_description += convertDVBUTF8((*it)->getItem());
111 for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
113 switch ((*desc)->getTag())
115 case COMPONENT_DESCRIPTOR:
117 const ComponentDescriptor *cp = (ComponentDescriptor*)*desc;
119 data.m_streamContent = cp->getStreamContent();
120 data.m_componentType = cp->getComponentType();
121 data.m_componentTag = cp->getComponentTag();
122 data.m_iso639LanguageCode = cp->getIso639LanguageCode();
123 int table=encodingHandler.getCountryCodeDefaultMapping(data.m_iso639LanguageCode);
124 data.m_text = convertDVBUTF8(cp->getText(),table,tsidonid);
125 m_component_data.push_back(data);
128 case LINKAGE_DESCRIPTOR:
130 const LinkageDescriptor *ld = (LinkageDescriptor*)*desc;
131 if ( ld->getLinkageType() == 0xB0 )
133 eServiceReference ref;
134 ref.type = eServiceReference::idDVB;
135 eServiceReferenceDVB &dvb_ref = (eServiceReferenceDVB&) ref;
136 dvb_ref.setServiceType(1);
137 dvb_ref.setTransportStreamID(ld->getTransportStreamId());
138 dvb_ref.setOriginalNetworkID(ld->getOriginalNetworkId());
139 dvb_ref.setServiceID(ld->getServiceId());
140 const PrivateDataByteVector *privateData = ld->getPrivateDataBytes();
141 dvb_ref.name = convertDVBUTF8((const unsigned char*)&((*privateData)[0]), privateData->size(), 0, tsidonid);
142 m_linkage_services.push_back(ref);
149 if ( m_extended_description.find(m_short_description) == 0 )
150 m_short_description="";
154 RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid)
156 uint16_t stime_mjd = evt->getStartTimeMjd();
157 uint32_t stime_bcd = evt->getStartTimeBcd();
158 uint32_t duration = evt->getDuration();
159 m_begin = parseDVBtime(
163 (stime_bcd >> 8)&0xFF,
166 m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration);
167 std::string country="de_DE"; // TODO use local data here
168 for (int i=0; i < MAX_LANG; i++)
169 if (country==ISOtbl[i][0])
170 if (loadLanguage(evt, ISOtbl[i][1], tsidonid))
172 if (loadLanguage(evt, "eng", tsidonid))
174 if (loadLanguage(evt, std::string(), tsidonid))
179 std::string eServiceEvent::getBeginTimeString() const
182 localtime_r(&m_begin, &t);
184 snprintf(tmp, 13, "%02d.%02d, %02d:%02d",
185 t.tm_mday, t.tm_mon+1,
186 t.tm_hour, t.tm_min);
187 return std::string(tmp, 12);
190 RESULT eServiceEvent::getComponentData(ePtr<eComponentData> &dest, int tagnum) const
192 std::list<eComponentData>::const_iterator it =
193 m_component_data.begin();
194 for(;it != m_component_data.end(); ++it)
196 if ( it->m_componentTag == tagnum )
198 dest=new eComponentData(*it);
206 RESULT eServiceEvent::getLinkageService(eServiceReference &service, int num) const
208 std::list<eServiceReference>::const_iterator it =
209 m_linkage_services.begin();
210 while( it != m_linkage_services.end() && num-- )
212 if ( it != m_linkage_services.end() )
217 service.type = eServiceReference::idInvalid;
221 DEFINE_REF(eDebugClass);