Changeset 140


Ignore:
Timestamp:
Feb 7, 2006 12:34:58 PM (18 years ago)
Author:
bennylp
Message:

Added STATE_REMOTE_OFFER state in negotiator

Location:
pjproject/trunk/pjmedia
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/errno.h

    r129 r140  
    150150/** 
    151151 * @hideinitializer 
     152 * No initial local SDP. 
     153 */ 
     154#define PJMEDIA_SDPNEG_ENOINITIAL   (PJMEDIA_ERRNO_START+41)    /* 220041 */ 
     155/** 
     156 * @hideinitializer 
    152157 * No currently active SDP. 
    153158 */ 
    154 #define PJMEDIA_SDPNEG_ENOACTIVE    (PJMEDIA_ERRNO_START+41)    /* 220041 */ 
     159#define PJMEDIA_SDPNEG_ENOACTIVE    (PJMEDIA_ERRNO_START+42)    /* 220042 */ 
     160/** 
     161 * @hideinitializer 
     162 * No current offer or answer. 
     163 */ 
     164#define PJMEDIA_SDPNEG_ENONEG       (PJMEDIA_ERRNO_START+43)    /* 220043 */ 
    155165/** 
    156166 * @hideinitializer 
    157167 * Media count mismatch in offer and answer. 
    158168 */ 
    159 #define PJMEDIA_SDPNEG_EMISMEDIA    (PJMEDIA_ERRNO_START+42)    /* 220042 */ 
     169#define PJMEDIA_SDPNEG_EMISMEDIA    (PJMEDIA_ERRNO_START+44)    /* 220044 */ 
    160170/** 
    161171 * @hideinitializer 
    162172 * Media type is different in the remote answer. 
    163173 */ 
    164 #define PJMEDIA_SDPNEG_EINVANSMEDIA (PJMEDIA_ERRNO_START+43)    /* 220043 */ 
     174#define PJMEDIA_SDPNEG_EINVANSMEDIA (PJMEDIA_ERRNO_START+45)    /* 220045 */ 
    165175/** 
    166176 * @hideinitializer 
    167177 * Transport type is different in the remote answer. 
    168178 */ 
    169 #define PJMEDIA_SDPNEG_EINVANSTP    (PJMEDIA_ERRNO_START+44)    /* 220044 */ 
     179#define PJMEDIA_SDPNEG_EINVANSTP    (PJMEDIA_ERRNO_START+46)    /* 220046 */ 
    170180/** 
    171181 * @hideinitializer 
    172182 * No common media payload is provided in the answer. 
    173183 */ 
    174 #define PJMEDIA_SDPNEG_EANSNOMEDIA  (PJMEDIA_ERRNO_START+45)    /* 220045 */ 
     184#define PJMEDIA_SDPNEG_EANSNOMEDIA  (PJMEDIA_ERRNO_START+47)    /* 220047 */ 
     185/** 
     186 * @hideinitializer 
     187 * No media is active after negotiation. 
     188 */ 
     189#define PJMEDIA_SDPNEG_ENOMEDIA     (PJMEDIA_ERRNO_START+48)    /* 220048 */ 
    175190 
    176191 
  • pjproject/trunk/pjmedia/include/pjmedia/sdp_neg.h

    r129 r140  
    4040 
    4141/** 
    42  * This enumeration describes SDP negotiation state. 
     42 * This enumeration describes SDP negotiation state. The negotiator state 
     43 * is illustrated in the following diagram. 
     44 *  
     45 * <pre> 
     46 *                                              reinit_local_offer() 
     47 *                                              modify_local_offer() 
     48 *     create_w_local_offer()  +-------------+  send_local_offer() 
     49 *     ----------------------->| LOCAL_OFFER |<----------------------- 
     50 *    |                        +-------------+                        | 
     51 *    |                               |                               | 
     52 *    |           set_remote_answer() |                               | 
     53 *    |                               V                               | 
     54 * +--+---+                     +-----------+     negotiate()     +------+ 
     55 * | NULL |                     | WAIT_NEGO |-------------------->| DONE | 
     56 * +------+                     +-----------+                     +------+ 
     57 *    |                               A                               | 
     58 *    |            set_local_answer() |                               | 
     59 *    |                               |                               | 
     60 *    |                        +--------------+   set_remote_offer()  | 
     61 *     ----------------------->| REMOTE_OFFER |<---------------------- 
     62 *     create_w_remote_offer() +--------------+ 
     63 * 
     64 * </pre> 
    4365 */ 
    4466enum pjmedia_sdp_neg_state 
     
    5173    /**  
    5274     * This state occurs when SDP negotiator has sent our offer to remote and 
    53      * it is waiting for answer. 
     75     * it is waiting for answer.  
    5476     */ 
    5577    PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, 
     78 
     79    /**  
     80     * This state occurs when SDP negotiator has received offer from remote 
     81     * and currently waiting for local answer. 
     82     */ 
     83    PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER, 
    5684 
    5785    /** 
    5886     * This state occurs when an offer (either local or remote) has been  
    5987     * provided with answer. The SDP negotiator is ready to negotiate both 
    60      * session descriptors. 
     88     * session descriptors. Application can call #pjmedia_sdp_neg_negotiate() 
     89     * immediately to begin negotiation process. 
    6190     */ 
    6291    PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, 
     
    6998}; 
    7099 
    71 /* Negotiator state: 
    72  * 
    73  *                                                 reinit_local_offer() 
    74  *                                                 modify_local_offer() 
    75  *     create_w_local_offer()     +-------------+  tx_local_offer() 
    76  *     /------------------------->| LOCAL_OFFER |<----------------------\ 
    77  *    |                           +-------------+                        | 
    78  *    |                                  |                               | 
    79  *    |               rx_remote_answer() |                               | 
    80  *    |                                  V                               | 
    81  * +--+---+                         +-----------+     negotiate()     +------+ 
    82  * + NULL |------------------------>| WAIT_NEGO |-------------------->| DONE | 
    83  * +------+ create_w_remote_offer() +-----------+                     +------+ 
    84  *                                       A                               | 
    85  *                                       |         rx_remote_offer()     | 
    86  *                                        \-----------------------------/ 
    87  */  
    88  
    89100/** 
    90101 * Create the SDP negotiator with local offer. The SDP negotiator then 
    91102 * will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER state, where it waits 
    92103 * until it receives answer from remote. When SDP answer from remote is 
    93  * received, application should call #pjmedia_sdp_neg_rx_remote_answer(). 
     104 * received, application should call #pjmedia_sdp_neg_set_remote_answer(). 
    94105 * 
    95106 * After calling this function, application should send the local SDP offer 
    96  * to remote party and wait for SDP answer. 
     107 * to remote party using higher layer signaling protocol (e.g. SIP) and  
     108 * wait for SDP answer. 
     109 * 
     110 * @param pool          Pool to allocate memory. The pool's lifetime needs 
     111 *                      to be valid for the duration of the negotiator. 
     112 * @param local         The initial local capability. 
     113 * @param p_neg         Pointer to receive the negotiator instance. 
     114 * 
     115 * @return              PJ_SUCCESS on success, or the appropriate error 
     116 *                      code. 
    97117 */ 
    98118PJ_DECL(pj_status_t)  
     
    102122 
    103123/** 
    104  * Initialize the SDP negotiator with both local and remote offer.  
    105  * Application normally calls this function when it receives initial offer 
    106  * from remote. Application must also provide initial local offer when 
    107  * calling this function. After this function is called, the SDP negotiator 
    108  * state will move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and the negotiation 
    109  * function can be called. 
     124 * Initialize the SDP negotiator with remote offer, and optionally 
     125 * specify the initial local capability, if known. Application normally  
     126 * calls this function when it receives initial offer 
     127 * from remote.  
     128 * 
     129 * If local media capability is specified, this capability will be set as 
     130 * initial local capability of the negotiator, and after this function is 
     131 * called, the SDP negotiator state will move to state 
     132 * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and the negotiation function can be  
     133 * called.  
     134 * 
     135 * If local SDP is not specified, the negotiator will not have initial local 
     136 * capability, and after this function is called the negotiator state will  
     137 * move to PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER state. Application MUST supply 
     138 * local answer later with #pjmedia_sdp_neg_set_local_answer(), before 
     139 * calling the negotiation function. 
     140 * 
     141 * @param pool          Pool to allocate memory. The pool's lifetime needs 
     142 *                      to be valid for the duration of the negotiator. 
     143 * @param initial       Optional initial local capability. 
     144 * @param remote        The remote offer. 
     145 * @param p_neg         Pointer to receive the negotiator instance. 
     146 * 
     147 * @return              PJ_SUCCESS on success, or the appropriate error 
     148 *                      code. 
    110149 */ 
    111150PJ_DECL(pj_status_t)  
    112151pjmedia_sdp_neg_create_w_remote_offer(pj_pool_t *pool, 
    113                                       const pjmedia_sdp_session *local, 
     152                                      const pjmedia_sdp_session *initial, 
    114153                                      const pjmedia_sdp_session *remote, 
    115154                                      pjmedia_sdp_neg **p_neg); 
     
    117156/** 
    118157 * Get SDP negotiator state. 
     158 * 
     159 * @param neg           The SDP negotiator instance. 
     160 * 
     161 * @return              The negotiator state. 
    119162 */ 
    120163PJ_DECL(pjmedia_sdp_neg_state) 
     
    126169 * active SDPs. Calling this function will not change the state of the  
    127170 * negotiator. 
    128  */ 
    129 PJ_DECL(pj_status_t)  
    130 pjmedia_sdp_neg_get_local( pjmedia_sdp_neg *neg, 
    131                            const pjmedia_sdp_session **local); 
     171 * 
     172 * @param neg           The SDP negotiator instance. 
     173 * @param local         Pointer to receive the local active SDP. 
     174 * 
     175 * @return              PJ_SUCCESS if local active SDP is present. 
     176 */ 
     177PJ_DECL(pj_status_t)  
     178pjmedia_sdp_neg_get_active_local( pjmedia_sdp_neg *neg, 
     179                                  const pjmedia_sdp_session **local); 
    132180 
    133181/** 
     
    136184 * active SDPs. Calling this function will not change the state of the  
    137185 * negotiator. 
    138  */ 
    139 PJ_DECL(pj_status_t)  
    140 pjmedia_sdp_neg_get_remote( pjmedia_sdp_neg *neg, 
    141                             const pjmedia_sdp_session **remote); 
    142  
     186 * 
     187 * @param neg           The SDP negotiator instance. 
     188 * @param remote        Pointer to receive the remote active SDP. 
     189 * 
     190 * @return              PJ_SUCCESS if remote active SDP is present. 
     191 */ 
     192PJ_DECL(pj_status_t)  
     193pjmedia_sdp_neg_get_active_remote( pjmedia_sdp_neg *neg, 
     194                                   const pjmedia_sdp_session **remote); 
     195 
     196/** 
     197 * Get the current remote SDP offer or answer. Application can only  
     198 * call this function in state PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER or 
     199 * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, or otherwise there won't be remote  
     200 * SDP offer/answer. Calling this  function will not change the state  
     201 * of the negotiator. 
     202 * 
     203 * @param neg           The SDP negotiator instance. 
     204 * @param remote        Pointer to receive the current remote offer or 
     205 *                      answer. 
     206 * 
     207 * @return              PJ_SUCCESS if the negotiator currently has 
     208 *                      remote offer or answer. 
     209 */ 
     210PJ_DECL(pj_status_t) 
     211pjmedia_sdp_neg_get_neg_remote( pjmedia_sdp_neg *neg, 
     212                                const pjmedia_sdp_session **remote); 
     213 
     214 
     215/** 
     216 * Get the current local SDP offer or answer. Application can only  
     217 * call this function in state PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER or 
     218 * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, or otherwise there won't be local  
     219 * SDP offer/answer. Calling this function will not change the state  
     220 * of the negotiator. 
     221 * 
     222 * @param neg           The SDP negotiator instance. 
     223 * @param local         Pointer to receive the current local offer or 
     224 *                      answer. 
     225 * 
     226 * @return              PJ_SUCCESS if the negotiator currently has 
     227 *                      local offer or answer. 
     228 */ 
     229PJ_DECL(pj_status_t)  
     230pjmedia_sdp_neg_get_neg_local( pjmedia_sdp_neg *neg, 
     231                               const pjmedia_sdp_session **local); 
    143232 
    144233/** 
     
    148237 * The negotiator state will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, 
    149238 * where it waits for SDP answer from remote. 
     239 * 
     240 * @param pool          Pool to allocate memory. The pool's lifetime needs 
     241 *                      to be valid for the duration of the negotiator. 
     242 * @param neg           The SDP negotiator instance. 
     243 * @param local         The new local SDP. 
     244 * 
     245 * @return              PJ_SUCCESS on success, or the appropriate 
     246 *                      error code. 
    150247 */ 
    151248PJ_DECL(pj_status_t)  
     
    158255 * SDP negotiator must be in PJMEDIA_SDP_NEG_STATE_WAIT_NEGO state. 
    159256 * After calling this function, the negotiator state will move to 
    160  * PJMEDIA_SDP_NEG_STATE_DONE. 
     257 * PJMEDIA_SDP_NEG_STATE_DONE regardless whether the negotiation has 
     258 * been successfull or not. 
     259 * 
     260 * If the negotiation succeeds (i.e. the return value is PJ_SUCCESS), 
     261 * the active local and remote SDP will be replaced with the new SDP 
     262 * from the negotiation process. 
     263 * 
     264 * If the negotiation fails, the active local and remote SDP will not 
     265 * change. 
     266 * 
     267 * @param pool          Pool to allocate memory. The pool's lifetime needs 
     268 *                      to be valid for the duration of the negotiator. 
     269 * @param neg           The SDP negotiator instance. 
     270 * @param allow_asym    Should be zero. 
     271 * 
     272 * @return              PJ_SUCCESS when there is at least one media 
     273 *                      is actuve common in both offer and answer, or  
     274 *                      failure code when negotiation has failed. 
    161275 */ 
    162276PJ_DECL(pj_status_t) pjmedia_sdp_neg_negotiate( pj_pool_t *pool, 
     
    170284 * local SDP to be sent to remote. The negotiator state will then move 
    171285 * to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, where it waits for SDP answer 
    172  * from remote. 
    173  */ 
    174 PJ_DECL(pj_status_t)  
    175 pjmedia_sdp_neg_tx_local_offer( pj_pool_t *pool, 
    176                                 pjmedia_sdp_neg *neg, 
    177                                 const pjmedia_sdp_session **offer); 
     286 * from remote. When SDP answer has been received from remote, application 
     287 * must call #pjmedia_sdp_neg_set_remote_answer(). 
     288 * 
     289 * @param pool          Pool to allocate memory. The pool's lifetime needs 
     290 *                      to be valid for the duration of the negotiator. 
     291 * @param neg           The SDP negotiator instance. 
     292 * @param offer         Pointer to receive active local SDP to be 
     293 *                      offered to remote. 
     294 * 
     295 * @return              PJ_SUCCESS if local offer can be created. 
     296 */ 
     297PJ_DECL(pj_status_t)  
     298pjmedia_sdp_neg_send_local_offer( pj_pool_t *pool, 
     299                                  pjmedia_sdp_neg *neg, 
     300                                  const pjmedia_sdp_session **offer); 
     301 
     302/** 
     303 * This function can only be called in PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER 
     304 * state, i.e. after application calls #pjmedia_sdp_neg_send_local_offer() 
     305 * function. Application calls this function when it receives SDP answer 
     306 * from remote. After this function is called, the negotiator state will 
     307 * move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the 
     308 * negotiation function #pjmedia_sdp_neg_negotiate(). 
     309 * 
     310 * @param pool          Pool to allocate memory. The pool's lifetime needs 
     311 *                      to be valid for the duration of the negotiator. 
     312 * @param neg           The SDP negotiator instance. 
     313 * @param remote        The remote answer. 
     314 * 
     315 * @return              PJ_SUCCESS on success. 
     316 */ 
     317PJ_DECL(pj_status_t)  
     318pjmedia_sdp_neg_set_remote_answer( pj_pool_t *pool, 
     319                                   pjmedia_sdp_neg *neg, 
     320                                   const pjmedia_sdp_session *remote); 
     321 
     322 
    178323 
    179324/** 
     
    181326 * Application calls this function when it receives SDP offer from remote. 
    182327 * After this function is called, the negotiator state will move to  
    183  * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the 
    184  * negotiation function #pjmedia_sdp_neg_negotiate(). 
    185  */ 
    186 PJ_DECL(pj_status_t)  
    187 pjmedia_sdp_neg_rx_remote_offer( pj_pool_t *pool, 
    188                                  pjmedia_sdp_neg *neg, 
    189                                  const pjmedia_sdp_session *remote); 
    190  
    191  
    192 /** 
    193  * This function can only be called in PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER 
    194  * state. Application calls this function when it receives SDP answer 
    195  * from remote. After this function is called, the negotiator state will 
     328 * PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER, and application MUST call the 
     329 * #pjmedia_sdp_neg_set_local_answer() to set local answer before it can 
     330 * call the negotiation function. 
     331 * 
     332 * @param pool          Pool to allocate memory. The pool's lifetime needs 
     333 *                      to be valid for the duration of the negotiator. 
     334 * @param neg           The SDP negotiator instance. 
     335 * @param remote        The remote offer. 
     336 * 
     337 * @return              PJ_SUCCESS on success. 
     338 */ 
     339PJ_DECL(pj_status_t)  
     340pjmedia_sdp_neg_set_remote_offer( pj_pool_t *pool, 
     341                                  pjmedia_sdp_neg *neg, 
     342                                  const pjmedia_sdp_session *remote); 
     343 
     344 
     345 
     346/** 
     347 * This function can only be called in PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER 
     348 * state, i.e. after application calls #pjmedia_sdp_neg_set_remote_offer() 
     349 * function. After this function is called, the negotiator state will 
    196350 * move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the 
    197351 * negotiation function #pjmedia_sdp_neg_negotiate(). 
    198  */ 
    199 PJ_DECL(pj_status_t)  
    200 pjmedia_sdp_neg_rx_remote_answer( pj_pool_t *pool, 
     352 * 
     353 * @param pool          Pool to allocate memory. The pool's lifetime needs 
     354 *                      to be valid for the duration of the negotiator. 
     355 * @param neg           The SDP negotiator instance. 
     356 * @param local         Optional local answer. If negotiator has initial 
     357 *                      local capability, application can specify NULL on 
     358 *                      this argument; in this case, the negotiator will 
     359 *                      create answer by by negotiating remote offer with 
     360 *                      initial local capability. If negotiator doesn't have 
     361 *                      initial local capability, application MUST specify 
     362 *                      local answer here. 
     363 * 
     364 * @return              PJ_SUCCESS on success. 
     365 */ 
     366PJ_DECL(pj_status_t)  
     367pjmedia_sdp_neg_set_local_answer( pj_pool_t *pool, 
    201368                                  pjmedia_sdp_neg *neg, 
    202                                   const pjmedia_sdp_session *remote); 
     369                                  const pjmedia_sdp_session *local); 
     370 
    203371 
    204372 
  • pjproject/trunk/pjmedia/src/pjmedia/errno.c

    r129 r140  
    5454    /* SDP negotiator errors. */ 
    5555    { PJMEDIA_SDPNEG_EINSTATE,      "Invalid SDP negotiator state for operation" }, 
     56    { PJMEDIA_SDPNEG_ENOINITIAL,    "No initial local SDP in SDP negotiator" }, 
    5657    { PJMEDIA_SDPNEG_ENOACTIVE,     "No active SDP in SDP negotiator" }, 
     58    { PJMEDIA_SDPNEG_ENONEG,        "No current local/remote offer/answer" }, 
    5759    { PJMEDIA_SDPNEG_EMISMEDIA,     "SDP media count mismatch in offer/answer" }, 
    5860    { PJMEDIA_SDPNEG_EINVANSMEDIA,  "SDP media type mismatch in offer/answer" }, 
    5961    { PJMEDIA_SDPNEG_EINVANSTP,     "SDP media transport type mismatch in offer/answer" }, 
    6062    { PJMEDIA_SDPNEG_EANSNOMEDIA,   "No common SDP media payload in answer" }, 
     63    { PJMEDIA_SDPNEG_ENOMEDIA,      "No active media stream after negotiation" }, 
    6164 
    6265    /* SDP comparison results */ 
  • pjproject/trunk/pjmedia/src/pjmedia/sdp.c

    r129 r140  
    10941094{ 
    10951095    unsigned i; 
     1096    const pj_str_t STR_RTPMAP = { "rtpmap", 6 }; 
    10961097 
    10971098    CHECK( sdp != NULL, PJ_EINVAL); 
     
    11561157                const pjmedia_sdp_attr *a; 
    11571158 
    1158                 a = pjmedia_sdp_media_find_attr2(m, "rtpmap", &m->desc.fmt[j]); 
     1159                a = pjmedia_sdp_media_find_attr(m,&STR_RTPMAP,&m->desc.fmt[j]); 
    11591160                CHECK( a != NULL, PJMEDIA_SDP_EMISSINGRTPMAP); 
    11601161            } 
  • pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c

    r129 r140  
    7878PJ_DEF(pj_status_t)  
    7979pjmedia_sdp_neg_create_w_remote_offer(pj_pool_t *pool, 
    80                                       const pjmedia_sdp_session *local, 
     80                                      const pjmedia_sdp_session *initial, 
    8181                                      const pjmedia_sdp_session *remote, 
    8282                                      pjmedia_sdp_neg **p_neg) 
     
    8686 
    8787    /* Check arguments are valid. */ 
    88     PJ_ASSERT_RETURN(pool && local && remote && p_neg, PJ_EINVAL); 
     88    PJ_ASSERT_RETURN(pool && remote && p_neg, PJ_EINVAL); 
    8989 
    9090    *p_neg = NULL; 
    9191 
    92     /* Validate remote offer and local answer */ 
     92    /* Validate remote offer and initial answer */ 
    9393    status = pjmedia_sdp_validate(remote); 
    9494    if (status != PJ_SUCCESS) 
    9595        return status; 
    96     PJ_ASSERT_RETURN((status=pjmedia_sdp_validate(local))==PJ_SUCCESS, status); 
    9796 
    9897    /* Create and initialize negotiator. */ 
     
    10099    PJ_ASSERT_RETURN(neg != NULL, PJ_ENOMEM); 
    101100 
    102     neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO; 
    103     neg->initial_sdp = pjmedia_sdp_session_clone(pool, local); 
    104     PJ_ASSERT_RETURN((status=pjmedia_sdp_validate(neg->initial_sdp))==PJ_SUCCESS, 
    105                      status); 
    106  
    107     neg->neg_local_sdp = pjmedia_sdp_session_clone(pool, local); 
    108101    neg->neg_remote_sdp = pjmedia_sdp_session_clone(pool, remote); 
    109     PJ_ASSERT_RETURN((status=pjmedia_sdp_validate(neg->neg_remote_sdp))==PJ_SUCCESS, 
    110                       status); 
     102 
     103    if (initial) { 
     104        PJ_ASSERT_RETURN((status=pjmedia_sdp_validate(initial))==PJ_SUCCESS,  
     105                         status); 
     106 
     107        neg->initial_sdp = pjmedia_sdp_session_clone(pool, initial); 
     108        neg->neg_local_sdp = pjmedia_sdp_session_clone(pool, initial); 
     109 
     110        neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO; 
     111 
     112    } else { 
     113         
     114        neg->state = PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER; 
     115 
     116    } 
    111117 
    112118    *p_neg = neg; 
     
    127133 
    128134PJ_DEF(pj_status_t)  
    129 pjmedia_sdp_neg_get_local( pjmedia_sdp_neg *neg, 
    130                            const pjmedia_sdp_session **local) 
     135pjmedia_sdp_neg_get_active_local( pjmedia_sdp_neg *neg, 
     136                                  const pjmedia_sdp_session **local) 
    131137{ 
    132138    PJ_ASSERT_RETURN(neg && local, PJ_EINVAL); 
     
    139145 
    140146PJ_DEF(pj_status_t)  
    141 pjmedia_sdp_neg_get_remote( pjmedia_sdp_neg *neg, 
    142                             const pjmedia_sdp_session **remote) 
     147pjmedia_sdp_neg_get_active_remote( pjmedia_sdp_neg *neg, 
     148                                   const pjmedia_sdp_session **remote) 
    143149{ 
    144150    PJ_ASSERT_RETURN(neg && remote, PJ_EINVAL); 
     
    146152 
    147153    *remote = neg->active_remote_sdp; 
     154    return PJ_SUCCESS; 
     155} 
     156 
     157PJ_DEF(pj_status_t) 
     158pjmedia_sdp_neg_get_neg_remote( pjmedia_sdp_neg *neg, 
     159                                const pjmedia_sdp_session **remote) 
     160{ 
     161    PJ_ASSERT_RETURN(neg && remote, PJ_EINVAL); 
     162    PJ_ASSERT_RETURN(neg->neg_remote_sdp, PJMEDIA_SDPNEG_ENONEG); 
     163 
     164    *remote = neg->neg_remote_sdp; 
     165    return PJ_SUCCESS; 
     166} 
     167 
     168PJ_DEF(pj_status_t)  
     169pjmedia_sdp_neg_get_neg_local( pjmedia_sdp_neg *neg, 
     170                               const pjmedia_sdp_session **local) 
     171{ 
     172    PJ_ASSERT_RETURN(neg && local, PJ_EINVAL); 
     173    PJ_ASSERT_RETURN(neg->neg_local_sdp, PJMEDIA_SDPNEG_ENONEG); 
     174 
     175    *local = neg->neg_local_sdp; 
    148176    return PJ_SUCCESS; 
    149177} 
     
    175203 
    176204PJ_DEF(pj_status_t)  
    177 pjmedia_sdp_neg_tx_local_offer( pj_pool_t *pool, 
    178                                 pjmedia_sdp_neg *neg, 
    179                                 const pjmedia_sdp_session **offer) 
     205pjmedia_sdp_neg_send_local_offer( pj_pool_t *pool, 
     206                                  pjmedia_sdp_neg *neg, 
     207                                  const pjmedia_sdp_session **offer) 
    180208{ 
    181209    /* Check arguments are valid. */ 
     
    211239 
    212240PJ_DEF(pj_status_t)  
    213 pjmedia_sdp_neg_rx_remote_offer( pj_pool_t *pool, 
    214                                  pjmedia_sdp_neg *neg, 
    215                                  const pjmedia_sdp_session *remote) 
     241pjmedia_sdp_neg_set_remote_answer( pj_pool_t *pool, 
     242                                   pjmedia_sdp_neg *neg, 
     243                                   const pjmedia_sdp_session *remote) 
     244{ 
     245    /* Check arguments are valid. */ 
     246    PJ_ASSERT_RETURN(pool && neg && remote, PJ_EINVAL); 
     247 
     248    /* Can only do this in STATE_LOCAL_OFFER. 
     249     * If we haven't provided local offer, then rx_remote_offer() should 
     250     * be called instead of this function. 
     251     */ 
     252    PJ_ASSERT_RETURN(neg->state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,  
     253                     PJMEDIA_SDPNEG_EINSTATE); 
     254 
     255    /* We're ready to negotiate. */ 
     256    neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO; 
     257    neg->has_remote_answer = 1; 
     258    neg->neg_remote_sdp = pjmedia_sdp_session_clone(pool, remote); 
     259  
     260    return PJ_SUCCESS; 
     261} 
     262 
     263PJ_DEF(pj_status_t)  
     264pjmedia_sdp_neg_set_remote_offer( pj_pool_t *pool, 
     265                                  pjmedia_sdp_neg *neg, 
     266                                  const pjmedia_sdp_session *remote) 
    216267{ 
    217268    /* Check arguments are valid. */ 
     
    225276                     PJMEDIA_SDPNEG_EINSTATE); 
    226277 
    227     /* We're ready to negotiate. */ 
    228     neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO; 
     278    /* State now is STATE_REMOTE_OFFER. */ 
     279    neg->state = PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER; 
    229280    neg->neg_remote_sdp = pjmedia_sdp_session_clone(pool, remote); 
    230281 
     
    233284 
    234285PJ_DEF(pj_status_t)  
    235 pjmedia_sdp_neg_rx_remote_answer( pj_pool_t *pool, 
     286pjmedia_sdp_neg_set_local_answer( pj_pool_t *pool, 
    236287                                  pjmedia_sdp_neg *neg, 
    237                                   const pjmedia_sdp_session *remote) 
     288                                  const pjmedia_sdp_session *local) 
    238289{ 
    239290    /* Check arguments are valid. */ 
    240     PJ_ASSERT_RETURN(pool && neg && remote, PJ_EINVAL); 
    241  
    242     /* Can only do this in STATE_LOCAL_OFFER. 
    243      * If we haven't provided local offer, then rx_remote_offer() should 
     291    PJ_ASSERT_RETURN(pool && neg && local, PJ_EINVAL); 
     292 
     293    /* Can only do this in STATE_REMOTE_OFFER. 
     294     * If we already provide local offer, then rx_remote_answer() should 
    244295     * be called instead of this function. 
    245296     */ 
    246     PJ_ASSERT_RETURN(neg->state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,  
     297    PJ_ASSERT_RETURN(neg->state == PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER,  
    247298                     PJMEDIA_SDPNEG_EINSTATE); 
    248299 
    249     /* We're ready to negotiate. */ 
     300    /* State now is STATE_WAIT_NEGO. */ 
    250301    neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO; 
    251     neg->has_remote_answer = 1; 
    252     neg->neg_remote_sdp = pjmedia_sdp_session_clone(pool, remote); 
    253   
     302    if (local) 
     303        neg->neg_local_sdp = pjmedia_sdp_session_clone(pool, local); 
     304    else { 
     305        PJ_ASSERT_RETURN(neg->initial_sdp, PJMEDIA_SDPNEG_ENOINITIAL); 
     306        neg->neg_local_sdp = pjmedia_sdp_session_clone(pool, neg->initial_sdp); 
     307    } 
     308 
    254309    return PJ_SUCCESS; 
    255310} 
     
    464519{ 
    465520    unsigned mi; 
     521    pj_bool_t has_active = PJ_FALSE; 
    466522    pj_status_t status; 
    467523 
     
    479535        if (status != PJ_SUCCESS) 
    480536            return status; 
     537 
     538        if (offer->media[mi]->desc.port != 0) 
     539            has_active = PJ_TRUE; 
    481540    } 
    482541 
    483542    *p_active = offer; 
    484     return PJ_SUCCESS; 
     543 
     544    return has_active ? PJ_SUCCESS : PJMEDIA_SDPNEG_ENOMEDIA; 
    485545} 
    486546 
     
    675735{ 
    676736    pj_status_t status; 
     737    pj_bool_t has_active = PJ_FALSE; 
    677738    pjmedia_sdp_session *answer; 
    678739    char media_used[PJSDP_MAX_MEDIA]; 
     
    749810        /* Add the media answer */ 
    750811        answer->media[answer->media_count++] = am; 
     812 
     813        /* Check if this media is active.*/ 
     814        if (am->desc.port != 0) 
     815            has_active = PJ_TRUE; 
    751816    } 
    752817 
    753818    *p_answer = answer; 
    754     return PJ_SUCCESS; 
     819 
     820    return has_active ? PJ_SUCCESS : PJMEDIA_SDPNEG_ENOMEDIA; 
    755821} 
    756822 
     
    785851        pjmedia_sdp_session *answer; 
    786852 
    787         status = create_answer(pool, neg->initial_sdp, neg->neg_remote_sdp, 
     853        status = create_answer(pool, neg->neg_local_sdp, neg->neg_remote_sdp, 
    788854                               &answer); 
    789855        if (status == PJ_SUCCESS) { 
Note: See TracChangeset for help on using the changeset viewer.