show repeated timers in TimerEntryComponent
[enigma2.git] / lib / dvb / dvb.h
1 #ifndef __dvb_dvb_h
2 #define __dvb_dvb_h
3
4 #include <lib/dvb/idvb.h>
5 #include <lib/dvb/demux.h>
6 #include <lib/dvb/frontend.h>
7 #include <lib/dvb/tstools.h>
8 #include <connection.h>
9
10 class eDVBChannel;
11 class eDVBChannel;
12
13         /* we do NOT handle resource conflicts here. instead, the allocateChannel
14            fails, and the application has to see why the channel is allocated
15            (and how to deallocate it). */
16 class iDVBAdapter;
17
18 class eDVBRegisteredFrontend: public iObject
19 {
20 DECLARE_REF(eDVBRegisteredFrontend);
21 public:
22         iDVBAdapter *m_adapter;
23         ePtr<eDVBFrontend> m_frontend;
24         int m_inuse;
25         eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap): m_adapter(adap), m_frontend(fe), m_inuse(0) { }
26 };
27
28 struct eDVBRegisteredDemux
29 {
30 DECLARE_REF(eDVBRegisteredDemux);
31 public:
32         iDVBAdapter *m_adapter;
33         ePtr<eDVBDemux> m_demux;
34         int m_inuse;
35         eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
36 };
37
38 class eDVBAllocatedFrontend
39 {
40 DECLARE_REF(eDVBAllocatedFrontend);
41 public:
42         
43         eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
44         ~eDVBAllocatedFrontend();
45         eDVBFrontend &get() { return *m_fe->m_frontend; }
46         operator eDVBRegisteredFrontend*() { return m_fe; }
47         operator eDVBFrontend*() { return m_fe->m_frontend; }
48
49 private:
50         eDVBRegisteredFrontend *m_fe;
51 };
52
53 class eDVBAllocatedDemux
54 {
55 DECLARE_REF(eDVBAllocatedDemux);
56 public:
57         
58         eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
59         ~eDVBAllocatedDemux();
60         eDVBDemux &get() { return *m_demux->m_demux; }
61         operator eDVBRegisteredDemux*() { return m_demux; }
62         operator eDVBDemux*() { return m_demux->m_demux; }
63         
64 private:
65         eDVBRegisteredDemux *m_demux;
66 };
67
68 class iDVBAdapter: public iObject
69 {
70 public:
71         virtual int getNumDemux() = 0;
72         virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
73         
74         virtual int getNumFrontends() = 0;
75         virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr) = 0;
76 };
77
78 class eDVBAdapterLinux: public iDVBAdapter
79 {
80 DECLARE_REF(eDVBAdapterLinux);
81 public:
82         eDVBAdapterLinux(int nr);
83
84         int getNumDemux();
85         RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
86         
87         int getNumFrontends();
88         RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr);
89         
90         static int exist(int nr);
91 private:
92         int m_nr;
93         eSmartPtrList<eDVBFrontend> m_frontend;
94         eSmartPtrList<eDVBDemux>    m_demux;
95 };
96
97 class eDVBResourceManager: public iObject
98 {
99         DECLARE_REF(eDVBResourceManager);
100         int avail, busy;
101         
102         eSmartPtrList<iDVBAdapter> m_adapter;
103         
104         eSmartPtrList<eDVBRegisteredDemux> m_demux;
105         eSmartPtrList<eDVBRegisteredFrontend> m_frontend;
106         
107         void addAdapter(iDVBAdapter *adapter);
108         
109                         /* allocates a frontend able to tune to channelID "chid".
110                            the frontend must be tuned lateron. there is no guarante
111                            that tuning will suceed - it just means that if this frontend
112                            can't tune, no other frontend could do it.
113                            
114                            there might be a priority given to certain frontend/chid 
115                            combinations. this will be evaluated here. */
116                            
117         RESULT allocateFrontend(ePtr<iDVBFrontendParameters> &feparm, ePtr<eDVBAllocatedFrontend> &fe);
118         
119                         /* allocate a demux able to filter on the selected frontend. */
120         RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
121         
122         struct active_channel
123         {
124                 eDVBChannelID m_channel_id;
125                         /* we don't hold a reference here. */
126                 eDVBChannel *m_channel;
127                 
128                 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
129         };
130         
131         std::list<active_channel> m_active_channels;
132         
133         ePtr<iDVBChannelList> m_list;
134         ePtr<iDVBSatelliteEquipmentControl> m_sec;
135         static eDVBResourceManager *instance;
136         
137         friend class eDVBChannel;
138         RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
139         RESULT removeChannel(eDVBChannel *ch);
140         
141         Signal1<void,eDVBChannel*> m_channelAdded;
142         Signal1<void,eDVBChannel*> m_channelRemoved;
143         Signal1<void,iDVBChannel*> m_channelRunning;
144 public:
145         eDVBResourceManager();
146         virtual ~eDVBResourceManager();
147         
148         static RESULT getInstance(ePtr<eDVBResourceManager> &ptr) { if (instance) { ptr = instance; return 0; } return -1; }
149         
150         RESULT setChannelList(iDVBChannelList *list);
151         RESULT getChannelList(ePtr<iDVBChannelList> &list);
152         
153         enum {
154                 errNoFrontend = -1,
155                 errNoDemux    = -2,
156                 errChidNotFound = -3
157         };
158         
159                 /* allocate channel... */
160         RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel);
161         RESULT allocateRawChannel(eUsePtr<iDVBChannel> &channel);
162         RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
163
164         RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
165         RESULT connectChannelRemoved(const Slot1<void,eDVBChannel*> &channelRemoved, ePtr<eConnection> &connection);
166         RESULT connectChannelRunning(const Slot1<void,iDVBChannel*> &channelRemoved, ePtr<eConnection> &connection);
167 };
168
169 class eFilePushThread;
170
171         /* iDVBPVRChannel includes iDVBChannel. don't panic. */
172 class eDVBChannel: public iDVBPVRChannel, public Object
173 {
174         DECLARE_REF(eDVBChannel);
175 public:
176         eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
177         virtual ~eDVBChannel();
178
179                 /* only for managed channels - effectively tunes to the channelid. should not be used... */
180                 /* cannot be used for PVR channels. */
181         RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
182         eDVBChannelID getChannelID() { return m_channel_id; }
183
184         RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
185         RESULT getState(int &state);
186
187         RESULT setCIRouting(const eDVBCIRouting &routing);
188         RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
189         RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
190         
191                 /* iDVBPVRChannel */
192         RESULT playFile(const char *file);
193         RESULT getLength(pts_t &len);
194         RESULT getCurrentPosition(pts_t &pos);
195         RESULT seekTo(int relative, pts_t &pts);
196                         /* seeking to relative positions won't work - 
197                            there is an unknown amount of buffers in between */
198         RESULT seekToPosition(const off_t &off);
199
200 private:
201         ePtr<eDVBAllocatedFrontend> m_frontend;
202         ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
203         
204         ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
205         eDVBChannelID m_channel_id;
206         Signal1<void,iDVBChannel*> m_stateChanged;
207         int m_state;
208
209                         /* for channel list */
210         ePtr<eDVBResourceManager> m_mgr;
211         
212         void frontendStateChanged(iDVBFrontend*fe);
213         ePtr<eConnection> m_conn_frontendStateChanged;
214         
215                 /* for PVR playback */
216         eFilePushThread *m_pvr_thread;
217         int m_pvr_fd_src, m_pvr_fd_dst;
218         eDVBTSTools m_tstools;
219
220         friend class eUsePtr<eDVBChannel>;
221                 /* use count */
222         oRefCount m_use_count;
223         void AddUse();
224         void ReleaseUse();
225 };
226
227 #endif