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;
34 eDebug("---- opening lame channel db");
35 FILE *f=fopen("lamedb", "rt");
39 if ((!fgets(line, 256, f)) || strncmp(line, "eDVB services", 13))
41 eDebug("not a servicefile");
45 eDebug("reading services");
46 if ((!fgets(line, 256, f)) || strcmp(line, "transponders\n"))
48 eDebug("services invalid, no transponders");
53 // clear all transponders
57 if (!fgets(line, 256, f))
59 if (!strcmp(line, "end\n"))
61 int dvb_namespace=-1, transport_stream_id=-1, original_network_id=-1;
62 sscanf(line, "%x:%x:%x", &dvb_namespace, &transport_stream_id, &original_network_id);
63 if (original_network_id == -1)
65 eDVBChannelID channelid = eDVBChannelID(
66 eDVBNamespace(dvb_namespace),
67 eTransportStreamID(transport_stream_id),
68 eOriginalNetworkID(original_network_id));
70 ePtr<eDVBFrontendParameters> feparm = new eDVBFrontendParameters;
74 if (!strcmp(line, "/\n"))
78 eDVBFrontendParametersSatellite sat;
79 int frequency, symbol_rate, polarisation, fec, orbital_position, inversion;
80 sscanf(line+2, "%d:%d:%d:%d:%d:%d", &frequency, &symbol_rate, &polarisation, &fec, &inversion, &orbital_position);
81 sat.frequency = frequency;
82 sat.symbol_rate = symbol_rate;
83 sat.polarisation = polarisation;
85 sat.orbital_position = orbital_position;
86 sat.inversion = inversion;
88 // t.setSatellite(frequency, symbol_rate, polarisation, fec, sat, inversion);
93 int frequency, symbol_rate, inversion=0, modulation=3;
94 sscanf(line+2, "%d:%d:%d:%d", &frequency, &symbol_rate, &inversion, &modulation);
95 // t.setCable(frequency, symbol_rate, inversion, modulation);
98 addChannelToList(channelid, feparm);
101 if ((!fgets(line, 256, f)) || strcmp(line, "services\n"))
103 eDebug("services invalid, no services");
107 // clear all services
113 if (!fgets(line, 256, f))
115 if (!strcmp(line, "end\n"))
118 int service_id=-1, dvb_namespace, transport_stream_id=-1, original_network_id=-1, service_type=-1, service_number=-1;
119 sscanf(line, "%x:%x:%x:%x:%d:%d", &service_id, &dvb_namespace, &transport_stream_id, &original_network_id, &service_type, &service_number);
120 if (service_number == -1)
122 ePtr<eDVBService> s = new eDVBService;
123 eServiceReferenceDVB ref =
124 eServiceReferenceDVB(
125 eDVBNamespace(dvb_namespace),
126 eTransportStreamID(transport_stream_id),
127 eOriginalNetworkID(original_network_id),
128 eServiceID(service_id),
133 line[strlen(line)-1]=0;
134 s->m_service_name=line;
137 line[strlen(line)-1]=0;
139 std::string str=line;
141 if (str[1]!=':') // old ... (only service_provider)
143 s->m_provider_name=line;
145 while ((!str.empty()) && str[1]==':') // new: p:, f:, c:%02d...
147 unsigned int c=str.find(',');
150 if (c == std::string::npos)
156 v=str.substr(2, c-2);
159 // eDebug("%c ... %s", p, v.c_str());
161 s->m_provider_name=v;
164 sscanf(v.c_str(), "%x", &s->m_flags);
168 sscanf(v.c_str(), "%02d%04x", &cid, &val);
173 sscanf(v.c_str(), "%04x", &val);
180 eDebug("loaded %d services", count);
188 eDebug("---- saving lame channel db");
189 FILE *f=fopen("lamedb", "wt");
190 int channels=0, services=0;
192 eFatal("couldn't save lame channel db!");
193 fprintf(f, "eDVB services /3/\n");
194 fprintf(f, "transponders\n");
195 for (std::map<eDVBChannelID, channel>::const_iterator i(m_channels.begin());
196 i != m_channels.end(); ++i)
198 const eDVBChannelID &chid = i->first;
199 const channel &ch = i->second;
201 fprintf(f, "%08x:%04x:%04x\n", chid.dvbnamespace.get(),
202 chid.transport_stream_id.get(), chid.original_network_id.get());
203 eDVBFrontendParametersSatellite sat;
204 if (!ch.m_frontendParameters->getDVBS(sat))
206 fprintf(f, "\ts %d:%d:%d:%d:%d:%d\n",
207 sat.frequency, sat.symbol_rate,
208 sat.polarisation, sat.fec, sat.inversion,
209 sat.orbital_position);
214 fprintf(f, "end\nservices\n");
216 for (std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator i(m_services.begin());
217 i != m_services.end(); ++i)
219 const eServiceReferenceDVB &s = i->first;
220 fprintf(f, "%04x:%08x:%04x:%04x:%d:%d\n",
221 s.getServiceID().get(), s.getDVBNamespace().get(),
222 s.getTransportStreamID().get(),s.getOriginalNetworkID().get(),
226 fprintf(f, "%s\n", i->second->m_service_name.c_str());
227 fprintf(f, "p:%s", i->second->m_provider_name.c_str());
228 for (std::set<int>::const_iterator ca(i->second->m_ca.begin());
229 ca != i->second->m_ca.end(); ++ca)
230 fprintf(f, ",C:%04x", *ca);
234 fprintf(f, "end\nHave a lot of bugs!\n");
235 eDebug("saved %d channels and %d services!", channels, services);
239 RESULT eDVBDB::addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)
243 ch.m_frontendParameters = feparm;
244 m_channels.insert(std::pair<eDVBChannelID, channel>(id, ch));
248 RESULT eDVBDB::removeChannel(const eDVBChannelID &id)
250 m_channels.erase(id);
254 RESULT eDVBDB::getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)
256 std::map<eDVBChannelID, channel>::iterator i = m_channels.find(id);
257 if (i == m_channels.end())
262 parm = i->second.m_frontendParameters;
266 RESULT eDVBDB::addService(const eServiceReferenceDVB &serviceref, eDVBService *service)
268 m_services.insert(std::pair<eServiceReferenceDVB, ePtr<eDVBService> >(serviceref, service));
272 RESULT eDVBDB::getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)
274 std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator i;
275 i = m_services.find(reference);
276 if (i == m_services.end())