4 #include <lib/dvb/idemux.h>
7 #define TABLE_eDebug(x...) do { if (m_debug) eDebug(x); } while(0)
8 #define TABLE_eDebugNoNewLine(x...) do { if (m_debug) eDebugNoNewLine(x); } while(0)
10 class eGTable: public iObject, public sigc::trackable
13 ePtr<iDVBSectionReader> m_reader;
14 eDVBTableSpec m_table;
18 ePtr<eTimer> m_timeout;
20 void sectionRead(const __u8 *data, int len);
22 ePtr<eConnection> m_sectionRead_conn;
25 virtual int createTable(unsigned int nr, const __u8 *data, int len, unsigned int max)=0;
27 sigc::signal1<void, int> tableReady;
28 eGTable(bool debug=true);
29 RESULT start(iDVBSectionReader *reader, const eDVBTableSpec &table);
30 RESULT start(iDVBDemux *reader, const eDVBTableSpec &table);
31 RESULT getSpec(eDVBTableSpec &spec) { spec = m_table; return 0; }
37 template <class Section>
38 class eTable: public eGTable
41 std::vector<Section*> sections;
44 int createTable(unsigned int nr, const __u8 *data, int len, unsigned int max)
48 unsigned int ssize = sections.size();
49 if (max < ssize || nr >= max)
51 TABLE_eDebug("kaputt max(%d) < ssize(%d) || nr(%d) >= max(%d)",
55 if (avail.find(nr) != avail.end())
59 sections[nr] = new Section(data);
62 for (unsigned int i = 0; i < max; ++i)
63 if (avail.find(i) != avail.end())
64 TABLE_eDebugNoNewLine("+");
66 TABLE_eDebugNoNewLine("-");
68 TABLE_eDebug(" %zd/%d TID %02x", avail.size(), max, data[0]);
70 if (avail.size() == max)
72 TABLE_eDebug("done!");
78 std::vector<Section*> &getSections() { return sections; }
79 eTable(bool debug=true): eGTable(debug)
84 for (std::set<int>::iterator i(avail.begin()); i != avail.end(); ++i)
89 class eAUGTable: public iObject, public sigc::trackable
91 DECLARE_REF(eAUGTable);
93 void slotTableReady(int);
95 sigc::signal1<void, int> tableReady;
96 virtual void getNext(int err)=0;
99 template <class Table>
100 class eAUTable: public eAUGTable
102 ePtr<Table> current, next; // current is READY AND ERRORFREE, next is not yet ready
104 ePtr<iDVBDemux> m_demux;
107 /* needed to detect broken table version handling (seen on some m2ts files) */
108 struct timespec m_prev_table_update;
127 int begin(eMainloop *m, const eDVBTableSpec &spec, ePtr<iDVBDemux> demux)
135 CONNECT(next->tableReady, eAUTable::slotTableReady);
136 next->start(demux, spec);
144 /*emit*/ tableReady(0);
148 /*emit*/ tableReady(-1);
154 RESULT getCurrent(ePtr<Table> &ptr)
165 eDebug("eAUTable: aborted!");
178 void inject(Table *t)
184 void getNext(int error)
191 /*emit*/ tableReady(error);
200 ASSERT(current->ready);
202 /*emit*/ tableReady(0);
206 if (current && (!current->getSpec(spec)))
208 /* detect broken table version handling (seen on some m2ts files) */
211 if (llabs(timeout_msec(m_prev_table_update)) > 500)
213 else if (m_table_cnt > 1) // two pmt update within one second
215 eDebug("Seen two consecutive table version changes within 500ms. "
216 "This seems broken, so auto update for pid %04x, table %02x is now disabled!!",
224 clock_gettime(CLOCK_MONOTONIC, &m_prev_table_update);
227 CONNECT(next->tableReady, eAUTable::slotTableReady);
228 spec.flags &= ~(eDVBTableSpec::tfAnyVersion|eDVBTableSpec::tfThisVersion|eDVBTableSpec::tfHaveTimeout);
229 next->eGTable::start(m_demux, spec);