decoder/flac: migrate from class Error to C++ exceptions

This commit is contained in:
Max Kellermann 2016-11-10 12:19:33 +01:00
parent 42a696873b
commit 4e16ea0f0a
4 changed files with 18 additions and 19 deletions

View File

@ -24,10 +24,11 @@
#include "config.h" #include "config.h"
#include "FlacCommon.hxx" #include "FlacCommon.hxx"
#include "FlacMetadata.hxx" #include "FlacMetadata.hxx"
#include "util/Error.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <stdexcept>
bool bool
FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample, FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample,
unsigned channels, FLAC__uint64 total_frames) unsigned channels, FLAC__uint64 total_frames)
@ -35,10 +36,11 @@ FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample,
assert(!initialized); assert(!initialized);
assert(!unsupported); assert(!unsupported);
::Error error; try {
if (!pcm_import.Open(sample_rate, bits_per_sample, pcm_import.Open(sample_rate, bits_per_sample,
channels, error)) { channels);
LogError(error); } catch (const std::runtime_error &e) {
LogError(e);
unsupported = true; unsupported = true;
return false; return false;
} }

View File

@ -26,7 +26,6 @@
#include "OggCodec.hxx" #include "OggCodec.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/NarrowPath.hxx" #include "fs/NarrowPath.hxx"
#include "util/Error.hxx"
#include "Log.hxx" #include "Log.hxx"
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7

View File

@ -19,9 +19,8 @@
#include "config.h" #include "config.h"
#include "FlacPcm.hxx" #include "FlacPcm.hxx"
#include "FlacDomain.hxx"
#include "CheckAudioFormat.hxx" #include "CheckAudioFormat.hxx"
#include "util/Error.hxx" #include "util/RuntimeError.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include <assert.h> #include <assert.h>
@ -47,19 +46,16 @@ flac_sample_format(unsigned bits_per_sample)
} }
} }
bool void
FlacPcmImport::Open(unsigned sample_rate, unsigned bits_per_sample, FlacPcmImport::Open(unsigned sample_rate, unsigned bits_per_sample,
unsigned channels, Error &error) unsigned channels)
{ {
auto sample_format = flac_sample_format(bits_per_sample); auto sample_format = flac_sample_format(bits_per_sample);
if (sample_format == SampleFormat::UNDEFINED) { if (sample_format == SampleFormat::UNDEFINED)
error.Format(flac_domain, "Unsupported FLAC bit depth: %u", throw FormatRuntimeError("Unsupported FLAC bit depth: %u",
bits_per_sample); bits_per_sample);
return false;
}
audio_format = CheckAudioFormat(sample_rate, sample_format, channels); audio_format = CheckAudioFormat(sample_rate, sample_format, channels);
return true;
} }
template<typename T> template<typename T>

View File

@ -26,7 +26,6 @@
#include <FLAC/ordinals.h> #include <FLAC/ordinals.h>
class Error;
template<typename T> struct ConstBuffer; template<typename T> struct ConstBuffer;
/** /**
@ -39,8 +38,11 @@ class FlacPcmImport {
AudioFormat audio_format; AudioFormat audio_format;
public: public:
bool Open(unsigned sample_rate, unsigned bits_per_sample, /**
unsigned channels, Error &error); * Throws #std::runtime_error on error.
*/
void Open(unsigned sample_rate, unsigned bits_per_sample,
unsigned channels);
const AudioFormat &GetAudioFormat() const { const AudioFormat &GetAudioFormat() const {
return audio_format; return audio_format;