@@ -58,7 +58,11 @@ typedef struct RTCContext {
58
58
/* The ICE username and pwd from remote server. */
59
59
char * ice_ufrag_remote ;
60
60
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
+ */
62
66
char * ice_protocol ;
63
67
int ice_priority ;
64
68
char * ice_host ;
@@ -372,9 +376,7 @@ static int parse_answer(AVFormatContext *s)
372
376
int i ;
373
377
RTCContext * rtc = s -> priv_data ;
374
378
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 );
378
380
if (!pb ) {
379
381
av_log (s , AV_LOG_ERROR , "Failed to alloc AVIOContext for answer: %s" , rtc -> sdp_answer );
380
382
ret = AVERROR (ENOMEM );
@@ -383,13 +385,11 @@ static int parse_answer(AVFormatContext *s)
383
385
384
386
for (i = 0 ; !avio_feof (pb ); i ++ ) {
385
387
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 ) {
388
389
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 ) {
391
391
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 ) {
393
393
ptr = av_stristr (ptr , "udp" );
394
394
if (ptr && av_stristr (ptr , "host" )) {
395
395
char protocol [17 ], host [129 ];
@@ -403,14 +403,13 @@ static int parse_answer(AVFormatContext *s)
403
403
}
404
404
405
405
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 );
407
408
ret = AVERROR (EINVAL );
408
409
goto end ;
409
410
}
410
411
411
- av_freep (& rtc -> ice_protocol );
412
412
rtc -> ice_protocol = av_strdup (protocol );
413
- av_freep (& rtc -> ice_host );
414
413
rtc -> ice_host = av_strdup (host );
415
414
rtc -> ice_priority = priority ;
416
415
rtc -> ice_port = port ;
0 commit comments