Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android screen sharing using WebRTC

Tags:

android

webrtc

I have heard about screen sharing on desktop using WebRTC. But for the Android, it seems not to have much information.

My question is:

  1. Is it possible to use WebRTC for screen sharing on android?. I mean I can cast the current screen to the other phone's screen.
  2. If 1 is Yes, How can I achieve this?

Thanks.

like image 848
Paul Avatar asked Nov 19 '14 09:11

Paul


People also ask

Can we use WebRTC in Android?

You can use WebRTC facilities in the Android Platform with the help of Ant Media Server's Native WebRTC Android SDK.

How does WebRTC work on Android?

WebRTC is a platform that supports video, voice, and generic data to be sent between peers, allowing developers to build powerful voice and video communication solutions.


1 Answers

  1. It is possible!
  2. It can be done using the directions below.

I've used ScreenShareRTC in conjunction with ProjectRTC to stream the contents of the screen to a browser with decent quality and fairly low latency ~100ms.

I've added an example below that shows how to configure a screen share as a video source and add it as a track on a stream.

Get the VideoCapturer

@TargetApi(21)
private VideoCapturer createScreenCapturer() {
    if (mMediaProjectionPermissionResultCode != Activity.RESULT_OK) {
        report("User didn't give permission to capture the screen.");
        return null;
    }
    return new ScreenCapturerAndroid(
            mMediaProjectionPermissionResultData, new MediaProjection.Callback() {
        @Override
        public void onStop() {
            report("User revoked permission to capture the screen.");
        }
    });
}

Initialize the capturer and add the tracks to the local media stream

private void initScreenCapturStream() {
    mLocalMediaStream = factory.createLocalMediaStream("ARDAMS");
    MediaConstraints videoConstraints = new MediaConstraints();
    videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxHeight", Integer.toString(mPeerConnParams.videoHeight)));
    videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxWidth", Integer.toString(mPeerConnParams.videoWidth)));
    videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxFrameRate", Integer.toString(mPeerConnParams.videoFps)));
    videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minFrameRate", Integer.toString(mPeerConnParams.videoFps)));

    mVideoSource = factory.createVideoSource(videoCapturer);
    videoCapturer.startCapture(mPeerConnParams.videoWidth, mPeerConnParams.videoHeight, mPeerConnParams.videoFps);
    VideoTrack localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, mVideoSource);
    localVideoTrack.setEnabled(true);
    mLocalMediaStream.addTrack(factory.createVideoTrack("ARDAMSv0", mVideoSource));
    AudioSource audioSource = factory.createAudioSource(new MediaConstraints());
    mLocalMediaStream.addTrack(factory.createAudioTrack("ARDAMSa0", audioSource));

    mListener.onStatusChanged("STREAMING");
}

For more information this might be a good place to start. Its a Android project that connects to a ProjectRTC signalling server and shares the screen as video. I found it very helpful!

Android screen sharing project(Android client - Java) https://github.com/Jeffiano/ScreenShareRTC

ProjectRTC(Node server) https://github.com/pchab/ProjectRTC

like image 58
A. Watson Avatar answered Sep 21 '22 08:09

A. Watson