mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
LibAudio: Make LoaderPlugin::error_string return String&
Previously, error_string() returned char* which is bad Serenity style and caused issues when other error handling methods were tried. As both WavLoader and (future) FLAC loader store a String internally for the error message, it makes sense to return a String reference instead.
This commit is contained in:
parent
d599a14545
commit
488de12ed4
2 changed files with 6 additions and 3 deletions
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
namespace Audio {
|
namespace Audio {
|
||||||
|
|
||||||
|
static const String empty_string = "";
|
||||||
|
static String no_plugin_error = "No loader plugin available";
|
||||||
|
|
||||||
class LoaderPlugin {
|
class LoaderPlugin {
|
||||||
public:
|
public:
|
||||||
virtual ~LoaderPlugin() { }
|
virtual ~LoaderPlugin() { }
|
||||||
|
@ -22,7 +25,7 @@ public:
|
||||||
virtual bool sniff() = 0;
|
virtual bool sniff() = 0;
|
||||||
|
|
||||||
virtual bool has_error() { return false; }
|
virtual bool has_error() { return false; }
|
||||||
virtual const char* error_string() { return ""; }
|
virtual const String& error_string() { return empty_string; }
|
||||||
|
|
||||||
virtual RefPtr<Buffer> get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB) = 0;
|
virtual RefPtr<Buffer> get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB) = 0;
|
||||||
|
|
||||||
|
@ -52,7 +55,7 @@ public:
|
||||||
static NonnullRefPtr<Loader> create(const ByteBuffer& buffer) { return adopt_ref(*new Loader(buffer)); }
|
static NonnullRefPtr<Loader> create(const ByteBuffer& buffer) { return adopt_ref(*new Loader(buffer)); }
|
||||||
|
|
||||||
bool has_error() const { return m_plugin ? m_plugin->has_error() : true; }
|
bool has_error() const { return m_plugin ? m_plugin->has_error() : true; }
|
||||||
const char* error_string() const { return m_plugin ? m_plugin->error_string() : "No loader plugin available"; }
|
const String& error_string() const { return m_plugin ? m_plugin->error_string() : no_plugin_error; }
|
||||||
|
|
||||||
RefPtr<Buffer> get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB) const { return m_plugin ? m_plugin->get_more_samples(max_bytes_to_read_from_input) : nullptr; }
|
RefPtr<Buffer> get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB) const { return m_plugin ? m_plugin->get_more_samples(max_bytes_to_read_from_input) : nullptr; }
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
virtual bool sniff() override { return valid; }
|
virtual bool sniff() override { return valid; }
|
||||||
|
|
||||||
virtual bool has_error() override { return !m_error_string.is_null(); }
|
virtual bool has_error() override { return !m_error_string.is_null(); }
|
||||||
virtual const char* error_string() override { return m_error_string.characters(); }
|
virtual const String& error_string() override { return m_error_string; }
|
||||||
|
|
||||||
// The Buffer returned contains input data resampled at the
|
// The Buffer returned contains input data resampled at the
|
||||||
// destination audio device sample rate.
|
// destination audio device sample rate.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue