Commit 07b93dcf authored by Max Kellermann's avatar Max Kellermann

InputStream: make Seek() always absolute

Remove the "whence" parameter that is not actually necessary, and only complicates the InputStream implementations.
parent 374c6a27
...@@ -125,7 +125,7 @@ struct ZzipInputStream final : public InputStream { ...@@ -125,7 +125,7 @@ struct ZzipInputStream final : public InputStream {
/* virtual methods from InputStream */ /* virtual methods from InputStream */
bool IsEOF() override; bool IsEOF() override;
size_t Read(void *ptr, size_t size, Error &error) 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;
}; };
InputStream * InputStream *
...@@ -165,9 +165,9 @@ ZzipInputStream::IsEOF() ...@@ -165,9 +165,9 @@ ZzipInputStream::IsEOF()
} }
bool bool
ZzipInputStream::Seek(offset_type new_offset, int whence, Error &error) ZzipInputStream::Seek(offset_type new_offset, Error &error)
{ {
zzip_off_t ofs = zzip_seek(file, new_offset, whence); zzip_off_t ofs = zzip_seek(file, new_offset, SEEK_SET);
if (ofs != -1) { if (ofs != -1) {
error.Set(zzip_domain, "zzip_seek() has failed"); error.Set(zzip_domain, "zzip_seek() has failed");
offset = ofs; offset = ofs;
......
...@@ -92,13 +92,17 @@ audiofile_file_destroy(AFvirtualfile *vfile) ...@@ -92,13 +92,17 @@ audiofile_file_destroy(AFvirtualfile *vfile)
} }
static AFfileoffset static AFfileoffset
audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset offset, int is_relative) audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset _offset,
int is_relative)
{ {
InputStream &is = *(InputStream *)vfile->closure; InputStream &is = *(InputStream *)vfile->closure;
int whence = (is_relative ? SEEK_CUR : SEEK_SET);
InputStream::offset_type offset = _offset;
if (is_relative)
offset += is.GetOffset();
Error error; Error error;
if (is.LockSeek(offset, whence, error)) { if (is.LockSeek(offset, IgnoreError())) {
return is.GetOffset(); return is.GetOffset();
} else { } else {
return -1; return -1;
......
...@@ -30,9 +30,7 @@ ...@@ -30,9 +30,7 @@
#include "tag/TagId3.hxx" #include "tag/TagId3.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include <unistd.h>
#include <string.h> #include <string.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
#ifdef HAVE_ID3TAG #ifdef HAVE_ID3TAG
#include <id3tag.h> #include <id3tag.h>
...@@ -63,7 +61,7 @@ dsdlib_skip_to(Decoder *decoder, InputStream &is, ...@@ -63,7 +61,7 @@ dsdlib_skip_to(Decoder *decoder, InputStream &is,
int64_t offset) int64_t offset)
{ {
if (is.IsSeekable()) if (is.IsSeekable())
return is.Seek(offset, SEEK_SET, IgnoreError()); return is.Seek(offset, IgnoreError());
if (is.GetOffset() > offset) if (is.GetOffset() > offset)
return false; return false;
...@@ -96,7 +94,7 @@ dsdlib_skip(Decoder *decoder, InputStream &is, ...@@ -96,7 +94,7 @@ dsdlib_skip(Decoder *decoder, InputStream &is,
return true; return true;
if (is.IsSeekable()) if (is.IsSeekable())
return is.Seek(delta, SEEK_CUR, IgnoreError()); return is.Seek(is.GetOffset() + delta, IgnoreError());
char buffer[8192]; char buffer[8192];
while (delta > 0) { while (delta > 0) {
......
...@@ -186,7 +186,7 @@ faad_song_duration(DecoderBuffer *buffer, InputStream &is) ...@@ -186,7 +186,7 @@ faad_song_duration(DecoderBuffer *buffer, InputStream &is)
/* obtain the duration from the ADTS header */ /* obtain the duration from the ADTS header */
float song_length = adts_song_duration(buffer); float song_length = adts_song_duration(buffer);
is.LockSeek(tagsize, SEEK_SET, IgnoreError()); is.LockSeek(tagsize, IgnoreError());
decoder_buffer_clear(buffer); decoder_buffer_clear(buffer);
decoder_buffer_fill(buffer); decoder_buffer_fill(buffer);
......
...@@ -120,10 +120,29 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence) ...@@ -120,10 +120,29 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
{ {
AvioStream *stream = (AvioStream *)opaque; AvioStream *stream = (AvioStream *)opaque;
if (whence == AVSEEK_SIZE) switch (whence) {
case SEEK_SET:
break;
case SEEK_CUR:
pos += stream->input.GetOffset();
break;
case SEEK_END:
if (!stream->input.KnownSize())
return -1;
pos += stream->input.GetSize();
break;
case AVSEEK_SIZE:
return stream->input.GetSize(); return stream->input.GetSize();
if (!stream->input.LockSeek(pos, whence, IgnoreError())) default:
return -1;
}
if (!stream->input.LockSeek(pos, IgnoreError()))
return -1; return -1;
return stream->input.GetOffset(); return stream->input.GetOffset();
......
...@@ -62,12 +62,31 @@ FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle) ...@@ -62,12 +62,31 @@ FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
} }
static int static int
FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence) FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 _offset, int whence)
{ {
InputStream *is = (InputStream *)handle; InputStream *is = (InputStream *)handle;
Error error; InputStream::offset_type offset = _offset;
return is->LockSeek(offset, whence, error) ? 0 : -1; switch (whence) {
case SEEK_SET:
break;
case SEEK_CUR:
offset += is->GetOffset();
break;
case SEEK_END:
if (!is->KnownSize())
return -1;
offset += is->GetSize();
break;
default:
return -1;
}
return is->LockSeek(offset, IgnoreError()) ? 0 : -1;
} }
static FLAC__int64 static FLAC__int64
......
...@@ -51,7 +51,7 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset) ...@@ -51,7 +51,7 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
::Error error; ::Error error;
if (!input_stream.LockSeek(absolute_byte_offset, SEEK_SET, error)) { if (!input_stream.LockSeek(absolute_byte_offset, error)) {
LogError(error); LogError(error);
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
} }
......
...@@ -208,7 +208,7 @@ inline bool ...@@ -208,7 +208,7 @@ inline bool
MadDecoder::Seek(long offset) MadDecoder::Seek(long offset)
{ {
Error error; Error error;
if (!input_stream.LockSeek(offset, SEEK_SET, error)) if (!input_stream.LockSeek(offset, error))
return false; return false;
mad_stream_buffer(&stream, input_buffer, 0); mad_stream_buffer(&stream, input_buffer, 0);
......
...@@ -57,7 +57,7 @@ mpc_seek_cb(mpc_reader *reader, mpc_int32_t offset) ...@@ -57,7 +57,7 @@ mpc_seek_cb(mpc_reader *reader, mpc_int32_t offset)
struct mpc_decoder_data *data = struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data; (struct mpc_decoder_data *)reader->data;
return data->is.LockSeek(offset, SEEK_SET, IgnoreError()); return data->is.LockSeek(offset, IgnoreError());
} }
static mpc_int32_t static mpc_int32_t
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
#include "OggSyncState.hxx" #include "OggSyncState.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include <stdio.h>
bool bool
OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet) OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet)
{ {
...@@ -41,7 +39,7 @@ OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet) ...@@ -41,7 +39,7 @@ OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet)
bool bool
OggSeekPageAtOffset(OggSyncState &oy, ogg_stream_state &os, InputStream &is, OggSeekPageAtOffset(OggSyncState &oy, ogg_stream_state &os, InputStream &is,
InputStream::offset_type offset, int whence) InputStream::offset_type offset)
{ {
oy.Reset(); oy.Reset();
...@@ -49,7 +47,7 @@ OggSeekPageAtOffset(OggSyncState &oy, ogg_stream_state &os, InputStream &is, ...@@ -49,7 +47,7 @@ OggSeekPageAtOffset(OggSyncState &oy, ogg_stream_state &os, InputStream &is,
data */ data */
ogg_stream_reset(&os); ogg_stream_reset(&os);
return is.LockSeek(offset, whence, IgnoreError()) && return is.LockSeek(offset, IgnoreError()) &&
oy.ExpectPageSeekIn(os); oy.ExpectPageSeekIn(os);
} }
...@@ -57,12 +55,15 @@ bool ...@@ -57,12 +55,15 @@ bool
OggSeekFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet, OggSeekFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet,
InputStream &is) InputStream &is)
{ {
if (is.KnownSize() && is.GetRest() < 65536) if (!is.KnownSize())
return false;
if (is.GetRest() < 65536)
return OggFindEOS(oy, os, packet); return OggFindEOS(oy, os, packet);
if (!is.CheapSeeking()) if (!is.CheapSeeking())
return false; return false;
return OggSeekPageAtOffset(oy, os, is, -65536, SEEK_END) && return OggSeekPageAtOffset(oy, os, is, is.GetSize() - 65536) &&
OggFindEOS(oy, os, packet); OggFindEOS(oy, os, packet);
} }
...@@ -41,7 +41,7 @@ OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet); ...@@ -41,7 +41,7 @@ OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet);
*/ */
bool bool
OggSeekPageAtOffset(OggSyncState &oy, ogg_stream_state &os, InputStream &is, OggSeekPageAtOffset(OggSyncState &oy, ogg_stream_state &os, InputStream &is,
InputStream::offset_type offset, int whence); InputStream::offset_type offset);
/** /**
* Try to find the end-of-stream (EOS) packet. Seek to the end of the * Try to find the end-of-stream (EOS) packet. Seek to the end of the
......
...@@ -199,7 +199,7 @@ LoadEOSPacket(InputStream &is, Decoder *decoder, int serialno, ...@@ -199,7 +199,7 @@ LoadEOSPacket(InputStream &is, Decoder *decoder, int serialno,
ogg_stream_clear(&os); ogg_stream_clear(&os);
/* restore the previous file position */ /* restore the previous file position */
is.Seek(old_offset, SEEK_SET, IgnoreError()); is.Seek(old_offset, IgnoreError());
return result; return result;
} }
...@@ -344,7 +344,7 @@ MPDOpusDecoder::Seek(OggSyncState &oy, double where_s) ...@@ -344,7 +344,7 @@ MPDOpusDecoder::Seek(OggSyncState &oy, double where_s)
InputStream::offset_type offset(where_granulepos * input_stream.GetSize() InputStream::offset_type offset(where_granulepos * input_stream.GetSize()
/ eos_granulepos); / eos_granulepos);
if (!OggSeekPageAtOffset(oy, os, input_stream, offset, SEEK_SET)) if (!OggSeekPageAtOffset(oy, os, input_stream, offset))
return false; return false;
decoder_timestamp(decoder, where_s); decoder_timestamp(decoder, where_s);
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "Log.hxx" #include "Log.hxx"
#include <string.h> #include <string.h>
#include <stdio.h> /* for SEEK_SET */
static void static void
pcm_stream_decode(Decoder &decoder, InputStream &is) pcm_stream_decode(Decoder &decoder, InputStream &is)
...@@ -76,7 +75,7 @@ pcm_stream_decode(Decoder &decoder, InputStream &is) ...@@ -76,7 +75,7 @@ pcm_stream_decode(Decoder &decoder, InputStream &is)
decoder_seek_where(decoder)); decoder_seek_where(decoder));
Error error; Error error;
if (is.LockSeek(offset, SEEK_SET, error)) { if (is.LockSeek(offset, error)) {
decoder_command_finished(decoder); decoder_command_finished(decoder);
} else { } else {
LogError(error); LogError(error);
......
...@@ -41,11 +41,31 @@ sndfile_vio_get_filelen(void *user_data) ...@@ -41,11 +41,31 @@ sndfile_vio_get_filelen(void *user_data)
} }
static sf_count_t static sf_count_t
sndfile_vio_seek(sf_count_t offset, int whence, void *user_data) sndfile_vio_seek(sf_count_t _offset, int whence, void *user_data)
{ {
InputStream &is = *(InputStream *)user_data; InputStream &is = *(InputStream *)user_data;
if (!is.LockSeek(offset, whence, IgnoreError())) InputStream::offset_type offset = _offset;
switch (whence) {
case SEEK_SET:
break;
case SEEK_CUR:
offset += is.GetOffset();
break;
case SEEK_END:
if (!is.KnownSize())
return -1;
offset += is.GetSize();
break;
default:
return -1;
}
if (!is.LockSeek(offset, IgnoreError()))
return -1; return -1;
return is.GetOffset(); return is.GetOffset();
......
...@@ -70,15 +70,37 @@ static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *data) ...@@ -70,15 +70,37 @@ static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *data)
return ret / size; return ret / size;
} }
static int ogg_seek_cb(void *data, ogg_int64_t offset, int whence) static int ogg_seek_cb(void *data, ogg_int64_t _offset, int whence)
{ {
VorbisInputStream *vis = (VorbisInputStream *)data; VorbisInputStream *vis = (VorbisInputStream *)data;
InputStream &is = vis->input_stream;
Error error; if (!vis->seekable ||
return vis->seekable && (vis->decoder != nullptr &&
(vis->decoder == nullptr || decoder_get_command(*vis->decoder) == DecoderCommand::STOP))
decoder_get_command(*vis->decoder) != DecoderCommand::STOP) && return -1;
vis->input_stream.LockSeek(offset, whence, error)
InputStream::offset_type offset = _offset;
switch (whence) {
case SEEK_SET:
break;
case SEEK_CUR:
offset += is.GetOffset();
break;
case SEEK_END:
if (!is.KnownSize())
return -1;
offset += is.GetSize();
break;
default:
return -1;
}
return is.LockSeek(offset, IgnoreError())
? 0 : -1; ? 0 : -1;
} }
......
...@@ -392,13 +392,35 @@ wavpack_input_get_pos(void *id) ...@@ -392,13 +392,35 @@ wavpack_input_get_pos(void *id)
static int static int
wavpack_input_set_pos_abs(void *id, uint32_t pos) wavpack_input_set_pos_abs(void *id, uint32_t pos)
{ {
return wpin(id)->is.LockSeek(pos, SEEK_SET, IgnoreError()) ? 0 : -1; return wpin(id)->is.LockSeek(pos, IgnoreError()) ? 0 : -1;
} }
static int static int
wavpack_input_set_pos_rel(void *id, int32_t delta, int mode) wavpack_input_set_pos_rel(void *id, int32_t delta, int mode)
{ {
return wpin(id)->is.LockSeek(delta, mode, IgnoreError()) ? 0 : -1; InputStream &is = wpin(id)->is;
InputStream::offset_type offset = delta;
switch (mode) {
case SEEK_SET:
break;
case SEEK_CUR:
offset += is.GetOffset();
break;
case SEEK_END:
if (!is.KnownSize())
return -1;
offset += is.GetSize();
break;
default:
return -1;
}
return is.LockSeek(offset, IgnoreError()) ? 0 : -1;
} }
static int static int
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include <assert.h> #include <assert.h>
#include <stdio.h> /* for SEEK_SET */
InputStream::~InputStream() InputStream::~InputStream()
{ {
...@@ -75,29 +74,17 @@ InputStream::CheapSeeking() const ...@@ -75,29 +74,17 @@ InputStream::CheapSeeking() const
} }
bool 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) gcc_unused Error &error)
{ {
return false; return false;
} }
bool bool
InputStream::LockSeek(offset_type _offset, int whence, Error &error) InputStream::LockSeek(offset_type _offset, Error &error)
{ {
const ScopeLock protect(mutex); const ScopeLock protect(mutex);
return Seek(_offset, whence, error); return Seek(_offset, error);
}
bool
InputStream::Rewind(Error &error)
{
return Seek(0, SEEK_SET, error);
}
bool
InputStream::LockRewind(Error &error)
{
return LockSeek(0, SEEK_SET, error);
} }
Tag * Tag *
......
...@@ -275,22 +275,26 @@ public: ...@@ -275,22 +275,26 @@ public:
* The caller must lock the mutex. * The caller must lock the mutex.
* *
* @param offset the relative offset * @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 * Wrapper for Seek() which locks and unlocks the mutex; the
* caller must not be holding it already. * 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 * 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 Rewind(Error &error) {
bool LockRewind(Error &error); return Seek(0, error);
}
bool LockRewind(Error &error) {
return LockSeek(0, error);
}
/** /**
* Returns true if the stream has reached end-of-file. * Returns true if the stream has reached end-of-file.
......
...@@ -63,9 +63,9 @@ ProxyInputStream::Update() ...@@ -63,9 +63,9 @@ ProxyInputStream::Update()
} }
bool 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(); CopyAttributes();
return success; return success;
} }
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
/* virtual methods from InputStream */ /* virtual methods from InputStream */
bool Check(Error &error) override; bool Check(Error &error) override;
void Update() 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; bool IsEOF() override;
Tag *ReadTag() override; Tag *ReadTag() override;
bool IsAvailable() override; bool IsAvailable() override;
......
...@@ -99,7 +99,7 @@ class CdioParanoiaInputStream final : public InputStream { ...@@ -99,7 +99,7 @@ class CdioParanoiaInputStream final : public InputStream {
/* virtual methods from InputStream */ /* virtual methods from InputStream */
bool IsEOF() override; bool IsEOF() override;
size_t Read(void *ptr, size_t size, Error &error) 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"); static constexpr Domain cdio_domain("cdio");
...@@ -272,21 +272,8 @@ input_cdio_open(const char *uri, ...@@ -272,21 +272,8 @@ input_cdio_open(const char *uri,
} }
bool bool
CdioParanoiaInputStream::Seek(InputPlugin::offset_type new_offset, CdioParanoiaInputStream::Seek(offset_type new_offset, Error &error)
int whence, 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) { if (new_offset < 0 || new_offset > size) {
error.Format(cdio_domain, "Invalid offset to seek %ld (%ld)", error.Format(cdio_domain, "Invalid offset to seek %ld (%ld)",
(long int)new_offset, (long int)size); (long int)new_offset, (long int)size);
......
...@@ -175,7 +175,7 @@ struct CurlInputStream final : public InputStream { ...@@ -175,7 +175,7 @@ struct CurlInputStream final : public InputStream {
} }
size_t Read(void *ptr, size_t size, Error &error) 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;
}; };
class CurlMulti; class CurlMulti;
...@@ -887,12 +887,11 @@ CurlInputStream::InitEasy(Error &error) ...@@ -887,12 +887,11 @@ CurlInputStream::InitEasy(Error &error)
} }
inline bool inline bool
CurlInputStream::Seek(InputPlugin::offset_type new_offset, int whence, CurlInputStream::Seek(offset_type new_offset, Error &error)
Error &error)
{ {
assert(IsReady()); assert(IsReady());
if (whence == SEEK_SET && new_offset == offset) if (new_offset == offset)
/* no-op */ /* no-op */
return true; return true;
...@@ -901,26 +900,6 @@ CurlInputStream::Seek(InputPlugin::offset_type new_offset, int whence, ...@@ -901,26 +900,6 @@ CurlInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
/* calculate the absolute offset */ /* 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) if (new_offset < 0)
return false; return false;
......
...@@ -60,7 +60,7 @@ struct FfmpegInputStream final : public InputStream { ...@@ -60,7 +60,7 @@ struct FfmpegInputStream final : public InputStream {
/* virtual methods from InputStream */ /* virtual methods from InputStream */
bool IsEOF() override; bool IsEOF() override;
size_t Read(void *ptr, size_t size, Error &error) 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"); static constexpr Domain ffmpeg_domain("ffmpeg");
...@@ -134,9 +134,9 @@ FfmpegInputStream::IsEOF() ...@@ -134,9 +134,9 @@ FfmpegInputStream::IsEOF()
} }
bool 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) { if (ret >= 0) {
eof = false; eof = false;
......
...@@ -56,7 +56,7 @@ struct FileInputStream final : public InputStream { ...@@ -56,7 +56,7 @@ struct FileInputStream final : public InputStream {
} }
size_t Read(void *ptr, size_t size, Error &error) 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 InputStream * static InputStream *
...@@ -99,11 +99,9 @@ input_file_open(const char *filename, ...@@ -99,11 +99,9 @@ input_file_open(const char *filename,
} }
bool bool
FileInputStream::Seek(InputPlugin::offset_type new_offset, int whence, FileInputStream::Seek(offset_type new_offset, Error &error)
Error &error)
{ {
new_offset = (InputPlugin::offset_type)lseek(fd, (off_t)new_offset, new_offset = (offset_type)lseek(fd, (off_t)new_offset, SEEK_SET);
whence);
if (new_offset < 0) { if (new_offset < 0) {
error.SetErrno("Failed to seek"); error.SetErrno("Failed to seek");
return false; return false;
......
...@@ -61,7 +61,7 @@ public: ...@@ -61,7 +61,7 @@ public:
} }
size_t Read(void *ptr, size_t size, Error &error) 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;
}; };
size_t size_t
...@@ -77,10 +77,10 @@ NfsInputStream::Read(void *ptr, size_t read_size, Error &error) ...@@ -77,10 +77,10 @@ NfsInputStream::Read(void *ptr, size_t read_size, Error &error)
} }
bool bool
NfsInputStream::Seek(offset_type new_offset, int whence, Error &error) NfsInputStream::Seek(offset_type new_offset, Error &error)
{ {
uint64_t current_offset; 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); &current_offset);
if (result < 0) { if (result < 0) {
error.SetErrno(-result, "smbc_lseek() failed"); error.SetErrno(-result, "smbc_lseek() failed");
......
...@@ -64,7 +64,7 @@ public: ...@@ -64,7 +64,7 @@ public:
} }
size_t Read(void *ptr, size_t size, Error &error) 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;
private: private:
/** /**
...@@ -117,13 +117,12 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error) ...@@ -117,13 +117,12 @@ RewindInputStream::Read(void *ptr, size_t read_size, Error &error)
} }
bool bool
RewindInputStream::Seek(offset_type new_offset, int whence, RewindInputStream::Seek(offset_type new_offset,
Error &error) Error &error)
{ {
assert(IsReady()); assert(IsReady());
if (whence == SEEK_SET && tail > 0 && if (tail > 0 && new_offset <= (offset_type)tail) {
new_offset <= (offset_type)tail) {
/* buffered seek */ /* buffered seek */
assert(!ReadingFromBuffer() || assert(!ReadingFromBuffer() ||
...@@ -139,7 +138,7 @@ RewindInputStream::Seek(offset_type new_offset, int whence, ...@@ -139,7 +138,7 @@ RewindInputStream::Seek(offset_type new_offset, int whence,
buffered range now */ buffered range now */
tail = 0; tail = 0;
return ProxyInputStream::Seek(new_offset, whence, error); return ProxyInputStream::Seek(new_offset, error);
} }
} }
......
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
} }
size_t Read(void *ptr, size_t size, Error &error) 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;
}; };
/* /*
...@@ -136,11 +136,10 @@ SmbclientInputStream::Read(void *ptr, size_t read_size, Error &error) ...@@ -136,11 +136,10 @@ SmbclientInputStream::Read(void *ptr, size_t read_size, Error &error)
} }
bool bool
SmbclientInputStream::Seek(InputStream::offset_type new_offset, SmbclientInputStream::Seek(offset_type new_offset, Error &error)
int whence, Error &error)
{ {
smbclient_mutex.lock(); 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(); smbclient_mutex.unlock();
if (result < 0) { if (result < 0) {
error.SetErrno("smbc_lseek() failed"); error.SetErrno("smbc_lseek() failed");
......
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
ris->GetOffset()); ris->GetOffset());
CPPUNIT_ASSERT(!ris->IsEOF()); CPPUNIT_ASSERT(!ris->IsEOF());
CPPUNIT_ASSERT(ris->Seek(1, SEEK_SET, error)); CPPUNIT_ASSERT(ris->Seek(1, error));
CPPUNIT_ASSERT_EQUAL(InputStream::offset_type(1), CPPUNIT_ASSERT_EQUAL(InputStream::offset_type(1),
ris->GetOffset()); ris->GetOffset());
CPPUNIT_ASSERT(!ris->IsEOF()); CPPUNIT_ASSERT(!ris->IsEOF());
...@@ -105,7 +105,7 @@ public: ...@@ -105,7 +105,7 @@ public:
ris->GetOffset()); ris->GetOffset());
CPPUNIT_ASSERT(!ris->IsEOF()); CPPUNIT_ASSERT(!ris->IsEOF());
CPPUNIT_ASSERT(ris->Seek(0, SEEK_SET, error)); CPPUNIT_ASSERT(ris->Seek(0, error));
CPPUNIT_ASSERT_EQUAL(InputStream::offset_type(0), CPPUNIT_ASSERT_EQUAL(InputStream::offset_type(0),
ris->GetOffset()); ris->GetOffset());
CPPUNIT_ASSERT(!ris->IsEOF()); CPPUNIT_ASSERT(!ris->IsEOF());
...@@ -135,7 +135,7 @@ public: ...@@ -135,7 +135,7 @@ public:
ris->GetOffset()); ris->GetOffset());
CPPUNIT_ASSERT(ris->IsEOF()); CPPUNIT_ASSERT(ris->IsEOF());
CPPUNIT_ASSERT(ris->Seek(3, SEEK_SET, error)); CPPUNIT_ASSERT(ris->Seek(3, error));
CPPUNIT_ASSERT_EQUAL(InputStream::offset_type(3), CPPUNIT_ASSERT_EQUAL(InputStream::offset_type(3),
ris->GetOffset()); ris->GetOffset());
CPPUNIT_ASSERT(!ris->IsEOF()); CPPUNIT_ASSERT(!ris->IsEOF());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment