X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fbase%2Frawfile.cpp;h=3a09e07eef2b2a4f663200fcc4666eadcbe59c52;hp=1552203ae358952b9b324eb280b5440f5bcae4e3;hb=fe619dbed1c9bf14a0d442cc16d7e968769bbcc0;hpb=81b7cc6b1815ec6f0f0c42d6a826d56c8b35033b diff --git a/lib/base/rawfile.cpp b/lib/base/rawfile.cpp index 1552203..3a09e07 100644 --- a/lib/base/rawfile.cpp +++ b/lib/base/rawfile.cpp @@ -7,7 +7,7 @@ DEFINE_REF(eRawFile); eRawFile::eRawFile() - :m_lock(true) + :m_lock(false) { m_fd = -1; m_file = 0; @@ -56,6 +56,13 @@ void eRawFile::setfd(int fd) off_t eRawFile::lseek(off_t offset, int whence) { + eSingleLocker l(m_lock); + m_current_offset = lseek_internal(offset, whence); + return m_current_offset; +} + +off_t eRawFile::lseek_internal(off_t offset, int whence) +{ // eDebug("lseek: %lld, %d", offset, whence); /* if there is only one file, use the native lseek - the file could be growing! */ if (m_nrfiles < 2) @@ -64,7 +71,8 @@ off_t eRawFile::lseek(off_t offset, int whence) return ::lseek(m_fd, offset, whence); else { - ::fseeko(m_file, offset, whence); + if (::fseeko(m_file, offset, whence) < 0) + perror("fseeko"); return ::ftello(m_file); } } @@ -103,11 +111,19 @@ int eRawFile::close() } } -ssize_t eRawFile::read(void *buf, size_t count) +ssize_t eRawFile::read(off_t offset, void *buf, size_t count) { -// eDebug("read: %p, %d", buf, count); + eSingleLocker l(m_lock); + + if (offset != m_current_offset) + { + m_current_offset = lseek_internal(offset, SEEK_SET); + if (m_current_offset < 0) + return m_current_offset; + } + switchOffset(m_current_offset); - + if (m_nrfiles >= 2) { if (m_current_offset + count > m_totallength) @@ -235,20 +251,3 @@ off_t eRawFile::length() { return m_totallength; } - -off_t eRawFile::position() -{ - if (m_nrfiles < 2) - { - if (!m_cached) - return ::lseek(m_fd, 0, SEEK_CUR); - else - return ::fseeko(m_file, 0, SEEK_CUR); - } - return m_current_offset; -} - -eSingleLock &eRawFile::getLock() -{ - return m_lock; -}