在DASH中,自适应码率控制是关键部分,其最终目标是最大程度地提高视频码率,同时最大程度地减少重缓冲导致的卡顿事件,而对于吞吐量的预测在帮助动态选择合适的视频码率方面发挥着重要的作用。由于现实世界中的网络情况是不断波动的,因此我们通常需要对多个网络传输链路的实时吞吐量进行大规模测试并统计分析。尽管文献[1]中已经提出了一种基于网络请求轨迹的算法并实现了仿真,但作者并没有在实际的网络视频传输中将其实现,而且该算法只考虑了单个请求源的情况。
考虑到我们平台中的码率自适应算法也需要考虑传输带宽,我们提出了一种全新基于网络请求轨迹的联合带宽预测算法,适用于多个并行、异步请求同时存在的情况下预测实时带宽。
提出方法:
此处结合图例解释具体算法思路,其目的是获得一定时隙内的传输数据量及有效传输时间,然后相除得到该时隙的平均带宽:
初始化时设定一个index为当前时隙的结束时间,totalData为0,totalTime为时隙时长;
往前寻找离index时间最近的request(以request完成的时间为寻找目标),情况如(a)所示,totalData加上该request在该时隙内所传输的数据量,totalTime减去request完成后到时隙结束的时间(原因是这段时间没有参与传输),同时index更新为该request开始传输的时间;
-
再往前寻找下一个request:
若该request的开始时间大于index,如(b),则totalData加上该request在该时隙内所传输数据量,totalTime和index不变;
若该request开始时间小于index且完成时间大于index,如(c),则totalData加上该request在该时隙内所传输数据量,totalTime不变,index更新为该request开始传输的时间;
若该request完成时间小于index,如(d),则totalData加上该request在该时隙内所传输数据量,totalTime减去index和该request完成时间之差,index更新为该request开始传输的时间;
-
注意当寻找到该时隙的最后一个request时,还要注意以下两种情况:
若该request的开始时间大于时隙开始时间,则totalTime需要减去两者之差(原因是这段时间没有参与传输);
若该request的开始时间小于时隙开始时间,则totalData只需要加上该request在当前时隙中传输的数据量即可;
最终根据totalData和totalTime计算获得该时隙的平均传输带宽,然后经过一定的函数处理可用于预测未来带宽情况。
实现代码:
function computetotalThroughput() {
const precurTime = new Date().getTime(); // Get current time
const curTime = precurTime - $scope.requestLayBack;
let TotalDataInAnInterval = 0; // Byte
let TotalTimeInAnInterval = $scope.requestDuration; // ms
let requestListLength = $scope.requestList.length;
let requestListIndex = requestListLength - 1;
let requestTimeIndex = curTime;
while (requestListLength > 0 && requestListIndex >= 0) {
let requestFinishTime = $scope.requestList[requestListIndex]._tfinish.getTime();
let requestResponseTime = $scope.requestList[requestListIndex].tresponse.getTime();
if (requestFinishTime > curTime - $scope.requestDuration && requestResponseTime < curTime) {
// Accumulate the downloaded data (Byte)
let requestDownloadBytes = $scope.requestList[requestListIndex].trace.reduce((a, b) => a + b.b[0], 0);
if (requestResponseTime > curTime - $scope.requestDuration) {
if (requestFinishTime <= curTime) {
TotalDataInAnInterval += requestDownloadBytes;
} else {
TotalDataInAnInterval += ( requestDownloadBytes * ( ( curTime - requestResponseTime ) / ( requestFinishTime - requestResponseTime ) ) );
}
} else {
if (requestFinishTime <= curTime) {
TotalDataInAnInterval += ( requestDownloadBytes * ( ( requestFinishTime - (curTime - $scope.requestDuration) ) / ( requestFinishTime - requestResponseTime ) ) );
} else {
TotalDataInAnInterval += ( requestDownloadBytes * ( $scope.requestDuration / ( requestFinishTime - requestResponseTime ) ) );
}
}
// Subtract the free time (ms)
if (requestTimeIndex > requestFinishTime) {
TotalTimeInAnInterval -= (requestTimeIndex - requestFinishTime);
}
// More the time index forward
if (requestTimeIndex > requestResponseTime) {
requestTimeIndex = requestResponseTime;
}
}
requestListIndex--;
}
if (curTime - $scope.requestDuration < requestTimeIndex) {
TotalTimeInAnInterval -= (requestTimeIndex - (curTime - $scope.requestDuration));
}
if (TotalDataInAnInterval != 0 && TotalTimeInAnInterval != 0) {
$scope.totalThroughput = Math.round((8 * TotalDataInAnInterval) / (TotalTimeInAnInterval / 1000)); // bps
}
}
[1] B. Wei, H. Song, S. Wang, K. Kanai and J. Katto, "Evaluation of Throughput Prediction for Adaptive Bitrate Control Using Trace-Based Emulation," in IEEE Access, vol. 7, pp. 51346-51356, 2019, doi: 10.1109/ACCESS.2019.2909399.