Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

41 linhas
1.5KB

  1. #include "rtp-ext.h"
  2. #include <inttypes.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <assert.h>
  7. #include <stdio.h>
  8. // https://webrtc.googlesource.com/src/+/refs/heads/main/docs/native-code/rtp-hdrext/abs-send-time
  9. /*
  10. Wire format: 1-byte extension, 3 bytes of data. total 4 bytes extra per packet (plus shared 4 bytes for all extensions present: 2 byte magic word 0xBEDE, 2 byte # of extensions). Will in practice replace the ¡°toffset¡± extension so we should see no long term increase in traffic as a result.
  11. Encoding: Timestamp is in seconds, 24 bit 6.18 fixed point, yielding 64s wraparound and 3.8us resolution (one increment for each 477 bytes going out on a 1Gbps interface).
  12. Relation to NTP timestamps: abs_send_time_24 = (ntp_timestamp_64 >> 14) & 0x00ffffff ; NTP timestamp is 32 bits for whole seconds, 32 bits fraction of second.
  13. SDP "a= name": "abs-send-time" ; this is also used in client/cloud signaling.
  14. */
  15. int rtp_ext_abs_send_time_parse(const uint8_t* data, int bytes, uint64_t *timestamp)
  16. {
  17. if (bytes < 3)
  18. return -1;
  19. *timestamp = ((uint64_t)data[0] << 16) | ((uint64_t)data[1] << 8) | data[2];
  20. *timestamp = (*timestamp * 1000000) >> 18;
  21. return 0;
  22. }
  23. int rtp_ext_abs_send_time_write(uint8_t* data, int bytes, uint64_t timestamp)
  24. {
  25. if (bytes < 3)
  26. return -1;
  27. timestamp = (timestamp << 18) / 1000000;
  28. data[0] = (uint8_t)(timestamp >> 16);
  29. data[1] = (uint8_t)(timestamp >> 8);
  30. data[2] = (uint8_t)(timestamp >> 0);
  31. return 3;
  32. }