* 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
| 1051 | * @return Returns 0 if successful or AVERROR_xxx if an error occurs. |
| 1052 | */ |
| 1053 | static 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); |
no test coverage detected