2 #include <lib/dvb/db.h>
3 #include <lib/dvb/frontend.h>
4 #include <lib/base/eerror.h>
5 #include <lib/dvb_si/sdt.h>
6 #include <lib/dvb_si/descriptor_tag.h>
7 #include <lib/dvb_si/service_descriptor.h>
8 #include <lib/dvb_si/satellite_delivery_system_descriptor.h>
10 DEFINE_REF(eDVBService);
12 eDVBService::eDVBService()
16 eDVBService::~eDVBService()
20 eDVBService &eDVBService::operator=(const eDVBService &s)
22 m_service_name = s.m_service_name;
23 m_provider_name = s.m_provider_name;
30 RESULT eDVBService::getName(const eServiceReference &ref, std::string &name)
32 name = m_service_name;
35 int eDVBService::checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query)
40 case eDVBChannelQuery::tName:
41 res = m_service_name.find(query.m_string) != std::string::npos;
43 case eDVBChannelQuery::tProvider:
44 res = m_provider_name.find(query.m_string) != std::string::npos;
46 case eDVBChannelQuery::tType:
47 res = ref.getServiceType() == query.m_int;
49 case eDVBChannelQuery::tBouquet:
52 case eDVBChannelQuery::tSatellitePosition:
53 res = (ref.getDVBNamespace().get() >> 16) == query.m_int;
55 case eDVBChannelQuery::tChannelID:
58 ref.getChannelID(chid);
59 res = chid == query.m_channelid;
62 case eDVBChannelQuery::tAND:
63 res = checkFilter(ref, *query.m_p1) && checkFilter(ref, *query.m_p2);
65 case eDVBChannelQuery::tOR:
66 res = checkFilter(ref, *query.m_p1) || checkFilter(ref, *query.m_p2);
80 eDebug("---- opening lame channel db");
81 FILE *f=fopen("lamedb", "rt");
85 if ((!fgets(line, 256, f)) || strncmp(line, "eDVB services", 13))
87 eDebug("not a servicefile");
91 eDebug("reading services");
92 if ((!fgets(line, 256, f)) || strcmp(line, "transponders\n"))
94 eDebug("services invalid, no transponders");
99 // clear all transponders
103 if (!fgets(line, 256, f))
105 if (!strcmp(line, "end\n"))
107 int dvb_namespace=-1, transport_stream_id=-1, original_network_id=-1;
108 sscanf(line, "%x:%x:%x", &dvb_namespace, &transport_stream_id, &original_network_id);
109 if (original_network_id == -1)
111 eDVBChannelID channelid = eDVBChannelID(
112 eDVBNamespace(dvb_namespace),
113 eTransportStreamID(transport_stream_id),
114 eOriginalNetworkID(original_network_id));
116 ePtr<eDVBFrontendParameters> feparm = new eDVBFrontendParameters;
120 if (!strcmp(line, "/\n"))
124 eDVBFrontendParametersSatellite sat;
125 int frequency, symbol_rate, polarisation, fec, orbital_position, inversion;
126 sscanf(line+2, "%d:%d:%d:%d:%d:%d", &frequency, &symbol_rate, &polarisation, &fec, &inversion, &orbital_position);
127 sat.frequency = frequency;
128 sat.symbol_rate = symbol_rate;
129 sat.polarisation = polarisation;
131 sat.orbital_position = orbital_position;
132 sat.inversion = inversion;
134 // t.setSatellite(frequency, symbol_rate, polarisation, fec, sat, inversion);
135 feparm->setDVBS(sat);
139 int frequency, symbol_rate, inversion=0, modulation=3;
140 sscanf(line+2, "%d:%d:%d:%d", &frequency, &symbol_rate, &inversion, &modulation);
141 // t.setCable(frequency, symbol_rate, inversion, modulation);
144 addChannelToList(channelid, feparm);
147 if ((!fgets(line, 256, f)) || strcmp(line, "services\n"))
149 eDebug("services invalid, no services");
153 // clear all services
159 if (!fgets(line, 256, f))
161 if (!strcmp(line, "end\n"))
164 int service_id=-1, dvb_namespace, transport_stream_id=-1, original_network_id=-1, service_type=-1, service_number=-1;
165 sscanf(line, "%x:%x:%x:%x:%d:%d", &service_id, &dvb_namespace, &transport_stream_id, &original_network_id, &service_type, &service_number);
166 if (service_number == -1)
168 ePtr<eDVBService> s = new eDVBService;
169 eServiceReferenceDVB ref =
170 eServiceReferenceDVB(
171 eDVBNamespace(dvb_namespace),
172 eTransportStreamID(transport_stream_id),
173 eOriginalNetworkID(original_network_id),
174 eServiceID(service_id),
179 line[strlen(line)-1]=0;
180 s->m_service_name=line;
183 line[strlen(line)-1]=0;
185 std::string str=line;
187 if (str[1]!=':') // old ... (only service_provider)
189 s->m_provider_name=line;
191 while ((!str.empty()) && str[1]==':') // new: p:, f:, c:%02d...
193 unsigned int c=str.find(',');
196 if (c == std::string::npos)
202 v=str.substr(2, c-2);
205 // eDebug("%c ... %s", p, v.c_str());
207 s->m_provider_name=v;
210 sscanf(v.c_str(), "%x", &s->m_flags);
214 sscanf(v.c_str(), "%02d%04x", &cid, &val);
219 sscanf(v.c_str(), "%04x", &val);
226 eDebug("loaded %d services", count);
234 eDebug("---- saving lame channel db");
235 FILE *f=fopen("lamedb", "wt");
236 int channels=0, services=0;
238 eFatal("couldn't save lame channel db!");
239 fprintf(f, "eDVB services /3/\n");
240 fprintf(f, "transponders\n");
241 for (std::map<eDVBChannelID, channel>::const_iterator i(m_channels.begin());
242 i != m_channels.end(); ++i)
244 const eDVBChannelID &chid = i->first;
245 const channel &ch = i->second;
247 fprintf(f, "%08x:%04x:%04x\n", chid.dvbnamespace.get(),
248 chid.transport_stream_id.get(), chid.original_network_id.get());
249 eDVBFrontendParametersSatellite sat;
250 if (!ch.m_frontendParameters->getDVBS(sat))
252 fprintf(f, "\ts %d:%d:%d:%d:%d:%d\n",
253 sat.frequency, sat.symbol_rate,
254 sat.polarisation, sat.fec, sat.inversion,
255 sat.orbital_position);
260 fprintf(f, "end\nservices\n");
262 for (std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator i(m_services.begin());
263 i != m_services.end(); ++i)
265 const eServiceReferenceDVB &s = i->first;
266 fprintf(f, "%04x:%08x:%04x:%04x:%d:%d\n",
267 s.getServiceID().get(), s.getDVBNamespace().get(),
268 s.getTransportStreamID().get(),s.getOriginalNetworkID().get(),
272 fprintf(f, "%s\n", i->second->m_service_name.c_str());
273 fprintf(f, "p:%s", i->second->m_provider_name.c_str());
274 for (std::set<int>::const_iterator ca(i->second->m_ca.begin());
275 ca != i->second->m_ca.end(); ++ca)
276 fprintf(f, ",C:%04x", *ca);
280 fprintf(f, "end\nHave a lot of bugs!\n");
281 eDebug("saved %d channels and %d services!", channels, services);
285 RESULT eDVBDB::addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)
289 ch.m_frontendParameters = feparm;
290 m_channels.insert(std::pair<eDVBChannelID, channel>(id, ch));
294 RESULT eDVBDB::removeChannel(const eDVBChannelID &id)
296 m_channels.erase(id);
300 RESULT eDVBDB::getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)
302 std::map<eDVBChannelID, channel>::iterator i = m_channels.find(id);
303 if (i == m_channels.end())
308 parm = i->second.m_frontendParameters;
312 RESULT eDVBDB::addService(const eServiceReferenceDVB &serviceref, eDVBService *service)
314 m_services.insert(std::pair<eServiceReferenceDVB, ePtr<eDVBService> >(serviceref, service));
318 RESULT eDVBDB::getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)
320 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator i;
321 i = m_services.find(reference);
322 if (i == m_services.end())
331 RESULT eDVBDB::startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *q)
333 query = new eDVBDBQuery(this, q);
337 DEFINE_REF(eDVBDBQuery);
339 eDVBDBQuery::eDVBDBQuery(eDVBDB *db, eDVBChannelQuery *query): m_db(db), m_query(query)
341 m_cursor = m_db->m_services.begin();
344 RESULT eDVBDBQuery::getNextResult(eServiceReferenceDVB &ref)
346 while (m_cursor != m_db->m_services.end())
348 ref = m_cursor->first;
350 int res = (!m_query) || m_cursor->second->checkFilter(ref, *m_query);
360 RESULT eDVBChannelQuery::compile(ePtr<eDVBChannelQuery> &res, std::string query)
362 res = new eDVBChannelQuery();
363 res->m_type = eDVBChannelQuery::tName;
365 res->m_string = query;
369 DEFINE_REF(eDVBChannelQuery);