1 #include <lib/base/eerror.h>
2 #include <lib/dvb/pesparse.h>
5 ePESParser::ePESParser()
12 setStreamID(0); /* must be overridden */
15 void ePESParser::setStreamID(unsigned char id, unsigned char id_mask)
18 m_stream_id_mask = id_mask;
21 void ePESParser::processData(const __u8 *p, int len)
25 /* this is a state machine, handling arbitary amounts of pes-formatted data. */
28 if (m_pes_position >= 6) // length ok?
30 int max = m_pes_length - m_pes_position;
33 memcpy(m_pes_buffer + m_pes_position, p, max);
34 m_pes_position += max;
39 if (m_pes_position == m_pes_length)
41 processPESPacket(m_pes_buffer, m_pes_position);
46 if (m_pes_position < 4)
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])
53 // eDebug("sync lost at %d (%02x)", m_pes_position, *p);
55 while (m_header[m_pes_position] == ch) /* guaranteed to stop at the old m_pes_position */
62 m_pes_buffer[m_pes_position++] = *p++; len--;
63 if (m_pes_position == 6)
65 m_pes_length = ((m_pes_buffer[4] << 8) | m_pes_buffer[5]) + 6;