No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

67 líneas
2.6KB

  1. #include "rtp-ext.h"
  2. #include "rtp-util.h"
  3. #include <inttypes.h>
  4. #include <stdint.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <assert.h>
  8. #include <stdio.h>
  9. // https://webrtc.googlesource.com/src/+/refs/heads/main/docs/native-code/rtp-hdrext/transport-wide-cc-02/
  10. /*
  11. RTP header extension format
  12. Data layout overview
  13. Data layout of transport-wide sequence number 1-byte header + 2 bytes of data:
  14. 0 1 2
  15. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
  16. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  17. | ID | L=1 |transport-wide sequence number |
  18. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  19. Data layout of transport-wide sequence number and optional feedback request 1-byte header + 4 bytes of data:
  20. 0 1 2 3
  21. 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
  22. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  23. | ID | L=3 |transport-wide sequence number |T| seq count |
  24. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  25. |seq count cont.|
  26. +-+-+-+-+-+-+-+-+
  27. Data layout details
  28. The data is written in the following order,
  29. - transport-wide sequence number (16-bit unsigned integer)
  30. - feedback request (optional) (16-bit unsigned integer)
  31. If the extension contains two extra bytes for feedback request, this means that a feedback packet should be generated and sent immediately. The feedback request consists of a one-bit field giving the flag value T and a 15-bit field giving the sequence count as an unsigned number.
  32. - If the bit T is set the feedback packet must contain timing information.
  33. - seq count specifies how many packets of history that should be included in the feedback packet. If seq count is zero no feedback should be be generated, which is equivalent of sending the two-byte extension above. This is added as an option to allow for a fixed packet header size.
  34. */
  35. int rtp_ext_transport_wide_cc_parse(const uint8_t* data, int bytes, struct rtp_ext_transport_wide_cc_t *ext)
  36. {
  37. assert(bytes == 2 || bytes == 4);
  38. if (bytes < 2)
  39. return -1;
  40. memset(ext, 0, sizeof(*ext));
  41. ext->seq = rtp_read_uint16(data);
  42. if (bytes >= 4)
  43. {
  44. ext->t = (data[2] >> 7) & 0x01;
  45. ext->count = rtp_read_uint16(data + 2) & 0x7FFF;
  46. }
  47. return 0;
  48. }
  49. int rtp_ext_transport_wide_cc_write(uint8_t* data, int bytes, const struct rtp_ext_transport_wide_cc_t *ext)
  50. {
  51. if (bytes < 2)
  52. return -1;
  53. rtp_write_uint16(data, (uint16_t)ext->seq);
  54. if (bytes >= 4)
  55. rtp_write_uint16(data + 2, (uint16_t)(ext->t << 15) | (ext->count & 0x7FFF));
  56. return bytes >= 4 ? 4 : 2;
  57. }