Android
Android

Reputation: 1609

WebRTC VideoView incorrect view for local peer

I am writing a WebRTC solution and having an issue in Local View while using back camera (Wrong Rotation / Incorrect View)

<com.src.webrtc.android.VideoView
     android:id="@+id/main_view"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />

Local View (Incorrect view)

enter image description here

Remote View (Correct View : while viewing as a Remote user)

enter image description here

Upvotes: 4

Views: 782

Answers (1)

satya-p91
satya-p91

Reputation: 486

I was facing the same issue while working on the webRTC. I fixed it by setting the method setMirror(false).

here's some code: call_activity.xml

<org.webrtc.SurfaceViewRenderer
    android:id="@+id/fullscreen_video_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />

<org.webrtc.SurfaceViewRenderer
    android:id="@+id/pip_video_view"
    android:layout_height="144dp"
    android:layout_width="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp"/>

in CallActivity.java

SurfaceViewRenderer fullscreenRenderer = 
findViewById(R.id.fullscreen_video_view);
fullscreenRenderer.init(eglBase.getEglBaseContext(), null);
fullscreenRenderer.setScalingType(ScalingType.SCALE_ASPECT_FILL);
fullscreenRenderer.setEnableHardwareScaler(false /* enabled */);
//this code is used for rotation
fullscreenRenderer.setMirror(false);

I am using implementation 'org.webrtc:google-webrtc:1.0.28513'

Update: what you can do in VideoView.kt is:

class VideoView : SurfaceViewRenderer{
constructor(context: Context) : super(context)

constructor(context: Context, attrs: android.util.AttributeSet?) : super(context, attrs)

fun init(rendererEvents: RendererCommon.RendererEvents?) {
    super.init(EglBaseProvider.getEglBase(this).eglBaseContext, rendererEvents)
    setMirror(false)
}

override fun release() {
    super.release()
    EglBaseProvider.release(this)
}

override fun setMirror(mirror: Boolean) {
    super.setMirror(mirror)
}
}

or

class VideoView : SurfaceViewRenderer{
constructor(context: Context) : super(context)

constructor(context: Context, attrs: android.util.AttributeSet?) : super(context, attrs)

fun init(rendererEvents: RendererCommon.RendererEvents?) {
    super.init(EglBaseProvider.getEglBase(this).eglBaseContext, rendererEvents)
    super.setMirror(false)
}

override fun release() {
    super.release()
    EglBaseProvider.release(this)
}
}

Upvotes: 7

Related Questions