decoder/flac: migrate from class Error to C++ exceptions
This commit is contained in:
parent
42a696873b
commit
4e16ea0f0a
@ -24,10 +24,11 @@
|
||||
#include "config.h"
|
||||
#include "FlacCommon.hxx"
|
||||
#include "FlacMetadata.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
bool
|
||||
FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample,
|
||||
unsigned channels, FLAC__uint64 total_frames)
|
||||
@ -35,10 +36,11 @@ FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample,
|
||||
assert(!initialized);
|
||||
assert(!unsupported);
|
||||
|
||||
::Error error;
|
||||
if (!pcm_import.Open(sample_rate, bits_per_sample,
|
||||
channels, error)) {
|
||||
LogError(error);
|
||||
try {
|
||||
pcm_import.Open(sample_rate, bits_per_sample,
|
||||
channels);
|
||||
} catch (const std::runtime_error &e) {
|
||||
LogError(e);
|
||||
unsupported = true;
|
||||
return false;
|
||||
}
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "OggCodec.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "fs/NarrowPath.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "FlacPcm.hxx"
|
||||
#include "FlacDomain.hxx"
|
||||
#include "CheckAudioFormat.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
|
||||
#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,
|
||||
unsigned channels, Error &error)
|
||||
unsigned channels)
|
||||
{
|
||||
auto sample_format = flac_sample_format(bits_per_sample);
|
||||
if (sample_format == SampleFormat::UNDEFINED) {
|
||||
error.Format(flac_domain, "Unsupported FLAC bit depth: %u",
|
||||
bits_per_sample);
|
||||
return false;
|
||||
}
|
||||
if (sample_format == SampleFormat::UNDEFINED)
|
||||
throw FormatRuntimeError("Unsupported FLAC bit depth: %u",
|
||||
bits_per_sample);
|
||||
|
||||
audio_format = CheckAudioFormat(sample_rate, sample_format, channels);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
#include <FLAC/ordinals.h>
|
||||
|
||||
class Error;
|
||||
template<typename T> struct ConstBuffer;
|
||||
|
||||
/**
|
||||
@ -39,8 +38,11 @@ class FlacPcmImport {
|
||||
AudioFormat audio_format;
|
||||
|
||||
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 {
|
||||
return audio_format;
|
||||
|
Loading…
Reference in New Issue
Block a user