1 #include <lib/base/eerror.h>
2 #include <lib/base/object.h>
4 #include <lib/service/servicedvb.h>
5 #include <lib/service/service.h>
6 #include <lib/base/init_num.h>
7 #include <lib/base/init.h>
9 #include <lib/dvb/dvb.h>
10 #include <lib/dvb/db.h>
12 #include <lib/service/servicedvbrecord.h>
14 DEFINE_REF(eServiceFactoryDVB)
16 eServiceFactoryDVB::eServiceFactoryDVB()
18 ePtr<eServiceCenter> sc;
20 eServiceCenter::getInstance(sc);
22 sc->addServiceFactory(eServiceFactoryDVB::id, this);
25 eServiceFactoryDVB::~eServiceFactoryDVB()
27 ePtr<eServiceCenter> sc;
29 eServiceCenter::getInstance(sc);
31 sc->removeServiceFactory(eServiceFactoryDVB::id);
34 DEFINE_REF(eDVBServiceList);
36 eDVBServiceList::eDVBServiceList(const eServiceReference &parent): m_parent(parent)
40 eDVBServiceList::~eDVBServiceList()
44 RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list)
46 ePtr<iDVBChannelList> db;
47 ePtr<eDVBResourceManager> res;
50 if ((err = eDVBResourceManager::getInstance(res)) != 0)
52 eDebug("no resource manager");
55 if ((err = res->getChannelList(db)) != 0)
57 eDebug("no channel list");
61 ePtr<iDVBChannelListQuery> query;
63 ePtr<eDVBChannelQuery> q;
65 if (m_parent.path.size())
66 eDVBChannelQuery::compile(q, m_parent.path);
68 if ((err = db->startQuery(query, q)) != 0)
70 eDebug("startQuery failed");
74 eServiceReferenceDVB ref;
76 while (!query->getNextResult(ref))
81 RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
83 ePtr<eDVBService> service;
84 int r = lookupService(service, ref);
88 ptr = new eDVBServicePlay(ref, service);
92 RESULT eServiceFactoryDVB::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
94 ptr = new eDVBServiceRecord((eServiceReferenceDVB&)ref);
98 RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
100 ptr = new eDVBServiceList(ref);
104 RESULT eServiceFactoryDVB::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
106 ePtr<eDVBService> service;
107 int r = lookupService(service, ref);
110 /* eDVBService has the iStaticServiceInformation interface, so we pass it here. */
115 RESULT eServiceFactoryDVB::lookupService(ePtr<eDVBService> &service, const eServiceReference &ref)
117 // TODO: handle the listing itself
118 // if (ref.... == -1) .. return "... bouquets ...";
119 // could be also done in another serviceFactory (with seperate ID) to seperate actual services and lists
121 ePtr<iDVBChannelList> db;
122 ePtr<eDVBResourceManager> res;
125 if ((err = eDVBResourceManager::getInstance(res)) != 0)
127 eDebug("no resource manager");
130 if ((err = res->getChannelList(db)) != 0)
132 eDebug("no channel list");
136 /* we are sure to have a ..DVB reference as the info() call was forwarded here according to it's ID. */
137 if ((err = db->getService((eServiceReferenceDVB&)ref, service)) != 0)
139 eDebug("getService failed!");
146 eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref, eDVBService *service):
147 m_reference(ref), m_dvb_service(service)
149 CONNECT(m_service_handler.serviceEvent, eDVBServicePlay::serviceEvent);
150 CONNECT(m_event_handler.m_eit_changed, eDVBServicePlay::gotNewEvent);
151 eDebug("DVB start (play)");
154 eDVBServicePlay::~eDVBServicePlay()
156 eDebug("DVB stop (play)");
159 void eDVBServicePlay::gotNewEvent()
163 ePtr<eServiceEvent> m_event_now, m_event_next;
164 getEvent(m_event_now, 0);
165 getEvent(m_event_next, 1);
168 eDebug("now running: %s (%d seconds :)", m_event_now->m_event_name.c_str(), m_event_now->m_duration);
170 eDebug("next running: %s (%d seconds :)", m_event_next->m_event_name.c_str(), m_event_next->m_duration);
172 m_event((iPlayableService*)this, evUpdatedEventInfo);
175 void eDVBServicePlay::serviceEvent(int event)
177 eDebug("service event %d", event);
180 case eDVBServicePMTHandler::eventTuned:
182 ePtr<iDVBDemux> m_demux;
183 if (!m_service_handler.getDemux(m_demux))
185 // eventStartedEventAcquisition
186 m_event_handler.start(m_demux, ((eServiceReferenceDVB&)m_reference).getServiceID().get());
188 eDebug("no event data available :( ");
192 case eDVBServicePMTHandler::eventNewProgramInfo:
194 int vpid = -1, apid = -1, pcrpid = -1;
195 eDVBServicePMTHandler::program program;
196 if (m_service_handler.getProgramInfo(program))
197 eDebug("getting program info failed.");
200 eDebugNoNewLine("have %d video stream(s)", program.videoStreams.size());
201 if (!program.videoStreams.empty())
203 eDebugNoNewLine(" (");
204 for (std::vector<eDVBServicePMTHandler::videoStream>::const_iterator
205 i(program.videoStreams.begin());
206 i != program.videoStreams.end(); ++i)
210 if (i != program.videoStreams.begin())
211 eDebugNoNewLine(", ");
212 eDebugNoNewLine("%04x", i->pid);
214 eDebugNoNewLine(")");
216 eDebugNoNewLine(", and %d audio stream(s)", program.audioStreams.size());
217 if (!program.audioStreams.empty())
219 eDebugNoNewLine(" (");
220 for (std::vector<eDVBServicePMTHandler::audioStream>::const_iterator
221 i(program.audioStreams.begin());
222 i != program.audioStreams.end(); ++i)
226 if (i != program.audioStreams.begin())
227 eDebugNoNewLine(", ");
228 eDebugNoNewLine("%04x", i->pid);
230 eDebugNoNewLine(")");
232 eDebug(", and the pcr pid is %04x", program.pcrPid);
233 if (program.pcrPid != 0x1fff)
234 pcrpid = program.pcrPid;
239 ePtr<iDVBDemux> demux;
240 m_service_handler.getDemux(demux);
242 demux->getMPEGDecoder(m_decoder);
247 m_decoder->setVideoPID(vpid);
248 m_decoder->setAudioPID(apid, 0);
249 m_decoder->setSyncPCR(pcrpid);
258 RESULT eDVBServicePlay::start()
260 eDebug("starting DVB service");
261 m_event(this, evStart);
262 return m_service_handler.tune((eServiceReferenceDVB&)m_reference);
265 RESULT eDVBServicePlay::stop()
267 eDebug("stopping..");
271 RESULT eDVBServicePlay::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
273 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
277 RESULT eDVBServicePlay::pause(ePtr<iPauseableService> &ptr)
279 // not yet possible, maybe later...
284 RESULT eDVBServicePlay::info(ePtr<iServiceInformation> &ptr)
290 RESULT eDVBServicePlay::getName(std::string &name)
293 m_dvb_service->getName(m_reference, name);
295 name = "DVB service";
299 RESULT eDVBServicePlay::getEvent(ePtr<eServiceEvent> &evt, int nownext)
301 return m_event_handler.getEvent(evt, nownext);
304 DEFINE_REF(eDVBServicePlay)
306 eAutoInitPtr<eServiceFactoryDVB> init_eServiceFactoryDVB(eAutoInitNumbers::service+1, "eServiceFactoryDVB");