ogg chunk len

git-svn-id: svn://elaine/murooma/trunk@225 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-08-30 22:32:11 +00:00
parent 77856ac910
commit 192aa6fd9e
6 changed files with 19 additions and 12 deletions

View file

@ -7,7 +7,7 @@ class Encoder
{ {
public: public:
Encoder(); Encoder();
virtual bool encode(Chunk* chunk) = 0; virtual double encode(Chunk* chunk) = 0;
}; };

View file

@ -8,6 +8,7 @@ using namespace std;
OggEncoder::OggEncoder() OggEncoder::OggEncoder()
{ {
init(); 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; WireChunk* wireChunk = chunk->wireChunk;
if (tv_sec == 0) if (tv_sec == 0)
{ {
@ -70,7 +71,6 @@ bool OggEncoder::encode(Chunk* chunk)
if (result == 0) if (result == 0)
break; break;
res = true; 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; size_t nextLen = pos + og.header_len + og.body_len;
if (wireChunk->length < nextLen) if (wireChunk->length < nextLen)
@ -85,10 +85,14 @@ bool OggEncoder::encode(Chunk* chunk)
} }
if (res) 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->payload = (char*)realloc(wireChunk->payload, pos);
wireChunk->length = pos; wireChunk->length = pos;
// wireChunk->tv_sec = tv_sec;
// wireChunk->tv_usec = tv_usec;
tv_sec = 0; tv_sec = 0;
tv_usec = 0; tv_usec = 0;
} }

View file

@ -8,7 +8,7 @@ class OggEncoder
{ {
public: public:
OggEncoder(); OggEncoder();
virtual bool encode(Chunk* chunk); virtual double encode(Chunk* chunk);
virtual bool getHeader(Chunk* chunk); virtual bool getHeader(Chunk* chunk);
private: private:
@ -30,6 +30,8 @@ private:
ogg_packet header_comm; ogg_packet header_comm;
ogg_packet header_code; ogg_packet header_code;
ogg_int64_t lastGranulepos;
int eos=0,ret; int eos=0,ret;
int i, founddata; int i, founddata;
char* oggHeader; char* oggHeader;

View file

@ -5,13 +5,13 @@ PcmEncoder::PcmEncoder()
} }
bool PcmEncoder::encode(Chunk* chunk) double PcmEncoder::encode(Chunk* chunk)
{ {
/* WireChunk* wireChunk = chunk->wireChunk; /* WireChunk* wireChunk = chunk->wireChunk;
for (size_t n=0; n<wireChunk->length; ++n) for (size_t n=0; n<wireChunk->length; ++n)
wireChunk->payload[n] *= 1; wireChunk->payload[n] *= 1;
*/ */
return true; return chunk->getDuration();
} }

View file

@ -7,7 +7,7 @@ class PcmEncoder
{ {
public: public:
PcmEncoder(); PcmEncoder();
virtual bool encode(Chunk* chunk); virtual double encode(Chunk* chunk);
}; };

View file

@ -307,11 +307,12 @@ size_t duration = 50;
wireChunk->tv_sec = tvChunk.tv_sec; wireChunk->tv_sec = tvChunk.tv_sec;
wireChunk->tv_usec = tvChunk.tv_usec; wireChunk->tv_usec = tvChunk.tv_usec;
if (encoder.encode(chunk.get())) double chunkDuration = encoder.encode(chunk.get());
if (chunkDuration > 0)
server->send(chunk); server->send(chunk);
//cout << wireChunk->tv_sec << ", " << wireChunk->tv_usec / 1000 << "\n"; //cout << wireChunk->tv_sec << ", " << wireChunk->tv_usec / 1000 << "\n";
// addUs(tvChunk, 1000*chunk->getDuration()); // addUs(tvChunk, 1000*chunk->getDuration());
addMs(tvChunk, duration); addUs(tvChunk, chunkDuration * 1000);
nextTick += duration; nextTick += duration;
long currentTick = getTickCount(); long currentTick = getTickCount();
if (nextTick > currentTick) if (nextTick > currentTick)