fixed refcount of eListboxPythonStringContent
[enigma2.git] / lib / service / servicedvb.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/base/object.h>
3 #include <string>
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>
8
9 DEFINE_REF(eServiceFactoryDVB)
10
11 eServiceFactoryDVB::eServiceFactoryDVB()
12 {
13         ePtr<eServiceCenter> sc;
14         
15         eServiceCenter::getInstance(sc);
16         if (sc)
17                 sc->addServiceFactory(eServiceFactoryDVB::id, this);
18 }
19
20 eServiceFactoryDVB::~eServiceFactoryDVB()
21 {
22         ePtr<eServiceCenter> sc;
23         
24         eServiceCenter::getInstance(sc);
25         if (sc)
26                 sc->removeServiceFactory(eServiceFactoryDVB::id);
27 }
28
29 RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
30 {
31                 // check resources...
32         ptr = new eDVBServicePlay(ref);
33         return 0;
34 }
35
36 RESULT eServiceFactoryDVB::record(const eServiceReference &, ePtr<iRecordableService> &ptr)
37 {
38         ptr = 0;
39         return -1;
40 }
41
42 RESULT eServiceFactoryDVB::list(const eServiceReference &, ePtr<iListableService> &ptr)
43 {
44         ptr = 0;
45         return -1;
46 }
47
48 eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref): 
49         m_reference(ref)
50 {
51         CONNECT(m_serviceHandler.serviceEvent, eDVBServicePlay::serviceEvent);
52         eDebug("DVB start (play)");
53 }
54
55 eDVBServicePlay::~eDVBServicePlay()
56 {
57         eDebug("DVB stop (play)");
58 }
59
60 void eDVBServicePlay::serviceEvent(int event)
61 {
62         eDebug("service event %d", event);
63         switch (event)
64         {
65         case eDVBServicePMTHandler::eventNewProgramInfo:
66         {
67                 int vpid = -1, apid = -1, pcrpid = -1;
68                 eDVBServicePMTHandler::program program;
69                 if (m_serviceHandler.getProgramInfo(program))
70                         eDebug("getting program info failed.");
71                 else
72                 {
73                         eDebugNoNewLine("have %d video stream(s)", program.videoStreams.size());
74                         if (!program.videoStreams.empty())
75                         {
76                                 eDebugNoNewLine(" (");
77                                 for (std::vector<eDVBServicePMTHandler::videoStream>::const_iterator
78                                         i(program.videoStreams.begin()); 
79                                         i != program.videoStreams.end(); ++i)
80                                 {
81                                         if (vpid == -1)
82                                                 vpid = i->pid;
83                                         if (i != program.videoStreams.begin())
84                                                 eDebugNoNewLine(", ");
85                                         eDebugNoNewLine("%04x", i->pid);
86                                 }
87                                 eDebugNoNewLine(")");
88                         }
89                         eDebugNoNewLine(", and %d audio stream(s)", program.audioStreams.size());
90                         if (!program.audioStreams.empty())
91                         {
92                                 eDebugNoNewLine(" (");
93                                 for (std::vector<eDVBServicePMTHandler::audioStream>::const_iterator
94                                         i(program.audioStreams.begin()); 
95                                         i != program.audioStreams.end(); ++i)
96                                 {
97                                         if (apid == -1)
98                                                 apid = i->pid;
99                                         if (i != program.audioStreams.begin())
100                                                 eDebugNoNewLine(", ");
101                                         eDebugNoNewLine("%04x", i->pid);
102                                 }
103                                 eDebugNoNewLine(")");
104                         }
105                         eDebug(", and the pcr pid is %04x", program.pcrPid);
106                         if (program.pcrPid != 0x1fff)
107                                 pcrpid = program.pcrPid;
108                 }
109                 
110                 if (!m_decoder)
111                 {
112                         ePtr<iDVBDemux> demux;
113                         m_serviceHandler.getDemux(demux);
114                         if (demux)
115                                 demux->getMPEGDecoder(m_decoder);
116                 }
117
118                 if (m_decoder)
119                 {
120                         m_decoder->setVideoPID(vpid);
121                         m_decoder->setAudioPID(apid, 0);
122                         m_decoder->setSyncPCR(pcrpid);
123                         m_decoder->start();
124                 }
125                                 
126                 break;
127         }
128         }
129 }
130
131 RESULT eDVBServicePlay::start()
132 {
133         eDebug("starting DVB service");
134         return m_serviceHandler.tune((eServiceReferenceDVB&)m_reference);
135 }
136
137 RESULT eDVBServicePlay::stop()
138 {
139         eDebug("stopping..");
140         return 0;
141 }
142
143 RESULT eDVBServicePlay::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
144 {
145         return -1;
146 }
147
148 RESULT eDVBServicePlay::getIPausableService(ePtr<iPauseableService> &ptr)
149 {
150                 // not yet possible, maybe later...
151         ptr = 0;
152         return -1;
153 }
154
155 RESULT eDVBServicePlay::getIServiceInformation(ePtr<iServiceInformation> &ptr)
156 {
157         ptr = this;
158         return 0;
159 }
160
161 RESULT eDVBServicePlay::getName(std::string &name)
162 {
163         name = "DVB service";
164         return 0;
165 }
166
167 DEFINE_REF(eDVBServicePlay)
168
169 eAutoInitPtr<eServiceFactoryDVB> init_eServiceFactoryDVB(eAutoInitNumbers::service+1, "eServiceFactoryDVB");