1

I am using Pjsip library for SIP Video call. I am facing issue displying my own view in a SurfaceView.

Here is the image:

image

Expected View:

Expected view Fetching Preview ID in onCallMediaState

mVideoPreview = VideoPreview(mediaInfo.videoCapDev)
mVideoWindow = VideoWindow(mediaInfo.videoIncomingWindowId)

Code I have used to display this preview in my SurfaceView:

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

I know that the person on other side will always recieve mirror view of my video. But in case of my own view, this should not happen. What I feel is I am displaying the preview which is sent to the other person. I am not getting a single hint about how to display my own view(without mirror effect) using Pjsip library.

Can anyone please help me with this?

Aanal Shah
  • 1,946
  • 2
  • 20
  • 30
  • Have you checked with the native camera app? It does the same – Rahul Khurana Sep 13 '19 at 07:00
  • @RahulKhurana No. It's not like that. Here I am displaying my front view in video which results mirror effect when the person on the other side receives my view. But when you are seeing your own view in a camera, it's never mirror view. – Aanal Shah Sep 13 '19 at 07:05
  • In the image, you provided on the first arrow your thumb is on the left side and on the second arrow your thumb is on the right side. I think this is called mirror effect – Rahul Khurana Sep 13 '19 at 07:08
  • @RahulKhurana Please check my updated post with the image from default camera fron view. It should look like this. – Aanal Shah Sep 13 '19 at 07:15
  • Try recording video from front camera and then play it. You will see the difference – Rahul Khurana Sep 13 '19 at 07:20
  • @RahulKhurana That's totally correct. But this is the case when you are recording a video. In that case you'll never have mirror effect. – Aanal Shah Sep 13 '19 at 07:21
  • In a video call, they internally record video and upload it on the server and then plays it in continuous mode. This happens so fast that the user will feel like it is live streaming. – Rahul Khurana Sep 13 '19 at 07:23
  • @RahulKhurana Okay Thank you so much. But this is not what I want. :) – Aanal Shah Sep 13 '19 at 07:30
  • Mirroring image could be better for performance level but the video isn't. You can try rotate your local preview view to 180 degrees – Rahul Khurana Sep 13 '19 at 07:50
  • You could also try `android:scaleX=-1` in the XML – Rahul Khurana Sep 13 '19 at 10:40
  • @RahulKhurana I have already tried that but no success. – Aanal Shah Sep 13 '19 at 11:08

2 Answers2

2

What I did is replaced SurfaceView with TextureView and then check:

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

And it worked. Hope it help others. :)

====== UPDATE ======

When I checked my back camera, the view was also flipped over there so I need to do this to make it proper:

surfacePreviewCapture.setTransform(null)
Aanal Shah
  • 1,946
  • 2
  • 20
  • 30
  • Does pjsua 2 Android sample app ..has video call feature as well..... – tomtom Jul 09 '20 at 14:35
  • It does support Video call. – Aanal Shah Jul 20 '20 at 07:37
  • Default sample Pjsip video quality is very bad , can you please have a look at my post here ..how to improve video quality https://stackoverflow.com/questions/57918701/pjsip-android-video-call-inverted-video-preview – tomtom Dec 27 '20 at 22:29
1

Instead of using SurfaceView, you can use TextureView for your preview which you can flipped afterwards. Have a look at How to keep android from inverting the image from the front facing camera? as a reference