Ticket #817: sdp_neg_cancel_remote_offer_r2669.patch

File sdp_neg_cancel_remote_offer_r2669.patch, 4.4 KB (added by bennylp, 15 years ago)

This patch adds capability to cancel remote offer state in the SDP negotiator. It's useful if application has set the remote offer, but then decides to reject the re-INVITE.

  • pjmedia/include/pjmedia/sdp_neg.h

     
    5050 *                                               
    5151 *                                              modify_local_offer() 
    5252 *     create_w_local_offer()  +-------------+  send_local_offer() 
    53  *     ----------------------->| LOCAL_OFFER |<----------------------- 
     53 *    /----------------------->| LOCAL_OFFER |<-----------------------\ 
    5454 *    |                        +-------------+______                  | 
    55  *    |                               |             \______ cancel()  | 
    56  *    |           set_remote_answer() |                    \______    | 
    57  *    |                               V                            \  | 
     55 *    |                               |             \_____________    | 
     56 *    |           set_remote_answer() |           cancel_offer()  \   | 
     57 *    |                               V                            v  | 
    5858 * +--+---+                     +-----------+     negotiate()     +-~----+ 
    5959 * | NULL |                     | WAIT_NEGO |-------------------->| DONE | 
    6060 * +------+                     +-----------+                     +------+ 
    61  *    |                               A                               | 
    62  *    |            set_local_answer() |                               | 
    63  *    |                               |                               | 
     61 *    |                               A      ______________________^  | 
     62 *    |            set_local_answer() |     / cancel_remote_offer()   | 
     63 *    |                               |    /                          | 
    6464 *    |                        +--------------+   set_remote_offer()  | 
    65  *     ----------------------->| REMOTE_OFFER |<---------------------- 
     65 *    \----------------------->| REMOTE_OFFER |<----------------------/ 
    6666 *     create_w_remote_offer() +--------------+ 
    6767 * 
    6868 * </pre> 
     
    255255 * Regardless of the return status of the #pjmedia_sdp_neg_negotiate(),  
    256256 * the negotiator state will move to PJMEDIA_SDP_NEG_STATE_DONE. 
    257257 * 
     258 * \subsection sdpneg_cancel_remote_offer Cancelling Remote Offer 
     259 *  
     260 * In other scenarios, application may want to reset the negotiator state 
     261 * after it has set a remote offer. Consider the following scenario: 
     262 *  - media has been established, and negotiator state is 
     263 *    PJMEDIA_SDP_NEG_STATE_DONE. 
     264 *  - application receives a new offer in re-INVITE, so in this case 
     265 *    it would call #pjmedia_sdp_neg_set_remote_offer(). 
     266 *  - the negotiator state moves to PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER 
     267 *  - application rejects the re-INVITE request with non-successful 
     268 *    final response. 
    258269 * 
     270 * In this case, application can call #pjmedia_sdp_neg_cancel_remote_offer() 
     271 * to reset the negotiator state back to PJMEDIA_SDP_NEG_STATE_DONE. 
    259272 */ 
    260273 
    261274#include <pjmedia/sdp.h> 
     
    634647 
    635648 
    636649/** 
     650 * Cancel previously received remote offer, and move negotiator state back 
     651 * to previous stable state ((PJMEDIA_SDP_NEG_STATE_DONE). The negotiator 
     652 * must be in PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER state. 
     653 * 
     654 * @param neg           The negotiator. 
     655 * 
     656 * @return              PJ_SUCCESS or the appropriate error code. 
     657 */ 
     658PJ_DECL(pj_status_t) pjmedia_sdp_neg_cancel_remote_offer(pjmedia_sdp_neg *neg); 
     659 
     660 
     661/** 
    637662 * Negotiate local and remote answer. Before calling this function, the 
    638663 * SDP negotiator must be in PJMEDIA_SDP_NEG_STATE_WAIT_NEGO state. 
    639664 * After calling this function, the negotiator state will move to 
  • pjmedia/src/pjmedia/sdp_neg.c

     
    13461346} 
    13471347 
    13481348 
     1349/* Cancel remote offer */ 
     1350PJ_DEF(pj_status_t) pjmedia_sdp_neg_cancel_remote_offer(pjmedia_sdp_neg *neg) 
     1351{ 
     1352    PJ_ASSERT_RETURN(neg, PJ_EINVAL); 
     1353 
     1354    /* Must be in LOCAL_OFFER state. */ 
     1355    PJ_ASSERT_RETURN(neg->state == PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER, 
     1356                     PJMEDIA_SDPNEG_EINSTATE); 
     1357 
     1358    /* Reset state to done */ 
     1359    neg->state = PJMEDIA_SDP_NEG_STATE_DONE; 
     1360 
     1361    /* Clear temporary SDP */ 
     1362    neg->neg_local_sdp = neg->neg_remote_sdp = NULL; 
     1363 
     1364    return PJ_SUCCESS; 
     1365} 
     1366 
     1367 
    13491368/* The best bit: SDP negotiation function! */ 
    13501369PJ_DEF(pj_status_t) pjmedia_sdp_neg_negotiate( pj_pool_t *pool, 
    13511370                                               pjmedia_sdp_neg *neg,