[pjsip] Ending a Call; Running pjsua in the background; default speaker and microphone levels

Benny Prijono bennylp at pjsip.org
Thu Sep 13 17:38:05 EDT 2007

Thomas Martin wrote:
> Hello,
> First of all I have to say thank you for making this excellent framework 
> and application.  Well done!
> Now, I have pjsua running on an embedded arm based device and have a 
> couple questions.

Thanks for the kind words, glad you find it useful. Btw what kind of 
embedded ARM and development tools that you use? Just for future 
reference just in case someone asks.

> 1)  How can I hang up on an existing call immediately?  I have hacked 
> the code so that when ever there is a new incoming call, regardless of 
> replaces header or not, it replaces the current call with the new one.  
> However, to the current call it just sends BYE over and over until a 
> timeout (I am aware that this is the clients fault (ekiga) not pjsip).  

What API abstraction do you use (pjsip, or pjsua-lib)?

With pjsip, there is this pjsip_inv_terminate() to force terminate 
the session without doing any signaling. But this function normally 
is used for special circumstances, like when the invite session 
initialization fails, so I can't guarantee that it'll work in this case.

A cleaner hack is to send BYE request to the session, creating the 
request as if it comes from remote endpoint (by constructing it 
using the dialog properties, with pjsip_endpt_create_request()) and 
send it from the application with pjsip_endpt_send_request().

> In the mean time, both calls are answered with 200 OK.  On my system, 
> this somehow turns off all audio and I can't get it back.  So, I need to 

Are you not using conference bridge?

> hang up on the call NOW so as to not answer both calls at the same 
> time!  Not be nice and send BYE.  What is the clean way to do this?  
> Also acceptable would be if I could somehow wait to answer the new call 
> until after the existing call is gone.  Looping and looking for 

Rather than looping, you could:
  - save the call id of the new call
  - answer the new call with 180/Ringing
  - disconnect old call
  - when the old call is disconnected in on_call_state(), answer the
    new call.

> 2)  Why is it that pjsua is so displeased when it is run in the 
> background?  I have it configured to auto answer calls, so don't need 
> any keyboard input whatsoever.  However, I had to spend some time trying 
> to get it to run on boot correctly because adding it to /etc/inittab 
> would run it in the background and it would just exit immediately.  
> Eventually I added it to the normal boot process in /etc/init.d/ and 
> exec pjsua so it isn't running in the background.  I have no problem 
> fixing what ever it is that might be doing this, but I don't really know 
> where to start looking.  I know it expects stdin and stdout, but I have 
> run numerous processes in the background before that expect stdin and 
> stdout without any problems.

That's because of stdin reading by pjsua. Have a look at 
pjsua_app.c, and disable the call to console_app_main() (replace it 
with "while (1) sleep(1000);" or something like that).

> Not a question number 3) I added code to be able to pass input 
> parameters for setting the default levels of the microphone and 
> speakers.  It is 95% just adding the new inputs into the code, and 5% 
> setting the values passed in.  If you want this code, I can do a diff or 
> something for you, just let me know what you want and where to put it.  
> Otherwise, I am sure it is a simple addition for you to make, and I 
> think it is a good thing to have in the app.  Some peoples microphones 
> and/or speakers need different default levels to function properly.  
> Having to hit V and change it every time you start up pjsua seems like 
> it could get annoying.

If you write a patch that makes pjsua reads commands from script 
file, I'll be interested. That would solve this kind of problems 
more generically.

On Windows, we *can* feed script file to pjsua with something like this:
    type script.txt | pjsua_vc6

But we can't on Linux since I couldn't find a function to switch 
stdin from redirection back to console. So if you do the same on 
Linux, pjsua will quit after executing the last command in the file.


> That is all.  Thank you for such a great SIP project!
> -Thomas
> ------------------------------------------------------------------------
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
> pjsip mailing list
> pjsip at lists.pjsip.org
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Benny Prijono

More information about the pjsip mailing list