From 96844b5bd92b331390597061efe140172979c34d Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 10 Nov 2010 17:13:44 +0100 Subject: [PATCH] migrate eDVBTsTools to new iDataSource seek function --- lib/dvb/tstools.cpp | 47 +++++++++++------------------------------------ lib/dvb/tstools.h | 2 +- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/lib/dvb/tstools.cpp b/lib/dvb/tstools.cpp index 7739f60..c7d9a41 100644 --- a/lib/dvb/tstools.cpp +++ b/lib/dvb/tstools.cpp @@ -37,8 +37,6 @@ int eDVBTSTools::openFile(const char *filename, int nostreaminfo) eRawFile *f = new eRawFile(); ePtr src = f; - eSingleLocker l(f->getLock()); - if (f->open(filename, 1) < 0) return -1; @@ -47,7 +45,7 @@ int eDVBTSTools::openFile(const char *filename, int nostreaminfo) return 0; } -void eDVBTSTools::setSource(ePtr source, const char *stream_info_filename) +void eDVBTSTools::setSource(ePtr &source, const char *stream_info_filename) { closeFile(); @@ -72,10 +70,8 @@ void eDVBTSTools::setSource(ePtr source, const char *stream_info_fi void eDVBTSTools::closeFile() { - if (m_source) { - eSingleLocker l(m_source->getLock()); + if (m_source) closeSource(); - } } void eDVBTSTools::setSyncPID(int pid) @@ -100,29 +96,19 @@ int eDVBTSTools::getPTS(off_t &offset, pts_t &pts, int fixed) offset -= offset % 188; - iDataSourcePositionRestorer r(m_source); - - eSingleLocker l(m_source->getLock()); - - if (m_source->lseek(offset, SEEK_SET) < 0) - { - eDebug("lseek failed"); - return -1; - } - int left = m_maxrange; while (left >= 188) { unsigned char packet[188]; - if (m_source->read(packet, 188) != 188) + if (m_source->read(offset, packet, 188) != 188) { eDebug("read error"); break; } left -= 188; offset += 188; - + if (packet[0] != 0x47) { eDebug("resync"); @@ -132,8 +118,8 @@ int eDVBTSTools::getPTS(off_t &offset, pts_t &pts, int fixed) if (packet[i] == 0x47) break; ++i; + --offset; } - offset = m_source->lseek(i - 188, SEEK_CUR); continue; } @@ -443,10 +429,6 @@ void eDVBTSTools::calcEnd() if (!m_source->valid()) return; - iDataSourcePositionRestorer r(m_source); - - eSingleLocker l(m_source->getLock()); - off_t end = m_source->lseek(0, SEEK_END); if (llabs(end - m_last_filelength) > 1*1024*1024) @@ -603,28 +585,22 @@ int eDVBTSTools::findPMT(int &pmt_pid, int &service_id) return -1; } - iDataSourcePositionRestorer r(m_source); - - eSingleLocker l(m_source->getLock()); - - if (m_source->lseek(0, SEEK_SET) < 0) - { - eDebug("seek failed"); - return -1; - } + off_t position=0; int left = 5*1024*1024; while (left >= 188) { unsigned char packet[188]; - if (m_source->read(packet, 188) != 188) + int ret = m_source->read(position, packet, 188); + if (ret != 188) { eDebug("read error"); break; } left -= 188; - + position += 188; + if (packet[0] != 0x47) { int i = 0; @@ -632,12 +608,11 @@ int eDVBTSTools::findPMT(int &pmt_pid, int &service_id) { if (packet[i] == 0x47) break; + --position; ++i; } - m_source->lseek(i - 188, SEEK_CUR); continue; } - int pid = ((packet[1] << 8) | packet[2]) & 0x1FFF; int pusi = !!(packet[1] & 0x40); diff --git a/lib/dvb/tstools.h b/lib/dvb/tstools.h index 41312c4..1192cd2 100644 --- a/lib/dvb/tstools.h +++ b/lib/dvb/tstools.h @@ -19,7 +19,7 @@ public: eDVBTSTools(); ~eDVBTSTools(); - void setSource(ePtr source, const char *streaminfo_filename=NULL); + void setSource(ePtr &source, const char *streaminfo_filename=NULL); void closeSource(); int openFile(const char *filename, int nostreaminfo = 0); -- 2.7.4