remove unused variable 'delta'
[enigma2.git] / lib / dvb / pesparse.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/dvb/pesparse.h>
3 #include <memory.h>
4
5 ePESParser::ePESParser()
6 {
7         m_pes_position = 0;
8         m_pes_length = 0;
9         m_header[0] = 0;
10         m_header[1] = 0;
11         m_header[2] = 1;
12         setStreamID(0); /* must be overridden */
13 }
14
15 void ePESParser::setStreamID(unsigned char id, unsigned char id_mask)
16 {
17         m_header[3] = id;
18         m_stream_id_mask = id_mask;
19 }
20
21 void ePESParser::processData(const __u8 *p, int len)
22 {
23         int i;
24
25                 /* this is a state machine, handling arbitary amounts of pes-formatted data. */
26         while (len)
27         {
28                 if (m_pes_position >= 6) // length ok?
29                 {
30                         int max = m_pes_length - m_pes_position;
31                         if (max > len)
32                                 max = len;
33                         memcpy(m_pes_buffer + m_pes_position, p, max);
34                         m_pes_position += max;
35                         p += max;
36                         
37                         len -= max;
38                         
39                         if (m_pes_position == m_pes_length)
40                         {
41                                 processPESPacket(m_pes_buffer, m_pes_position);
42                                 m_pes_position = 0;
43                         }
44                 } else
45                 {
46                         if (m_pes_position < 4)
47                         {
48                                 unsigned char ch = *p;
49                                 if (m_pes_position == 3)
50                                         ch &= m_stream_id_mask;
51                                 if (ch != m_header[m_pes_position])
52                                 {
53 //                                      eDebug("sync lost at %d (%02x)", m_pes_position, *p);
54                                         m_pes_position = 0;
55                                         while (m_header[m_pes_position] == ch) /* guaranteed to stop at the old m_pes_position */
56                                                 m_pes_position++;
57                                         p++;
58                                         len--;
59                                         continue;
60                                 }
61                         }
62                         m_pes_buffer[m_pes_position++] = *p++; len--;
63                         if (m_pes_position == 6)
64                         {
65                                 m_pes_length = ((m_pes_buffer[4] << 8) | m_pes_buffer[5]) + 6;
66                         }
67                 }
68         }
69 }