mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-25 06:56:15 +02:00
fixed crash when switching streams
This commit is contained in:
parent
060e52aeee
commit
3a5af32d98
5 changed files with 14 additions and 2 deletions
|
@ -94,14 +94,18 @@ void Controller::onMessageReceived(ClientConnection* connection, const msg::Base
|
|||
headerChunk_->deserialize(baseMessage, buffer);
|
||||
|
||||
logO << "Codec: " << headerChunk_->codec << "\n";
|
||||
decoder_.reset(nullptr);
|
||||
if (headerChunk_->codec == "pcm")
|
||||
decoder_.reset(new PcmDecoder());
|
||||
#ifndef ANDROID
|
||||
if (headerChunk_->codec == "ogg")
|
||||
else if (headerChunk_->codec == "ogg")
|
||||
decoder_.reset(new OggDecoder());
|
||||
#endif
|
||||
else if (headerChunk_->codec == "flac")
|
||||
decoder_.reset(new FlacDecoder());
|
||||
else
|
||||
throw SnapException("codec not supported: \"" + headerChunk_->codec + "\"");
|
||||
|
||||
sampleFormat_ = decoder_->setHeader(headerChunk_.get());
|
||||
logO << "sample rate: " << sampleFormat_.rate << "Hz\n";
|
||||
logO << "bits/sample: " << sampleFormat_.bits << "\n";
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#ifndef DECODER_H
|
||||
#define DECODER_H
|
||||
#include <mutex>
|
||||
#include "message/pcmChunk.h"
|
||||
#include "message/header.h"
|
||||
#include "message/sampleFormat.h"
|
||||
|
@ -30,6 +31,9 @@ public:
|
|||
virtual ~Decoder() {};
|
||||
virtual bool decode(msg::PcmChunk* chunk) = 0;
|
||||
virtual SampleFormat setHeader(msg::Header* chunk) = 0;
|
||||
|
||||
protected:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ FlacDecoder::FlacDecoder() : Decoder()
|
|||
|
||||
FlacDecoder::~FlacDecoder()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
delete flacChunk;
|
||||
delete decoder;
|
||||
}
|
||||
|
@ -57,6 +58,7 @@ FlacDecoder::~FlacDecoder()
|
|||
|
||||
bool FlacDecoder::decode(msg::PcmChunk* chunk)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
cacheInfo_.reset();
|
||||
pcmChunk = chunk;
|
||||
flacChunk->payload = (char*)realloc(flacChunk->payload, chunk->payloadSize);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "decoder.h"
|
||||
|
||||
|
||||
struct CacheInfo
|
||||
{
|
||||
CacheInfo() : sampleRate_(0)
|
||||
|
|
|
@ -39,6 +39,7 @@ OggDecoder::OggDecoder() : Decoder(), buffer(NULL), bytes(0)
|
|||
|
||||
OggDecoder::~OggDecoder()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
free(convbuffer);
|
||||
vorbis_block_clear(&vb);
|
||||
vorbis_dsp_clear(&vd);
|
||||
|
@ -51,7 +52,7 @@ OggDecoder::~OggDecoder()
|
|||
|
||||
bool OggDecoder::decode(msg::PcmChunk* chunk)
|
||||
{
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
/* grab some data at the head of the stream. We want the first page
|
||||
(which is guaranteed to be small and only contain the Vorbis
|
||||
stream initial header) We need the first page to get the stream
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue