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-csrc-audio-level.c 2.1KB

10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "rtp-ext.h"
  2. // https://datatracker.ietf.org/doc/html/rfc6465
  3. /*
  4. The audio level header extension carries the level of the audio in
  5. the RTP payload of the packet with which it is associated. This
  6. information is carried in an RTP header extension element as defined
  7. 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 2 and 3 show sample audio level encodings with
  11. each of these header formats.
  12. 0 1 2 3
  13. 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
  14. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  15. | ID | len=2 |0| level 1 |0| level 2 |0| level 3 |
  16. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  17. Figure 2: 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=3 |0| level 1 |0| level 2 |
  23. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  24. |0| level 3 | 0 (pad) | ...
  25. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  26. Figure 3: Sample Audio Level Encoding Using the
  27. Two-Byte Header Format
  28. */
  29. int rtp_ext_csrc_audio_level_parse(const uint8_t* data, int bytes, uint8_t levels[], int num)
  30. {
  31. int i;
  32. if (bytes < 1)
  33. return 0;
  34. for(i = 0; i < bytes && i < num; i++)
  35. levels[i] = data[0] & 0x7f;
  36. return i;
  37. }
  38. int rtp_ext_csrc_audio_level_write(uint8_t* data, int bytes, const uint8_t levels[], int num)
  39. {
  40. int i;
  41. if (bytes < num)
  42. return -1;
  43. for(i = 0; i < num; i++)
  44. data[i] = levels[i] & 0x7f;
  45. return num;
  46. }