- skip first field in flexible python listbox to allow having private data.
[enigma2.git] / lib / dvb / esection.cpp
1 #include <lib/dvb/esection.h>
2 #include <lib/base/eerror.h>
3
4 void eGTable::sectionRead(const __u8 *d)
5 {
6         unsigned int last_section_number = d[7];
7         m_table.flags &= ~eDVBTableSpec::tfAnyVersion;
8         m_table.flags |= eDVBTableSpec::tfThisVersion;
9         m_table.version = (d[5]>>1)&0x1F;
10
11
12         if (createTable(d[6], d, last_section_number + 1))
13         {
14                 if (m_timeout)
15                         m_timeout->stop();
16                 m_reader->stop();
17                 ready = 1;
18                 tableReady(error);
19         } else if ((m_table.flags & eDVBTableSpec::tfHaveTimeout) && m_timeout)
20                 m_timeout->start(m_table.timeout, 1); // reset timeout
21 }
22
23 void eGTable::timeout()
24 {
25         printf("timeout!\n");
26 //      eDebug("timeout!");
27         m_reader->stop();
28         ready = 1;
29         error = -1;
30         tableReady(error);
31 }
32
33 eGTable::eGTable():
34                 m_timeout(0), error(0)
35 {
36 }
37
38 DEFINE_REF(eGTable);
39
40 RESULT eGTable::start(iDVBSectionReader *reader, const eDVBTableSpec &table)
41 {
42         RESULT res;
43         m_table = table;
44
45         m_reader = reader;
46         m_reader->connectRead(slot(*this, &eGTable::sectionRead), m_sectionRead_conn);
47         
48         // setup filter struct
49         eDVBSectionFilterMask mask;
50         
51         memset(&mask, 0, sizeof(mask));
52         mask.pid   = m_table.pid;
53         mask.flags = 0;
54         
55         if (m_table.flags & eDVBTableSpec::tfCheckCRC)
56                 mask.flags |= eDVBSectionFilterMask::rfCRC;
57         
58         if (m_table.flags & eDVBTableSpec::tfHaveTID)
59         {
60                 mask.data[0] = m_table.tid;
61                 mask.mask[0] = 0xFF;
62         }
63         
64         if (m_table.flags & eDVBTableSpec::tfHaveTIDExt)
65         {
66                 mask.data[1] = m_table.tidext >> 8;
67                 mask.data[2] = m_table.tidext;
68                 mask.mask[1] = 0xFF;
69                 mask.mask[2] = 0xFF;
70         }
71         
72         if (!(m_table.flags & eDVBTableSpec::tfAnyVersion))
73         {
74                 eDebug("doing version filtering");
75                 mask.data[3] |= (m_table.version << 1)|1;
76                 mask.mask[3] |= 0x3f;
77                 if (!(m_table.flags & eDVBTableSpec::tfThisVersion))
78                         mask.mode[3] |= 0x3e; // negative filtering
79         } else
80                 eDebug("no version filtering");
81         
82         eDebug("%04x:  %02x %02x %02x %02x %02x %02x",
83                 mask.pid,
84                 mask.data[0], mask.data[1], mask.data[2],
85                 mask.data[3], mask.data[4], mask.data[5]);
86         eDebug("mask:  %02x %02x %02x %02x %02x %02x",
87                 mask.mask[0], mask.mask[1], mask.mask[2],
88                 mask.mask[3], mask.mask[4], mask.mask[5]);
89         eDebug("mode:  %02x %02x %02x %02x %02x %02x",
90                 mask.mode[0], mask.mode[1], mask.mode[2],
91                 mask.mode[3], mask.mode[4], mask.mode[5]);
92
93         if ((res = m_reader->start(mask)))
94         {
95                 eDebug("reader failed to start.");
96                 return res;
97         }
98         
99         if (m_table.flags & eDVBTableSpec::tfHaveTimeout)
100         {
101                 if (m_timeout)
102                         delete m_timeout;
103                 m_timeout = new eTimer(eApp);
104                 m_timeout->start(m_table.timeout, 1); // begin timeout
105                 CONNECT(m_timeout->timeout, eGTable::timeout);
106         }
107         
108         return 0;
109 }
110
111 RESULT eGTable::start(iDVBDemux *demux, const eDVBTableSpec &table)
112 {
113         int res;
114         ePtr<iDVBSectionReader> reader;
115         res = demux->createSectionReader(eApp, reader);
116         if (res)
117                 return res;
118         return start(reader, table);
119 }
120
121 eGTable::~eGTable()
122 {
123         if (m_timeout)
124                 delete m_timeout;
125 }
126
127 void eAUGTable::slotTableReady(int error)
128 {
129         getNext(error);
130 }