|
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 | /**
|
@@ -417,6 +424,9 @@ static av_cold int initialize(AVFormatContext *s)
|
417 | 424 | seed = av_get_random_seed();
|
418 | 425 | av_lfg_init(&whip->rnd, seed);
|
419 | 426 |
|
| 427 | + /* 64-bit tie-breaker for ICE-CONTROLLING (RFC 8445 6.1.1) */ |
| 428 | + whip->ice_tie_breaker = ((uint64_t)av_lfg_get(&whip->rnd) << 32) | (uint64_t)av_lfg_get(&whip->rnd); |
| 429 | + |
420 | 430 | if (whip->pkt_size < ideal_pkt_size)
|
421 | 431 | av_log(whip, AV_LOG_WARNING, "pkt_size=%d(<%d) is too small, may cause packet loss\n",
|
422 | 432 | whip->pkt_size, ideal_pkt_size);
|
@@ -907,6 +917,8 @@ static int parse_answer(AVFormatContext *s)
|
907 | 917 | goto end;
|
908 | 918 | }
|
909 | 919 | }
|
| 920 | + } else if (av_strstart(line, "a=ice-lite", NULL)) { |
| 921 | + whip->ice_lite_remote = 1; |
910 | 922 | }
|
911 | 923 | }
|
912 | 924 |
|
@@ -998,6 +1010,22 @@ static int ice_create_request(AVFormatContext *s, uint8_t *buf, int buf_size, in
|
998 | 1010 | avio_wb16(pb, STUN_ATTR_USE_CANDIDATE); /* attribute type use-candidate */
|
999 | 1011 | avio_wb16(pb, 0); /* size of use-candidate */
|
1000 | 1012 |
|
| 1013 | + /** |
| 1014 | + * For ICE-lite peers we are *always* the controlling agent (RFC 8445 6.1.3.1). |
| 1015 | + * Add PRIORITY + ICE-CONTROLLING attributes. |
| 1016 | + */ |
| 1017 | + if (whip->ice_lite_remote) { |
| 1018 | + /* we are controlling, use host-candidate priority 126 << 24 | 65535 << 8 | 255 = 2130706431 */ |
| 1019 | + avio_wb16(pb, STUN_ATTR_PRIORITY); |
| 1020 | + avio_wb16(pb, 4); |
| 1021 | + avio_wb32(pb, 2130706431); |
| 1022 | + |
| 1023 | + avio_wb16(pb, STUN_ATTR_ICE_CONTROLLING); |
| 1024 | + avio_wb16(pb, 8); |
| 1025 | + avio_wb32(pb, (uint32_t)(whip->ice_tie_breaker >> 32)); |
| 1026 | + avio_wb32(pb, (uint32_t)(whip->ice_tie_breaker & 0xffffffff)); |
| 1027 | + } |
| 1028 | + |
1001 | 1029 | /* Build and update message integrity */
|
1002 | 1030 | avio_wb16(pb, STUN_ATTR_MESSAGE_INTEGRITY); /* attribute type message integrity */
|
1003 | 1031 | avio_wb16(pb, 20); /* size of message integrity */
|
|
0 commit comments