[pjsip] Strange behavior with camera on Android

Сергей Митрофанов goretz.m at gmail.com
Tue Apr 5 12:19:15 EDT 2016

I'm developing a video call app and facing strange behavior of pjsip.
>From example app there are helper classes for working with camera:
PjCamera.java and PjCameraInfo.java

I'm trying to switch camera via the next code:
try {
    CallVidSetStreamParam callVidSetStreamParam = new

}catch (Exception e){

Where mCameraId is ID of the camera that is elected by the user. My
conception is to allow user choose camera only before the calling. So I put
this method into onCallMediaState(OnCallMediaStateParam prm) callback
inside myCall after all media parsing operations done (same as in the
example app).
So the sequencing of app logic is:
1. User chooses the camera
2. immediately calling (auto)
3. after all media initialize camera switched to desired one (back or front)
4. user ends call

All is fine here while user chooses the front camera. But when user chooses
the back one strange thing happens:
1. First time he selects the back one all is ok. And he hangs up.
2. Now when he tries to do another one call (no matter which camera to
choose now) the camera preview becomes black and no video sent to other
3. Now when he hangs up the call the app crashes immediately without any
related error or warning.

After investigation I have found the reason of crash:
PjCamera.java contains methods Start() and Stop() that initialize and
free/destroy android camera object to work with.
These methods are called by pjsip lib.
Using the debugger I have noticed that behavior of theese differs for calls
with front camera and for calls with back camera.
let suppose facing camera id = 0 and back = 1

So for calls wit front camera the sequencing is:
1. Start() for 0 (starts camera at a call time)
2. Stop() for 0 (when call is ended)
3. Stop() for 0 (for some reason once again after call is ended)

And for calls with back camera the sequencing is:
1. Start() for 0 (starts camera at a call time)
2. Stop() for 0 (to switch the camera)
3. Start() for 1 (switching camera to back)
4. Stop() for 1(when call is ended)
5. Start() for 1(for some reason after call is ended)

So for front camera case the repeat is not fatal - second Stop() call is
just NOP
But for the back camera this becomes pain - library reopens the back camera
after the call was ended.
And this provides the app crash when calling after that.

I tried to investigate the pjsip source but failed to found a reason for
such behavior. I'm not very familiar with C/C++ programming though.
So why is it happens?
Why pjsip tries to Stop() front camera twice while it reopens the back
camera after call is ended and camera closed?
And how to overcome this issue?

Best Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20160405/a25c7f4e/attachment-0002.html>

More information about the pjsip mailing list