RSS订阅优然探索
你的位置:首页 » 未分类 » 正文

最好的一点:SDP协商功能

选择字号: 超大 标准 发布时间:2016-2-14 10:11:18 | 作者:admin | 0个评论 | 人浏览

 

/* The best bit: SDP negotiation function! */
PJ_DEF(pj_status_t) pjmedia_sdp_neg_negotiate( pj_pool_t *pool,
            pjmedia_sdp_neg *neg,
            pj_bool_t allow_asym)
{
    pj_status_t status;

    /* Check arguments are valid. */
    PJ_ASSERT_RETURN(pool && neg, PJ_EINVAL);

    /* Must be in STATE_WAIT_NEGO state. */
    PJ_ASSERT_RETURN(neg->state == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO,
       PJMEDIA_SDPNEG_EINSTATE);

    /* Must have remote offer. */
    PJ_ASSERT_RETURN(neg->neg_remote_sdp, PJ_EBUG);

    if (neg->has_remote_answer) {
 pjmedia_sdp_session *active;
 status = process_answer(pool, neg->neg_local_sdp, neg->neg_remote_sdp,
           allow_asym, &active);
 if (status == PJ_SUCCESS) {
     /* Only update active SDPs when negotiation is successfull */
     neg->active_local_sdp = active;
     neg->active_remote_sdp = neg->neg_remote_sdp;
 }
    } else {
 pjmedia_sdp_session *answer = NULL;

 status = create_answer(pool, neg->prefer_remote_codec_order,
                               neg->answer_with_multiple_codecs,
          neg->neg_local_sdp, neg->neg_remote_sdp,
          &answer);
 if (status == PJ_SUCCESS) {
     pj_uint32_t active_ver;

     if (neg->active_local_sdp)
  active_ver = neg->active_local_sdp->origin.version;
     else
  active_ver = neg->initial_sdp->origin.version;

     /* Only update active SDPs when negotiation is successfull */
     neg->active_local_sdp = answer;
     neg->active_remote_sdp = neg->neg_remote_sdp;

     /* Increment SDP version */
     neg->active_local_sdp->origin.version = ++active_ver;
 }
    }

    /* State is DONE regardless */
    neg->state = PJMEDIA_SDP_NEG_STATE_DONE;

    /* Save state */
    neg->answer_was_remote = neg->has_remote_answer;

    /* Revert back initial SDP if nego fails */
    if (status != PJ_SUCCESS)
 neg->initial_sdp = neg->initial_sdp_tmp;

    /* Clear temporary SDP */
    neg->initial_sdp_tmp = NULL;
    neg->neg_local_sdp = neg->neg_remote_sdp = NULL;
    neg->has_remote_answer = PJ_FALSE;

    return status;
}

标签:

猜你喜欢

发表评论

必填

选填

选填

必填,不填不让过哦,嘻嘻。

记住我,下次回复时不用重新输入个人信息

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。