Skip to content

Commit 48d93eb

Browse files
committed
WHIP: Refine code.
1 parent 2e26baf commit 48d93eb

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

libavformat/rtcenc.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ typedef struct RTCContext {
5858
/* The ICE username and pwd from remote server. */
5959
char *ice_ufrag_remote;
6060
char *ice_pwd_remote;
61-
/* The ICE candidate protocol, priority, host and port. */
61+
/**
62+
* The ICE candidate protocol, priority, host and port. Note that only
63+
* support one candidate for now. We will choose the first udp candidate.
64+
* We will support multiple candidates in the future.
65+
*/
6266
char *ice_protocol;
6367
int ice_priority;
6468
char *ice_host;
@@ -372,9 +376,7 @@ static int parse_answer(AVFormatContext *s)
372376
int i;
373377
RTCContext *rtc = s->priv_data;
374378

375-
pb = avio_alloc_context(
376-
(unsigned char *)rtc->sdp_answer, (int)strlen(rtc->sdp_answer),
377-
AVIO_FLAG_READ, NULL, NULL, NULL, NULL);
379+
pb = avio_alloc_context(rtc->sdp_answer, strlen(rtc->sdp_answer), AVIO_FLAG_READ, NULL, NULL, NULL, NULL);
378380
if (!pb) {
379381
av_log(s, AV_LOG_ERROR, "Failed to alloc AVIOContext for answer: %s", rtc->sdp_answer);
380382
ret = AVERROR(ENOMEM);
@@ -383,13 +385,11 @@ static int parse_answer(AVFormatContext *s)
383385

384386
for (i = 0; !avio_feof(pb); i++) {
385387
ff_get_chomp_line(pb, line, sizeof(line));
386-
if (av_strstart(line, "a=ice-ufrag:", &ptr)) {
387-
av_freep(&rtc->ice_ufrag_remote);
388+
if (av_strstart(line, "a=ice-ufrag:", &ptr) && !rtc->ice_ufrag_remote) {
388389
rtc->ice_ufrag_remote = av_strdup(ptr);
389-
} else if (av_strstart(line, "a=ice-pwd:", &ptr)) {
390-
av_freep(&rtc->ice_pwd_remote);
390+
} else if (av_strstart(line, "a=ice-pwd:", &ptr) && !rtc->ice_pwd_remote) {
391391
rtc->ice_pwd_remote = av_strdup(ptr);
392-
} else if (av_strstart(line, "a=candidate:", &ptr)) {
392+
} else if (av_strstart(line, "a=candidate:", &ptr) && !rtc->ice_protocol) {
393393
ptr = av_stristr(ptr, "udp");
394394
if (ptr && av_stristr(ptr, "host")) {
395395
char protocol[17], host[129];
@@ -403,14 +403,13 @@ static int parse_answer(AVFormatContext *s)
403403
}
404404

405405
if (av_strcasecmp(protocol, "udp")) {
406-
av_log(s, AV_LOG_ERROR, "Protocol %s is not supported by RTC, choose udp", protocol);
406+
av_log(s, AV_LOG_ERROR, "Protocol %s is not supported by RTC, choose udp, line %d %s of %s",
407+
protocol, i, line, rtc->sdp_answer);
407408
ret = AVERROR(EINVAL);
408409
goto end;
409410
}
410411

411-
av_freep(&rtc->ice_protocol);
412412
rtc->ice_protocol = av_strdup(protocol);
413-
av_freep(&rtc->ice_host);
414413
rtc->ice_host = av_strdup(host);
415414
rtc->ice_priority = priority;
416415
rtc->ice_port = port;

0 commit comments

Comments
 (0)