mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-12 08:36:43 +02:00
ogg chunk len
git-svn-id: svn://elaine/murooma/trunk@225 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
77856ac910
commit
192aa6fd9e
6 changed files with 19 additions and 12 deletions
|
@ -7,7 +7,7 @@ class Encoder
|
|||
{
|
||||
public:
|
||||
Encoder();
|
||||
virtual bool encode(Chunk* chunk) = 0;
|
||||
virtual double encode(Chunk* chunk) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ using namespace std;
|
|||
OggEncoder::OggEncoder()
|
||||
{
|
||||
init();
|
||||
lastGranulepos = -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,9 +23,9 @@ bool OggEncoder::getHeader(Chunk* chunk)
|
|||
}
|
||||
|
||||
|
||||
bool OggEncoder::encode(Chunk* chunk)
|
||||
double OggEncoder::encode(Chunk* chunk)
|
||||
{
|
||||
bool res = false;
|
||||
double res = 0;
|
||||
WireChunk* wireChunk = chunk->wireChunk;
|
||||
if (tv_sec == 0)
|
||||
{
|
||||
|
@ -70,7 +71,6 @@ bool OggEncoder::encode(Chunk* chunk)
|
|||
if (result == 0)
|
||||
break;
|
||||
res = true;
|
||||
// cout << "pcm: " << wireChunk->length << ", header len: " << og.header_len << ", body len: " << og.body_len << endl;
|
||||
|
||||
size_t nextLen = pos + og.header_len + og.body_len;
|
||||
if (wireChunk->length < nextLen)
|
||||
|
@ -85,10 +85,14 @@ bool OggEncoder::encode(Chunk* chunk)
|
|||
}
|
||||
if (res)
|
||||
{
|
||||
if (lastGranulepos == -1)
|
||||
res = os.granulepos;
|
||||
else
|
||||
res = os.granulepos - lastGranulepos;
|
||||
res /= 48.;
|
||||
lastGranulepos = os.granulepos;
|
||||
wireChunk->payload = (char*)realloc(wireChunk->payload, pos);
|
||||
wireChunk->length = pos;
|
||||
// wireChunk->tv_sec = tv_sec;
|
||||
// wireChunk->tv_usec = tv_usec;
|
||||
tv_sec = 0;
|
||||
tv_usec = 0;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ class OggEncoder
|
|||
{
|
||||
public:
|
||||
OggEncoder();
|
||||
virtual bool encode(Chunk* chunk);
|
||||
virtual double encode(Chunk* chunk);
|
||||
virtual bool getHeader(Chunk* chunk);
|
||||
|
||||
private:
|
||||
|
@ -30,6 +30,8 @@ private:
|
|||
ogg_packet header_comm;
|
||||
ogg_packet header_code;
|
||||
|
||||
ogg_int64_t lastGranulepos;
|
||||
|
||||
int eos=0,ret;
|
||||
int i, founddata;
|
||||
char* oggHeader;
|
||||
|
|
|
@ -5,13 +5,13 @@ PcmEncoder::PcmEncoder()
|
|||
}
|
||||
|
||||
|
||||
bool PcmEncoder::encode(Chunk* chunk)
|
||||
double PcmEncoder::encode(Chunk* chunk)
|
||||
{
|
||||
/* WireChunk* wireChunk = chunk->wireChunk;
|
||||
for (size_t n=0; n<wireChunk->length; ++n)
|
||||
wireChunk->payload[n] *= 1;
|
||||
*/
|
||||
return true;
|
||||
return chunk->getDuration();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class PcmEncoder
|
|||
{
|
||||
public:
|
||||
PcmEncoder();
|
||||
virtual bool encode(Chunk* chunk);
|
||||
virtual double encode(Chunk* chunk);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -307,11 +307,12 @@ size_t duration = 50;
|
|||
|
||||
wireChunk->tv_sec = tvChunk.tv_sec;
|
||||
wireChunk->tv_usec = tvChunk.tv_usec;
|
||||
if (encoder.encode(chunk.get()))
|
||||
double chunkDuration = encoder.encode(chunk.get());
|
||||
if (chunkDuration > 0)
|
||||
server->send(chunk);
|
||||
//cout << wireChunk->tv_sec << ", " << wireChunk->tv_usec / 1000 << "\n";
|
||||
// addUs(tvChunk, 1000*chunk->getDuration());
|
||||
addMs(tvChunk, duration);
|
||||
addUs(tvChunk, chunkDuration * 1000);
|
||||
nextTick += duration;
|
||||
long currentTick = getTickCount();
|
||||
if (nextTick > currentTick)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue