Pjsip Android Video Call: Inverted Video Preview

眉间皱痕 提交于 2021-01-29 07:50:14

问题


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

Here is the image:

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?


回答1:


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)



回答2:


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



来源:https://stackoverflow.com/questions/57918701/pjsip-android-video-call-inverted-video-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!