Skip to content

Commit

Permalink
WHIP: Refine code.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 22, 2023
1 parent 2e26baf commit 48d93eb
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions libavformat/rtcenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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];
Expand All @@ -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;
Expand Down

0 comments on commit 48d93eb

Please sign in to comment.