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);
87 if (lang.empty() || cc == lang)
89 m_event_name = convertDVBUTF8(sed->getEventName(), table, tsidonid);
90 m_short_description = convertDVBUTF8(sed->getText(), table, tsidonid);
95 case EXTENDED_EVENT_DESCRIPTOR:
97 const ExtendedEventDescriptor *eed = (ExtendedEventDescriptor*)*desc;
98 const std::string &cc = eed->getIso639LanguageCode();
99 int table=encodingHandler.getCountryCodeDefaultMapping(cc);
100 if (lang.empty() || cc == lang)
102 m_extended_description += convertDVBUTF8(eed->getText(), table, tsidonid);
106 const ExtendedEventList *itemlist = eed->getItems();
107 for (ExtendedEventConstIterator it = itemlist->begin(); it != itemlist->end(); ++it)
109 m_extended_description += '\n';
110 m_extended_description += convertDVBUTF8((*it)->getItemDescription());
111 m_extended_description += ' ';
112 m_extended_description += convertDVBUTF8((*it)->getItem());
123 for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
125 switch ((*desc)->getTag())
127 case COMPONENT_DESCRIPTOR:
129 const ComponentDescriptor *cp = (ComponentDescriptor*)*desc;
131 data.m_streamContent = cp->getStreamContent();
132 data.m_componentType = cp->getComponentType();
133 data.m_componentTag = cp->getComponentTag();
134 data.m_iso639LanguageCode = cp->getIso639LanguageCode();
135 int table=encodingHandler.getCountryCodeDefaultMapping(data.m_iso639LanguageCode);
136 data.m_text = convertDVBUTF8(cp->getText(),table,tsidonid);
137 m_component_data.push_back(data);
140 case LINKAGE_DESCRIPTOR:
142 const LinkageDescriptor *ld = (LinkageDescriptor*)*desc;
143 if ( ld->getLinkageType() == 0xB0 )
145 eServiceReference ref;
146 ref.type = eServiceReference::idDVB;
147 eServiceReferenceDVB &dvb_ref = (eServiceReferenceDVB&) ref;
148 dvb_ref.setServiceType(1);
149 dvb_ref.setTransportStreamID(ld->getTransportStreamId());
150 dvb_ref.setOriginalNetworkID(ld->getOriginalNetworkId());
151 dvb_ref.setServiceID(ld->getServiceId());
152 const PrivateDataByteVector *privateData = ld->getPrivateDataBytes();
153 dvb_ref.name = convertDVBUTF8((const unsigned char*)&((*privateData)[0]), privateData->size(), 0, tsidonid);
154 m_linkage_services.push_back(ref);
161 if ( m_extended_description.find(m_short_description) == 0 )
162 m_short_description="";
166 RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid)
168 uint16_t stime_mjd = evt->getStartTimeMjd();
169 uint32_t stime_bcd = evt->getStartTimeBcd();
170 uint32_t duration = evt->getDuration();
171 m_begin = parseDVBtime(
175 (stime_bcd >> 8)&0xFF,
178 m_event_id = evt->getEventId();
179 m_duration = fromBCD(duration>>16)*3600+fromBCD(duration>>8)*60+fromBCD(duration);
180 for (int i=0; i < MAX_LANG; i++)
181 if (m_language==ISOtbl[i][0])
182 if (loadLanguage(evt, ISOtbl[i][1], tsidonid))
184 if (loadLanguage(evt, "eng", tsidonid))
186 if (loadLanguage(evt, std::string(), tsidonid))
191 RESULT eServiceEvent::parseFrom(const std::string filename, int tsidonid)
193 if (!filename.empty())
195 int fd = ::open( filename.c_str(), O_RDONLY );
199 int rd = ::read(fd, buf, 4096);
201 if ( rd > 12 /*EIT_LOOP_SIZE*/ )
204 parseFrom(&ev, tsidonid);
212 std::string eServiceEvent::getBeginTimeString() const
215 localtime_r(&m_begin, &t);
217 snprintf(tmp, 13, "%02d.%02d, %02d:%02d",
218 t.tm_mday, t.tm_mon+1,
219 t.tm_hour, t.tm_min);
220 return std::string(tmp, 12);
223 RESULT eServiceEvent::getComponentData(ePtr<eComponentData> &dest, int tagnum) const
225 std::list<eComponentData>::const_iterator it =
226 m_component_data.begin();
227 for(;it != m_component_data.end(); ++it)
229 if ( it->m_componentTag == tagnum )
231 dest=new eComponentData(*it);
239 RESULT eServiceEvent::getLinkageService(eServiceReference &service, eServiceReference &parent, int num) const
241 std::list<eServiceReference>::const_iterator it =
242 m_linkage_services.begin();
243 while( it != m_linkage_services.end() && num-- )
245 if ( it != m_linkage_services.end() )
248 eServiceReferenceDVB &subservice = (eServiceReferenceDVB&) service;
249 eServiceReferenceDVB ¤t = (eServiceReferenceDVB&) parent;
250 subservice.setDVBNamespace(current.getDVBNamespace());
251 if ( current.getParentTransportStreamID().get() )
253 subservice.setParentTransportStreamID( current.getParentTransportStreamID() );
254 subservice.setParentServiceID( current.getParentServiceID() );
258 subservice.setParentTransportStreamID( current.getTransportStreamID() );
259 subservice.setParentServiceID( current.getServiceID() );
261 if ( subservice.getParentTransportStreamID() == subservice.getTransportStreamID() &&
262 subservice.getParentServiceID() == subservice.getServiceID() )
264 subservice.setParentTransportStreamID( eTransportStreamID(0) );
265 subservice.setParentServiceID( eServiceID(0) );
269 service.type = eServiceReference::idInvalid;
273 DEFINE_REF(eDebugClass);