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.");
29 eDebug("ok ... now we start!!");
30 m_PAT.begin(eApp, eDVBPATSpec(), m_demux);
35 void eDVBServicePMTHandler::PMTready(int error)
38 serviceEvent(eventNoPMT);
40 serviceEvent(eventNewProgramInfo);
43 void eDVBServicePMTHandler::PATready(int)
45 ePtr<eTable<ProgramAssociationTable> > ptr;
46 if (!m_PAT.getCurrent(ptr))
49 ProgramAssociationTableConstIterator i;
50 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
52 const ProgramAssociationTable &pat = **i;
53 ProgramAssociationConstIterator program;
54 for (program = pat.getPrograms()->begin(); program != pat.getPrograms()->end(); ++program)
55 if (eServiceID((*program)->getProgramNumber()) == m_reference.getServiceID())
56 pmtpid = (*program)->getProgramMapPid();
59 serviceEvent(eventNoPATEntry);
61 m_PMT.begin(eApp, eDVBPMTSpec(pmtpid, m_reference.getServiceID().get()), m_demux);
63 serviceEvent(eventNoPAT);
66 int eDVBServicePMTHandler::getProgramInfo(struct program &program)
68 ePtr<eTable<ProgramMapTable> > ptr;
70 program.videoStreams.clear();
71 program.audioStreams.clear();
74 if (!m_PMT.getCurrent(ptr))
76 ProgramMapTableConstIterator i;
77 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
79 const ProgramMapTable &pmt = **i;
80 program.pcrPid = pmt.getPcrPid();
82 ElementaryStreamInfoConstIterator es;
83 for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
85 int isaudio = 0, isvideo = 0;
89 video.pid = (*es)->getPid();
90 audio.pid = (*es)->getPid();
92 switch ((*es)->getType())
94 case 0x01: // MPEG 1 video
95 case 0x02: // MPEG 2 video
98 case 0x03: // MPEG 1 audio
99 case 0x04: // MPEG 2 audio:
101 audio.type = audioStream::atMPEG;
105 program.audioStreams.push_back(audio);
107 program.videoStreams.push_back(video);
115 int eDVBServicePMTHandler::getDemux(ePtr<iDVBDemux> &demux)
124 int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref)
128 m_channelStateChanged_connection = 0;
131 ref.getChannelID(chid);
132 res = m_resourceManager->allocateChannel(chid, m_channel);
133 eDebug("eDVBServicePMTHandler: tune %d", res);
136 m_channel->connectStateChange(
137 slot(*this, &eDVBServicePMTHandler::channelStateChanged),
138 m_channelStateChanged_connection);
139 m_last_channel_state = -1;
140 channelStateChanged(m_channel);