1 #include <lib/base/eerror.h>
2 #include <lib/dvb/pmt.h>
3 #include <lib/dvb/specs.h>
4 #include <lib/dvb/dvb.h>
6 eDVBServicePMTHandler::eDVBServicePMTHandler()
8 ePtr<eDVBResourceManager> mgr;
9 eDVBResourceManager::getInstance(mgr);
10 m_resourceManager = mgr;
11 CONNECT(m_PMT.tableReady, eDVBServicePMTHandler::PMTready);
12 CONNECT(m_PAT.tableReady, eDVBServicePMTHandler::PATready);
15 void eDVBServicePMTHandler::channelStateChanged(iDVBChannel *channel)
18 channel->getState(state);
20 if ((m_last_channel_state != iDVBChannel::state_ok)
21 && (state == iDVBChannel::state_ok) && (!m_demux))
24 if (m_channel->getDemux(m_demux))
25 eDebug("shit it failed.. again.");
27 serviceEvent(eventTuned);
31 eDebug("ok ... now we start!!");
32 m_PAT.begin(eApp, eDVBPATSpec(), m_demux);
37 void eDVBServicePMTHandler::PMTready(int error)
40 serviceEvent(eventNoPMT);
42 serviceEvent(eventNewProgramInfo);
45 void eDVBServicePMTHandler::PATready(int)
48 ePtr<eTable<ProgramAssociationTable> > ptr;
49 if (!m_PAT.getCurrent(ptr))
52 ProgramAssociationTableConstIterator i;
53 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
55 const ProgramAssociationTable &pat = **i;
56 ProgramAssociationConstIterator program;
57 for (program = pat.getPrograms()->begin(); program != pat.getPrograms()->end(); ++program)
58 if (eServiceID((*program)->getProgramNumber()) == m_reference.getServiceID())
59 pmtpid = (*program)->getProgramMapPid();
62 serviceEvent(eventNoPATEntry);
64 m_PMT.begin(eApp, eDVBPMTSpec(pmtpid, m_reference.getServiceID().get()), m_demux);
66 serviceEvent(eventNoPAT);
69 int eDVBServicePMTHandler::getProgramInfo(struct program &program)
72 ePtr<eTable<ProgramMapTable> > ptr;
74 program.videoStreams.clear();
75 program.audioStreams.clear();
78 if (!m_PMT.getCurrent(ptr))
80 ProgramMapTableConstIterator i;
81 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
83 const ProgramMapTable &pmt = **i;
84 program.pcrPid = pmt.getPcrPid();
86 ElementaryStreamInfoConstIterator es;
87 for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
89 int isaudio = 0, isvideo = 0;
93 video.pid = (*es)->getPid();
94 audio.pid = (*es)->getPid();
96 switch ((*es)->getType())
98 case 0x01: // MPEG 1 video
99 case 0x02: // MPEG 2 video
102 case 0x03: // MPEG 1 audio
103 case 0x04: // MPEG 2 audio:
105 audio.type = audioStream::atMPEG;
109 program.audioStreams.push_back(audio);
111 program.videoStreams.push_back(video);
119 int eDVBServicePMTHandler::getDemux(ePtr<iDVBDemux> &demux)
128 int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref)
132 m_channelStateChanged_connection = 0;
135 ref.getChannelID(chid);
136 res = m_resourceManager->allocateChannel(chid, m_channel);
137 eDebug("eDVBServicePMTHandler: tune %d", res);
140 m_channel->connectStateChange(
141 slot(*this, &eDVBServicePMTHandler::channelStateChanged),
142 m_channelStateChanged_connection);
143 m_last_channel_state = -1;
144 channelStateChanged(m_channel);