mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-16 10:36:17 +02:00
new messaging
git-svn-id: svn://elaine/murooma/trunk@229 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
c6ee0960fd
commit
a519d0f0dd
9 changed files with 96 additions and 62 deletions
73
common/message.cpp
Normal file
73
common/message.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "message.h"
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include "common/log.h"
|
||||
|
||||
|
||||
PcmChunk::PcmChunk(const SampleFormat& sampleFormat, size_t ms) : WireChunk(), format(sampleFormat), idx(0)
|
||||
{
|
||||
payloadSize = format.rate*format.frameSize*ms / 1000;
|
||||
payload = (char*)malloc(payloadSize);
|
||||
}
|
||||
|
||||
|
||||
PcmChunk::~PcmChunk()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool PcmChunk::isEndOfChunk() const
|
||||
{
|
||||
return idx >= getFrameCount();
|
||||
}
|
||||
|
||||
|
||||
double PcmChunk::getFrameCount() const
|
||||
{
|
||||
return (payloadSize / format.frameSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
double PcmChunk::getDuration() const
|
||||
{
|
||||
return getFrameCount() / format.msRate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
double PcmChunk::getTimeLeft() const
|
||||
{
|
||||
return (getFrameCount() - idx) / format.msRate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int PcmChunk::seek(int frames)
|
||||
{
|
||||
idx += frames;
|
||||
if (idx > getFrameCount())
|
||||
idx = getFrameCount();
|
||||
if (idx < 0)
|
||||
idx = 0;
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
int PcmChunk::read(void* outputBuffer, size_t frameCount)
|
||||
{
|
||||
//logd << "read: " << frameCount << ", total: " << (wireChunk->length / format.frameSize) << ", idx: " << idx;// << std::endl;
|
||||
int result = frameCount;
|
||||
if (idx + frameCount > (payloadSize / format.frameSize))
|
||||
result = (payloadSize / format.frameSize) - idx;
|
||||
|
||||
//logd << ", from: " << format.frameSize*idx << ", to: " << format.frameSize*idx + format.frameSize*result;
|
||||
if (outputBuffer != NULL)
|
||||
memcpy((char*)outputBuffer, (char*)(payload) + format.frameSize*idx, format.frameSize*result);
|
||||
|
||||
idx += result;
|
||||
//logd << ", new idx: " << idx << ", result: " << result << ", wireChunk->length: " << wireChunk->length << ", format.frameSize: " << format.frameSize << "\n";//std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue