decoder/Internal: convert error from Error to std::exception_ptr

This commit is contained in:
Max Kellermann 2016-09-08 20:31:06 +02:00
parent 25f7360264
commit 845901ab01
3 changed files with 9 additions and 8 deletions

View File

@ -77,7 +77,7 @@ decoder_initialized(Decoder &decoder,
if (!decoder.convert->Open(dc.in_audio_format, if (!decoder.convert->Open(dc.in_audio_format,
dc.out_audio_format, dc.out_audio_format,
error)) error))
decoder.error = std::move(error); decoder.error = std::make_exception_ptr(std::move(error));
} }
const ScopeLock protect(dc.mutex); const ScopeLock protect(dc.mutex);
@ -140,7 +140,7 @@ gcc_pure
static DecoderCommand static DecoderCommand
decoder_get_virtual_command(Decoder &decoder) decoder_get_virtual_command(Decoder &decoder)
{ {
if (decoder.error.IsDefined()) if (decoder.error)
/* an error has occurred: stop the decoder plugin */ /* an error has occurred: stop the decoder plugin */
return DecoderCommand::STOP; return DecoderCommand::STOP;

View File

@ -21,7 +21,8 @@
#define MPD_DECODER_INTERNAL_HXX #define MPD_DECODER_INTERNAL_HXX
#include "ReplayGainInfo.hxx" #include "ReplayGainInfo.hxx"
#include "util/Error.hxx"
#include <exception>
class PcmConvert; class PcmConvert;
struct MusicChunk; struct MusicChunk;
@ -91,7 +92,7 @@ struct Decoder {
* An error has occurred (in DecoderAPI.cxx), and the plugin * An error has occurred (in DecoderAPI.cxx), and the plugin
* will be asked to stop. * will be asked to stop.
*/ */
Error error; std::exception_ptr error;
Decoder(DecoderControl &_dc, bool _initial_seek_pending, Tag *_tag) Decoder(DecoderControl &_dc, bool _initial_seek_pending, Tag *_tag)
:dc(_dc), :dc(_dc),

View File

@ -211,7 +211,7 @@ decoder_run_stream_plugin(Decoder &decoder, InputStream &is,
if (!decoder_check_plugin(plugin, is, suffix)) if (!decoder_check_plugin(plugin, is, suffix))
return false; return false;
decoder.error.Clear(); decoder.error = std::exception_ptr();
tried_r = true; tried_r = true;
return decoder_stream_decode(plugin, decoder, is); return decoder_stream_decode(plugin, decoder, is);
@ -300,7 +300,7 @@ TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix,
if (!plugin.SupportsSuffix(suffix)) if (!plugin.SupportsSuffix(suffix))
return false; return false;
decoder.error.Clear(); decoder.error = std::exception_ptr();
DecoderControl &dc = decoder.dc; DecoderControl &dc = decoder.dc;
@ -398,10 +398,10 @@ decoder_run_song(DecoderControl &dc,
} }
if (decoder.error.IsDefined()) { if (decoder.error) {
/* copy the Error from struct Decoder to /* copy the Error from struct Decoder to
DecoderControl */ DecoderControl */
throw std::move(decoder.error); std::rethrow_exception(decoder.error);
} else if (success) } else if (success)
dc.state = DecoderState::STOP; dc.state = DecoderState::STOP;
else { else {