|
@@ -18,6 +18,7 @@ const u32_t anti_replay_buff_size=30000;//can be set very large
|
|
const int max_fec_packet_num=255;// this is the limitation of the rs lib
|
|
const int max_fec_packet_num=255;// this is the limitation of the rs lib
|
|
extern u32_t fec_buff_num;
|
|
extern u32_t fec_buff_num;
|
|
|
|
|
|
|
|
+const int rs_str_len=max_fec_packet_num*10+100;
|
|
|
|
|
|
struct fec_parameter_t
|
|
struct fec_parameter_t
|
|
{
|
|
{
|
|
@@ -27,21 +28,111 @@ struct fec_parameter_t
|
|
int timeout=8*1000;
|
|
int timeout=8*1000;
|
|
int mode=0;
|
|
int mode=0;
|
|
|
|
|
|
- int rs_cnt;
|
|
|
|
|
|
+ int rs_cnt=0;
|
|
struct rs_parameter_t //parameters for reed solomon
|
|
struct rs_parameter_t //parameters for reed solomon
|
|
{
|
|
{
|
|
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[255+10];
|
|
|
|
|
|
- int rs_from_str(char * s)
|
|
|
|
|
|
+ int rs_from_str(char * s)//todo inefficient
|
|
{
|
|
{
|
|
|
|
+ vector<string> str_vec=string_to_vec(s,",");
|
|
|
|
+ if(str_vec.size()<1) return -1;
|
|
|
|
+ vector<rs_parameter_t> par_vec;
|
|
|
|
+ for(int i=0;i<(int)str_vec.size();i++)
|
|
|
|
+ {
|
|
|
|
+ rs_parameter_t tmp_par;
|
|
|
|
+ string &tmp_str=str_vec[i];
|
|
|
|
+ int x,y;
|
|
|
|
+ if(sscanf((char *)tmp_str.c_str(),"%d:%d",&x,&y)!=2)
|
|
|
|
+ {
|
|
|
|
+ mylog(log_warn,"failed to parse [%s]\n",tmp_str.c_str());
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ if(x<1||y<1||x+y>max_fec_packet_num)
|
|
|
|
+ {
|
|
|
|
+ mylog(log_warn,"invaild value x=%d y=%d\n",x,y);
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ tmp_par.x=x;
|
|
|
|
+ tmp_par.y=y;
|
|
|
|
+ par_vec.push_back(tmp_par);
|
|
|
|
+ }
|
|
|
|
+ assert(par_vec.size()==str_vec.size());
|
|
|
|
+
|
|
|
|
+ for(int i=1;i<(int)par_vec.size();i++)
|
|
|
|
+ {
|
|
|
|
+ if(par_vec[i].x<=par_vec[i-1].x)
|
|
|
|
+ {
|
|
|
|
+ mylog(log_warn,"error in [%s], x in x:y should be in ascend order\n",s);
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ int now_x=par_vec[i].x;
|
|
|
|
+ int now_y=par_vec[i].y;
|
|
|
|
+ int pre_x=par_vec[i-1].x;
|
|
|
|
+ int pre_y=par_vec[i-1].y;
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+
|
|
|
|
+ if(pre_ratio<now_ratio)
|
|
|
|
+ {
|
|
|
|
+ mylog(log_warn,"%d/%d < %d/%d ,not suggested\n",pre_y,pre_x,now_y,now_x);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ { //special treatment for first parameter
|
|
|
|
+ int x=par_vec[0].x;
|
|
|
|
+ int y=par_vec[0].y;
|
|
|
|
+ for(int i=1;i<=x;i++)
|
|
|
|
+ {
|
|
|
|
+ rs_par[i-1].x=i;
|
|
|
|
+ rs_par[i-1].y=y;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for(int i=1;i<(int)par_vec.size();i++)
|
|
|
|
+ {
|
|
|
|
+ int now_x=par_vec[i].x;
|
|
|
|
+ int now_y=par_vec[i].y;
|
|
|
|
+ int pre_x=par_vec[i-1].x;
|
|
|
|
+ int pre_y=par_vec[i-1].y;
|
|
|
|
+ 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);
|
|
|
|
+ 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
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ rs_cnt=par_vec[par_vec.size()-1].x;
|
|
|
|
+
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- char *rs_to_str()
|
|
|
|
|
|
+ char *rs_to_str()//todo inefficient
|
|
{
|
|
{
|
|
- return 0;
|
|
|
|
|
|
+ static char res[rs_str_len];
|
|
|
|
+ string tmp_string;
|
|
|
|
+ char tmp_buf[100];
|
|
|
|
+ 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));
|
|
|
|
+ tmp_string+=tmp_buf;
|
|
|
|
+ }
|
|
|
|
+ strcpy(res,tmp_string.c_str());
|
|
|
|
+ return res;
|
|
}
|
|
}
|
|
|
|
|
|
rs_parameter_t get_tail()
|
|
rs_parameter_t get_tail()
|