webrtc QOS笔记一 Neteq直方图算法浅读
文章目录
- webrtc QOS笔记一 Neteq直方图算法浅读
- Histogram Algorithm
- 获取目标延迟
- 遗忘因子曲线
Histogram Algorithm
DelayManager::Update()->Histogram::Add() 会根据计算的iat_packet(inter arrival times, =实际包间间隔 / 打包时长),将该iat_packet插入IATVector直方图对应数组下标内。并更新该直方图的数据下标下概率参数。[M88 SRC]
一共有四步操作:
1、用遗忘因子,对历史数据的出现概率进行遗忘, 并统计概率合
b
u
c
k
e
t
s
_
[
i
]
=
b
u
c
k
e
t
s
_
[
i
]
∗
f
o
r
g
e
t
_
f
a
c
t
o
r
buckets\_[i] = buckets\_[i] * forget\_factor
buckets_[i]=buckets_[i]∗forget_factor
v e c t o r _ s u m = ∑ 0 b u c k e t s . s i z e ( ) b u c k e t s _ [ i ] ∗ f o r g e t _ f a c t o r vector\_sum=\sum_{0}^{buckets.size()} buckets\_[i] * forget\_factor vector_sum=∑0buckets.size()buckets_[i]∗forget_factor
2、增大本次计算到的IAT的概率值。
b u c k e t s _ [ v a l u e ] = b u c k e t s _ [ v a l u e ] + ( 1 − f o r g e t f a c t o r _ ) buckets\_[value]=buckets\_[value]+(1−forget_factor\_) buckets_[value]=buckets_[value]+(1−forgetfactor_)
v e c t o r _ s u m = v e c t o r _ s u m + ( 1 − f o r g e t _ f a c t o r _ ) vector\_sum = vector\_sum + (1-forget\_factor\_) vector_sum=vector_sum+(1−forget_factor_)
- 例:
假如历史bucket 数据为:
buckets_ = {0,0,1,0}
遗忘因子为 0.9:
forget_factor = 0.9
新来的抖动延迟数据为66ms, 桶间为20ms一个单位, 那插入位置为 66 / 20 = 3,则更新后
buckets = {0,0,0.9,0.1}
假若使用%95分位的值作为目标延迟, 则更新后的目标延迟为 60ms.
3、调整本次计算到的IAT的概率,使整个IAT的概率分布之和近似为1。调整方式为假设当前概率分布之和为tempSum,则:
v e c t o r s u m = 1 − v e c t o r s u m vector_sum=1−vector_sum vectorsum=1−vectorsum
b u c k e t s [ n ] = { b u c k e t s _ [ n ] − M i n ( ∣ v e c t o r _ s u m ∣ , b u c k e t s _ [ n ] / 16 ) i f ( v e c t o r s u m > 0 ) b u c k e t s _ [ n ] + M i n ( ∣ v e c t o r _ s u m ∣ , b u c k e t s _ [ n ] / 16 ) i f ( v e c t o r s u m > 0 ) buckets_[n]= \begin{cases} buckets\_[n]−Min(∣vector\_sum∣,buckets\_[n]/16) if(vector_sum>0) \\ buckets\_[n]+Min(∣vector\_sum∣,buckets\_[n]/16) if(vector_sum>0) \\ \end{cases} buckets[n]={buckets_[n]−Min(∣vector_sum∣,buckets_[n]/16)if(vectorsum>0)buckets_[n]+Min(∣vector_sum∣,buckets_[n]/16)if(vectorsum>0)
4、更新forget_factor_, 使遗忘因子forget_factor_逼近base_forget_factor_
a.使用start_forget_weight_更新(默认初始值start_forget_weight_ = 2,base_forget_factor_=0.9993)
a
d
d
_
c
o
u
n
t
_
+
+
add\_count\_++
add_count_++
f
o
r
g
e
t
_
f
a
c
t
o
r
_
=
1
−
(
s
t
a
r
t
_
f
o
r
g
e
t
_
w
e
i
g
h
t
_
/
(
a
d
d
_
c
o
u
n
t
_
+
1
)
)
forget\_factor\_=1−(start\_forget\_weight\_/(add\_count\_+1))
forget_factor_=1−(start_forget_weight_/(add_count_+1))
f
o
r
g
e
t
_
f
a
c
t
o
r
_
=
M
a
x
(
0
,
M
i
n
(
b
a
s
e
_
f
o
r
g
e
t
_
f
a
c
t
o
r
_
,
f
o
r
g
e
t
_
f
a
c
t
o
r
)
)
forget\_factor\_=Max(0,Min(base\_forget\_factor\_,forget\_factor))
forget_factor_=Max(0,Min(base_forget_factor_,forget_factor))
b. 其中的3是Q30的值,没有多大 = 0.000091552734375
f
o
r
g
e
t
_
f
a
c
t
o
r
_
=
f
o
r
g
e
t
f
a
c
t
o
r
_
+
(
b
a
s
e
_
f
o
r
g
e
t
_
f
a
c
t
o
r
_
−
f
o
r
g
e
t
_
f
a
c
t
o
r
_
+
3
)
/
4
forget\_factor\_=forget_factor\_+(base\_forget\_factor\_−forget\_factor\_+3)/4
forget_factor_=forgetfactor_+(base_forget_factor_−forget_factor_+3)/4
获取目标延迟
依据probability获取此百分位的值作为目标延迟(初始值0.97)
∑ 0 n b u c k e t s _ [ n ] > p r o b a b i l i t y \sum_{0}^{n} buckets\_[n] > probability ∑0nbuckets_[n]>probability
int Histogram::Quantile(int probability) {
// Find the bucket for which the probability of observing an
// inter-arrival time larger than or equal to |index| is larger than or
// equal to |probability|. The sought probability is estimated using
// the histogram as the reverse cumulant PDF, i.e., the sum of elements from
// the end up until |index|. Now, since the sum of all elements is 1
// (in Q30) by definition, and since the solution is often a low value for
// |iat_index|, it is more efficient to start with |sum| = 1 and subtract
// elements from the start of the histogram.
int inverse_probability = (1 << 30) - probability;
size_t index = 0; // Start from the beginning of |buckets_|.
int sum = 1 << 30; // Assign to 1 in Q30.
sum -= buckets_[index];
while ((sum > inverse_probability) && (index < buckets_.size() - 1)) {
// Subtract the probabilities one by one until the sum is no longer greater
// than |inverse_probability|.
++index;
sum -= buckets_[index];
}
return static_cast<int>(index);
}
遗忘因子曲线
测试曲线,调整遗忘因子提高抖动估计灵敏度:
#include <iostream>
#include <cstdint>
#include <vector>
uint32_t packet_loss_rate_ = 0;
int main()
{
std::vector<int> input;
std::vector<float> buckets;
float forget_factor = 0.9993;
float val = 0;
for (size_t k = 0; k < 1000; k ++) {
val = val * forget_factor + (1-forget_factor);
buckets.push_back(val);
}
for (int i = 0; i < 1000; ++i) {
std::cout << buckets[i]<< " ";
}
return 0;
}