diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2006-02-15 01:20:15 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2006-02-15 01:20:15 +0000 |
| commit | ca329d3e86a98aacb0597d8581f5354cc99542e4 (patch) | |
| tree | 9245b99c8971d7ae0c50ea8cc5d09608599fc6b3 /lib/dvb/tstools.cpp | |
| parent | b62474db510d8ffea6d3501bdb6f96a0cb15d180 (diff) | |
| download | enigma2-ca329d3e86a98aacb0597d8581f5354cc99542e4.tar.gz enigma2-ca329d3e86a98aacb0597d8581f5354cc99542e4.zip | |
use cached pts/offsets when available, clean up
Diffstat (limited to 'lib/dvb/tstools.cpp')
| -rw-r--r-- | lib/dvb/tstools.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/dvb/tstools.cpp b/lib/dvb/tstools.cpp index bec17a56..72a5f16f 100644 --- a/lib/dvb/tstools.cpp +++ b/lib/dvb/tstools.cpp @@ -13,6 +13,8 @@ eDVBTSTools::eDVBTSTools() m_begin_valid = 0; m_end_valid = 0; + + m_use_streaminfo = 0; } eDVBTSTools::~eDVBTSTools() @@ -23,6 +25,14 @@ eDVBTSTools::~eDVBTSTools() int eDVBTSTools::openFile(const char *filename) { closeFile(); + + m_streaminfo.load((std::string(filename) + ".ap").c_str()); + + if (!m_streaminfo.empty()) + m_use_streaminfo = 1; + else + m_use_streaminfo = 0; + m_fd = ::open(filename, O_RDONLY); if (m_fd < 0) return -1; @@ -48,6 +58,14 @@ void eDVBTSTools::setSearchRange(int maxrange) /* getPTS extracts a pts value from any PID at a given offset. */ int eDVBTSTools::getPTS(off_t &offset, pts_t &pts) { + if (m_use_streaminfo) + { + off_t off = offset; + pts_t p = pts; + int r = m_streaminfo.getPTS(off, p); + eDebug("streaminfo result: %d, %08llx, %08llx", r, off, p); + } + if (m_fd < 0) return -1; @@ -112,6 +130,10 @@ int eDVBTSTools::getPTS(off_t &offset, pts_t &pts) pts |= ((unsigned long long)(pes[12]&0xFF)) << 7; pts |= ((unsigned long long)(pes[13]&0xFE)) >> 1; offset -= 188; + + /* convert to zero-based */ + fixupPTS(offset, pts); + eDebug("tstools result: %08llx, %08llx", offset, pts); return 0; } } @@ -119,6 +141,35 @@ int eDVBTSTools::getPTS(off_t &offset, pts_t &pts) return -1; } +int eDVBTSTools::fixupPTS(const off_t &offset, pts_t &now) +{ + if (m_use_streaminfo) + { + eDebug("streaminfo fixup, before %08llx", now); + int r = m_streaminfo.fixupPTS(offset, now); + eDebug("streaminfo fixup, after %08llx", now); + return r; + } else + { + /* for the simple case, we assume one epoch, with up to one wrap around in the middle. */ + calcBegin(); + off_t begin = 0; + pts_t pos; + if (getPTS(begin, pos)) + return -1; + if ((now < pos) && ((pos - now) < 90000 * 10)) + { + pos = 0; + return 0; + } + if (now < pos) /* wrap around */ + pos = now + 0x200000000LL - pos; + else + pos = now - pos; + return 0; + } +} + void eDVBTSTools::calcBegin() { if (m_fd < 0) |
