From 93deb844996120b6326345d6d87e803142dd1968 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 23 Oct 2013 22:08:59 +0200 Subject: [PATCH] input_stream: rename struct to InputStream --- src/ArchiveFile.hxx | 8 ++-- src/ArchivePlugin.hxx | 2 +- src/DecoderAPI.cxx | 23 +++++----- src/DecoderAPI.hxx | 22 +++++++-- src/DecoderBuffer.cxx | 9 ++-- src/DecoderBuffer.hxx | 4 +- src/DecoderInternal.hxx | 2 +- src/DecoderPlugin.hxx | 14 +++--- src/DecoderThread.cxx | 33 +++++++------ src/InputPlugin.hxx | 24 +++++----- src/InputStream.cxx | 44 +++++++++--------- src/InputStream.hxx | 14 +++--- src/PlaylistAny.cxx | 8 ++-- src/PlaylistAny.hxx | 4 +- src/PlaylistMapper.cxx | 8 ++-- src/PlaylistMapper.hxx | 4 +- src/PlaylistPlugin.hxx | 6 +-- src/PlaylistPrint.cxx | 2 +- src/PlaylistQueue.cxx | 2 +- src/PlaylistRegistry.cxx | 27 ++++++----- src/PlaylistRegistry.hxx | 6 +-- src/TagFile.cxx | 8 ++-- src/TextInputStream.cxx | 2 +- src/TextInputStream.hxx | 6 +-- src/archive/Bzip2ArchivePlugin.cxx | 22 ++++----- src/archive/Iso9660ArchivePlugin.cxx | 16 +++---- src/archive/ZzipArchivePlugin.cxx | 18 ++++---- src/decoder/AudiofileDecoderPlugin.cxx | 28 ++++++------ src/decoder/DsdLib.cxx | 30 ++++++------ src/decoder/DsdLib.hxx | 9 ++-- src/decoder/DsdiffDecoderPlugin.cxx | 56 +++++++++++------------ src/decoder/DsfDecoderPlugin.cxx | 14 +++--- src/decoder/FaadDecoderPlugin.cxx | 18 ++++---- src/decoder/FfmpegDecoderPlugin.cxx | 30 ++++++------ src/decoder/FlacCommon.cxx | 4 +- src/decoder/FlacCommon.hxx | 4 +- src/decoder/FlacDecoderPlugin.cxx | 16 +++---- src/decoder/FlacIOHandle.cxx | 10 ++-- src/decoder/FlacIOHandle.hxx | 8 ++-- src/decoder/FlacInput.cxx | 16 +++---- src/decoder/FlacInput.hxx | 7 +-- src/decoder/FlacMetadata.hxx | 4 +- src/decoder/MadDecoderPlugin.cxx | 34 +++++++------- src/decoder/ModplugDecoderPlugin.cxx | 16 +++---- src/decoder/MpcdecDecoderPlugin.cxx | 29 ++++++------ src/decoder/OggCodec.cxx | 2 +- src/decoder/OggCodec.hxx | 2 +- src/decoder/OggSyncState.hxx | 16 +++---- src/decoder/OggUtil.cxx | 12 ++--- src/decoder/OggUtil.hxx | 16 +++---- src/decoder/OpusDecoderPlugin.cxx | 22 ++++----- src/decoder/PcmDecoderPlugin.cxx | 16 +++---- src/decoder/SndfileDecoderPlugin.cxx | 22 ++++----- src/decoder/VorbisDecoderPlugin.cxx | 18 ++++---- src/decoder/WavpackDecoderPlugin.cxx | 28 ++++++------ src/input/ArchiveInputPlugin.cxx | 4 +- src/input/CdioParanoiaInputPlugin.cxx | 12 ++--- src/input/CurlInputPlugin.cxx | 20 ++++---- src/input/DespotifyInputPlugin.cxx | 12 ++--- src/input/FfmpegInputPlugin.cxx | 12 ++--- src/input/FileInputPlugin.cxx | 12 ++--- src/input/MmsInputPlugin.cxx | 10 ++-- src/input/RewindInputPlugin.cxx | 30 ++++++------ src/input/RewindInputPlugin.hxx | 6 +-- src/playlist/AsxPlaylistPlugin.cxx | 4 +- src/playlist/CuePlaylistPlugin.cxx | 6 +-- src/playlist/ExtM3uPlaylistPlugin.cxx | 4 +- src/playlist/M3uPlaylistPlugin.cxx | 4 +- src/playlist/PlsPlaylistPlugin.cxx | 4 +- src/playlist/RssPlaylistPlugin.cxx | 4 +- src/playlist/SoundCloudPlaylistPlugin.cxx | 4 +- src/playlist/XspfPlaylistPlugin.cxx | 4 +- test/dump_playlist.cxx | 17 ++++--- test/dump_text_file.cxx | 25 +++++----- test/read_tags.cxx | 13 +++--- test/run_decoder.cxx | 14 +++--- test/run_input.cxx | 6 +-- 77 files changed, 530 insertions(+), 522 deletions(-) diff --git a/src/ArchiveFile.hxx b/src/ArchiveFile.hxx index b771409b7..4bdba62ab 100644 --- a/src/ArchiveFile.hxx +++ b/src/ArchiveFile.hxx @@ -46,13 +46,13 @@ public: virtual void Visit(ArchiveVisitor &visitor) = 0; /** - * Opens an input_stream of a file within the archive. + * Opens an InputStream of a file within the archive. * * @param path the path within the archive */ - virtual input_stream *OpenStream(const char *path, - Mutex &mutex, Cond &cond, - Error &error) = 0; + virtual InputStream *OpenStream(const char *path, + Mutex &mutex, Cond &cond, + Error &error) = 0; }; #endif diff --git a/src/ArchivePlugin.hxx b/src/ArchivePlugin.hxx index cbc2e9816..6439c7242 100644 --- a/src/ArchivePlugin.hxx +++ b/src/ArchivePlugin.hxx @@ -20,7 +20,7 @@ #ifndef MPD_ARCHIVE_PLUGIN_HXX #define MPD_ARCHIVE_PLUGIN_HXX -struct input_stream; +struct InputStream; class ArchiveFile; class ArchiveVisitor; class Error; diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx index c2f1267c1..546aec033 100644 --- a/src/DecoderAPI.cxx +++ b/src/DecoderAPI.cxx @@ -251,7 +251,7 @@ decoder_check_cancel_read(const Decoder *decoder) size_t decoder_read(Decoder *decoder, - struct input_stream *is, + InputStream &is, void *buffer, size_t length) { /* XXX don't allow decoder==nullptr */ @@ -259,35 +259,34 @@ decoder_read(Decoder *decoder, assert(decoder == nullptr || decoder->dc.state == DecoderState::START || decoder->dc.state == DecoderState::DECODE); - assert(is != nullptr); assert(buffer != nullptr); if (length == 0) return 0; - is->Lock(); + is.Lock(); while (true) { if (decoder_check_cancel_read(decoder)) { - is->Unlock(); + is.Unlock(); return 0; } - if (is->IsAvailable()) + if (is.IsAvailable()) break; - is->cond.wait(is->mutex); + is.cond.wait(is.mutex); } Error error; - size_t nbytes = is->Read(buffer, length, error); + size_t nbytes = is.Read(buffer, length, error); assert(nbytes == 0 || !error.IsDefined()); - assert(nbytes > 0 || error.IsDefined() || is->IsEOF()); + assert(nbytes > 0 || error.IsDefined() || is.IsEOF()); if (gcc_unlikely(nbytes == 0 && error.IsDefined())) LogError(error); - is->Unlock(); + is.Unlock(); return nbytes; } @@ -329,7 +328,7 @@ do_send_tag(Decoder &decoder, const Tag &tag) } static bool -update_stream_tag(Decoder &decoder, struct input_stream *is) +update_stream_tag(Decoder &decoder, InputStream *is) { Tag *tag; @@ -353,7 +352,7 @@ update_stream_tag(Decoder &decoder, struct input_stream *is) DecoderCommand decoder_data(Decoder &decoder, - struct input_stream *is, + InputStream *is, const void *data, size_t length, uint16_t kbit_rate) { @@ -462,7 +461,7 @@ decoder_data(Decoder &decoder, } DecoderCommand -decoder_tag(Decoder &decoder, struct input_stream *is, +decoder_tag(Decoder &decoder, InputStream *is, Tag &&tag) { gcc_unused const decoder_control &dc = decoder.dc; diff --git a/src/DecoderAPI.hxx b/src/DecoderAPI.hxx index 4b3664297..3abb077ca 100644 --- a/src/DecoderAPI.hxx +++ b/src/DecoderAPI.hxx @@ -99,11 +99,11 @@ decoder_seek_error(Decoder &decoder); * occurs: end of file; error; command (like SEEK or STOP). */ size_t -decoder_read(Decoder *decoder, struct input_stream *is, +decoder_read(Decoder *decoder, InputStream &is, void *buffer, size_t length); static inline size_t -decoder_read(Decoder &decoder, input_stream *is, +decoder_read(Decoder &decoder, InputStream &is, void *buffer, size_t length) { return decoder_read(&decoder, is, buffer, length); @@ -131,10 +131,18 @@ decoder_timestamp(Decoder &decoder, double t); * command pending */ DecoderCommand -decoder_data(Decoder &decoder, struct input_stream *is, +decoder_data(Decoder &decoder, InputStream *is, const void *data, size_t length, uint16_t kbit_rate); +static inline DecoderCommand +decoder_data(Decoder &decoder, InputStream &is, + const void *data, size_t length, + uint16_t kbit_rate) +{ + return decoder_data(decoder, &is, data, length, kbit_rate); +} + /** * This function is called by the decoder plugin when it has * successfully decoded a tag. @@ -147,7 +155,13 @@ decoder_data(Decoder &decoder, struct input_stream *is, * command pending */ DecoderCommand -decoder_tag(Decoder &decoder, struct input_stream *is, Tag &&tag); +decoder_tag(Decoder &decoder, InputStream *is, Tag &&tag); + +static inline DecoderCommand +decoder_tag(Decoder &decoder, InputStream &is, Tag &&tag) +{ + return decoder_tag(decoder, &is, std::move(tag)); +} /** * Set replay gain values for the following chunks. diff --git a/src/DecoderBuffer.cxx b/src/DecoderBuffer.cxx index 16e6e7f7f..6aad53cb2 100644 --- a/src/DecoderBuffer.cxx +++ b/src/DecoderBuffer.cxx @@ -28,7 +28,7 @@ struct DecoderBuffer { Decoder *decoder; - struct input_stream *is; + InputStream *is; /** the allocated size of the buffer */ size_t size; @@ -45,17 +45,16 @@ struct DecoderBuffer { }; DecoderBuffer * -decoder_buffer_new(Decoder *decoder, struct input_stream *is, +decoder_buffer_new(Decoder *decoder, InputStream &is, size_t size) { DecoderBuffer *buffer = (DecoderBuffer *) g_malloc(sizeof(*buffer) - sizeof(buffer->data) + size); - assert(is != nullptr); assert(size > 0); buffer->decoder = decoder; - buffer->is = is; + buffer->is = &is; buffer->size = size; buffer->length = 0; buffer->consumed = 0; @@ -105,7 +104,7 @@ decoder_buffer_fill(DecoderBuffer *buffer) /* buffer is full */ return false; - nbytes = decoder_read(buffer->decoder, buffer->is, + nbytes = decoder_read(buffer->decoder, *buffer->is, buffer->data + buffer->length, buffer->size - buffer->length); if (nbytes == 0) diff --git a/src/DecoderBuffer.hxx b/src/DecoderBuffer.hxx index cba788d0b..92cc31aa4 100644 --- a/src/DecoderBuffer.hxx +++ b/src/DecoderBuffer.hxx @@ -30,7 +30,7 @@ struct DecoderBuffer; struct Decoder; -struct input_stream; +struct InputStream; /** * Creates a new buffer. @@ -41,7 +41,7 @@ struct input_stream; * @return the new decoder_buffer object */ DecoderBuffer * -decoder_buffer_new(Decoder *decoder, struct input_stream *is, +decoder_buffer_new(Decoder *decoder, InputStream &is, size_t size); /** diff --git a/src/DecoderInternal.hxx b/src/DecoderInternal.hxx index 742357d5f..07c682f19 100644 --- a/src/DecoderInternal.hxx +++ b/src/DecoderInternal.hxx @@ -25,7 +25,7 @@ #include "ReplayGainInfo.hxx" struct decoder_control; -struct input_stream; +struct InputStream; struct Tag; struct Decoder { diff --git a/src/DecoderPlugin.hxx b/src/DecoderPlugin.hxx index 600d4e3b3..6b0340123 100644 --- a/src/DecoderPlugin.hxx +++ b/src/DecoderPlugin.hxx @@ -23,7 +23,7 @@ #include "Compiler.h" struct config_param; -struct input_stream; +struct InputStream; struct Tag; struct tag_handler; @@ -59,7 +59,7 @@ struct DecoderPlugin { * possible, it is recommended to implement this method, * because it is more versatile. */ - void (*stream_decode)(Decoder &decoder, input_stream *is); + void (*stream_decode)(Decoder &decoder, InputStream &is); /** * Decode a local file. @@ -82,7 +82,7 @@ struct DecoderPlugin { * * @return false if the operation has failed */ - bool (*scan_stream)(struct input_stream *is, + bool (*scan_stream)(InputStream &is, const struct tag_handler *handler, void *handler_ctx); @@ -127,8 +127,8 @@ struct DecoderPlugin { /** * Decode a stream. */ - void StreamDecode(Decoder &decoder, input_stream &is) const { - stream_decode(decoder, &is); + void StreamDecode(Decoder &decoder, InputStream &is) const { + stream_decode(decoder, is); } /** @@ -151,10 +151,10 @@ struct DecoderPlugin { /** * Read the tag of a stream. */ - bool ScanStream(input_stream &is, + bool ScanStream(InputStream &is, const tag_handler &handler, void *handler_ctx) const { return scan_stream != nullptr - ? scan_stream(&is, &handler, handler_ctx) + ? scan_stream(is, &handler, handler_ctx) : false; } diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx index 3364f23b3..513fdb663 100644 --- a/src/DecoderThread.cxx +++ b/src/DecoderThread.cxx @@ -67,12 +67,12 @@ decoder_command_finished_locked(decoder_control &dc) * @return an input_stream on success or if #DecoderCommand::STOP is * received, nullptr on error */ -static struct input_stream * +static InputStream * decoder_input_stream_open(decoder_control &dc, const char *uri) { Error error; - input_stream *is = input_stream::Open(uri, dc.mutex, dc.cond, error); + InputStream *is = InputStream::Open(uri, dc.mutex, dc.cond, error); if (is == nullptr) { if (error.IsDefined()) LogError(error); @@ -108,13 +108,12 @@ decoder_input_stream_open(decoder_control &dc, const char *uri) static bool decoder_stream_decode(const DecoderPlugin &plugin, Decoder &decoder, - struct input_stream *input_stream) + InputStream &input_stream) { assert(plugin.stream_decode != nullptr); assert(decoder.stream_tag == nullptr); assert(decoder.decoder_tag == nullptr); - assert(input_stream != nullptr); - assert(input_stream->ready); + assert(input_stream.ready); assert(decoder.dc.state == DecoderState::START); FormatDebug(decoder_thread_domain, "probing plugin %s", plugin.name); @@ -123,11 +122,11 @@ decoder_stream_decode(const DecoderPlugin &plugin, return true; /* rewind the stream, so each plugin gets a fresh start */ - input_stream->Rewind(IgnoreError()); + input_stream.Rewind(IgnoreError()); decoder.dc.Unlock(); - plugin.StreamDecode(decoder, *input_stream); + plugin.StreamDecode(decoder, input_stream); decoder.dc.Lock(); @@ -167,7 +166,7 @@ decoder_file_decode(const DecoderPlugin &plugin, gcc_pure static bool -decoder_check_plugin_mime(const DecoderPlugin &plugin, const input_stream &is) +decoder_check_plugin_mime(const DecoderPlugin &plugin, const InputStream &is) { assert(plugin.stream_decode != nullptr); @@ -185,7 +184,7 @@ decoder_check_plugin_suffix(const DecoderPlugin &plugin, const char *suffix) gcc_pure static bool -decoder_check_plugin(const DecoderPlugin &plugin, const input_stream &is, +decoder_check_plugin(const DecoderPlugin &plugin, const InputStream &is, const char *suffix) { return plugin.stream_decode != nullptr && @@ -194,7 +193,7 @@ decoder_check_plugin(const DecoderPlugin &plugin, const input_stream &is, } static bool -decoder_run_stream_plugin(Decoder &decoder, input_stream &is, +decoder_run_stream_plugin(Decoder &decoder, InputStream &is, const char *suffix, const DecoderPlugin &plugin, bool &tried_r) @@ -203,11 +202,11 @@ decoder_run_stream_plugin(Decoder &decoder, input_stream &is, return false; tried_r = true; - return decoder_stream_decode(plugin, decoder, &is); + return decoder_stream_decode(plugin, decoder, is); } static bool -decoder_run_stream_locked(Decoder &decoder, input_stream &is, +decoder_run_stream_locked(Decoder &decoder, InputStream &is, const char *uri, bool &tried_r) { const char *const suffix = uri_get_suffix(uri); @@ -223,7 +222,7 @@ decoder_run_stream_locked(Decoder &decoder, input_stream &is, * Try decoding a stream, using the fallback plugin. */ static bool -decoder_run_stream_fallback(Decoder &decoder, struct input_stream *is) +decoder_run_stream_fallback(Decoder &decoder, InputStream &is) { const struct DecoderPlugin *plugin; @@ -239,7 +238,7 @@ static bool decoder_run_stream(Decoder &decoder, const char *uri) { decoder_control &dc = decoder.dc; - struct input_stream *input_stream; + InputStream *input_stream; bool success; dc.Unlock(); @@ -259,7 +258,7 @@ decoder_run_stream(Decoder &decoder, const char *uri) /* fallback to mp3: this is needed for bastard streams that don't have a suffix or set the mimeType */ (!tried && - decoder_run_stream_fallback(decoder, input_stream)); + decoder_run_stream_fallback(decoder, *input_stream)); dc.Unlock(); input_stream->Close(); @@ -306,7 +305,7 @@ decoder_run_file(Decoder &decoder, const char *path_fs) dc.Unlock(); } else if (plugin->stream_decode != nullptr) { - struct input_stream *input_stream; + InputStream *input_stream; bool success; input_stream = decoder_input_stream_open(dc, path_fs); @@ -316,7 +315,7 @@ decoder_run_file(Decoder &decoder, const char *path_fs) dc.Lock(); success = decoder_stream_decode(*plugin, decoder, - input_stream); + *input_stream); dc.Unlock(); diff --git a/src/InputPlugin.hxx b/src/InputPlugin.hxx index 1a867b118..00226d195 100644 --- a/src/InputPlugin.hxx +++ b/src/InputPlugin.hxx @@ -27,7 +27,7 @@ #include struct config_param; -struct input_stream; +struct InputStream; class Error; struct Tag; @@ -50,10 +50,10 @@ struct InputPlugin { */ void (*finish)(void); - struct input_stream *(*open)(const char *uri, - Mutex &mutex, Cond &cond, - Error &error); - void (*close)(struct input_stream *is); + InputStream *(*open)(const char *uri, + Mutex &mutex, Cond &cond, + Error &error); + void (*close)(InputStream *is); /** * Check for errors that may have occurred in the I/O thread. @@ -61,15 +61,15 @@ struct InputPlugin { * * @return false on error */ - bool (*check)(struct input_stream *is, Error &error); + bool (*check)(InputStream *is, Error &error); /** * Update the public attributes. Call before access. Can be * nullptr if the plugin always keeps its attributes up to date. */ - void (*update)(struct input_stream *is); + void (*update)(InputStream *is); - Tag *(*tag)(struct input_stream *is); + Tag *(*tag)(InputStream *is); /** * Returns true if the next read operation will not block: @@ -79,12 +79,12 @@ struct InputPlugin { * If this method is unimplemented, then it is assumed that * reading will never block. */ - bool (*available)(struct input_stream *is); + bool (*available)(InputStream *is); - size_t (*read)(struct input_stream *is, void *ptr, size_t size, + size_t (*read)(InputStream *is, void *ptr, size_t size, Error &error); - bool (*eof)(struct input_stream *is); - bool (*seek)(struct input_stream *is, offset_type offset, int whence, + bool (*eof)(InputStream *is); + bool (*seek)(InputStream *is, offset_type offset, int whence, Error &error); }; diff --git a/src/InputStream.cxx b/src/InputStream.cxx index 56ca57e55..ca3c5618f 100644 --- a/src/InputStream.cxx +++ b/src/InputStream.cxx @@ -31,13 +31,13 @@ static constexpr Domain input_domain("input"); -struct input_stream * -input_stream::Open(const char *url, - Mutex &mutex, Cond &cond, - Error &error) +InputStream * +InputStream::Open(const char *url, + Mutex &mutex, Cond &cond, + Error &error) { input_plugins_for_each_enabled(plugin) { - struct input_stream *is; + InputStream *is; is = plugin->open(url, mutex, cond, error); if (is != nullptr) { @@ -58,20 +58,20 @@ input_stream::Open(const char *url, } bool -input_stream::Check(Error &error) +InputStream::Check(Error &error) { return plugin.check == nullptr || plugin.check(this, error); } void -input_stream::Update() +InputStream::Update() { if (plugin.update != nullptr) plugin.update(this); } void -input_stream::WaitReady() +InputStream::WaitReady() { while (true) { Update(); @@ -83,20 +83,20 @@ input_stream::WaitReady() } void -input_stream::LockWaitReady() +InputStream::LockWaitReady() { const ScopeLock protect(mutex); WaitReady(); } bool -input_stream::CheapSeeking() const +InputStream::CheapSeeking() const { return IsSeekable() && !uri_has_scheme(uri.c_str()); } bool -input_stream::Seek(offset_type _offset, int whence, Error &error) +InputStream::Seek(offset_type _offset, int whence, Error &error) { if (plugin.seek == nullptr) return false; @@ -105,7 +105,7 @@ input_stream::Seek(offset_type _offset, int whence, Error &error) } bool -input_stream::LockSeek(offset_type _offset, int whence, Error &error) +InputStream::LockSeek(offset_type _offset, int whence, Error &error) { if (plugin.seek == nullptr) return false; @@ -115,19 +115,19 @@ input_stream::LockSeek(offset_type _offset, int whence, Error &error) } bool -input_stream::Rewind(Error &error) +InputStream::Rewind(Error &error) { return Seek(0, SEEK_SET, error); } bool -input_stream::LockRewind(Error &error) +InputStream::LockRewind(Error &error) { return LockSeek(0, SEEK_SET, error); } Tag * -input_stream::ReadTag() +InputStream::ReadTag() { return plugin.tag != nullptr ? plugin.tag(this) @@ -135,7 +135,7 @@ input_stream::ReadTag() } Tag * -input_stream::LockReadTag() +InputStream::LockReadTag() { if (plugin.tag == nullptr) return nullptr; @@ -145,7 +145,7 @@ input_stream::LockReadTag() } bool -input_stream::IsAvailable() +InputStream::IsAvailable() { return plugin.available != nullptr ? plugin.available(this) @@ -153,7 +153,7 @@ input_stream::IsAvailable() } size_t -input_stream::Read(void *ptr, size_t _size, Error &error) +InputStream::Read(void *ptr, size_t _size, Error &error) { assert(ptr != nullptr); assert(_size > 0); @@ -162,7 +162,7 @@ input_stream::Read(void *ptr, size_t _size, Error &error) } size_t -input_stream::LockRead(void *ptr, size_t _size, Error &error) +InputStream::LockRead(void *ptr, size_t _size, Error &error) { assert(ptr != nullptr); assert(_size > 0); @@ -172,19 +172,19 @@ input_stream::LockRead(void *ptr, size_t _size, Error &error) } void -input_stream::Close() +InputStream::Close() { plugin.close(this); } bool -input_stream::IsEOF() +InputStream::IsEOF() { return plugin.eof(this); } bool -input_stream::LockIsEOF() +InputStream::LockIsEOF() { const ScopeLock protect(mutex); return IsEOF(); diff --git a/src/InputStream.hxx b/src/InputStream.hxx index 343f3277c..b1bc9c4ab 100644 --- a/src/InputStream.hxx +++ b/src/InputStream.hxx @@ -34,7 +34,7 @@ class Error; struct Tag; struct InputPlugin; -struct input_stream { +struct InputStream { typedef int64_t offset_type; /** @@ -93,8 +93,8 @@ struct input_stream { */ std::string mime; - input_stream(const InputPlugin &_plugin, - const char *_uri, Mutex &_mutex, Cond &_cond) + InputStream(const InputPlugin &_plugin, + const char *_uri, Mutex &_mutex, Cond &_cond) :plugin(_plugin), uri(_uri), mutex(_mutex), cond(_cond), ready(false), seekable(false), @@ -111,12 +111,12 @@ struct input_stream { * @param cond a cond that gets signalled when the state of * this object changes; may be nullptr if the caller doesn't want to get * notifications - * @return an #input_stream object on success, nullptr on error + * @return an #InputStream object on success, nullptr on error */ gcc_nonnull_all gcc_malloc - static input_stream *Open(const char *uri, Mutex &mutex, Cond &cond, - Error &error); + static InputStream *Open(const char *uri, Mutex &mutex, Cond &cond, + Error &error); /** * Close the input stream and free resources. @@ -273,7 +273,7 @@ struct input_stream { * * The caller must lock the mutex. * - * @param is the input_stream object + * @param is the InputStream object * @param ptr the buffer to read into * @param size the maximum number of bytes to read * @return the number of bytes read diff --git a/src/PlaylistAny.cxx b/src/PlaylistAny.cxx index 997c59a4e..52304700f 100644 --- a/src/PlaylistAny.cxx +++ b/src/PlaylistAny.cxx @@ -31,7 +31,7 @@ static SongEnumerator * playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond, - struct input_stream **is_r) + InputStream **is_r) { assert(uri_has_scheme(uri)); @@ -42,7 +42,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond, } Error error; - input_stream *is = input_stream::Open(uri, mutex, cond, error); + InputStream *is = InputStream::Open(uri, mutex, cond, error); if (is == nullptr) { if (error.IsDefined()) FormatError(error, "Failed to open %s", uri); @@ -50,7 +50,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond, return nullptr; } - playlist = playlist_list_open_stream(is, uri); + playlist = playlist_list_open_stream(*is, uri); if (playlist == nullptr) { is->Close(); return nullptr; @@ -62,7 +62,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond, SongEnumerator * playlist_open_any(const char *uri, Mutex &mutex, Cond &cond, - struct input_stream **is_r) + InputStream **is_r) { return uri_has_scheme(uri) ? playlist_open_remote(uri, mutex, cond, is_r) diff --git a/src/PlaylistAny.hxx b/src/PlaylistAny.hxx index 898057cdd..743db2e39 100644 --- a/src/PlaylistAny.hxx +++ b/src/PlaylistAny.hxx @@ -23,7 +23,7 @@ class Mutex; class Cond; class SongEnumerator; -struct input_stream; +struct InputStream; /** * Opens a playlist from the specified URI, which can be either an @@ -36,6 +36,6 @@ struct input_stream; */ SongEnumerator * playlist_open_any(const char *uri, Mutex &mutex, Cond &cond, - struct input_stream **is_r); + InputStream **is_r); #endif diff --git a/src/PlaylistMapper.cxx b/src/PlaylistMapper.cxx index 11e10f7ba..68ac22438 100644 --- a/src/PlaylistMapper.cxx +++ b/src/PlaylistMapper.cxx @@ -29,7 +29,7 @@ static SongEnumerator * playlist_open_path(const char *path_fs, Mutex &mutex, Cond &cond, - struct input_stream **is_r) + InputStream **is_r) { auto playlist = playlist_list_open_uri(path_fs, mutex, cond); if (playlist != nullptr) @@ -45,7 +45,7 @@ playlist_open_path(const char *path_fs, Mutex &mutex, Cond &cond, */ static SongEnumerator * playlist_open_in_playlist_dir(const char *uri, Mutex &mutex, Cond &cond, - struct input_stream **is_r) + InputStream **is_r) { assert(spl_valid_name(uri)); @@ -69,7 +69,7 @@ playlist_open_in_playlist_dir(const char *uri, Mutex &mutex, Cond &cond, */ static SongEnumerator * playlist_open_in_music_dir(const char *uri, Mutex &mutex, Cond &cond, - struct input_stream **is_r) + InputStream **is_r) { assert(uri_safe_local(uri)); @@ -82,7 +82,7 @@ playlist_open_in_music_dir(const char *uri, Mutex &mutex, Cond &cond, SongEnumerator * playlist_mapper_open(const char *uri, Mutex &mutex, Cond &cond, - struct input_stream **is_r) + InputStream **is_r) { if (spl_valid_name(uri)) { auto playlist = playlist_open_in_playlist_dir(uri, mutex, cond, diff --git a/src/PlaylistMapper.hxx b/src/PlaylistMapper.hxx index 69ed01d02..7132415f1 100644 --- a/src/PlaylistMapper.hxx +++ b/src/PlaylistMapper.hxx @@ -23,7 +23,7 @@ class Mutex; class Cond; class SongEnumerator; -struct input_stream; +struct InputStream; /** * Opens a playlist from an URI relative to the playlist or music @@ -35,6 +35,6 @@ struct input_stream; */ SongEnumerator * playlist_mapper_open(const char *uri, Mutex &mutex, Cond &cond, - struct input_stream **is_r); + InputStream **is_r); #endif diff --git a/src/PlaylistPlugin.hxx b/src/PlaylistPlugin.hxx index af2ceac47..6eb0f4771 100644 --- a/src/PlaylistPlugin.hxx +++ b/src/PlaylistPlugin.hxx @@ -21,7 +21,7 @@ #define MPD_PLAYLIST_PLUGIN_HXX struct config_param; -struct input_stream; +struct InputStream; struct Tag; class Mutex; class Cond; @@ -58,7 +58,7 @@ struct playlist_plugin { * either matched one of the suffixes or one of the MIME * types. */ - SongEnumerator *(*open_stream)(struct input_stream *is); + SongEnumerator *(*open_stream)(InputStream &is); const char *const*schemes; const char *const*suffixes; @@ -101,7 +101,7 @@ playlist_plugin_open_uri(const struct playlist_plugin *plugin, const char *uri, static inline SongEnumerator * playlist_plugin_open_stream(const struct playlist_plugin *plugin, - struct input_stream *is) + InputStream &is) { return plugin->open_stream(is); } diff --git a/src/PlaylistPrint.cxx b/src/PlaylistPrint.cxx index 95b77aa0d..8e3beaa47 100644 --- a/src/PlaylistPrint.cxx +++ b/src/PlaylistPrint.cxx @@ -175,7 +175,7 @@ playlist_file_print(Client &client, const char *uri, bool detail) Mutex mutex; Cond cond; - struct input_stream *is; + InputStream *is; SongEnumerator *playlist = playlist_open_any(uri, mutex, cond, &is); if (playlist == nullptr) return false; diff --git a/src/PlaylistQueue.cxx b/src/PlaylistQueue.cxx index ebb1bfffa..5d7773a86 100644 --- a/src/PlaylistQueue.cxx +++ b/src/PlaylistQueue.cxx @@ -72,7 +72,7 @@ playlist_open_into_queue(const char *uri, Mutex mutex; Cond cond; - struct input_stream *is; + InputStream *is; auto playlist = playlist_open_any(uri, mutex, cond, &is); if (playlist == nullptr) return PlaylistResult::NO_SUCH_LIST; diff --git a/src/PlaylistRegistry.cxx b/src/PlaylistRegistry.cxx index e29bd49c6..9afbe349d 100644 --- a/src/PlaylistRegistry.cxx +++ b/src/PlaylistRegistry.cxx @@ -209,9 +209,8 @@ playlist_list_open_uri(const char *uri, Mutex &mutex, Cond &cond) } static SongEnumerator * -playlist_list_open_stream_mime2(struct input_stream *is, const char *mime) +playlist_list_open_stream_mime2(InputStream &is, const char *mime) { - assert(is != nullptr); assert(mime != nullptr); playlist_plugins_for_each_enabled(plugin) { @@ -220,9 +219,10 @@ 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->Rewind(IgnoreError()); + is.Rewind(IgnoreError()); - auto playlist = playlist_plugin_open_stream(plugin, is); + auto playlist = playlist_plugin_open_stream(plugin, + is); if (playlist != nullptr) return playlist; } @@ -232,7 +232,7 @@ playlist_list_open_stream_mime2(struct input_stream *is, const char *mime) } static SongEnumerator * -playlist_list_open_stream_mime(struct input_stream *is, const char *full_mime) +playlist_list_open_stream_mime(InputStream &is, const char *full_mime) { assert(full_mime != nullptr); @@ -249,9 +249,8 @@ playlist_list_open_stream_mime(struct input_stream *is, const char *full_mime) } static SongEnumerator * -playlist_list_open_stream_suffix(struct input_stream *is, const char *suffix) +playlist_list_open_stream_suffix(InputStream &is, const char *suffix) { - assert(is != nullptr); assert(suffix != nullptr); playlist_plugins_for_each_enabled(plugin) { @@ -260,7 +259,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->Rewind(IgnoreError()); + is.Rewind(IgnoreError()); auto playlist = playlist_plugin_open_stream(plugin, is); if (playlist != nullptr) @@ -272,13 +271,13 @@ playlist_list_open_stream_suffix(struct input_stream *is, const char *suffix) } SongEnumerator * -playlist_list_open_stream(struct input_stream *is, const char *uri) +playlist_list_open_stream(InputStream &is, const char *uri) { const char *suffix; - is->LockWaitReady(); + is.LockWaitReady(); - const char *const mime = is->GetMimeType(); + const char *const mime = is.GetMimeType(); if (mime != nullptr) { auto playlist = playlist_list_open_stream_mime(is, mime); if (playlist != nullptr) @@ -311,7 +310,7 @@ playlist_suffix_supported(const char *suffix) SongEnumerator * playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond, - struct input_stream **is_r) + InputStream **is_r) { const char *suffix; @@ -322,7 +321,7 @@ playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond, return nullptr; Error error; - input_stream *is = input_stream::Open(path_fs, mutex, cond, error); + InputStream *is = InputStream::Open(path_fs, mutex, cond, error); if (is == nullptr) { if (error.IsDefined()) LogError(error); @@ -332,7 +331,7 @@ playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond, is->LockWaitReady(); - auto playlist = playlist_list_open_stream_suffix(is, suffix); + auto playlist = playlist_list_open_stream_suffix(*is, suffix); if (playlist != nullptr) *is_r = is; else diff --git a/src/PlaylistRegistry.hxx b/src/PlaylistRegistry.hxx index 72cd7222f..2b747316d 100644 --- a/src/PlaylistRegistry.hxx +++ b/src/PlaylistRegistry.hxx @@ -23,7 +23,7 @@ class Mutex; class Cond; class SongEnumerator; -struct input_stream; +struct InputStream; extern const struct playlist_plugin *const playlist_plugins[]; @@ -59,7 +59,7 @@ playlist_list_open_uri(const char *uri, Mutex &mutex, Cond &cond); * used to select the appropriate playlist plugin */ SongEnumerator * -playlist_list_open_stream(struct input_stream *is, const char *uri); +playlist_list_open_stream(InputStream &is, const char *uri); /** * Determines if there is a playlist plugin which can handle the @@ -78,6 +78,6 @@ playlist_suffix_supported(const char *suffix); */ SongEnumerator * playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond, - struct input_stream **is_r); + InputStream **is_r); #endif diff --git a/src/TagFile.cxx b/src/TagFile.cxx index 5e3711532..0e13b0530 100644 --- a/src/TagFile.cxx +++ b/src/TagFile.cxx @@ -46,7 +46,7 @@ tag_file_scan(const char *path_fs, if (plugin == nullptr) return false; - struct input_stream *is = nullptr; + InputStream *is = nullptr; Mutex mutex; Cond cond; @@ -58,11 +58,11 @@ tag_file_scan(const char *path_fs, /* fall back to stream tag */ if (plugin->scan_stream != nullptr) { - /* open the input_stream (if not already + /* open the InputStream (if not already open) */ if (is == nullptr) - is = input_stream::Open(path_fs, mutex, cond, - IgnoreError()); + is = InputStream::Open(path_fs, mutex, cond, + IgnoreError()); /* now try the stream_tag() method */ if (is != nullptr) { diff --git a/src/TextInputStream.cxx b/src/TextInputStream.cxx index f3664018a..36a726aa6 100644 --- a/src/TextInputStream.cxx +++ b/src/TextInputStream.cxx @@ -42,7 +42,7 @@ bool TextInputStream::ReadLine(std::string &line) --dest.size; Error error; - nbytes = is->LockRead(dest.data, dest.size, error); + nbytes = is.LockRead(dest.data, dest.size, error); if (nbytes > 0) buffer.Append(nbytes); else if (error.IsDefined()) { diff --git a/src/TextInputStream.hxx b/src/TextInputStream.hxx index f3d87c90a..8d606d5a9 100644 --- a/src/TextInputStream.hxx +++ b/src/TextInputStream.hxx @@ -24,11 +24,11 @@ #include -struct input_stream; +struct InputStream; struct fifo_buffer; class TextInputStream { - struct input_stream *is; + InputStream &is; FifoBuffer buffer; public: @@ -38,7 +38,7 @@ public: * * @param _is an open #input_stream object */ - explicit TextInputStream(struct input_stream *_is) + explicit TextInputStream(InputStream &_is) :is(_is) {} TextInputStream(const TextInputStream &) = delete; diff --git a/src/archive/Bzip2ArchivePlugin.cxx b/src/archive/Bzip2ArchivePlugin.cxx index c6bd7c40b..d1e6b51af 100644 --- a/src/archive/Bzip2ArchivePlugin.cxx +++ b/src/archive/Bzip2ArchivePlugin.cxx @@ -49,9 +49,9 @@ public: RefCount ref; std::string name; - struct input_stream *const istream; + InputStream *const istream; - Bzip2ArchiveFile(const char *path, input_stream *_is) + Bzip2ArchiveFile(const char *path, InputStream *_is) :ArchiveFile(bz2_archive_plugin), name(PathTraits::GetBaseUTF8(path)), istream(_is) { @@ -84,13 +84,13 @@ public: visitor.VisitArchiveEntry(name.c_str()); } - virtual input_stream *OpenStream(const char *path, - Mutex &mutex, Cond &cond, - Error &error) override; + virtual InputStream *OpenStream(const char *path, + Mutex &mutex, Cond &cond, + Error &error) override; }; struct Bzip2InputStream { - struct input_stream base; + InputStream base; Bzip2ArchiveFile *archive; @@ -148,7 +148,7 @@ bz2_open(const char *pathname, Error &error) { static Mutex mutex; static Cond cond; - input_stream *is = input_stream::Open(pathname, mutex, cond, error); + InputStream *is = InputStream::Open(pathname, mutex, cond, error); if (is == nullptr) return nullptr; @@ -170,7 +170,7 @@ Bzip2InputStream::~Bzip2InputStream() archive->Unref(); } -input_stream * +InputStream * Bzip2ArchiveFile::OpenStream(const char *path, Mutex &mutex, Cond &cond, Error &error) @@ -185,7 +185,7 @@ Bzip2ArchiveFile::OpenStream(const char *path, } static void -bz2_is_close(struct input_stream *is) +bz2_is_close(InputStream *is) { Bzip2InputStream *bis = (Bzip2InputStream *)is; @@ -215,7 +215,7 @@ bz2_fillbuffer(Bzip2InputStream *bis, Error &error) } static size_t -bz2_is_read(struct input_stream *is, void *ptr, size_t length, +bz2_is_read(InputStream *is, void *ptr, size_t length, Error &error) { Bzip2InputStream *bis = (Bzip2InputStream *)is; @@ -255,7 +255,7 @@ bz2_is_read(struct input_stream *is, void *ptr, size_t length, } static bool -bz2_is_eof(struct input_stream *is) +bz2_is_eof(InputStream *is) { Bzip2InputStream *bis = (Bzip2InputStream *)is; diff --git a/src/archive/Iso9660ArchivePlugin.cxx b/src/archive/Iso9660ArchivePlugin.cxx index 729efb589..8233d03f7 100644 --- a/src/archive/Iso9660ArchivePlugin.cxx +++ b/src/archive/Iso9660ArchivePlugin.cxx @@ -66,9 +66,9 @@ public: virtual void Visit(ArchiveVisitor &visitor) override; - virtual input_stream *OpenStream(const char *path, - Mutex &mutex, Cond &cond, - Error &error) override; + virtual InputStream *OpenStream(const char *path, + Mutex &mutex, Cond &cond, + Error &error) override; }; extern const InputPlugin iso9660_input_plugin; @@ -132,7 +132,7 @@ Iso9660ArchiveFile::Visit(ArchiveVisitor &visitor) /* single archive handling */ struct Iso9660InputStream { - struct input_stream base; + InputStream base; Iso9660ArchiveFile *archive; @@ -158,7 +158,7 @@ struct Iso9660InputStream { } }; -input_stream * +InputStream * Iso9660ArchiveFile::OpenStream(const char *pathname, Mutex &mutex, Cond &cond, Error &error) @@ -177,7 +177,7 @@ Iso9660ArchiveFile::OpenStream(const char *pathname, } static void -iso9660_input_close(struct input_stream *is) +iso9660_input_close(InputStream *is) { Iso9660InputStream *iis = (Iso9660InputStream *)is; @@ -186,7 +186,7 @@ iso9660_input_close(struct input_stream *is) static size_t -iso9660_input_read(struct input_stream *is, void *ptr, size_t size, +iso9660_input_read(InputStream *is, void *ptr, size_t size, Error &error) { Iso9660InputStream *iis = (Iso9660InputStream *)is; @@ -226,7 +226,7 @@ iso9660_input_read(struct input_stream *is, void *ptr, size_t size, } static bool -iso9660_input_eof(struct input_stream *is) +iso9660_input_eof(InputStream *is) { return is->offset == is->size; } diff --git a/src/archive/ZzipArchivePlugin.cxx b/src/archive/ZzipArchivePlugin.cxx index ee2f2e76a..973fe91dc 100644 --- a/src/archive/ZzipArchivePlugin.cxx +++ b/src/archive/ZzipArchivePlugin.cxx @@ -60,9 +60,9 @@ public: virtual void Visit(ArchiveVisitor &visitor) override; - virtual input_stream *OpenStream(const char *path, - Mutex &mutex, Cond &cond, - Error &error) override; + virtual InputStream *OpenStream(const char *path, + Mutex &mutex, Cond &cond, + Error &error) override; }; extern const InputPlugin zzip_input_plugin; @@ -99,7 +99,7 @@ ZzipArchiveFile::Visit(ArchiveVisitor &visitor) /* single archive handling */ struct ZzipInputStream { - struct input_stream base; + InputStream base; ZzipArchiveFile *archive; @@ -127,7 +127,7 @@ struct ZzipInputStream { } }; -input_stream * +InputStream * ZzipArchiveFile::OpenStream(const char *pathname, Mutex &mutex, Cond &cond, Error &error) @@ -147,7 +147,7 @@ ZzipArchiveFile::OpenStream(const char *pathname, } static void -zzip_input_close(struct input_stream *is) +zzip_input_close(InputStream *is) { ZzipInputStream *zis = (ZzipInputStream *)is; @@ -155,7 +155,7 @@ zzip_input_close(struct input_stream *is) } static size_t -zzip_input_read(struct input_stream *is, void *ptr, size_t size, +zzip_input_read(InputStream *is, void *ptr, size_t size, Error &error) { ZzipInputStream *zis = (ZzipInputStream *)is; @@ -173,7 +173,7 @@ zzip_input_read(struct input_stream *is, void *ptr, size_t size, } static bool -zzip_input_eof(struct input_stream *is) +zzip_input_eof(InputStream *is) { ZzipInputStream *zis = (ZzipInputStream *)is; @@ -181,7 +181,7 @@ zzip_input_eof(struct input_stream *is) } static bool -zzip_input_seek(struct input_stream *is, InputPlugin::offset_type offset, +zzip_input_seek(InputStream *is, InputPlugin::offset_type offset, int whence, Error &error) { ZzipInputStream *zis = (ZzipInputStream *)is; diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx index 5b3ffa642..ab3557e52 100644 --- a/src/decoder/AudiofileDecoderPlugin.cxx +++ b/src/decoder/AudiofileDecoderPlugin.cxx @@ -54,10 +54,10 @@ static int audiofile_get_duration(const char *file) static ssize_t audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length) { - struct input_stream *is = (struct input_stream *) vfile->closure; + InputStream &is = *(InputStream *)vfile->closure; Error error; - size_t nbytes = is->LockRead(data, length, error); + size_t nbytes = is.LockRead(data, length, error); if (nbytes == 0 && error.IsDefined()) { LogError(error); return -1; @@ -69,15 +69,15 @@ audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length) static AFfileoffset audiofile_file_length(AFvirtualfile *vfile) { - struct input_stream *is = (struct input_stream *) vfile->closure; - return is->GetSize(); + InputStream &is = *(InputStream *)vfile->closure; + return is.GetSize(); } static AFfileoffset audiofile_file_tell(AFvirtualfile *vfile) { - struct input_stream *is = (struct input_stream *) vfile->closure; - return is->GetOffset(); + InputStream &is = *(InputStream *)vfile->closure; + return is.GetOffset(); } static void @@ -91,22 +91,22 @@ audiofile_file_destroy(AFvirtualfile *vfile) static AFfileoffset audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset offset, int is_relative) { - struct input_stream *is = (struct input_stream *) vfile->closure; + InputStream &is = *(InputStream *)vfile->closure; int whence = (is_relative ? SEEK_CUR : SEEK_SET); Error error; - if (is->LockSeek(offset, whence, error)) { - return is->GetOffset(); + if (is.LockSeek(offset, whence, error)) { + return is.GetOffset(); } else { return -1; } } static AFvirtualfile * -setup_virtual_fops(struct input_stream *stream) +setup_virtual_fops(InputStream &stream) { AFvirtualfile *vf = new AFvirtualfile(); - vf->closure = stream; + vf->closure = &stream; vf->write = nullptr; vf->read = audiofile_file_read; vf->length = audiofile_file_length; @@ -157,7 +157,7 @@ audiofile_setup_sample_format(AFfilehandle af_fp) } static void -audiofile_stream_decode(Decoder &decoder, struct input_stream *is) +audiofile_stream_decode(Decoder &decoder, InputStream &is) { AFvirtualfile *vf; int fs, frame_count; @@ -168,7 +168,7 @@ audiofile_stream_decode(Decoder &decoder, struct input_stream *is) int ret; char chunk[CHUNK_SIZE]; - if (!is->IsSeekable()) { + if (!is.IsSeekable()) { LogWarning(audiofile_domain, "not seekable"); return; } @@ -196,7 +196,7 @@ audiofile_stream_decode(Decoder &decoder, struct input_stream *is) total_time = ((float)frame_count / (float)audio_format.sample_rate); - bit_rate = (uint16_t)(is->GetSize() * 8.0 / total_time / 1000.0 + 0.5); + bit_rate = (uint16_t)(is.GetSize() * 8.0 / total_time / 1000.0 + 0.5); fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1); diff --git a/src/decoder/DsdLib.cxx b/src/decoder/DsdLib.cxx index ab1a132fc..81ea9e5e8 100644 --- a/src/decoder/DsdLib.cxx +++ b/src/decoder/DsdLib.cxx @@ -51,7 +51,7 @@ dsdlib_id_equals(const struct dsdlib_id *id, const char *s) } bool -dsdlib_read(Decoder *decoder, struct input_stream *is, +dsdlib_read(Decoder *decoder, InputStream &is, void *data, size_t length) { size_t nbytes = decoder_read(decoder, is, data, length); @@ -62,27 +62,27 @@ dsdlib_read(Decoder *decoder, struct input_stream *is, * Skip the #input_stream to the specified offset. */ bool -dsdlib_skip_to(Decoder *decoder, struct input_stream *is, +dsdlib_skip_to(Decoder *decoder, InputStream &is, int64_t offset) { - if (is->IsSeekable()) - return is->Seek(offset, SEEK_SET, IgnoreError()); + if (is.IsSeekable()) + return is.Seek(offset, SEEK_SET, IgnoreError()); - if (is->GetOffset() > offset) + if (is.GetOffset() > offset) return false; char buffer[8192]; - while (is->GetOffset() < offset) { + while (is.GetOffset() < offset) { size_t length = sizeof(buffer); - if (offset - is->GetOffset() < (int64_t)length) - length = offset - is->GetOffset(); + if (offset - is.GetOffset() < (int64_t)length) + length = offset - is.GetOffset(); size_t nbytes = decoder_read(decoder, is, buffer, length); if (nbytes == 0) return false; } - assert(is->GetOffset() == offset); + assert(is.GetOffset() == offset); return true; } @@ -90,7 +90,7 @@ dsdlib_skip_to(Decoder *decoder, struct input_stream *is, * Skip some bytes from the #input_stream. */ bool -dsdlib_skip(Decoder *decoder, struct input_stream *is, +dsdlib_skip(Decoder *decoder, InputStream &is, int64_t delta) { assert(delta >= 0); @@ -98,8 +98,8 @@ dsdlib_skip(Decoder *decoder, struct input_stream *is, if (delta == 0) return true; - if (is->IsSeekable()) - return is->Seek(delta, SEEK_CUR, IgnoreError()); + if (is.IsSeekable()) + return is.Seek(delta, SEEK_CUR, IgnoreError()); char buffer[8192]; while (delta > 0) { @@ -124,7 +124,7 @@ dsdlib_skip(Decoder *decoder, struct input_stream *is, #ifdef HAVE_ID3TAG void -dsdlib_tag_id3(struct input_stream *is, +dsdlib_tag_id3(InputStream &is, const struct tag_handler *handler, void *handler_ctx, int64_t tagoffset) { @@ -140,8 +140,8 @@ dsdlib_tag_id3(struct input_stream *is, id3_length_t count; /* Prevent broken files causing problems */ - const auto size = is->GetSize(); - const auto offset = is->GetOffset(); + const auto size = is.GetSize(); + const auto offset = is.GetOffset(); if (offset >= size) return; diff --git a/src/decoder/DsdLib.hxx b/src/decoder/DsdLib.hxx index 261273091..3e21bffb0 100644 --- a/src/decoder/DsdLib.hxx +++ b/src/decoder/DsdLib.hxx @@ -24,6 +24,7 @@ #include struct Decoder; +struct InputStream; struct dsdlib_id { char value[4]; @@ -33,19 +34,19 @@ bool dsdlib_id_equals(const struct dsdlib_id *id, const char *s); bool -dsdlib_read(Decoder *decoder, struct input_stream *is, +dsdlib_read(Decoder *decoder, InputStream &is, void *data, size_t length); bool -dsdlib_skip_to(Decoder *decoder, struct input_stream *is, +dsdlib_skip_to(Decoder *decoder, InputStream &is, int64_t offset); bool -dsdlib_skip(Decoder *decoder, struct input_stream *is, +dsdlib_skip(Decoder *decoder, InputStream &is, int64_t delta); void -dsdlib_tag_id3(struct input_stream *is, +dsdlib_tag_id3(InputStream &is, const struct tag_handler *handler, void *handler_ctx, int64_t tagoffset); diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx index 3f768f60f..f39679a30 100644 --- a/src/decoder/DsdiffDecoderPlugin.cxx +++ b/src/decoder/DsdiffDecoderPlugin.cxx @@ -72,13 +72,13 @@ struct DsdiffMetaData { bool bitreverse; uint64_t chunk_size; #ifdef HAVE_ID3TAG - input_stream::offset_type id3_offset; + InputStream::offset_type id3_offset; uint64_t id3_size; #endif /** offset for artist tag */ - input_stream::offset_type diar_offset; + InputStream::offset_type diar_offset; /** offset for title tag */ - input_stream::offset_type diti_offset; + InputStream::offset_type diti_offset; }; static bool lsbitfirst; @@ -91,21 +91,21 @@ dsdiff_init(const config_param ¶m) } static bool -dsdiff_read_id(Decoder *decoder, struct input_stream *is, +dsdiff_read_id(Decoder *decoder, InputStream &is, struct dsdlib_id *id) { return dsdlib_read(decoder, is, id, sizeof(*id)); } static bool -dsdiff_read_chunk_header(Decoder *decoder, struct input_stream *is, +dsdiff_read_chunk_header(Decoder *decoder, InputStream &is, DsdiffChunkHeader *header) { return dsdlib_read(decoder, is, header, sizeof(*header)); } static bool -dsdiff_read_payload(Decoder *decoder, struct input_stream *is, +dsdiff_read_payload(Decoder *decoder, InputStream &is, const DsdiffChunkHeader *header, void *data, size_t length) { @@ -121,16 +121,16 @@ dsdiff_read_payload(Decoder *decoder, struct input_stream *is, * Read and parse a "SND" chunk inside "PROP". */ static bool -dsdiff_read_prop_snd(Decoder *decoder, struct input_stream *is, +dsdiff_read_prop_snd(Decoder *decoder, InputStream &is, DsdiffMetaData *metadata, - input_stream::offset_type end_offset) + InputStream::offset_type end_offset) { DsdiffChunkHeader header; - while ((input_stream::offset_type)(is->GetOffset() + sizeof(header)) <= end_offset) { + while ((InputStream::offset_type)(is.GetOffset() + sizeof(header)) <= end_offset) { if (!dsdiff_read_chunk_header(decoder, is, &header)) return false; - input_stream::offset_type chunk_end_offset = is->GetOffset() + InputStream::offset_type chunk_end_offset = is.GetOffset() + header.GetSize(); if (chunk_end_offset > end_offset) return false; @@ -172,19 +172,19 @@ dsdiff_read_prop_snd(Decoder *decoder, struct input_stream *is, } } - return is->GetOffset() == end_offset; + return is.GetOffset() == end_offset; } /** * Read and parse a "PROP" chunk. */ static bool -dsdiff_read_prop(Decoder *decoder, struct input_stream *is, +dsdiff_read_prop(Decoder *decoder, InputStream &is, DsdiffMetaData *metadata, const DsdiffChunkHeader *prop_header) { uint64_t prop_size = prop_header->GetSize(); - input_stream::offset_type end_offset = is->GetOffset() + prop_size; + InputStream::offset_type end_offset = is.GetOffset() + prop_size; struct dsdlib_id prop_id; if (prop_size < sizeof(prop_id) || @@ -199,9 +199,9 @@ dsdiff_read_prop(Decoder *decoder, struct input_stream *is, } static void -dsdiff_handle_native_tag(struct input_stream *is, +dsdiff_handle_native_tag(InputStream &is, const struct tag_handler *handler, - void *handler_ctx, input_stream::offset_type tagoffset, + void *handler_ctx, InputStream::offset_type tagoffset, TagType type) { if (!dsdlib_skip_to(nullptr, is, tagoffset)) @@ -239,7 +239,7 @@ dsdiff_handle_native_tag(struct input_stream *is, */ static bool -dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is, +dsdiff_read_metadata_extra(Decoder *decoder, InputStream &is, DsdiffMetaData *metadata, DsdiffChunkHeader *chunk_header, const struct tag_handler *handler, @@ -259,8 +259,8 @@ dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is, /* Now process all the remaining chunk headers in the stream and record their position and size */ - const auto size = is->GetSize(); - while (is->GetOffset() < size) { + const auto size = is.GetSize(); + while (is.GetOffset() < size) { uint64_t chunk_size = chunk_header->GetSize(); /* DIIN chunk, is directly followed by other chunks */ @@ -270,19 +270,19 @@ dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is, /* DIAR chunk - DSDIFF native tag for Artist */ if (dsdlib_id_equals(&chunk_header->id, "DIAR")) { chunk_size = chunk_header->GetSize(); - metadata->diar_offset = is->GetOffset(); + metadata->diar_offset = is.GetOffset(); } /* DITI chunk - DSDIFF native tag for Title */ if (dsdlib_id_equals(&chunk_header->id, "DITI")) { chunk_size = chunk_header->GetSize(); - metadata->diti_offset = is->GetOffset(); + metadata->diti_offset = is.GetOffset(); } #ifdef HAVE_ID3TAG /* 'ID3 ' chunk, offspec. Used by sacdextract */ if (dsdlib_id_equals(&chunk_header->id, "ID3 ")) { chunk_size = chunk_header->GetSize(); - metadata->id3_offset = is->GetOffset(); + metadata->id3_offset = is.GetOffset(); metadata->id3_size = chunk_size; } #endif @@ -291,7 +291,7 @@ dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is, break; } - if (is->GetOffset() < size) { + if (is.GetOffset() < size) { if (!dsdiff_read_chunk_header(decoder, is, chunk_header)) return false; } @@ -325,7 +325,7 @@ dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is, * "chunk_header" parameter. */ static bool -dsdiff_read_metadata(Decoder *decoder, struct input_stream *is, +dsdiff_read_metadata(Decoder *decoder, InputStream &is, DsdiffMetaData *metadata, DsdiffChunkHeader *chunk_header) { @@ -351,8 +351,8 @@ dsdiff_read_metadata(Decoder *decoder, struct input_stream *is, } else { /* ignore unknown chunk */ const uint64_t chunk_size = chunk_header->GetSize(); - input_stream::offset_type chunk_end_offset = - is->GetOffset() + chunk_size; + InputStream::offset_type chunk_end_offset = + is.GetOffset() + chunk_size; if (!dsdlib_skip_to(decoder, is, chunk_end_offset)) return false; @@ -371,7 +371,7 @@ bit_reverse_buffer(uint8_t *p, uint8_t *end) * Decode one "DSD" chunk. */ static bool -dsdiff_decode_chunk(Decoder &decoder, struct input_stream *is, +dsdiff_decode_chunk(Decoder &decoder, InputStream &is, unsigned channels, uint64_t chunk_size) { @@ -422,7 +422,7 @@ dsdiff_decode_chunk(Decoder &decoder, struct input_stream *is, } static void -dsdiff_stream_decode(Decoder &decoder, struct input_stream *is) +dsdiff_stream_decode(Decoder &decoder, InputStream &is) { DsdiffMetaData metadata; @@ -474,7 +474,7 @@ dsdiff_stream_decode(Decoder &decoder, struct input_stream *is) } static bool -dsdiff_scan_stream(struct input_stream *is, +dsdiff_scan_stream(InputStream &is, gcc_unused const struct tag_handler *handler, gcc_unused void *handler_ctx) { diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx index 4b848d4a4..10a88d370 100644 --- a/src/decoder/DsfDecoderPlugin.cxx +++ b/src/decoder/DsfDecoderPlugin.cxx @@ -47,7 +47,7 @@ struct DsfMetaData { bool bitreverse; uint64_t chunk_size; #ifdef HAVE_ID3TAG - input_stream::offset_type id3_offset; + InputStream::offset_type id3_offset; uint64_t id3_size; #endif }; @@ -99,7 +99,7 @@ struct DsfDataChunk { * Read and parse all needed metadata chunks for DSF files. */ static bool -dsf_read_metadata(Decoder *decoder, struct input_stream *is, +dsf_read_metadata(Decoder *decoder, InputStream &is, DsfMetaData *metadata) { uint64_t chunk_size; @@ -165,7 +165,7 @@ dsf_read_metadata(Decoder *decoder, struct input_stream *is, metadata->chunk_size = data_size; /* data_size cannot be bigger or equal to total file size */ - const uint64_t size = (uint64_t)is->GetSize(); + const uint64_t size = (uint64_t)is.GetSize(); if (data_size >= size) return false; @@ -176,7 +176,7 @@ dsf_read_metadata(Decoder *decoder, struct input_stream *is, if (metadata_offset >= size) metadata->id3_offset = 0; else - metadata->id3_offset = (input_stream::offset_type)metadata_offset; + metadata->id3_offset = (InputStream::offset_type)metadata_offset; #endif /* check bits per sample format, determine if bitreverse is needed */ metadata->bitreverse = dsf_fmt_chunk.bitssample == 1; @@ -219,7 +219,7 @@ dsf_to_pcm_order(uint8_t *dest, uint8_t *scratch, size_t nrbytes) * Decode one complete DSF 'data' chunk i.e. a complete song */ static bool -dsf_decode_chunk(Decoder &decoder, struct input_stream *is, +dsf_decode_chunk(Decoder &decoder, InputStream &is, unsigned channels, uint64_t chunk_size, bool bitreverse) @@ -277,7 +277,7 @@ dsf_decode_chunk(Decoder &decoder, struct input_stream *is, } static void -dsf_stream_decode(Decoder &decoder, struct input_stream *is) +dsf_stream_decode(Decoder &decoder, InputStream &is) { /* check if it is a proper DSF file */ DsfMetaData metadata; @@ -307,7 +307,7 @@ dsf_stream_decode(Decoder &decoder, struct input_stream *is) } static bool -dsf_scan_stream(struct input_stream *is, +dsf_scan_stream(InputStream &is, gcc_unused const struct tag_handler *handler, gcc_unused void *handler_ctx) { diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx index 05d929fb4..e8b5ad4a8 100644 --- a/src/decoder/FaadDecoderPlugin.cxx +++ b/src/decoder/FaadDecoderPlugin.cxx @@ -163,14 +163,14 @@ adts_song_duration(DecoderBuffer *buffer) } static float -faad_song_duration(DecoderBuffer *buffer, struct input_stream *is) +faad_song_duration(DecoderBuffer *buffer, InputStream &is) { size_t fileread; size_t tagsize; size_t length; bool success; - const auto size = is->GetSize(); + const auto size = is.GetSize(); fileread = size >= 0 ? size : 0; decoder_buffer_fill(buffer); @@ -198,12 +198,12 @@ faad_song_duration(DecoderBuffer *buffer, struct input_stream *is) return -1; } - if (is->IsSeekable() && length >= 2 && + if (is.IsSeekable() && length >= 2 && data[0] == 0xFF && ((data[1] & 0xF6) == 0xF0)) { /* obtain the duration from the ADTS header */ float song_length = adts_song_duration(buffer); - is->LockSeek(tagsize, SEEK_SET, IgnoreError()); + is.LockSeek(tagsize, SEEK_SET, IgnoreError()); data = (const uint8_t *)decoder_buffer_read(buffer, &length); if (data != nullptr) @@ -304,7 +304,7 @@ faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer *buffer, * file is invalid. */ static float -faad_get_file_time_float(struct input_stream *is) +faad_get_file_time_float(InputStream &is) { DecoderBuffer *buffer; float length; @@ -345,7 +345,7 @@ faad_get_file_time_float(struct input_stream *is) * file is invalid. */ static int -faad_get_file_time(struct input_stream *is) +faad_get_file_time(InputStream &is) { int file_time = -1; float length; @@ -357,7 +357,7 @@ faad_get_file_time(struct input_stream *is) } static void -faad_stream_decode(Decoder &mpd_decoder, struct input_stream *is) +faad_stream_decode(Decoder &mpd_decoder, InputStream &is) { float total_time = 0; AudioFormat audio_format; @@ -380,7 +380,7 @@ faad_stream_decode(Decoder &mpd_decoder, struct input_stream *is) config->dontUpSampleImplicitSBR = 0; NeAACDecSetConfiguration(decoder, config); - while (!decoder_buffer_is_full(buffer) && !is->LockIsEOF() && + while (!decoder_buffer_is_full(buffer) && !is.LockIsEOF() && decoder_get_command(mpd_decoder) == DecoderCommand::NONE) { adts_find_frame(buffer); decoder_buffer_fill(buffer); @@ -464,7 +464,7 @@ faad_stream_decode(Decoder &mpd_decoder, struct input_stream *is) } static bool -faad_scan_stream(struct input_stream *is, +faad_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { int file_time = faad_get_file_time(is); diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx index cba7f5e2d..0d24371d2 100644 --- a/src/decoder/FfmpegDecoderPlugin.cxx +++ b/src/decoder/FfmpegDecoderPlugin.cxx @@ -86,13 +86,13 @@ mpd_ffmpeg_log_callback(gcc_unused void *ptr, int level, struct AvioStream { Decoder *const decoder; - struct input_stream *input; + InputStream &input; AVIOContext *io; unsigned char buffer[8192]; - AvioStream(Decoder *_decoder, input_stream *_input) + AvioStream(Decoder *_decoder, InputStream &_input) :decoder(_decoder), input(_input), io(nullptr) {} ~AvioStream() { @@ -118,13 +118,13 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence) AvioStream *stream = (AvioStream *)opaque; if (whence == AVSEEK_SIZE) - return stream->input->size; + return stream->input.size; Error error; - if (!stream->input->LockSeek(pos, whence, error)) + if (!stream->input.LockSeek(pos, whence, error)) return -1; - return stream->input->offset; + return stream->input.offset; } bool @@ -133,7 +133,7 @@ AvioStream::Open() io = avio_alloc_context(buffer, sizeof(buffer), false, this, mpd_ffmpeg_stream_read, nullptr, - input->seekable + input.seekable ? mpd_ffmpeg_stream_seek : nullptr); return io != nullptr; } @@ -249,7 +249,7 @@ copy_interleave_frame(const AVCodecContext *codec_context, } static DecoderCommand -ffmpeg_send_packet(Decoder &decoder, struct input_stream *is, +ffmpeg_send_packet(Decoder &decoder, InputStream &is, const AVPacket *packet, AVCodecContext *codec_context, const AVRational *time_base, @@ -335,7 +335,7 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt) } static AVInputFormat * -ffmpeg_probe(Decoder *decoder, struct input_stream *is) +ffmpeg_probe(Decoder *decoder, InputStream &is) { enum { BUFFER_SIZE = 16384, @@ -346,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->LockRewind(error)) + if (nbytes <= PADDING || !is.LockRewind(error)) return nullptr; /* some ffmpeg parsers (e.g. ac3_parser.c) read a few bytes @@ -358,13 +358,13 @@ ffmpeg_probe(Decoder *decoder, struct input_stream *is) AVProbeData avpd; avpd.buf = buffer; avpd.buf_size = nbytes; - avpd.filename = is->uri.c_str(); + avpd.filename = is.uri.c_str(); return av_probe_input_format(&avpd, true); } static void -ffmpeg_decode(Decoder &decoder, struct input_stream *input) +ffmpeg_decode(Decoder &decoder, InputStream &input) { AVInputFormat *input_format = ffmpeg_probe(&decoder, input); if (input_format == nullptr) @@ -382,7 +382,7 @@ ffmpeg_decode(Decoder &decoder, struct input_stream *input) //ffmpeg works with ours "fileops" helper AVFormatContext *format_context = nullptr; if (mpd_ffmpeg_open_input(&format_context, stream.io, - input->uri.c_str(), + input.uri.c_str(), input_format) != 0) { LogError(ffmpeg_domain, "Open failed"); return; @@ -451,7 +451,7 @@ ffmpeg_decode(Decoder &decoder, struct input_stream *input) : 0; decoder_initialized(decoder, audio_format, - input->seekable, total_time); + input.seekable, total_time); AVFrame *frame = avcodec_alloc_frame(); if (!frame) { @@ -509,7 +509,7 @@ ffmpeg_decode(Decoder &decoder, struct input_stream *input) //no tag reading in ffmpeg, check if playable static bool -ffmpeg_scan_stream(struct input_stream *is, +ffmpeg_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { AVInputFormat *input_format = ffmpeg_probe(nullptr, is); @@ -521,7 +521,7 @@ ffmpeg_scan_stream(struct input_stream *is, return false; AVFormatContext *f = nullptr; - if (mpd_ffmpeg_open_input(&f, stream.io, is->uri.c_str(), + if (mpd_ffmpeg_open_input(&f, stream.io, is.uri.c_str(), input_format) != 0) return false; diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx index 46fd9fff9..2aa4ce695 100644 --- a/src/decoder/FlacCommon.cxx +++ b/src/decoder/FlacCommon.cxx @@ -33,7 +33,7 @@ #include flac_data::flac_data(Decoder &_decoder, - struct input_stream *_input_stream) + InputStream &_input_stream) :FlacInput(_input_stream, &_decoder), initialized(false), unsupported(false), total_frames(0), first_frame(0), next_frame(0), position(0), @@ -144,7 +144,7 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header) data->frame_size = data->audio_format.GetFrameSize(); decoder_initialized(data->decoder, data->audio_format, - data->input_stream->seekable, + data->input_stream.seekable, (float)data->total_frames / (float)data->audio_format.sample_rate); diff --git a/src/decoder/FlacCommon.hxx b/src/decoder/FlacCommon.hxx index e35bceb30..65b5defd6 100644 --- a/src/decoder/FlacCommon.hxx +++ b/src/decoder/FlacCommon.hxx @@ -76,11 +76,11 @@ struct flac_data : public FlacInput { FLAC__uint64 position; Decoder &decoder; - struct input_stream *input_stream; + InputStream &input_stream; Tag tag; - flac_data(Decoder &decoder, struct input_stream *input_stream); + flac_data(Decoder &decoder, InputStream &input_stream); }; void flac_metadata_common_cb(const FLAC__StreamMetadata * block, diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx index 10a052d3d..9390b62ba 100644 --- a/src/decoder/FlacDecoderPlugin.cxx +++ b/src/decoder/FlacDecoderPlugin.cxx @@ -99,7 +99,7 @@ flac_scan_file(const char *file, } static bool -flac_scan_stream(struct input_stream *is, +flac_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { FlacMetadataChain chain; @@ -148,13 +148,13 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd, if (data->initialized) { /* done */ decoder_initialized(data->decoder, data->audio_format, - data->input_stream->seekable, + data->input_stream.seekable, (float)data->total_frames / (float)data->audio_format.sample_rate); return true; } - if (data->input_stream->seekable) + if (data->input_stream.seekable) /* allow the workaround below only for nonseekable streams*/ return false; @@ -252,7 +252,7 @@ stream_init(FLAC__StreamDecoder *flac_dec, struct flac_data *data, bool is_ogg) static void flac_decode_internal(Decoder &decoder, - struct input_stream *input_stream, + InputStream &input_stream, bool is_ogg) { FLAC__StreamDecoder *flac_dec; @@ -285,7 +285,7 @@ flac_decode_internal(Decoder &decoder, } static void -flac_decode(Decoder &decoder, struct input_stream *input_stream) +flac_decode(Decoder &decoder, InputStream &input_stream) { flac_decode_internal(decoder, input_stream, false); } @@ -313,7 +313,7 @@ oggflac_scan_file(const char *file, } static bool -oggflac_scan_stream(struct input_stream *is, +oggflac_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { FlacMetadataChain chain; @@ -329,14 +329,14 @@ oggflac_scan_stream(struct input_stream *is, } static void -oggflac_decode(Decoder &decoder, struct input_stream *input_stream) +oggflac_decode(Decoder &decoder, InputStream &input_stream) { if (ogg_codec_detect(&decoder, input_stream) != OGG_CODEC_FLAC) return; /* rewind the stream, because ogg_codec_detect() has moved it */ - input_stream->LockRewind(IgnoreError()); + input_stream.LockRewind(IgnoreError()); flac_decode_internal(decoder, input_stream, true); } diff --git a/src/decoder/FlacIOHandle.cxx b/src/decoder/FlacIOHandle.cxx index 28ef60006..ff8b5a5bc 100644 --- a/src/decoder/FlacIOHandle.cxx +++ b/src/decoder/FlacIOHandle.cxx @@ -27,7 +27,7 @@ static size_t FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle) { - input_stream *is = (input_stream *)handle; + InputStream *is = (InputStream *)handle; uint8_t *const p0 = (uint8_t *)ptr, *p = p0, *const end = p0 + size * nmemb; @@ -64,7 +64,7 @@ FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle) static int FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence) { - input_stream *is = (input_stream *)handle; + InputStream *is = (InputStream *)handle; Error error; return is->LockSeek(offset, whence, error) ? 0 : -1; @@ -73,7 +73,7 @@ FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence) static FLAC__int64 FlacIOTell(FLAC__IOHandle handle) { - input_stream *is = (input_stream *)handle; + InputStream *is = (InputStream *)handle; return is->offset; } @@ -81,7 +81,7 @@ FlacIOTell(FLAC__IOHandle handle) static int FlacIOEof(FLAC__IOHandle handle) { - input_stream *is = (input_stream *)handle; + InputStream *is = (InputStream *)handle; return is->LockIsEOF(); } @@ -90,7 +90,7 @@ static int FlacIOClose(gcc_unused FLAC__IOHandle handle) { /* no-op because the libFLAC caller is repsonsible for closing - the #input_stream */ + the #InputStream */ return 0; } diff --git a/src/decoder/FlacIOHandle.hxx b/src/decoder/FlacIOHandle.hxx index 996f0d96b..a4c9a6b15 100644 --- a/src/decoder/FlacIOHandle.hxx +++ b/src/decoder/FlacIOHandle.hxx @@ -29,15 +29,15 @@ extern const FLAC__IOCallbacks flac_io_callbacks; extern const FLAC__IOCallbacks flac_io_callbacks_seekable; static inline FLAC__IOHandle -ToFlacIOHandle(input_stream *is) +ToFlacIOHandle(InputStream &is) { - return (FLAC__IOHandle)is; + return (FLAC__IOHandle)&is; } static inline const FLAC__IOCallbacks & -GetFlacIOCallbacks(const input_stream *is) +GetFlacIOCallbacks(const InputStream &is) { - return is->seekable + return is.seekable ? flac_io_callbacks_seekable : flac_io_callbacks; } diff --git a/src/decoder/FlacInput.cxx b/src/decoder/FlacInput.cxx index 39e323716..71a082db1 100644 --- a/src/decoder/FlacInput.cxx +++ b/src/decoder/FlacInput.cxx @@ -33,7 +33,7 @@ FlacInput::Read(FLAC__byte buffer[], size_t *bytes) *bytes = r; if (r == 0) { - if (input_stream->LockIsEOF() || + if (input_stream.LockIsEOF() || (decoder != nullptr && decoder_get_command(*decoder) != DecoderCommand::NONE)) return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; @@ -47,11 +47,11 @@ FlacInput::Read(FLAC__byte buffer[], size_t *bytes) FLAC__StreamDecoderSeekStatus FlacInput::Seek(FLAC__uint64 absolute_byte_offset) { - if (!input_stream->seekable) + if (!input_stream.seekable) return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; ::Error error; - if (!input_stream->LockSeek(absolute_byte_offset, SEEK_SET, error)) { + if (!input_stream.LockSeek(absolute_byte_offset, SEEK_SET, error)) { LogError(error); return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; } @@ -62,20 +62,20 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset) FLAC__StreamDecoderTellStatus FlacInput::Tell(FLAC__uint64 *absolute_byte_offset) { - if (!input_stream->seekable) + if (!input_stream.seekable) return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; - *absolute_byte_offset = (FLAC__uint64)input_stream->offset; + *absolute_byte_offset = (FLAC__uint64)input_stream.offset; return FLAC__STREAM_DECODER_TELL_STATUS_OK; } FLAC__StreamDecoderLengthStatus FlacInput::Length(FLAC__uint64 *stream_length) { - if (input_stream->size < 0) + if (input_stream.size < 0) return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; - *stream_length = (FLAC__uint64)input_stream->size; + *stream_length = (FLAC__uint64)input_stream.size; return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; } @@ -85,7 +85,7 @@ FlacInput::Eof() return (decoder != nullptr && decoder_get_command(*decoder) != DecoderCommand::NONE && decoder_get_command(*decoder) != DecoderCommand::SEEK) || - input_stream->LockIsEOF(); + input_stream.LockIsEOF(); } void diff --git a/src/decoder/FlacInput.hxx b/src/decoder/FlacInput.hxx index 2879f5dd4..ac2b4bd25 100644 --- a/src/decoder/FlacInput.hxx +++ b/src/decoder/FlacInput.hxx @@ -23,18 +23,19 @@ #include struct Decoder; +struct InputStream; /** - * This class wraps an #input_stream in libFLAC stream decoder + * This class wraps an #InputStream in libFLAC stream decoder * callbacks. */ class FlacInput { Decoder *const decoder; - struct input_stream *input_stream; + InputStream &input_stream; public: - FlacInput(struct input_stream *_input_stream, + FlacInput(InputStream &_input_stream, Decoder *_decoder=nullptr) :decoder(_decoder), input_stream(_input_stream) {} diff --git a/src/decoder/FlacMetadata.hxx b/src/decoder/FlacMetadata.hxx index 5159a1a41..2b4acad06 100644 --- a/src/decoder/FlacMetadata.hxx +++ b/src/decoder/FlacMetadata.hxx @@ -51,7 +51,7 @@ public: callbacks); } - bool Read(input_stream *is) { + bool Read(InputStream &is) { return Read(::ToFlacIOHandle(is), ::GetFlacIOCallbacks(is)); } @@ -65,7 +65,7 @@ public: callbacks); } - bool ReadOgg(input_stream *is) { + bool ReadOgg(InputStream &is) { return ReadOgg(::ToFlacIOHandle(is), ::GetFlacIOCallbacks(is)); } diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx index 4b25ef87b..b59bde8b4 100644 --- a/src/decoder/MadDecoderPlugin.cxx +++ b/src/decoder/MadDecoderPlugin.cxx @@ -140,10 +140,10 @@ struct MadDecoder { bool decoded_first_frame; unsigned long bit_rate; Decoder *const decoder; - struct input_stream *input_stream; + InputStream &input_stream; enum mad_layer layer; - MadDecoder(Decoder *decoder, struct input_stream *input_stream); + MadDecoder(Decoder *decoder, InputStream &input_stream); ~MadDecoder(); bool Seek(long offset); @@ -153,10 +153,10 @@ struct MadDecoder { enum mp3_action DecodeNextFrame(); gcc_pure - input_stream::offset_type ThisFrameOffset() const; + InputStream::offset_type ThisFrameOffset() const; gcc_pure - input_stream::offset_type RestIncludingThisFrame() const; + InputStream::offset_type RestIncludingThisFrame() const; /** * Attempt to calulcate the length of the song from filesize @@ -185,7 +185,7 @@ struct MadDecoder { }; MadDecoder::MadDecoder(Decoder *_decoder, - struct input_stream *_input_stream) + InputStream &_input_stream) :mute_frame(MUTEFRAME_NONE), frame_offsets(nullptr), times(nullptr), @@ -208,7 +208,7 @@ inline bool MadDecoder::Seek(long offset) { Error error; - if (!input_stream->LockSeek(offset, SEEK_SET, error)) + if (!input_stream.LockSeek(offset, SEEK_SET, error)) return false; mad_stream_buffer(&stream, input_buffer, 0); @@ -777,10 +777,10 @@ mp3_frame_duration(const struct mad_frame *frame) MAD_UNITS_MILLISECONDS) / 1000.0; } -inline input_stream::offset_type +inline InputStream::offset_type MadDecoder::ThisFrameOffset() const { - auto offset = input_stream->GetOffset(); + auto offset = input_stream.GetOffset(); if (stream.this_frame != nullptr) offset -= stream.bufend - stream.this_frame; @@ -790,16 +790,16 @@ MadDecoder::ThisFrameOffset() const return offset; } -inline input_stream::offset_type +inline InputStream::offset_type MadDecoder::RestIncludingThisFrame() const { - return input_stream->GetSize() - ThisFrameOffset(); + return input_stream.GetSize() - ThisFrameOffset(); } inline void MadDecoder::FileSizeToSongLength() { - input_stream::offset_type rest = RestIncludingThisFrame(); + InputStream::offset_type rest = RestIncludingThisFrame(); if (rest > 0) { float frame_duration = mp3_frame_duration(&frame); @@ -861,7 +861,7 @@ MadDecoder::DecodeFirstFrame(Tag **tag) } if (parse_lame(&lame, &ptr, &bitlen)) { - if (gapless_playback && input_stream->IsSeekable()) { + if (gapless_playback && input_stream.IsSeekable()) { drop_start_samples = lame.encoder_delay + DECODERDELAY; drop_end_samples = lame.encoder_padding; @@ -908,7 +908,7 @@ MadDecoder::~MadDecoder() /* this is primarily used for getting total time for tags */ static int -mad_decoder_total_file_time(struct input_stream *is) +mad_decoder_total_file_time(InputStream &is) { MadDecoder data(nullptr, is); return data.DecodeFirstFrame(nullptr) @@ -1063,7 +1063,7 @@ MadDecoder::Read() if (cmd == DecoderCommand::SEEK) { unsigned long j; - assert(input_stream->IsSeekable()); + assert(input_stream.IsSeekable()); j = TimeToFrame(decoder_seek_where(*decoder)); if (j < highest_frame) { @@ -1116,7 +1116,7 @@ MadDecoder::Read() } static void -mp3_decode(Decoder &decoder, struct input_stream *input_stream) +mp3_decode(Decoder &decoder, InputStream &input_stream) { MadDecoder data(&decoder, input_stream); @@ -1143,7 +1143,7 @@ mp3_decode(Decoder &decoder, struct input_stream *input_stream) } decoder_initialized(decoder, audio_format, - input_stream->IsSeekable(), + input_stream.IsSeekable(), data.total_time); if (tag != nullptr) { @@ -1155,7 +1155,7 @@ mp3_decode(Decoder &decoder, struct input_stream *input_stream) } static bool -mad_decoder_scan_stream(struct input_stream *is, +mad_decoder_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { int total_time; diff --git a/src/decoder/ModplugDecoderPlugin.cxx b/src/decoder/ModplugDecoderPlugin.cxx index a86166622..e75f5479c 100644 --- a/src/decoder/ModplugDecoderPlugin.cxx +++ b/src/decoder/ModplugDecoderPlugin.cxx @@ -36,7 +36,7 @@ static constexpr Domain modplug_domain("modplug"); static constexpr size_t MODPLUG_FRAME_SIZE = 4096; static constexpr size_t MODPLUG_PREALLOC_BLOCK = 256 * 1024; -static constexpr input_stream::offset_type MODPLUG_FILE_LIMIT = 100 * 1024 * 1024; +static constexpr InputStream::offset_type MODPLUG_FILE_LIMIT = 100 * 1024 * 1024; static int modplug_loop_count; @@ -52,9 +52,9 @@ modplug_decoder_init(const config_param ¶m) } static WritableBuffer -mod_loadfile(Decoder *decoder, struct input_stream *is) +mod_loadfile(Decoder *decoder, InputStream &is) { - const input_stream::offset_type size = is->GetSize(); + const InputStream::offset_type size = is.GetSize(); if (size == 0) { LogWarning(modplug_domain, "file is empty"); @@ -80,7 +80,7 @@ mod_loadfile(Decoder *decoder, struct input_stream *is) while (true) { size_t ret = decoder_read(decoder, is, p, end - p); if (ret == 0) { - if (is->LockIsEOF()) + if (is.LockIsEOF()) /* end of file */ break; @@ -107,7 +107,7 @@ mod_loadfile(Decoder *decoder, struct input_stream *is) } static ModPlugFile * -LoadModPlugFile(Decoder *decoder, struct input_stream *is) +LoadModPlugFile(Decoder *decoder, InputStream &is) { const auto buffer = mod_loadfile(decoder, is); if (buffer.IsNull()) { @@ -121,7 +121,7 @@ LoadModPlugFile(Decoder *decoder, struct input_stream *is) } static void -mod_decode(Decoder &decoder, struct input_stream *is) +mod_decode(Decoder &decoder, InputStream &is) { ModPlug_Settings settings; int ret; @@ -147,7 +147,7 @@ mod_decode(Decoder &decoder, struct input_stream *is) assert(audio_format.IsValid()); decoder_initialized(decoder, audio_format, - is->IsSeekable(), + is.IsSeekable(), ModPlug_GetLength(f) / 1000.0); DecoderCommand cmd; @@ -174,7 +174,7 @@ mod_decode(Decoder &decoder, struct input_stream *is) } static bool -modplug_scan_stream(struct input_stream *is, +modplug_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { ModPlugFile *f = LoadModPlugFile(nullptr, is); diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx index 1d38ec23b..feb2caeb4 100644 --- a/src/decoder/MpcdecDecoderPlugin.cxx +++ b/src/decoder/MpcdecDecoderPlugin.cxx @@ -35,8 +35,11 @@ #include struct mpc_decoder_data { - struct input_stream *is; + InputStream &is; Decoder *decoder; + + mpc_decoder_data(InputStream &_is, Decoder *_decoder) + :is(_is), decoder(_decoder) {} }; static constexpr Domain mpcdec_domain("mpcdec"); @@ -56,7 +59,7 @@ mpc_seek_cb(mpc_reader *reader, mpc_int32_t offset) struct mpc_decoder_data *data = (struct mpc_decoder_data *)reader->data; - return data->is->LockSeek(offset, SEEK_SET, IgnoreError()); + return data->is.LockSeek(offset, SEEK_SET, IgnoreError()); } static mpc_int32_t @@ -65,7 +68,7 @@ mpc_tell_cb(mpc_reader *reader) struct mpc_decoder_data *data = (struct mpc_decoder_data *)reader->data; - return (long)data->is->GetOffset(); + return (long)data->is.GetOffset(); } static mpc_bool_t @@ -74,7 +77,7 @@ mpc_canseek_cb(mpc_reader *reader) struct mpc_decoder_data *data = (struct mpc_decoder_data *)reader->data; - return data->is->IsSeekable(); + return data->is.IsSeekable(); } static mpc_int32_t @@ -83,7 +86,7 @@ mpc_getsize_cb(mpc_reader *reader) struct mpc_decoder_data *data = (struct mpc_decoder_data *)reader->data; - return data->is->GetSize(); + return data->is.GetSize(); } /* this _looks_ performance-critical, don't de-inline -- eric */ @@ -130,13 +133,11 @@ mpc_to_mpd_buffer(int32_t *dest, const MPC_SAMPLE_FORMAT *src, } static void -mpcdec_decode(Decoder &mpd_decoder, struct input_stream *is) +mpcdec_decode(Decoder &mpd_decoder, InputStream &is) { MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH]; - struct mpc_decoder_data data; - data.is = is; - data.decoder = &mpd_decoder; + mpc_decoder_data data(is, &mpd_decoder); mpc_reader reader; reader.read = mpc_read_cb; @@ -177,7 +178,7 @@ mpcdec_decode(Decoder &mpd_decoder, struct input_stream *is) decoder_replay_gain(mpd_decoder, &replay_gain_info); decoder_initialized(mpd_decoder, audio_format, - is->IsSeekable(), + is.IsSeekable(), mpc_streaminfo_get_length(&info)); DecoderCommand cmd = DecoderCommand::NONE; @@ -227,11 +228,9 @@ mpcdec_decode(Decoder &mpd_decoder, struct input_stream *is) } static float -mpcdec_get_file_duration(struct input_stream *is) +mpcdec_get_file_duration(InputStream &is) { - struct mpc_decoder_data data; - data.is = is; - data.decoder = nullptr; + mpc_decoder_data data(is, nullptr); mpc_reader reader; reader.read = mpc_read_cb; @@ -253,7 +252,7 @@ mpcdec_get_file_duration(struct input_stream *is) } static bool -mpcdec_scan_stream(struct input_stream *is, +mpcdec_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { float total_time = mpcdec_get_file_duration(is); diff --git a/src/decoder/OggCodec.cxx b/src/decoder/OggCodec.cxx index adc88188e..565dbafcf 100644 --- a/src/decoder/OggCodec.cxx +++ b/src/decoder/OggCodec.cxx @@ -27,7 +27,7 @@ #include enum ogg_codec -ogg_codec_detect(Decoder *decoder, struct input_stream *is) +ogg_codec_detect(Decoder *decoder, InputStream &is) { /* oggflac detection based on code in ogg123 and this post * http://lists.xiph.org/pipermail/flac/2004-December/000393.html diff --git a/src/decoder/OggCodec.hxx b/src/decoder/OggCodec.hxx index b24b4ec5c..857871607 100644 --- a/src/decoder/OggCodec.hxx +++ b/src/decoder/OggCodec.hxx @@ -34,6 +34,6 @@ enum ogg_codec { }; enum ogg_codec -ogg_codec_detect(Decoder *decoder, struct input_stream *is); +ogg_codec_detect(Decoder *decoder, InputStream &is); #endif /* _OGG_COMMON_H */ diff --git a/src/decoder/OggSyncState.hxx b/src/decoder/OggSyncState.hxx index c85b931bb..5235c1bd8 100644 --- a/src/decoder/OggSyncState.hxx +++ b/src/decoder/OggSyncState.hxx @@ -33,11 +33,11 @@ class OggSyncState { ogg_sync_state oy; - input_stream &is; + InputStream &is; Decoder *const decoder; public: - OggSyncState(input_stream &_is, Decoder *const _decoder=nullptr) + OggSyncState(InputStream &_is, Decoder *const _decoder=nullptr) :is(_is), decoder(_decoder) { ogg_sync_init(&oy); } @@ -51,27 +51,27 @@ public: } bool Feed(size_t size) { - return OggFeed(oy, decoder, &is, size); + return OggFeed(oy, decoder, is, size); } bool ExpectPage(ogg_page &page) { - return OggExpectPage(oy, page, decoder, &is); + return OggExpectPage(oy, page, decoder, is); } bool ExpectFirstPage(ogg_stream_state &os) { - return OggExpectFirstPage(oy, os, decoder, &is); + return OggExpectFirstPage(oy, os, decoder, is); } bool ExpectPageIn(ogg_stream_state &os) { - return OggExpectPageIn(oy, os, decoder, &is); + return OggExpectPageIn(oy, os, decoder, is); } bool ExpectPageSeek(ogg_page &page) { - return OggExpectPageSeek(oy, page, decoder, &is); + return OggExpectPageSeek(oy, page, decoder, is); } bool ExpectPageSeekIn(ogg_stream_state &os) { - return OggExpectPageSeekIn(oy, os, decoder, &is); + return OggExpectPageSeekIn(oy, os, decoder, is); } }; diff --git a/src/decoder/OggUtil.cxx b/src/decoder/OggUtil.cxx index 294a87276..f82d0a082 100644 --- a/src/decoder/OggUtil.cxx +++ b/src/decoder/OggUtil.cxx @@ -23,7 +23,7 @@ bool OggFeed(ogg_sync_state &oy, Decoder *decoder, - input_stream *input_stream, size_t size) + InputStream &input_stream, size_t size) { char *buffer = ogg_sync_buffer(&oy, size); if (buffer == nullptr) @@ -40,7 +40,7 @@ OggFeed(ogg_sync_state &oy, Decoder *decoder, bool OggExpectPage(ogg_sync_state &oy, ogg_page &page, - Decoder *decoder, input_stream *input_stream) + Decoder *decoder, InputStream &input_stream) { while (true) { int r = ogg_sync_pageout(&oy, &page); @@ -54,7 +54,7 @@ OggExpectPage(ogg_sync_state &oy, ogg_page &page, bool OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, input_stream *is) + Decoder *decoder, InputStream &is) { ogg_page page; if (!OggExpectPage(oy, page, decoder, is)) @@ -67,7 +67,7 @@ OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, bool OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, input_stream *is) + Decoder *decoder, InputStream &is) { ogg_page page; if (!OggExpectPage(oy, page, decoder, is)) @@ -79,7 +79,7 @@ OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, bool OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, - Decoder *decoder, input_stream *input_stream) + Decoder *decoder, InputStream &input_stream) { size_t remaining_skipped = 16384; @@ -107,7 +107,7 @@ OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, bool OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, input_stream *is) + Decoder *decoder, InputStream &is) { ogg_page page; if (!OggExpectPageSeek(oy, page, decoder, is)) diff --git a/src/decoder/OggUtil.hxx b/src/decoder/OggUtil.hxx index 77ec83f2c..d9a54b2cf 100644 --- a/src/decoder/OggUtil.hxx +++ b/src/decoder/OggUtil.hxx @@ -26,16 +26,16 @@ #include -struct input_stream; +struct InputStream; struct Decoder; /** - * Feed data from the #input_stream into the #ogg_sync_state. + * Feed data from the #InputStream into the #ogg_sync_state. * * @return false on error or end-of-file */ bool -OggFeed(ogg_sync_state &oy, Decoder *decoder, input_stream *is, +OggFeed(ogg_sync_state &oy, Decoder *decoder, InputStream &is, size_t size); /** @@ -46,7 +46,7 @@ OggFeed(ogg_sync_state &oy, Decoder *decoder, input_stream *is, */ bool OggExpectPage(ogg_sync_state &oy, ogg_page &page, - Decoder *decoder, input_stream *input_stream); + Decoder *decoder, InputStream &is); /** * Combines OggExpectPage(), ogg_stream_init() and @@ -57,7 +57,7 @@ OggExpectPage(ogg_sync_state &oy, ogg_page &page, */ bool OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, input_stream *is); + Decoder *decoder, InputStream &is); /** * Combines OggExpectPage() and ogg_stream_pagein(). @@ -66,14 +66,14 @@ OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, */ bool OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, input_stream *is); + Decoder *decoder, InputStream &is); /** * Like OggExpectPage(), but allow skipping garbage (after seeking). */ bool OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, - Decoder *decoder, input_stream *input_stream); + Decoder *decoder, InputStream &is); /** * Combines OggExpectPageSeek() and ogg_stream_pagein(). @@ -82,6 +82,6 @@ OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, */ bool OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, input_stream *is); + Decoder *decoder, InputStream &is); #endif diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx index 1ef4b5f92..ad2ee6297 100644 --- a/src/decoder/OpusDecoderPlugin.cxx +++ b/src/decoder/OpusDecoderPlugin.cxx @@ -67,7 +67,7 @@ mpd_opus_init(gcc_unused const config_param ¶m) class MPDOpusDecoder { Decoder &decoder; - struct input_stream *input_stream; + InputStream &input_stream; ogg_stream_state os; @@ -84,7 +84,7 @@ class MPDOpusDecoder { public: MPDOpusDecoder(Decoder &_decoder, - struct input_stream *_input_stream) + InputStream &_input_stream) :decoder(_decoder), input_stream(_input_stream), opus_decoder(nullptr), output_buffer(nullptr), output_size(0), @@ -265,17 +265,17 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet) static void mpd_opus_stream_decode(Decoder &decoder, - struct input_stream *input_stream) + InputStream &input_stream) { if (ogg_codec_detect(&decoder, input_stream) != OGG_CODEC_OPUS) return; /* rewind the stream, because ogg_codec_detect() has moved it */ - input_stream->LockRewind(IgnoreError()); + input_stream.LockRewind(IgnoreError()); MPDOpusDecoder d(decoder, input_stream); - OggSyncState oy(*input_stream, &decoder); + OggSyncState oy(input_stream, &decoder); if (!d.ReadFirstPage(oy)) return; @@ -293,27 +293,27 @@ mpd_opus_stream_decode(Decoder &decoder, static bool SeekFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet, - input_stream *is) + InputStream &is) { - if (is->size > 0 && is->size - is->offset < 65536) + if (is.size > 0 && is.size - is.offset < 65536) return OggFindEOS(oy, os, packet); - if (!is->CheapSeeking()) + if (!is.CheapSeeking()) return false; oy.Reset(); Error error; - return is->LockSeek(-65536, SEEK_END, error) && + return is.LockSeek(-65536, SEEK_END, error) && oy.ExpectPageSeekIn(os) && OggFindEOS(oy, os, packet); } static bool -mpd_opus_scan_stream(struct input_stream *is, +mpd_opus_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { - OggSyncState oy(*is); + OggSyncState oy(is); ogg_stream_state os; if (!oy.ExpectFirstPage(os)) diff --git a/src/decoder/PcmDecoderPlugin.cxx b/src/decoder/PcmDecoderPlugin.cxx index 0a19ed59b..dbc38fb76 100644 --- a/src/decoder/PcmDecoderPlugin.cxx +++ b/src/decoder/PcmDecoderPlugin.cxx @@ -31,7 +31,7 @@ #include /* for SEEK_SET */ static void -pcm_stream_decode(Decoder &decoder, struct input_stream *is) +pcm_stream_decode(Decoder &decoder, InputStream &is) { static constexpr AudioFormat audio_format = { 44100, @@ -39,19 +39,19 @@ pcm_stream_decode(Decoder &decoder, struct input_stream *is) 2, }; - const char *const mime = is->GetMimeType(); + const char *const mime = is.GetMimeType(); const bool reverse_endian = mime != nullptr && strcmp(mime, "audio/x-mpd-cdda-pcm-reverse") == 0; const double time_to_size = audio_format.GetTimeToSize(); float total_time = -1; - const auto size = is->GetSize(); + const auto size = is.GetSize(); if (size >= 0) total_time = size / time_to_size; decoder_initialized(decoder, audio_format, - is->IsSeekable(), total_time); + is.IsSeekable(), total_time); DecoderCommand cmd; do { @@ -60,7 +60,7 @@ pcm_stream_decode(Decoder &decoder, struct input_stream *is) size_t nbytes = decoder_read(decoder, is, buffer, sizeof(buffer)); - if (nbytes == 0 && is->LockIsEOF()) + if (nbytes == 0 && is.LockIsEOF()) break; if (reverse_endian) @@ -74,11 +74,11 @@ pcm_stream_decode(Decoder &decoder, struct input_stream *is) buffer, nbytes, 0) : decoder_get_command(decoder); if (cmd == DecoderCommand::SEEK) { - input_stream::offset_type offset(time_to_size * - decoder_seek_where(decoder)); + InputStream::offset_type offset(time_to_size * + decoder_seek_where(decoder)); Error error; - if (is->LockSeek(offset, SEEK_SET, error)) { + if (is.LockSeek(offset, SEEK_SET, error)) { decoder_command_finished(decoder); } else { LogError(error); diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx index 5f5c256e9..3360cd1bf 100644 --- a/src/decoder/SndfileDecoderPlugin.cxx +++ b/src/decoder/SndfileDecoderPlugin.cxx @@ -34,29 +34,29 @@ static constexpr Domain sndfile_domain("sndfile"); static sf_count_t sndfile_vio_get_filelen(void *user_data) { - const struct input_stream *is = (const struct input_stream *)user_data; + const InputStream &is = *(const InputStream *)user_data; - return is->GetSize(); + return is.GetSize(); } static sf_count_t sndfile_vio_seek(sf_count_t offset, int whence, void *user_data) { - struct input_stream *is = (struct input_stream *)user_data; + InputStream &is = *(InputStream *)user_data; - if (!is->LockSeek(offset, whence, IgnoreError())) + if (!is.LockSeek(offset, whence, IgnoreError())) return -1; - return is->GetOffset(); + return is.GetOffset(); } static sf_count_t sndfile_vio_read(void *ptr, sf_count_t count, void *user_data) { - struct input_stream *is = (struct input_stream *)user_data; + InputStream &is = *(InputStream *)user_data; Error error; - size_t nbytes = is->LockRead(ptr, count, error); + size_t nbytes = is.LockRead(ptr, count, error); if (nbytes == 0 && error.IsDefined()) { LogError(error); return -1; @@ -77,9 +77,9 @@ sndfile_vio_write(gcc_unused const void *ptr, static sf_count_t sndfile_vio_tell(void *user_data) { - const struct input_stream *is = (const struct input_stream *)user_data; + const InputStream &is = *(const InputStream *)user_data; - return is->GetOffset(); + return is.GetOffset(); } /** @@ -113,7 +113,7 @@ time_to_frame(float t, const AudioFormat *audio_format) } static void -sndfile_stream_decode(Decoder &decoder, struct input_stream *is) +sndfile_stream_decode(Decoder &decoder, InputStream &is) { SNDFILE *sf; SF_INFO info; @@ -123,7 +123,7 @@ sndfile_stream_decode(Decoder &decoder, struct input_stream *is) info.format = 0; - sf = sf_open_virtual(&vio, SFM_READ, &info, is); + sf = sf_open_virtual(&vio, SFM_READ, &info, &is); if (sf == nullptr) { LogWarning(sndfile_domain, "sf_open_virtual() failed"); return; diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx index c1d3566e1..8705d875f 100644 --- a/src/decoder/VorbisDecoderPlugin.cxx +++ b/src/decoder/VorbisDecoderPlugin.cxx @@ -54,14 +54,14 @@ struct vorbis_input_stream { Decoder *decoder; - struct input_stream *input_stream; + InputStream *input_stream; bool seekable; }; static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *data) { struct vorbis_input_stream *vis = (struct vorbis_input_stream *)data; - size_t ret = decoder_read(vis->decoder, vis->input_stream, + size_t ret = decoder_read(vis->decoder, *vis->input_stream, ptr, size * nmemb); errno = 0; @@ -127,11 +127,11 @@ vorbis_strerror(int code) static bool vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf, - Decoder *decoder, struct input_stream *input_stream) + Decoder *decoder, InputStream &input_stream) { vis->decoder = decoder; - vis->input_stream = input_stream; - vis->seekable = input_stream->CheapSeeking(); + vis->input_stream = &input_stream; + vis->seekable = input_stream.CheapSeeking(); int ret = ov_open_callbacks(vis, vf, NULL, 0, vorbis_is_callbacks); if (ret < 0) { @@ -147,7 +147,7 @@ vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf, } static void -vorbis_send_comments(Decoder &decoder, struct input_stream *is, +vorbis_send_comments(Decoder &decoder, InputStream &is, char **comments) { Tag *tag = vorbis_comments_to_tag(comments); @@ -176,14 +176,14 @@ vorbis_interleave(float *dest, const float *const*src, /* public */ static void vorbis_stream_decode(Decoder &decoder, - struct input_stream *input_stream) + InputStream &input_stream) { if (ogg_codec_detect(&decoder, input_stream) != OGG_CODEC_VORBIS) return; /* rewind the stream, because ogg_codec_detect() has moved it */ - input_stream->LockRewind(IgnoreError()); + input_stream.LockRewind(IgnoreError()); struct vorbis_input_stream vis; OggVorbis_File vf; @@ -303,7 +303,7 @@ vorbis_stream_decode(Decoder &decoder, } static bool -vorbis_scan_stream(struct input_stream *is, +vorbis_scan_stream(InputStream &is, const struct tag_handler *handler, void *handler_ctx) { struct vorbis_input_stream vis; diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx index 9805a5f78..3588f0797 100644 --- a/src/decoder/WavpackDecoderPlugin.cxx +++ b/src/decoder/WavpackDecoderPlugin.cxx @@ -346,7 +346,7 @@ wavpack_scan_file(const char *fname, /* This struct is needed for per-stream last_byte storage. */ struct wavpack_input { Decoder *decoder; - struct input_stream *is; + InputStream *is; /* Needed for push_back_byte() */ int last_byte; }; @@ -378,7 +378,7 @@ wavpack_input_read_bytes(void *id, void *data, int32_t bcount) until the buffer is full */ while (bcount > 0) { size_t nbytes = decoder_read( - wpin(id)->decoder, wpin(id)->is, buf, bcount + wpin(id)->decoder, *wpin(id)->is, buf, bcount ); if (nbytes == 0) { /* EOF, error or a decoder command */ @@ -450,19 +450,19 @@ static WavpackStreamReader mpd_is_reader = { static void wavpack_input_init(struct wavpack_input *isp, Decoder &decoder, - struct input_stream *is) + InputStream &is) { isp->decoder = &decoder; - isp->is = is; + isp->is = &is; isp->last_byte = EOF; } -static struct input_stream * +static InputStream * wavpack_open_wvc(Decoder &decoder, const char *uri, Mutex &mutex, Cond &cond, struct wavpack_input *wpi) { - struct input_stream *is_wvc; + InputStream *is_wvc; char *wvc_url = nullptr; char first_byte; size_t nbytes; @@ -476,7 +476,7 @@ wavpack_open_wvc(Decoder &decoder, const char *uri, wvc_url = g_strconcat(uri, "c", nullptr); - is_wvc = input_stream::Open(wvc_url, mutex, cond, IgnoreError()); + is_wvc = InputStream::Open(wvc_url, mutex, cond, IgnoreError()); g_free(wvc_url); if (is_wvc == nullptr) @@ -487,7 +487,7 @@ wavpack_open_wvc(Decoder &decoder, const char *uri, * about a possible 404 error. */ nbytes = decoder_read( - decoder, is_wvc, &first_byte, sizeof(first_byte) + decoder, *is_wvc, &first_byte, sizeof(first_byte) ); if (nbytes == 0) { is_wvc->Close(); @@ -495,7 +495,7 @@ wavpack_open_wvc(Decoder &decoder, const char *uri, } /* push it back */ - wavpack_input_init(wpi, decoder, is_wvc); + wavpack_input_init(wpi, decoder, *is_wvc); wpi->last_byte = first_byte; return is_wvc; } @@ -504,17 +504,17 @@ wavpack_open_wvc(Decoder &decoder, const char *uri, * Decodes a stream. */ static void -wavpack_streamdecode(Decoder & decoder, struct input_stream *is) +wavpack_streamdecode(Decoder &decoder, InputStream &is) { char error[ERRORLEN]; WavpackContext *wpc; - struct input_stream *is_wvc; + InputStream *is_wvc; int open_flags = OPEN_NORMALIZE; struct wavpack_input isp, isp_wvc; - bool can_seek = is->seekable; + bool can_seek = is.seekable; - is_wvc = wavpack_open_wvc(decoder, is->uri.c_str(), - is->mutex, is->cond, + is_wvc = wavpack_open_wvc(decoder, is.uri.c_str(), + is.mutex, is.cond, &isp_wvc); if (is_wvc != nullptr) { open_flags |= OPEN_WVC; diff --git a/src/input/ArchiveInputPlugin.cxx b/src/input/ArchiveInputPlugin.cxx index 38435d563..c5c881330 100644 --- a/src/input/ArchiveInputPlugin.cxx +++ b/src/input/ArchiveInputPlugin.cxx @@ -39,13 +39,13 @@ * parent_stream so tar plugin fetches file data from gzip * plugin and gzip fetches file from disk */ -static struct input_stream * +static InputStream * input_archive_open(const char *pathname, Mutex &mutex, Cond &cond, Error &error) { const struct archive_plugin *arplug; - struct input_stream *is; + InputStream *is; if (!PathTraits::IsAbsoluteFS(pathname)) return NULL; diff --git a/src/input/CdioParanoiaInputPlugin.cxx b/src/input/CdioParanoiaInputPlugin.cxx index b606df869..c67f8492b 100644 --- a/src/input/CdioParanoiaInputPlugin.cxx +++ b/src/input/CdioParanoiaInputPlugin.cxx @@ -43,7 +43,7 @@ #include struct CdioParanoiaInputStream { - struct input_stream base; + InputStream base; cdrom_drive_t *drv; CdIo_t *cdio; @@ -78,7 +78,7 @@ struct CdioParanoiaInputStream { static constexpr Domain cdio_domain("cdio"); static void -input_cdio_close(struct input_stream *is) +input_cdio_close(InputStream *is) { CdioParanoiaInputStream *i = (CdioParanoiaInputStream *)is; @@ -149,7 +149,7 @@ cdio_detect_device(void) return path; } -static struct input_stream * +static InputStream * input_cdio_open(const char *uri, Mutex &mutex, Cond &cond, Error &error) @@ -247,7 +247,7 @@ input_cdio_open(const char *uri, } static bool -input_cdio_seek(struct input_stream *is, +input_cdio_seek(InputStream *is, InputPlugin::offset_type offset, int whence, Error &error) { CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is; @@ -284,7 +284,7 @@ input_cdio_seek(struct input_stream *is, } static size_t -input_cdio_read(struct input_stream *is, void *ptr, size_t length, +input_cdio_read(InputStream *is, void *ptr, size_t length, Error &error) { CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is; @@ -354,7 +354,7 @@ input_cdio_read(struct input_stream *is, void *ptr, size_t length, } static bool -input_cdio_eof(struct input_stream *is) +input_cdio_eof(InputStream *is) { CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is; diff --git a/src/input/CurlInputPlugin.cxx b/src/input/CurlInputPlugin.cxx index bce0c94aa..aca9d9608 100644 --- a/src/input/CurlInputPlugin.cxx +++ b/src/input/CurlInputPlugin.cxx @@ -131,7 +131,7 @@ public: }; struct input_curl { - struct input_stream base; + InputStream base; /* some buffers which were passed to libcurl, which we have too free */ @@ -162,7 +162,7 @@ struct input_curl { std::string meta_name; /** the tag object ready to be requested via - input_stream::ReadTag() */ + InputStream::ReadTag() */ Tag *tag; Error postponed_error; @@ -636,7 +636,7 @@ input_curl::~input_curl() } static bool -input_curl_check(struct input_stream *is, Error &error) +input_curl_check(InputStream *is, Error &error) { struct input_curl *c = (struct input_curl *)is; @@ -650,7 +650,7 @@ input_curl_check(struct input_stream *is, Error &error) } static Tag * -input_curl_tag(struct input_stream *is) +input_curl_tag(InputStream *is) { struct input_curl *c = (struct input_curl *)is; Tag *tag = c->tag; @@ -741,7 +741,7 @@ copy_icy_tag(struct input_curl *c) } static bool -input_curl_available(struct input_stream *is) +input_curl_available(InputStream *is) { struct input_curl *c = (struct input_curl *)is; @@ -750,7 +750,7 @@ input_curl_available(struct input_stream *is) } static size_t -input_curl_read(struct input_stream *is, void *ptr, size_t size, +input_curl_read(InputStream *is, void *ptr, size_t size, Error &error) { struct input_curl *c = (struct input_curl *)is; @@ -795,7 +795,7 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size, } static void -input_curl_close(struct input_stream *is) +input_curl_close(InputStream *is) { struct input_curl *c = (struct input_curl *)is; @@ -803,7 +803,7 @@ input_curl_close(struct input_stream *is) } static bool -input_curl_eof(gcc_unused struct input_stream *is) +input_curl_eof(gcc_unused InputStream *is) { struct input_curl *c = (struct input_curl *)is; @@ -976,7 +976,7 @@ input_curl_easy_init(struct input_curl *c, Error &error) } static bool -input_curl_seek(struct input_stream *is, InputPlugin::offset_type offset, +input_curl_seek(InputStream *is, InputPlugin::offset_type offset, int whence, Error &error) { @@ -1080,7 +1080,7 @@ input_curl_seek(struct input_stream *is, InputPlugin::offset_type offset, return true; } -static struct input_stream * +static InputStream * input_curl_open(const char *url, Mutex &mutex, Cond &cond, Error &error) { diff --git a/src/input/DespotifyInputPlugin.cxx b/src/input/DespotifyInputPlugin.cxx index 6fc408de9..5476b41fd 100644 --- a/src/input/DespotifyInputPlugin.cxx +++ b/src/input/DespotifyInputPlugin.cxx @@ -38,7 +38,7 @@ extern "C" { #include struct DespotifyInputStream { - struct input_stream base; + InputStream base; struct despotify_session *session; struct ds_track *track; @@ -121,7 +121,7 @@ static void callback(gcc_unused struct despotify_session* ds, } -static struct input_stream * +static InputStream * input_despotify_open(const char *url, Mutex &mutex, Cond &cond, gcc_unused Error &error) @@ -171,7 +171,7 @@ input_despotify_open(const char *url, } static size_t -input_despotify_read(struct input_stream *is, void *ptr, size_t size, +input_despotify_read(InputStream *is, void *ptr, size_t size, gcc_unused Error &error) { DespotifyInputStream *ctx = (DespotifyInputStream *)is; @@ -191,7 +191,7 @@ input_despotify_read(struct input_stream *is, void *ptr, size_t size, } static void -input_despotify_close(struct input_stream *is) +input_despotify_close(InputStream *is) { DespotifyInputStream *ctx = (DespotifyInputStream *)is; @@ -200,7 +200,7 @@ input_despotify_close(struct input_stream *is) } static bool -input_despotify_eof(struct input_stream *is) +input_despotify_eof(InputStream *is) { DespotifyInputStream *ctx = (DespotifyInputStream *)is; @@ -208,7 +208,7 @@ input_despotify_eof(struct input_stream *is) } static Tag * -input_despotify_tag(struct input_stream *is) +input_despotify_tag(InputStream *is) { DespotifyInputStream *ctx = (DespotifyInputStream *)is; Tag *tag = ctx->tag; diff --git a/src/input/FfmpegInputPlugin.cxx b/src/input/FfmpegInputPlugin.cxx index cba978029..8f9cd0b86 100644 --- a/src/input/FfmpegInputPlugin.cxx +++ b/src/input/FfmpegInputPlugin.cxx @@ -36,7 +36,7 @@ extern "C" { #include struct FfmpegInputStream { - struct input_stream base; + InputStream base; AVIOContext *h; @@ -86,7 +86,7 @@ input_ffmpeg_init(gcc_unused const config_param ¶m, return true; } -static struct input_stream * +static InputStream * input_ffmpeg_open(const char *uri, Mutex &mutex, Cond &cond, Error &error) @@ -112,7 +112,7 @@ input_ffmpeg_open(const char *uri, } static size_t -input_ffmpeg_read(struct input_stream *is, void *ptr, size_t size, +input_ffmpeg_read(InputStream *is, void *ptr, size_t size, Error &error) { FfmpegInputStream *i = (FfmpegInputStream *)is; @@ -131,7 +131,7 @@ input_ffmpeg_read(struct input_stream *is, void *ptr, size_t size, } static void -input_ffmpeg_close(struct input_stream *is) +input_ffmpeg_close(InputStream *is) { FfmpegInputStream *i = (FfmpegInputStream *)is; @@ -139,7 +139,7 @@ input_ffmpeg_close(struct input_stream *is) } static bool -input_ffmpeg_eof(struct input_stream *is) +input_ffmpeg_eof(InputStream *is) { FfmpegInputStream *i = (FfmpegInputStream *)is; @@ -147,7 +147,7 @@ input_ffmpeg_eof(struct input_stream *is) } static bool -input_ffmpeg_seek(struct input_stream *is, InputPlugin::offset_type offset, +input_ffmpeg_seek(InputStream *is, InputPlugin::offset_type offset, int whence, Error &error) { diff --git a/src/input/FileInputPlugin.cxx b/src/input/FileInputPlugin.cxx index a351edf98..26e40d609 100644 --- a/src/input/FileInputPlugin.cxx +++ b/src/input/FileInputPlugin.cxx @@ -36,7 +36,7 @@ static constexpr Domain file_domain("file"); struct FileInputStream { - struct input_stream base; + InputStream base; int fd; @@ -54,7 +54,7 @@ struct FileInputStream { } }; -static struct input_stream * +static InputStream * input_file_open(const char *filename, Mutex &mutex, Cond &cond, Error &error) @@ -96,7 +96,7 @@ input_file_open(const char *filename, } static bool -input_file_seek(struct input_stream *is, InputPlugin::offset_type offset, +input_file_seek(InputStream *is, InputPlugin::offset_type offset, int whence, Error &error) { @@ -113,7 +113,7 @@ input_file_seek(struct input_stream *is, InputPlugin::offset_type offset, } static size_t -input_file_read(struct input_stream *is, void *ptr, size_t size, +input_file_read(InputStream *is, void *ptr, size_t size, Error &error) { FileInputStream *fis = (FileInputStream *)is; @@ -130,7 +130,7 @@ input_file_read(struct input_stream *is, void *ptr, size_t size, } static void -input_file_close(struct input_stream *is) +input_file_close(InputStream *is) { FileInputStream *fis = (FileInputStream *)is; @@ -138,7 +138,7 @@ input_file_close(struct input_stream *is) } static bool -input_file_eof(struct input_stream *is) +input_file_eof(InputStream *is) { return is->offset >= is->size; } diff --git a/src/input/MmsInputPlugin.cxx b/src/input/MmsInputPlugin.cxx index ed391bc9f..6f9c1c92e 100644 --- a/src/input/MmsInputPlugin.cxx +++ b/src/input/MmsInputPlugin.cxx @@ -31,7 +31,7 @@ #include struct MmsInputStream { - struct input_stream base; + InputStream base; mmsx_t *mms; @@ -56,7 +56,7 @@ struct MmsInputStream { static constexpr Domain mms_domain("mms"); -static struct input_stream * +static InputStream * input_mms_open(const char *url, Mutex &mutex, Cond &cond, Error &error) @@ -78,7 +78,7 @@ input_mms_open(const char *url, } static size_t -input_mms_read(struct input_stream *is, void *ptr, size_t size, +input_mms_read(InputStream *is, void *ptr, size_t size, Error &error) { MmsInputStream *m = (MmsInputStream *)is; @@ -99,7 +99,7 @@ input_mms_read(struct input_stream *is, void *ptr, size_t size, } static void -input_mms_close(struct input_stream *is) +input_mms_close(InputStream *is) { MmsInputStream *m = (MmsInputStream *)is; @@ -107,7 +107,7 @@ input_mms_close(struct input_stream *is) } static bool -input_mms_eof(struct input_stream *is) +input_mms_eof(InputStream *is) { MmsInputStream *m = (MmsInputStream *)is; diff --git a/src/input/RewindInputPlugin.cxx b/src/input/RewindInputPlugin.cxx index c451ad332..8d229c54f 100644 --- a/src/input/RewindInputPlugin.cxx +++ b/src/input/RewindInputPlugin.cxx @@ -30,9 +30,9 @@ extern const InputPlugin rewind_input_plugin; struct RewindInputStream { - struct input_stream base; + InputStream base; - struct input_stream *input; + InputStream *input; /** * The read position within the buffer. Undefined as long as @@ -55,7 +55,7 @@ struct RewindInputStream { */ char buffer[64 * 1024]; - RewindInputStream(input_stream *_input) + RewindInputStream(InputStream *_input) :base(rewind_input_plugin, _input->uri.c_str(), _input->mutex, _input->cond), input(_input), tail(0) { @@ -80,8 +80,8 @@ struct RewindInputStream { * attributes. */ void CopyAttributes() { - struct input_stream *dest = &base; - const struct input_stream *src = input; + InputStream *dest = &base; + const InputStream *src = input; assert(dest != src); @@ -98,7 +98,7 @@ struct RewindInputStream { }; static void -input_rewind_close(struct input_stream *is) +input_rewind_close(InputStream *is) { RewindInputStream *r = (RewindInputStream *)is; @@ -106,7 +106,7 @@ input_rewind_close(struct input_stream *is) } static bool -input_rewind_check(struct input_stream *is, Error &error) +input_rewind_check(InputStream *is, Error &error) { RewindInputStream *r = (RewindInputStream *)is; @@ -114,7 +114,7 @@ input_rewind_check(struct input_stream *is, Error &error) } static void -input_rewind_update(struct input_stream *is) +input_rewind_update(InputStream *is) { RewindInputStream *r = (RewindInputStream *)is; @@ -123,7 +123,7 @@ input_rewind_update(struct input_stream *is) } static Tag * -input_rewind_tag(struct input_stream *is) +input_rewind_tag(InputStream *is) { RewindInputStream *r = (RewindInputStream *)is; @@ -131,7 +131,7 @@ input_rewind_tag(struct input_stream *is) } static bool -input_rewind_available(struct input_stream *is) +input_rewind_available(InputStream *is) { RewindInputStream *r = (RewindInputStream *)is; @@ -139,7 +139,7 @@ input_rewind_available(struct input_stream *is) } static size_t -input_rewind_read(struct input_stream *is, void *ptr, size_t size, +input_rewind_read(InputStream *is, void *ptr, size_t size, Error &error) { RewindInputStream *r = (RewindInputStream *)is; @@ -182,7 +182,7 @@ input_rewind_read(struct input_stream *is, void *ptr, size_t size, } static bool -input_rewind_eof(struct input_stream *is) +input_rewind_eof(InputStream *is) { RewindInputStream *r = (RewindInputStream *)is; @@ -190,7 +190,7 @@ input_rewind_eof(struct input_stream *is) } static bool -input_rewind_seek(struct input_stream *is, InputPlugin::offset_type offset, +input_rewind_seek(InputStream *is, InputPlugin::offset_type offset, int whence, Error &error) { @@ -237,8 +237,8 @@ const InputPlugin rewind_input_plugin = { input_rewind_seek, }; -struct input_stream * -input_rewind_open(struct input_stream *is) +InputStream * +input_rewind_open(InputStream *is) { assert(is != NULL); assert(is->offset == 0); diff --git a/src/input/RewindInputPlugin.hxx b/src/input/RewindInputPlugin.hxx index cf21e92f1..2d461970a 100644 --- a/src/input/RewindInputPlugin.hxx +++ b/src/input/RewindInputPlugin.hxx @@ -29,9 +29,9 @@ #include "check.h" -struct input_stream; +struct InputStream; -struct input_stream * -input_rewind_open(struct input_stream *is); +InputStream * +input_rewind_open(InputStream *is); #endif diff --git a/src/playlist/AsxPlaylistPlugin.cxx b/src/playlist/AsxPlaylistPlugin.cxx index 14063fdf2..23985cad8 100644 --- a/src/playlist/AsxPlaylistPlugin.cxx +++ b/src/playlist/AsxPlaylistPlugin.cxx @@ -205,7 +205,7 @@ asx_parser_destroy(gpointer data) */ static SongEnumerator * -asx_open_stream(struct input_stream *is) +asx_open_stream(InputStream &is) { AsxParser parser; GMarkupParseContext *context; @@ -222,7 +222,7 @@ asx_open_stream(struct input_stream *is) &parser, asx_parser_destroy); while (true) { - nbytes = is->LockRead(buffer, sizeof(buffer), error2); + nbytes = is.LockRead(buffer, sizeof(buffer), error2); if (nbytes == 0) { if (error2.IsDefined()) { g_markup_parse_context_free(context); diff --git a/src/playlist/CuePlaylistPlugin.cxx b/src/playlist/CuePlaylistPlugin.cxx index 5b0b6c6d2..0ec030a54 100644 --- a/src/playlist/CuePlaylistPlugin.cxx +++ b/src/playlist/CuePlaylistPlugin.cxx @@ -30,12 +30,12 @@ #include class CuePlaylist final : public SongEnumerator { - struct input_stream *is; + InputStream &is; TextInputStream tis; CueParser parser; public: - CuePlaylist(struct input_stream *_is) + CuePlaylist(InputStream &_is) :is(_is), tis(is) { } @@ -43,7 +43,7 @@ class CuePlaylist final : public SongEnumerator { }; static SongEnumerator * -cue_playlist_open_stream(struct input_stream *is) +cue_playlist_open_stream(InputStream &is) { return new CuePlaylist(is); } diff --git a/src/playlist/ExtM3uPlaylistPlugin.cxx b/src/playlist/ExtM3uPlaylistPlugin.cxx index 9d164185a..8d260fec7 100644 --- a/src/playlist/ExtM3uPlaylistPlugin.cxx +++ b/src/playlist/ExtM3uPlaylistPlugin.cxx @@ -35,7 +35,7 @@ class ExtM3uPlaylist final : public SongEnumerator { TextInputStream tis; public: - ExtM3uPlaylist(input_stream *is) + ExtM3uPlaylist(InputStream &is) :tis(is) { } @@ -49,7 +49,7 @@ public: }; static SongEnumerator * -extm3u_open_stream(struct input_stream *is) +extm3u_open_stream(InputStream &is) { ExtM3uPlaylist *playlist = new ExtM3uPlaylist(is); diff --git a/src/playlist/M3uPlaylistPlugin.cxx b/src/playlist/M3uPlaylistPlugin.cxx index c0b63ca2d..20b192cf5 100644 --- a/src/playlist/M3uPlaylistPlugin.cxx +++ b/src/playlist/M3uPlaylistPlugin.cxx @@ -29,7 +29,7 @@ class M3uPlaylist final : public SongEnumerator { TextInputStream tis; public: - M3uPlaylist(input_stream *is) + M3uPlaylist(InputStream &is) :tis(is) { } @@ -37,7 +37,7 @@ public: }; static SongEnumerator * -m3u_open_stream(struct input_stream *is) +m3u_open_stream(InputStream &is) { return new M3uPlaylist(is); } diff --git a/src/playlist/PlsPlaylistPlugin.cxx b/src/playlist/PlsPlaylistPlugin.cxx index f3be73a20..46143225b 100644 --- a/src/playlist/PlsPlaylistPlugin.cxx +++ b/src/playlist/PlsPlaylistPlugin.cxx @@ -107,7 +107,7 @@ pls_parser(GKeyFile *keyfile, std::forward_list &songs) } static SongEnumerator * -pls_open_stream(struct input_stream *is) +pls_open_stream(InputStream &is) { GError *error = NULL; Error error2; @@ -119,7 +119,7 @@ pls_open_stream(struct input_stream *is) std::string kf_data; do { - nbytes = is->LockRead(buffer, sizeof(buffer), error2); + nbytes = is.LockRead(buffer, sizeof(buffer), error2); if (nbytes == 0) { if (error2.IsDefined()) { LogError(error2); diff --git a/src/playlist/RssPlaylistPlugin.cxx b/src/playlist/RssPlaylistPlugin.cxx index 4aa6f1026..43ad68cf6 100644 --- a/src/playlist/RssPlaylistPlugin.cxx +++ b/src/playlist/RssPlaylistPlugin.cxx @@ -202,7 +202,7 @@ rss_parser_destroy(gpointer data) */ static SongEnumerator * -rss_open_stream(struct input_stream *is) +rss_open_stream(InputStream &is) { RssParser parser; GMarkupParseContext *context; @@ -219,7 +219,7 @@ rss_open_stream(struct input_stream *is) &parser, rss_parser_destroy); while (true) { - nbytes = is->LockRead(buffer, sizeof(buffer), error2); + nbytes = is.LockRead(buffer, sizeof(buffer), error2); if (nbytes == 0) { if (error2.IsDefined()) { g_markup_parse_context_free(context); diff --git a/src/playlist/SoundCloudPlaylistPlugin.cxx b/src/playlist/SoundCloudPlaylistPlugin.cxx index d70e4ed51..f9c030a21 100644 --- a/src/playlist/SoundCloudPlaylistPlugin.cxx +++ b/src/playlist/SoundCloudPlaylistPlugin.cxx @@ -253,8 +253,8 @@ soundcloud_parse_json(const char *url, yajl_handle hand, unsigned char *ubuffer = (unsigned char *)buffer; Error error; - input_stream *input_stream = input_stream::Open(url, mutex, cond, - error); + InputStream *input_stream = InputStream::Open(url, mutex, cond, + error); if (input_stream == NULL) { if (error.IsDefined()) LogError(error); diff --git a/src/playlist/XspfPlaylistPlugin.cxx b/src/playlist/XspfPlaylistPlugin.cxx index c1ce21e6d..75991cfd4 100644 --- a/src/playlist/XspfPlaylistPlugin.cxx +++ b/src/playlist/XspfPlaylistPlugin.cxx @@ -220,7 +220,7 @@ xspf_parser_destroy(gpointer data) */ static SongEnumerator * -xspf_open_stream(struct input_stream *is) +xspf_open_stream(InputStream &is) { XspfParser parser; GMarkupParseContext *context; @@ -237,7 +237,7 @@ xspf_open_stream(struct input_stream *is) &parser, xspf_parser_destroy); while (true) { - nbytes = is->LockRead(buffer, sizeof(buffer), error2); + nbytes = is.LockRead(buffer, sizeof(buffer), error2); if (nbytes == 0) { if (error2.IsDefined()) { g_markup_parse_context_free(context); diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx index 6233443c2..044b85d79 100644 --- a/test/dump_playlist.cxx +++ b/test/dump_playlist.cxx @@ -85,11 +85,10 @@ decoder_seek_error(gcc_unused Decoder &decoder) size_t decoder_read(gcc_unused Decoder *decoder, - struct input_stream *is, + InputStream &is, void *buffer, size_t length) { - Error error; - return is->LockRead(buffer, length, error); + return is.LockRead(buffer, length, IgnoreError()); } void @@ -100,7 +99,7 @@ decoder_timestamp(gcc_unused Decoder &decoder, DecoderCommand decoder_data(gcc_unused Decoder &decoder, - gcc_unused struct input_stream *is, + gcc_unused InputStream *is, const void *data, size_t datalen, gcc_unused uint16_t kbit_rate) { @@ -110,7 +109,7 @@ decoder_data(gcc_unused Decoder &decoder, DecoderCommand decoder_tag(gcc_unused Decoder &decoder, - gcc_unused struct input_stream *is, + gcc_unused InputStream *is, gcc_unused Tag &&tag) { return DecoderCommand::NONE; @@ -143,7 +142,7 @@ decoder_mixramp(gcc_unused Decoder &decoder, int main(int argc, char **argv) { const char *uri; - struct input_stream *is = NULL; + InputStream *is = NULL; Song *song; if (argc != 3) { @@ -192,12 +191,12 @@ int main(int argc, char **argv) if (playlist == NULL) { /* open the stream and wait until it becomes ready */ - is = input_stream::Open(uri, mutex, cond, error); + is = InputStream::Open(uri, mutex, cond, error); if (is == NULL) { if (error.IsDefined()) LogError(error); else - g_printerr("input_stream::Open() failed\n"); + g_printerr("InputStream::Open() failed\n"); return 2; } @@ -205,7 +204,7 @@ int main(int argc, char **argv) /* open the playlist */ - playlist = playlist_list_open_stream(is, uri); + playlist = playlist_list_open_stream(*is, uri); if (playlist == NULL) { is->Close(); g_printerr("Failed to open playlist\n"); diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx index 00281bd8b..bb84f5cce 100644 --- a/test/dump_text_file.cxx +++ b/test/dump_text_file.cxx @@ -57,46 +57,45 @@ dump_text_file(TextInputStream &is) } static int -dump_input_stream(struct input_stream *is) +dump_input_stream(InputStream &is) { Error error; - is->Lock(); + is.Lock(); /* wait until the stream becomes ready */ - is->WaitReady(); + is.WaitReady(); - if (!is->Check(error)) { + if (!is.Check(error)) { LogError(error); - is->Unlock(); + is.Unlock(); return EXIT_FAILURE; } /* read data and tags from the stream */ - is->Unlock(); + is.Unlock(); { TextInputStream tis(is); dump_text_file(tis); } - is->Lock(); + is.Lock(); - if (!is->Check(error)) { + if (!is.Check(error)) { LogError(error); - is->Unlock(); + is.Unlock(); return EXIT_FAILURE; } - is->Unlock(); + is.Unlock(); return 0; } int main(int argc, char **argv) { - struct input_stream *is; int ret; if (argc != 2) { @@ -134,9 +133,9 @@ int main(int argc, char **argv) Mutex mutex; Cond cond; - is = input_stream::Open(argv[1], mutex, cond, error); + InputStream *is = InputStream::Open(argv[1], mutex, cond, error); if (is != NULL) { - ret = dump_input_stream(is); + ret = dump_input_stream(*is); is->Close(); } else { if (error.IsDefined()) diff --git a/test/read_tags.cxx b/test/read_tags.cxx index 449557597..9511072ff 100644 --- a/test/read_tags.cxx +++ b/test/read_tags.cxx @@ -73,11 +73,10 @@ decoder_seek_error(gcc_unused Decoder &decoder) size_t decoder_read(gcc_unused Decoder *decoder, - struct input_stream *is, + InputStream &is, void *buffer, size_t length) { - Error error; - return is->LockRead(buffer, length, error); + return is.LockRead(buffer, length, IgnoreError()); } void @@ -88,7 +87,7 @@ decoder_timestamp(gcc_unused Decoder &decoder, DecoderCommand decoder_data(gcc_unused Decoder &decoder, - gcc_unused struct input_stream *is, + gcc_unused InputStream *is, const void *data, size_t datalen, gcc_unused uint16_t kbit_rate) { @@ -98,7 +97,7 @@ decoder_data(gcc_unused Decoder &decoder, DecoderCommand decoder_tag(gcc_unused Decoder &decoder, - gcc_unused struct input_stream *is, + gcc_unused InputStream *is, gcc_unused Tag &&tag) { return DecoderCommand::NONE; @@ -189,8 +188,8 @@ int main(int argc, char **argv) Mutex mutex; Cond cond; - input_stream *is = input_stream::Open(path, mutex, cond, - error); + InputStream *is = InputStream::Open(path, mutex, cond, + error); if (is == NULL) { g_printerr("Failed to open %s: %s\n", path, error.GetMessage()); diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx index 99a312f3d..1044856c2 100644 --- a/test/run_decoder.cxx +++ b/test/run_decoder.cxx @@ -94,10 +94,10 @@ decoder_seek_error(gcc_unused Decoder &decoder) size_t decoder_read(gcc_unused Decoder *decoder, - struct input_stream *is, + InputStream &is, void *buffer, size_t length) { - return is->LockRead(buffer, length, IgnoreError()); + return is.LockRead(buffer, length, IgnoreError()); } void @@ -108,7 +108,7 @@ decoder_timestamp(gcc_unused Decoder &decoder, DecoderCommand decoder_data(gcc_unused Decoder &decoder, - gcc_unused struct input_stream *is, + gcc_unused InputStream *is, const void *data, size_t datalen, gcc_unused uint16_t kbit_rate) { @@ -118,7 +118,7 @@ decoder_data(gcc_unused Decoder &decoder, DecoderCommand decoder_tag(gcc_unused Decoder &decoder, - gcc_unused struct input_stream *is, + gcc_unused InputStream *is, gcc_unused Tag &&tag) { return DecoderCommand::NONE; @@ -192,13 +192,13 @@ int main(int argc, char **argv) Mutex mutex; Cond cond; - input_stream *is = - input_stream::Open(decoder.uri, mutex, cond, error); + InputStream *is = + InputStream::Open(decoder.uri, mutex, cond, error); if (is == NULL) { if (error.IsDefined()) LogError(error); else - g_printerr("input_stream::Open() failed\n"); + g_printerr("InputStream::Open() failed\n"); return 1; } diff --git a/test/run_input.cxx b/test/run_input.cxx index 042c7ddd0..3817ed418 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -49,7 +49,7 @@ my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level, } static int -dump_input_stream(struct input_stream *is) +dump_input_stream(InputStream *is) { Error error; char buffer[4096]; @@ -110,7 +110,7 @@ dump_input_stream(struct input_stream *is) int main(int argc, char **argv) { Error error; - struct input_stream *is; + InputStream *is; int ret; if (argc != 2) { @@ -147,7 +147,7 @@ int main(int argc, char **argv) Mutex mutex; Cond cond; - is = input_stream::Open(argv[1], mutex, cond, error); + is = InputStream::Open(argv[1], mutex, cond, error); if (is != NULL) { ret = dump_input_stream(is); is->Close();