error handling

This commit is contained in:
badaix 2016-11-13 15:58:02 +01:00
parent 3fe88b7440
commit 943df9bb03
2 changed files with 26 additions and 3 deletions

View file

@ -19,7 +19,6 @@
#include <iostream>
#include <cstring>
#include <cmath>
#include <FLAC/stream_decoder.h>
#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<FlacDecoder*>(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<FlacDecoder*>(client_data)->lastError_ = std::unique_ptr<FLAC__StreamDecoderErrorStatus>(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

View file

@ -21,6 +21,11 @@
#include "decoder.h"
#include <FLAC/stream_decoder.h>
#include <atomic>
#include <memory>
struct CacheInfo
{
@ -50,6 +55,7 @@ public:
virtual SampleFormat setHeader(msg::CodecHeader* chunk);
CacheInfo cacheInfo_;
std::unique_ptr<FLAC__StreamDecoderErrorStatus> lastError_;
};