Share via


3.1.1.6.4 Selecting the Coefficients Matrix

If the Source sequence numbers (section 3.1.1.2) for packets S1, S2, S3 … Sn are s1, s2, s3 … sn, the coefficient matrix is calculated as follows.

Matrix coefficient calculation

Figure 12: Matrix coefficient calculation

The division uses finite field division as described in section 3.1.1.6.1.2. Note that since all the packets in an FEC Packet are sequential, s2=s1+1, s3=s1+2, …, sn=s1+(n-1).

Only the last byte of the Source sequence number is used in calculating the coefficient. The fecIndex field described in the following pseudo-code example is equivalent to the uFecIndex field, as specified in section 2.2.2.2. The value of the fecIndex field is updated using the following code prior to every call for encoding an FEC Packet:

 if ((sn & 0xff) >= (s1 & 0xff) && ((fecIndex >= (s1 & 0xff)) && (fecIndex <= (sn & 0xff))) ||
     (sn & 0xff) < (s1 & 0xff) && ((fecIndex >= (s1 & 0xff)) || (fecIndex <= (sn & 0xff))))
     fecIndex = (sn + 1) & 0xff;

Pseudo-code example:

 void GenerateCoeffArray(BYTE *pbCoEfficientArray, 
 int cLength, 
 USHORT ucOrigStart, 
 USHORT ucOrigEnd, 
 __out BYTE *pucFecIndex)
 {
     if ((ucOrigEnd >= ucOrigStart) &&
         ((*pucFecIndex >= ucOrigStart) && (*pucFecIndex <= ucOrigEnd)))
         *pucFecIndex = (BYTE)(ucOrigEnd+1);
     if ((ucOrigEnd < ucOrigStart) &&
         ((*pucFecIndex >= ucOrigStart) || (*pucFecIndex <= ucOrigEnd)))
         *pucFecIndex = (BYTE)(ucOrigEnd+1);
  
     for (int i=0; i < cLength; i++, ucOrigStart++)
     {
         pbCoEfficientArray[i] = (BYTE)Div(1, (*pucFecIndex)^(ucOrigStart & 0xff));
     }
 }
  
 void RegenerateCoeffArrayFromFecIndex(BYTE *pbCoefficientArray, 
 int cLength, 
 BYTE fecIndex, 
 USHORT ucOrigStart, 
 USHORT ucOrigEnd)
 {
     for (int i=0; i < cLength; i++, ucOrigStart++)
     {
         pbCoefficientArray[i] = (BYTE)Div(1, fecIndex^(ucOrigStart & 0xff));
     }
 }