From ceebe176cf593cba40f9713145be0dec3c1ff625 Mon Sep 17 00:00:00 2001 From: xtaci Date: Thu, 12 Oct 2023 23:10:50 +0800 Subject: [PATCH] fix autotune fec mis-align when parameters are different --- fec.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fec.go b/fec.go index 88f5a9c..27dd66e 100644 --- a/fec.go +++ b/fec.go @@ -45,7 +45,8 @@ type fecDecoder struct { codec reedsolomon.Encoder // auto tune fec parameter - autoTune autoTune + autoTune autoTune + shouldTune bool } func newFECDecoder(dataShards, parityShards int) *fecDecoder { @@ -78,18 +79,17 @@ func (dec *fecDecoder) decode(in fecPacket) (recovered [][]byte) { } // check if FEC parameters is out of sync - var shouldTune bool if int(in.seqid())%dec.shardSize < dec.dataShards { if in.flag() != typeData { // expect typeData - shouldTune = true + dec.shouldTune = true } } else { if in.flag() != typeParity { - shouldTune = true + dec.shouldTune = true } } - if shouldTune { + if dec.shouldTune { autoDS := dec.autoTune.FindPeriod(true) autoPS := dec.autoTune.FindPeriod(false) @@ -108,11 +108,17 @@ func (dec *fecDecoder) decode(in fecPacket) (recovered [][]byte) { dec.codec = codec dec.decodeCache = make([][]byte, dec.shardSize) dec.flagCache = make([]bool, dec.shardSize) + dec.shouldTune = false //log.Println("autotune to :", dec.dataShards, dec.parityShards) } } } + // parameters in tuning + if dec.shouldTune { + return nil + } + // insertion n := len(dec.rx) - 1 insertIdx := 0