Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

77 řádky
3.3KB

  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/video-timing
  10. /*
  11. SDP "a= name": "video-timing" ; this is also used in client/cloud signaling.
  12. Wire format: 1-byte extension, 13 bytes of data. Total 14 bytes extra per packet (plus 1-3 padding byte in some cases, plus shared 4 bytes for all extensions present: 2 byte magic word 0xBEDE, 2 byte # of extensions).
  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. | ID | len=12| flags | encode start ms delta |
  17. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  18. | encode finish ms delta | packetizer finish ms delta |
  19. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  20. | pacer exit ms delta | network timestamp ms delta |
  21. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  22. | network2 timestamp ms delta |
  23. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  24. First byte is a flags field. Defined flags:
  25. - 0x01 - extension is set due to timer.
  26. - 0x02 - extension is set because the frame is larger than usual.
  27. Both flags may be set at the same time. All remaining 6 bits are reserved and should be ignored.
  28. Next, 6 timestamps are stored as 16-bit values in big-endian order, representing delta from the capture time of a packet in ms. Timestamps are, in order:
  29. - Encode start.
  30. - Encode finish.
  31. - Packetization complete.
  32. - Last packet left the pacer.
  33. - Reserved for network.
  34. - Reserved for network (2).
  35. Pacer timestamp should be updated inside the RTP packet by pacer component when the last packet (containing the extension) is sent to the network. Last two, reserved timstamps, are not set by the sender but are reserved in packet for any in-network RTP stream processor to modify.
  36. Notes: Extension shoud be present only in the last packet of video frames. If attached to other packets it should be ignored.
  37. */
  38. int rtp_ext_video_timing_parse(const uint8_t* data, int bytes, struct rtp_ext_video_timing_t *ext)
  39. {
  40. assert(bytes == 13);
  41. if (bytes < 13)
  42. return -1;
  43. memset(ext, 0, sizeof(*ext));
  44. ext->flags = data[0];
  45. ext->encode_start = rtp_read_uint16(data + 1);
  46. ext->encode_finish = rtp_read_uint16(data + 3);
  47. ext->packetization_complete = rtp_read_uint16(data + 5);
  48. ext->last_packet_left_the_pacer = rtp_read_uint16(data + 7);
  49. ext->network_timestamp = rtp_read_uint16(data + 9);
  50. ext->network_timestamp2 = rtp_read_uint16(data + 11);
  51. return 0;
  52. }
  53. int rtp_ext_video_timing_write(uint8_t* data, int bytes, const struct rtp_ext_video_timing_t *ext)
  54. {
  55. if (bytes < 13)
  56. return -1;
  57. data[0] = (uint8_t)ext->flags;
  58. rtp_write_uint16(data + 1, ext->encode_start);
  59. rtp_write_uint16(data + 3, ext->encode_finish);
  60. rtp_write_uint16(data + 5, ext->packetization_complete);
  61. rtp_write_uint16(data + 7, ext->last_packet_left_the_pacer);
  62. rtp_write_uint16(data + 9, ext->network_timestamp);
  63. rtp_write_uint16(data + 11, ext->network_timestamp2);
  64. return 13;
  65. }