diff options
author | Max Kellermann <max@duempel.org> | 2014-05-22 10:10:16 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-05-22 13:52:00 +0200 |
commit | 07b93dcf8084bcae92fa1f33652723ca9c990db2 (patch) | |
tree | 5cfa3d13c14d68b70d54ade24169b84a7f614b8e /src/decoder/plugins/VorbisDecoderPlugin.cxx | |
parent | 374c6a27db790eb637feaeb9bd27ed82897d7953 (diff) | |
download | mpd-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/decoder/plugins/VorbisDecoderPlugin.cxx')
-rw-r--r-- | src/decoder/plugins/VorbisDecoderPlugin.cxx | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/decoder/plugins/VorbisDecoderPlugin.cxx b/src/decoder/plugins/VorbisDecoderPlugin.cxx index 4fe44e9e8..72542e3a2 100644 --- a/src/decoder/plugins/VorbisDecoderPlugin.cxx +++ b/src/decoder/plugins/VorbisDecoderPlugin.cxx @@ -70,15 +70,37 @@ static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *data) 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; + InputStream &is = vis->input_stream; - Error error; - return vis->seekable && - (vis->decoder == nullptr || - decoder_get_command(*vis->decoder) != DecoderCommand::STOP) && - vis->input_stream.LockSeek(offset, whence, error) + if (!vis->seekable || + (vis->decoder != nullptr && + decoder_get_command(*vis->decoder) == DecoderCommand::STOP)) + return -1; + + 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; } |