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 eDVBServiceList::getNext(eServiceReference &)
87 RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
89 ePtr<eDVBService> service;
90 int r = lookupService(service, ref);
94 ptr = new eDVBServicePlay(ref, service);
98 RESULT eServiceFactoryDVB::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
100 ptr = new eDVBServiceRecord((eServiceReferenceDVB&)ref);
104 RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
106 ptr = new eDVBServiceList(ref);
110 RESULT eServiceFactoryDVB::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
112 ePtr<eDVBService> service;
113 int r = lookupService(service, ref);
116 /* eDVBService has the iStaticServiceInformation interface, so we pass it here. */
121 RESULT eServiceFactoryDVB::lookupService(ePtr<eDVBService> &service, const eServiceReference &ref)
123 // TODO: handle the listing itself
124 // if (ref.... == -1) .. return "... bouquets ...";
125 // could be also done in another serviceFactory (with seperate ID) to seperate actual services and lists
127 ePtr<iDVBChannelList> db;
128 ePtr<eDVBResourceManager> res;
131 if ((err = eDVBResourceManager::getInstance(res)) != 0)
133 eDebug("no resource manager");
136 if ((err = res->getChannelList(db)) != 0)
138 eDebug("no channel list");
142 /* we are sure to have a ..DVB reference as the info() call was forwarded here according to it's ID. */
143 if ((err = db->getService((eServiceReferenceDVB&)ref, service)) != 0)
145 eDebug("getService failed!");
152 eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref, eDVBService *service):
153 m_reference(ref), m_dvb_service(service)
155 CONNECT(m_service_handler.serviceEvent, eDVBServicePlay::serviceEvent);
156 CONNECT(m_event_handler.m_eit_changed, eDVBServicePlay::gotNewEvent);
157 eDebug("DVB start (play)");
160 eDVBServicePlay::~eDVBServicePlay()
162 eDebug("DVB stop (play)");
165 void eDVBServicePlay::gotNewEvent()
169 ePtr<eServiceEvent> m_event_now, m_event_next;
170 getEvent(m_event_now, 0);
171 getEvent(m_event_next, 1);
174 eDebug("now running: %s (%d seconds :)", m_event_now->m_event_name.c_str(), m_event_now->m_duration);
176 eDebug("next running: %s (%d seconds :)", m_event_next->m_event_name.c_str(), m_event_next->m_duration);
178 m_event((iPlayableService*)this, evUpdatedEventInfo);
181 void eDVBServicePlay::serviceEvent(int event)
183 eDebug("service event %d", event);
186 case eDVBServicePMTHandler::eventTuned:
188 ePtr<iDVBDemux> m_demux;
189 if (!m_service_handler.getDemux(m_demux))
191 // eventStartedEventAcquisition
192 m_event_handler.start(m_demux, ((eServiceReferenceDVB&)m_reference).getServiceID().get());
194 eDebug("no event data available :( ");
198 case eDVBServicePMTHandler::eventNewProgramInfo:
200 int vpid = -1, apid = -1, pcrpid = -1;
201 eDVBServicePMTHandler::program program;
202 if (m_service_handler.getProgramInfo(program))
203 eDebug("getting program info failed.");
206 eDebugNoNewLine("have %d video stream(s)", program.videoStreams.size());
207 if (!program.videoStreams.empty())
209 eDebugNoNewLine(" (");
210 for (std::vector<eDVBServicePMTHandler::videoStream>::const_iterator
211 i(program.videoStreams.begin());
212 i != program.videoStreams.end(); ++i)
216 if (i != program.videoStreams.begin())
217 eDebugNoNewLine(", ");
218 eDebugNoNewLine("%04x", i->pid);
220 eDebugNoNewLine(")");
222 eDebugNoNewLine(", and %d audio stream(s)", program.audioStreams.size());
223 if (!program.audioStreams.empty())
225 eDebugNoNewLine(" (");
226 for (std::vector<eDVBServicePMTHandler::audioStream>::const_iterator
227 i(program.audioStreams.begin());
228 i != program.audioStreams.end(); ++i)
232 if (i != program.audioStreams.begin())
233 eDebugNoNewLine(", ");
234 eDebugNoNewLine("%04x", i->pid);
236 eDebugNoNewLine(")");
238 eDebug(", and the pcr pid is %04x", program.pcrPid);
239 if (program.pcrPid != 0x1fff)
240 pcrpid = program.pcrPid;
245 ePtr<iDVBDemux> demux;
246 m_service_handler.getDemux(demux);
248 demux->getMPEGDecoder(m_decoder);
253 m_decoder->setVideoPID(vpid);
254 m_decoder->setAudioPID(apid, 0);
255 m_decoder->setSyncPCR(pcrpid);
264 RESULT eDVBServicePlay::start()
266 eDebug("starting DVB service");
267 m_event(this, evStart);
268 return m_service_handler.tune((eServiceReferenceDVB&)m_reference);
271 RESULT eDVBServicePlay::stop()
273 eDebug("stopping..");
277 RESULT eDVBServicePlay::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
279 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
283 RESULT eDVBServicePlay::pause(ePtr<iPauseableService> &ptr)
285 // not yet possible, maybe later...
290 RESULT eDVBServicePlay::info(ePtr<iServiceInformation> &ptr)
296 RESULT eDVBServicePlay::getName(std::string &name)
299 m_dvb_service->getName(m_reference, name);
301 name = "DVB service";
305 RESULT eDVBServicePlay::getEvent(ePtr<eServiceEvent> &evt, int nownext)
307 return m_event_handler.getEvent(evt, nownext);
310 DEFINE_REF(eDVBServicePlay)
312 eAutoInitPtr<eServiceFactoryDVB> init_eServiceFactoryDVB(eAutoInitNumbers::service+1, "eServiceFactoryDVB");