show error messages when hdd-init fails
[enigma2.git] / lib / service / event.cpp
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>
10
11 DEFINE_REF(eServiceEvent);
12
13 const char MAX_LANG = 37;
14 /* OSD language (see /share/locales/locales) to iso639 conversion table */
15 std::string ISOtbl[MAX_LANG][2] =
16 {
17         {"ar_AE","ara"},
18         {"C","eng"},
19         {"cs_CZ","ces"},     /* or 'cze' */
20         {"cs_CZ","cze"},
21         {"da_DK","dan"},
22         {"de_DE","deu"},     /* also 'ger' is valid iso639 code!! */
23         {"de_DE","ger"},
24         {"el_GR","gre"},     /* also 'ell' is valid */
25         {"el_GR","ell"},
26         {"es_ES","esl"},     /* also 'spa' is ok */
27         {"es_ES","spa"},
28         {"et_EE","est"},
29         {"fi_FI","fin"},
30         {"fr_FR","fra"},
31         {"hr_HR","hrv"},     /* or 'scr' */
32         {"hr_HR","scr"},
33         {"hu_HU","hun"},
34         {"is_IS","isl"},     /* or 'ice' */
35         {"is_IS","ice"},
36         {"it_IT","ita"},
37         {"lt_LT","lit"},
38         {"nl_NL","nld"},     /* or 'dut' */
39         {"nl_NL","dut"},
40         {"no_NO","nor"},
41         {"pl_PL","pol"},
42         {"pt_PT","por"},
43         {"ro_RO","ron"},     /* or 'rum' */
44         {"ro_RO","rum"},
45         {"ru_RU","rus"},
46         {"sk_SK","slk"},     /* or 'slo' */
47         {"sk_SK","slo"},
48         {"sl_SI","slv"},
49         {"sr_YU","srp"},     /* or 'scc' */
50         {"sr_YU","scc"},
51         {"sv_SE","swe"},
52         {"tr_TR","tur"},
53         {"ur_IN","urd"}
54 };
55
56 /* search for the presence of language from given EIT event descriptors*/
57 bool eServiceEvent::loadLanguage(Event *evt, std::string lang, int tsidonid)
58 {
59         bool retval=0;
60         for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
61         {
62                 switch ((*desc)->getTag())
63                 {
64                         case LINKAGE_DESCRIPTOR:
65                                 m_linkage_services.clear();
66                                 break;
67                         case SHORT_EVENT_DESCRIPTOR:
68                         {
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)
73                                 {
74                                         m_event_name = convertDVBUTF8(sed->getEventName(), table, tsidonid);
75                                         m_short_description = convertDVBUTF8(sed->getText(), table, tsidonid);
76                                         retval=1;
77                                 }
78                                 break;
79                         }
80                         case EXTENDED_EVENT_DESCRIPTOR:
81                         {
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)
86                                 {
87                                         m_extended_description += convertDVBUTF8(eed->getText(), table, tsidonid);
88                                         retval=1;
89                                 }
90 #if 0
91                                 const ExtendedEventList *itemlist = eed->getItems();
92                                 for (ExtendedEventConstIterator it = itemlist->begin(); it != itemlist->end(); ++it)
93                                 {
94                                         m_extended_description += '\n';
95                                         m_extended_description += convertDVBUTF8((*it)->getItemDescription());
96                                         m_extended_description += ' ';
97                                         m_extended_description += convertDVBUTF8((*it)->getItem());
98                                 }
99 #endif
100                                 break;
101                         }
102                         default:
103                                 break;
104                 }
105         }
106         if ( retval == 1 )
107         {
108                 for (DescriptorConstIterator desc = evt->getDescriptors()->begin(); desc != evt->getDescriptors()->end(); ++desc)
109                 {
110                         switch ((*desc)->getTag())
111                         {
112                                 case LINKAGE_DESCRIPTOR:
113                                 {
114                                         const LinkageDescriptor  *ld = (LinkageDescriptor*)*desc;
115                                         if ( ld->getLinkageType() == 0xB0 )
116                                         {
117                                                 linkage_service s;
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);
125                                         }
126                                         break;
127                                 }
128                         }
129                 }
130         }
131         if ( m_extended_description.find(m_short_description) == 0 )
132                 m_short_description="";
133         return retval;
134 }
135
136 RESULT eServiceEvent::parseFrom(Event *evt, int tsidonid)
137 {
138         uint16_t stime_mjd = evt->getStartTimeMjd();
139         uint32_t stime_bcd = evt->getStartTimeBcd();
140         uint32_t duration = evt->getDuration();
141         m_begin = parseDVBtime(
142                 stime_mjd >> 8,
143                 stime_mjd&0xFF,
144                 stime_bcd >> 16,
145                 (stime_bcd >> 8)&0xFF,
146                 stime_bcd & 0xFF
147         );
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))
153                                 return 0;
154         if (loadLanguage(evt, "eng", tsidonid))
155                 return 0;
156         if (loadLanguage(evt, std::string(), tsidonid))
157                 return 0;
158         return 0;
159 }
160
161 std::string eServiceEvent::getBeginTimeString()
162 {
163         tm t;
164         localtime_r(&m_begin, &t);
165         char tmp[13];
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);
170 }
171
172 DEFINE_REF(eDebugClass);