You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rtp-ext-ssrc-audio-level.c 1.8KB

10 kuukautta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "rtp-ext.h"
  2. // https://datatracker.ietf.org/doc/html/rfc6464
  3. /*
  4. The audio level header extension carries the level of the audio in
  5. the RTP [RFC3550] payload of the packet with which it is associated.
  6. This information is carried in an RTP header extension element as
  7. defined by "A General Mechanism for RTP Header Extensions" [RFC5285].
  8. The payload of the audio level header extension element can be
  9. encoded using either the one-byte or two-byte header defined in
  10. [RFC5285]. Figures 1 and 2 show sample audio level encodings with
  11. each of these header formats.
  12. 0 1
  13. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  14. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  15. | ID | len=0 |V| level |
  16. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  17. Figure 1: Sample Audio Level Encoding Using the
  18. One-Byte Header Format
  19. 0 1 2 3
  20. 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
  21. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  22. | ID | len=1 |V| level | 0 (pad) |
  23. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  24. Figure 2: Sample Audio Level Encoding Using the
  25. Two-Byte Header Format
  26. */
  27. int rtp_ext_ssrc_audio_level_parse(const uint8_t* data, int bytes, uint8_t *activity, uint8_t *level)
  28. {
  29. if (bytes < 1)
  30. return -1;
  31. *activity = (data[0] & 0x80) ? 1 : 0;
  32. *level = data[0] & 0x7f;
  33. return 0;
  34. }
  35. int rtp_ext_ssrc_audio_level_write(uint8_t* data, int bytes, uint8_t activity, uint8_t level)
  36. {
  37. if (bytes < 1)
  38. return -1;
  39. data[0] = (activity ? 0x80 : 0) | level;
  40. return 1;
  41. }