Search code examples
javaandroidkotlinwebrtcwebrtc-android

WebRTC not creating IceCandidates for video


On an Android app I am trying to make a webRTC connection.

When I am the callee I receive enough number of IceCandidates for video and audio from the socket connection. When my IceCandidates are created there are much fewer of them. Approximately 6 of them are created and they are all for audio.

From the log messages I see connection is successful and audio is going both ways and I manage to send my video to the caller as well however I can not receive the caller's video stream. I guess it is related to not being able to create enough IceCandidates to send to socket connection. Any ideas?


Solution

  • Maybe it is not ideal but the following solved my problem.

    First of all it is OK to have fewer number of IceCandidate s. During creation of IceCandidate s on my side, sdpMid fields still don't contain video value -i receive both video and audio values for sdpMid key in IceCandidate s from socket connection-.

    All I had to do was to touch my views again after the connection is set with the following methods.

    I walked through these here and here.

    private void updateVideoViews(final boolean remoteVisible) {
        activity.runOnUiThread(() -> {
            ViewGroup.LayoutParams params = localVideoView.getLayoutParams();
            ViewGroup.LayoutParams params2 = remoteVideoView.getLayoutParams();
            if (remoteVisible) {
                params.height = dpToPx(100);
                params.width = dpToPx(100);
    
                params2.height = dpToPx(100);
                params2.width = dpToPx(100);
            } else {
                params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                params2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            }
            localVideoView.setLayoutParams(params);
            remoteVideoView.setLayoutParams(params2);
        });
    }
    
    public int dpToPx(int dp) {
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    }