From bce2ef4220fecb2c2e296c85ec2fbef5794f4492 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 17 Dec 2009 14:58:54 +0100 Subject: [PATCH] lib/dvb/tstools.h/cpp: make eDVBTSTool thread safe (i.e. this fixes seeking in timeshift and seeking in files without additional startcode/accespoint file --- lib/dvb/tstools.cpp | 10 ++++++++-- lib/dvb/tstools.h | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/dvb/tstools.cpp b/lib/dvb/tstools.cpp index 2e5c5665..dafd70fe 100644 --- a/lib/dvb/tstools.cpp +++ b/lib/dvb/tstools.cpp @@ -7,6 +7,7 @@ #include eDVBTSTools::eDVBTSTools() + :m_file_lock(true) { m_pid = -1; m_maxrange = 256*1024; @@ -47,6 +48,7 @@ int eDVBTSTools::openFile(const char *filename, int nostreaminfo) m_samples_taken = 0; + eSingleLocker l(m_file_lock); if (m_file.open(filename, 1) < 0) return -1; return 0; @@ -54,6 +56,7 @@ int eDVBTSTools::openFile(const char *filename, int nostreaminfo) void eDVBTSTools::closeFile() { + eSingleLocker l(m_file_lock); m_file.close(); } @@ -78,7 +81,8 @@ int eDVBTSTools::getPTS(off_t &offset, pts_t &pts, int fixed) return -1; offset -= offset % 188; - + + eSingleLocker l(m_file_lock); if (m_file.lseek(offset, SEEK_SET) < 0) { eDebug("lseek failed"); @@ -355,7 +359,8 @@ void eDVBTSTools::calcEnd() { if (!m_file.valid()) return; - + + eSingleLocker l(m_file_lock); off_t end = m_file.lseek(0, SEEK_END); if (llabs(end - m_last_filelength) > 1*1024*1024) @@ -504,6 +509,7 @@ int eDVBTSTools::findPMT(int &pmt_pid, int &service_id) return -1; } + eSingleLocker l(m_file_lock); if (m_file.lseek(0, SEEK_SET) < 0) { eDebug("seek failed"); diff --git a/lib/dvb/tstools.h b/lib/dvb/tstools.h index c230a341..ed8b9241 100644 --- a/lib/dvb/tstools.h +++ b/lib/dvb/tstools.h @@ -4,6 +4,7 @@ #include #include #include +#include /* * Note: we're interested in PTS values, not STC values. @@ -75,9 +76,10 @@ public: private: int m_pid; int m_maxrange; - + + eSingleLock m_file_lock; eRawFile m_file; - + int m_begin_valid, m_end_valid; pts_t m_pts_begin, m_pts_end; off_t m_offset_begin, m_offset_end; -- 2.30.2