107 | | 1. '''generating initial offer''': this happens for outgoing calls, right after {{{media_create()}}} is called. The transport must initialize local SDP with default values (for ICE: include all candidates. For SRTP: include all crypto options). Normally it does not need to modify it's state. |
108 | | 1. '''generating initial answer''': this happens for incoming calls, also right after {{{media_create()}}} is called. The transport must inspect the remote SDP '''and'''' update the transport according to the info in remote SDP '''and''' update local SDP to be sent as answer. For example: disable the feature if remote SDP doesn't contain the required attributes. |
109 | | 1. '''generating subsequent offer''': this happens when local endpoint sends UPDATE or re-INVITE. In this case, the transport '''MUST NOT''' modify it's state, and rather just encode it's current state in the local SDP. |
110 | | 1. '''generating subsequent answer''': this happens when we receive UPDATE or re-INVITE. The processing is similar to ''generating initial answer'' above. |
| 111 | |
| 112 | |
| 113 | == Sample: ICE processing with the new media framework == |
| 114 | |
| 115 | === Generating initial offer === |
| 116 | |
| 117 | This happens in {{{encode_sdp()}}}, when ICE is not running and {{{rem_sdp==NULL}}. The transport will include all ICE candidates in the offer. |
| 118 | |
| 119 | === Generating initial answer === |
| 120 | |
| 121 | First, the transport detects whether the remote offer contains ICE in {{{media_create()}}}. If yes, it marks {{{use_ice=True}}}. |
| 122 | |
| 123 | Then in {{{encode_sdp()}}}, it checks if ICE is already running. Since this is an initial answer, ICE is not running yet. So it puts all candidates in the answer. In this function, the transport also checks for ICE-mismatch. |
| 124 | |
| 125 | === Generating subsequent offer === |
| 126 | |
| 127 | This happens in {{{encode_sdp()}}}, when ICE is already running and {{{rem_sdp==NULL}}}. The transport fills in the SDP with selected candidate only, one for each component. |
| 128 | |
| 129 | === Generating subsequent answer === |
| 130 | |
| 131 | This happens in {{{encode_sdp()}}}, when ICE is already running and {{{rem_sdp}}} is present. The transport detects for ICE '''restart''' condition or if the new offer no longer contains support for ICE. If ICE is restarted, then the internal ICE session will be destroyed and re-created. |
| 132 | |
| 133 | The populated SDP depends on whether ICE is restarted or not. If ICE doesn't restart, then the answer contains only the selected candidate from the valid pairs, just like ''Generating subsequent offer'' above. If ICE is restarted, then it will contains all candidates. |
| 134 | |
| 135 | === media_start() processing === |
| 136 | |
| 137 | When we send offer, this is where we will see the remote answer for the first time. So we do the "heavy" negotiation here. |
| 138 | |
| 139 | For ICE: |
| 140 | - Detect if answer contains ICE support ==> disable ICE |
| 141 | - Handle answer that contains ice-mismatch attribute ==> disable ICE |
| 142 | - Handle answer with transport address that doesn't match any candidates ==> disable ICE |
| 143 | - Handle when we set our role as Controlled, but answer contains ice-list ==> change role to Controlling |
| 144 | - If remote SDP contains the same ice-ufrag and ice-pwd as previous SDP, that means there's no change in the offer/answer, no need to do anything. |
| 145 | |
| 146 | If things are okay, start ICE negotiation. |