Commit af864e98 authored by Christopher Mueller's avatar Christopher Mueller Committed by Hugo Beauzée-Luyssen

dash: fixed buffer precision bug

Signed-off-by: default avatarChristopher Mueller <christopher.mueller@itec.aau.at>
Signed-off-by: default avatarHugo Beauzée-Luyssen <beauze.h@gmail.com>
parent df63a73a
...@@ -117,14 +117,14 @@ int BlockBuffer::get (void *p_data, unsigned int len) ...@@ -117,14 +117,14 @@ int BlockBuffer::get (void *p_data, unsigned int len)
int ret = len > this->sizeBytes ? this->sizeBytes : len; int ret = len > this->sizeBytes ? this->sizeBytes : len;
this->reduceBufferMilliSec(ret);
if(p_data == NULL) if(p_data == NULL)
block_SkipBytes(&this->buffer, ret); block_SkipBytes(&this->buffer, ret);
else else
block_GetBytes(&this->buffer, (uint8_t *)p_data, ret); block_GetBytes(&this->buffer, (uint8_t *)p_data, ret);
block_BytestreamFlush(&this->buffer); block_BytestreamFlush(&this->buffer);
this->updateBufferSize(ret);
this->notify(); this->notify();
vlc_cond_signal(&this->empty); vlc_cond_signal(&this->empty);
...@@ -178,47 +178,19 @@ void BlockBuffer::notify () ...@@ -178,47 +178,19 @@ void BlockBuffer::notify ()
for(size_t i = 0; i < this->bufferObservers.size(); i++) for(size_t i = 0; i < this->bufferObservers.size(); i++)
this->bufferObservers.at(i)->bufferLevelChanged(this->sizeMicroSec, ((float)this->sizeMicroSec / this->capacityMicroSec) * 100); this->bufferObservers.at(i)->bufferLevelChanged(this->sizeMicroSec, ((float)this->sizeMicroSec / this->capacityMicroSec) * 100);
} }
void BlockBuffer::reduceBufferMilliSec (size_t bytes) void BlockBuffer::updateBufferSize (size_t bytes)
{ {
size_t pos = 0;
float microsec = 0;
block_t *block = this->buffer.p_block; block_t *block = this->buffer.p_block;
if(bytes < (block->i_buffer - this->buffer.i_offset)) this->sizeMicroSec = 0;
{
pos = bytes;
microsec = ((float)block->i_length / block->i_buffer) * bytes;
}
else
{
pos = block->i_buffer - this->buffer.i_offset;
microsec = ((float)block->i_length / block->i_buffer) * (block->i_buffer - this->buffer.i_offset);
}
while(pos < bytes) while(block)
{ {
this->sizeMicroSec += block->i_length;
block = block->p_next; block = block->p_next;
if((bytes - pos) < (block->i_buffer - this->buffer.i_offset))
{
pos = bytes;
microsec += ((float)block->i_length / block->i_buffer) * (bytes - pos);
}
else
{
pos += block->i_buffer;
microsec += block->i_length;
}
} }
this->sizeMicroSec -= microsec; this->sizeBytes -= bytes;
this->sizeBytes -= bytes;
if(this->sizeMicroSec < 0)
this->sizeMicroSec = 0;
if(this->sizeBytes == 0)
this->sizeMicroSec = 0;
} }
mtime_t BlockBuffer::size () mtime_t BlockBuffer::size ()
{ {
......
...@@ -70,7 +70,7 @@ namespace dash ...@@ -70,7 +70,7 @@ namespace dash
std::vector<IBufferObserver *> bufferObservers; std::vector<IBufferObserver *> bufferObservers;
void reduceBufferMilliSec(size_t bytes); void updateBufferSize(size_t bytes);
}; };
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment