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

This commit is contained in:
Max Kellermann 2016-11-10 12:15:49 +01:00
parent cfd51db229
commit 42a696873b

View File

@ -26,7 +26,6 @@
#include "tag/TagHandler.hxx" #include "tag/TagHandler.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -248,16 +247,16 @@ faad_decoder_new()
/** /**
* Wrapper for NeAACDecInit() which works around some API * Wrapper for NeAACDecInit() which works around some API
* inconsistencies in libfaad. * inconsistencies in libfaad.
*
* Throws #std::runtime_error on error.
*/ */
static bool static void
faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer &buffer, faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer &buffer,
AudioFormat &audio_format, Error &error) AudioFormat &audio_format)
{ {
auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read()); auto data = ConstBuffer<uint8_t>::FromVoid(buffer.Read());
if (data.IsEmpty()) { if (data.IsEmpty())
error.Set(faad_decoder_domain, "Empty file"); throw std::runtime_error("Empty file");
return false;
}
uint8_t channels; uint8_t channels;
unsigned long sample_rate; unsigned long sample_rate;
@ -266,16 +265,13 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer &buffer,
const_cast<unsigned char *>(data.data), const_cast<unsigned char *>(data.data),
data.size, data.size,
&sample_rate, &channels); &sample_rate, &channels);
if (nbytes < 0) { if (nbytes < 0)
error.Set(faad_decoder_domain, "Not an AAC stream"); throw std::runtime_error("Not an AAC stream");
return false;
}
buffer.Consume(nbytes); buffer.Consume(nbytes);
audio_format = CheckAudioFormat(sample_rate, SampleFormat::S16, audio_format = CheckAudioFormat(sample_rate, SampleFormat::S16,
channels); channels);
return true;
} }
/** /**
@ -317,9 +313,11 @@ faad_get_file_time(InputStream &is)
buffer.Fill(); buffer.Fill();
AudioFormat audio_format; AudioFormat audio_format;
if (faad_decoder_init(decoder, buffer, audio_format, try {
IgnoreError())) faad_decoder_init(decoder, buffer, audio_format);
recognized = true; recognized = true;
} catch (const std::runtime_error &e) {
}
} }
return std::make_pair(recognized, duration); return std::make_pair(recognized, duration);
@ -336,12 +334,8 @@ faad_stream_decode(Decoder &mpd_decoder, InputStream &is,
/* initialize it */ /* initialize it */
Error error;
AudioFormat audio_format; AudioFormat audio_format;
if (!faad_decoder_init(decoder, buffer, audio_format, error)) { faad_decoder_init(decoder, buffer, audio_format);
LogError(error);
return;
}
/* initialize the MPD core */ /* initialize the MPD core */