diff options
author | Max Kellermann <max@musicpd.org> | 2016-09-05 12:19:20 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2016-09-09 14:44:13 +0200 |
commit | ae1eb9ccdeb16183ad3faaf8dbf548b1934889db (patch) | |
tree | 17456fa28a7a030cbba445512def9c0bb9f8e306 /src/pcm/PcmConvert.cxx | |
parent | 860064c8128fd12b2ae6a32d399f01fe6390a223 (diff) |
pcm/Convert: migrate from class Error to C++ exceptions
Diffstat (limited to 'src/pcm/PcmConvert.cxx')
-rw-r--r-- | src/pcm/PcmConvert.cxx | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx index 81bec1c75..2470583c8 100644 --- a/src/pcm/PcmConvert.cxx +++ b/src/pcm/PcmConvert.cxx @@ -22,15 +22,14 @@ #include "Domain.hxx" #include "ConfiguredResampler.hxx" #include "AudioFormat.hxx" -#include "util/Error.hxx" #include "util/ConstBuffer.hxx" #include <assert.h> -bool -pcm_convert_global_init(Error &error) +void +pcm_convert_global_init() { - return pcm_resampler_global_init(error); + pcm_resampler_global_init(); } PcmConvert::PcmConvert() @@ -47,9 +46,8 @@ PcmConvert::~PcmConvert() assert(!dest_format.IsValid()); } -bool -PcmConvert::Open(const AudioFormat _src_format, const AudioFormat _dest_format, - Error &error) +void +PcmConvert::Open(const AudioFormat _src_format, const AudioFormat _dest_format) { assert(!src_format.IsValid()); assert(!dest_format.IsValid()); @@ -62,39 +60,42 @@ PcmConvert::Open(const AudioFormat _src_format, const AudioFormat _dest_format, enable_resampler = format.sample_rate != _dest_format.sample_rate; if (enable_resampler) { - if (!resampler.Open(format, _dest_format.sample_rate, error)) - return false; + resampler.Open(format, _dest_format.sample_rate); format.format = resampler.GetOutputSampleFormat(); format.sample_rate = _dest_format.sample_rate; } enable_format = format.format != _dest_format.format; - if (enable_format && - !format_converter.Open(format.format, _dest_format.format, - error)) { - if (enable_resampler) - resampler.Close(); - return false; + if (enable_format) { + try { + format_converter.Open(format.format, + _dest_format.format); + } catch (...) { + if (enable_resampler) + resampler.Close(); + throw; + } } format.format = _dest_format.format; enable_channels = format.channels != _dest_format.channels; - if (enable_channels && - !channels_converter.Open(format.format, format.channels, - _dest_format.channels, error)) { - if (enable_format) - format_converter.Close(); - if (enable_resampler) - resampler.Close(); - return false; + if (enable_channels) { + try { + channels_converter.Open(format.format, format.channels, + _dest_format.channels); + } catch (...) { + if (enable_format) + format_converter.Close(); + if (enable_resampler) + resampler.Close(); + throw; + } } src_format = _src_format; dest_format = _dest_format; - - return true; } void @@ -118,39 +119,27 @@ PcmConvert::Close() } ConstBuffer<void> -PcmConvert::Convert(ConstBuffer<void> buffer, Error &error) +PcmConvert::Convert(ConstBuffer<void> buffer) { #ifdef ENABLE_DSD if (src_format.format == SampleFormat::DSD) { auto s = ConstBuffer<uint8_t>::FromVoid(buffer); auto d = dsd.ToFloat(src_format.channels, s); - if (d.IsNull()) { - error.Set(pcm_domain, - "DSD to PCM conversion failed"); - return nullptr; - } + if (d.IsNull()) + throw std::runtime_error("DSD to PCM conversion failed"); buffer = d.ToVoid(); } #endif - if (enable_resampler) { - buffer = resampler.Resample(buffer, error); - if (buffer.IsNull()) - return nullptr; - } + if (enable_resampler) + buffer = resampler.Resample(buffer); - if (enable_format) { - buffer = format_converter.Convert(buffer, error); - if (buffer.IsNull()) - return nullptr; - } + if (enable_format) + buffer = format_converter.Convert(buffer); - if (enable_channels) { - buffer = channels_converter.Convert(buffer, error); - if (buffer.IsNull()) - return nullptr; - } + if (enable_channels) + buffer = channels_converter.Convert(buffer); return buffer; } |