aboutsummaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-05-22 10:10:16 +0200
committerMax Kellermann <max@duempel.org>2014-05-22 13:52:00 +0200
commit07b93dcf8084bcae92fa1f33652723ca9c990db2 (patch)
tree5cfa3d13c14d68b70d54ade24169b84a7f614b8e /src/input
parent374c6a27db790eb637feaeb9bd27ed82897d7953 (diff)
downloadmpd-07b93dcf8084bcae92fa1f33652723ca9c990db2.tar.gz
mpd-07b93dcf8084bcae92fa1f33652723ca9c990db2.tar.xz
mpd-07b93dcf8084bcae92fa1f33652723ca9c990db2.zip
InputStream: make Seek() always absolute
Remove the "whence" parameter that is not actually necessary, and only complicates the InputStream implementations.
Diffstat (limited to 'src/input')
-rw-r--r--src/input/InputStream.cxx19
-rw-r--r--src/input/InputStream.hxx16
-rw-r--r--src/input/ProxyInputStream.cxx4
-rw-r--r--src/input/ProxyInputStream.hxx2
-rw-r--r--src/input/plugins/CdioParanoiaInputPlugin.cxx17
-rw-r--r--src/input/plugins/CurlInputPlugin.cxx27
-rw-r--r--src/input/plugins/FfmpegInputPlugin.cxx6
-rw-r--r--src/input/plugins/FileInputPlugin.cxx8
-rw-r--r--src/input/plugins/NfsInputPlugin.cxx6
-rw-r--r--src/input/plugins/RewindInputPlugin.cxx9
-rw-r--r--src/input/plugins/SmbclientInputPlugin.cxx7
11 files changed, 37 insertions, 84 deletions
diff --git a/src/input/InputStream.cxx b/src/input/InputStream.cxx
index e7307540d..657b9df09 100644
--- a/src/input/InputStream.cxx
+++ b/src/input/InputStream.cxx
@@ -23,7 +23,6 @@
#include "util/UriUtil.hxx"
#include <assert.h>
-#include <stdio.h> /* for SEEK_SET */
InputStream::~InputStream()
{
@@ -75,29 +74,17 @@ InputStream::CheapSeeking() const
}
bool
-InputStream::Seek(gcc_unused offset_type new_offset, gcc_unused int whence,
+InputStream::Seek(gcc_unused offset_type new_offset,
gcc_unused Error &error)
{
return false;
}
bool
-InputStream::LockSeek(offset_type _offset, int whence, Error &error)
+InputStream::LockSeek(offset_type _offset, Error &error)
{
const ScopeLock protect(mutex);
- return Seek(_offset, whence, error);
-}
-
-bool
-InputStream::Rewind(Error &error)
-{
- return Seek(0, SEEK_SET, error);
-}
-
-bool
-InputStream::LockRewind(Error &error)
-{
- return LockSeek(0, SEEK_SET, error);
+ return Seek(_offset, error);
}
Tag *
diff --git a/src/input/InputStream.hxx b/src/input/InputStream.hxx
index 5f754940b..25e99de3d 100644
--- a/src/input/InputStream.hxx
+++ b/src/input/InputStream.hxx
@@ -275,22 +275,26 @@ public:
* The caller must lock the mutex.
*
* @param offset the relative offset
- * @param whence the base of the seek, one of SEEK_SET, SEEK_CUR, SEEK_END
*/
- virtual bool Seek(offset_type offset, int whence, Error &error);
+ virtual bool Seek(offset_type offset, Error &error);
/**
* Wrapper for Seek() which locks and unlocks the mutex; the
* caller must not be holding it already.
*/
- bool LockSeek(offset_type offset, int whence, Error &error);
+ bool LockSeek(offset_type offset, Error &error);
/**
* Rewind to the beginning of the stream. This is a wrapper
- * for Seek(0, SEEK_SET, error).
+ * for Seek(0, error).
*/
- bool Rewind(Error &error);
- bool LockRewind(Error &error);
+ bool Rewind(Error &error) {
+ return Seek(0, error);
+ }
+
+ bool LockRewind(Error &error) {
+ return LockSeek(0, error);
+ }
/**
* Returns true if the stream has reached end-of-file.
diff --git a/src/input/ProxyInputStream.cxx b/src/input/ProxyInputStream.cxx
index 7b6e9f937..d65fb5df1 100644
--- a/src/input/ProxyInputStream.cxx
+++ b/src/input/ProxyInputStream.cxx
@@ -63,9 +63,9 @@ ProxyInputStream::Update()
}
bool
-ProxyInputStream::Seek(offset_type new_offset, int whence, Error &error)
+ProxyInputStream::Seek(offset_type new_offset, Error &error)
{
- bool success = input.Seek(new_offset, whence, error);
+ bool success = input.Seek(new_offset, error);
CopyAttributes();
return success;
}
diff --git a/src/input/ProxyInputStream.hxx b/src/input/ProxyInputStream.hxx
index b2049fbc0..727ae5917 100644
--- a/src/input/ProxyInputStream.hxx
+++ b/src/input/ProxyInputStream.hxx
@@ -45,7 +45,7 @@ public:
/* virtual methods from InputStream */
bool Check(Error &error) override;
void Update() override;
- bool Seek(offset_type new_offset, int whence, Error &error) override;
+ bool Seek(offset_type new_offset, Error &error) override;
bool IsEOF() override;
Tag *ReadTag() override;
bool IsAvailable() override;
diff --git a/src/input/plugins/CdioParanoiaInputPlugin.cxx b/src/input/plugins/CdioParanoiaInputPlugin.cxx
index 534084e0d..6f1ea976a 100644
--- a/src/input/plugins/CdioParanoiaInputPlugin.cxx
+++ b/src/input/plugins/CdioParanoiaInputPlugin.cxx
@@ -99,7 +99,7 @@ class CdioParanoiaInputStream final : public InputStream {
/* virtual methods from InputStream */
bool IsEOF() override;
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
static constexpr Domain cdio_domain("cdio");
@@ -272,21 +272,8 @@ input_cdio_open(const char *uri,
}
bool
-CdioParanoiaInputStream::Seek(InputPlugin::offset_type new_offset,
- int whence, Error &error)
+CdioParanoiaInputStream::Seek(offset_type new_offset, Error &error)
{
- /* calculate absolute offset */
- switch (whence) {
- case SEEK_SET:
- break;
- case SEEK_CUR:
- new_offset += offset;
- break;
- case SEEK_END:
- new_offset += size;
- break;
- }
-
if (new_offset < 0 || new_offset > size) {
error.Format(cdio_domain, "Invalid offset to seek %ld (%ld)",
(long int)new_offset, (long int)size);
diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx
index dc26e0aa2..e464a3ce0 100644
--- a/src/input/plugins/CurlInputPlugin.cxx
+++ b/src/input/plugins/CurlInputPlugin.cxx
@@ -175,7 +175,7 @@ struct CurlInputStream final : public InputStream {
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
class CurlMulti;
@@ -887,12 +887,11 @@ CurlInputStream::InitEasy(Error &error)
}
inline bool
-CurlInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
- Error &error)
+CurlInputStream::Seek(offset_type new_offset, Error &error)
{
assert(IsReady());
- if (whence == SEEK_SET && new_offset == offset)
+ if (new_offset == offset)
/* no-op */
return true;
@@ -901,26 +900,6 @@ CurlInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
/* calculate the absolute offset */
- switch (whence) {
- case SEEK_SET:
- break;
-
- case SEEK_CUR:
- new_offset += offset;
- break;
-
- case SEEK_END:
- if (size < 0)
- /* stream size is not known */
- return false;
-
- new_offset += size;
- break;
-
- default:
- return false;
- }
-
if (new_offset < 0)
return false;
diff --git a/src/input/plugins/FfmpegInputPlugin.cxx b/src/input/plugins/FfmpegInputPlugin.cxx
index 9ae07dbef..6e0260aee 100644
--- a/src/input/plugins/FfmpegInputPlugin.cxx
+++ b/src/input/plugins/FfmpegInputPlugin.cxx
@@ -60,7 +60,7 @@ struct FfmpegInputStream final : public InputStream {
/* virtual methods from InputStream */
bool IsEOF() override;
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
static constexpr Domain ffmpeg_domain("ffmpeg");
@@ -134,9 +134,9 @@ FfmpegInputStream::IsEOF()
}
bool
-FfmpegInputStream::Seek(offset_type new_offset, int whence, Error &error)
+FfmpegInputStream::Seek(offset_type new_offset, Error &error)
{
- int64_t ret = avio_seek(h, new_offset, whence);
+ int64_t ret = avio_seek(h, new_offset, SEEK_SET);
if (ret >= 0) {
eof = false;
diff --git a/src/input/plugins/FileInputPlugin.cxx b/src/input/plugins/FileInputPlugin.cxx
index 1035973b6..60c316567 100644
--- a/src/input/plugins/FileInputPlugin.cxx
+++ b/src/input/plugins/FileInputPlugin.cxx
@@ -56,7 +56,7 @@ struct FileInputStream final : public InputStream {
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
static InputStream *
@@ -99,11 +99,9 @@ input_file_open(const char *filename,
}
bool
-FileInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
- Error &error)
+FileInputStream::Seek(offset_type new_offset, Error &error)
{
- new_offset = (InputPlugin::offset_type)lseek(fd, (off_t)new_offset,
- whence);
+ new_offset = (offset_type)lseek(fd, (off_t)new_offset, SEEK_SET);
if (new_offset < 0) {
error.SetErrno("Failed to seek");
return false;
diff --git a/src/input/plugins/NfsInputPlugin.cxx b/src/input/plugins/NfsInputPlugin.cxx
index b73389662..c90f00257 100644
--- a/src/input/plugins/NfsInputPlugin.cxx
+++ b/src/input/plugins/NfsInputPlugin.cxx
@@ -61,7 +61,7 @@ public:
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
size_t
@@ -77,10 +77,10 @@ NfsInputStream::Read(void *ptr, size_t read_size, Error &error)
}
bool
-NfsInputStream::Seek(offset_type new_offset, int whence, Error &error)
+NfsInputStream::Seek(offset_type new_offset, Error &error)
{
uint64_t current_offset;
- int result = nfs_lseek(ctx, fh, new_offset, whence,
+ int result = nfs_lseek(ctx, fh, new_offset, SEEK_SET,
&current_offset);
if (result < 0) {
error.SetErrno(-result, "smbc_lseek() failed");
diff --git a/src/input/plugins/RewindInputPlugin.cxx b/src/input/plugins/RewindInputPlugin.cxx
index c18799c64..95f604044 100644
--- a/src/input/plugins/RewindInputPlugin.cxx
+++ b/src/input/plugins/RewindInputPlugin.cxx
@@ -64,7 +64,7 @@ public:
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
private:
/**
@@ -117,13 +117,12 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
}
bool
-RewindInputStream::Seek(offset_type new_offset, int whence,
+RewindInputStream::Seek(offset_type new_offset,
Error &error)
{
assert(IsReady());
- if (whence == SEEK_SET && tail > 0 &&
- new_offset <= (offset_type)tail) {
+ if (tail > 0 && new_offset <= (offset_type)tail) {
/* buffered seek */
assert(!ReadingFromBuffer() ||
@@ -139,7 +138,7 @@ RewindInputStream::Seek(offset_type new_offset, int whence,
buffered range now */
tail = 0;
- return ProxyInputStream::Seek(new_offset, whence, error);
+ return ProxyInputStream::Seek(new_offset, error);
}
}
diff --git a/src/input/plugins/SmbclientInputPlugin.cxx b/src/input/plugins/SmbclientInputPlugin.cxx
index aa1ba0381..79987180f 100644
--- a/src/input/plugins/SmbclientInputPlugin.cxx
+++ b/src/input/plugins/SmbclientInputPlugin.cxx
@@ -57,7 +57,7 @@ public:
}
size_t Read(void *ptr, size_t size, Error &error) override;
- bool Seek(offset_type offset, int whence, Error &error) override;
+ bool Seek(offset_type offset, Error &error) override;
};
/*
@@ -136,11 +136,10 @@ SmbclientInputStream::Read(void *ptr, size_t read_size, Error &error)
}
bool
-SmbclientInputStream::Seek(InputStream::offset_type new_offset,
- int whence, Error &error)
+SmbclientInputStream::Seek(offset_type new_offset, Error &error)
{
smbclient_mutex.lock();
- off_t result = smbc_lseek(fd, new_offset, whence);
+ off_t result = smbc_lseek(fd, new_offset, SEEK_SET);
smbclient_mutex.unlock();
if (result < 0) {
error.SetErrno("smbc_lseek() failed");