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 Object
13 ePtr<iDVBSectionReader> m_reader;
14 eDVBTableSpec m_table;
18 ePtr<eTimer> m_timeout;
20 void sectionRead(const __u8 *data);
22 ePtr<eConnection> m_sectionRead_conn;
25 virtual int createTable(unsigned int nr, const __u8 *data, unsigned int max)=0;
27 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, unsigned int max)
46 unsigned int ssize = sections.size();
47 if (max < ssize || nr >= max)
49 TABLE_eDebug("kaputt max(%d) < ssize(%d) || nr(%d) >= max(%d)",
53 if (avail.find(nr) != avail.end())
57 sections[nr] = new Section(data);
60 for (unsigned int i = 0; i < max; ++i)
61 if (avail.find(i) != avail.end())
62 TABLE_eDebugNoNewLine("+");
64 TABLE_eDebugNoNewLine("-");
66 TABLE_eDebug(" %d/%d TID %02x", avail.size(), max, data[0]);
68 if (avail.size() == max)
70 TABLE_eDebug("done!");
76 std::vector<Section*> &getSections() { return sections; }
77 eTable(bool debug=true): eGTable(debug)
82 for (std::set<int>::iterator i(avail.begin()); i != avail.end(); ++i)
87 class eAUGTable: public Object
90 void slotTableReady(int);
92 Signal1<void, int> tableReady;
93 virtual void getNext(int err)=0;
96 template <class Table>
97 class eAUTable: public eAUGTable
99 ePtr<Table> current, next; // current is READY AND ERRORFREE, next is not yet ready
101 ePtr<iDVBDemux> m_demux;
104 /* needed to detect broken table version handling (seen on some m2ts files) */
105 struct timespec m_prev_table_update;
124 int begin(eMainloop *m, const eDVBTableSpec &spec, ePtr<iDVBDemux> demux)
132 CONNECT(next->tableReady, eAUTable::slotTableReady);
133 next->start(demux, spec);
141 /*emit*/ tableReady(0);
145 /*emit*/ tableReady(-1);
151 RESULT getCurrent(ePtr<Table> &ptr)
162 eDebug("eAUTable: aborted!");
175 void inject(Table *t)
181 void getNext(int error)
188 /*emit*/ tableReady(error);
197 ASSERT(current->ready);
199 /*emit*/ tableReady(0);
203 if (current && (!current->getSpec(spec)))
205 /* detect broken table version handling (seen on some m2ts files) */
208 if (abs(timeout_usec(m_prev_table_update)) > 500000)
210 else if (m_table_cnt > 1) // two pmt update within one second
212 eDebug("Seen two consecutive table version changes within 500ms. "
213 "This seems broken, so auto update for pid %04x, table %02x is now disabled!!",
221 clock_gettime(CLOCK_MONOTONIC, &m_prev_table_update);
224 CONNECT(next->tableReady, eAUTable::slotTableReady);
225 spec.flags &= ~(eDVBTableSpec::tfAnyVersion|eDVBTableSpec::tfThisVersion|eDVBTableSpec::tfHaveTimeout);
226 next->eGTable::start(m_demux, spec);