Search code examples
androidpjsippjsua2

Pjsip Android Video Call: How to display your view in a SurfaceView using Pjsip Library


I am implementing SIP Video Call using Pjsip library.

My view is successfully transmitted to other person but what I want is to display my camera view in my screen(Something like WhatsApp).

I found that Pjsip is using camera to transmit view. How can I display my Camera View in a SurfaceView using Pjsip library(as I can not use multiple instances of Camera)?

I have already tried this using the following code:

fun updateVideoPreview(holder: SurfaceHolder) {
if (SipManager.getInstance()?.activeCalls?.get(callId) != null &&
        SipManager.getInstance()?.activeCalls?.get(callId)?.mVideoWindow != null &&
        SipManager.getInstance()?.activeCalls?.get(callId)?.mVideoPreview != null) {
    if (videoPreviewActive) {
        val vidWH = VideoWindowHandle()
        vidWH.handle?.setWindow(holder.surface)
        val vidPrevParam = VideoPreviewOpParam()
        vidPrevParam.window = vidWH
        vidPrevParam.show = true
        try {
            SipManager.getInstance()?.activeCalls?.get(callId)?.mVideoPreview?.start(vidPrevParam)
        } catch (e: Exception) {
            println(e)
        }
    } else {
        try {
            SipManager.getInstance()?.activeCalls?.get(callId)?.mVideoPreview?.stop()
        } catch (e: Exception) {
            println(e)
        }
    }
}

}

When I executed this code what I found is the preview that is transmitted to other side(mirror effect) but what I want is my own view.

Can anyone help me with this?


Solution

  • I did this: - Replaced SurfaceView with TextureView and

    if (isFrontCamera) {
        val matrix = Matrix()
        matrix.setScale(-1.0f, 1.0f)
        matrix.postTranslate(width.toFloat(), 0.0f)
        surfacePreviewCapture.setTransform(matrix)
    }
    

    It worked for me. Hope it help others.