Pjsip Android Video Call: Inverted Video Preview
I am using Pjsip library for SIP Video call. I am facing issue
displying my own view in a SurfaceView.
图片如下:
预期视图:
在 onCallMediaState
中获取预览 ID
1 2 | mVideoPreview = VideoPreview(mediaInfo.videoCapDev) mVideoWindow = VideoWindow(mediaInfo.videoIncomingWindowId) |
我用来在 SurfaceView 中显示此预览的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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) } } } } |
我知道对面的人总是会收到我视频的镜像。但就我自己的观点而言,这不应该发生。
我的感觉是我正在显示发送给其他人的预览。我没有得到任何关于如何使用 Pjsip 库显示我自己的视图(没有镜像效果)的提示。
谁能帮我解决这个问题?
我所做的是将 SurfaceView 替换为 TextureView,然后检查:
1 2 3 4 5 6 | if (isFrontCamera) { val matrix = Matrix() matrix.setScale(-1.0f, 1.0f) matrix.postTranslate(width.toFloat(), 0.0f) surfacePreviewCapture.setTransform(matrix) } |
它奏效了。
希望对其他人有所帮助。 :)
====== 更新 ======
当我检查我的后置摄像头时,那里的视图也被翻转了,所以我需要这样做以使其正确:
1 | surfacePreviewCapture.setTransform(null) |
您可以使用 TextureView 进行预览,而不是使用 SurfaceView,然后您可以翻转它。看看如何防止 android 从前置摄像头反转图像?作为参考