diff --git a/client/decoder/flacDecoder.cpp b/client/decoder/flacDecoder.cpp index a25cb8da..e4d02ca9 100644 --- a/client/decoder/flacDecoder.cpp +++ b/client/decoder/flacDecoder.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include "flacDecoder.h" #include "common/snapException.h" #include "common/endian.h" @@ -43,7 +42,7 @@ static FLAC__StreamDecoder *decoder = NULL; -FlacDecoder::FlacDecoder() : Decoder() +FlacDecoder::FlacDecoder() : Decoder(), lastError_(nullptr) { flacChunk = new msg::PcmChunk(); } @@ -69,7 +68,19 @@ bool FlacDecoder::decode(msg::PcmChunk* chunk) pcmChunk->payload = (char*)realloc(pcmChunk->payload, 0); pcmChunk->payloadSize = 0; while (flacChunk->payloadSize > 0) - FLAC__stream_decoder_process_single(decoder); + { + if (!FLAC__stream_decoder_process_single(decoder)) + { + return false; + } + + if (lastError_) + { + logE << "FLAC decode error: " << FLAC__StreamDecoderErrorStatusString[*lastError_] << "\n"; + lastError_= nullptr; + return false; + } + } if ((cacheInfo_.cachedBlocks_ > 0) && (cacheInfo_.sampleRate_ != 0)) { @@ -116,10 +127,14 @@ FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *decoder, } else if (flacChunk != NULL) { +// cerr << "read_callback: " << *bytes << ", avail: " << flacChunk->payloadSize << "\n"; static_cast(client_data)->cacheInfo_.isCachedChunk_ = false; if (*bytes > flacChunk->payloadSize) *bytes = flacChunk->payloadSize; +// if (*bytes == 0) +// return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; + memcpy(buffer, flacChunk->payload, *bytes); memmove(flacChunk->payload, flacChunk->payload + *bytes, flacChunk->payloadSize - *bytes); flacChunk->payloadSize = flacChunk->payloadSize - *bytes; @@ -196,6 +211,8 @@ void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderError { (void)decoder, (void)client_data; logS(kLogErr) << "Got error callback: " << FLAC__StreamDecoderErrorStatusString[status] << "\n"; + static_cast(client_data)->lastError_ = std::unique_ptr(new FLAC__StreamDecoderErrorStatus(status)); + /// TODO, see issue #120: // Thu Nov 10 07:26:44 2016 daemon.warn dnsmasq-dhcp[1194]: no address range available for DHCP request via wlan0 // Thu Nov 10 07:54:39 2016 daemon.err snapclient[1158]: Got error callback: FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC diff --git a/client/decoder/flacDecoder.h b/client/decoder/flacDecoder.h index 4106ebb4..2896987e 100644 --- a/client/decoder/flacDecoder.h +++ b/client/decoder/flacDecoder.h @@ -21,6 +21,11 @@ #include "decoder.h" +#include +#include +#include + + struct CacheInfo { @@ -50,6 +55,7 @@ public: virtual SampleFormat setHeader(msg::CodecHeader* chunk); CacheInfo cacheInfo_; + std::unique_ptr lastError_; };