Android WebRTC customize remote and local view
Asked Answered
C

1

6

I am implementing the webrtc in an Android project and I am based on this sample in github.

This example uses the libjingle library. This is how the video render view is created:

        // Create video renderers.
        VideoRendererGui.setView((GLSurfaceView)videoView, new Runnable() {
            @Override
            public void run() {
                createPeerConnectionFactory();
            }
        });
        remoteRender = VideoRendererGui.create(
                REMOTE_X, REMOTE_Y,
                REMOTE_WIDTH, REMOTE_HEIGHT, scalingType, false);
        localRender = VideoRendererGui.create(
                LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
                LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, scalingType, true);

My question is how can I manage to customize the remoteRender and localRender, so that I can change it position in the GLSurfaceView and its width and height

EDIT:

I have made a listener and I have tried this:

    @Override
    public void onWidthHeightChange(int width, int height) {
        VideoRendererGui.update(remoteRender,
                REMOTE_X-width, REMOTE_X-height,
                REMOTE_WIDTH-width, REMOTE_HEIGHT-height, scalingType, false);
        if (iceConnected) {
            VideoRendererGui.update(localRender,
                    LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED,
                    LOCAL_WIDTH_CONNECTED, LOCAL_HEIGHT_CONNECTED,
                    ScalingType.SCALE_ASPECT_FIT, true);
        } else {
            VideoRendererGui.update(localRender,
                    LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
                    LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, scalingType, true);
        }
    }

When I give value 150 for both width and height it gives me this error:

08-21 14:34:01.621    7636-7636/org.appspot.apprtc E/AppRTCDemoActivity﹕ Fatal error: glUseProgram: GLES20 error: 1281
    java.lang.RuntimeException: glUseProgram: GLES20 error: 1281
            at org.webrtc.GlUtil.checkNoGLES2Error(GlUtil.java:48)
            at org.webrtc.GlShader.useProgram(GlShader.java:123)
            at org.webrtc.GlRectDrawer.drawOes(GlRectDrawer.java:132)
            at org.webrtc.VideoRendererGui$YuvImageRenderer.draw(VideoRendererGui.java:371)
            at org.webrtc.VideoRendererGui$YuvImageRenderer.access$800(VideoRendererGui.java:131)
            at org.webrtc.VideoRendererGui.onDrawFrame(VideoRendererGui.java:722)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)

EDIT 2 with the solution:

When I was looking at mattm answer I understood that he was right.

While I was searching for my exception I found that it was an exception thrown from libjingle library. I found this piece of code here VideoRendererGui.java at line 368, 347 I found the solution for my questions.

When adding the view height and width it has to be inside these ranges based on this code:

  /**
   * Creates VideoRenderer.Callbacks with top left corner at (x, y) and
   * resolution (width, height). All parameters are in percentage of
   * screen resolution.
   */
  public static YuvImageRenderer create(
      int x, int y, int width, int height) {
    // Check display region parameters.
    if (x < 0 || x > 100 || y < 0 || y > 100 ||
        width < 0 || width > 100 || height < 0 || height > 100 ||
        x + width > 100 || y + height > 100) {
      throw new RuntimeException("Incorrect window parameters.");
    }

So for as long as I follow these rules calling the method VideoRendererGui.update(... will work perfectly

Thanks

Catamount answered 21/8, 2015 at 11:55 Comment(0)
E
3

It's as simple as changing the fields

  • the coordinates:
    REMOTE_X, REMOTE_Y, or LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
  • or the dimensions: REMOTE_WIDTH, REMOTE_HEIGHT or LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING

If you want to change the rendering once the objects have been created, call VideoRendererGui.update(remoteRender, ...).

Evaporate answered 21/8, 2015 at 12:25 Comment(5)
I have tried that but It didnt work, and sometimes it crashed, I will try again and give you feedback. ThanksCatamount
I have found the reason why it crashed :) ThanksCatamount
@Catamount I got the same issue what was the reason ?Commingle
@richashah you are giving values which are not accepted, check my answer above in the question, or check the method you call documentation. Try different values...Catamount
how to convert VideoRendererGui.setView(binding.remoteStreamView) to surfaceview render ?Commingle

© 2022 - 2024 — McMap. All rights reserved.