Closed Bug 770384 Opened 14 years ago Closed 14 years ago

ICE integration into SIPCC

Categories

(Core :: WebRTC: Signaling, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: emannion, Assigned: emannion)

Details

(Whiteboard: [qa-])

Attachments

(1 file, 8 obsolete files)

Attached patch ICE SDP Patch 1 (obsolete) — — Splinter Review
Covers adding ICE attributes into SIPCC SDP and the parsing of ICE attributes.
Comment on attachment 638546 [details] [diff] [review] ICE SDP Patch 1 Review of attachment 638546 [details] [diff] [review]: ----------------------------------------------------------------- ::: media/webrtc/signaling/src/sipcc/core/ccapp/ccapi_call_info.c @@ +801,5 @@ > media_track_tbl = data->media_track_tbl; > stream->stream_id = media_track_tbl->stream_id; > stream->track[0].ref_id = media_track_tbl->track[0].ref_id; > stream->track[0].video = media_track_tbl->track[0].video; > + */ What does this code do? Why does commenting it out help? ::: media/webrtc/signaling/src/sipcc/core/gsm/gsm_sdp.c @@ +1334,5 @@ > + sdp_attr_e sdp_attr = SDP_ATTR_ICECANDIDATE; > + uint16_t a_instance = 0; > + > + if (media->level) { > + (void) sdp_add_new_attr(sdp_p, media->level, 0, sdp_attr, &a_instance); Why are you ignoring errors here? @@ +1338,5 @@ > + (void) sdp_add_new_attr(sdp_p, media->level, 0, sdp_attr, &a_instance); > + } else { > + /* Just in case that there is no level defined, add to the session */ > + (void) sdp_add_new_attr(sdp_p, SDP_SESSION_LEVEL, 0, sdp_attr, > + &a_instance); It's not legal to have session level candidates, so I think this is an error. @@ +1341,5 @@ > + (void) sdp_add_new_attr(sdp_p, SDP_SESSION_LEVEL, 0, sdp_attr, > + &a_instance); > + } > + > + sdp_attr_set_ice_candidate(sdp_p, media->level, 0, a_instance, candidate); Check for errors. @@ +1363,5 @@ > +gsmsdp_get_ice_candidates (uint16_t level, void *sdp_p, char* ice_candidate) > +{ > + uint16_t num_a_lines = 0; > + uint16_t i; > + char localCandidates[1024] = {'\0'}; // re-think size or array Fixed-size arrays are not a good idea. Also, how am I going to separate the candidates later? @@ +1367,5 @@ > + char localCandidates[1024] = {'\0'}; // re-think size or array > + char* candidate; > + > + (void) sdp_attr_num_instances(sdp_p, level, 0, SDP_ATTR_ICECANDIDATE, > + &num_a_lines); Check for errors. @@ +1370,5 @@ > + (void) sdp_attr_num_instances(sdp_p, level, 0, SDP_ATTR_ICECANDIDATE, > + &num_a_lines); > + > + for (i = 0; i < num_a_lines; i++) { > + sdp_attr_get_ice_candidate (sdp_p, level, 0, (uint16_t) (i + 1), candidate); aren't you about to strcpy into an unassigned pointer? @@ +1372,5 @@ > + > + for (i = 0; i < num_a_lines; i++) { > + sdp_attr_get_ice_candidate (sdp_p, level, 0, (uint16_t) (i + 1), candidate); > + //sstrncat(localCandidates, candidate, sizeof(candidate)); > + //strlib_free(candidate); This code not finished. @@ +3702,5 @@ > > + // <emannion> So far I think this is where we can get the available remote ICE > + // candidates. gsmsdp_get_ice_candidates not fully working yet, very close > + char* candidates; > + gsmsdp_get_ice_candidates (i, sdp_p->dest_sdp, candidates); Again, you seem to be passing in an uninitialized pointer. ::: media/webrtc/signaling/src/sipcc/core/gsm/h/fsm.h @@ +429,5 @@ > > char peerconnection[PC_HANDLE_SIZE]; /* A handle to the peerconnection */ > boolean peerconnection_set; > + > + char ice_ufrag[ICE_STRING_SIZE]; // <emannion> got to Comment not complete. Also, use C-style /**/ comments in C code. ::: media/webrtc/signaling/src/sipcc/core/includes/ccapi.h @@ +58,5 @@ > #define CC_CALL_NONE CC_CALL_TYPE_NONE > #define CC_CALL_INCOMING CC_CALL_TYPE_INCOMING > #define SDP_SIZE 1024 // must increase this > #define PC_HANDLE_SIZE (1 + (sizeof(void *) * 2)) > +#define ICE_STRING_SIZE 81 // <emannion> maybe this could be better Where is it even necessary? ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr.c @@ +5132,5 @@ > + > +sdp_result_e sdp_build_attr_ice_candidate (sdp_t *sdp_p, sdp_attr_t *attr_p, > + char **ptr, u16 len) > +{ > + u16 i, j; These variables don't seem to be used. @@ +5140,5 @@ > + /* Find ptr to the end of the buf for recalculating len remaining. */ > + endbuf_p = *ptr + len; > + > + /* Get a pointer to the capability structure. */ > + cap_p = attr_p->attr.cap_p; This also seems not to be used. @@ +5142,5 @@ > + > + /* Get a pointer to the capability structure. */ > + cap_p = attr_p->attr.cap_p; > + > + *ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%s\r\n", I'm confused by how you are handling length here. In 5141 you assigned endbuf_p = *ptr + len. You haven't changed either of these, so isn't this MAX(...) expression just "len"? @@ +5162,5 @@ > + tmp); > + } > + > + ptr = sdp_getnextstrtok(ptr, tmp, "\r", &result); > + if (result != SDP_SUCCESS){ What if there is stuff after the "\n"? since ptr isn't returned, I don't see how that gets accessed. Also, what the heck is a '\r' doing in here? @@ +5163,5 @@ > + } > + > + ptr = sdp_getnextstrtok(ptr, tmp, "\r", &result); > + if (result != SDP_SUCCESS){ > + return (SDP_SUCCESS); Why not SDP_FAILURE? @@ +5180,5 @@ > + } > +} > + > + > +sdp_result_e sdp_build_attr_ice_pwd (sdp_t *sdp_p, sdp_attr_t *attr_p, There seems to be a lot of cutting and pasting here. AFAICT sdp_build_attr_ice_pwd is exactly the same as build_attr_ice_candidate and ice_ufrag. Wouldn't it make more sense to have a function called sdp_result_build_attr_ice and then three wrappers that just grabbed the appropriate structure element and passed it to that generic function? Same thing applies to the parsers. ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr_access.c @@ +3981,5 @@ > + sdp_p->conf_p->num_invalid_param++; > + return (SDP_INVALID_PARAMETER); > + } else { > + if (ice_candidate) { > + sstrncpy(attr_p->attr.ice_candidate, ice_candidate, Check for over-long candidates here. @@ +3997,5 @@ > + * level The level to check for the attribute. > + * cap_num The capability number associated with the > + * attribute if any. If none, should be zero. > + * inst_num The attribute instance number to check. > + * Returns: ice candidate. Returns TRUE or FALSE. Wh not sdp_result_e.
(In reply to Eric Rescorla from comment #1) > Comment on attachment 638546 [details] [diff] [review] > ICE SDP Patch > > Review of attachment 638546 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: media/webrtc/signaling/src/sipcc/core/ccapp/ccapi_call_info.c > @@ +801,5 @@ > > media_track_tbl = data->media_track_tbl; > > stream->stream_id = media_track_tbl->stream_id; > > stream->track[0].ref_id = media_track_tbl->track[0].ref_id; > > stream->track[0].video = media_track_tbl->track[0].video; > > + */ > > What does this code do? Why does commenting it out help? That was a first pass at passing remote stream info up to the PeerConnection Interface. It needs about two hours to finish out. > > ::: media/webrtc/signaling/src/sipcc/core/gsm/gsm_sdp.c > @@ +1334,5 @@ > > + sdp_attr_e sdp_attr = SDP_ATTR_ICECANDIDATE; > > + uint16_t a_instance = 0; > > + > > + if (media->level) { > > + (void) sdp_add_new_attr(sdp_p, media->level, 0, sdp_attr, &a_instance); > > Why are you ignoring errors here? I am following other very similar functions in this file, maybe I should do them differently then? > > @@ +1338,5 @@ > > + (void) sdp_add_new_attr(sdp_p, media->level, 0, sdp_attr, &a_instance); > > + } else { > > + /* Just in case that there is no level defined, add to the session */ > > + (void) sdp_add_new_attr(sdp_p, SDP_SESSION_LEVEL, 0, sdp_attr, > > + &a_instance); > > It's not legal to have session level candidates, so I think this is an error. Changed. > > @@ +1341,5 @@ > > + (void) sdp_add_new_attr(sdp_p, SDP_SESSION_LEVEL, 0, sdp_attr, > > + &a_instance); > > + } > > + > > + sdp_attr_set_ice_candidate(sdp_p, media->level, 0, a_instance, candidate); > > Check for errors. I can do, but that will different from other such functions in this file. > > @@ +1363,5 @@ > > +gsmsdp_get_ice_candidates (uint16_t level, void *sdp_p, char* ice_candidate) > > +{ > > + uint16_t num_a_lines = 0; > > + uint16_t i; > > + char localCandidates[1024] = {'\0'}; // re-think size or array > > Fixed-size arrays are not a good idea. Also, how am I going to separate the > candidates later? Changed using an array of pointers now. > > @@ +1367,5 @@ > > + char localCandidates[1024] = {'\0'}; // re-think size or array > > + char* candidate; > > + > > + (void) sdp_attr_num_instances(sdp_p, level, 0, SDP_ATTR_ICECANDIDATE, > > + &num_a_lines); > > Check for errors. > > @@ +1370,5 @@ > > + (void) sdp_attr_num_instances(sdp_p, level, 0, SDP_ATTR_ICECANDIDATE, > > + &num_a_lines); > > + > > + for (i = 0; i < num_a_lines; i++) { > > + sdp_attr_get_ice_candidate (sdp_p, level, 0, (uint16_t) (i + 1), candidate); > > aren't you about to strcpy into an unassigned pointer? Fixed > > @@ +1372,5 @@ > > + > > + for (i = 0; i < num_a_lines; i++) { > > + sdp_attr_get_ice_candidate (sdp_p, level, 0, (uint16_t) (i + 1), candidate); > > + //sstrncat(localCandidates, candidate, sizeof(candidate)); > > + //strlib_free(candidate); > > This code not finished. Finished > > @@ +3702,5 @@ > > > > + // <emannion> So far I think this is where we can get the available remote ICE > > + // candidates. gsmsdp_get_ice_candidates not fully working yet, very close > > + char* candidates; > > + gsmsdp_get_ice_candidates (i, sdp_p->dest_sdp, candidates); > > Again, you seem to be passing in an uninitialized pointer. Fixed. > > ::: media/webrtc/signaling/src/sipcc/core/gsm/h/fsm.h > @@ +429,5 @@ > > > > char peerconnection[PC_HANDLE_SIZE]; /* A handle to the peerconnection */ > > boolean peerconnection_set; > > + > > + char ice_ufrag[ICE_STRING_SIZE]; // <emannion> got to > > Comment not complete. Also, use C-style /**/ comments in C code. Ok, but I find C ctyle comments a pain when commenting a large block around them > > ::: media/webrtc/signaling/src/sipcc/core/includes/ccapi.h > @@ +58,5 @@ > > #define CC_CALL_NONE CC_CALL_TYPE_NONE > > #define CC_CALL_INCOMING CC_CALL_TYPE_INCOMING > > #define SDP_SIZE 1024 // must increase this > > #define PC_HANDLE_SIZE (1 + (sizeof(void *) * 2)) > > +#define ICE_STRING_SIZE 81 // <emannion> maybe this could be better > > Where is it even necessary? > > ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr.c > @@ +5132,5 @@ > > + > > +sdp_result_e sdp_build_attr_ice_candidate (sdp_t *sdp_p, sdp_attr_t *attr_p, > > + char **ptr, u16 len) > > +{ > > + u16 i, j; > > These variables don't seem to be used. removed. > > @@ +5140,5 @@ > > + /* Find ptr to the end of the buf for recalculating len remaining. */ > > + endbuf_p = *ptr + len; > > + > > + /* Get a pointer to the capability structure. */ > > + cap_p = attr_p->attr.cap_p; > > This also seems not to be used. Your right, fixed now. > > @@ +5142,5 @@ > > + > > + /* Get a pointer to the capability structure. */ > > + cap_p = attr_p->attr.cap_p; > > + > > + *ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "%s\r\n", > > I'm confused by how you are handling length here. > > In 5141 you assigned endbuf_p = *ptr + len. You haven't changed either of > these, so isn't this MAX(...) expression just "len"? > > @@ +5162,5 @@ > > + tmp); > > + } > > + > > + ptr = sdp_getnextstrtok(ptr, tmp, "\r", &result); > > + if (result != SDP_SUCCESS){ > > What if there is stuff after the "\n"? > > since ptr isn't returned, I don't see how that gets accessed. Also, what the > heck is a '\r' doing in here? From 4566 The sequence CRLF (0x0d0a) is used to end a record, although parsers SHOULD be tolerant and also accept records terminated with a single newline character. maybe \r is not the best way of doing this? Any ideas what is? > > @@ +5163,5 @@ > > + } > > + > > + ptr = sdp_getnextstrtok(ptr, tmp, "\r", &result); > > + if (result != SDP_SUCCESS){ > > + return (SDP_SUCCESS); > > Why not SDP_FAILURE? This just means the SDP does not contain that attribute, not an error I think. > > @@ +5180,5 @@ > > + } > > +} > > + > > + > > +sdp_result_e sdp_build_attr_ice_pwd (sdp_t *sdp_p, sdp_attr_t *attr_p, > > There seems to be a lot of cutting and pasting here. AFAICT > sdp_build_attr_ice_pwd is exactly the same as build_attr_ice_candidate and > ice_ufrag. > > Wouldn't it make more sense to have a function called > sdp_result_build_attr_ice and then three wrappers that just grabbed the > appropriate structure element and passed it to that generic function? > > Same thing applies to the parsers. Done, using the code samples you sent me, thanks > > ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr_access.c > @@ +3981,5 @@ > > + sdp_p->conf_p->num_invalid_param++; > > + return (SDP_INVALID_PARAMETER); > > + } else { > > + if (ice_candidate) { > > + sstrncpy(attr_p->attr.ice_candidate, ice_candidate, > > Check for over-long candidates here. How long for a candidate? > > @@ +3997,5 @@ > > + * level The level to check for the attribute. > > + * cap_num The capability number associated with the > > + * attribute if any. If none, should be zero. > > + * inst_num The attribute instance number to check. > > + * Returns: ice candidate. > > Returns TRUE or FALSE. Wh not sdp_result_e. Done
Attached patch SDP ICE Patch 2 (obsolete) — — Splinter Review
I have not implemented all the error checking yet from your review comment, as per my comments to your review, I may do this on your request. I added placeholders for comments using this text '<emannion>' use the brackets. You will also see where I think you need to grab the ufrag and pwd. I am a little worried about the method, gsmsdp_get_ice_candidates can you maybe have a look at it for me, It also leaks.
Attachment #638546 - Attachment is obsolete: true
Attachment #639132 - Flags: feedback?(ekr)
Attached patch ICE SDP Patch 3 (obsolete) — — Splinter Review
Attachment #639132 - Attachment is obsolete: true
Attachment #639132 - Flags: feedback?(ekr)
Attachment #639200 - Flags: feedback?(ekr)
Comment on attachment 639200 [details] [diff] [review] ICE SDP Patch 3 Review of attachment 639200 [details] [diff] [review]: ----------------------------------------------------------------- ::: media/webrtc/signaling/src/sipcc/core/gsm/gsm_sdp.c @@ +1335,5 @@ > + uint16_t num_a_lines = 0; > + uint16_t i; > + char* candidate = (char *)cpr_malloc(ICE_STRING_SIZE); > + > + if (!(*candidate)) candidate, not *candidate *candidate is the first byte of the buffer. @@ +1336,5 @@ > + uint16_t i; > + char* candidate = (char *)cpr_malloc(ICE_STRING_SIZE); > + > + if (!(*candidate)) > + return; you can't return without a value from a function returning bool. @@ +1340,5 @@ > + return; > + > + *candidate_ctp = 0; > + > + (void) sdp_attr_num_instances(sdp_p, level, 0, SDP_ATTR_ICECANDIDATE, &num_a_lines); Error check needed here. @@ +1345,5 @@ > + > + *candidatesp = (char **)cpr_malloc(num_a_lines * sizeof(char *)); > + > + if (!(*candidatesp)) > + return; return value again. @@ +1348,5 @@ > + if (!(*candidatesp)) > + return; > + > + for (i = 0; i < num_a_lines; i++) { > + (*candidatesp)[i] = (char *) cpr_malloc(ICE_STRING_SIZE + 1); Check the return value of this malloc. @@ +1376,5 @@ > +{ > + sdp_attr_e sdp_attr = SDP_ATTR_ICECANDIDATE; > + uint16_t a_instance = 0; > + > + sdp_add_new_attr(sdp_p, media->level, 0, sdp_attr, &a_instance); Can't this generate errors. @@ +1378,5 @@ > + uint16_t a_instance = 0; > + > + sdp_add_new_attr(sdp_p, media->level, 0, sdp_attr, &a_instance); > + > + sdp_attr_set_ice_candidate(sdp_p, media->level, 0, a_instance, candidate); And this. @@ +4453,5 @@ > + > + if (sdpmode == FALSE) { > + > + /* > + * Ensure that there is at least one audio line. We're going to need to remove this at some point, since not having audio is totally permissible ::: media/webrtc/signaling/src/sipcc/core/gsm/h/fsm.h @@ +245,5 @@ > int32_t profile_level; > > void *video; > + > + char **candidatesp; Do these get freed somewhere? ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr.c @@ +5137,5 @@ > + > + /* Find ptr to the end of the buf for recalculating len remaining. */ > + endbuf_p = *ptr + len; > + > + *ptr += snprintf(*ptr, MAX((endbuf_p - *ptr), 0), "a=%s\r\n", str); What does endbuf_p do here? @@ +5170,5 @@ > + } > + > + > + /* <emannion> I'm not sure if "\r\n" is the best token here */ > + ptr = sdp_getnextstrtok(ptr, tmp, "\r\n", &result); I'm very confused as to what the heck these tokens are doing here. Why are there embedded newlines? ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr_access.c @@ +3982,5 @@ > + sizeof(attr_p->attr.ice_candidate)); > + > + return (SDP_SUCCESS); > + } else { > + if (sdp_p->debug_flag[SDP_DEBUG_ERRORS]) { How could this happen? Isn't it an internal error? @@ +4005,5 @@ > + * ice_candidate ICE candidate for this m= line. > + * Returns: SDP_SUCCESS Attribute param was set successfully. > + * SDP_INVALID_PARAMETER Specified attribute is not defined. > + */ > +sdp_result_e sdp_attr_set_ice_candidate(void *sdp_ptr, u16 level, Is there a way to refactor these functions so there's not so much cutting and pasting?
Attached patch ICE SDP Patch 4 (obsolete) — — Splinter Review
I read TFM and have added better error handling and some more code tidy up.
Attachment #639200 - Attachment is obsolete: true
Attachment #639200 - Flags: feedback?(ekr)
Attachment #639303 - Flags: feedback?(ekr)
Attachment #638546 - Attachment description: ICE SDP Patch → ICE SDP Patch 1
Attachment #639132 - Attachment description: SDP ICE Patch → SDP ICE Patch 2
Attachment #639200 - Attachment description: ICE SDP Patch → ICE SDP Patch 3
Attachment #639303 - Attachment description: ICE SDP Patch → ICE SDP Patch 4
Attached patch ICE SDP Patch (obsolete) — — Splinter Review
search for <emannion> to find API points
Attachment #639303 - Attachment is obsolete: true
Attachment #639303 - Flags: feedback?(ekr)
Attachment #639421 - Flags: feedback?(ekr)
Wire up outgoing ice
Attachment #639421 - Attachment is obsolete: true
Attachment #639421 - Flags: feedback?(ekr)
Attached patch Refactor for simplicity (obsolete) — — Splinter Review
Attachment #639672 - Flags: feedback?(emannion)
Attachment #639539 - Attachment is obsolete: true
Comment on attachment 639672 [details] [diff] [review] Refactor for simplicity Review of attachment 639672 [details] [diff] [review]: ----------------------------------------------------------------- Nice work, how come you are not using gsmsdp_get_ice_attribute ::: media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp @@ +664,5 @@ > + return; > + strncpy(pwd, attrs[i].c_str(), attrs[i].size()); > + pwd[attrs[i].size()] = 0; > + } > + Are the two strings ice-ufrag and ice-pwd always lower case if not maybe worth doing a case insensitive compare, but I guess they are alwasy lower case. ::: media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c @@ +3175,5 @@ > + if (cause != CC_CAUSE_OK) { > + ui_set_remote_description(evSetRemoteDescError, line, call_id, dcb->caller_id.call_instance_id, NULL, PC_SETREMOTEDESCERROR); > + return (SM_RC_END); > + } > + I agree, I think gsmsdp_negotiate_offer_sdp needs to go here, I also have it in createAnswer which may need to be removed. Inside in the negotiate functions when iterating the remote m= lines the code is expecting media streams with audio first then video, I assume this will need to be freed up. i.e. in gsmsdp_negotiate_media_lines This is because when SIPCC generates SDP it always creates two media streams, the forst one audio and the second one video, see, gsmsdp_get_media_capability and the g_media_table pre-filles array.
This patch has working call setup and ICE negotiation but no media yet. I am currently seeing the occasional crash in shutdown, I think due to some odd interactions with the final shutdown logic and my replacemnet of AutoLock. However, they do not seem to affect non-shutdown operation.
Attachment #639672 - Attachment is obsolete: true
Attachment #639672 - Flags: feedback?(emannion)
Attachment #640069 - Flags: feedback?(emannion)
> > > + char ice_ufrag[ICE_STRING_SIZE]; // <emannion> got to > > > > Comment not complete. Also, use C-style /**/ comments in C code. > > Ok, but I find C ctyle comments a pain when commenting a large block around > them Understood but the problem is that they aren't portable to all C variants. IIRC they came in with C99. I usually use #if 0 for this (and it's what's recommended in the portability guidelines: https://developer.mozilla.org/index.php?title=en/C%2B%2B_Portability_Guide#Use_.23if_0_rather_than_comments_to_temporarily_kill_blocks_of_code [Not that I subscribe to everything in the portability guidelines, since it's sorta outdated, but.. ] > From 4566 > > The sequence CRLF (0x0d0a) is used to end a record, although parsers SHOULD > be > tolerant and also accept records terminated with a single newline > character. > > maybe \r is not the best way of doing this? Any ideas what is? I think this is right. I didn't realize that the parser didn't give you complete terminated lines. Ugh. > > > + ptr = sdp_getnextstrtok(ptr, tmp, "\r", &result); > > > + if (result != SDP_SUCCESS){ > > > + return (SDP_SUCCESS); > > > > Why not SDP_FAILURE? > > This just means the SDP does not contain that attribute, not an error I > think. Is that right? I haven't traced through the code, but I wonder if it means that the string just terminates early. > > ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr_access.c > > @@ +3981,5 @@ > > > + sdp_p->conf_p->num_invalid_param++; > > > + return (SDP_INVALID_PARAMETER); > > > + } else { > > > + if (ice_candidate) { > > > + sstrncpy(attr_p->attr.ice_candidate, ice_candidate, > > > > Check for over-long candidates here. > > How long for a candidate? I think my patch removed a lot of this stuff...
(In reply to enda mannion (:emannion) from comment #10) > Comment on attachment 639672 [details] [diff] [review] > Refactor for simplicity > > Review of attachment 639672 [details] [diff] [review]: > ----------------------------------------------------------------- > > Nice work, how come you are not using gsmsdp_get_ice_attribute Just wasn't done yet. > ::: media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp > @@ +664,5 @@ > > + return; > > + strncpy(pwd, attrs[i].c_str(), attrs[i].size()); > > + pwd[attrs[i].size()] = 0; > > + } > > + > > Are the two strings ice-ufrag and ice-pwd always lower case if not maybe > worth doing a case insensitive compare, but I guess they are alwasy lower > case. I believe they are. Can you check the SDP spec? > Inside in the negotiate functions when iterating the remote m= lines the > code is expecting media streams with audio first then video, I assume this > will need to be freed up. i.e. in gsmsdp_negotiate_media_lines > This is because when SIPCC generates SDP it always creates two media > streams, the forst one audio and the second one video, see, > gsmsdp_get_media_capability and the g_media_table pre-filles array. So these assumptions in SIPCC are going to be a problem. When you go to refactor things to interrogate the media streams, were going to need to fix that.
(In reply to Eric Rescorla from comment #13) > (In reply to enda mannion (:emannion) from comment #10) > > Comment on attachment 639672 [details] [diff] [review] > > Refactor for simplicity > > > > Review of attachment 639672 [details] [diff] [review]: > > ----------------------------------------------------------------- > > > > Nice work, how come you are not using gsmsdp_get_ice_attribute > > Just wasn't done yet. > > > > > ::: media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp > > @@ +664,5 @@ > > > + return; > > > + strncpy(pwd, attrs[i].c_str(), attrs[i].size()); > > > + pwd[attrs[i].size()] = 0; > > > + } > > > + > > > > Are the two strings ice-ufrag and ice-pwd always lower case if not maybe > > worth doing a case insensitive compare, but I guess they are alwasy lower > > case. > > I believe they are. Can you check the SDP spec? I checked both 4566 5245 and saw nothing to suggest the SDP value should be lower case only, eventhough I don't remember seeing uppercase in any of my media negotiation debugging. In 4566 the type field is mandated as lower case but not the value field. <type>=<value> > > > > Inside in the negotiate functions when iterating the remote m= lines the > > code is expecting media streams with audio first then video, I assume this > > will need to be freed up. i.e. in gsmsdp_negotiate_media_lines > > This is because when SIPCC generates SDP it always creates two media > > streams, the forst one audio and the second one video, see, > > gsmsdp_get_media_capability and the g_media_table pre-filles array. > > So these assumptions in SIPCC are going to be a problem. When you go to > refactor things to interrogate the media streams, were going to need to > fix that.
Comment on attachment 640069 [details] [diff] [review] Working call setup and ICE handshake (no media) Review of attachment 640069 [details] [diff] [review]: ----------------------------------------------------------------- ::: media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp @@ +392,5 @@ > + default: > + // TODO(enda) > + // A lot of states not handled here!!!!! > + // Do something here? > + break; Is handling non JSEP states relavant? There are many states what will not occur in SDPMode. But this needs some work true. @@ +439,5 @@ > + mIceState = kIceConnected; > + if (mPCObserver) { > + mPCObserver->OnStateChange(PeerConnectionObserver::kIceState); > + } > +} Do we also need to call into SIPCC here to tell it to start media flowing or is that handled outside SIPCC in mtransport? ::: media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h @@ +115,5 @@ > + // ICE events > + void IceGatheringCompleted(NrIceCtx *ctx); > + void IceCompleted(NrIceCtx *ctx); > + void IceStreamReady(NrIceMediaStream *stream); > + Let me know if you want me to wire these into SIPCC. ::: media/webrtc/signaling/src/sipcc/core/common/config_parser.c @@ +493,5 @@ > + // Debugging suggests that alghouth *line* is 1-indexed, the config entries > + // are 1-indexed. See. config_get_line_id(). > + // You may want to rewrite this in terms of config_get_line_id(). > + // Please check -- EKR > + for(line = 0; line < MAX_REG_LINES; line++) { The line index was always based on a number from the downloaded config file that was 1 in my case, but I guess now we don't rely on that. ::: media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c @@ +2852,5 @@ > + vcmGetIceParams(dcb->peerconnection, &ufrag, &ice_pwd); > + if (!ufrag || !ice_pwd) { > + ui_create_offer(evCreateOfferError, line, call_id, dcb->caller_id.call_instance_id, NULL); > + return (fsmdef_release(fcb, cause, FALSE)); > + } Maybe we should pass an error code up to the PC interface as a new param on ui_create_offer similarly to ui_set_local_description for example. This also applies to ui_create_answer. The new param would be just after the NULL which is where SDP goes. @@ +2951,5 @@ > part->content_id = NULL; > + > + vcmGetIceParams(dcb->peerconnection, &ufrag, &ice_pwd); > + if (!ufrag || !ice_pwd) { > + ui_create_offer(evCreateOfferError, line, call_id, dcb->caller_id.call_instance_id, NULL); This should be ui_create_answer, the wrong callback will get fired at the UI. @@ +2965,5 @@ > + free(ice_pwd); > + > + > + /* TODO(ekr@rtfm.com): Why is this necessary? it seems to be to get the > + ice-pwd created, but we get an sdp value in any case, so, hmmmm.... */ I don't totally follow you here, are you saying the SDP had been created already in setRemoteDesc(OFFER). If that is the case, at time of writing I was not fully sure SRD(OFFER) would certainly get called before createAnswer. @@ +3025,5 @@ > return (SM_RC_END); > } > > if (dcb == NULL) { > + /* TODO(emannion): how can this happen? shouldn't createoffer/createanswer have made the dcb? */ At the time I wrote this I didn't see anything in the JSEP spec that mandated createoffer or createanswer being called before setLocalDesc, eventhough it makes sence that they should. @@ +3053,5 @@ > ui_set_local_description(evSetLocalDescError, line, call_id, dcb->caller_id.call_instance_id, NULL, PC_SETLOCALDESCERROR); > return (SM_RC_END); > } > > //compare and fail if different I should have used C style comments, my bad. @@ +3063,1 @@ > fsm_change_state(fcb, __LINE__, FSMDEF_S_CALL_SENT); I am not totally sure we should be using the original call states but shuld replace them with new JSEP states. ::: media/webrtc/signaling/src/sipcc/core/gsm/gsm_sdp.c @@ +5476,5 @@ > + fsmdef_dcb_t *dcb_p = fcb_p->dcb; > + cc_sdp_t *sdp_p = dcb_p->sdp; > + fsmdef_media_t *media; > + int level; > + short result; local variable miss-alignment (I hope I come up with better comments) @@ +5493,5 @@ > + > + vcm_res = vcmSetIceSessionParams(dcb_p->peerconnection, ufrag, pwd); > + if (vcm_res) > + return (CC_CAUSE_ERROR); > + How are we reporting if the ufrag or pwd are incorrect, will CC_CAUSE_ERROR always mean this only? @@ +5514,5 @@ > + candidate_ct = 0; > + result = gsmsdp_get_ice_attributes (SDP_ATTR_ICE_CANDIDATE, media->level, sdp_p->dest_sdp, > + &candidates, &candidate_ct); > + if(!result) > + return (CC_CAUSE_ERROR); If you return here you have a memory leak, wait until you free the candidates. ::: media/webrtc/signaling/src/sipcc/core/gsm/h/fsm.h @@ +429,5 @@ > > char peerconnection[PC_HANDLE_SIZE]; /* A handle to the peerconnection */ > boolean peerconnection_set; > + > + char ice_ufrag[ICE_STRING_SIZE]; /* <emannion> got to check array size */ Are you happy with ICE_STRING_SIZE being 81? I based this on another string size in the attrib structure. ::: media/webrtc/signaling/src/sipcc/core/gsm/lsm.c @@ +1045,5 @@ > media->local_dynamic_payload_type_value = media->payload; > } > > roapproxy = 0; > config_get_value(CFGID_ROAPPROXY, &roapproxy, sizeof(roapproxy)); I think we should remove any of the old roap proxy demo code and use sdpmode instead. @@ +1047,5 @@ > > roapproxy = 0; > config_get_value(CFGID_ROAPPROXY, &roapproxy, sizeof(roapproxy)); > + if (dcb->peerconnection) { > + fprintf(stderr, "******** THIS IS WHERE MEDIA WOULD START ******** \n"); Do we need to have something similar in lsm_tx_start, a place where we start media. How will this get called, is it as a result of the ICE completed call into SIPCC? ::: media/webrtc/signaling/src/sipcc/core/includes/ccapi.h @@ +63,1 @@ > IS 81 ok? Its based on other string attrib sizes. ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr.c @@ +5149,5 @@ > + char tmp[SDP_MAX_STRING_LEN]; > + > + /* <emannion> I'm not sure if "\r\n" is the best token here */ > + ptr = sdp_getnextstrtok(ptr, tmp, "\r\n", &result); > + if (result != SDP_SUCCESS){ I'm thinking we should only have "\r" here as per spec 4566. The sequence CRLF (0x0d0a) is used to end a record, although parsers SHOULD be tolerant and also accept records terminated with a single newline character.
Comment on attachment 640069 [details] [diff] [review] Working call setup and ICE handshake (no media) Review of attachment 640069 [details] [diff] [review]: ----------------------------------------------------------------- i've responded to your comments. ::: media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp @@ +392,5 @@ > + default: > + // TODO(enda) > + // A lot of states not handled here!!!!! > + // Do something here? > + break; At minimum i think we need to go through each state and add them to this switch statement with a comment about why. One of the reasons I turned this into a switch was so that unhandled cases were reported by the compiler. @@ +439,5 @@ > + mIceState = kIceConnected; > + if (mPCObserver) { > + mPCObserver->OnStateChange(PeerConnectionObserver::kIceState); > + } > +} Not at this callback point. The individual streams also have indicators of when they are ready. However, I intend to handle those events in vcm. ::: media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h @@ +115,5 @@ > + // ICE events > + void IceGatheringCompleted(NrIceCtx *ctx); > + void IceCompleted(NrIceCtx *ctx); > + void IceStreamReady(NrIceMediaStream *stream); > + I'm not sure what you mean... PC can get these directly from the ICE stack. ::: media/webrtc/signaling/src/sipcc/core/common/config_parser.c @@ +493,5 @@ > + // Debugging suggests that alghouth *line* is 1-indexed, the config entries > + // are 1-indexed. See. config_get_line_id(). > + // You may want to rewrite this in terms of config_get_line_id(). > + // Please check -- EKR > + for(line = 0; line < MAX_REG_LINES; line++) { ? The comment in the code is incompetent, but here's the executive summary. The configuration data table index for line L is CFGID_XXX + L -1. So if you set these directly, then you're actually setting line L + 1. ::: media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c @@ +2852,5 @@ > + vcmGetIceParams(dcb->peerconnection, &ufrag, &ice_pwd); > + if (!ufrag || !ice_pwd) { > + ui_create_offer(evCreateOfferError, line, call_id, dcb->caller_id.call_instance_id, NULL); > + return (fsmdef_release(fcb, cause, FALSE)); > + } I think it would be better to just abandon the event structure for these calls and go to callbacks. It will make the code simpler and then we can punt this problem. @@ +2951,5 @@ > part->content_id = NULL; > + > + vcmGetIceParams(dcb->peerconnection, &ufrag, &ice_pwd); > + if (!ufrag || !ice_pwd) { > + ui_create_offer(evCreateOfferError, line, call_id, dcb->caller_id.call_instance_id, NULL); Did I mention I hate cut-and-paste. @@ +2965,5 @@ > + free(ice_pwd); > + > + > + /* TODO(ekr@rtfm.com): Why is this necessary? it seems to be to get the > + ice-pwd created, but we get an sdp value in any case, so, hmmmm.... */ I'm really not sure. I just cargo-culted this code. Can you straighten this out? @@ +3025,5 @@ > return (SM_RC_END); > } > > if (dcb == NULL) { > + /* TODO(emannion): how can this happen? shouldn't createoffer/createanswer have made the dcb? */ well, at this point setPeerConnection makes the dcb, so perhaps we can remove this. @@ +3063,1 @@ > fsm_change_state(fcb, __LINE__, FSMDEF_S_CALL_SENT); WFM. This was your code :) ::: media/webrtc/signaling/src/sipcc/core/gsm/gsm_sdp.c @@ +1343,5 @@ > + GSM_ERR_MSG("enumerating ICE attributes failed\n"); > + return FALSE; > + } > + > + *ice_attribs = (char **)cpr_malloc(num_a_lines * sizeof(char *)); Better to use calloc here to avoid confusion. Or alternately set all the values to NULL after we check for allocation failure. @@ +1365,5 @@ > + strncpy((*ice_attribs)[i], ice_attrib, strlen(ice_attrib) + 1); > + (*attributes_ctp)++; > + } > + > + return TRUE; This function needs to be rewritten so that it will free all the allocated memory on failure. @@ +5476,5 @@ > + fsmdef_dcb_t *dcb_p = fcb_p->dcb; > + cc_sdp_t *sdp_p = dcb_p->sdp; > + fsmdef_media_t *media; > + int level; > + short result; Yah. I can fix or you can. @@ +5493,5 @@ > + > + vcm_res = vcmSetIceSessionParams(dcb_p->peerconnection, ufrag, pwd); > + if (vcm_res) > + return (CC_CAUSE_ERROR); > + More generally, I'm not sure what the error convention is here. There are a lot of things that can go wrong and SIPCC doesn't seme to know how to meaningfully distinguish them. Thoughts? @@ +5514,5 @@ > + candidate_ct = 0; > + result = gsmsdp_get_ice_attributes (SDP_ATTR_ICE_CANDIDATE, media->level, sdp_p->dest_sdp, > + &candidates, &candidate_ct); > + if(!result) > + return (CC_CAUSE_ERROR); Generally I prefer to have the get_attributes function only return results of there is a success. Saves thinking about partly-constructed objects. So let's fix it there instead. I.e., the guarantee is that gsmsdp_get_ice_attributes returns either a full object or nothing. ::: media/webrtc/signaling/src/sipcc/core/gsm/lsm.c @@ +1047,5 @@ > > roapproxy = 0; > config_get_value(CFGID_ROAPPROXY, &roapproxy, sizeof(roapproxy)); > + if (dcb->peerconnection) { > + fprintf(stderr, "******** THIS IS WHERE MEDIA WOULD START ******** \n"); My current intention is to actually just to wire up the mtransport to the MediaSessionConduit as soon as we have done the negotiation. Then we'll just let packets flow as soon as ICE is ready with no intervention from SIPCC. This was just a placeholder because it wasn't safe to call the existing vcm function and crypt's code wasn't ready yet. ::: media/webrtc/signaling/src/sipcc/core/includes/ccapi.h @@ +63,1 @@ > I'm not excited about it. Is there some way we can make it dynamically allocated? ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr.c @@ +5149,5 @@ > + char tmp[SDP_MAX_STRING_LEN]; > + > + /* <emannion> I'm not sure if "\r\n" is the best token here */ > + ptr = sdp_getnextstrtok(ptr, tmp, "\r\n", &result); > + if (result != SDP_SUCCESS){ If I understand the strtok function, it will stop on a sequence of [\r\n]*. So, if bare \n is legal you need to have both here.
(In reply to Eric Rescorla from comment #16) > Comment on attachment 640069 [details] [diff] [review] > Working call setup and ICE handshake (no media) > > Review of attachment 640069 [details] [diff] [review]: > ----------------------------------------------------------------- > > i've responded to your comments. > > ::: media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp > @@ +392,5 @@ > > + default: > > + // TODO(enda) > > + // A lot of states not handled here!!!!! > > + // Do something here? > > + break; > > At minimum i think we need to go through each state and add them to this > switch statement > with a comment about why. One of the reasons I turned this into a switch was > so that > unhandled cases were reported by the compiler. For now I added this to my SIPCC cleanup TODO list. > > @@ +439,5 @@ > > + mIceState = kIceConnected; > > + if (mPCObserver) { > > + mPCObserver->OnStateChange(PeerConnectionObserver::kIceState); > > + } > > +} > > Not at this callback point. The individual streams also have indicators of > when they are ready. However, I intend to handle those events in vcm. > > ::: media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h > @@ +115,5 @@ > > + // ICE events > > + void IceGatheringCompleted(NrIceCtx *ctx); > > + void IceCompleted(NrIceCtx *ctx); > > + void IceStreamReady(NrIceMediaStream *stream); > > + > > I'm not sure what you mean... PC can get these directly from the ICE stack. > > ::: media/webrtc/signaling/src/sipcc/core/common/config_parser.c > @@ +493,5 @@ > > + // Debugging suggests that alghouth *line* is 1-indexed, the config entries > > + // are 1-indexed. See. config_get_line_id(). > > + // You may want to rewrite this in terms of config_get_line_id(). > > + // Please check -- EKR > > + for(line = 0; line < MAX_REG_LINES; line++) { > > ? > > The comment in the code is incompetent, but here's the executive summary. > > The configuration data table index for line L is CFGID_XXX + L -1. So if you > set these directly, then you're actually setting line L + 1. > > ::: media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c > @@ +2852,5 @@ > > + vcmGetIceParams(dcb->peerconnection, &ufrag, &ice_pwd); > > + if (!ufrag || !ice_pwd) { > > + ui_create_offer(evCreateOfferError, line, call_id, dcb->caller_id.call_instance_id, NULL); > > + return (fsmdef_release(fcb, cause, FALSE)); > > + } > > I think it would be better to just abandon the event structure for these > calls and go to callbacks. It will make the code simpler and then we can > punt this problem. For a future patch then. > > @@ +2951,5 @@ > > part->content_id = NULL; > > + > > + vcmGetIceParams(dcb->peerconnection, &ufrag, &ice_pwd); > > + if (!ufrag || !ice_pwd) { > > + ui_create_offer(evCreateOfferError, line, call_id, dcb->caller_id.call_instance_id, NULL); > > Did I mention I hate cut-and-paste. Fixed now. > > @@ +2965,5 @@ > > + free(ice_pwd); > > + > > + > > + /* TODO(ekr@rtfm.com): Why is this necessary? it seems to be to get the > > + ice-pwd created, but we get an sdp value in any case, so, hmmmm.... */ > > I'm really not sure. I just cargo-culted this code. Can you straighten this > out? My debugging seem ok, I updated the comment in the code. > > @@ +3025,5 @@ > > return (SM_RC_END); > > } > > > > if (dcb == NULL) { > > + /* TODO(emannion): how can this happen? shouldn't createoffer/createanswer have made the dcb? */ > > well, at this point setPeerConnection makes the dcb, so perhaps we can > remove this. This is fine but what if the client calls CreateOffer before Initilize, I think we need code in the interface to make sure init is called then we can be more sure the DCB exists. I may leave this for now and add it to the TODOs. > > @@ +3063,1 @@ > > fsm_change_state(fcb, __LINE__, FSMDEF_S_CALL_SENT); > > WFM. This was your code :) > > ::: media/webrtc/signaling/src/sipcc/core/gsm/gsm_sdp.c > @@ +1343,5 @@ > > + GSM_ERR_MSG("enumerating ICE attributes failed\n"); > > + return FALSE; > > + } > > + > > + *ice_attribs = (char **)cpr_malloc(num_a_lines * sizeof(char *)); > > Better to use calloc here to avoid confusion. Or alternately set all the > values to NULL after we check for allocation failure. > > @@ +1365,5 @@ > > + strncpy((*ice_attribs)[i], ice_attrib, strlen(ice_attrib) + 1); > > + (*attributes_ctp)++; > > + } > > + > > + return TRUE; > > This function needs to be rewritten so that it will free all the allocated > memory on failure. > > @@ +5476,5 @@ > > + fsmdef_dcb_t *dcb_p = fcb_p->dcb; > > + cc_sdp_t *sdp_p = dcb_p->sdp; > > + fsmdef_media_t *media; > > + int level; > > + short result; > > Yah. I can fix or you can. done now. > > @@ +5493,5 @@ > > + > > + vcm_res = vcmSetIceSessionParams(dcb_p->peerconnection, ufrag, pwd); > > + if (vcm_res) > > + return (CC_CAUSE_ERROR); > > + > > More generally, I'm not sure what the error convention is here. There are a > lot of things that can go wrong and SIPCC doesn't seme to know how to > meaningfully distinguish them. Thoughts? We can extend the cc_causes_t enum in cc_constants.h, with new errors for ICE. This header file is accessible throughout SIPCC. > > @@ +5514,5 @@ > > + candidate_ct = 0; > > + result = gsmsdp_get_ice_attributes (SDP_ATTR_ICE_CANDIDATE, media->level, sdp_p->dest_sdp, > > + &candidates, &candidate_ct); > > + if(!result) > > + return (CC_CAUSE_ERROR); > > Generally I prefer to have the get_attributes function only return results > of there is a success. Saves thinking about partly-constructed objects. So > let's fix it there instead. I.e., the guarantee is that > gsmsdp_get_ice_attributes returns either a full object or nothing. I made a change to gsmsdp_get_ice_attributes it will only allocate memory if there is an attribute count > 0, else it will return, I return TRUE as I don't think it is a failure. > > ::: media/webrtc/signaling/src/sipcc/core/gsm/lsm.c > @@ +1047,5 @@ > > > > roapproxy = 0; > > config_get_value(CFGID_ROAPPROXY, &roapproxy, sizeof(roapproxy)); > > + if (dcb->peerconnection) { > > + fprintf(stderr, "******** THIS IS WHERE MEDIA WOULD START ******** \n"); > > My current intention is to actually just to wire up the mtransport to the > MediaSessionConduit as soon as we have done the negotiation. Then we'll just > let packets flow as soon as ICE is ready with no intervention from SIPCC. > This was just a placeholder because it wasn't safe to call the existing vcm > function and crypt's code wasn't ready yet. > > ::: media/webrtc/signaling/src/sipcc/core/includes/ccapi.h > @@ +63,1 @@ > > > > I'm not excited about it. Is there some way we can make it dynamically > allocated? I dod not touch this for now. > > ::: media/webrtc/signaling/src/sipcc/core/sdp/sdp_attr.c > @@ +5149,5 @@ > > + char tmp[SDP_MAX_STRING_LEN]; > > + > > + /* <emannion> I'm not sure if "\r\n" is the best token here */ > > + ptr = sdp_getnextstrtok(ptr, tmp, "\r\n", &result); > > + if (result != SDP_SUCCESS){ > > If I understand the strtok function, it will stop on a sequence of [\r\n]*. > So, if bare \n is legal you need to have both here.
Attachment #640069 - Attachment is obsolete: true
Attachment #640069 - Flags: feedback?(emannion)
Attachment #640277 - Flags: feedback?(ekr)
Comment on attachment 640277 [details] [diff] [review] ICE SDP Patch no media Review of attachment 640277 [details] [diff] [review]: ----------------------------------------------------------------- ::: media/webrtc/signaling/src/sipcc/core/gsm/gsm_sdp.c @@ +1353,5 @@ > + > + if (!(*ice_attribs)) > + return FALSE; > + > + *attributes_ctp = 0; Zero all the pointers to make freeing work. @@ +1363,5 @@ > + GSM_ERR_MSG("Failed to retrieve ICE attribute\n"); > + cpr_free(ice_attribs); > + return FALSE; > + } > + (*ice_attribs)[i] = (char *) cpr_malloc(strlen(ice_attrib) + 1); This is a potential memory leak. What happens if we allocate one of the values but not another? We end up with a bogus array. If we return any error, we need to free the entire array.
Pushed to Alder/transport_integration - https://hg.mozilla.org/projects/alder/rev/59965a747070
QA Contact: jsmith
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Whiteboard: [qa-]
Attachment #640277 - Flags: feedback?(ekr)
Assignee: nobody → emannion
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: