Java Code Examples for org.webrtc.PeerConnectionFactory#Options

The following examples show how to use org.webrtc.PeerConnectionFactory#Options . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PCFactoryProxy.java    From owt-client-android with Apache License 2.0 7 votes vote down vote up
static PeerConnectionFactory instance() {
    if (peerConnectionFactory == null) {
        PeerConnectionFactory.InitializationOptions initializationOptions =
                PeerConnectionFactory.InitializationOptions.builder(context)
                        .setFieldTrials(fieldTrials)
                        .createInitializationOptions();
        PeerConnectionFactory.initialize(initializationOptions);
        PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
        options.networkIgnoreMask = networkIgnoreMask;
        peerConnectionFactory = PeerConnectionFactory.builder()
                .setOptions(options)
                .setAudioDeviceModule(adm == null ? JavaAudioDeviceModule.builder(context).createAudioDeviceModule() : adm)
                .setVideoEncoderFactory(
                        encoderFactory == null
                                ? new DefaultVideoEncoderFactory(localContext, true, true)
                                : encoderFactory)
                .setVideoDecoderFactory(
                        decoderFactory == null
                                ? new DefaultVideoDecoderFactory(remoteContext)
                                : decoderFactory)
                .createPeerConnectionFactory();
    }
    return peerConnectionFactory;
}
 
Example 2
Source File: WebRTCNativeMgr.java    From appinventor-extensions with Apache License 2.0 7 votes vote down vote up
public void initiate(ReplForm form, Context context, String code) {

    this.form = form;
    rCode = code;
    /* Initialize WebRTC globally */
    PeerConnectionFactory.initializeAndroidGlobals(context, false);
    /* Setup factory options */
    PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
    /* Create the factory */
    PeerConnectionFactory factory = new PeerConnectionFactory(options);
    /* Create the peer connection using the iceServers we received in the constructor */
    RTCConfiguration rtcConfig = new RTCConfiguration(iceServers);
    rtcConfig.continualGatheringPolicy = ContinualGatheringPolicy.GATHER_CONTINUALLY;
    peerConnection = factory.createPeerConnection(rtcConfig, new MediaConstraints(),
      observer);
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
          Poller();
        }
      }, 0, 1000);              // Start the Poller now and then every second
  }
 
Example 3
Source File: WebRtcClient.java    From imsdk-android with MIT License 5 votes vote down vote up
public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options options) {
    this.options = options;
    if (options != null) {
        LogUtil.d(TAG, "Factory networkIgnoreMask option: " + options.networkIgnoreMask);
        factory.setOptions(options);
    }
}
 
Example 4
Source File: PeersManager.java    From WebRTCapp with Apache License 2.0 5 votes vote down vote up
public void start() {
    PeerConnectionFactory.initializeAndroidGlobals(activity, true);

    PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
    peerConnectionFactory = new PeerConnectionFactory(options);

    videoGrabberAndroid = createVideoGrabber();
    MediaConstraints constraints = new MediaConstraints();

    VideoSource videoSource = peerConnectionFactory.createVideoSource(videoGrabberAndroid);
    localVideoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);

    AudioSource audioSource = peerConnectionFactory.createAudioSource(constraints);
    localAudioTrack = peerConnectionFactory.createAudioTrack("101", audioSource);

    if (videoGrabberAndroid != null) {
        videoGrabberAndroid.startCapture(1000, 1000, 30);
    }

    localRenderer = new VideoRenderer(localVideoView);
    localVideoTrack.addRenderer(localRenderer);

    MediaConstraints sdpConstraints = new MediaConstraints();
    sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveAudio", "true"));
    sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveVideo", "true"));

    createLocalPeerConnection(sdpConstraints);
}
 
Example 5
Source File: WebRTCActivity.java    From voip_android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void startStream() {
    logAndToast("Creating peer connection");

    peerConnectionClient = new PeerConnectionClient(getApplicationContext(), rootEglBase, peerConnectionParameters, this);

    PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();

    peerConnectionClient.createPeerConnectionFactory(options);

    PeerConnection.IceServer server = new PeerConnection.IceServer("stun:stun.counterpath.net:3478");

    String username = turnUserName;
    String password = turnPassword;
    PeerConnection.IceServer server2 = new PeerConnection.IceServer("turn:turn.gobelieve.io:3478?transport=udp", username, password);

    peerConnectionClient.clearIceServer();
    peerConnectionClient.addIceServer(server);
    peerConnectionClient.addIceServer(server2);

    VideoCapturer videoCapturer = null;
    if (peerConnectionParameters.videoCallEnabled) {
        videoCapturer = createVideoCapturer();
    }
    peerConnectionClient.createPeerConnection(localRender,
            remoteRender, videoCapturer);

    if (this.isCaller) {
        logAndToast("Creating OFFER...");
        // Create offer. Offer SDP will be sent to answering client in
        // PeerConnectionEvents.onLocalDescription event.
        peerConnectionClient.createOffer();
    }
}
 
Example 6
Source File: PeerConnectionClient.java    From voip_android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This function should only be called once.
 */
public void createPeerConnectionFactory(PeerConnectionFactory.Options options) {
    if (factory != null) {
        throw new IllegalStateException("PeerConnectionFactory has already been constructed");
    }
    executor.execute(() -> createPeerConnectionFactoryInternal(options));
}
 
Example 7
Source File: MainActivity.java    From webrtc-android-tutorial with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EglBase.Context eglBaseContext = EglBase.create().getEglBaseContext();

        // create PeerConnectionFactory
        PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
                .builder(this)
                .createInitializationOptions());
        PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
        DefaultVideoEncoderFactory defaultVideoEncoderFactory =
                new DefaultVideoEncoderFactory(eglBaseContext, true, true);
        DefaultVideoDecoderFactory defaultVideoDecoderFactory =
                new DefaultVideoDecoderFactory(eglBaseContext);
        peerConnectionFactory = PeerConnectionFactory.builder()
                .setOptions(options)
                .setVideoEncoderFactory(defaultVideoEncoderFactory)
                .setVideoDecoderFactory(defaultVideoDecoderFactory)
                .createPeerConnectionFactory();

        SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBaseContext);
        // create VideoCapturer
        VideoCapturer videoCapturer = createCameraCapturer(true);
        VideoSource videoSource = peerConnectionFactory.createVideoSource(videoCapturer.isScreencast());
        videoCapturer.initialize(surfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver());
        videoCapturer.startCapture(480, 640, 30);

        localView = findViewById(R.id.localView);
        localView.setMirror(true);
        localView.init(eglBaseContext, null);

        // create VideoTrack
        VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);
//        // display in localView
//        videoTrack.addSink(localView);




        SurfaceTextureHelper remoteSurfaceTextureHelper = SurfaceTextureHelper.create("RemoteCaptureThread", eglBaseContext);
        // create VideoCapturer
        VideoCapturer remoteVideoCapturer = createCameraCapturer(false);
        VideoSource remoteVideoSource = peerConnectionFactory.createVideoSource(remoteVideoCapturer.isScreencast());
        remoteVideoCapturer.initialize(remoteSurfaceTextureHelper, getApplicationContext(), remoteVideoSource.getCapturerObserver());
        remoteVideoCapturer.startCapture(480, 640, 30);

        remoteView = findViewById(R.id.remoteView);
        remoteView.setMirror(false);
        remoteView.init(eglBaseContext, null);

        // create VideoTrack
        VideoTrack remoteVideoTrack = peerConnectionFactory.createVideoTrack("102", remoteVideoSource);
//        // display in remoteView
//        remoteVideoTrack.addSink(remoteView);



        mediaStreamLocal = peerConnectionFactory.createLocalMediaStream("mediaStreamLocal");
        mediaStreamLocal.addTrack(videoTrack);

        mediaStreamRemote = peerConnectionFactory.createLocalMediaStream("mediaStreamRemote");
        mediaStreamRemote.addTrack(remoteVideoTrack);

        call(mediaStreamLocal, mediaStreamRemote);
    }
 
Example 8
Source File: MainActivity.java    From webrtc-android-tutorial with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EglBase.Context eglBaseContext = EglBase.create().getEglBaseContext();

        // create PeerConnectionFactory
        PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
                .builder(this)
                .createInitializationOptions());
        PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
        DefaultVideoEncoderFactory defaultVideoEncoderFactory =
                new DefaultVideoEncoderFactory(eglBaseContext, true, true);
        DefaultVideoDecoderFactory defaultVideoDecoderFactory =
                new DefaultVideoDecoderFactory(eglBaseContext);
        peerConnectionFactory = PeerConnectionFactory.builder()
                .setOptions(options)
                .setVideoEncoderFactory(defaultVideoEncoderFactory)
                .setVideoDecoderFactory(defaultVideoDecoderFactory)
                .createPeerConnectionFactory();

        SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBaseContext);
        // create VideoCapturer
        VideoCapturer videoCapturer = createCameraCapturer(true);
        VideoSource videoSource = peerConnectionFactory.createVideoSource(videoCapturer.isScreencast());
        videoCapturer.initialize(surfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver());
        videoCapturer.startCapture(480, 640, 30);

        localView = findViewById(R.id.localView);
        localView.setMirror(true);
        localView.init(eglBaseContext, null);

        // create VideoTrack
        VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);
//        // display in localView
        videoTrack.addSink(localView);


        remoteView = findViewById(R.id.remoteView);
        remoteView.setMirror(false);
        remoteView.init(eglBaseContext, null);


        AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());
        AudioTrack audioTrack = peerConnectionFactory.createAudioTrack("101", audioSource);

        mediaStream = peerConnectionFactory.createLocalMediaStream("mediaStream");
        mediaStream.addTrack(videoTrack);
        mediaStream.addTrack(audioTrack);

        SignalingClient.get().setCallback(this);
        call();
    }
 
Example 9
Source File: PeerConnectionClient.java    From sample-videoRTC with Apache License 2.0 4 votes vote down vote up
public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options options) {
  this.options = options;
}
 
Example 10
Source File: PeerConnectionClient.java    From janus-gateway-android with MIT License 4 votes vote down vote up
public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options options) {
  this.options = options;
}
 
Example 11
Source File: PeerConnectionClient.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options options) {
    this.options = options;
}
 
Example 12
Source File: PeerConnectionClient.java    From voip_android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options options) {
    this.options = options;
}
 
Example 13
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options options) {
  this.options = options;
}