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 ### Full Options
``` ```
UDPspeeder V2 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 repository: https://github.com/wangyu-/UDPspeeder
usage: usage:
@ -110,6 +110,8 @@ advanced options:
do not use if you dont know what it means. 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. -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. 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. --random-drop <number> simulate packet loss, unit: 0.01%. default value: 0.
--disable-obscure <number> disable obscure, to save a bit bandwidth and cpu. --disable-obscure <number> disable obscure, to save a bit bandwidth and cpu.
developer options: developer options:

View File

@ -106,7 +106,7 @@ https://github.com/wangyu-/udp2raw-tunnel
### 命令选项 ### 命令选项
``` ```
UDPspeeder V2 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 repository: https://github.com/wangyu-/UDPspeeder
usage: usage:
@ -131,6 +131,8 @@ advanced options:
do not use if you dont know what it means. 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. -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. 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. --random-drop <number> simulate packet loss, unit: 0.01%. default value: 0.
--disable-obscure <number> disable obscure, to save a bit bandwidth and cpu. --disable-obscure <number> disable obscure, to save a bit bandwidth and cpu.
developer options: developer options:
@ -151,8 +153,6 @@ log and help options:
--disable-color disable log color --disable-color disable log color
-h,--help print this help message -h,--help print this help message
``` ```
### 包发送选项,两端设置可以不同。 只影响本地包发送。 ### 包发送选项,两端设置可以不同。 只影响本地包发送。
##### `-f` 选项 ##### `-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 x;//AKA fec_data_num (x should be same as <index of rs_par>+1 at the moment)
unsigned char y;//fec_redundant_num 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 int rs_from_str(char * s)//todo inefficient
{ {
vector<string> str_vec=string_to_vec(s,","); 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; vector<rs_parameter_t> par_vec;
for(int i=0;i<(int)str_vec.size();i++) 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) 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; return -1;
} }
tmp_par.x=x; tmp_par.x=x;
@ -63,6 +67,7 @@ struct fec_parameter_t
} }
assert(par_vec.size()==str_vec.size()); assert(par_vec.size()==str_vec.size());
int found_problem=0;
for(int i=1;i<(int)par_vec.size();i++) for(int i=1;i<(int)par_vec.size();i++)
{ {
if(par_vec[i].x<=par_vec[i-1].x) if(par_vec[i].x<=par_vec[i-1].x)
@ -80,8 +85,17 @@ struct fec_parameter_t
if(pre_ratio<now_ratio) 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 { //special treatment for first parameter
@ -103,16 +117,27 @@ struct fec_parameter_t
rs_par[now_x-1].x=now_x; rs_par[now_x-1].x=now_x;
rs_par[now_x-1].y=now_y; 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++) for(int j=pre_x+1;j<=now_x-1;j++)
{ {
int in_x=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) if(in_x+in_y>max_fec_packet_num)
{ {
in_y=max_fec_packet_num-in_x; in_y=max_fec_packet_num-in_x;
assert(in_y>=0&&in_y<=max_fec_packet_num); assert(in_y>=0&&in_y<=max_fec_packet_num);
} }
rs_par[in_x-1].x=in_x; rs_par[in_x-1].x=in_x;
rs_par[in_x-1].y=in_y; rs_par[in_x-1].y=in_y;
} }
@ -130,7 +155,9 @@ struct fec_parameter_t
assert(rs_cnt>=1); assert(rs_cnt>=1);
for(int i=0;i<rs_cnt;i++) 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; tmp_string+=tmp_buf;
} }
strcpy(res,tmp_string.c_str()); 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(" 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(" -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(" default value: 200. \n");
printf(" -j,--jitter <number> simulated jitter. randomly delay first packet for 0~<number> ms, default value: 0.\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(" 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(" -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(" 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(" --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-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("developer options:\n");
printf(" --fifo <string> use a fifo(named pipe) for sending commands to the running program, so that you\n"); printf(" --fifo <string> use a fifo(named pipe) for sending commands to the running program, so that you\n");