|
156 | 156 | /* STUN Attribute, comprehension-required range (0x0000-0x7FFF) */
|
157 | 157 | enum STUNAttr {
|
158 | 158 | STUN_ATTR_USERNAME = 0x0006, /// shared secret response/bind request
|
| 159 | + STUN_ATTR_PRIORITY = 0x0024, /// ICE controlling/controlled |
159 | 160 | STUN_ATTR_USE_CANDIDATE = 0x0025, /// bind request
|
160 | 161 | STUN_ATTR_MESSAGE_INTEGRITY = 0x0008, /// bind request/response
|
161 | 162 | STUN_ATTR_FINGERPRINT = 0x8028, /// rfc5389
|
| 163 | + STUN_ATTR_ICE_CONTROLLING = 0x802A, /// full agent talking to ice-lite |
162 | 164 | };
|
163 | 165 |
|
164 | 166 | enum WHIPState {
|
@@ -303,6 +305,11 @@ typedef struct WHIPContext {
|
303 | 305 | /* The certificate and private key used for DTLS handshake. */
|
304 | 306 | char* cert_file;
|
305 | 307 | char* key_file;
|
| 308 | + |
| 309 | + |
| 310 | + /* ICE-lite support */ |
| 311 | + int ice_lite_remote; |
| 312 | + uint64_t ice_tie_breaker; /* random 64-bit, for ICE-CONTROLLING */ |
306 | 313 | } WHIPContext;
|
307 | 314 |
|
308 | 315 | /**
|
@@ -412,6 +419,9 @@ static av_cold int initialize(AVFormatContext *s)
|
412 | 419 | seed = av_get_random_seed();
|
413 | 420 | av_lfg_init(&whip->rnd, seed);
|
414 | 421 |
|
| 422 | + /* 64-bit tie-breaker for ICE-CONTROLLING (RFC 8445 6.1.1) */ |
| 423 | + whip->ice_tie_breaker = ((uint64_t)av_lfg_get(&whip->rnd) << 32) | (uint64_t)av_lfg_get(&whip->rnd); |
| 424 | + |
415 | 425 | if (whip->pkt_size < ideal_pkt_size)
|
416 | 426 | av_log(whip, AV_LOG_WARNING, "WHIP: pkt_size=%d(<%d) is too small, may cause packet loss\n",
|
417 | 427 | whip->pkt_size, ideal_pkt_size);
|
@@ -894,6 +904,8 @@ static int parse_answer(AVFormatContext *s)
|
894 | 904 | goto end;
|
895 | 905 | }
|
896 | 906 | }
|
| 907 | + } else if (av_strstart(line, "a=ice-lite", NULL)) { |
| 908 | + whip->ice_lite_remote = 1; |
897 | 909 | }
|
898 | 910 | }
|
899 | 911 |
|
@@ -985,6 +997,22 @@ static int ice_create_request(AVFormatContext *s, uint8_t *buf, int buf_size, in
|
985 | 997 | avio_wb16(pb, STUN_ATTR_USE_CANDIDATE); /* attribute type use-candidate */
|
986 | 998 | avio_wb16(pb, 0); /* size of use-candidate */
|
987 | 999 |
|
| 1000 | + /** |
| 1001 | + * For ICE-lite peers we are *always* the controlling agent (RFC 8445 6.1.3.1). |
| 1002 | + * Add PRIORITY + ICE-CONTROLLING attributes. |
| 1003 | + */ |
| 1004 | + if (whip->ice_lite_remote) { |
| 1005 | + /* we are controlling, use host-candidate priority 126 << 24 | 65535 << 8 | 255 = 2130706431 */ |
| 1006 | + avio_wb16(pb, STUN_ATTR_PRIORITY); |
| 1007 | + avio_wb16(pb, 4); |
| 1008 | + avio_wb32(pb, 2130706431); |
| 1009 | + |
| 1010 | + avio_wb16(pb, STUN_ATTR_ICE_CONTROLLING); |
| 1011 | + avio_wb16(pb, 8); |
| 1012 | + avio_wb32(pb, (uint32_t)(whip->ice_tie_breaker >> 32)); |
| 1013 | + avio_wb32(pb, (uint32_t)(whip->ice_tie_breaker & 0xffffffff)); |
| 1014 | + } |
| 1015 | + |
988 | 1016 | /* Build and update message integrity */
|
989 | 1017 | avio_wb16(pb, STUN_ATTR_MESSAGE_INTEGRITY); /* attribute type message integrity */
|
990 | 1018 | avio_wb16(pb, 20); /* size of message integrity */
|
|
0 commit comments