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)
23 /* this is a state machine, handling arbitary amounts of pes-formatted data. */
26 if (m_pes_position >= 6) // length ok?
28 int max = m_pes_length - m_pes_position;
31 memcpy(m_pes_buffer + m_pes_position, p, max);
32 m_pes_position += max;
37 if (m_pes_position == m_pes_length)
39 processPESPacket(m_pes_buffer, m_pes_position);
44 if (m_pes_position < 4)
46 unsigned char ch = *p;
47 if (m_pes_position == 3)
48 ch &= m_stream_id_mask;
49 if (ch != m_header[m_pes_position])
51 // eDebug("sync lost at %d (%02x)", m_pes_position, *p);
53 while (m_header[m_pes_position] == ch) /* guaranteed to stop at the old m_pes_position */
60 m_pes_buffer[m_pes_position++] = *p++; len--;
61 if (m_pes_position == 6)
63 m_pes_length = ((m_pes_buffer[4] << 8) | m_pes_buffer[5]) + 6;