aboutsummaryrefslogtreecommitdiff
path: root/lib/base
diff options
context:
space:
mode:
authorghost <andreas.monzner@multimedia-labs.de>2010-11-23 13:58:30 +0100
committerghost <andreas.monzner@multimedia-labs.de>2010-11-23 13:58:30 +0100
commit7b2960a205f3c3e3b421d1664cd38644b3ffb679 (patch)
treed57819fb0ff1eb5e64638bc584c54ae18816043f /lib/base
parentfc83dfbe60f36712953498b20a1c2f10737e7685 (diff)
parent7199d3c37e7e7065bd6943702b5864fa5186b9a8 (diff)
downloadenigma2-7b2960a205f3c3e3b421d1664cd38644b3ffb679.tar.gz
enigma2-7b2960a205f3c3e3b421d1664cd38644b3ffb679.zip
Merge branch 'bug_615_replace_rawfile'
Diffstat (limited to 'lib/base')
-rw-r--r--lib/base/filepush.cpp60
-rw-r--r--lib/base/filepush.h12
-rw-r--r--lib/base/idatasource.h19
-rw-r--r--lib/base/rawfile.cpp27
-rw-r--r--lib/base/rawfile.h15
5 files changed, 84 insertions, 49 deletions
diff --git a/lib/base/filepush.cpp b/lib/base/filepush.cpp
index 91f24ba0..af5a8bb6 100644
--- a/lib/base/filepush.cpp
+++ b/lib/base/filepush.cpp
@@ -29,7 +29,7 @@ void eFilePushThread::thread()
{
setIoPrio(prio_class, prio);
- off_t dest_pos = 0, source_pos = 0;
+ off_t dest_pos = 0;
size_t bytes_read = 0;
off_t current_span_offset = 0;
@@ -46,9 +46,7 @@ void eFilePushThread::thread()
sigaction(SIGUSR1, &act, 0);
hasStarted();
-
- source_pos = m_raw_source.lseek(0, SEEK_CUR);
-
+
/* m_stop must be evaluated after each syscall. */
while (!m_stop)
{
@@ -137,14 +135,12 @@ void eFilePushThread::thread()
if (m_sg && !current_span_remaining)
{
- m_sg->getNextSourceSpan(source_pos, bytes_read, current_span_offset, current_span_remaining);
+ m_sg->getNextSourceSpan(m_current_position, bytes_read, current_span_offset, current_span_remaining);
ASSERT(!(current_span_remaining % m_blocksize));
-
- if (source_pos != current_span_offset)
- source_pos = m_raw_source.lseek(current_span_offset, SEEK_SET);
+ m_current_position = current_span_offset;
bytes_read = 0;
}
-
+
size_t maxread = sizeof(m_buffer);
/* if we have a source span, don't read past the end */
@@ -157,9 +153,9 @@ void eFilePushThread::thread()
m_buf_start = 0;
m_filter_end = 0;
m_buf_end = 0;
-
+
if (maxread)
- m_buf_end = m_raw_source.read(m_buffer, maxread);
+ m_buf_end = m_source->read(m_current_position, m_buffer, maxread);
if (m_buf_end < 0)
{
@@ -177,10 +173,7 @@ void eFilePushThread::thread()
/* a read might be mis-aligned in case of a short read. */
int d = m_buf_end % m_blocksize;
if (d)
- {
- m_raw_source.lseek(-d, SEEK_CUR);
m_buf_end -= d;
- }
if (m_buf_end == 0)
{
@@ -216,18 +209,10 @@ void eFilePushThread::thread()
sleep(1);
continue;
}
-#if 0
- eDebug("FILEPUSH: end-of-file! (currently unhandled)");
- if (!m_raw_source.lseek(0, SEEK_SET))
- {
- eDebug("(looping)");
- continue;
- }
-#endif
break;
} else
{
- source_pos += m_buf_end;
+ m_current_position += m_buf_end;
bytes_read += m_buf_end;
if (m_sg)
current_span_remaining -= m_buf_end;
@@ -239,20 +224,30 @@ void eFilePushThread::thread()
eDebug("FILEPUSH THREAD STOP");
}
-void eFilePushThread::start(int fd_source, int fd_dest)
+void eFilePushThread::start(int fd, int fd_dest)
{
- m_raw_source.setfd(fd_source);
- m_fd_dest = fd_dest;
- resume();
+ eRawFile *f = new eRawFile();
+ ePtr<iDataSource> source = f;
+ f->setfd(fd);
+ start(source, fd_dest);
}
-int eFilePushThread::start(const char *filename, int fd_dest)
+int eFilePushThread::start(const char *file, int fd_dest)
{
- if (m_raw_source.open(filename) < 0)
+ eRawFile *f = new eRawFile();
+ ePtr<iDataSource> source = f;
+ if (f->open(file) < 0)
return -1;
+ start(source, fd_dest);
+ return 0;
+}
+
+void eFilePushThread::start(ePtr<iDataSource> &source, int fd_dest)
+{
+ m_source = source;
m_fd_dest = fd_dest;
+ m_current_position = 0;
resume();
- return 0;
}
void eFilePushThread::stop()
@@ -273,11 +268,6 @@ void eFilePushThread::pause()
stop();
}
-void eFilePushThread::seek(int whence, off_t where)
-{
- m_raw_source.lseek(where, whence);
-}
-
void eFilePushThread::resume()
{
m_stop = 0;
diff --git a/lib/base/filepush.h b/lib/base/filepush.h
index 71ee9979..eb8e7924 100644
--- a/lib/base/filepush.h
+++ b/lib/base/filepush.h
@@ -24,9 +24,10 @@ public:
void stop();
void start(int sourcefd, int destfd);
int start(const char *filename, int destfd);
-
+
+ void start(ePtr<iDataSource> &source, int destfd);
+
void pause();
- void seek(int whence, off_t where);
void resume();
/* flushes the internal readbuffer */
@@ -57,11 +58,12 @@ private:
int m_send_pvr_commit;
int m_stream_mode;
int m_blocksize;
+ off_t m_current_position;
+
+ ePtr<iDataSource> m_source;
- eRawFile m_raw_source;
-
eFixedMessagePump<int> m_messagepump;
-
+
void recvEvent(const int &evt);
};
diff --git a/lib/base/idatasource.h b/lib/base/idatasource.h
new file mode 100644
index 00000000..0daa5267
--- /dev/null
+++ b/lib/base/idatasource.h
@@ -0,0 +1,19 @@
+#ifndef __lib_base_idatasource_h
+#define __lib_base_idatasource_h
+
+#include <lib/base/object.h>
+
+class iDataSource: public iObject
+{
+public:
+ /* NOTE: should only be used to get current position or filelength */
+ virtual off_t lseek(off_t offset, int whence)=0;
+
+ /* NOTE: you must be able to handle short reads! */
+ virtual ssize_t read(off_t offset, void *buf, size_t count)=0; /* NOTE: this is what you in normal case have to use!! */
+
+ virtual off_t length()=0;
+ virtual int valid()=0;
+};
+
+#endif
diff --git a/lib/base/rawfile.cpp b/lib/base/rawfile.cpp
index c7e11feb..3a09e07e 100644
--- a/lib/base/rawfile.cpp
+++ b/lib/base/rawfile.cpp
@@ -4,7 +4,10 @@
#include <lib/base/rawfile.h>
#include <lib/base/eerror.h>
+DEFINE_REF(eRawFile);
+
eRawFile::eRawFile()
+ :m_lock(false)
{
m_fd = -1;
m_file = 0;
@@ -53,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)
@@ -61,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);
}
}
@@ -100,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)
diff --git a/lib/base/rawfile.h b/lib/base/rawfile.h
index a1c73d6a..1720d581 100644
--- a/lib/base/rawfile.h
+++ b/lib/base/rawfile.h
@@ -2,24 +2,27 @@
#define __lib_base_rawfile_h
#include <string>
+#include <lib/base/idatasource.h>
-class eRawFile
+class eRawFile: public iDataSource
{
+ DECLARE_REF(eRawFile);
+ eSingleLock m_lock;
public:
eRawFile();
~eRawFile();
-
int open(const char *filename, int cached = 0);
void setfd(int fd);
- off_t lseek(off_t offset, int whence);
int close();
- ssize_t read(void *buf, size_t count); /* NOTE: you must be able to handle short reads! */
+
+ // iDataSource
+ off_t lseek(off_t offset, int whence);
+ ssize_t read(off_t offset, void *buf, size_t count);
off_t length();
int valid();
private:
int m_fd; /* for uncached */
FILE *m_file; /* for cached */
-
int m_cached;
std::string m_basename;
off_t m_splitsize, m_totallength, m_current_offset, m_base_offset, m_last_offset;
@@ -27,6 +30,8 @@ private:
void scan();
int m_current_file;
int switchOffset(off_t off);
+
+ off_t lseek_internal(off_t offset, int whence);
FILE *openFileCached(int nr);
int openFileUncached(int nr);
};