Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching camera from front to back in pjsip android

I am working on pjsip video calling app. I want to switch preview camera in an ongoing call.

Here is the code that I am trying.

private void switchCamera(boolean isFront) {
        try {
            int w = (int) SipCallService.currentCall.vidPrev.getVideoWindow()
                    .getInfo().getSize().getW();
            int h = (int) SipCallService.currentCall.vidPrev.getVideoWindow()
                    .getInfo().getSize().getH();
            if (isFront) {
                PjCamera camera = new PjCamera(0, w, h, 0, 0, 0,
                        mSurfaceCapture);
                camera.SwitchDevice(0);
            } else {
                PjCamera camera = new PjCamera(0, w, h, 0, 0, 0,
                        mSurfaceCapture);
                camera.SwitchDevice(1);
            }

        } catch (Exception e) {
            e.printStackTrace();
            showToast("Error while switching camera");
        }
    }

PjCamera is the class provided by pjsip.

I am not able to switch camera using above code.

If there is any other method please guide me to it.

like image 833
Manoj Avatar asked Nov 09 '22 22:11

Manoj


1 Answers

I used this code, to switch between the front / back cameras.

    int cameraId = isFront? 1 :2;

    CallVidSetStreamParam callVidSetStreamParam = new CallVidSetStreamParam();
    callVidSetStreamParam.setCapDev(cameraId);
    try {
        sipCall.vidSetStream(pjsua_call_vid_strm_op.PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV, callVidSetStreamParam);
        result = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
like image 151
user3001001 Avatar answered Nov 14 '22 21:11

user3001001