openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
dvb.h
Go to the documentation of this file.
1 #ifndef __dvb_dvb_h
2 #define __dvb_dvb_h
3 
4 #ifndef SWIG
5 
6 #include <lib/base/ebase.h>
7 #include <lib/base/elock.h>
8 #include <lib/dvb/idvb.h>
9 #include <lib/dvb/fbc.h>
10 #include <lib/dvb/demux.h>
11 #include <lib/dvb/frontend.h>
12 #include <lib/dvb/tstools.h>
13 #include <lib/dvb/esection.h>
14 #include "filepush.h"
15 #include <connection.h>
16 
17 #include <dvbsi++/service_description_section.h>
18 
19 class eDVBChannel;
20 
21  /* we do NOT handle resource conflicts here. instead, the allocateChannel
22  fails, and the application has to see why the channel is allocated
23  (and how to deallocate it). */
24 class iDVBAdapter;
25 
26 class eDVBRegisteredFrontend: public iObject, public sigc::trackable
27 {
28  DECLARE_REF(eDVBRegisteredFrontend);
29  ePtr<eTimer> disable;
30  void closeFrontend()
31  {
32  if (!m_inuse && m_frontend->closeFrontend()) // frontend busy
33  disable->start(60000, true); // retry close in 60secs
34  }
35 public:
36  sigc::signal0<void> stateChanged;
38  :disable(eTimer::create(eApp)), m_adapter(adap), m_frontend(fe), m_inuse(0)
39  {
40  CONNECT(disable->timeout, eDVBRegisteredFrontend::closeFrontend);
41  }
42  void dec_use()
43  {
44  if (!--m_inuse)
45  {
46  /* emit */ stateChanged();
47  disable->start(3000, true);
48  }
49  }
50  void inc_use()
51  {
52  if (++m_inuse == 1)
53  {
55  /* emit */ stateChanged();
56  }
57  }
60  int m_inuse;
61 };
62 
64 {
66 public:
69  int m_inuse;
70  eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
71 };
72 
74 {
75  DECLARE_REF(eDVBAllocatedFrontend);
76 public:
77 
80  eDVBFrontend &get() { return *m_fe->m_frontend; }
81  operator eDVBRegisteredFrontend*() { return m_fe; }
82  operator eDVBFrontend*() { return m_fe->m_frontend; }
83 
84 private:
86 };
87 
89 {
90  DECLARE_REF(eDVBAllocatedDemux);
91 public:
92 
95  eDVBDemux &get() { return *m_demux->m_demux; }
96  operator eDVBRegisteredDemux*() { return m_demux; }
97  operator eDVBDemux*() { return m_demux->m_demux; }
98 
99 private:
100  eDVBRegisteredDemux *m_demux;
101 };
102 
103 class iDVBAdapter: public iObject
104 {
105 public:
106  virtual int getNumDemux() = 0;
107  virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
108 
109  virtual int getNumFrontends() = 0;
110  virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr, bool simulate=false) = 0;
111 };
112 
114 {
115  DECLARE_REF(eDVBAdapterLinux);
116 public:
117  eDVBAdapterLinux(int nr);
118 
119  void scanDevices();
120 
121  int getNumDemux();
122  RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
123 
124  int getNumFrontends();
125  RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr, bool simulate=false);
126 
127  static int exist(int nr);
128  static bool isusb(int nr);
129 private:
130  int m_nr;
131  eSmartPtrList<eDVBFrontend> m_frontend, m_simulate_frontend;
132  eSmartPtrList<eDVBDemux> m_demux;
133 protected:
134  static std::map<std::string, std::string> mappedFrontendName;
135 };
136 
138 {
139  DECLARE_REF(eDVBUsbAdapter);
140 private:
141  int vtunerFd;
142  int demuxFd;
143  int pipeFd[2];
144  std::string usbFrontendName;
145  std::string virtualFrontendName;
146  bool running;
147  unsigned short int pidList[30];
148  unsigned char buffer[4 * 1024 * 188];
149  pthread_t pumpThread;
150  static void *threadproc(void *arg);
151  void *vtunerPump();
152 
153 public:
154  eDVBUsbAdapter(int nr);
155  ~eDVBUsbAdapter();
156 };
157 #endif // SWIG
158 
160 class eDVBResourceManager: public iObject, public sigc::trackable
161 {
162  DECLARE_REF(eDVBResourceManager);
163  int avail, busy;
164 
165  enum { DM7025, DM800, DM500HD, DM800SE, DM8000, DM7020HD, DM7080, DM820, DM520, DM525, DM900, DM920, GIGABLUE, DM500HDV2, DM800SEV2, WETEKPLAY, WETEKPLAY2, WETEKHUB};
166 
167  int m_boxtype;
168 
169  eSmartPtrList<iDVBAdapter> m_adapter;
171  eSmartPtrList<eDVBRegisteredFrontend> m_frontend, m_simulate_frontend;
172  void addAdapter(iDVBAdapter *adapter, bool front = false);
173  void setUsbTuner();
174 
175 public:
177  {
179  /* we don't hold a reference here. */
181 
182  active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
183  };
184 
185 private:
186  std::list<active_channel> m_active_channels, m_active_simulate_channels;
187 
188  ePtr<iDVBChannelList> m_list;
190  static eDVBResourceManager *instance;
191  ePtr<eFBCTunerManager> m_fbc_mng;
192 
193  friend class eDVBChannel;
194  friend class eFBCTunerManager;
195  friend class eRTSPStreamClient;
196 
197  RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
198  RESULT removeChannel(eDVBChannel *ch);
199 
200  sigc::signal1<void,eDVBChannel*> m_channelAdded;
201 
202  eUsePtr<iDVBChannel> m_cached_channel;
203  sigc::connection m_cached_channel_state_changed_conn;
204  ePtr<eTimer> m_releaseCachedChannelTimer;
205  void DVBChannelStateChanged(iDVBChannel*);
206  void feStateChanged();
207 #ifndef SWIG
208 public:
209 #endif
210  void releaseCachedChannel();
212  virtual ~eDVBResourceManager();
213 
216  RESULT getActiveChannels(std::list<active_channel> &list);
217 
218  enum {
219  /* errNoFrontend = -1 replaced by more spcific messages */
226  };
227 
228  RESULT connectChannelAdded(const sigc::slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
229  int canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore, int &system, bool simulate=false);
230 
231  /* allocate channel... */
232  bool frontendPreferenceAllowsChannelUse(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> channel, bool simulate);
233  RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel, bool simulate=false);
236 
237  /* allocates a frontend able to tune to frontend paramters 'feperm'.
238  the frontend must be tuned lateron. there is no guarante
239  that tuning will succeed - it just means that if this frontend
240  can't tune, no other frontend could do it.
241 
242  there might be a priority given to certain frontend/chid
243  combinations. this will be evaluated here. */
244  RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm, bool simulate=false, bool returnScoreOnly=false);
245 
247  /* allocate a demux able to filter on the selected frontend. */
249 #ifdef SWIG
250 public:
251 #endif
252  int canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm, bool simulate=false);
257  bool frontendIsCompatible(int index, const char *type);
258  bool frontendIsMultistream(int index);
259  std::string getFrontendCapabilities(int index);
260  void setFrontendType(int index, const char *type, bool append=false);
261  int getFrontendType(int index);
262 };
265  static ePtr<eDVBResourceManager> getInstance()
266  {
268  return NewResourceManagerPtr();
269  }
270 );
271 
272 #ifndef SWIG
273 
274 class eDVBChannelFilePush;
275 
276  /* iDVBPVRChannel includes iDVBChannel. don't panic. */
277 class eDVBChannel: public iDVBPVRChannel, public iFilePushScatterGather, public sigc::trackable
278 {
279  DECLARE_REF(eDVBChannel);
280  friend class eDVBResourceManager;
281 public:
283  virtual ~eDVBChannel();
284 
285  /* only for managed channels - effectively tunes to the channelid. should not be used... */
286  /* cannot be used for PVR channels. */
287  /* RESULT == 0: succeeded */
288  /* RESULT != 0: failed */
290  eDVBChannelID getChannelID() { return m_channel_id; }
291 #if defined(__sh__) //see filepush.h
292  int getSkipMode() { return m_skipmode_m; }
293 #endif
294 
295  RESULT connectStateChange(const sigc::slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
296  RESULT connectEvent(const sigc::slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection);
297 
298  RESULT getState(int &state);
299 
300  RESULT setCIRouting(const eDVBCIRouting &routing);
301  RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
304 
305  /* iDVBPVRChannel */
306  RESULT playFile(const char *file);
307  RESULT playSource(ePtr<iTsSource>& source, const char *priv=NULL);
308  void stop();
309 
310  void setCueSheet(eCueSheet *cuesheet);
311  void setOfflineDecodeMode(int parityswitchdelay);
312 
313  RESULT getLength(pts_t &len);
314  RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode);
315 
316  int getUseCount() { return m_use_count; }
317 
319  int reserveDemux();
320  int getDvrId();
321 private:
322  ePtr<eDVBAllocatedFrontend> m_frontend;
323  ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
324 
325  ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
326  eDVBChannelID m_channel_id;
327  sigc::signal1<void,iDVBChannel*> m_stateChanged;
328  sigc::signal2<void,iDVBChannel*,int> m_event;
329  int m_state;
330  ePtr<iTsSource> m_source;
331 
332  /* for channel list */
334 
335  void frontendStateChanged(iDVBFrontend*fe);
336  ePtr<eConnection> m_conn_frontendStateChanged;
337 
338  /* for PVR playback */
339  ePtr<eDVBChannelFilePush> m_pvr_thread;
340  void pvrEvent(int event);
341 
342  int m_pvr_fd_dst;
343  eSingleLock m_tstools_lock;
344  eDVBTSTools m_tstools;
345 
346  ePtr<eCueSheet> m_cue;
347 
348  void cueSheetEvent(int event);
349  ePtr<eConnection> m_conn_cueSheetEvent;
350  int m_skipmode_m, m_skipmode_n, m_skipmode_frames, m_skipmode_frames_remainder;
351 
352  std::list<std::pair<off_t, off_t> > m_source_span;
353  void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size, int blocksize);
354  void flushPVR(iDVBDemux *decoding_demux=0);
355 
356  eSingleLock m_cuesheet_lock;
357 
358  friend class eUsePtr<eDVBChannel>;
359  /* use count */
360  oRefCount m_use_count;
361  void AddUse();
362  void ReleaseUse();
363 
364  /* for tsid/onid read */
365  ePtr<iDVBDemux> m_tsid_onid_demux;
367  void SDTready(int err);
368 };
369 #endif // SWIG
370 
371 #endif
long long pts_t
Definition: cfile.h:7
Definition: idvb.h:695
Definition: dvb.h:114
int getNumFrontends()
Definition: dvb.cpp:311
RESULT getDemux(ePtr< eDVBDemux > &demux, int nr)
Definition: dvb.cpp:293
static int exist(int nr)
Definition: dvb.cpp:333
void scanDevices()
Definition: dvb.cpp:233
int getNumDemux()
Definition: dvb.cpp:288
eDVBAdapterLinux(int nr)
Definition: dvb.cpp:229
static std::map< std::string, std::string > mappedFrontendName
Definition: dvb.h:134
static bool isusb(int nr)
Definition: dvb.cpp:340
RESULT getFrontend(ePtr< eDVBFrontend > &fe, int nr, bool simulate=false)
Definition: dvb.cpp:316
Definition: dvb.h:89
eDVBAllocatedDemux(eDVBRegisteredDemux *demux)
Definition: dvb.cpp:53
~eDVBAllocatedDemux()
Definition: dvb.cpp:58
eDVBDemux & get()
Definition: dvb.h:95
Definition: dvb.h:74
~eDVBAllocatedFrontend()
Definition: dvb.cpp:46
eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe)
Definition: dvb.cpp:33
eDVBFrontend & get()
Definition: dvb.h:80
Definition: dvb.cpp:1899
Definition: dvb.h:278
RESULT getLength(pts_t &len)
Definition: dvb.cpp:2678
RESULT getState(int &state)
Definition: dvb.cpp:2451
int reserveDemux()
Definition: dvb.cpp:2479
void setOfflineDecodeMode(int parityswitchdelay)
Definition: dvb.cpp:2673
int getDvrId()
Definition: dvb.cpp:2491
RESULT playFile(const char *file)
Definition: dvb.cpp:2575
RESULT getCurrentFrontendParameters(ePtr< iDVBFrontendParameters > &param)
Definition: dvb.cpp:2569
RESULT getFrontend(ePtr< iDVBFrontend > &frontend)
Definition: dvb.cpp:2558
void setCueSheet(eCueSheet *cuesheet)
Definition: dvb.cpp:2665
RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode)
Definition: dvb.cpp:2686
RESULT setChannel(const eDVBChannelID &id, ePtr< iDVBFrontendParameters > &feparam)
Definition: dvb.cpp:2405
int getUseCount()
Definition: dvb.h:316
void stop()
Definition: dvb.cpp:2649
RESULT setCIRouting(const eDVBCIRouting &routing)
Definition: dvb.cpp:2457
RESULT getDemux(ePtr< iDVBDemux > &demux, int cap)
Definition: dvb.cpp:2520
eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend)
Definition: dvb.cpp:1957
eDVBChannelID getChannelID()
Definition: dvb.h:290
RESULT requestTsidOnid()
Definition: dvb.cpp:2501
RESULT connectStateChange(const sigc::slot1< void, iDVBChannel * > &stateChange, ePtr< eConnection > &connection)
Definition: dvb.cpp:2439
RESULT connectEvent(const sigc::slot2< void, iDVBChannel *, int > &eventChange, ePtr< eConnection > &connection)
Definition: dvb.cpp:2445
virtual ~eDVBChannel()
Definition: dvb.cpp:1970
RESULT playSource(ePtr< iTsSource > &source, const char *priv=NULL)
Definition: dvb.cpp:2589
Definition: demux.h:11
Definition: frontend.h:59
int closeFrontend(bool force=false, bool no_delayed=false)
Definition: frontend.cpp:931
int openFrontend()
Definition: frontend.cpp:706
Definition: dvb.h:27
int m_inuse
Definition: dvb.h:60
eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap)
Definition: dvb.h:37
sigc::signal0< void > stateChanged
Definition: dvb.h:36
iDVBAdapter * m_adapter
Definition: dvb.h:58
ePtr< eDVBFrontend > m_frontend
Definition: dvb.h:59
void inc_use()
Definition: dvb.h:50
void dec_use()
Definition: dvb.h:42
Definition: dvb.h:161
static RESULT getInstance(ePtr< eDVBResourceManager > &)
Definition: dvb.cpp:67
void releaseCachedChannel()
Definition: dvb.cpp:1547
int canAllocateFrontend(ePtr< iDVBFrontendParameters > &feparm, bool simulate=false)
Definition: dvb.cpp:1650
SWIG_VOID(RESULT) allocateRawChannel(eUsePtr< iDVBChannel > &SWIG_OUTPUT
PyObject * setFrontendSlotInformations(SWIG_PYOBJECT(ePyObject) list)
Definition: dvb.cpp:841
RESULT connectChannelAdded(const sigc::slot1< void, eDVBChannel * > &channelAdded, ePtr< eConnection > &connection)
Definition: dvb.cpp:1644
PSignal1< void, int > frontendUseMaskChanged
Definition: dvb.h:254
RESULT getActiveChannels(std::list< active_channel > &list)
Definition: dvb.cpp:1350
std::string getFrontendCapabilities(int index)
Definition: dvb.cpp:959
RESULT getChannelList(ePtr< iDVBChannelList > &list)
Definition: dvb.cpp:1341
RESULT allocateFrontend(ePtr< eDVBAllocatedFrontend > &fe, ePtr< iDVBFrontendParameters > &feparm, bool simulate=false, bool returnScoreOnly=false)
Definition: dvb.cpp:1008
eDVBResourceManager()
Definition: dvb.cpp:84
RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr< iDVBChannel > &channel, bool simulate=false)
Definition: dvb.cpp:1424
bool frontendIsMultistream(int index)
Definition: dvb.cpp:947
bool frontendIsCompatible(int index, const char *type)
Definition: dvb.cpp:897
bool frontendPreferenceAllowsChannelUse(const eDVBChannelID &channelid, eUsePtr< iDVBChannel > channel, bool simulate)
Definition: dvb.cpp:1362
virtual ~eDVBResourceManager()
Definition: dvb.cpp:712
void setFrontendType(int index, const char *type, bool append=false)
Definition: dvb.cpp:971
@ errChannelNotInList
Definition: dvb.h:223
@ errNoSourceFound
Definition: dvb.h:225
@ errNoChannelList
Definition: dvb.h:222
@ errAllSourcesBusy
Definition: dvb.h:224
@ errNoDemux
Definition: dvb.h:220
@ errChidNotFound
Definition: dvb.h:221
int slot_index
Definition: dvb.h:255
RESULT allocateFrontendByIndex(ePtr< eDVBAllocatedFrontend > &fe, int slot_index)
Definition: dvb.cpp:1084
int canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore, int &system, bool simulate=false)
Definition: dvb.cpp:1714
RESULT allocatePVRChannel(const eDVBChannelID &channelid, eUsePtr< iDVBPVRChannel > &channel)
Definition: dvb.cpp:1573
RESULT setChannelList(iDVBChannelList *list)
Definition: dvb.cpp:1335
RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr< eDVBAllocatedDemux > &demux, int &cap)
Definition: dvb.cpp:1140
bool canMeasureFrontendInputPower()
Definition: dvb.cpp:1889
int getFrontendType(int index)
Definition: dvb.cpp:937
Definition: tstools.h:36
Definition: dvb.h:138
eDVBUsbAdapter(int nr)
Definition: dvb.cpp:353
~eDVBUsbAdapter()
Definition: dvb.cpp:560
Definition: fbc.h:24
Definition: python.h:31
Definition: rtspstreamserver.h:17
int fe
Definition: rtspstreamserver.h:43
Definition: elock.h:81
Gives a callback after a specified timeout.
Definition: ebase.h:277
void start(long msec, bool b=false)
Definition: ebase.cpp:48
PSignal0< void > timeout
Definition: ebase.h:299
Definition: dvb.h:104
virtual int getNumDemux()=0
virtual int getNumFrontends()=0
virtual RESULT getDemux(ePtr< eDVBDemux > &demux, int nr)=0
virtual RESULT getFrontend(ePtr< eDVBFrontend > &fe, int nr, bool simulate=false)=0
Definition: idvb.h:637
Definition: idvb.h:443
Definition: idvb.h:755
Definition: idvb.h:583
Definition: idvb.h:726
Definition: filepush.h:12
Definition: object.h:15
Definition: object.h:36
ePtr< eDVBResourceManager > NewResourceManagerPtr(void)
Definition: dvb.cpp:77
SWIG_TEMPLATE_TYPEDEF(ePtr< eDVBResourceManager >, eDVBResourceManager)
SWIG_EXTEND(ePtr< eDVBResourceManager >, static ePtr< eDVBResourceManager > getInstance() { extern ePtr< eDVBResourceManager > NewResourceManagerPtr(void);return NewResourceManagerPtr();})
SWIG_IGNORE(eDVBResourceManager)
eApplication * eApp
Definition: ebase.cpp:416
#define NULL
Definition: eerror.h:101
#define CONNECT(_signal, _slot)
Definition: libsig_comp.h:6
size
Definition: Plugins/SystemPlugins/PositionerSetup/log.py:16
file
Definition: newplugin.py:100
arg
Definition: UnitConversions.py:88
pos
Definition: enigma_py_patcher.py:16
source
Definition: enigma_py_patcher.py:9
list list
Definition: main.py:25
index
Definition: main.py:28
int RESULT
Definition: object.h:12
Definition: idvb.h:630
Definition: idvb.h:144
Definition: dvb.h:64
iDVBAdapter * m_adapter
Definition: dvb.h:67
int m_inuse
Definition: dvb.h:69
eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap)
Definition: dvb.h:70
DECLARE_REF(eDVBRegisteredDemux)
ePtr< eDVBDemux > m_demux
Definition: dvb.h:68
active_channel(const eDVBChannelID &chid, eDVBChannel *ch)
Definition: dvb.h:182
eDVBChannel * m_channel
Definition: dvb.h:180
eDVBChannelID m_channel_id
Definition: dvb.h:178
#define SWIG_OUTPUT
Definition: swig.h:20
#define SWIG_PYOBJECT(x)
Definition: swig.h:23
uint8_t mode
Definition: vps.cpp:40