pjsip / pjproject

PJSIP project
http://www.pjsip.org
GNU General Public License v2.0
2k stars 767 forks source link

Custom Call-ID to call_setting #4051

Closed austinkottke closed 2 weeks ago

austinkottke commented 3 weeks ago

Describe the feature

Ive added in the ability to pass in a custom call id to pjsua2 and pjsua. Affects the CPP api as well. This modifies the CallSetting structure. I use a professional paid pjsip license and would like to get this into the future releases. I realize this request was rejected earlier but if possible Id like to get it done.

If you would not like to include it in future releases that's fine. Other sip stacks have this ability and I will keep patching the pjsip releases for our software.

The good news is Ive rewritten the changes to be minimal.

Shall I submit a PR? This touches two files. Tested on OSX/Win

Describe alternatives you've considered

No response

Additional context

No response

austinkottke commented 3 weeks ago

pjsua_call.c

pjsua_make_call:

 /* Create outgoing dialog: */
    status = pjsip_dlg_create_uac( pjsip_ua_instance(),
                   &acc->cfg.id, &contact,
                   dest_uri,
                                   (msg_data && msg_data->target_uri.slen?
                                    &msg_data->target_uri: dest_uri),
                                   &dlg);

if( opt->user_call_id.slen >= 0 ){
        PJ_LOG(4,(THIS_FILE, "User defined call-id - copy to dialog ") );
        pj_strcpy(&dlg->call_id->id, &opt->user_call_id);
    }

...

pjsua.h:

{
    pjmedia_dir      media_dir[PJMEDIA_MAX_SDP_MEDIA];

    pj_str_t        user_call_id;

} pjsua_call_setting;

And call.cpp

pjsua_call_setting CallSetting::toPj() const
{
    pjsua_call_setting setting;
    unsigned mi;

    /* This is important to initialize media_dir array. */
    pjsua_call_setting_default(&setting);

    setting.flag                = this->flag;
    setting.req_keyframe_method = this->reqKeyframeMethod;
    setting.aud_cnt             = this->audioCount;
    setting.vid_cnt             = this->videoCount;
    for (mi = 0; mi < this->mediaDir.size(); mi++) {
        setting.media_dir[mi] = (pjmedia_dir)this->mediaDir[mi];
    }

    if( ! this->user_call_id.empty()) {
        setting.user_call_id = str2Pj(this->user_call_id);
        PJ_LOG(4, (THIS_FILE, "call_setting - set user_call_id (%s) ", this->user_call_id.c_str() ));
    }

    return setting;
}

void CallSetting::fromPj(const pjsua_call_setting &prm)
{
    int i, mi;

    this->flag              = prm.flag;
    this->reqKeyframeMethod = prm.req_keyframe_method;
    this->audioCount        = prm.aud_cnt;
    this->videoCount        = prm.vid_cnt;
    this->mediaDir.clear();
    this->user_call_id           = pj2Str(prm.user_call_id);
    /* Since we don't know the size of media_dir array, we populate
     * mediaDir vector up to the element with non-default value.
     */
    for (mi = PJMEDIA_MAX_SDP_MEDIA - 1; mi >= 0; mi--) {
        if (prm.media_dir[mi] != PJMEDIA_DIR_ENCODING_DECODING) break;
    }
    for (i = 0; i <= mi; i++) {
        this->mediaDir.push_back(prm.media_dir[i]);
    }
}

Example usage using Cpp high level api:

                    callOpParam.opt.user_call_id = "2141242143543543";

                    call->makeCall(destinationFull.toStdString(), callOpParam);
sauwming commented 3 weeks ago

Yes, feel free to create a PR and we will review it.

austinkottke commented 3 weeks ago

Ok great PR is here: https://github.com/pjsip/pjproject/pull/4052

austinkottke commented 2 weeks ago

Thank you @sauwming and the team for the review, This is a great feature!