Skip to content
21 changes: 16 additions & 5 deletions src/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ bool CNetBuf::Put ( const CVector<uint8_t>& vecbyData, int iInSize )
return false;
}

// to get the number of input blocks we assume that the number of bytes for
// the sequence number is much smaller than the number of coded audio bytes
// This divide is exact if and only if iNumBlocks * iNumBytesSeqNum < iBlockSize,
// since the actual input is iNumBlocks * ( iBlockSize + iNumBytesSeqNum ) bytes. The
// sequence number merely being "much smaller" than the coded audio is not the
// condition: at iNumBlocks == iBlockSize the count comes out one too high whatever
// the ratio is. The bound is not enforced here but by the properties validator in
// protocol.cpp, EvaluateNetwTranspPropsMes, which rejects a base network packet size
// below CELT_MINIMUM_NUM_BYTES (10) and a block size factor outside
// { FRAME_SIZE_FACTOR_PREFERRED, _DEFAULT, _SAFE }. With iNumBytesSeqNum == 1 and
// iBlockSize == iBaseNetworkPacketSize - 1 (channel.cpp), the worst reachable case is
// a factor of 4 against a block size of 9.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above is far too verbose for anyone to read it clearly. Two lines looks like a good length. Ten lines isn't.

It needs to be short and to the point:

Intent:
Purpose of this section, including what the result is used for.

Inputs:

  • iInSize: where this comes from and what it means
  • iBlockSize: ...
  • ...

Method:
Explanation of why this method works. But only if it's not transparently obvious.

const int iNumBlocks = /* floor */ ( iInSize / iBlockSize );

// copy new data in internal buffer
Expand All @@ -190,9 +198,12 @@ bool CNetBuf::Put ( const CVector<uint8_t>& vecbyData, int iInSize )
iSeqNumDiff -= 256;
}

// The 1-byte sequence number wraps around at a count of 256. So, if a packet is delayed
// further than this we cannot detect it. But it does not matter since such a packet is
// more than 100 ms delayed so we have a bad network situation anyway. Therefore we
// The 1-byte sequence number is folded into a signed difference above, so a
// delayed packet is mistaken for an early one once it is more than 128 counts
// late, not 256. At the fastest possible frame rate that is still 171 ms
// (64-sample frames, 750 counts/s) and at the default frame size 341 ms
// (128-sample frames, 375 counts/s), so such a packet is long useless either
// way and we have a bad network situation anyway. Therefore we

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't add anything at all.

// assume that the sequence number difference between the received and local counter is
// correct. The idea of the following code is that we always move our "buffer window" so
// that the received packet fits into the buffer. By doing this we are robust against
Expand Down