fix bluescreen in ci menu when no entries in a menulist an ok is pressed
[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                 /* if a section is missing, we retry reading the
12                    whole data up to 5 times. if after that the
13                    section is still missing, we timeout. */
14         if (m_tries > 5 * (last_section_number+1))
15         {
16                 timeout();
17                 return;
18         }
19         
20         m_tries++;
21
22         if (createTable(d[6], d, last_section_number + 1))
23         {
24                 if (m_timeout)
25                         m_timeout->stop();
26                 if (m_reader)
27                 {
28                         m_reader->stop();
29                         m_reader=0;
30                 }
31                 m_sectionRead_conn=0;
32                 ready = 1;
33                 tableReady(error);
34         } else if ((m_table.flags & eDVBTableSpec::tfHaveTimeout) && m_timeout)
35                 m_timeout->start(m_table.timeout, 1); // reset timeout
36 }
37
38 void eGTable::timeout()
39 {
40         eDebug("timeout!");
41         if (m_reader)
42         {
43                 m_reader->stop();
44                 m_reader=0;
45         }
46         m_sectionRead_conn=0;
47         ready = 1;
48         error = -1;
49         tableReady(error);
50 }
51
52 eGTable::eGTable():
53                 m_timeout(0), error(0)
54 {
55 }
56
57 DEFINE_REF(eGTable);
58
59 RESULT eGTable::start(iDVBSectionReader *reader, const eDVBTableSpec &table)
60 {
61         RESULT res;
62         m_table = table;
63
64         m_reader = reader;
65         m_reader->connectRead(slot(*this, &eGTable::sectionRead), m_sectionRead_conn);
66         
67         m_tries = 0;
68         
69         // setup filter struct
70         eDVBSectionFilterMask mask;
71         
72         memset(&mask, 0, sizeof(mask));
73         mask.pid   = m_table.pid;
74         mask.flags = 0;
75         
76         if (m_table.flags & eDVBTableSpec::tfCheckCRC)
77                 mask.flags |= eDVBSectionFilterMask::rfCRC;
78         
79         if (m_table.flags & eDVBTableSpec::tfHaveTID)
80         {
81                 mask.data[0] = m_table.tid;
82                 if (m_table.flags & eDVBTableSpec::tfHaveTIDMask)
83                         mask.mask[0] = m_table.tid_mask;
84                 else
85                         mask.mask[0] = 0xFF;
86         }
87
88         if (m_table.flags & eDVBTableSpec::tfHaveTIDExt)
89         {
90                 mask.data[1] = m_table.tidext >> 8;
91                 mask.data[2] = m_table.tidext;
92                 if (m_table.flags & eDVBTableSpec::tfHaveTIDExtMask)
93                 {
94                         mask.mask[1] = m_table.tidext_mask >> 8;
95                         mask.mask[2] = m_table.tidext_mask;
96                 }
97                 else
98                 {
99                         mask.mask[1] = 0xFF;
100                         mask.mask[2] = 0xFF;
101                 }
102         }
103         
104         if (!(m_table.flags & eDVBTableSpec::tfAnyVersion))
105         {
106                 eDebug("doing version filtering");
107                 mask.data[3] |= (m_table.version << 1)|1;
108                 mask.mask[3] |= 0x3f;
109                 if (!(m_table.flags & eDVBTableSpec::tfThisVersion))
110                         mask.mode[3] |= 0x3e; // negative filtering
111         } else
112                 eDebug("no version filtering");
113         
114         eDebug("%04x:  %02x %02x %02x %02x %02x %02x",
115                 mask.pid,
116                 mask.data[0], mask.data[1], mask.data[2],
117                 mask.data[3], mask.data[4], mask.data[5]);
118         eDebug("mask:  %02x %02x %02x %02x %02x %02x",
119                 mask.mask[0], mask.mask[1], mask.mask[2],
120                 mask.mask[3], mask.mask[4], mask.mask[5]);
121         eDebug("mode:  %02x %02x %02x %02x %02x %02x",
122                 mask.mode[0], mask.mode[1], mask.mode[2],
123                 mask.mode[3], mask.mode[4], mask.mode[5]);
124
125         if ((res = m_reader->start(mask)))
126         {
127                 eDebug("reader failed to start.");
128                 return res;
129         }
130         
131         if (m_table.flags & eDVBTableSpec::tfHaveTimeout)
132         {
133                 if (m_timeout)
134                         delete m_timeout;
135                 m_timeout = new eTimer(eApp);
136                 m_timeout->start(m_table.timeout, 1); // begin timeout
137                 CONNECT(m_timeout->timeout, eGTable::timeout);
138         }
139         
140         return 0;
141 }
142
143 RESULT eGTable::start(iDVBDemux *demux, const eDVBTableSpec &table)
144 {
145         int res;
146         ePtr<iDVBSectionReader> reader;
147         res = demux->createSectionReader(eApp, reader);
148         if (res)
149                 return res;
150         return start(reader, table);
151 }
152
153 eGTable::~eGTable()
154 {
155         if (m_timeout)
156                 delete m_timeout;
157 }
158
159 void eAUGTable::slotTableReady(int error)
160 {
161         getNext(error);
162 }