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)
84 ptr = new eDVBServicePlay(ref);
88 RESULT eServiceFactoryDVB::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
90 ptr = new eDVBServiceRecord((eServiceReferenceDVB&)ref);
94 RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
96 ptr = new eDVBServiceList(ref);
100 RESULT eServiceFactoryDVB::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
103 // TODO: handle the listing itself
104 // if (ref.... == -1) .. return "... bouquets ...";
105 // could be also done in another serviceFactory (with seperate ID) to seperate actual services and lists
107 ePtr<iDVBChannelList> db;
108 ePtr<eDVBResourceManager> res;
111 if ((err = eDVBResourceManager::getInstance(res)) != 0)
113 eDebug("no resource manager");
116 if ((err = res->getChannelList(db)) != 0)
118 eDebug("no channel list");
122 ePtr<eDVBService> service;
124 /* we are sure to have a ..DVB reference as the info() call was forwarded here according to it's ID. */
125 if ((err = db->getService((eServiceReferenceDVB&)ref, service)) != 0)
127 eDebug("getService failed!");
131 /* eDVBService has the iStaticServiceInformation interface, so we pass it here. */
136 eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref):
139 CONNECT(m_service_handler.serviceEvent, eDVBServicePlay::serviceEvent);
140 CONNECT(m_event_handler.m_eit_changed, eDVBServicePlay::gotNewEvent);
141 eDebug("DVB start (play)");
144 eDVBServicePlay::~eDVBServicePlay()
146 eDebug("DVB stop (play)");
149 void eDVBServicePlay::gotNewEvent()
153 ePtr<eServiceEvent> m_event_now, m_event_next;
154 getEvent(m_event_now, 0);
155 getEvent(m_event_next, 1);
158 eDebug("now running: %s (%d seconds :)", m_event_now->m_event_name.c_str(), m_event_now->m_duration);
160 eDebug("next running: %s (%d seconds :)", m_event_next->m_event_name.c_str(), m_event_next->m_duration);
162 m_event((iPlayableService*)this, evUpdatedEventInfo);
165 void eDVBServicePlay::serviceEvent(int event)
167 eDebug("service event %d", event);
170 case eDVBServicePMTHandler::eventTuned:
172 ePtr<iDVBDemux> m_demux;
173 if (!m_service_handler.getDemux(m_demux))
175 // eventStartedEventAcquisition
176 m_event_handler.start(m_demux, ((eServiceReferenceDVB&)m_reference).getServiceID().get());
178 eDebug("no event data available :( ");
182 case eDVBServicePMTHandler::eventNewProgramInfo:
184 int vpid = -1, apid = -1, pcrpid = -1;
185 eDVBServicePMTHandler::program program;
186 if (m_service_handler.getProgramInfo(program))
187 eDebug("getting program info failed.");
190 eDebugNoNewLine("have %d video stream(s)", program.videoStreams.size());
191 if (!program.videoStreams.empty())
193 eDebugNoNewLine(" (");
194 for (std::vector<eDVBServicePMTHandler::videoStream>::const_iterator
195 i(program.videoStreams.begin());
196 i != program.videoStreams.end(); ++i)
200 if (i != program.videoStreams.begin())
201 eDebugNoNewLine(", ");
202 eDebugNoNewLine("%04x", i->pid);
204 eDebugNoNewLine(")");
206 eDebugNoNewLine(", and %d audio stream(s)", program.audioStreams.size());
207 if (!program.audioStreams.empty())
209 eDebugNoNewLine(" (");
210 for (std::vector<eDVBServicePMTHandler::audioStream>::const_iterator
211 i(program.audioStreams.begin());
212 i != program.audioStreams.end(); ++i)
216 if (i != program.audioStreams.begin())
217 eDebugNoNewLine(", ");
218 eDebugNoNewLine("%04x", i->pid);
220 eDebugNoNewLine(")");
222 eDebug(", and the pcr pid is %04x", program.pcrPid);
223 if (program.pcrPid != 0x1fff)
224 pcrpid = program.pcrPid;
229 ePtr<iDVBDemux> demux;
230 m_service_handler.getDemux(demux);
232 demux->getMPEGDecoder(m_decoder);
237 m_decoder->setVideoPID(vpid);
238 m_decoder->setAudioPID(apid, 0);
239 m_decoder->setSyncPCR(pcrpid);
248 RESULT eDVBServicePlay::start()
250 eDebug("starting DVB service");
251 return m_service_handler.tune((eServiceReferenceDVB&)m_reference);
254 RESULT eDVBServicePlay::stop()
256 eDebug("stopping..");
260 RESULT eDVBServicePlay::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
262 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
266 RESULT eDVBServicePlay::pause(ePtr<iPauseableService> &ptr)
268 // not yet possible, maybe later...
273 RESULT eDVBServicePlay::info(ePtr<iServiceInformation> &ptr)
279 RESULT eDVBServicePlay::getName(const eServiceReference &ref, std::string &name)
281 name = "DVB service";
285 RESULT eDVBServicePlay::getEvent(ePtr<eServiceEvent> &evt, int nownext)
287 return m_event_handler.getEvent(evt, nownext);
290 DEFINE_REF(eDVBServicePlay)
292 eAutoInitPtr<eServiceFactoryDVB> init_eServiceFactoryDVB(eAutoInitNumbers::service+1, "eServiceFactoryDVB");