mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-28 13:58:48 +02:00
added start function to wireChunk
This commit is contained in:
parent
d51cb125fc
commit
063ed462f9
3 changed files with 24 additions and 19 deletions
|
@ -27,17 +27,17 @@ using namespace std;
|
|||
namespace msg
|
||||
{
|
||||
|
||||
PcmChunk::PcmChunk(const SampleFormat& sampleFormat, size_t ms) : WireChunk(sampleFormat.rate*sampleFormat.frameSize*ms / 1000), format(sampleFormat), idx(0)
|
||||
PcmChunk::PcmChunk(const SampleFormat& sampleFormat, size_t ms) : WireChunk(sampleFormat.rate*sampleFormat.frameSize*ms / 1000), format(sampleFormat), idx_(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PcmChunk::PcmChunk(const PcmChunk& pcmChunk) : WireChunk(pcmChunk), format(pcmChunk.format), idx(0)
|
||||
PcmChunk::PcmChunk(const PcmChunk& pcmChunk) : WireChunk(pcmChunk), format(pcmChunk.format), idx_(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PcmChunk::PcmChunk() : WireChunk(), idx(0)
|
||||
PcmChunk::PcmChunk() : WireChunk(), idx_(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -50,12 +50,12 @@ PcmChunk::~PcmChunk()
|
|||
|
||||
int PcmChunk::seek(int frames)
|
||||
{
|
||||
idx += frames;
|
||||
if (idx > getFrameCount())
|
||||
idx = getFrameCount();
|
||||
if (idx < 0)
|
||||
idx = 0;
|
||||
return idx;
|
||||
idx_ += frames;
|
||||
if (idx_ > getFrameCount())
|
||||
idx_ = getFrameCount();
|
||||
if (idx_ < 0)
|
||||
idx_ = 0;
|
||||
return idx_;
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,14 +63,14 @@ int PcmChunk::readFrames(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;
|
||||
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);
|
||||
memcpy((char*)outputBuffer, (char*)(payload) + format.frameSize*idx_, format.frameSize*result);
|
||||
|
||||
idx += result;
|
||||
idx_ += result;
|
||||
//logd << ", new idx: " << idx << ", result: " << result << ", wireChunk->length: " << wireChunk->length << ", format.frameSize: " << format.frameSize << "\n";//std::endl;
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "message.h"
|
||||
#include "wireChunk.h"
|
||||
#include "sampleFormat.h"
|
||||
#include "common/timeDefs.h"
|
||||
|
||||
|
||||
namespace msg
|
||||
|
@ -45,12 +44,12 @@ public:
|
|||
int readFrames(void* outputBuffer, size_t frameCount);
|
||||
int seek(int frames);
|
||||
|
||||
inline chronos::time_point_hrc start() const
|
||||
virtual chronos::time_point_hrc start() const
|
||||
{
|
||||
return chronos::time_point_hrc(
|
||||
chronos::sec(timestamp.sec) +
|
||||
chronos::usec(timestamp.usec) +
|
||||
chronos::usec((chronos::usec::rep)(1000000. * ((double)idx / (double)format.rate)))
|
||||
chronos::usec((chronos::usec::rep)(1000000. * ((double)idx_ / (double)format.rate)))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -68,12 +67,12 @@ public:
|
|||
template<typename T>
|
||||
inline T durationLeft() const
|
||||
{
|
||||
return std::chrono::duration_cast<T>(chronos::nsec((chronos::nsec::rep)(1000000 * (getFrameCount() - idx) / format.msRate())));
|
||||
return std::chrono::duration_cast<T>(chronos::nsec((chronos::nsec::rep)(1000000 * (getFrameCount() - idx_) / format.msRate())));
|
||||
}
|
||||
|
||||
inline bool isEndOfChunk() const
|
||||
{
|
||||
return idx >= getFrameCount();
|
||||
return idx_ >= getFrameCount();
|
||||
}
|
||||
|
||||
inline size_t getFrameCount() const
|
||||
|
@ -89,7 +88,7 @@ public:
|
|||
SampleFormat format;
|
||||
|
||||
private:
|
||||
uint32_t idx;
|
||||
uint32_t idx_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <streambuf>
|
||||
#include <vector>
|
||||
#include "message.h"
|
||||
#include "common/timeDefs.h"
|
||||
|
||||
|
||||
namespace msg
|
||||
|
@ -68,6 +69,11 @@ public:
|
|||
return sizeof(int32_t) + sizeof(int32_t) + sizeof(uint32_t) + payloadSize;
|
||||
}
|
||||
|
||||
virtual chronos::time_point_hrc start() const
|
||||
{
|
||||
return chronos::time_point_hrc(chronos::sec(timestamp.sec) + chronos::usec(timestamp.usec));
|
||||
}
|
||||
|
||||
tv timestamp;
|
||||
uint32_t payloadSize;
|
||||
char* payload;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue