transportccextension.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package rtp
  4. import (
  5. "encoding/binary"
  6. )
  7. const (
  8. // transport-wide sequence
  9. transportCCExtensionSize = 2
  10. )
  11. // TransportCCExtension is a extension payload format in
  12. // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
  13. // 0 1 2 3
  14. // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  15. // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  16. // | 0xBE | 0xDE | length=1 |
  17. // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  18. // | ID | L=1 |transport-wide sequence number | zero padding |
  19. // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  20. type TransportCCExtension struct {
  21. TransportSequence uint16
  22. }
  23. // Marshal serializes the members to buffer
  24. func (t TransportCCExtension) Marshal() ([]byte, error) {
  25. buf := make([]byte, transportCCExtensionSize)
  26. binary.BigEndian.PutUint16(buf[0:2], t.TransportSequence)
  27. return buf, nil
  28. }
  29. // Unmarshal parses the passed byte slice and stores the result in the members
  30. func (t *TransportCCExtension) Unmarshal(rawData []byte) error {
  31. if len(rawData) < transportCCExtensionSize {
  32. return errTooSmall
  33. }
  34. t.TransportSequence = binary.BigEndian.Uint16(rawData[0:2])
  35. return nil
  36. }