diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2006-05-12 15:17:24 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2006-05-12 15:17:24 +0000 |
| commit | 141be00b0febd77db0bca46e9a788f018d07aeb8 (patch) | |
| tree | c09e95f62c526670d889bfe24e68d778e33b9911 /lib | |
| parent | 29f1104e0e69589c5d78e3bdf4811fa6362fb4aa (diff) | |
| download | enigma2-141be00b0febd77db0bca46e9a788f018d07aeb8.tar.gz enigma2-141be00b0febd77db0bca46e9a788f018d07aeb8.zip | |
add pes parser
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dvb/Makefile.am | 3 | ||||
| -rw-r--r-- | lib/dvb/pesparse.cpp | 57 | ||||
| -rw-r--r-- | lib/dvb/pesparse.h | 17 |
3 files changed, 76 insertions, 1 deletions
diff --git a/lib/dvb/Makefile.am b/lib/dvb/Makefile.am index a255a616..49ed05ff 100644 --- a/lib/dvb/Makefile.am +++ b/lib/dvb/Makefile.am @@ -5,4 +5,5 @@ noinst_LIBRARIES = libenigma_dvb.a libenigma_dvb_a_SOURCES = dvb.cpp demux.cpp frontend.cpp esection.cpp db.cpp \ sec.cpp scan.cpp crc32.cpp pmt.cpp decoder.cpp eit.cpp rotor_calc.cpp \ - epgcache.cpp dvbtime.cpp metaparser.cpp volume.cpp tstools.cpp pvrparse.cpp + epgcache.cpp dvbtime.cpp metaparser.cpp volume.cpp tstools.cpp pvrparse.cpp \ + pesparse.cpp diff --git a/lib/dvb/pesparse.cpp b/lib/dvb/pesparse.cpp new file mode 100644 index 00000000..7e05c96a --- /dev/null +++ b/lib/dvb/pesparse.cpp @@ -0,0 +1,57 @@ +#include <lib/dvb/pesparse.h> +#include <memory.h> + +ePESParser::ePESParser() +{ + m_pes_position = 0; + m_pes_length = 0; + m_header[0] = 0; + m_header[1] = 0; + m_header[2] = 1; + setStreamID(0); /* must be overridden */ +} + +void ePESParser::setStreamID(unsigned char id) +{ + m_header[3] = id; +} + +void ePESParser::processData(unsigned char *p, int len) +{ + /* this is a state machine, handling arbitary amounts of pes-formatted data. */ + while (len) + { + if (m_pes_position >= 6) // length ok? + { + int max = m_pes_length - m_pes_position; + if (max > len) + max = len; + memcpy(m_pes_buffer + m_pes_position, p, max); + m_pes_position += max; + p += max; + + len -= max; + + if (m_pes_position == m_pes_length) + { + processPESPacket(m_pes_buffer, m_pes_position); + m_pes_position = 0; + } + } else + { + if (m_pes_position < 4) + if (*p != "\x00\x00\x01\xbd"[m_pes_position]) + { + m_pes_position = 0; + p++; + len--; + continue; + } + m_pes_buffer[m_pes_position++] = *p++; len--; + if (m_pes_position == 6) + { + m_pes_length = ((m_pes_buffer[4] << 8) | m_pes_buffer[5]) + 6; + } + } + } +} diff --git a/lib/dvb/pesparse.h b/lib/dvb/pesparse.h new file mode 100644 index 00000000..f2f59f94 --- /dev/null +++ b/lib/dvb/pesparse.h @@ -0,0 +1,17 @@ +#ifndef __lib_dvb_pesparse_h +#define __lib_dvb_pesparse_h + +class ePESParser +{ +public: + ePESParser(); + void setStreamID(unsigned char id); + void processData(unsigned char *data, int len); + virtual void processPESPacket(unsigned char *pkt, int len) = 0; +private: + unsigned char m_pes_buffer[65536]; + int m_pes_position, m_pes_length; + unsigned char m_header[4]; +}; + +#endif |
