[vlc-commits] demux: adaptive: compute latency from request
Francois Cartegnie
git at videolan.org
Thu Mar 4 15:38:27 UTC 2021
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Mar 3 14:00:31 2021 +0100| [e8c855dea80be91bba876e4c4709e4022e479f6e] | committer: Francois Cartegnie
demux: adaptive: compute latency from request
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e8c855dea80be91bba876e4c4709e4022e479f6e
---
modules/demux/adaptive/http/Chunk.cpp | 34 +++++++++++++++++++++-------------
modules/demux/adaptive/http/Chunk.h | 4 +++-
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index b138b26f9c..663d318aaa 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -210,23 +210,29 @@ block_t * HTTPChunkSource::read(size_t readsize)
return nullptr;
}
- vlc_tick_t time = vlc_tick_now();
ssize_t ret = connection->read(p_block->p_buffer, readsize);
- time = vlc_tick_now() - time;
if(ret < 0)
{
block_Release(p_block);
p_block = nullptr;
eof = true;
+ downloadEndTime = vlc_tick_now();
}
else
{
p_block->i_buffer = (size_t) ret;
consumed += p_block->i_buffer;
if((size_t)ret < readsize)
+ {
eof = true;
- if(ret && time && type == ChunkType::Segment)
- connManager->updateDownloadRate(sourceid, p_block->i_buffer, time);
+ downloadEndTime = vlc_tick_now();
+ }
+ if(ret && p_block->i_buffer &&
+ downloadEndTime > requestStartTime && type == ChunkType::Segment)
+ {
+ connManager->updateDownloadRate(sourceid, p_block->i_buffer,
+ downloadEndTime - requestStartTime);
+ }
}
return p_block;
@@ -251,6 +257,8 @@ bool HTTPChunkSource::prepare()
ConnectionParams connparams = params; /* can be changed on 301 */
+ requestStartTime = vlc_tick_now();
+
unsigned int i_redirects = 0;
while(i_redirects++ < HTTPConnection::MAX_REDIRECTS)
{
@@ -281,6 +289,7 @@ bool HTTPChunkSource::prepare()
from content length */
contentLength = connection->getContentLength();
prepared = true;
+ responseTime = vlc_tick_now();
return true;
}
@@ -303,7 +312,6 @@ HTTPChunkBufferedSource::HTTPChunkBufferedSource(const std::string& url, Abstrac
done = false;
eof = false;
held = false;
- downloadstart = 0;
}
HTTPChunkBufferedSource::~HTTPChunkBufferedSource()
@@ -374,7 +382,8 @@ void HTTPChunkBufferedSource::bufferize(size_t readsize)
{
size_t size;
vlc_tick_t time;
- } rate = {0,0};
+ vlc_tick_t latency;
+ } rate = {0,0,0};
ssize_t ret = connection->read(p_block->p_buffer, readsize);
if(ret <= 0)
@@ -383,9 +392,10 @@ void HTTPChunkBufferedSource::bufferize(size_t readsize)
p_block = nullptr;
mutex_locker locker {lock};
done = true;
+ downloadEndTime = vlc_tick_now();
rate.size = buffered + consumed;
- rate.time = vlc_tick_now() - downloadstart;
- downloadstart = 0;
+ rate.time = downloadEndTime - requestStartTime;
+ rate.latency = responseTime - requestStartTime;
}
else
{
@@ -396,9 +406,10 @@ void HTTPChunkBufferedSource::bufferize(size_t readsize)
if((size_t) ret < readsize)
{
done = true;
+ downloadEndTime = vlc_tick_now();
rate.size = buffered + consumed;
- rate.time = vlc_tick_now() - downloadstart;
- downloadstart = 0;
+ rate.time = downloadEndTime - requestStartTime;
+ rate.latency = responseTime - requestStartTime;
}
}
@@ -413,10 +424,7 @@ void HTTPChunkBufferedSource::bufferize(size_t readsize)
bool HTTPChunkBufferedSource::prepare()
{
if(!prepared)
- {
- downloadstart = vlc_tick_now();
return HTTPChunkSource::prepare();
- }
return true;
}
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index bcfa8dc468..c596c953fd 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -120,6 +120,9 @@ namespace adaptive
bool eof;
ID sourceid;
ChunkType type;
+ vlc_tick_t requestStartTime;
+ vlc_tick_t responseTime;
+ vlc_tick_t downloadEndTime;
private:
bool init(const std::string &);
@@ -151,7 +154,6 @@ namespace adaptive
size_t buffered; /* read cache size */
bool done;
bool eof;
- vlc_tick_t downloadstart;
vlc::threads::condition_variable avail;
bool held;
};
More information about the vlc-commits
mailing list