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)
47 ePtr<eTable<ProgramAssociationTable> > ptr;
48 if (!m_PAT.getCurrent(ptr))
51 ProgramAssociationTableConstIterator i;
52 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
54 const ProgramAssociationTable &pat = **i;
55 ProgramAssociationConstIterator program;
56 for (program = pat.getPrograms()->begin(); program != pat.getPrograms()->end(); ++program)
57 if (eServiceID((*program)->getProgramNumber()) == m_reference.getServiceID())
58 pmtpid = (*program)->getProgramMapPid();
61 serviceEvent(eventNoPATEntry);
63 m_PMT.begin(eApp, eDVBPMTSpec(pmtpid, m_reference.getServiceID().get()), m_demux);
65 serviceEvent(eventNoPAT);
68 int eDVBServicePMTHandler::getProgramInfo(struct program &program)
70 ePtr<eTable<ProgramMapTable> > ptr;
72 program.videoStreams.clear();
73 program.audioStreams.clear();
76 if (!m_PMT.getCurrent(ptr))
78 ProgramMapTableConstIterator i;
79 for (i = ptr->getSections().begin(); i != ptr->getSections().end(); ++i)
81 const ProgramMapTable &pmt = **i;
82 program.pcrPid = pmt.getPcrPid();
84 ElementaryStreamInfoConstIterator es;
85 for (es = pmt.getEsInfo()->begin(); es != pmt.getEsInfo()->end(); ++es)
87 int isaudio = 0, isvideo = 0;
91 video.pid = (*es)->getPid();
92 audio.pid = (*es)->getPid();
94 switch ((*es)->getType())
96 case 0x01: // MPEG 1 video
97 case 0x02: // MPEG 2 video
100 case 0x03: // MPEG 1 audio
101 case 0x04: // MPEG 2 audio:
103 audio.type = audioStream::atMPEG;
107 program.audioStreams.push_back(audio);
109 program.videoStreams.push_back(video);
117 int eDVBServicePMTHandler::getDemux(ePtr<iDVBDemux> &demux)
126 int eDVBServicePMTHandler::tune(eServiceReferenceDVB &ref)
130 m_channelStateChanged_connection = 0;
133 ref.getChannelID(chid);
134 res = m_resourceManager->allocateChannel(chid, m_channel);
135 eDebug("eDVBServicePMTHandler: tune %d", res);
138 m_channel->connectStateChange(
139 slot(*this, &eDVBServicePMTHandler::channelStateChanged),
140 m_channelStateChanged_connection);
141 m_last_channel_state = -1;
142 channelStateChanged(m_channel);