diff --git a/fec_manager.cpp b/fec_manager.cpp index f301661..5dc851c 100644 --- a/fec_manager.cpp +++ b/fec_manager.cpp @@ -189,6 +189,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/) { int about_to_fec=0; int delayed_append=0; + //int counter_back=counter; if(type==0&& s!=0 &&counter==0&&blob_encode.get_shard_len(fec_data_num,len)>=fec_mtu) { mylog(log_warn,"message too long len=%d,ignored\n",len); @@ -302,6 +303,9 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/) mylog(log_info,"!!! s= %d\n"); + ready_for_output=1; + seq++; + counter=0; output_n=actual_data_num+actual_redundant_num; blob_encode.clear(); @@ -309,19 +313,18 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/) memset(&its,0,sizeof(its)); timerfd_settime(timer_fd,TFD_TIMER_ABSTIME,&its,0); - if(encode_fast_send&&s!=0&&type==1) + if(encode_fast_send&&type==1) { int packet_to_send[max_fec_packet_num+5]={0}; int packet_to_send_counter=0; - assert(counter!=0); + //assert(counter!=0); if(s!=0) - packet_to_send[packet_to_send_counter++]=counter-1; + packet_to_send[packet_to_send_counter++]=actual_data_num-1; for(int i=actual_data_num;idata_num) + //data_num=mp[seq].data_num; + //redundant_num=mp[seq].redundant_num; + + /*if(mp[seq].data_counter>data_num) //invaild { mylog(log_warn,"unexpected mp[seq].data_counter>mp[seq].data_num\n"); anti_replay.set_invaild(seq); return -1; + }*/ + //assert((int)inner_mp.size()<=data_num); + if((int)inner_mp.size()>=mp[seq].data_num) + { + about_to_fec=1; } - else if(mp[seq].data_counter==data_num) + + + /* + else if(mp[seq].data_counter==data_num) //no need to fec . (received first redundant packet ,or received a data packet after redunant packet) { anti_replay.set_invaild(seq);// dont do fec,but still set invaild } else //mp[seq].data_counter < mp[seq].data_num { - if((int)inner_mp.size()>data_num+1) + if((int)inner_mp.size()>data_num) { mylog(log_warn,"unexpected (int)inner_mp.size()>data_num+1\n"); anti_replay.set_invaild(seq); return -1; - } + }*/ + //if((int)inner_mp.size()==data_num) + //about_to_fec=1; + + /* if((int)inner_mp.size()==data_num+1) { anti_replay.set_invaild(seq); - if(data_num==0) + + if(old_data_num==0) return 0; else { - //mylog(log_warn,"data_num!=0\n"); //this is possible + mylog(log_warn,"data_num=0\n"); return -1; } - } + }*/ - if((int)inner_mp.size()==data_num) - about_to_fec=1; - } + + //} } else { @@ -564,9 +592,13 @@ int fec_decode_manager_t::input(char *s,int len) //for() } + if(about_to_fec) { - mylog(log_error,"fec here!\n"); + int group_data_num=mp[seq].data_num; + int group_redundant_num=mp[seq].redundant_num; + + //mylog(log_error,"fec here!\n"); if(type==0) { char *fec_tmp_arr[max_fec_packet_num+5]={0}; @@ -574,9 +606,9 @@ int fec_decode_manager_t::input(char *s,int len) { fec_tmp_arr[it->first]=fec_data[it->second].buf; } - rs_decode2(data_num,data_num+redundant_num,fec_tmp_arr,len); //the input data has been modified in-place + rs_decode2(group_data_num,group_data_num+group_redundant_num,fec_tmp_arr,len); //the input data has been modified in-place blob_decode.clear(); - for(int i=0;imax_data_len) { - mylog(log_warn,"invaild len %d,seq= %u,data_num= %d r_num= %d,i= %d\n",output_len_arr_buf[i],seq,data_num,redundant_num,i); + mylog(log_warn,"invaild len %d,seq= %u,data_num= %d r_num= %d,i= %d\n",output_len_arr_buf[i],seq,group_data_num,group_redundant_num,i); fec_ok=0; for(int i=0;i