diff --git a/libavformat/rtcenc.c b/libavformat/rtcenc.c index 3abc85f52a246..d68ad1a713d3d 100644 --- a/libavformat/rtcenc.c +++ b/libavformat/rtcenc.c @@ -58,7 +58,11 @@ typedef struct RTCContext { /* The ICE username and pwd from remote server. */ char *ice_ufrag_remote; char *ice_pwd_remote; - /* The ICE candidate protocol, priority, host and port. */ + /** + * The ICE candidate protocol, priority, host and port. Note that only + * support one candidate for now. We will choose the first udp candidate. + * We will support multiple candidates in the future. + */ char *ice_protocol; int ice_priority; char *ice_host; @@ -372,9 +376,7 @@ static int parse_answer(AVFormatContext *s) int i; RTCContext *rtc = s->priv_data; - pb = avio_alloc_context( - (unsigned char *)rtc->sdp_answer, (int)strlen(rtc->sdp_answer), - AVIO_FLAG_READ, NULL, NULL, NULL, NULL); + pb = avio_alloc_context(rtc->sdp_answer, strlen(rtc->sdp_answer), AVIO_FLAG_READ, NULL, NULL, NULL, NULL); if (!pb) { av_log(s, AV_LOG_ERROR, "Failed to alloc AVIOContext for answer: %s", rtc->sdp_answer); ret = AVERROR(ENOMEM); @@ -383,13 +385,11 @@ static int parse_answer(AVFormatContext *s) for (i = 0; !avio_feof(pb); i++) { ff_get_chomp_line(pb, line, sizeof(line)); - if (av_strstart(line, "a=ice-ufrag:", &ptr)) { - av_freep(&rtc->ice_ufrag_remote); + if (av_strstart(line, "a=ice-ufrag:", &ptr) && !rtc->ice_ufrag_remote) { rtc->ice_ufrag_remote = av_strdup(ptr); - } else if (av_strstart(line, "a=ice-pwd:", &ptr)) { - av_freep(&rtc->ice_pwd_remote); + } else if (av_strstart(line, "a=ice-pwd:", &ptr) && !rtc->ice_pwd_remote) { rtc->ice_pwd_remote = av_strdup(ptr); - } else if (av_strstart(line, "a=candidate:", &ptr)) { + } else if (av_strstart(line, "a=candidate:", &ptr) && !rtc->ice_protocol) { ptr = av_stristr(ptr, "udp"); if (ptr && av_stristr(ptr, "host")) { char protocol[17], host[129]; @@ -403,14 +403,13 @@ static int parse_answer(AVFormatContext *s) } if (av_strcasecmp(protocol, "udp")) { - av_log(s, AV_LOG_ERROR, "Protocol %s is not supported by RTC, choose udp", protocol); + av_log(s, AV_LOG_ERROR, "Protocol %s is not supported by RTC, choose udp, line %d %s of %s", + protocol, i, line, rtc->sdp_answer); ret = AVERROR(EINVAL); goto end; } - av_freep(&rtc->ice_protocol); rtc->ice_protocol = av_strdup(protocol); - av_freep(&rtc->ice_host); rtc->ice_host = av_strdup(host); rtc->ice_priority = priority; rtc->ice_port = port;