improve fine-grained fec

This commit is contained in:
wangyu- 2018-08-05 22:30:22 -05:00
parent 3e248b414c
commit 8d1ab91cc3
4 changed files with 44 additions and 12 deletions

View File

@ -85,7 +85,7 @@ See [UDPspeeder + openvpn config guide](https://github.com/wangyu-/UDPspeeder/wi
### Full Options
```
UDPspeeder V2
git version: 6f55b8a2fc build date: Nov 19 2017 06:11:23
git version: 3e248b414c build date: Aug 5 2018 21:59:52
repository: https://github.com/wangyu-/UDPspeeder
usage:
@ -110,6 +110,8 @@ advanced options:
do not use if you dont know what it means.
-i,--interval <number> scatter each fec group to a interval of <number> ms, to protect burst packet loss.
default value: 0. do not use if you dont know what it means.
-f,--fec x1:y1,x2:y2,.. similiar to -f/--fec above,fine-grained fec parameters,may help save bandwidth.
example: "-f 1:3,2:4,10:6,20:10". check repo for details
--random-drop <number> simulate packet loss, unit: 0.01%. default value: 0.
--disable-obscure <number> disable obscure, to save a bit bandwidth and cpu.
developer options:

View File

@ -106,7 +106,7 @@ https://github.com/wangyu-/udp2raw-tunnel
### 命令选项
```
UDPspeeder V2
git version: 6f55b8a2fc build date: Nov 19 2017 06:11:23
git version: 3e248b414c build date: Aug 5 2018 21:59:52
repository: https://github.com/wangyu-/UDPspeeder
usage:
@ -131,6 +131,8 @@ advanced options:
do not use if you dont know what it means.
-i,--interval <number> scatter each fec group to a interval of <number> ms, to protect burst packet loss.
default value: 0. do not use if you dont know what it means.
-f,--fec x1:y1,x2:y2,.. similiar to -f/--fec above,fine-grained fec parameters,may help save bandwidth.
example: "-f 1:3,2:4,10:6,20:10". check repo for details
--random-drop <number> simulate packet loss, unit: 0.01%. default value: 0.
--disable-obscure <number> disable obscure, to save a bit bandwidth and cpu.
developer options:
@ -151,8 +153,6 @@ log and help options:
--disable-color disable log color
-h,--help print this help message
```
### 包发送选项,两端设置可以不同。 只影响本地包发送。
##### `-f` 选项

View File

@ -35,12 +35,16 @@ struct fec_parameter_t
{
unsigned char x;//AKA fec_data_num (x should be same as <index of rs_par>+1 at the moment)
unsigned char y;//fec_redundant_num
}rs_par[255+10];
}rs_par[max_fec_packet_num+10];
int rs_from_str(char * s)//todo inefficient
{
vector<string> str_vec=string_to_vec(s,",");
if(str_vec.size()<1) return -1;
if(str_vec.size()<1)
{
mylog(log_warn,"failed to parse [%s]\n",s);
return -1;
}
vector<rs_parameter_t> par_vec;
for(int i=0;i<(int)str_vec.size();i++)
{
@ -54,7 +58,7 @@ struct fec_parameter_t
}
if(x<1||y<0||x+y>max_fec_packet_num)
{
mylog(log_warn,"invaild value x=%d y=%d\n",x,y);
mylog(log_warn,"invaild value x=%d y=%d, x should >=1, y should >=0, x +y should <%d\n",x,y,max_fec_packet_num);
return -1;
}
tmp_par.x=x;
@ -63,6 +67,7 @@ struct fec_parameter_t
}
assert(par_vec.size()==str_vec.size());
int found_problem=0;
for(int i=1;i<(int)par_vec.size();i++)
{
if(par_vec[i].x<=par_vec[i-1].x)
@ -80,9 +85,18 @@ struct fec_parameter_t
if(pre_ratio<now_ratio)
{
mylog(log_warn,"%d/%d < %d/%d ,not suggested\n",pre_y,pre_x,now_y,now_x);
if(found_problem==0)
{
log_bare(log_warn,"possible problems: %d/%d < %d/%d ",pre_y,pre_x,now_y,now_x);
found_problem=1;
}
log_bare(log_warn,",%d/%d < %d/%d",pre_y,pre_x,now_y,now_x);
}
}
if(found_problem)
{
log_bare(log_warn,"\n");
}
{ //special treatment for first parameter
int x=par_vec[0].x;
@ -103,16 +117,27 @@ struct fec_parameter_t
rs_par[now_x-1].x=now_x;
rs_par[now_x-1].y=now_y;
double k= double(now_y-pre_y)/double(now_x-pre_x);
double now_ratio=double(par_vec[i].y)/par_vec[i].x;
double pre_ratio=double(par_vec[i-1].y)/par_vec[i-1].x;
//double k= double(now_y-pre_y)/double(now_x-pre_x);
for(int j=pre_x+1;j<=now_x-1;j++)
{
int in_x=j;
int in_y= double(pre_y) + double(in_x-pre_x)*k+ 0.9999;// round to upper
//////// int in_y= double(pre_y) + double(in_x-pre_x)*k+ 0.9999;// round to upper
double distance=now_x-pre_x;
/////// double in_ratio=pre_ratio*(1.0-(in_x-pre_x)/distance) + now_ratio *(1.0- (now_x-in_x)/distance);
////// int in_y= in_x*in_ratio + 0.9999;
int in_y= pre_y +(now_y-pre_y) *(in_x-pre_x)/distance +0.99999;
if(in_x+in_y>max_fec_packet_num)
{
in_y=max_fec_packet_num-in_x;
assert(in_y>=0&&in_y<=max_fec_packet_num);
}
rs_par[in_x-1].x=in_x;
rs_par[in_x-1].y=in_y;
}
@ -130,7 +155,9 @@ struct fec_parameter_t
assert(rs_cnt>=1);
for(int i=0;i<rs_cnt;i++)
{
sprintf(tmp_buf,"<%d,%d> ",int(rs_par[i].x),int(rs_par[i].y));
sprintf(tmp_buf,"%d:%d",int(rs_par[i].x),int(rs_par[i].y));
if(i!=0)
tmp_string+=",";
tmp_string+=tmp_buf;
}
strcpy(res,tmp_string.c_str());

View File

@ -44,13 +44,16 @@ static void print_help()
printf(" default value: 1250. you typically shouldnt change this value.\n");
printf(" -q,--queue-len <number> fec queue len, only for mode 0, fec will be performed immediately after queue is full.\n");
printf(" default value: 200. \n");
printf(" -j,--jitter <number> simulated jitter. randomly delay first packet for 0~<number> ms, default value: 0.\n");
printf(" do not use if you dont know what it means.\n");
printf(" -i,--interval <number> scatter each fec group to a interval of <number> ms, to protect burst packet loss.\n");
printf(" default value: 0. do not use if you dont know what it means.\n");
printf(" -f,--fec x1:y1,x2:y2,.. similiar to -f/--fec above,fine-grained fec parameters,may help save bandwidth.\n");
printf(" example: \"-f 1:3,2:4,10:6,20:10\". check repo for details\n");
printf(" --random-drop <number> simulate packet loss, unit: 0.01%%. default value: 0.\n");
printf(" --disable-obscure <number> disable obscure, to save a bit bandwidth and cpu.\n");
// printf(" --disable-xor <number> disable xor\n");
//printf(" --disable-xor <number> disable xor\n");
printf("developer options:\n");
printf(" --fifo <string> use a fifo(named pipe) for sending commands to the running program, so that you\n");