openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
esection.h
Go to the documentation of this file.
1 #ifndef __esection_h
2 #define __esection_h
3 
4 #include <lib/dvb/idemux.h>
5 #include <set>
6 
7 #define TABLE_eDebug(x...) do { if (m_debug) eDebug(x); } while(0)
8 #define TABLE_eDebugNoNewLineStart(x...) do { if (m_debug) eDebugNoNewLineStart(x); } while(0)
9 #define TABLE_eDebugNoNewLine(x...) do { if (m_debug) eDebugNoNewLine(x); } while(0)
10 
11 class eGTable: public iObject, public sigc::trackable
12 {
13  DECLARE_REF(eGTable);
14  ePtr<iDVBSectionReader> m_reader;
15  eDVBTableSpec m_table;
16 
17  unsigned int m_tries;
18 
19  ePtr<eTimer> m_timeout;
20 
21  void sectionRead(const uint8_t *data);
22  void timeout();
23  ePtr<eConnection> m_sectionRead_conn;
24 protected:
25  static const bool m_debug = false;
26  virtual int createTable(unsigned int nr, const uint8_t *data, unsigned int max)=0;
27  virtual unsigned int totalSections(unsigned int max) { return max + 1; }
28 public:
29  sigc::signal1<void, int> tableReady;
30  eGTable();
32  RESULT start(iDVBDemux *reader, const eDVBTableSpec &table);
33  RESULT getSpec(eDVBTableSpec &spec) { spec = m_table; return 0; }
34  virtual ~eGTable();
35  int error;
36  int ready;
37 };
38 
39 template <class Section>
40 class eTable: public eGTable
41 {
42 private:
43  std::vector<Section*> sections;
44  std::set<int> avail;
45  unsigned char m_section_data[4096];
46 protected:
47  int createTable(unsigned int nr, const uint8_t *data, unsigned int max)
48  {
49  unsigned int ssize = sections.size();
50  if (max < ssize || nr >= max)
51  {
52  TABLE_eDebug("[eTable] bounds error: max(%d) < ssize(%d) || nr(%d) >= max(%d)",
53  max, ssize, nr, max);
54  return 0;
55  }
56  if (avail.find(nr) != avail.end())
57  delete sections[nr];
58 
59  memset(m_section_data, 0, 4096);
60  memcpy(m_section_data, data, 4096);
61 
62  sections.resize(max);
63  sections[nr] = new Section(data);
64  avail.insert(nr);
65 
66  TABLE_eDebugNoNewLineStart("[eTable] ");
67  for (unsigned int i = 0; i < max; ++i)
68  if (avail.find(i) != avail.end())
70  else
72 
73  TABLE_eDebugNoNewLine(" %zd/%d TID %02x\n", avail.size(), max, data[0]);
74 
75  if (avail.size() == max)
76  {
77  TABLE_eDebug("[eTable] done!");
78  return 1;
79  } else
80  return 0;
81  }
82 public:
83  std::vector<Section*> &getSections() { return sections; }
84  unsigned char* getBufferData() { return m_section_data; }
86  {
87  for (std::set<int>::iterator i(avail.begin()); i != avail.end(); ++i)
88  delete sections[*i];
89  }
90 };
91 
92 class eAUGTable: public sigc::trackable
93 {
94 protected:
95  void slotTableReady(int);
96 public:
97  virtual ~eAUGTable(){};
98  sigc::signal1<void, int> tableReady;
99  virtual void getNext(int err)=0;
100 };
101 
102 template <class Table>
103 class eAUTable: public eAUGTable
104 {
105  ePtr<Table> current, next; // current is READY AND ERRORFREE, next is not yet ready
106  int first;
107  ePtr<iDVBDemux> m_demux;
108  ePtr<iDVBSectionReader> m_reader;
109  eMainloop *ml;
110 
111  /* needed to detect broken table version handling (seen on some m2ts files) */
112  struct timespec m_prev_table_update;
113  int m_table_cnt;
114 
115  void begin(eMainloop *m)
116  {
117  m_table_cnt = 0;
118  ml = m;
119  first= 1;
120  current = 0;
121  next = new Table();
122  CONNECT(next->tableReady, eAUTable::slotTableReady);
123  }
124 
125 public:
126 
128  {
129  }
130 
132  {
133  stop();
134  }
135 
136  void stop()
137  {
138  current = next = 0;
139  m_demux = 0;
140  m_reader = 0;
141  }
142 
143  int begin(eMainloop *m, const eDVBTableSpec &spec, ePtr<iDVBDemux> demux)
144  {
145  begin(m);
146  m_demux = demux;
147  m_reader = 0;
148  next->start(demux, spec);
149  return 0;
150  }
151 
153  {
154  begin(m);
155  m_demux = 0;
156  m_reader = reader;
157  next->start(reader, spec);
158  return 0;
159  }
160 
161  int get()
162  {
163  if (current)
164  {
165  /*emit*/ tableReady(0);
166  return 0;
167  } else if (!next)
168  {
169  /*emit*/ tableReady(-1);
170  return 0;
171  } else
172  return 1;
173  }
174 
176  {
177  if (!current)
178  return -1;
179  ptr = current;
180  return 0;
181  }
182 
183 #if 0
184  void abort()
185  {
186  eDebug("[eAUTable] aborted!");
187  if (next)
188  next->abort();
189  delete next;
190  next=0;
191  }
192 #endif
193 
194  int ready()
195  {
196  return !!current;
197  }
198 
199  void inject(Table *t)
200  {
201  next=t;
202  getNext(0);
203  }
204 
205  void getNext(int error)
206  {
207  current = 0;
208  if (error)
209  {
210  next=0;
211  if (first)
212  /*emit*/ tableReady(error);
213  first=0;
214  return;
215  } else
216  current=next;
217 
218  next=0;
219  first=0;
220 
221  ASSERT(current->ready);
222 
223  /*emit*/ tableReady(0);
224 
225  eDVBTableSpec spec;
226 
227  if (current && (!current->getSpec(spec)))
228  {
229  /* detect broken table version handling (seen on some m2ts files) */
230  if (m_table_cnt)
231  {
232  if (abs(timeout_usec(m_prev_table_update)) > 500000)
233  m_table_cnt = -1;
234  else if (m_table_cnt > 1) // two pmt update within one second
235  {
236  eDebug("[eAUTable] Seen two consecutive table version changes within 500ms. "
237  "This seems broken, so auto update for pid %04x, table %02x is now disabled!!",
238  spec.pid, spec.tid);
239  m_table_cnt = 0;
240  return;
241  }
242  }
243 
244  ++m_table_cnt;
245  clock_gettime(CLOCK_MONOTONIC, &m_prev_table_update);
246 
247  next = new Table();
248  CONNECT(next->tableReady, eAUTable::slotTableReady);
250  if (m_demux)
251  {
252  next->eGTable::start(m_demux, spec);
253  }
254  else if (m_reader)
255  {
256  next->eGTable::start(m_reader, spec);
257  }
258  }
259  }
260 };
261 
262 #endif
static int ptr
Definition: bcm.cpp:17
Definition: esection.h:93
virtual ~eAUGTable()
Definition: esection.h:97
virtual void getNext(int err)=0
sigc::signal1< void, int > tableReady
Definition: esection.h:97
void slotTableReady(int)
Definition: esection.cpp:155
Definition: esection.h:104
void inject(Table *t)
Definition: esection.h:199
~eAUTable()
Definition: esection.h:131
int begin(eMainloop *m, const eDVBTableSpec &spec, ePtr< iDVBSectionReader > reader)
Definition: esection.h:152
eAUTable()
Definition: esection.h:127
int get()
Definition: esection.h:161
int begin(eMainloop *m, const eDVBTableSpec &spec, ePtr< iDVBDemux > demux)
Definition: esection.h:143
RESULT getCurrent(ePtr< Table > &ptr)
Definition: esection.h:175
int ready()
Definition: esection.h:194
void stop()
Definition: esection.h:136
void getNext(int error)
Definition: esection.h:205
Definition: esection.h:12
sigc::signal1< void, int > tableReady
Definition: esection.h:29
static const bool m_debug
Definition: esection.h:25
virtual unsigned int totalSections(unsigned int max)
Definition: esection.h:27
eGTable()
Definition: esection.cpp:52
virtual ~eGTable()
Definition: esection.cpp:151
RESULT getSpec(eDVBTableSpec &spec)
Definition: esection.h:33
RESULT start(iDVBSectionReader *reader, const eDVBTableSpec &table)
Definition: esection.cpp:59
int error
Definition: esection.h:35
virtual int createTable(unsigned int nr, const uint8_t *data, unsigned int max)=0
int ready
Definition: esection.h:36
Definition: ebase.h:187
Definition: esection.h:41
int createTable(unsigned int nr, const uint8_t *data, unsigned int max)
Definition: esection.h:47
std::vector< Section * > & getSections()
Definition: esection.h:83
~eTable()
Definition: esection.h:85
unsigned char * getBufferData()
Definition: esection.h:84
Definition: idvb.h:755
Definition: idemux.h:7
Definition: object.h:15
static long timeout_usec(const timespec &orig)
Definition: ebase.h:128
#define ASSERT(x)
Definition: eerror.h:155
#define TABLE_eDebug(x...)
Definition: esection.h:7
#define TABLE_eDebugNoNewLineStart(x...)
Definition: esection.h:8
#define TABLE_eDebugNoNewLine(x...)
Definition: esection.h:9
unsigned char data[256]
Definition: hdmi_cec.h:2
#define CONNECT(_signal, _slot)
Definition: libsig_comp.h:6
reader
Definition: InputHotplug.py:47
int RESULT
Definition: object.h:12
eDebug("[ePicLoad] deprecated loadPic function used!!! please use the non blocking version! you can see demo code in Pictureplayer plugin... this function is removed in the near future!")
#define max(a, b)
Definition: region.cpp:7
Definition: idvb.h:37
int flags
Definition: idvb.h:58
int pid
Definition: idvb.h:38
int tid
Definition: idvb.h:38
@ tfHaveTimeout
Definition: idvb.h:54
@ tfThisVersion
Definition: idvb.h:50
@ tfAnyVersion
Definition: idvb.h:49