1 #include <lib/base/eerror.h>
2 #include <lib/dvb/pmt.h>
3 #include <lib/dvb/specs.h>
4 #include <lib/dvb/dvb.h>
5 #include <lib/dvb/metaparser.h>
7 eDVBServicePMTHandler::eDVBServicePMTHandler()
9 eDVBResourceManager::getInstance(m_resourceManager);
10 CONNECT(m_PMT.tableReady, eDVBServicePMTHandler::PMTready);
11 CONNECT(m_PAT.tableReady, eDVBServicePMTHandler::PATready);
14 void eDVBServicePMTHandler::channelStateChanged(iDVBChannel *channel)
17 channel->getState(state);
19 if ((m_last_channel_state != iDVBChannel::state_ok)
20 && (state == iDVBChannel::state_ok) && (!m_demux))
23 if (m_channel->getDemux(m_demux))
24 eDebug("shit it failed.. again.");
26 serviceEvent(eventTuned);
30 eDebug("ok ... now we start!!");
32 /* emit */ m_resourceManager->m_channelRunning(channel);
34 m_PAT.begin(eApp, eDVBPATSpec(), m_demux);
36 if ( m_service && !m_service->cacheEmpty() )
37 serviceEvent(eventNewProgramInfo);
42 void eDVBServicePMTHandler::PMTready(int error)
45 serviceEvent(eventNoPMT);
47 serviceEvent(eventNewProgramInfo);
50 void eDVBServicePMTHandler::PATready(int)
53 ePtr<eTable<ProgramAssociationTable> > ptr;
54 if (!m_PAT.getCurrent(ptr))
57 ProgramAssociationTableConstIterator i;
58 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
60 const ProgramAssociationTable &pat = **i;
61 ProgramAssociationConstIterator program;
62 for (program = pat.getPrograms()->begin(); program != pat.getPrograms()->end(); ++program)
63 if (eServiceID((*program)->getProgramNumber()) == m_reference.getServiceID())
64 pmtpid = (*program)->getProgramMapPid();
67 serviceEvent(eventNoPATEntry);
69 m_PMT.begin(eApp, eDVBPMTSpec(pmtpid, m_reference.getServiceID().get()), m_demux);
71 serviceEvent(eventNoPAT);
74 int eDVBServicePMTHandler::getProgramInfo(struct program &program)
77 ePtr<eTable<ProgramMapTable> > ptr;
79 program.videoStreams.clear();
80 program.audioStreams.clear();
83 if (!m_PMT.getCurrent(ptr))
85 ProgramMapTableConstIterator i;
86 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
88 const ProgramMapTable &pmt = **i;
89 program.pcrPid = pmt.getPcrPid();
91 ElementaryStreamInfoConstIterator es;
92 for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
94 int isaudio = 0, isvideo = 0;
98 video.pid = (*es)->getPid();
99 audio.pid = (*es)->getPid();
101 switch ((*es)->getType())
103 case 0x01: // MPEG 1 video
104 case 0x02: // MPEG 2 video
107 case 0x03: // MPEG 1 audio
108 case 0x04: // MPEG 2 audio:
110 audio.type = audioStream::atMPEG;
114 program.audioStreams.push_back(audio);
116 program.videoStreams.push_back(video);
121 else if ( m_service && !m_service->cacheEmpty() )
123 int vpid = m_service->getCachePID(eDVBService::cVPID),
124 apid_ac3 = m_service->getCachePID(eDVBService::cAPID),
125 apid_mpeg = m_service->getCachePID(eDVBService::cAC3PID),
126 pcrpid = m_service->getCachePID(eDVBService::cPCRPID),
132 program.videoStreams.push_back(s);
135 if ( apid_ac3 != -1 )
138 s.type = audioStream::atAC3;
140 program.audioStreams.push_back(s);
143 if ( apid_mpeg != -1 )
146 s.type = audioStream::atMPEG;
148 program.audioStreams.push_back(s);
154 program.pcrPid = pcrpid;
162 int eDVBServicePMTHandler::getDemux(ePtr<iDVBDemux> &demux)
171 int eDVBServicePMTHandler::getPVRChannel(ePtr<iDVBPVRChannel> &pvr_channel)
173 pvr_channel = m_pvr_channel;
180 int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref)
185 // ref.path = "/viva.ts"; // hrhr.
187 /* is this a normal (non PVR) channel? */
188 if (ref.path.empty())
191 ref.getChannelID(chid);
192 res = m_resourceManager->allocateChannel(chid, m_channel);
195 eDVBMetaParser parser;
197 if (parser.parseFile(ref.path))
198 eWarning("no .meta file found, trying original service ref.");
200 m_reference = parser.m_ref;
204 res = m_resourceManager->allocatePVRChannel(m_pvr_channel);
206 eDebug("allocatePVRChannel failed!\n");
207 m_channel = m_pvr_channel;
212 m_channel->connectStateChange(
213 slot(*this, &eDVBServicePMTHandler::channelStateChanged),
214 m_channelStateChanged_connection);
215 m_last_channel_state = -1;
216 channelStateChanged(m_channel);
220 m_pvr_channel->playFile(ref.path.c_str());
222 ePtr<iDVBChannelList> db;
223 if (!m_resourceManager->getChannelList(db))
224 db->getService((eServiceReferenceDVB&)m_reference, m_service);