MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / ice_create_request

Function ice_create_request

libavformat/whip.c:1053–1135  ·  view source on GitHub ↗

* Creates and marshals an ICE binding request packet. * * This function creates and marshals an ICE binding request packet. The function only * generates the username attribute and does not include goog-network-info, * use-candidate. However, some of these attributes may be added in the future. * * @param s Pointer to the AVFormatContext * @param buf Pointer to memory buffer to store the re

Source from the content-addressed store, hash-verified

1051 * @return Returns 0 if successful or AVERROR_xxx if an error occurs.
1052 */
1053static int ice_create_request(AVFormatContext *s, uint8_t *buf, int buf_size, int *request_size)
1054{
1055 int ret, size, crc32;
1056 char username[128];
1057 AVIOContext *pb = NULL;
1058 AVHMAC *hmac = NULL;
1059 WHIPContext *whip = s->priv_data;
1060
1061 pb = avio_alloc_context(buf, buf_size, 1, NULL, NULL, NULL, NULL);
1062 if (!pb)
1063 return AVERROR(ENOMEM);
1064
1065 hmac = av_hmac_alloc(AV_HMAC_SHA1);
1066 if (!hmac) {
1067 ret = AVERROR(ENOMEM);
1068 goto end;
1069 }
1070
1071 /* Write 20 bytes header */
1072 avio_wb16(pb, 0x0001); /* STUN binding request */
1073 avio_wb16(pb, 0); /* length */
1074 avio_wb32(pb, STUN_MAGIC_COOKIE); /* magic cookie */
1075 avio_wb32(pb, av_lfg_get(&whip->rnd)); /* transaction ID */
1076 avio_wb32(pb, av_lfg_get(&whip->rnd)); /* transaction ID */
1077 avio_wb32(pb, av_lfg_get(&whip->rnd)); /* transaction ID */
1078
1079 /* The username is the concatenation of the two ICE ufrag */
1080 ret = snprintf(username, sizeof(username), "%s:%s", whip->ice_ufrag_remote, whip->ice_ufrag_local);
1081 if (ret <= 0 || ret >= sizeof(username)) {
1082 av_log(whip, AV_LOG_ERROR, "Failed to build username %s:%s, max=%zu, ret=%d\n",
1083 whip->ice_ufrag_remote, whip->ice_ufrag_local, sizeof(username), ret);
1084 ret = AVERROR(EIO);
1085 goto end;
1086 }
1087
1088 /* Write the username attribute */
1089 avio_wb16(pb, STUN_ATTR_USERNAME); /* attribute type username */
1090 avio_wb16(pb, ret); /* size of username */
1091 avio_write(pb, username, ret); /* bytes of username */
1092 ffio_fill(pb, 0, (4 - (ret % 4)) % 4); /* padding */
1093
1094 /* Write the use-candidate attribute */
1095 avio_wb16(pb, STUN_ATTR_USE_CANDIDATE); /* attribute type use-candidate */
1096 avio_wb16(pb, 0); /* size of use-candidate */
1097
1098 avio_wb16(pb, STUN_ATTR_PRIORITY);
1099 avio_wb16(pb, 4);
1100 avio_wb32(pb, STUN_HOST_CANDIDATE_PRIORITY);
1101
1102 avio_wb16(pb, STUN_ATTR_ICE_CONTROLLING);
1103 avio_wb16(pb, 8);
1104 avio_wb64(pb, whip->ice_tie_breaker);
1105
1106 /* Build and update message integrity */
1107 avio_wb16(pb, STUN_ATTR_MESSAGE_INTEGRITY); /* attribute type message integrity */
1108 avio_wb16(pb, 20); /* size of message integrity */
1109 ffio_fill(pb, 0, 20); /* fill with zero to directly write and skip it */
1110 size = avio_tell(pb);

Callers 2

ice_dtls_handshakeFunction · 0.85
whip_write_packetFunction · 0.85

Calls 15

avio_alloc_contextFunction · 0.85
avio_wb16Function · 0.85
avio_wb32Function · 0.85
av_lfg_getFunction · 0.85
av_logFunction · 0.85
avio_writeFunction · 0.85
ffio_fillFunction · 0.85
avio_wb64Function · 0.85
avio_tellFunction · 0.85
av_hmac_initFunction · 0.85
av_hmac_updateFunction · 0.85
av_hmac_finalFunction · 0.85

Tested by

no test coverage detected