Mohammad Elsayed
Mohammad Elsayed

Reputation: 2066

WebRTC Android, can't get what I should do?

I am working with WebRTC to make a basic video call application that works between two Android phones, I have been searching for about more than 10 days, I have understood everything regarding the Android side, but I really can't get it in the web side, signalling, TURN and STUN. Unfortunately I am not a web guy (at least not now) and I am very very confused about what to do about the servers setup. I don't even understand exactly when to use what and why. to make the story shorter what I need is:

I need a roadmap to continue in the servers setup. thank you in advance.

UPDATE: The backend has been implemented and it seems to be working cuz I receive voice without any problem, I also receive the MediaStream which contains both the video and the audio, but no video is being displayed.

private void gotRemoteStream(MediaStream stream) {
    //we have remote video stream. add to the renderer.
    Log.d("KingArmstring", "gotRemoteStream: 1 stream == null" + String.valueOf(stream == null));
    Log.d("KingArmstring", "the value of the received stream: " + String.valueOf(stream));
    final VideoTrack videoTrack = stream.videoTracks.get(0);
    Log.d("TAG", "gotRemoteStream: we get here");
    runOnUiThread(() -> {
        try {
            Log.d("TAG", "we get here");
            remoteRenderer = new VideoRenderer(new VideoRenderer.Callbacks() {
                @Override
                public void renderFrame(VideoRenderer.I420Frame i420Frame) {
                    Log.d("TAG", "renderFrame: we get here");
                }
            });
            remoteVideoView.setVisibility(View.VISIBLE);
            videoTrack.addRenderer(remoteRenderer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });

}

Upvotes: 1

Views: 3022

Answers (2)

Mohammad Elsayed
Mohammad Elsayed

Reputation: 2066

I have figured finally the problem, thanks to Uriel cuz his answer helped me a lot my answer can't stand alone, it can only be added to his answer. You can see that the remoteRenderer has been initialized this way:

remoteRenderer = new VideoRenderer(new VideoRenderer.Callbacks() {
            @Override
            public void renderFrame(VideoRenderer.I420Frame i420Frame) {
                Log.d("TAG", "renderFrame: we get here");
            }
        });

(I have add that in the UPDATE in my qustion)

instead of that we should initialize it this way:

remoteRenderer = new VideoRenderer(remoteVideoView);

when I finish this part of the app, I will try to add a git repo for this webRTC part so that anyone can take advantage of using any part of it.

Upvotes: 1

Uriel Frankel
Uriel Frankel

Reputation: 14612

I played around with webRTC on Android and web. I was able to make my own project with the help of these projects:

What I suggest is to run these projects. After you success doing it, you can try to change the code to meet with your needs. Now I will explain some details about TURN and STUN.

  1. STUN - this is a way to know what is you real ip. If you use your phone with wifi, what will happen is that you will have ip like: 192.168.1.14. This is internal ip. Your real ip is something else. You need some server like google to tell you what is your real ip. Try typing on google search what is my ip and you will see it is different than what you see in the ifconfig.
  2. TURN - This is a relay of the stream of voice/video data. What happen is some cellular carrier cut of the voice/video data for some reason, what you can do to overcome this is use TURN, you send the data to the TURN and it transfer this to the other side.
  3. Signaling - this is a way 1 side calls the other side. lets say you have 2 guys that want to communicate, they need a way to send the communication data before the call starts. webRTC doesn't give you a mechanism. It gives you a json that you need 1 guy to send it to the second guy. The links I provided uses socket.io but there are other implementation like FCM. The data that travels is the first guy ip, the codacs that he wants to use, and things like that. The second guy needs to send the accept response and the voice call begins.

Upvotes: 3

Related Questions