From f1027ed198535ce16cfb9c83ac802788ec750488 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 23 Oct 2013 21:22:29 +0200 Subject: InputStream: add method Rewind() --- src/DecoderThread.cxx | 5 +---- src/InputStream.cxx | 13 +++++++++++++ src/InputStream.hxx | 7 +++++++ src/PlaylistRegistry.cxx | 5 ++--- src/TagFile.cxx | 3 +-- src/decoder/FfmpegDecoderPlugin.cxx | 14 ++++---------- src/decoder/FlacDecoderPlugin.cxx | 6 +----- src/decoder/OpusDecoderPlugin.cxx | 3 +-- src/decoder/VorbisDecoderPlugin.cxx | 3 +-- 9 files changed, 31 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx index 4e2c4418a..b3f0e6f36 100644 --- a/src/DecoderThread.cxx +++ b/src/DecoderThread.cxx @@ -40,9 +40,6 @@ #include -#include -#include /* for SEEK_SET */ - static constexpr Domain decoder_thread_domain("decoder_thread"); /** @@ -128,7 +125,7 @@ decoder_stream_decode(const DecoderPlugin &plugin, return true; /* rewind the stream, so each plugin gets a fresh start */ - input_stream->Seek(0, SEEK_SET, IgnoreError()); + input_stream->Rewind(IgnoreError()); decoder.dc.Unlock(); diff --git a/src/InputStream.cxx b/src/InputStream.cxx index 52eef2caf..56ca57e55 100644 --- a/src/InputStream.cxx +++ b/src/InputStream.cxx @@ -27,6 +27,7 @@ #include "util/Domain.hxx" #include +#include /* for SEEK_SET */ static constexpr Domain input_domain("input"); @@ -113,6 +114,18 @@ input_stream::LockSeek(offset_type _offset, int whence, Error &error) return Seek(_offset, whence, error); } +bool +input_stream::Rewind(Error &error) +{ + return Seek(0, SEEK_SET, error); +} + +bool +input_stream::LockRewind(Error &error) +{ + return LockSeek(0, SEEK_SET, error); +} + Tag * input_stream::ReadTag() { diff --git a/src/InputStream.hxx b/src/InputStream.hxx index ac774f723..343f3277c 100644 --- a/src/InputStream.hxx +++ b/src/InputStream.hxx @@ -217,6 +217,13 @@ struct input_stream { */ bool LockSeek(offset_type offset, int whence, Error &error); + /** + * Rewind to the beginning of the stream. This is a wrapper + * for Seek(0, SEEK_SET, error). + */ + bool Rewind(Error &error); + bool LockRewind(Error &error); + /** * Returns true if the stream has reached end-of-file. * diff --git a/src/PlaylistRegistry.cxx b/src/PlaylistRegistry.cxx index f18f7c5e9..e29bd49c6 100644 --- a/src/PlaylistRegistry.cxx +++ b/src/PlaylistRegistry.cxx @@ -44,7 +44,6 @@ #include #include -#include const struct playlist_plugin *const playlist_plugins[] = { &extm3u_playlist_plugin, @@ -221,7 +220,7 @@ playlist_list_open_stream_mime2(struct input_stream *is, const char *mime) string_array_contains(plugin->mime_types, mime)) { /* rewind the stream, so each plugin gets a fresh start */ - is->Seek(0, SEEK_SET, IgnoreError()); + is->Rewind(IgnoreError()); auto playlist = playlist_plugin_open_stream(plugin, is); if (playlist != nullptr) @@ -261,7 +260,7 @@ playlist_list_open_stream_suffix(struct input_stream *is, const char *suffix) string_array_contains(plugin->suffixes, suffix)) { /* rewind the stream, so each plugin gets a fresh start */ - is->Seek(0, SEEK_SET, IgnoreError()); + is->Rewind(IgnoreError()); auto playlist = playlist_plugin_open_stream(plugin, is); if (playlist != nullptr) diff --git a/src/TagFile.cxx b/src/TagFile.cxx index c26bdecde..5e3711532 100644 --- a/src/TagFile.cxx +++ b/src/TagFile.cxx @@ -27,7 +27,6 @@ #include "thread/Cond.hxx" #include -#include /* for SEEK_SET */ bool tag_file_scan(const char *path_fs, @@ -71,7 +70,7 @@ tag_file_scan(const char *path_fs, *handler, handler_ctx)) break; - is->LockSeek(0, SEEK_SET, IgnoreError()); + is->LockRewind(IgnoreError()); } } diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx index 5092bdf9e..cba7f5e2d 100644 --- a/src/decoder/FfmpegDecoderPlugin.cxx +++ b/src/decoder/FfmpegDecoderPlugin.cxx @@ -31,15 +31,6 @@ #include "util/Domain.hxx" #include "LogV.hxx" -#include -#include -#include -#include -#include -#include -#include -#include - extern "C" { #include #include @@ -50,6 +41,9 @@ extern "C" { #include } +#include +#include + static constexpr Domain ffmpeg_domain("ffmpeg"); /* suppress the ffmpeg compatibility macro */ @@ -352,7 +346,7 @@ ffmpeg_probe(Decoder *decoder, struct input_stream *is) unsigned char buffer[BUFFER_SIZE]; size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE); - if (nbytes <= PADDING || !is->LockSeek(0, SEEK_SET, error)) + if (nbytes <= PADDING || !is->LockRewind(error)) return nullptr; /* some ffmpeg parsers (e.g. ac3_parser.c) read a few bytes diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx index 168dfdd19..10a052d3d 100644 --- a/src/decoder/FlacDecoderPlugin.cxx +++ b/src/decoder/FlacDecoderPlugin.cxx @@ -29,10 +29,6 @@ #include #include -#include - -#include -#include #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 #error libFLAC is too old @@ -340,7 +336,7 @@ oggflac_decode(Decoder &decoder, struct input_stream *input_stream) /* rewind the stream, because ogg_codec_detect() has moved it */ - input_stream->LockSeek(0, SEEK_SET, IgnoreError()); + input_stream->LockRewind(IgnoreError()); flac_decode_internal(decoder, input_stream, true); } diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx index 48267e104..1ef4b5f92 100644 --- a/src/decoder/OpusDecoderPlugin.cxx +++ b/src/decoder/OpusDecoderPlugin.cxx @@ -39,7 +39,6 @@ #include -#include #include static const opus_int32 opus_sample_rate = 48000; @@ -273,7 +272,7 @@ mpd_opus_stream_decode(Decoder &decoder, /* rewind the stream, because ogg_codec_detect() has moved it */ - input_stream->LockSeek(0, SEEK_SET, IgnoreError()); + input_stream->LockRewind(IgnoreError()); MPDOpusDecoder d(decoder, input_stream); OggSyncState oy(*input_stream, &decoder); diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx index 105ca018e..c1d3566e1 100644 --- a/src/decoder/VorbisDecoderPlugin.cxx +++ b/src/decoder/VorbisDecoderPlugin.cxx @@ -50,7 +50,6 @@ #include #include -#include struct vorbis_input_stream { Decoder *decoder; @@ -184,7 +183,7 @@ vorbis_stream_decode(Decoder &decoder, /* rewind the stream, because ogg_codec_detect() has moved it */ - input_stream->LockSeek(0, SEEK_SET, IgnoreError()); + input_stream->LockRewind(IgnoreError()); struct vorbis_input_stream vis; OggVorbis_File vf; -- cgit v1.2.3