From 8ce48d83eb4d6f0d97359747f15e72dd1ef8760b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 23 Oct 2014 22:13:08 +0200 Subject: pcm/FormatConverter: move check to Open() Report unsupported format while opening the filter, not later when the first conversion takes place. --- src/pcm/FormatConverter.cxx | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/pcm') diff --git a/src/pcm/FormatConverter.cxx b/src/pcm/FormatConverter.cxx index 64e2d8594..b058b32f5 100644 --- a/src/pcm/FormatConverter.cxx +++ b/src/pcm/FormatConverter.cxx @@ -28,11 +28,31 @@ bool PcmFormatConverter::Open(SampleFormat _src_format, SampleFormat _dest_format, - gcc_unused Error &error) + Error &error) { assert(_src_format != SampleFormat::UNDEFINED); assert(_dest_format != SampleFormat::UNDEFINED); + switch (_dest_format) { + case SampleFormat::UNDEFINED: + assert(false); + gcc_unreachable(); + + case SampleFormat::S8: + case SampleFormat::DSD: + error.Format(pcm_domain, + "PCM conversion from %s to %s is not implemented", + sample_format_to_string(_src_format), + sample_format_to_string(_dest_format)); + return nullptr; + + case SampleFormat::S16: + case SampleFormat::S24_P32: + case SampleFormat::S32: + case SampleFormat::FLOAT: + break; + } + src_format = _src_format; dest_format = _dest_format; return true; @@ -48,20 +68,14 @@ PcmFormatConverter::Close() } ConstBuffer -PcmFormatConverter::Convert(ConstBuffer src, Error &error) +PcmFormatConverter::Convert(ConstBuffer src, gcc_unused Error &error) { switch (dest_format) { case SampleFormat::UNDEFINED: - assert(false); - gcc_unreachable(); - case SampleFormat::S8: case SampleFormat::DSD: - error.Format(pcm_domain, - "PCM conversion from %s to %s is not implemented", - sample_format_to_string(src_format), - sample_format_to_string(dest_format)); - return nullptr; + assert(false); + gcc_unreachable(); case SampleFormat::S16: return pcm_convert_to_16(buffer, dither, -- cgit v1.2.3