pjsip call doesn't reach the opposite site right after termination

83 Views Asked by At

I've got simple SIP client written on C++ using pjsua2 library (guess almost the same as pjsip). The client is only used to make a call (not to answer any calls). The problem is in that I can't make a call to the opposite site after I terminate the call from the opposite site. So the scenario is following:

  1. I do the call from my SIP client
  2. Call reaches the oppsoite site and communication is OK.
  3. I terminate the call from the oppsite site, my client receives DISCONNECTED call state and after that my client is closed.
  4. Right after that I'm trying to do another call from my SIP client but it doesn't reach the oppsite site.

I thought that the problem was in the way I terminate my SIP client, but not completely sure about this statement. I did tests with MicroSIP softphone and there everything was OK. Here is my code:

#include <pjsua2.hpp>
#include <iostream>
#include <string>

using namespace pj;

class SipCall : public pj::Call
{
   public:
     SipCall(pj::Account &acc, int call_id = PJSUA_INVALID_ID):Call(acc, call_id)
     {

     }

    ~SipCall() = default;

    virtual void onCallMediaState(pj::OnCallMediaStateParam &params) override
    {
         std::cout << "***** onCallMediaState *****" << std::endl;
         CallInfo callInfo = getInfo();
         for (unsigned int i = 0; i < callInfo.media.size(); i++)
         {
             if (callInfo.media[i].status == PJSUA_CALL_MEDIA_ACTIVE)
             {
                pjsua_conf_connect(callInfo.media[i].audioConfSlot, 0);
                pjsua_conf_connect(0, callInfo.media[i].audioConfSlot);
             }
         }
     }
};

int main(int argc, char *argv[])
{
Endpoint ep;
ep.libCreate();

EpConfig ep_cfg;
ep_cfg.medConfig.noVad = true;
ep.libInit(ep_cfg);
TransportConfig tcfg;
tcfg.port = 0;
try
{
    ep.transportCreate(PJSIP_TRANSPORT_TCP, tcfg);
}
catch (Error &err)
{
    std::cout << err.info() << std::endl;
    return 1;
}
ep.codecSetPriority("pcma", PJMEDIA_CODEC_PRIO_NORMAL + 15);
ep.libStart();

std::cout << "*** PJSUA2 STARTED ***" << std::endl;

// Configure an AccountConfig
AccountConfig acfg;
acfg.idUri = "sip:account@domain";
acfg.regConfig.registrarUri = "sip:domain";
acfg.sipConfig.proxies = {"sip:domain;transport=tcp"};

AuthCredInfo cred("digest", "*", "username", 0, "password");
acfg.sipConfig.authCreds.push_back(cred);

Account *acc = new Account;
acc->create(acfg);

SipCall * call = new SipCall(*acc);

CallOpParam prm(true); // Use default call settings
call->makeCall("sip:dest@domain", prm);

while(call->isActive())
{

}

delete call;
printf("INFO: call deleted\n");
acc->shutdown();
delete acc;
printf("INFO: Acc deleted\n");

ep.libDestroy();

printf("INFO: ep lib destroyed.\n"); 
return 0;
}

As I read from the documentation, default keepalive interval is 15 second which should be ok. Any ideas of what I'm doing wrong?

0

There are 0 best solutions below