InputLegacy: move functions to the input_stream class

This commit is contained in:
Max Kellermann 2013-09-05 00:06:31 +02:00
parent 52ffdb0a55
commit 7d0269d2ce
47 changed files with 461 additions and 608 deletions

View File

@ -716,7 +716,6 @@ libinput_a_SOURCES = \
src/InputInit.cxx src/InputInit.hxx \ src/InputInit.cxx src/InputInit.hxx \
src/InputRegistry.cxx src/InputRegistry.hxx \ src/InputRegistry.cxx src/InputRegistry.hxx \
src/InputStream.cxx src/InputStream.hxx \ src/InputStream.cxx src/InputStream.hxx \
src/InputLegacy.hxx \
src/InputPlugin.hxx \ src/InputPlugin.hxx \
src/InputInternal.cxx src/InputInternal.hxx \ src/InputInternal.cxx src/InputInternal.hxx \
src/input/RewindInputPlugin.cxx src/input/RewindInputPlugin.hxx \ src/input/RewindInputPlugin.cxx src/input/RewindInputPlugin.hxx \

View File

@ -268,29 +268,29 @@ size_t decoder_read(struct decoder *decoder,
if (length == 0) if (length == 0)
return 0; return 0;
input_stream_lock(is); is->Lock();
while (true) { while (true) {
if (decoder_check_cancel_read(decoder)) { if (decoder_check_cancel_read(decoder)) {
input_stream_unlock(is); is->Unlock();
return 0; return 0;
} }
if (input_stream_available(is)) if (is->IsAvailable())
break; break;
is->cond.wait(is->mutex); is->cond.wait(is->mutex);
} }
Error error; Error error;
size_t nbytes = input_stream_read(is, buffer, length, error); size_t nbytes = is->Read(buffer, length, error);
assert(nbytes == 0 || !error.IsDefined()); assert(nbytes == 0 || !error.IsDefined());
assert(nbytes > 0 || error.IsDefined() || input_stream_eof(is)); assert(nbytes > 0 || error.IsDefined() || is->IsEOF());
if (gcc_unlikely(nbytes == 0 && error.IsDefined())) if (gcc_unlikely(nbytes == 0 && error.IsDefined()))
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
input_stream_unlock(is); is->Unlock();
return nbytes; return nbytes;
} }
@ -338,7 +338,7 @@ update_stream_tag(struct decoder *decoder, struct input_stream *is)
Tag *tag; Tag *tag;
tag = is != NULL tag = is != NULL
? input_stream_lock_tag(is) ? is->LockReadTag()
: NULL; : NULL;
if (tag == NULL) { if (tag == NULL) {
tag = decoder->song_tag; tag = decoder->song_tag;

View File

@ -30,7 +30,6 @@
#include "check.h" #include "check.h"
#include "DecoderCommand.hxx" #include "DecoderCommand.hxx"
#include "DecoderPlugin.hxx" #include "DecoderPlugin.hxx"
#include "InputLegacy.hxx"
#include "replay_gain_info.h" #include "replay_gain_info.h"
#include "Tag.hxx" #include "Tag.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"

View File

@ -60,7 +60,7 @@ decoder_command_finished_locked(struct decoder_control *dc)
} }
/** /**
* Opens the input stream with input_stream_open(), and waits until * Opens the input stream with input_stream::Open(), and waits until
* the stream gets ready. If a decoder STOP command is received * the stream gets ready. If a decoder STOP command is received
* during that, it cancels the operation (but does not close the * during that, it cancels the operation (but does not close the
* stream). * stream).
@ -75,7 +75,7 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri)
{ {
Error error; Error error;
input_stream *is = input_stream_open(uri, dc->mutex, dc->cond, error); input_stream *is = input_stream::Open(uri, dc->mutex, dc->cond, error);
if (is == NULL) { if (is == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
@ -88,15 +88,15 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri)
dc->Lock(); dc->Lock();
input_stream_update(is); is->Update();
while (!is->ready && while (!is->ready &&
dc->command != DECODE_COMMAND_STOP) { dc->command != DECODE_COMMAND_STOP) {
dc->Wait(); dc->Wait();
input_stream_update(is); is->Update();
} }
if (!input_stream_check(is, error)) { if (!is->Check(error)) {
dc->Unlock(); dc->Unlock();
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
@ -128,10 +128,7 @@ decoder_stream_decode(const struct decoder_plugin *plugin,
return true; return true;
/* rewind the stream, so each plugin gets a fresh start */ /* rewind the stream, so each plugin gets a fresh start */
{ input_stream->Seek(0, SEEK_SET, IgnoreError());
Error error;
input_stream_seek(input_stream, 0, SEEK_SET, error);
}
decoder->dc->Unlock(); decoder->dc->Unlock();
@ -303,7 +300,7 @@ decoder_run_stream(struct decoder *decoder, const char *uri)
g_slist_free(tried); g_slist_free(tried);
dc->Unlock(); dc->Unlock();
input_stream_close(input_stream); input_stream->Close();
dc->Lock(); dc->Lock();
return success; return success;
@ -361,7 +358,7 @@ decoder_run_file(struct decoder *decoder, const char *path_fs)
dc->Unlock(); dc->Unlock();
input_stream_close(input_stream); input_stream->Close();
if (success) { if (success) {
dc->Lock(); dc->Lock();

View File

@ -1,225 +0,0 @@
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_INPUT_LEGACY_HXX
#define MPD_INPUT_LEGACY_HXX
#include "check.h"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "gcc.h"
#include <glib.h>
#include <stddef.h>
struct Tag;
struct input_stream;
class Error;
/**
* Opens a new input stream. You may not access it until the "ready"
* flag is set.
*
* @param mutex a mutex that is used to protect this object; must be
* locked before calling any of the public methods
* @param cond a cond that gets signalled when the state of
* this object changes; may be NULL if the caller doesn't want to get
* notifications
* @return an #input_stream object on success, NULL on error
*/
gcc_nonnull(1)
gcc_malloc
struct input_stream *
input_stream_open(const char *uri,
Mutex &mutex, Cond &cond,
Error &error);
/**
* Close the input stream and free resources.
*
* The caller must not lock the mutex.
*/
gcc_nonnull(1)
void
input_stream_close(struct input_stream *is);
/**
* Check for errors that may have occurred in the I/O thread.
*
* @return false on error
*/
gcc_nonnull(1)
bool
input_stream_check(struct input_stream *is, Error &error);
/**
* Update the public attributes. Call before accessing attributes
* such as "ready" or "offset".
*/
gcc_nonnull(1)
void
input_stream_update(struct input_stream *is);
/**
* Wait until the stream becomes ready.
*
* The caller must lock the mutex.
*/
gcc_nonnull(1)
void
input_stream_wait_ready(struct input_stream *is);
/**
* Wrapper for input_stream_wait_locked() which locks and unlocks the
* mutex; the caller must not be holding it already.
*/
gcc_nonnull(1)
void
input_stream_lock_wait_ready(struct input_stream *is);
gcc_nonnull_all gcc_pure
const char *
input_stream_get_mime_type(const struct input_stream *is);
gcc_nonnull_all
void
input_stream_override_mime_type(struct input_stream *is, const char *mime);
gcc_nonnull_all gcc_pure
goffset
input_stream_get_size(const struct input_stream *is);
gcc_nonnull_all gcc_pure
goffset
input_stream_get_offset(const struct input_stream *is);
gcc_nonnull_all gcc_pure
bool
input_stream_is_seekable(const struct input_stream *is);
/**
* Determines whether seeking is cheap. This is true for local files.
*/
gcc_pure gcc_nonnull(1)
bool
input_stream_cheap_seeking(const struct input_stream *is);
/**
* Seeks to the specified position in the stream. This will most
* likely fail if the "seekable" flag is false.
*
* The caller must lock the mutex.
*
* @param is the input_stream object
* @param offset the relative offset
* @param whence the base of the seek, one of SEEK_SET, SEEK_CUR, SEEK_END
*/
gcc_nonnull(1)
bool
input_stream_seek(struct input_stream *is, goffset offset, int whence,
Error &error);
/**
* Wrapper for input_stream_seek() which locks and unlocks the
* mutex; the caller must not be holding it already.
*/
gcc_nonnull(1)
bool
input_stream_lock_seek(struct input_stream *is, goffset offset, int whence,
Error &error);
/**
* Returns true if the stream has reached end-of-file.
*
* The caller must lock the mutex.
*/
gcc_nonnull(1)
gcc_pure
bool input_stream_eof(struct input_stream *is);
/**
* Wrapper for input_stream_eof() which locks and unlocks the mutex;
* the caller must not be holding it already.
*/
gcc_nonnull(1)
gcc_pure
bool
input_stream_lock_eof(struct input_stream *is);
/**
* Reads the tag from the stream.
*
* The caller must lock the mutex.
*
* @return a tag object which must be freed by the caller, or nullptr
* if the tag has not changed since the last call
*/
gcc_nonnull(1)
gcc_malloc
Tag *
input_stream_tag(struct input_stream *is);
/**
* Wrapper for input_stream_tag() which locks and unlocks the
* mutex; the caller must not be holding it already.
*/
gcc_nonnull(1)
gcc_malloc
Tag *
input_stream_lock_tag(struct input_stream *is);
/**
* Returns true if the next read operation will not block: either data
* is available, or end-of-stream has been reached, or an error has
* occurred.
*
* The caller must lock the mutex.
*/
gcc_nonnull(1)
gcc_pure
bool
input_stream_available(struct input_stream *is);
/**
* Reads data from the stream into the caller-supplied buffer.
* Returns 0 on error or eof (check with input_stream_eof()).
*
* The caller must lock the mutex.
*
* @param is the input_stream object
* @param ptr the buffer to read into
* @param size the maximum number of bytes to read
* @return the number of bytes read
*/
gcc_nonnull(1, 2)
size_t
input_stream_read(struct input_stream *is, void *ptr, size_t size,
Error &error);
/**
* Wrapper for input_stream_tag() which locks and unlocks the
* mutex; the caller must not be holding it already.
*/
gcc_nonnull(1, 2)
size_t
input_stream_lock_read(struct input_stream *is, void *ptr, size_t size,
Error &error);
#endif

View File

@ -20,13 +20,17 @@
#ifndef MPD_INPUT_PLUGIN_HXX #ifndef MPD_INPUT_PLUGIN_HXX
#define MPD_INPUT_PLUGIN_HXX #define MPD_INPUT_PLUGIN_HXX
#include "InputLegacy.hxx" #include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include <glib.h>
#include <stddef.h> #include <stddef.h>
struct config_param; struct config_param;
struct input_stream; struct input_stream;
class Error; class Error;
struct Tag;
struct input_plugin { struct input_plugin {
const char *name; const char *name;

View File

@ -31,7 +31,7 @@
static constexpr Domain input_domain("input"); static constexpr Domain input_domain("input");
struct input_stream * struct input_stream *
input_stream_open(const char *url, input_stream::Open(const char *url,
Mutex &mutex, Cond &cond, Mutex &mutex, Cond &cond,
Error &error) Error &error)
{ {
@ -57,191 +57,123 @@ input_stream_open(const char *url,
} }
bool bool
input_stream_check(struct input_stream *is, Error &error) input_stream::Check(Error &error)
{ {
assert(is != NULL); return plugin.check == nullptr || plugin.check(this, error);
return is->plugin.check == NULL ||
is->plugin.check(is, error);
} }
void void
input_stream_update(struct input_stream *is) input_stream::Update()
{ {
assert(is != NULL); if (plugin.update != nullptr)
plugin.update(this);
if (is->plugin.update != NULL)
is->plugin.update(is);
} }
void void
input_stream_wait_ready(struct input_stream *is) input_stream::WaitReady()
{ {
assert(is != NULL);
while (true) { while (true) {
input_stream_update(is); Update();
if (is->ready) if (ready)
break; break;
is->cond.wait(is->mutex); cond.wait(mutex);
} }
} }
void void
input_stream_lock_wait_ready(struct input_stream *is) input_stream::LockWaitReady()
{ {
assert(is != NULL); const ScopeLock protect(mutex);
WaitReady();
const ScopeLock protect(is->mutex);
input_stream_wait_ready(is);
}
const char *
input_stream_get_mime_type(const struct input_stream *is)
{
assert(is != NULL);
assert(is->ready);
return is->mime.empty() ? nullptr : is->mime.c_str();
}
void
input_stream_override_mime_type(struct input_stream *is, const char *mime)
{
assert(is != NULL);
assert(is->ready);
is->mime = mime;
}
goffset
input_stream_get_size(const struct input_stream *is)
{
assert(is != NULL);
assert(is->ready);
return is->size;
}
goffset
input_stream_get_offset(const struct input_stream *is)
{
assert(is != NULL);
assert(is->ready);
return is->offset;
} }
bool bool
input_stream_is_seekable(const struct input_stream *is) input_stream::CheapSeeking() const
{ {
assert(is != NULL); return IsSeekable() && !uri_has_scheme(uri.c_str());
assert(is->ready);
return is->seekable;
} }
bool bool
input_stream_cheap_seeking(const struct input_stream *is) input_stream::Seek(goffset _offset, int whence, Error &error)
{ {
return is->seekable && !uri_has_scheme(is->uri.c_str()); if (plugin.seek == nullptr)
}
bool
input_stream_seek(struct input_stream *is, goffset offset, int whence,
Error &error)
{
assert(is != NULL);
if (is->plugin.seek == NULL)
return false; return false;
return is->plugin.seek(is, offset, whence, error); return plugin.seek(this, _offset, whence, error);
} }
bool bool
input_stream_lock_seek(struct input_stream *is, goffset offset, int whence, input_stream::LockSeek(goffset _offset, int whence, Error &error)
Error &error)
{ {
assert(is != NULL); if (plugin.seek == nullptr)
if (is->plugin.seek == NULL)
return false; return false;
const ScopeLock protect(is->mutex); const ScopeLock protect(mutex);
return input_stream_seek(is, offset, whence, error); return Seek(_offset, whence, error);
} }
Tag * Tag *
input_stream_tag(struct input_stream *is) input_stream::ReadTag()
{ {
assert(is != NULL); return plugin.tag != nullptr
? plugin.tag(this)
return is->plugin.tag != NULL : nullptr;
? is->plugin.tag(is)
: NULL;
} }
Tag * Tag *
input_stream_lock_tag(struct input_stream *is) input_stream::LockReadTag()
{ {
assert(is != NULL); if (plugin.tag == nullptr)
if (is->plugin.tag == NULL)
return nullptr; return nullptr;
const ScopeLock protect(is->mutex); const ScopeLock protect(mutex);
return input_stream_tag(is); return ReadTag();
} }
bool bool
input_stream_available(struct input_stream *is) input_stream::IsAvailable()
{ {
assert(is != NULL); return plugin.available != nullptr
? plugin.available(this)
return is->plugin.available != NULL
? is->plugin.available(is)
: true; : true;
} }
size_t size_t
input_stream_read(struct input_stream *is, void *ptr, size_t size, input_stream::Read(void *ptr, size_t _size, Error &error)
Error &error)
{ {
assert(ptr != NULL); assert(ptr != NULL);
assert(size > 0); assert(_size > 0);
return is->plugin.read(is, ptr, size, error); return plugin.read(this, ptr, _size, error);
} }
size_t size_t
input_stream_lock_read(struct input_stream *is, void *ptr, size_t size, input_stream::LockRead(void *ptr, size_t _size, Error &error)
Error &error)
{ {
assert(ptr != NULL); assert(ptr != NULL);
assert(size > 0); assert(_size > 0);
const ScopeLock protect(is->mutex); const ScopeLock protect(mutex);
return input_stream_read(is, ptr, size, error); return Read(ptr, _size, error);
} }
void input_stream_close(struct input_stream *is) void
input_stream::Close()
{ {
is->plugin.close(is); plugin.close(this);
}
bool input_stream_eof(struct input_stream *is)
{
return is->plugin.eof(is);
} }
bool bool
input_stream_lock_eof(struct input_stream *is) input_stream::IsEOF()
{ {
assert(is != NULL); return plugin.eof(this);
}
const ScopeLock protect(is->mutex);
return input_stream_eof(is); bool
input_stream::LockIsEOF()
{
const ScopeLock protect(mutex);
return IsEOF();
} }

View File

@ -20,7 +20,6 @@
#ifndef MPD_INPUT_STREAM_HXX #ifndef MPD_INPUT_STREAM_HXX
#define MPD_INPUT_STREAM_HXX #define MPD_INPUT_STREAM_HXX
#include "InputLegacy.hxx"
#include "check.h" #include "check.h"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
#include "thread/Cond.hxx" #include "thread/Cond.hxx"
@ -28,8 +27,13 @@
#include <string> #include <string>
#include <glib.h>
#include <assert.h> #include <assert.h>
class Error;
struct Tag;
struct input_stream { struct input_stream {
/** /**
* the plugin which implements this input stream * the plugin which implements this input stream
@ -95,20 +99,185 @@ struct input_stream {
size(-1), offset(0) { size(-1), offset(0) {
assert(_uri != NULL); assert(_uri != NULL);
} }
/**
* Opens a new input stream. You may not access it until the "ready"
* flag is set.
*
* @param mutex a mutex that is used to protect this object; must be
* locked before calling any of the public methods
* @param cond a cond that gets signalled when the state of
* this object changes; may be NULL if the caller doesn't want to get
* notifications
* @return an #input_stream object on success, NULL on error
*/
gcc_nonnull_all
gcc_malloc
static input_stream *Open(const char *uri, Mutex &mutex, Cond &cond,
Error &error);
/**
* Close the input stream and free resources.
*
* The caller must not lock the mutex.
*/
void Close();
void Lock() {
mutex.lock();
}
void Unlock() {
mutex.unlock();
}
/**
* Check for errors that may have occurred in the I/O thread.
*
* @return false on error
*/
bool Check(Error &error);
/**
* Update the public attributes. Call before accessing attributes
* such as "ready" or "offset".
*/
void Update();
/**
* Wait until the stream becomes ready.
*
* The caller must lock the mutex.
*/
void WaitReady();
/**
* Wrapper for WaitReady() which locks and unlocks the mutex;
* the caller must not be holding it already.
*/
void LockWaitReady();
gcc_pure
const char *GetMimeType() const {
assert(ready);
return mime.empty() ? nullptr : mime.c_str();
}
gcc_nonnull_all
void OverrideMimeType(const char *_mime) {
assert(ready);
mime = _mime;
}
gcc_pure
goffset GetSize() const {
assert(ready);
return size;
}
gcc_pure
goffset GetOffset() const {
assert(ready);
return offset;
}
gcc_pure
bool IsSeekable() const {
assert(ready);
return seekable;
}
/**
* Determines whether seeking is cheap. This is true for local files.
*/
gcc_pure
bool CheapSeeking() const;
/**
* Seeks to the specified position in the stream. This will most
* likely fail if the "seekable" flag is false.
*
* The caller must lock the mutex.
*
* @param offset the relative offset
* @param whence the base of the seek, one of SEEK_SET, SEEK_CUR, SEEK_END
*/
bool Seek(goffset offset, int whence, Error &error);
/**
* Wrapper for Seek() which locks and unlocks the mutex; the
* caller must not be holding it already.
*/
bool LockSeek(goffset offset, int whence, Error &error);
/**
* Returns true if the stream has reached end-of-file.
*
* The caller must lock the mutex.
*/
gcc_pure
bool IsEOF();
/**
* Wrapper for IsEOF() which locks and unlocks the mutex; the
* caller must not be holding it already.
*/
gcc_pure
bool LockIsEOF();
/**
* Reads the tag from the stream.
*
* The caller must lock the mutex.
*
* @return a tag object which must be freed by the caller, or
* nullptr if the tag has not changed since the last call
*/
gcc_malloc
Tag *ReadTag();
/**
* Wrapper for ReadTag() which locks and unlocks the mutex;
* the caller must not be holding it already.
*/
gcc_malloc
Tag *LockReadTag();
/**
* Returns true if the next read operation will not block: either data
* is available, or end-of-stream has been reached, or an error has
* occurred.
*
* The caller must lock the mutex.
*/
gcc_pure
bool IsAvailable();
/**
* Reads data from the stream into the caller-supplied buffer.
* Returns 0 on error or eof (check with IsEOF()).
*
* The caller must lock the mutex.
*
* @param is the input_stream object
* @param ptr the buffer to read into
* @param size the maximum number of bytes to read
* @return the number of bytes read
*/
gcc_nonnull_all
size_t Read(void *ptr, size_t size, Error &error);
/**
* Wrapper for Read() which locks and unlocks the mutex;
* the caller must not be holding it already.
*/
gcc_nonnull_all
size_t LockRead(void *ptr, size_t size, Error &error);
}; };
gcc_nonnull(1)
static inline void
input_stream_lock(struct input_stream *is)
{
is->mutex.lock();
}
gcc_nonnull(1)
static inline void
input_stream_unlock(struct input_stream *is)
{
is->mutex.unlock();
}
#endif #endif

View File

@ -23,7 +23,7 @@
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include <assert.h> #include <assert.h>
@ -41,7 +41,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond,
} }
Error error; Error error;
input_stream *is = input_stream_open(uri, mutex, cond, error); input_stream *is = input_stream::Open(uri, mutex, cond, error);
if (is == NULL) { if (is == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("Failed to open %s: %s", g_warning("Failed to open %s: %s",
@ -52,7 +52,7 @@ playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond,
playlist = playlist_list_open_stream(is, uri); playlist = playlist_list_open_stream(is, uri);
if (playlist == NULL) { if (playlist == NULL) {
input_stream_close(is); is->Close();
return NULL; return NULL;
} }

View File

@ -30,7 +30,7 @@
#include "DatabaseGlue.hxx" #include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx" #include "DatabasePlugin.hxx"
#include "Client.hxx" #include "Client.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -182,7 +182,7 @@ playlist_file_print(Client *client, const char *uri, bool detail)
playlist_plugin_close(playlist); playlist_plugin_close(playlist);
if (is != NULL) if (is != NULL)
input_stream_close(is); is->Close();
return true; return true;
} }

View File

@ -23,7 +23,7 @@
#include "PlaylistAny.hxx" #include "PlaylistAny.hxx"
#include "PlaylistSong.hxx" #include "PlaylistSong.hxx"
#include "Playlist.hxx" #include "Playlist.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "Song.hxx" #include "Song.hxx"
enum playlist_result enum playlist_result
@ -83,7 +83,7 @@ playlist_open_into_queue(const char *uri,
playlist_plugin_close(playlist); playlist_plugin_close(playlist);
if (is != NULL) if (is != NULL)
input_stream_close(is); is->Close();
return result; return result;
} }

View File

@ -31,7 +31,7 @@
#include "playlist/RssPlaylistPlugin.hxx" #include "playlist/RssPlaylistPlugin.hxx"
#include "playlist/CuePlaylistPlugin.hxx" #include "playlist/CuePlaylistPlugin.hxx"
#include "playlist/EmbeddedCuePlaylistPlugin.hxx" #include "playlist/EmbeddedCuePlaylistPlugin.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -220,8 +220,7 @@ playlist_list_open_stream_mime2(struct input_stream *is, const char *mime)
string_array_contains(plugin->mime_types, mime)) { string_array_contains(plugin->mime_types, mime)) {
/* rewind the stream, so each plugin gets a /* rewind the stream, so each plugin gets a
fresh start */ fresh start */
Error error; is->Seek(0, SEEK_SET, IgnoreError());
input_stream_seek(is, 0, SEEK_SET, error);
playlist = playlist_plugin_open_stream(plugin, is); playlist = playlist_plugin_open_stream(plugin, is);
if (playlist != NULL) if (playlist != NULL)
@ -266,8 +265,7 @@ playlist_list_open_stream_suffix(struct input_stream *is, const char *suffix)
string_array_contains(plugin->suffixes, suffix)) { string_array_contains(plugin->suffixes, suffix)) {
/* rewind the stream, so each plugin gets a /* rewind the stream, so each plugin gets a
fresh start */ fresh start */
Error error; is->Seek(0, SEEK_SET, IgnoreError());
input_stream_seek(is, 0, SEEK_SET, error);
playlist = playlist_plugin_open_stream(plugin, is); playlist = playlist_plugin_open_stream(plugin, is);
if (playlist != NULL) if (playlist != NULL)
@ -284,9 +282,9 @@ playlist_list_open_stream(struct input_stream *is, const char *uri)
const char *suffix; const char *suffix;
struct playlist_provider *playlist; struct playlist_provider *playlist;
input_stream_lock_wait_ready(is); is->LockWaitReady();
const char *const mime = input_stream_get_mime_type(is); const char *const mime = is->GetMimeType();
if (mime != NULL) { if (mime != NULL) {
playlist = playlist_list_open_stream_mime(is, mime); playlist = playlist_list_open_stream_mime(is, mime);
if (playlist != NULL) if (playlist != NULL)
@ -331,7 +329,7 @@ playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
return NULL; return NULL;
Error error; Error error;
input_stream *is = input_stream_open(path_fs, mutex, cond, error); input_stream *is = input_stream::Open(path_fs, mutex, cond, error);
if (is == NULL) { if (is == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
@ -339,13 +337,13 @@ playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
return NULL; return NULL;
} }
input_stream_lock_wait_ready(is); is->LockWaitReady();
playlist = playlist_list_open_stream_suffix(is, suffix); playlist = playlist_list_open_stream_suffix(is, suffix);
if (playlist != NULL) if (playlist != NULL)
*is_r = is; *is_r = is;
else else
input_stream_close(is); is->Close();
return playlist; return playlist;
} }

View File

@ -26,7 +26,7 @@
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/FileSystem.hxx" #include "fs/FileSystem.hxx"
#include "Tag.hxx" #include "Tag.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "DecoderPlugin.hxx" #include "DecoderPlugin.hxx"
#include "DecoderList.hxx" #include "DecoderList.hxx"
#include "TagHandler.hxx" #include "TagHandler.hxx"
@ -127,12 +127,10 @@ Song::UpdateFile()
if (plugin->scan_stream != NULL) { if (plugin->scan_stream != NULL) {
/* open the input_stream (if not already /* open the input_stream (if not already
open) */ open) */
if (is == NULL) { if (is == NULL)
Error error; is = input_stream::Open(path_fs.c_str(),
is = input_stream_open(path_fs.c_str(),
mutex, cond, mutex, cond,
error); IgnoreError());
}
/* now try the stream_tag() method */ /* now try the stream_tag() method */
if (is != NULL) { if (is != NULL) {
@ -145,8 +143,7 @@ Song::UpdateFile()
delete tag; delete tag;
tag = nullptr; tag = nullptr;
Error error; is->LockSeek(0, SEEK_SET, IgnoreError());
input_stream_lock_seek(is, 0, SEEK_SET, error);
} }
} }
@ -154,7 +151,7 @@ Song::UpdateFile()
} while (plugin != NULL); } while (plugin != NULL);
if (is != NULL) if (is != NULL)
input_stream_close(is); is->Close();
if (tag != nullptr && tag->IsEmpty()) if (tag != nullptr && tag->IsEmpty())
tag_scan_fallback(path_fs.c_str(), &full_tag_handler, tag); tag_scan_fallback(path_fs.c_str(), &full_tag_handler, tag);

View File

@ -23,7 +23,7 @@
#include "util/Error.hxx" #include "util/Error.hxx"
#include "DecoderList.hxx" #include "DecoderList.hxx"
#include "DecoderPlugin.hxx" #include "DecoderPlugin.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include <assert.h> #include <assert.h>
#include <unistd.h> /* for SEEK_SET */ #include <unistd.h> /* for SEEK_SET */
@ -62,7 +62,7 @@ tag_file_scan(const char *path_fs,
open) */ open) */
if (is == nullptr) { if (is == nullptr) {
Error error; Error error;
is = input_stream_open(path_fs, mutex, cond, is = input_stream::Open(path_fs, mutex, cond,
error); error);
} }
@ -73,8 +73,7 @@ tag_file_scan(const char *path_fs,
handler_ctx)) handler_ctx))
break; break;
Error error; is->LockSeek(0, SEEK_SET, IgnoreError());
input_stream_lock_seek(is, 0, SEEK_SET, error);
} }
} }
@ -82,7 +81,7 @@ tag_file_scan(const char *path_fs,
} while (plugin != NULL); } while (plugin != NULL);
if (is != NULL) if (is != NULL)
input_stream_close(is); is->Close();
return plugin != NULL; return plugin != NULL;
} }

View File

@ -19,7 +19,7 @@
#include "config.h" #include "config.h"
#include "TextInputStream.hxx" #include "TextInputStream.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "util/fifo_buffer.h" #include "util/fifo_buffer.h"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -54,8 +54,7 @@ bool TextInputStream::ReadLine(std::string &line)
--length; --length;
Error error; Error error;
nbytes = input_stream_lock_read(is, dest, length, nbytes = is->LockRead(dest, length, error);
error);
if (nbytes > 0) if (nbytes > 0)
fifo_buffer_append(buffer, nbytes); fifo_buffer_append(buffer, nbytes);
else if (error.IsDefined()) { else if (error.IsDefined()) {

View File

@ -62,7 +62,7 @@ public:
} }
~Bzip2ArchiveFile() { ~Bzip2ArchiveFile() {
input_stream_close(istream); istream->Close();
} }
void Ref() { void Ref() {
@ -155,7 +155,7 @@ bz2_open(const char *pathname, Error &error)
{ {
static Mutex mutex; static Mutex mutex;
static Cond cond; static Cond cond;
input_stream *is = input_stream_open(pathname, mutex, cond, error); input_stream *is = input_stream::Open(pathname, mutex, cond, error);
if (is == nullptr) if (is == nullptr)
return nullptr; return nullptr;
@ -211,8 +211,7 @@ bz2_fillbuffer(Bzip2InputStream *bis, Error &error)
if (bzstream->avail_in > 0) if (bzstream->avail_in > 0)
return true; return true;
count = input_stream_read(bis->archive->istream, count = bis->archive->istream->Read(bis->buffer, sizeof(bis->buffer),
bis->buffer, sizeof(bis->buffer),
error); error);
if (count == 0) if (count == 0)
return false; return false;

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "AudiofileDecoderPlugin.hxx" #include "AudiofileDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "TagHandler.hxx" #include "TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -56,7 +57,7 @@ audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
struct input_stream *is = (struct input_stream *) vfile->closure; struct input_stream *is = (struct input_stream *) vfile->closure;
Error error; Error error;
size_t nbytes = input_stream_lock_read(is, data, length, error); size_t nbytes = is->LockRead(data, length, error);
if (nbytes == 0 && error.IsDefined()) { if (nbytes == 0 && error.IsDefined()) {
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
return -1; return -1;
@ -69,14 +70,14 @@ static AFfileoffset
audiofile_file_length(AFvirtualfile *vfile) audiofile_file_length(AFvirtualfile *vfile)
{ {
struct input_stream *is = (struct input_stream *) vfile->closure; struct input_stream *is = (struct input_stream *) vfile->closure;
return input_stream_get_size(is); return is->GetSize();
} }
static AFfileoffset static AFfileoffset
audiofile_file_tell(AFvirtualfile *vfile) audiofile_file_tell(AFvirtualfile *vfile)
{ {
struct input_stream *is = (struct input_stream *) vfile->closure; struct input_stream *is = (struct input_stream *) vfile->closure;
return input_stream_get_offset(is); return is->GetOffset();
} }
static void static void
@ -94,8 +95,8 @@ audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset offset, int is_relative)
int whence = (is_relative ? SEEK_CUR : SEEK_SET); int whence = (is_relative ? SEEK_CUR : SEEK_SET);
Error error; Error error;
if (input_stream_lock_seek(is, offset, whence, error)) { if (is->LockSeek(offset, whence, error)) {
return input_stream_get_offset(is); return is->GetOffset();
} else { } else {
return -1; return -1;
} }
@ -167,7 +168,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
char chunk[CHUNK_SIZE]; char chunk[CHUNK_SIZE];
enum decoder_command cmd; enum decoder_command cmd;
if (!input_stream_is_seekable(is)) { if (!is->IsSeekable()) {
g_warning("not seekable"); g_warning("not seekable");
return; return;
} }
@ -195,7 +196,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
total_time = ((float)frame_count / (float)audio_format.sample_rate); total_time = ((float)frame_count / (float)audio_format.sample_rate);
bit_rate = (uint16_t)(input_stream_get_size(is) * 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); fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);

View File

@ -26,6 +26,7 @@
#include "config.h" #include "config.h"
#include "DsdLib.hxx" #include "DsdLib.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "util/bit_reverse.h" #include "util/bit_reverse.h"
#include "TagHandler.hxx" #include "TagHandler.hxx"
#include "tag/TagId3.hxx" #include "tag/TagId3.hxx"
@ -64,24 +65,24 @@ bool
dsdlib_skip_to(struct decoder *decoder, struct input_stream *is, dsdlib_skip_to(struct decoder *decoder, struct input_stream *is,
goffset offset) goffset offset)
{ {
if (input_stream_is_seekable(is)) if (is->IsSeekable())
return input_stream_seek(is, offset, SEEK_SET, IgnoreError()); return is->Seek(offset, SEEK_SET, IgnoreError());
if (input_stream_get_offset(is) > offset) if (is->GetOffset() > offset)
return false; return false;
char buffer[8192]; char buffer[8192];
while (input_stream_get_offset(is) < offset) { while (is->GetOffset() < offset) {
size_t length = sizeof(buffer); size_t length = sizeof(buffer);
if (offset - input_stream_get_offset(is) < (goffset)length) if (offset - is->GetOffset() < (goffset)length)
length = offset - input_stream_get_offset(is); length = offset - is->GetOffset();
size_t nbytes = decoder_read(decoder, is, buffer, length); size_t nbytes = decoder_read(decoder, is, buffer, length);
if (nbytes == 0) if (nbytes == 0)
return false; return false;
} }
assert(input_stream_get_offset(is) == offset); assert(is->GetOffset() == offset);
return true; return true;
} }
@ -97,8 +98,8 @@ dsdlib_skip(struct decoder *decoder, struct input_stream *is,
if (delta == 0) if (delta == 0)
return true; return true;
if (input_stream_is_seekable(is)) if (is->IsSeekable())
return input_stream_seek(is, delta, SEEK_CUR, IgnoreError()); return is->Seek(delta, SEEK_CUR, IgnoreError());
char buffer[8192]; char buffer[8192];
while (delta > 0) { while (delta > 0) {
@ -139,8 +140,8 @@ dsdlib_tag_id3(struct input_stream *is,
id3_length_t count; id3_length_t count;
/* Prevent broken files causing problems */ /* Prevent broken files causing problems */
const goffset size = input_stream_get_size(is); const goffset size = is->GetSize();
const goffset offset = input_stream_get_offset(is); const goffset offset = is->GetOffset();
if (offset >= size) if (offset >= size)
return; return;

View File

@ -29,12 +29,12 @@
#include "config.h" #include "config.h"
#include "DsdiffDecoderPlugin.hxx" #include "DsdiffDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "util/bit_reverse.h" #include "util/bit_reverse.h"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "TagHandler.hxx" #include "TagHandler.hxx"
#include "DsdLib.hxx" #include "DsdLib.hxx"
#include "TagHandler.hxx"
#include <unistd.h> #include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */ #include <stdio.h> /* for SEEK_SET, SEEK_CUR */
@ -127,11 +127,11 @@ dsdiff_read_prop_snd(struct decoder *decoder, struct input_stream *is,
goffset end_offset) goffset end_offset)
{ {
DsdiffChunkHeader header; DsdiffChunkHeader header;
while ((goffset)(input_stream_get_offset(is) + sizeof(header)) <= end_offset) { while ((goffset)(is->GetOffset() + sizeof(header)) <= end_offset) {
if (!dsdiff_read_chunk_header(decoder, is, &header)) if (!dsdiff_read_chunk_header(decoder, is, &header))
return false; return false;
goffset chunk_end_offset = input_stream_get_offset(is) goffset chunk_end_offset = is->GetOffset()
+ header.GetSize(); + header.GetSize();
if (chunk_end_offset > end_offset) if (chunk_end_offset > end_offset)
return false; return false;
@ -173,7 +173,7 @@ dsdiff_read_prop_snd(struct decoder *decoder, struct input_stream *is,
} }
} }
return input_stream_get_offset(is) == end_offset; return is->GetOffset() == end_offset;
} }
/** /**
@ -185,7 +185,7 @@ dsdiff_read_prop(struct decoder *decoder, struct input_stream *is,
const DsdiffChunkHeader *prop_header) const DsdiffChunkHeader *prop_header)
{ {
uint64_t prop_size = prop_header->GetSize(); uint64_t prop_size = prop_header->GetSize();
goffset end_offset = input_stream_get_offset(is) + prop_size; goffset end_offset = is->GetOffset() + prop_size;
struct dsdlib_id prop_id; struct dsdlib_id prop_id;
if (prop_size < sizeof(prop_id) || if (prop_size < sizeof(prop_id) ||
@ -260,8 +260,8 @@ dsdiff_read_metadata_extra(struct decoder *decoder, struct input_stream *is,
/* Now process all the remaining chunk headers in the stream /* Now process all the remaining chunk headers in the stream
and record their position and size */ and record their position and size */
const goffset size = input_stream_get_size(is); const goffset size = is->GetSize();
while (input_stream_get_offset(is) < size) { while (is->GetOffset() < size) {
uint64_t chunk_size = chunk_header->GetSize(); uint64_t chunk_size = chunk_header->GetSize();
/* DIIN chunk, is directly followed by other chunks */ /* DIIN chunk, is directly followed by other chunks */
@ -271,19 +271,19 @@ dsdiff_read_metadata_extra(struct decoder *decoder, struct input_stream *is,
/* DIAR chunk - DSDIFF native tag for Artist */ /* DIAR chunk - DSDIFF native tag for Artist */
if (dsdlib_id_equals(&chunk_header->id, "DIAR")) { if (dsdlib_id_equals(&chunk_header->id, "DIAR")) {
chunk_size = chunk_header->GetSize(); chunk_size = chunk_header->GetSize();
metadata->diar_offset = input_stream_get_offset(is); metadata->diar_offset = is->GetOffset();
} }
/* DITI chunk - DSDIFF native tag for Title */ /* DITI chunk - DSDIFF native tag for Title */
if (dsdlib_id_equals(&chunk_header->id, "DITI")) { if (dsdlib_id_equals(&chunk_header->id, "DITI")) {
chunk_size = chunk_header->GetSize(); chunk_size = chunk_header->GetSize();
metadata->diti_offset = input_stream_get_offset(is); metadata->diti_offset = is->GetOffset();
} }
#ifdef HAVE_ID3TAG #ifdef HAVE_ID3TAG
/* 'ID3 ' chunk, offspec. Used by sacdextract */ /* 'ID3 ' chunk, offspec. Used by sacdextract */
if (dsdlib_id_equals(&chunk_header->id, "ID3 ")) { if (dsdlib_id_equals(&chunk_header->id, "ID3 ")) {
chunk_size = chunk_header->GetSize(); chunk_size = chunk_header->GetSize();
metadata->id3_offset = input_stream_get_offset(is); metadata->id3_offset = is->GetOffset();
metadata->id3_size = chunk_size; metadata->id3_size = chunk_size;
} }
#endif #endif
@ -292,7 +292,7 @@ dsdiff_read_metadata_extra(struct decoder *decoder, struct input_stream *is,
break; break;
} }
if (input_stream_get_offset(is) < size) { if (is->GetOffset() < size) {
if (!dsdiff_read_chunk_header(decoder, is, chunk_header)) if (!dsdiff_read_chunk_header(decoder, is, chunk_header))
return false; return false;
} }
@ -352,7 +352,7 @@ dsdiff_read_metadata(struct decoder *decoder, struct input_stream *is,
} else { } else {
/* ignore unknown chunk */ /* ignore unknown chunk */
const uint64_t chunk_size = chunk_header->GetSize(); const uint64_t chunk_size = chunk_header->GetSize();
goffset chunk_end_offset = input_stream_get_offset(is) goffset chunk_end_offset = is->GetOffset()
+ chunk_size; + chunk_size;
if (!dsdlib_skip_to(decoder, is, chunk_end_offset)) if (!dsdlib_skip_to(decoder, is, chunk_end_offset))

View File

@ -30,6 +30,7 @@
#include "config.h" #include "config.h"
#include "DsfDecoderPlugin.hxx" #include "DsfDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "util/bit_reverse.h" #include "util/bit_reverse.h"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -165,7 +166,7 @@ dsf_read_metadata(struct decoder *decoder, struct input_stream *is,
metadata->chunk_size = data_size; metadata->chunk_size = data_size;
/* data_size cannot be bigger or equal to total file size */ /* data_size cannot be bigger or equal to total file size */
const uint64_t size = (uint64_t)input_stream_get_size(is); const uint64_t size = (uint64_t)is->GetSize();
if (data_size >= size) if (data_size >= size)
return false; return false;

View File

@ -21,6 +21,7 @@
#include "FaadDecoderPlugin.hxx" #include "FaadDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "DecoderBuffer.hxx" #include "DecoderBuffer.hxx"
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "TagHandler.hxx" #include "TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -173,7 +174,7 @@ faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
size_t length; size_t length;
bool success; bool success;
const goffset size = input_stream_get_size(is); const goffset size = is->GetSize();
fileread = size >= 0 ? size : 0; fileread = size >= 0 ? size : 0;
decoder_buffer_fill(buffer); decoder_buffer_fill(buffer);
@ -201,12 +202,12 @@ faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
return -1; return -1;
} }
if (input_stream_is_seekable(is) && length >= 2 && if (is->IsSeekable() && length >= 2 &&
data[0] == 0xFF && ((data[1] & 0xF6) == 0xF0)) { data[0] == 0xFF && ((data[1] & 0xF6) == 0xF0)) {
/* obtain the duration from the ADTS header */ /* obtain the duration from the ADTS header */
float song_length = adts_song_duration(buffer); float song_length = adts_song_duration(buffer);
input_stream_lock_seek(is, tagsize, SEEK_SET, IgnoreError()); is->LockSeek(tagsize, SEEK_SET, IgnoreError());
data = (const uint8_t *)decoder_buffer_read(buffer, &length); data = (const uint8_t *)decoder_buffer_read(buffer, &length);
if (data != nullptr) if (data != nullptr)
@ -384,8 +385,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
config->dontUpSampleImplicitSBR = 0; config->dontUpSampleImplicitSBR = 0;
NeAACDecSetConfiguration(decoder, config); NeAACDecSetConfiguration(decoder, config);
while (!decoder_buffer_is_full(buffer) && while (!decoder_buffer_is_full(buffer) && !is->LockIsEOF() &&
!input_stream_lock_eof(is) &&
decoder_get_command(mpd_decoder) == DECODE_COMMAND_NONE) { decoder_get_command(mpd_decoder) == DECODE_COMMAND_NONE) {
adts_find_frame(buffer); adts_find_frame(buffer);
decoder_buffer_fill(buffer); decoder_buffer_fill(buffer);

View File

@ -126,7 +126,7 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
return stream->input->size; return stream->input->size;
Error error; Error error;
if (!input_stream_lock_seek(stream->input, pos, whence, error)) if (!stream->input->LockSeek(pos, whence, error))
return -1; return -1;
return stream->input->offset; return stream->input->offset;
@ -349,8 +349,7 @@ ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
unsigned char *buffer = (unsigned char *)g_malloc(BUFFER_SIZE); unsigned char *buffer = (unsigned char *)g_malloc(BUFFER_SIZE);
size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE); size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE);
if (nbytes <= PADDING || if (nbytes <= PADDING || !is->LockSeek(0, SEEK_SET, error)) {
!input_stream_lock_seek(is, 0, SEEK_SET, error)) {
g_free(buffer); g_free(buffer);
return NULL; return NULL;
} }

View File

@ -331,7 +331,7 @@ oggflac_decode(struct decoder *decoder, struct input_stream *input_stream)
/* rewind the stream, because ogg_codec_detect() has /* rewind the stream, because ogg_codec_detect() has
moved it */ moved it */
input_stream_lock_seek(input_stream, 0, SEEK_SET, IgnoreError()); input_stream->LockSeek(0, SEEK_SET, IgnoreError());
flac_decode_internal(decoder, input_stream, true); flac_decode_internal(decoder, input_stream, true);
} }

View File

@ -37,7 +37,7 @@ FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
Error error; Error error;
while (p < end) { while (p < end) {
size_t nbytes = input_stream_lock_read(is, p, end - p, error); size_t nbytes = is->LockRead(p, end - p, error);
if (nbytes == 0) { if (nbytes == 0) {
if (!error.IsDefined()) if (!error.IsDefined())
/* end of file */ /* end of file */
@ -67,7 +67,7 @@ FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
input_stream *is = (input_stream *)handle; input_stream *is = (input_stream *)handle;
Error error; Error error;
return input_stream_lock_seek(is, offset, whence, error) ? 0 : -1; return is->LockSeek(offset, whence, error) ? 0 : -1;
} }
static FLAC__int64 static FLAC__int64
@ -83,7 +83,7 @@ FlacIOEof(FLAC__IOHandle handle)
{ {
input_stream *is = (input_stream *)handle; input_stream *is = (input_stream *)handle;
return input_stream_lock_eof(is); return is->LockIsEOF();
} }
static int static int

View File

@ -31,7 +31,7 @@ FlacInput::Read(FLAC__byte buffer[], size_t *bytes)
*bytes = r; *bytes = r;
if (r == 0) { if (r == 0) {
if (input_stream_lock_eof(input_stream) || if (input_stream->LockIsEOF() ||
(decoder != nullptr && (decoder != nullptr &&
decoder_get_command(decoder) != DECODE_COMMAND_NONE)) decoder_get_command(decoder) != DECODE_COMMAND_NONE))
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
@ -49,9 +49,7 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
::Error error; ::Error error;
if (!input_stream_lock_seek(input_stream, if (!input_stream->LockSeek(absolute_byte_offset, SEEK_SET, error))
absolute_byte_offset, SEEK_SET,
error))
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
return FLAC__STREAM_DECODER_SEEK_STATUS_OK; return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
@ -83,7 +81,7 @@ FlacInput::Eof()
return (decoder != nullptr && return (decoder != nullptr &&
decoder_get_command(decoder) != DECODE_COMMAND_NONE && decoder_get_command(decoder) != DECODE_COMMAND_NONE &&
decoder_get_command(decoder) != DECODE_COMMAND_SEEK) || decoder_get_command(decoder) != DECODE_COMMAND_SEEK) ||
input_stream_lock_eof(input_stream); input_stream->LockIsEOF();
} }
void void

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "MadDecoderPlugin.hxx" #include "MadDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "conf.h" #include "conf.h"
#include "tag/TagId3.hxx" #include "tag/TagId3.hxx"
#include "tag/TagRva2.hxx" #include "tag/TagRva2.hxx"
@ -205,8 +206,7 @@ inline bool
MadDecoder::Seek(long offset) MadDecoder::Seek(long offset)
{ {
Error error; Error error;
if (!input_stream_lock_seek(input_stream, offset, SEEK_SET, if (!input_stream->LockSeek(offset, SEEK_SET, error))
error))
return false; return false;
mad_stream_buffer(&stream, input_buffer, 0); mad_stream_buffer(&stream, input_buffer, 0);
@ -776,7 +776,7 @@ mp3_frame_duration(const struct mad_frame *frame)
inline goffset inline goffset
MadDecoder::ThisFrameOffset() const MadDecoder::ThisFrameOffset() const
{ {
goffset offset = input_stream_get_offset(input_stream); goffset offset = input_stream->GetOffset();
if (stream.this_frame != nullptr) if (stream.this_frame != nullptr)
offset -= stream.bufend - stream.this_frame; offset -= stream.bufend - stream.this_frame;
@ -789,7 +789,7 @@ MadDecoder::ThisFrameOffset() const
inline goffset inline goffset
MadDecoder::RestIncludingThisFrame() const MadDecoder::RestIncludingThisFrame() const
{ {
return input_stream_get_size(input_stream) - ThisFrameOffset(); return input_stream->GetSize() - ThisFrameOffset();
} }
inline void inline void
@ -857,8 +857,7 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
} }
if (parse_lame(&lame, &ptr, &bitlen)) { if (parse_lame(&lame, &ptr, &bitlen)) {
if (gapless_playback && if (gapless_playback && input_stream->IsSeekable()) {
input_stream_is_seekable(input_stream)) {
drop_start_samples = lame.encoder_delay + drop_start_samples = lame.encoder_delay +
DECODERDELAY; DECODERDELAY;
drop_end_samples = lame.encoder_padding; drop_end_samples = lame.encoder_padding;
@ -1059,7 +1058,7 @@ MadDecoder::Read()
if (cmd == DECODE_COMMAND_SEEK) { if (cmd == DECODE_COMMAND_SEEK) {
unsigned long j; unsigned long j;
assert(input_stream_is_seekable(input_stream)); assert(input_stream->IsSeekable());
j = TimeToFrame(decoder_seek_where(decoder)); j = TimeToFrame(decoder_seek_where(decoder));
if (j < highest_frame) { if (j < highest_frame) {
@ -1139,7 +1138,7 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
} }
decoder_initialized(decoder, audio_format, decoder_initialized(decoder, audio_format,
input_stream_is_seekable(input_stream), input_stream->IsSeekable(),
data.total_time); data.total_time);
if (tag != nullptr) { if (tag != nullptr) {

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "ModplugDecoderPlugin.hxx" #include "ModplugDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "TagHandler.hxx" #include "TagHandler.hxx"
#include <glib.h> #include <glib.h>
@ -37,7 +38,7 @@ static constexpr goffset MODPLUG_FILE_LIMIT = 100 * 1024 * 1024;
static GByteArray * static GByteArray *
mod_loadfile(struct decoder *decoder, struct input_stream *is) mod_loadfile(struct decoder *decoder, struct input_stream *is)
{ {
const goffset size = input_stream_get_size(is); const goffset size = is->GetSize();
if (size == 0) { if (size == 0) {
g_warning("file is empty"); g_warning("file is empty");
@ -63,7 +64,7 @@ mod_loadfile(struct decoder *decoder, struct input_stream *is)
size_t ret = decoder_read(decoder, is, data, size_t ret = decoder_read(decoder, is, data,
MODPLUG_READ_BLOCK); MODPLUG_READ_BLOCK);
if (ret == 0) { if (ret == 0) {
if (input_stream_lock_eof(is)) if (is->LockIsEOF())
/* end of file */ /* end of file */
break; break;
@ -125,7 +126,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
assert(audio_format.IsValid()); assert(audio_format.IsValid());
decoder_initialized(decoder, audio_format, decoder_initialized(decoder, audio_format,
input_stream_is_seekable(is), is->IsSeekable(),
ModPlug_GetLength(f) / 1000.0); ModPlug_GetLength(f) / 1000.0);
do { do {

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "MpcdecDecoderPlugin.hxx" #include "MpcdecDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "TagHandler.hxx" #include "TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -54,8 +55,7 @@ mpc_seek_cb(mpc_reader *reader, mpc_int32_t offset)
struct mpc_decoder_data *data = struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data; (struct mpc_decoder_data *)reader->data;
return input_stream_lock_seek(data->is, offset, SEEK_SET, return data->is->LockSeek(offset, SEEK_SET, IgnoreError());
IgnoreError());
} }
static mpc_int32_t static mpc_int32_t
@ -64,7 +64,7 @@ mpc_tell_cb(mpc_reader *reader)
struct mpc_decoder_data *data = struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data; (struct mpc_decoder_data *)reader->data;
return (long)input_stream_get_offset(data->is); return (long)data->is->GetOffset();
} }
static mpc_bool_t static mpc_bool_t
@ -73,7 +73,7 @@ mpc_canseek_cb(mpc_reader *reader)
struct mpc_decoder_data *data = struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data; (struct mpc_decoder_data *)reader->data;
return input_stream_is_seekable(data->is); return data->is->IsSeekable();
} }
static mpc_int32_t static mpc_int32_t
@ -82,7 +82,7 @@ mpc_getsize_cb(mpc_reader *reader)
struct mpc_decoder_data *data = struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data; (struct mpc_decoder_data *)reader->data;
return input_stream_get_size(data->is); return data->is->GetSize();
} }
/* this _looks_ performance-critical, don't de-inline -- eric */ /* this _looks_ performance-critical, don't de-inline -- eric */
@ -175,7 +175,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
decoder_replay_gain(mpd_decoder, &replay_gain_info); decoder_replay_gain(mpd_decoder, &replay_gain_info);
decoder_initialized(mpd_decoder, audio_format, decoder_initialized(mpd_decoder, audio_format,
input_stream_is_seekable(is), is->IsSeekable(),
mpc_streaminfo_get_length(&info)); mpc_streaminfo_get_length(&info));
enum decoder_command cmd = DECODE_COMMAND_NONE; enum decoder_command cmd = DECODE_COMMAND_NONE;

View File

@ -272,7 +272,7 @@ mpd_opus_stream_decode(struct decoder *decoder,
/* rewind the stream, because ogg_codec_detect() has /* rewind the stream, because ogg_codec_detect() has
moved it */ moved it */
input_stream_lock_seek(input_stream, 0, SEEK_SET, IgnoreError()); input_stream->LockSeek(0, SEEK_SET, IgnoreError());
MPDOpusDecoder d(decoder, input_stream); MPDOpusDecoder d(decoder, input_stream);
OggSyncState oy(*input_stream, decoder); OggSyncState oy(*input_stream, decoder);
@ -298,13 +298,13 @@ SeekFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet,
if (is->size > 0 && is->size - is->offset < 65536) if (is->size > 0 && is->size - is->offset < 65536)
return OggFindEOS(oy, os, packet); return OggFindEOS(oy, os, packet);
if (!input_stream_cheap_seeking(is)) if (!is->CheapSeeking())
return false; return false;
oy.Reset(); oy.Reset();
Error error; Error error;
return input_stream_lock_seek(is, -65536, SEEK_END, error) && return is->LockSeek(-65536, SEEK_END, error) &&
oy.ExpectPageSeekIn(os) && oy.ExpectPageSeekIn(os) &&
OggFindEOS(oy, os, packet); OggFindEOS(oy, os, packet);
} }

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "decoder/PcmDecoderPlugin.hxx" #include "decoder/PcmDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
extern "C" { extern "C" {
@ -43,7 +44,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
2, 2,
}; };
const char *const mime = input_stream_get_mime_type(is); const char *const mime = is->GetMimeType();
const bool reverse_endian = mime != nullptr && const bool reverse_endian = mime != nullptr &&
strcmp(mime, "audio/x-mpd-cdda-pcm-reverse") == 0; strcmp(mime, "audio/x-mpd-cdda-pcm-reverse") == 0;
@ -52,12 +53,12 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
const double time_to_size = audio_format.GetTimeToSize(); const double time_to_size = audio_format.GetTimeToSize();
float total_time = -1; float total_time = -1;
const goffset size = input_stream_get_size(is); const goffset size = is->GetSize();
if (size >= 0) if (size >= 0)
total_time = size / time_to_size; total_time = size / time_to_size;
decoder_initialized(decoder, audio_format, decoder_initialized(decoder, audio_format,
input_stream_is_seekable(is), total_time); is->IsSeekable(), total_time);
do { do {
char buffer[4096]; char buffer[4096];
@ -65,7 +66,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
size_t nbytes = decoder_read(decoder, is, size_t nbytes = decoder_read(decoder, is,
buffer, sizeof(buffer)); buffer, sizeof(buffer));
if (nbytes == 0 && input_stream_lock_eof(is)) if (nbytes == 0 && is->LockIsEOF())
break; break;
if (reverse_endian) if (reverse_endian)
@ -83,8 +84,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
decoder_seek_where(decoder)); decoder_seek_where(decoder));
Error error; Error error;
if (input_stream_lock_seek(is, offset, SEEK_SET, if (is->LockSeek(offset, SEEK_SET, error)) {
error)) {
decoder_command_finished(decoder); decoder_command_finished(decoder);
} else { } else {
g_warning("seeking failed: %s", error.GetMessage()); g_warning("seeking failed: %s", error.GetMessage());

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "SndfileDecoderPlugin.hxx" #include "SndfileDecoderPlugin.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "TagHandler.hxx" #include "TagHandler.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -34,7 +35,7 @@ sndfile_vio_get_filelen(void *user_data)
{ {
const struct input_stream *is = (const struct input_stream *)user_data; const struct input_stream *is = (const struct input_stream *)user_data;
return input_stream_get_size(is); return is->GetSize();
} }
static sf_count_t static sf_count_t
@ -42,10 +43,10 @@ sndfile_vio_seek(sf_count_t offset, int whence, void *user_data)
{ {
struct input_stream *is = (struct input_stream *)user_data; struct input_stream *is = (struct input_stream *)user_data;
if (!input_stream_lock_seek(is, offset, whence, IgnoreError())) if (!is->LockSeek(offset, whence, IgnoreError()))
return -1; return -1;
return input_stream_get_offset(is); return is->GetOffset();
} }
static sf_count_t static sf_count_t
@ -54,7 +55,7 @@ sndfile_vio_read(void *ptr, sf_count_t count, void *user_data)
struct input_stream *is = (struct input_stream *)user_data; struct input_stream *is = (struct input_stream *)user_data;
Error error; Error error;
size_t nbytes = input_stream_lock_read(is, ptr, count, error); size_t nbytes = is->LockRead(ptr, count, error);
if (nbytes == 0 && error.IsDefined()) { if (nbytes == 0 && error.IsDefined()) {
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
return -1; return -1;
@ -77,7 +78,7 @@ sndfile_vio_tell(void *user_data)
{ {
const struct input_stream *is = (const struct input_stream *)user_data; const struct input_stream *is = (const struct input_stream *)user_data;
return input_stream_get_offset(is); return is->GetOffset();
} }
/** /**

View File

@ -84,7 +84,7 @@ static int ogg_seek_cb(void *data, ogg_int64_t offset, int whence)
Error error; Error error;
return vis->seekable && return vis->seekable &&
(!vis->decoder || decoder_get_command(vis->decoder) != DECODE_COMMAND_STOP) && (!vis->decoder || decoder_get_command(vis->decoder) != DECODE_COMMAND_STOP) &&
input_stream_lock_seek(vis->input_stream, offset, whence, error) vis->input_stream->LockSeek(offset, whence, error)
? 0 : -1; ? 0 : -1;
} }
@ -138,7 +138,7 @@ vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf,
{ {
vis->decoder = decoder; vis->decoder = decoder;
vis->input_stream = input_stream; vis->input_stream = input_stream;
vis->seekable = input_stream_cheap_seeking(input_stream); vis->seekable = input_stream->CheapSeeking();
int ret = ov_open_callbacks(vis, vf, NULL, 0, vorbis_is_callbacks); int ret = ov_open_callbacks(vis, vf, NULL, 0, vorbis_is_callbacks);
if (ret < 0) { if (ret < 0) {
@ -189,7 +189,7 @@ vorbis_stream_decode(struct decoder *decoder,
/* rewind the stream, because ogg_codec_detect() has /* rewind the stream, because ogg_codec_detect() has
moved it */ moved it */
input_stream_lock_seek(input_stream, 0, SEEK_SET, IgnoreError()); input_stream->LockSeek(0, SEEK_SET, IgnoreError());
struct vorbis_input_stream vis; struct vorbis_input_stream vis;
OggVorbis_File vf; OggVorbis_File vf;

View File

@ -401,17 +401,13 @@ wavpack_input_get_pos(void *id)
static int static int
wavpack_input_set_pos_abs(void *id, uint32_t pos) wavpack_input_set_pos_abs(void *id, uint32_t pos)
{ {
Error error; return wpin(id)->is->LockSeek(pos, SEEK_SET, IgnoreError()) ? 0 : -1;
return input_stream_lock_seek(wpin(id)->is, pos, SEEK_SET, error)
? 0 : -1;
} }
static int static int
wavpack_input_set_pos_rel(void *id, int32_t delta, int mode) wavpack_input_set_pos_rel(void *id, int32_t delta, int mode)
{ {
Error error; return wpin(id)->is->LockSeek(delta, mode, IgnoreError()) ? 0 : -1;
return input_stream_lock_seek(wpin(id)->is, delta, mode, error)
? 0 : -1;
} }
static int static int
@ -479,8 +475,7 @@ wavpack_open_wvc(struct decoder *decoder, const char *uri,
wvc_url = g_strconcat(uri, "c", NULL); wvc_url = g_strconcat(uri, "c", NULL);
Error error; is_wvc = input_stream::Open(wvc_url, mutex, cond, IgnoreError());
is_wvc = input_stream_open(wvc_url, mutex, cond, error);
g_free(wvc_url); g_free(wvc_url);
if (is_wvc == NULL) if (is_wvc == NULL)
@ -494,7 +489,7 @@ wavpack_open_wvc(struct decoder *decoder, const char *uri,
decoder, is_wvc, &first_byte, sizeof(first_byte) decoder, is_wvc, &first_byte, sizeof(first_byte)
); );
if (nbytes == 0) { if (nbytes == 0) {
input_stream_close(is_wvc); is_wvc->Close();
return NULL; return NULL;
} }
@ -545,7 +540,7 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is)
WavpackCloseFile(wpc); WavpackCloseFile(wpc);
if (open_flags & OPEN_WVC) { if (open_flags & OPEN_WVC) {
input_stream_close(is_wvc); is_wvc->Close();
} }
} }

View File

@ -161,7 +161,7 @@ struct input_curl {
char *meta_name; char *meta_name;
/** the tag object ready to be requested via /** the tag object ready to be requested via
input_stream_tag() */ input_stream::ReadTag() */
Tag *tag; Tag *tag;
Error postponed_error; Error postponed_error;

View File

@ -66,7 +66,7 @@ struct RewindInputStream {
} }
~RewindInputStream() { ~RewindInputStream() {
input_stream_close(input); input->Close();
} }
/** /**
@ -114,7 +114,7 @@ input_rewind_check(struct input_stream *is, Error &error)
{ {
RewindInputStream *r = (RewindInputStream *)is; RewindInputStream *r = (RewindInputStream *)is;
return input_stream_check(r->input, error); return r->input->Check(error);
} }
static void static void
@ -131,7 +131,7 @@ input_rewind_tag(struct input_stream *is)
{ {
RewindInputStream *r = (RewindInputStream *)is; RewindInputStream *r = (RewindInputStream *)is;
return input_stream_tag(r->input); return r->input->ReadTag();
} }
static bool static bool
@ -139,7 +139,7 @@ input_rewind_available(struct input_stream *is)
{ {
RewindInputStream *r = (RewindInputStream *)is; RewindInputStream *r = (RewindInputStream *)is;
return input_stream_available(r->input); return r->input->IsAvailable();
} }
static size_t static size_t
@ -165,7 +165,7 @@ input_rewind_read(struct input_stream *is, void *ptr, size_t size,
} else { } else {
/* pass method call to underlying stream */ /* pass method call to underlying stream */
size_t nbytes = input_stream_read(r->input, ptr, size, error); size_t nbytes = r->input->Read(ptr, size, error);
if (r->input->offset > (goffset)sizeof(r->buffer)) if (r->input->offset > (goffset)sizeof(r->buffer))
/* disable buffering */ /* disable buffering */
@ -190,7 +190,7 @@ input_rewind_eof(struct input_stream *is)
{ {
RewindInputStream *r = (RewindInputStream *)is; RewindInputStream *r = (RewindInputStream *)is;
return !r->ReadingFromBuffer() && input_stream_eof(r->input); return !r->ReadingFromBuffer() && r->input->IsEOF();
} }
static bool static bool
@ -213,8 +213,7 @@ input_rewind_seek(struct input_stream *is, goffset offset, int whence,
return true; return true;
} else { } else {
bool success = input_stream_seek(r->input, offset, whence, bool success = r->input->Seek(offset, whence, error);
error);
r->CopyAttributes(); r->CopyAttributes();
/* disable the buffer, because r->input has left the /* disable the buffer, because r->input has left the

View File

@ -20,7 +20,7 @@
#include "config.h" #include "config.h"
#include "AsxPlaylistPlugin.hxx" #include "AsxPlaylistPlugin.hxx"
#include "MemoryPlaylistProvider.hxx" #include "MemoryPlaylistProvider.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Tag.hxx" #include "Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -219,8 +219,7 @@ asx_open_stream(struct input_stream *is)
&parser, asx_parser_destroy); &parser, asx_parser_destroy);
while (true) { while (true) {
nbytes = input_stream_lock_read(is, buffer, sizeof(buffer), nbytes = is->LockRead(buffer, sizeof(buffer), error2);
error2);
if (nbytes == 0) { if (nbytes == 0) {
if (error2.IsDefined()) { if (error2.IsDefined()) {
g_markup_parse_context_free(context); g_markup_parse_context_free(context);

View File

@ -22,7 +22,6 @@
#include "PlaylistPlugin.hxx" #include "PlaylistPlugin.hxx"
#include "Tag.hxx" #include "Tag.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "InputLegacy.hxx"
#include "cue/CueParser.hxx" #include "cue/CueParser.hxx"
#include "TextInputStream.hxx" #include "TextInputStream.hxx"

View File

@ -23,7 +23,7 @@
#include "PlaylistRegistry.hxx" #include "PlaylistRegistry.hxx"
#include "conf.h" #include "conf.h"
#include "Song.hxx" #include "Song.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include <glib.h> #include <glib.h>
@ -45,7 +45,7 @@ struct LastfmPlaylist {
~LastfmPlaylist() { ~LastfmPlaylist() {
playlist_plugin_close(xspf); playlist_plugin_close(xspf);
input_stream_close(is); is->Close();
} }
}; };
@ -97,7 +97,7 @@ lastfm_get(const char *url, Mutex &mutex, Cond &cond)
char buffer[4096]; char buffer[4096];
size_t length = 0; size_t length = 0;
input_stream = input_stream_open(url, mutex, cond, error); input_stream = input_stream::Open(url, mutex, cond, error);
if (input_stream == NULL) { if (input_stream == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
@ -107,22 +107,22 @@ lastfm_get(const char *url, Mutex &mutex, Cond &cond)
mutex.lock(); mutex.lock();
input_stream_wait_ready(input_stream); input_stream->WaitReady();
do { do {
size_t nbytes = size_t nbytes =
input_stream_read(input_stream, buffer + length, input_stream->Read(buffer + length,
sizeof(buffer) - length, error); sizeof(buffer) - length, error);
if (nbytes == 0) { if (nbytes == 0) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
if (input_stream_eof(input_stream)) if (input_stream->IsEOF())
break; break;
/* I/O error */ /* I/O error */
mutex.unlock(); mutex.unlock();
input_stream_close(input_stream); input_stream->Close();
return NULL; return NULL;
} }
@ -131,7 +131,7 @@ lastfm_get(const char *url, Mutex &mutex, Cond &cond)
mutex.unlock(); mutex.unlock();
input_stream_close(input_stream); input_stream->Close();
return g_strndup(buffer, length); return g_strndup(buffer, length);
} }
@ -223,7 +223,7 @@ lastfm_open_uri(const char *uri, Mutex &mutex, Cond &cond)
g_free(session); g_free(session);
Error error; Error error;
const auto is = input_stream_open(p, mutex, cond, error); const auto is = input_stream::Open(p, mutex, cond, error);
g_free(p); g_free(p);
if (is == nullptr) { if (is == nullptr) {
@ -237,11 +237,11 @@ lastfm_open_uri(const char *uri, Mutex &mutex, Cond &cond)
mutex.lock(); mutex.lock();
input_stream_wait_ready(is); is->WaitReady();
/* last.fm does not send a MIME type, we have to fake it here /* last.fm does not send a MIME type, we have to fake it here
:-( */ :-( */
input_stream_override_mime_type(is, "application/xspf+xml"); is->OverrideMimeType("application/xspf+xml");
mutex.unlock(); mutex.unlock();
@ -249,7 +249,7 @@ lastfm_open_uri(const char *uri, Mutex &mutex, Cond &cond)
const auto xspf = playlist_list_open_stream(is, nullptr); const auto xspf = playlist_list_open_stream(is, nullptr);
if (xspf == nullptr) { if (xspf == nullptr) {
input_stream_close(is); is->Close();
g_warning("Failed to parse XSPF playlist"); g_warning("Failed to parse XSPF playlist");
return NULL; return NULL;
} }

View File

@ -20,7 +20,7 @@
#include "config.h" #include "config.h"
#include "PlsPlaylistPlugin.hxx" #include "PlsPlaylistPlugin.hxx"
#include "MemoryPlaylistProvider.hxx" #include "MemoryPlaylistProvider.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Tag.hxx" #include "Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -114,8 +114,7 @@ pls_open_stream(struct input_stream *is)
std::string kf_data; std::string kf_data;
do { do {
nbytes = input_stream_lock_read(is, buffer, sizeof(buffer), nbytes = is->LockRead(buffer, sizeof(buffer), error2);
error2);
if (nbytes == 0) { if (nbytes == 0) {
if (error2.IsDefined()) { if (error2.IsDefined()) {
g_warning("%s", error2.GetMessage()); g_warning("%s", error2.GetMessage());

View File

@ -20,7 +20,7 @@
#include "config.h" #include "config.h"
#include "RssPlaylistPlugin.hxx" #include "RssPlaylistPlugin.hxx"
#include "MemoryPlaylistProvider.hxx" #include "MemoryPlaylistProvider.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Tag.hxx" #include "Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -216,8 +216,7 @@ rss_open_stream(struct input_stream *is)
&parser, rss_parser_destroy); &parser, rss_parser_destroy);
while (true) { while (true) {
nbytes = input_stream_lock_read(is, buffer, sizeof(buffer), nbytes = is->LockRead(buffer, sizeof(buffer), error2);
error2);
if (nbytes == 0) { if (nbytes == 0) {
if (error2.IsDefined()) { if (error2.IsDefined()) {
g_markup_parse_context_free(context); g_markup_parse_context_free(context);

View File

@ -21,7 +21,7 @@
#include "SoundCloudPlaylistPlugin.hxx" #include "SoundCloudPlaylistPlugin.hxx"
#include "MemoryPlaylistProvider.hxx" #include "MemoryPlaylistProvider.hxx"
#include "conf.h" #include "conf.h"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Tag.hxx" #include "Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -249,7 +249,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
unsigned char *ubuffer = (unsigned char *)buffer; unsigned char *ubuffer = (unsigned char *)buffer;
Error error; Error error;
input_stream *input_stream = input_stream_open(url, mutex, cond, input_stream *input_stream = input_stream::Open(url, mutex, cond,
error); error);
if (input_stream == NULL) { if (input_stream == NULL) {
if (error.IsDefined()) if (error.IsDefined())
@ -258,24 +258,23 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
} }
mutex.lock(); mutex.lock();
input_stream_wait_ready(input_stream); input_stream->WaitReady();
yajl_status stat; yajl_status stat;
int done = 0; int done = 0;
while (!done) { while (!done) {
const size_t nbytes = const size_t nbytes =
input_stream_read(input_stream, buffer, sizeof(buffer), input_stream->Read(buffer, sizeof(buffer), error);
error);
if (nbytes == 0) { if (nbytes == 0) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
if (input_stream_eof(input_stream)) { if (input_stream->IsEOF()) {
done = true; done = true;
} else { } else {
mutex.unlock(); mutex.unlock();
input_stream_close(input_stream); input_stream->Close();
return -1; return -1;
} }
} }
@ -303,7 +302,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
} }
mutex.unlock(); mutex.unlock();
input_stream_close(input_stream); input_stream->Close();
return 0; return 0;
} }

View File

@ -20,7 +20,7 @@
#include "config.h" #include "config.h"
#include "XspfPlaylistPlugin.hxx" #include "XspfPlaylistPlugin.hxx"
#include "MemoryPlaylistProvider.hxx" #include "MemoryPlaylistProvider.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "Tag.hxx" #include "Tag.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -235,8 +235,7 @@ xspf_open_stream(struct input_stream *is)
&parser, xspf_parser_destroy); &parser, xspf_parser_destroy);
while (true) { while (true) {
nbytes = input_stream_lock_read(is, buffer, sizeof(buffer), nbytes = is->LockRead(buffer, sizeof(buffer), error2);
error2);
if (nbytes == 0) { if (nbytes == 0) {
if (error2.IsDefined()) { if (error2.IsDefined()) {
g_markup_parse_context_free(context); g_markup_parse_context_free(context);

View File

@ -21,7 +21,7 @@
#include "TagSave.hxx" #include "TagSave.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "Directory.hxx" #include "Directory.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "conf.h" #include "conf.h"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "DecoderList.hxx" #include "DecoderList.hxx"
@ -86,7 +86,7 @@ decoder_read(gcc_unused struct decoder *decoder,
void *buffer, size_t length) void *buffer, size_t length)
{ {
Error error; Error error;
return input_stream_lock_read(is, buffer, length, error); return is->LockRead(buffer, length, error);
} }
void void
@ -190,22 +190,22 @@ int main(int argc, char **argv)
if (playlist == NULL) { if (playlist == NULL) {
/* open the stream and wait until it becomes ready */ /* open the stream and wait until it becomes ready */
is = input_stream_open(uri, mutex, cond, error); is = input_stream::Open(uri, mutex, cond, error);
if (is == NULL) { if (is == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
else else
g_printerr("input_stream_open() failed\n"); g_printerr("input_stream::Open() failed\n");
return 2; return 2;
} }
input_stream_lock_wait_ready(is); is->LockWaitReady();
/* open the playlist */ /* open the playlist */
playlist = playlist_list_open_stream(is, uri); playlist = playlist_list_open_stream(is, uri);
if (playlist == NULL) { if (playlist == NULL) {
input_stream_close(is); is->Close();
g_printerr("Failed to open playlist\n"); g_printerr("Failed to open playlist\n");
return 2; return 2;
} }
@ -237,7 +237,7 @@ int main(int argc, char **argv)
playlist_plugin_close(playlist); playlist_plugin_close(playlist);
if (is != NULL) if (is != NULL)
input_stream_close(is); is->Close();
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();
playlist_list_global_finish(); playlist_list_global_finish();

View File

@ -59,34 +59,35 @@ dump_input_stream(struct input_stream *is)
{ {
Error error; Error error;
input_stream_lock(is); is->Lock();
/* wait until the stream becomes ready */ /* wait until the stream becomes ready */
input_stream_wait_ready(is); is->WaitReady();
if (!input_stream_check(is, error)) { if (!is->Check(error)) {
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
input_stream_unlock(is); is->Unlock();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* read data and tags from the stream */ /* read data and tags from the stream */
input_stream_unlock(is); is->Unlock();
{ {
TextInputStream tis(is); TextInputStream tis(is);
dump_text_file(tis); dump_text_file(tis);
} }
input_stream_lock(is);
if (!input_stream_check(is, error)) { is->Lock();
if (!is->Check(error)) {
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
input_stream_unlock(is); is->Unlock();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
input_stream_unlock(is); is->Unlock();
return 0; return 0;
} }
@ -131,15 +132,15 @@ int main(int argc, char **argv)
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
is = input_stream_open(argv[1], mutex, cond, error); is = input_stream::Open(argv[1], mutex, cond, error);
if (is != NULL) { if (is != NULL) {
ret = dump_input_stream(is); ret = dump_input_stream(is);
input_stream_close(is); is->Close();
} else { } else {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
else else
g_printerr("input_stream_open() failed\n"); g_printerr("input_stream::Open() failed\n");
ret = 2; ret = 2;
} }

View File

@ -72,7 +72,7 @@ decoder_read(gcc_unused struct decoder *decoder,
void *buffer, size_t length) void *buffer, size_t length)
{ {
Error error; Error error;
return input_stream_lock_read(is, buffer, length, error); return is->LockRead(buffer, length, error);
} }
void void
@ -185,9 +185,8 @@ int main(int argc, char **argv)
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
struct input_stream *is = input_stream *is = input_stream::Open(path, mutex, cond,
input_stream_open(path, mutex, cond, error); error);
if (is == NULL) { if (is == NULL) {
g_printerr("Failed to open %s: %s\n", g_printerr("Failed to open %s: %s\n",
path, error.GetMessage()); path, error.GetMessage());
@ -196,9 +195,9 @@ int main(int argc, char **argv)
mutex.lock(); mutex.lock();
input_stream_wait_ready(is); is->WaitReady();
if (!input_stream_check(is, error)) { if (!is->Check(error)) {
mutex.unlock(); mutex.unlock();
g_printerr("Failed to read %s: %s\n", g_printerr("Failed to read %s: %s\n",
@ -210,7 +209,7 @@ int main(int argc, char **argv)
success = decoder_plugin_scan_stream(plugin, is, success = decoder_plugin_scan_stream(plugin, is,
&print_handler, NULL); &print_handler, NULL);
input_stream_close(is); is->Close();
} }
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();

View File

@ -22,7 +22,7 @@
#include "DecoderList.hxx" #include "DecoderList.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "InputInit.hxx" #include "InputInit.hxx"
#include "InputLegacy.hxx" #include "InputStream.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "stdbin.h" #include "stdbin.h"
@ -92,8 +92,7 @@ decoder_read(gcc_unused struct decoder *decoder,
struct input_stream *is, struct input_stream *is,
void *buffer, size_t length) void *buffer, size_t length)
{ {
Error error; return is->LockRead(buffer, length, IgnoreError());
return input_stream_lock_read(is, buffer, length, error);
} }
void void
@ -189,20 +188,20 @@ int main(int argc, char **argv)
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
struct input_stream *is = input_stream *is =
input_stream_open(decoder.uri, mutex, cond, error); input_stream::Open(decoder.uri, mutex, cond, error);
if (is == NULL) { if (is == NULL) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
else else
g_printerr("input_stream_open() failed\n"); g_printerr("input_stream::Open() failed\n");
return 1; return 1;
} }
decoder_plugin_stream_decode(decoder.plugin, &decoder, is); decoder_plugin_stream_decode(decoder.plugin, &decoder, is);
input_stream_close(is); is->Close();
} else { } else {
g_printerr("Decoder plugin is not usable\n"); g_printerr("Decoder plugin is not usable\n");
return 1; return 1;

View File

@ -22,7 +22,6 @@
#include "stdbin.h" #include "stdbin.h"
#include "Tag.hxx" #include "Tag.hxx"
#include "conf.h" #include "conf.h"
#include "InputLegacy.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "InputInit.hxx" #include "InputInit.hxx"
#include "IOThread.hxx" #include "IOThread.hxx"
@ -55,15 +54,15 @@ dump_input_stream(struct input_stream *is)
size_t num_read; size_t num_read;
ssize_t num_written; ssize_t num_written;
input_stream_lock(is); is->Lock();
/* wait until the stream becomes ready */ /* wait until the stream becomes ready */
input_stream_wait_ready(is); is->WaitReady();
if (!input_stream_check(is, error)) { if (!is->Check(error)) {
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
input_stream_unlock(is); is->Unlock();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -74,16 +73,15 @@ dump_input_stream(struct input_stream *is)
/* read data and tags from the stream */ /* read data and tags from the stream */
while (!input_stream_eof(is)) { while (!is->IsEOF()) {
Tag *tag = input_stream_tag(is); Tag *tag = is->ReadTag();
if (tag != NULL) { if (tag != NULL) {
g_printerr("Received a tag:\n"); g_printerr("Received a tag:\n");
tag_save(stderr, *tag); tag_save(stderr, *tag);
delete tag; delete tag;
} }
num_read = input_stream_read(is, buffer, sizeof(buffer), num_read = is->Read(buffer, sizeof(buffer), error);
error);
if (num_read == 0) { if (num_read == 0) {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
@ -96,13 +94,13 @@ dump_input_stream(struct input_stream *is)
break; break;
} }
if (!input_stream_check(is, error)) { if (!is->Check(error)) {
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
input_stream_unlock(is); is->Unlock();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
input_stream_unlock(is); is->Unlock();
return 0; return 0;
} }
@ -147,15 +145,15 @@ int main(int argc, char **argv)
Mutex mutex; Mutex mutex;
Cond cond; Cond cond;
is = input_stream_open(argv[1], mutex, cond, error); is = input_stream::Open(argv[1], mutex, cond, error);
if (is != NULL) { if (is != NULL) {
ret = dump_input_stream(is); ret = dump_input_stream(is);
input_stream_close(is); is->Close();
} else { } else {
if (error.IsDefined()) if (error.IsDefined())
g_warning("%s", error.GetMessage()); g_warning("%s", error.GetMessage());
else else
g_printerr("input_stream_open() failed\n"); g_printerr("input_stream::Open() failed\n");
ret = 2; ret = 2;
} }