mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-04 03:41:43 +02:00
made SampleFormat not inherit from BaseMessage
This commit is contained in:
parent
eed7f287fb
commit
c4094a2175
18 changed files with 25 additions and 63 deletions
|
@ -146,10 +146,6 @@ void Controller::worker()
|
||||||
while (active_ && !(serverSettings = clientConnection_->sendReq<msg::ServerSettings>(&requestMsg)));
|
while (active_ && !(serverSettings = clientConnection_->sendReq<msg::ServerSettings>(&requestMsg)));
|
||||||
logO << "ServerSettings - buffer: " << serverSettings->bufferMs << ", latency: " << serverSettings->latency << ", volume: " << serverSettings->volume << ", muted: " << serverSettings->muted << "\n";
|
logO << "ServerSettings - buffer: " << serverSettings->bufferMs << ", latency: " << serverSettings->latency << ", volume: " << serverSettings->volume << ", muted: " << serverSettings->muted << "\n";
|
||||||
|
|
||||||
// requestMsg.request = kSampleFormat;
|
|
||||||
// while (active_ && !(sampleFormat_ = clientConnection_->sendReq<msg::SampleFormat>(&requestMsg)));
|
|
||||||
// logO << "SampleFormat rate: " << sampleFormat_->rate << ", bits: " << sampleFormat_->bits << ", channels: " << sampleFormat_->channels << "\n";
|
|
||||||
|
|
||||||
requestMsg.request = kHeader;
|
requestMsg.request = kHeader;
|
||||||
shared_ptr<msg::Header> headerChunk(NULL);
|
shared_ptr<msg::Header> headerChunk(NULL);
|
||||||
while (active_ && !(headerChunk = clientConnection_->sendReq<msg::Header>(&requestMsg)));
|
while (active_ && !(headerChunk = clientConnection_->sendReq<msg::Header>(&requestMsg)));
|
||||||
|
|
|
@ -62,7 +62,7 @@ private:
|
||||||
ClientConnection* clientConnection_;
|
ClientConnection* clientConnection_;
|
||||||
Stream* stream_;
|
Stream* stream_;
|
||||||
std::string ip_;
|
std::string ip_;
|
||||||
msg::SampleFormat sampleFormat_;
|
SampleFormat sampleFormat_;
|
||||||
Decoder* decoder_;
|
Decoder* decoder_;
|
||||||
PcmDevice pcmDevice_;
|
PcmDevice pcmDevice_;
|
||||||
size_t latency_;
|
size_t latency_;
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
Decoder() {};
|
Decoder() {};
|
||||||
virtual ~Decoder() {};
|
virtual ~Decoder() {};
|
||||||
virtual bool decode(msg::PcmChunk* chunk) = 0;
|
virtual bool decode(msg::PcmChunk* chunk) = 0;
|
||||||
virtual msg::SampleFormat setHeader(msg::Header* chunk) = 0;
|
virtual SampleFormat setHeader(msg::Header* chunk) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecod
|
||||||
static msg::Header* flacHeader = NULL;
|
static msg::Header* flacHeader = NULL;
|
||||||
static msg::PcmChunk* flacChunk = NULL;
|
static msg::PcmChunk* flacChunk = NULL;
|
||||||
static msg::PcmChunk* pcmChunk = NULL;
|
static msg::PcmChunk* pcmChunk = NULL;
|
||||||
static msg::SampleFormat sampleFormat;
|
static SampleFormat sampleFormat;
|
||||||
static FLAC__StreamDecoder *decoder = NULL;
|
static FLAC__StreamDecoder *decoder = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ bool FlacDecoder::decode(msg::PcmChunk* chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
msg::SampleFormat FlacDecoder::setHeader(msg::Header* chunk)
|
SampleFormat FlacDecoder::setHeader(msg::Header* chunk)
|
||||||
{
|
{
|
||||||
flacHeader = chunk;
|
flacHeader = chunk;
|
||||||
FLAC__StreamDecoderInitStatus init_status;
|
FLAC__StreamDecoderInitStatus init_status;
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
FlacDecoder();
|
FlacDecoder();
|
||||||
virtual ~FlacDecoder();
|
virtual ~FlacDecoder();
|
||||||
virtual bool decode(msg::PcmChunk* chunk);
|
virtual bool decode(msg::PcmChunk* chunk);
|
||||||
virtual msg::SampleFormat setHeader(msg::Header* chunk);
|
virtual SampleFormat setHeader(msg::Header* chunk);
|
||||||
|
|
||||||
CacheInfo cacheInfo_;
|
CacheInfo cacheInfo_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -143,7 +143,7 @@ bool OggDecoder::decode(msg::PcmChunk* chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
msg::SampleFormat OggDecoder::setHeader(msg::Header* chunk)
|
SampleFormat OggDecoder::setHeader(msg::Header* chunk)
|
||||||
{
|
{
|
||||||
bytes = chunk->payloadSize;
|
bytes = chunk->payloadSize;
|
||||||
buffer=ogg_sync_buffer(&oy, bytes);
|
buffer=ogg_sync_buffer(&oy, bytes);
|
||||||
|
@ -217,7 +217,7 @@ msg::SampleFormat OggDecoder::setHeader(msg::Header* chunk)
|
||||||
/// in parallel. We could init multiple vorbis_block structures for vd here
|
/// in parallel. We could init multiple vorbis_block structures for vd here
|
||||||
|
|
||||||
|
|
||||||
msg::SampleFormat sampleFormat(vi.rate, 16, vi.channels);
|
SampleFormat sampleFormat(vi.rate, 16, vi.channels);
|
||||||
return sampleFormat;
|
return sampleFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
OggDecoder();
|
OggDecoder();
|
||||||
virtual ~OggDecoder();
|
virtual ~OggDecoder();
|
||||||
virtual bool decode(msg::PcmChunk* chunk);
|
virtual bool decode(msg::PcmChunk* chunk);
|
||||||
virtual msg::SampleFormat setHeader(msg::Header* chunk);
|
virtual SampleFormat setHeader(msg::Header* chunk);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool decodePayload(msg::PcmChunk* chunk);
|
bool decodePayload(msg::PcmChunk* chunk);
|
||||||
|
|
|
@ -63,7 +63,7 @@ bool PcmDecoder::decode(msg::PcmChunk* chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
msg::SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
||||||
{
|
{
|
||||||
if (chunk->payloadSize < 44)
|
if (chunk->payloadSize < 44)
|
||||||
throw SnapException("PCM header too small");
|
throw SnapException("PCM header too small");
|
||||||
|
@ -112,7 +112,7 @@ msg::SampleFormat PcmDecoder::setHeader(msg::Header* chunk)
|
||||||
if (chunk_fmt.sample_rate == 0)
|
if (chunk_fmt.sample_rate == 0)
|
||||||
throw SnapException("Sample format not found");
|
throw SnapException("Sample format not found");
|
||||||
|
|
||||||
msg::SampleFormat sampleFormat(
|
SampleFormat sampleFormat(
|
||||||
chunk_fmt.sample_rate,
|
chunk_fmt.sample_rate,
|
||||||
chunk_fmt.bits_per_sample,
|
chunk_fmt.bits_per_sample,
|
||||||
chunk_fmt.num_channels);
|
chunk_fmt.num_channels);
|
||||||
|
|
|
@ -26,7 +26,7 @@ class PcmDecoder : public Decoder
|
||||||
public:
|
public:
|
||||||
PcmDecoder();
|
PcmDecoder();
|
||||||
virtual bool decode(msg::PcmChunk* chunk);
|
virtual bool decode(msg::PcmChunk* chunk);
|
||||||
virtual msg::SampleFormat setHeader(msg::Header* chunk);
|
virtual SampleFormat setHeader(msg::Header* chunk);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ void AlsaPlayer::initAlsa()
|
||||||
snd_pcm_hw_params_t *params;
|
snd_pcm_hw_params_t *params;
|
||||||
int buff_size;
|
int buff_size;
|
||||||
|
|
||||||
const msg::SampleFormat& format = stream_->getFormat();
|
const SampleFormat& format = stream_->getFormat();
|
||||||
rate = format.rate;
|
rate = format.rate;
|
||||||
channels = format.channels;
|
channels = format.channels;
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ void OpenslPlayer::initOpensl()
|
||||||
if (active_)
|
if (active_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const msg::SampleFormat& format = stream_->getFormat();
|
const SampleFormat& format = stream_->getFormat();
|
||||||
|
|
||||||
frames_ = 960;//rate / 50; // => 50ms
|
frames_ = 960;//rate / 50; // => 50ms
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ void Player::adjustVolume(char* buffer, size_t frames)
|
||||||
if (muted_)
|
if (muted_)
|
||||||
volume = 0.;
|
volume = 0.;
|
||||||
|
|
||||||
const msg::SampleFormat& sampleFormat = stream_->getFormat();
|
const SampleFormat& sampleFormat = stream_->getFormat();
|
||||||
|
|
||||||
if (volume < 1.0)
|
if (volume < 1.0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,7 @@ using namespace std;
|
||||||
namespace cs = chronos;
|
namespace cs = chronos;
|
||||||
|
|
||||||
|
|
||||||
Stream::Stream(const msg::SampleFormat& sampleFormat) : format_(sampleFormat), sleep_(0), median_(0), shortMedian_(0), lastUpdate_(0), playedFrames_(0), bufferMs_(cs::msec(500))
|
Stream::Stream(const SampleFormat& sampleFormat) : format_(sampleFormat), sleep_(0), median_(0), shortMedian_(0), lastUpdate_(0), playedFrames_(0), bufferMs_(cs::msec(500))
|
||||||
{
|
{
|
||||||
buffer_.setSize(500);
|
buffer_.setSize(500);
|
||||||
shortBuffer_.setSize(100);
|
shortBuffer_.setSize(100);
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
class Stream
|
class Stream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Stream(const msg::SampleFormat& format);
|
Stream(const SampleFormat& format);
|
||||||
|
|
||||||
/// Adds PCM data to the queue
|
/// Adds PCM data to the queue
|
||||||
void addChunk(msg::PcmChunk* chunk);
|
void addChunk(msg::PcmChunk* chunk);
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
/// "Server buffer": playout latency, e.g. 1000ms
|
/// "Server buffer": playout latency, e.g. 1000ms
|
||||||
void setBufferLen(size_t bufferLenMs);
|
void setBufferLen(size_t bufferLenMs);
|
||||||
|
|
||||||
const msg::SampleFormat& getFormat() const
|
const SampleFormat& getFormat() const
|
||||||
{
|
{
|
||||||
return format_;
|
return format_;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ private:
|
||||||
void resetBuffers();
|
void resetBuffers();
|
||||||
void setRealSampleRate(double sampleRate);
|
void setRealSampleRate(double sampleRate);
|
||||||
|
|
||||||
msg::SampleFormat format_;
|
SampleFormat format_;
|
||||||
|
|
||||||
long lastTick_;
|
long lastTick_;
|
||||||
chronos::usec sleep_;
|
chronos::usec sleep_;
|
||||||
|
|
|
@ -51,7 +51,7 @@ enum message_type
|
||||||
kBase = 0,
|
kBase = 0,
|
||||||
kHeader = 1,
|
kHeader = 1,
|
||||||
kWireChunk = 2,
|
kWireChunk = 2,
|
||||||
kSampleFormat = 3,
|
// kSampleFormat = 3,
|
||||||
kServerSettings = 4,
|
kServerSettings = 4,
|
||||||
kTime = 5,
|
kTime = 5,
|
||||||
kRequest = 6,
|
kRequest = 6,
|
||||||
|
|
|
@ -28,21 +28,19 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace msg
|
|
||||||
{
|
|
||||||
|
|
||||||
SampleFormat::SampleFormat() : BaseMessage(message_type::kSampleFormat)
|
SampleFormat::SampleFormat()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SampleFormat::SampleFormat(const std::string& format) : BaseMessage(message_type::kSampleFormat)
|
SampleFormat::SampleFormat(const std::string& format)
|
||||||
{
|
{
|
||||||
setFormat(format);
|
setFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SampleFormat::SampleFormat(uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount) : BaseMessage(message_type::kSampleFormat)
|
SampleFormat::SampleFormat(uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount)
|
||||||
{
|
{
|
||||||
setFormat(sampleRate, bitsPerSample, channelCount);
|
setFormat(sampleRate, bitsPerSample, channelCount);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +79,4 @@ void SampleFormat::setFormat(uint32_t rate, uint16_t bits, uint16_t channels)
|
||||||
// logD << "SampleFormat: " << rate << ":" << bits << ":" << channels << "\n";
|
// logD << "SampleFormat: " << rate << ":" << bits << ":" << channels << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,7 @@
|
||||||
#define SAMPLE_FORMAT_H
|
#define SAMPLE_FORMAT_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "message.h"
|
|
||||||
|
|
||||||
namespace msg
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sample and frame as defined in alsa:
|
* sample and frame as defined in alsa:
|
||||||
|
@ -36,7 +33,7 @@ namespace msg
|
||||||
* To sustain 2x 44.1 KHz analog rate - the system must be capable of data transfer rate, in Bytes/sec:
|
* To sustain 2x 44.1 KHz analog rate - the system must be capable of data transfer rate, in Bytes/sec:
|
||||||
* Bps_rate = (num_channels) * (1 sample in bytes) * (analog_rate) = (1 frame) * (analog_rate) = ( 2 channels ) * (2 bytes/sample) * (44100 samples/sec) = 2*2*44100 = 176400 Bytes/sec (link to formula img)
|
* Bps_rate = (num_channels) * (1 sample in bytes) * (analog_rate) = (1 frame) * (analog_rate) = ( 2 channels ) * (2 bytes/sample) * (44100 samples/sec) = 2*2*44100 = 176400 Bytes/sec (link to formula img)
|
||||||
*/
|
*/
|
||||||
class SampleFormat : public BaseMessage
|
class SampleFormat
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SampleFormat();
|
SampleFormat();
|
||||||
|
@ -72,34 +69,8 @@ public:
|
||||||
{
|
{
|
||||||
return (double)rate/1000000000.;
|
return (double)rate/1000000000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void read(std::istream& stream)
|
|
||||||
{
|
|
||||||
stream.read(reinterpret_cast<char *>(&rate), sizeof(uint32_t));
|
|
||||||
stream.read(reinterpret_cast<char *>(&bits), sizeof(uint16_t));
|
|
||||||
stream.read(reinterpret_cast<char *>(&channels), sizeof(uint16_t));
|
|
||||||
stream.read(reinterpret_cast<char *>(&sampleSize), sizeof(uint16_t));
|
|
||||||
stream.read(reinterpret_cast<char *>(&frameSize), sizeof(uint16_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual uint32_t getSize() const
|
|
||||||
{
|
|
||||||
return sizeof(int32_t) + 4*sizeof(int16_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void doserialize(std::ostream& stream) const
|
|
||||||
{
|
|
||||||
stream.write(reinterpret_cast<const char *>(&rate), sizeof(uint32_t));
|
|
||||||
stream.write(reinterpret_cast<const char *>(&bits), sizeof(uint16_t));
|
|
||||||
stream.write(reinterpret_cast<const char *>(&channels), sizeof(uint16_t));
|
|
||||||
stream.write(reinterpret_cast<const char *>(&sampleSize), sizeof(uint16_t));
|
|
||||||
stream.write(reinterpret_cast<const char *>(&frameSize), sizeof(uint16_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The listener will receive the encoded stream
|
/// The listener will receive the encoded stream
|
||||||
virtual void init(EncoderListener* listener, const msg::SampleFormat& format)
|
virtual void init(EncoderListener* listener, const SampleFormat& format)
|
||||||
{
|
{
|
||||||
if (codecOptions_ == "")
|
if (codecOptions_ == "")
|
||||||
codecOptions_ = getDefaultOptions();
|
codecOptions_ = getDefaultOptions();
|
||||||
|
@ -94,7 +94,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual void initEncoder() = 0;
|
virtual void initEncoder() = 0;
|
||||||
|
|
||||||
msg::SampleFormat sampleFormat_;
|
SampleFormat sampleFormat_;
|
||||||
msg::Header* headerChunk_;
|
msg::Header* headerChunk_;
|
||||||
EncoderListener* listener_;
|
EncoderListener* listener_;
|
||||||
std::string codecOptions_;
|
std::string codecOptions_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue