As discussed in issue https://github.com/versatica/mediasoup/issues/1366 (this comment by @penguinol: https://github.com/versatica/mediasoup/issues/1366#issuecomment-2045075046) we may use uint64_t in C++ maps and sets in which the key is a RTP seq number or similar. This would allow us to use our SeqManager compare functions into those containers without violating transitivity, i.e. comp(a,b) && comp(b,c) -> comp(a,c), which currently we are violating (see the referenced issue for details).
libwebrtc uses uint64_t for seq nums, it takes more memory and cpu usage, but it's easier to understand and more reliable. uint64_t is big enougth to avoid wrap around. When receiving a packet, unwrap uint16_t seq num to uint64_t by roc * 65535 + seq (where roc is the cycle number), and then store and use the uint64_t value as in https://webrtc.googlesource.com/src/+/refs/heads/main/rtc_base/numerics/sequence_number_unwrapper.h. libwebrtc creates a SeqNumUnwrapper object for every stream which stores the uint64_t value of the last packet. When a new packet arrives, it calculates the distance between the seq of the packet and the last seq in SeqNumUnwrapper by something like our SeqManager::SeqLowerThan to determine which cycle does the packet belongs to.
As discussed in issue https://github.com/versatica/mediasoup/issues/1366 (this comment by @penguinol: https://github.com/versatica/mediasoup/issues/1366#issuecomment-2045075046) we may use
uint64_t
in C++ maps and sets in which the key is a RTP seq number or similar. This would allow us to use ourSeqManager
compare functions into those containers without violating transitivity, i.e.comp(a,b) && comp(b,c) -> comp(a,c)
, which currently we are violating (see the referenced issue for details).libwebrtc uses
uint64_t
for seq nums, it takes more memory and cpu usage, but it's easier to understand and more reliable.uint64_t
is big enougth to avoid wrap around. When receiving a packet, unwrapuint16_t
seq num touint64_t
byroc * 65535 + seq
(whereroc
is the cycle number), and then store and use theuint64_t
value as in https://webrtc.googlesource.com/src/+/refs/heads/main/rtc_base/numerics/sequence_number_unwrapper.h. libwebrtc creates aSeqNumUnwrapper
object for every stream which stores theuint64_t
value of the last packet. When a new packet arrives, it calculates the distance between the seq of the packet and the last seq inSeqNumUnwrapper
by something like ourSeqManager::SeqLowerThan
to determine which cycle does the packet belongs to.