| 1 |
#ifndef RIST_PROTO_RTP_H |
| 2 |
#define RIST_PROTO_RTP_H |
| 3 |
|
| 4 |
#include "common/attributes.h" |
| 5 |
#include <stdint.h> |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
#define RTCP_FB_HEADER_SIZE 12 |
| 84 |
|
| 85 |
#define PTYPE_RTCP_CUSTOM1 72 |
| 86 |
#define PTYPE_RTCP_CUSTOM2 73 |
| 87 |
#define PTYPE_RTCP_CUSTOM3 74 |
| 88 |
#define PTYPE_RTCP_CUSTOM4 75 |
| 89 |
#define PTYPE_RTCP_CUSTOM5 76 |
| 90 |
#define PTYPE_XR 77 |
| 91 |
|
| 92 |
#define PTYPE_SR 200 |
| 93 |
#define PTYPE_RR 201 |
| 94 |
#define PTYPE_SDES 202 |
| 95 |
#define PTYPE_NACK_CUSTOM 204 |
| 96 |
#define PTYPE_NACK_BITMASK 205 |
| 97 |
|
| 98 |
#define PTYPE_XR_LEGACY 207 |
| 99 |
|
| 100 |
#define NACK_FMT_BITMASK 1 |
| 101 |
#define NACK_FMT_RANGE 0 |
| 102 |
#define ECHO_REQUEST 2 |
| 103 |
#define ECHO_RESPONSE 3 |
| 104 |
|
| 105 |
#define RTCP_SDES_SIZE 10 |
| 106 |
#define RTP_MPEGTS_FLAGS 0x80 |
| 107 |
#define RTCP_SR_FLAGS 0x80 |
| 108 |
#define RTCP_RR_FULL_FLAGS 0x81 |
| 109 |
#define RTCP_SDES_FLAGS 0x81 |
| 110 |
#define RTCP_NACK_RANGE_FLAGS 0x80 |
| 111 |
#define RTCP_NACK_BITMASK_FLAGS 0x81 |
| 112 |
#define RTCP_ECHOEXT_REQ_FLAGS 0x82 |
| 113 |
#define RTCP_ECHOEXT_RESP_FLAGS 0x83 |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
#define RTP_PTYPE_MPEGTS (0x21) |
| 119 |
#define RTP_PTYPE_MPEGTS_CLOCKHZ (90000) |
| 120 |
#define RTP_PTYPE_RIST (21) |
| 121 |
#define RTP_PTYPE_RIST_CLOCKHZ (UINT16_MAX + 1) |
| 122 |
|
| 123 |
RIST_PACKED_STRUCT(rist_rtp_hdr,{ |
| 124 |
uint8_t flags; |
| 125 |
uint8_t payload_type; |
| 126 |
uint16_t seq; |
| 127 |
uint32_t ts; |
| 128 |
uint32_t ssrc; |
| 129 |
}) |
| 130 |
|
| 131 |
RIST_PACKED_STRUCT(rist_rtp_hdr_ext, { |
| 132 |
uint16_t identifier; |
| 133 |
uint16_t length; |
| 134 |
uint8_t flags; |
| 135 |
uint8_t npd_bits; |
| 136 |
uint16_t seq_ext; |
| 137 |
}) |
| 138 |
|
| 139 |
RIST_PACKED_STRUCT(rist_protocol_hdr,{ |
| 140 |
uint16_t src_port; |
| 141 |
uint16_t dst_port; |
| 142 |
struct rist_rtp_hdr rtp; |
| 143 |
}) |
| 144 |
|
| 145 |
RIST_PACKED_STRUCT(rist_rtp_nack_record,{ |
| 146 |
uint16_t start; |
| 147 |
uint16_t extra; |
| 148 |
}) |
| 149 |
|
| 150 |
RIST_PACKED_STRUCT(rist_rtcp_hdr,{ |
| 151 |
uint8_t flags; |
| 152 |
uint8_t ptype; |
| 153 |
uint16_t len; |
| 154 |
uint32_t ssrc; |
| 155 |
}) |
| 156 |
|
| 157 |
RIST_PACKED_STRUCT(rist_rtcp_nack_range,{ |
| 158 |
uint8_t flags; |
| 159 |
uint8_t ptype; |
| 160 |
uint16_t len; |
| 161 |
uint32_t ssrc_source; |
| 162 |
uint8_t name[4]; |
| 163 |
}) |
| 164 |
|
| 165 |
RIST_PACKED_STRUCT(rist_rtcp_nack_bitmask,{ |
| 166 |
uint8_t flags; |
| 167 |
uint8_t ptype; |
| 168 |
uint16_t len; |
| 169 |
uint32_t ssrc_source; |
| 170 |
uint32_t ssrc; |
| 171 |
}) |
| 172 |
|
| 173 |
RIST_PACKED_STRUCT(rist_rtcp_echoext, { |
| 174 |
uint8_t flags; |
| 175 |
uint8_t ptype; |
| 176 |
uint16_t len; |
| 177 |
uint32_t ssrc; |
| 178 |
uint8_t name[4]; |
| 179 |
uint32_t ntp_msw; |
| 180 |
uint32_t ntp_lsw; |
| 181 |
uint32_t delay; |
| 182 |
}) |
| 183 |
|
| 184 |
RIST_PACKED_STRUCT(rist_rtcp_sr_pkt,{ |
| 185 |
struct rist_rtcp_hdr rtcp; |
| 186 |
uint32_t ntp_msw; |
| 187 |
uint32_t ntp_lsw; |
| 188 |
uint32_t rtp_ts; |
| 189 |
uint32_t sender_pkts; |
| 190 |
uint32_t sender_bytes; |
| 191 |
}) |
| 192 |
|
| 193 |
RIST_PACKED_STRUCT(rist_rtcp_rr_pkt,{ |
| 194 |
struct rist_rtcp_hdr rtcp; |
| 195 |
uint32_t recv_ssrc; |
| 196 |
uint8_t fraction_lost; |
| 197 |
uint8_t cumulative_pkt_loss_msb; |
| 198 |
uint16_t cumulative_pkt_loss_lshw; |
| 199 |
uint32_t highest_seq; |
| 200 |
uint32_t jitter; |
| 201 |
uint32_t lsr; |
| 202 |
uint32_t dlsr; |
| 203 |
}) |
| 204 |
|
| 205 |
RIST_PACKED_STRUCT(rist_rtcp_rr_empty_pkt,{ |
| 206 |
struct rist_rtcp_hdr rtcp; |
| 207 |
}) |
| 208 |
|
| 209 |
RIST_PACKED_STRUCT(rist_rtcp_sdes_pkt,{ |
| 210 |
struct rist_rtcp_hdr rtcp; |
| 211 |
uint8_t cname; |
| 212 |
uint8_t name_len; |
| 213 |
char udn[1]; |
| 214 |
}) |
| 215 |
|
| 216 |
RIST_PACKED_STRUCT(rist_rtcp_xr_block_hdr, { |
| 217 |
uint8_t type; |
| 218 |
uint8_t reserved; |
| 219 |
uint16_t length; |
| 220 |
}) |
| 221 |
|
| 222 |
RIST_PACKED_STRUCT(rist_rtcp_xr_rrtrb, { |
| 223 |
uint8_t block_type; |
| 224 |
uint8_t reserved; |
| 225 |
uint16_t length; |
| 226 |
uint32_t ntp_msw; |
| 227 |
uint32_t ntp_lsw; |
| 228 |
}) |
| 229 |
|
| 230 |
RIST_PACKED_STRUCT(rist_rtcp_xr_dlrr, { |
| 231 |
uint8_t block_type; |
| 232 |
uint8_t reserved; |
| 233 |
uint16_t length; |
| 234 |
uint32_t ssrc; |
| 235 |
uint32_t lrr; |
| 236 |
uint32_t delay; |
| 237 |
}) |
| 238 |
|
| 239 |
static inline uint32_t get_rtp_ts_clock(uint8_t ptype) { |
| 240 |
uint32_t clock = 0; |
| 241 |
switch(ptype) { |
| 242 |
case RTP_PTYPE_MPEGTS: |
| 243 |
case 14: |
| 244 |
case 25: |
| 245 |
case 26: |
| 246 |
case 28: |
| 247 |
case 31: |
| 248 |
case 32: |
| 249 |
case 34: |
| 250 |
clock = RTP_PTYPE_MPEGTS_CLOCKHZ; |
| 251 |
break; |
| 252 |
case 0: |
| 253 |
case 3: |
| 254 |
case 4: |
| 255 |
case 5: |
| 256 |
case 7: |
| 257 |
case 8: |
| 258 |
case 9: |
| 259 |
case 12: |
| 260 |
case 13: |
| 261 |
case 15: |
| 262 |
case 18: |
| 263 |
clock = 8000; |
| 264 |
break; |
| 265 |
case 16: |
| 266 |
clock = 11025; |
| 267 |
break; |
| 268 |
case 6: |
| 269 |
clock = 16000; |
| 270 |
break; |
| 271 |
case 17: |
| 272 |
clock = 22050; |
| 273 |
break; |
| 274 |
case 10: |
| 275 |
case 11: |
| 276 |
clock = 44100; |
| 277 |
break; |
| 278 |
default: |
| 279 |
clock = 0; |
| 280 |
break; |
| 281 |
} |
| 282 |
return clock; |
| 283 |
} |
| 284 |
|
| 285 |
#endif |