fix dry out time

This commit is contained in:
badaix 2017-10-16 22:07:26 +02:00
parent 1a51833f0e
commit 27baee7994
2 changed files with 14 additions and 12 deletions

View file

@ -72,8 +72,8 @@ void PipeStream::worker()
chronos::systemtimeofday(&tvChunk); chronos::systemtimeofday(&tvChunk);
tvEncodedChunk_ = tvChunk; tvEncodedChunk_ = tvChunk;
long nextTick = chronos::getTickCount(); long nextTick = chronos::getTickCount();
int idleFrames = 0; int idleBytes = 0;
int maxIdleFrames = sampleFormat_.rate*dryoutMs_/1000; int maxIdleBytes = sampleFormat_.rate*sampleFormat_.frameSize*dryoutMs_/1000;
try try
{ {
if (fd_ == -1) if (fd_ == -1)
@ -88,10 +88,10 @@ void PipeStream::worker()
do do
{ {
int count = read(fd_, chunk->payload + len, toRead - len); int count = read(fd_, chunk->payload + len, toRead - len);
if (count < 0 && idleFrames < maxIdleFrames) if (count < 0 && idleBytes < maxIdleBytes)
{ {
memset(chunk->payload + len, 0, toRead - len); memset(chunk->payload + len, 0, toRead - len);
idleFrames += toRead - len; idleBytes += toRead - len;
len += toRead - len; len += toRead - len;
continue; continue;
} }
@ -103,9 +103,10 @@ void PipeStream::worker()
} }
else if (count == 0) else if (count == 0)
throw SnapException("end of file"); throw SnapException("end of file");
else { else
{
len += count; len += count;
idleFrames = 0; idleBytes = 0;
} }
} }
while ((len < toRead) && active_); while ((len < toRead) && active_);

View file

@ -158,8 +158,8 @@ void ProcessStream::worker()
chronos::systemtimeofday(&tvChunk); chronos::systemtimeofday(&tvChunk);
tvEncodedChunk_ = tvChunk; tvEncodedChunk_ = tvChunk;
long nextTick = chronos::getTickCount(); long nextTick = chronos::getTickCount();
int idleFrames = 0; int idleBytes = 0;
int maxIdleFrames = sampleFormat_.rate*dryoutMs_/1000; int maxIdleBytes = sampleFormat_.rate*sampleFormat_.frameSize*dryoutMs_/1000;
try try
{ {
while (active_) while (active_)
@ -171,10 +171,10 @@ void ProcessStream::worker()
do do
{ {
int count = read(process_->getStdout(), chunk->payload + len, toRead - len); int count = read(process_->getStdout(), chunk->payload + len, toRead - len);
if (count < 0 && idleFrames < maxIdleFrames) if (count < 0 && idleBytes < maxIdleBytes)
{ {
memset(chunk->payload + len, 0, toRead - len); memset(chunk->payload + len, 0, toRead - len);
idleFrames += toRead - len; idleBytes += toRead - len;
len += toRead - len; len += toRead - len;
continue; continue;
} }
@ -186,9 +186,10 @@ void ProcessStream::worker()
} }
else if (count == 0) else if (count == 0)
throw SnapException("end of file"); throw SnapException("end of file");
else { else
{
len += count; len += count;
idleFrames = 0; idleBytes = 0;
} }
} }
while ((len < toRead) && active_); while ((len < toRead) && active_);