sampleSequenceLocation.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. // Package samplebuilder provides functionality to reconstruct media frames from RTP packets.
  4. package samplebuilder
  5. type sampleSequenceLocation struct {
  6. // head is the first packet in a sequence
  7. head uint16
  8. // tail is always set to one after the final sequence number,
  9. // so if head == tail then the sequence is empty
  10. tail uint16
  11. }
  12. func (l sampleSequenceLocation) empty() bool {
  13. return l.head == l.tail
  14. }
  15. func (l sampleSequenceLocation) hasData() bool {
  16. return l.head != l.tail
  17. }
  18. func (l sampleSequenceLocation) count() uint16 {
  19. return seqnumDistance(l.head, l.tail)
  20. }
  21. const (
  22. slCompareVoid = iota
  23. slCompareBefore
  24. slCompareInside
  25. slCompareAfter
  26. )
  27. func (l sampleSequenceLocation) compare(pos uint16) int {
  28. if l.head == l.tail {
  29. return slCompareVoid
  30. }
  31. if l.head < l.tail {
  32. if l.head <= pos && pos < l.tail {
  33. return slCompareInside
  34. }
  35. } else {
  36. if l.head <= pos || pos < l.tail {
  37. return slCompareInside
  38. }
  39. }
  40. if l.head-pos <= pos-l.tail {
  41. return slCompareBefore
  42. }
  43. return slCompareAfter
  44. }