0

I am using the below dependency of webrtc in my Android App

implementation 'org.webrtc:google-webrtc:1.0.+'

How to Initialize PeerConnectionFactory, I am doing it in below manner but it is giving compilation error.

private void initializePeerConnectionFactory() {
    PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true);
    factory = new PeerConnectionFactory(null);
    factory.setVideoHwAccelerationOptions(rootEglBase.getEglBaseContext(), rootEglBase.getEglBaseContext());
}

I tried it with below fashion:

private void initializePeerConnectionFactory() {
    PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true);
    factory = new PeerConnectionFactory(null);
    factory.setVideoHwAccelerationOptions(rootEglBase.getEglBaseContext(), rootEglBase.getEglBaseContext());
}

But it's not working

Hille
  • 2,123
  • 22
  • 39

2 Answers2

0

As of today (25 Jan 2023), use the latest version of the dependency. As the older ones had security vulnerabilities and google play does not accept them.

You can initialize PeerConnectionFactory like this: https://webrtc.googlesource.com/src/+/refs/heads/main/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java?autodive=0%2F%2F

0

Using

org.webrtc:google-webrtc:1.0.32006

which I believe to be the latest version of webrtc available

you initialise the peer connection factory using the following code

   PeerConnectionFactory.InitializationOptions initializationOptions = PeerConnectionFactory.InitializationOptions.builder(getApplicationContext()).createInitializationOptions();
    PeerConnectionFactory.initialize(initializationOptions);
    //Create a new PeerConnectionFactory instance - using Hardware encoder and decoder.
    PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
    DefaultVideoEncoderFactory defaultVideoEncoderFactory = new DefaultVideoEncoderFactory(rootEglBase.getEglBaseContext(),  /* enableIntelVp8Encoder */true,  /* enableH264HighProfile */true);
    DefaultVideoDecoderFactory defaultVideoDecoderFactory = new DefaultVideoDecoderFactory(rootEglBase.getEglBaseContext());

    factory = PeerConnectionFactory.builder().setOptions(options)
            .setVideoEncoderFactory(defaultVideoEncoderFactory)
            .setVideoDecoderFactory(defaultVideoDecoderFactory)
            .createPeerConnectionFactory();

Hope this helps!