@Override public void onCreate() { super.onCreate(); initializeRandomNumberFix(); initializeLogging(); initializeDependencyInjection(); initializeJobManager(); initializeExpiringMessageManager(); initializeGcmCheck(); initializeSignedPreKeyCheck(); initializePeriodicTasks(); initializeCircumvention(); if (Build.VERSION.SDK_INT >= 11) { PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true); } }
PeerConnectionClient createPeerConnectionClient(MockRenderer localRenderer, MockRenderer remoteRenderer, PeerConnectionParameters peerConnectionParameters, VideoCapturer videoCapturer, EglBase.Context eglContext) { List<PeerConnection.IceServer> iceServers = new LinkedList<PeerConnection.IceServer>(); SignalingParameters signalingParameters = new SignalingParameters(iceServers, true, // iceServers, initiator. null, null, null, // clientId, wssUrl, wssPostUrl. null, null); // offerSdp, iceCandidates. PeerConnectionClient client = PeerConnectionClient.getInstance(); PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); options.networkIgnoreMask = 0; options.disableNetworkMonitor = true; client.setPeerConnectionFactoryOptions(options); client.createPeerConnectionFactory( InstrumentationRegistry.getTargetContext(), peerConnectionParameters, this); client.createPeerConnection( eglContext, localRenderer, remoteRenderer, videoCapturer, signalingParameters); client.createOffer(); return client; }
private void initializeWebRtc() { Set<String> HARDWARE_AEC_BLACKLIST = new HashSet<String>() {{ add("Pixel"); add("Pixel XL"); }}; Set<String> OPEN_SL_ES_WHITELIST = new HashSet<String>() {{ add("Pixel"); add("Pixel XL"); }}; if (Build.VERSION.SDK_INT >= 11) { if (HARDWARE_AEC_BLACKLIST.contains(Build.MODEL)) { WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true); } if (!OPEN_SL_ES_WHITELIST.contains(Build.MODEL)) { WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true); } PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true); } }
WebRTC(WebRTCTask task, MainActivity activity) { this.task = task; this.activity = activity; // Initialize Android globals // See https://bugs.chromium.org/p/webrtc/issues/detail?id=3416 PeerConnectionFactory.initializeAndroidGlobals(activity, false); // Set ICE servers List<PeerConnection.IceServer> iceServers = new ArrayList<>(); iceServers.add(new org.webrtc.PeerConnection.IceServer("stun:" + Config.STUN_SERVER)); if (Config.TURN_SERVER != null) { iceServers.add(new org.webrtc.PeerConnection.IceServer("turn:" + Config.TURN_SERVER, Config.TURN_USER, Config.TURN_PASS)); } // Create peer connection final PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); this.factory = new PeerConnectionFactory(options); this.constraints = new MediaConstraints(); this.pc = this.factory.createPeerConnection(iceServers, constraints, new PeerConnectionObserver()); // Add task message event handler this.task.setMessageHandler(new TaskMessageHandler()); }
public WebRtcClient(RtcListener listener, String host, PeerConnectionClient.PeerConnectionParameters params) { mListener = listener; pcParams = params; PeerConnectionFactory.initializeAndroidGlobals(listener, true, true, params.videoCodecHwAcceleration); factory = new PeerConnectionFactory(); MessageHandler messageHandler = new MessageHandler(); try { client = IO.socket(host); } catch (URISyntaxException e) { e.printStackTrace(); } client.on("id", messageHandler.onId); client.on("message", messageHandler.onMessage); client.connect(); iceServers.add(new PeerConnection.IceServer("stun:23.21.150.121")); iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")); pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true")); }
private void initializeOutboundCall() { id = UUID.randomUUID().toString(); final Application application = (Application) getApplication(); final PeerConnectionFactory factory = application.getWebRtcFactory(); final MediaStream mediaStream = factory.createLocalMediaStream(UUID.randomUUID().toString()); mediaStream.addTrack(factory.createAudioTrack( UUID.randomUUID().toString(), factory.createAudioSource(CONSTRAINTS) )); peerConnection = factory.createPeerConnection( application.getBuiltInIceServers(), CONSTRAINTS, new PeerConnectionObserver() ); peerConnection.addStream(mediaStream); peerConnection.createOffer(sdpObserver, CONSTRAINTS); }
private void initializeInboundCall() { id = getIntent().getStringExtra(EXTRA_SESSION_ID); final Application application = (Application) getApplication(); final PeerConnectionFactory factory = application.getWebRtcFactory(); peerConnection = factory.createPeerConnection( application.getBuiltInIceServers(), CONSTRAINTS, new PeerConnectionObserver() ); peerConnection.setRemoteDescription( sdpObserver, new SessionDescription( SessionDescription.Type.OFFER, getIntent().getStringExtra(EXTRA_REMOTE_SDP) ) ); }
private void createPeerConnectionFactoryInternal(Context context) { Log.d(TAG, "Create peer connection peerConnectionFactory. Use video: " + peerConnectionParameters.videoCallEnabled); // isError = false; // Initialize field trials. String field_trials = FIELD_TRIAL_AUTOMATIC_RESIZE; // Check if VP9 is used by default. if (peerConnectionParameters.videoCallEnabled && peerConnectionParameters.videoCodec != null && peerConnectionParameters.videoCodec.equals(NBMMediaConfiguration.NBMVideoCodec.VP9.toString())) { field_trials += FIELD_TRIAL_VP9; } PeerConnectionFactory.initializeFieldTrials(field_trials); if (!PeerConnectionFactory.initializeAndroidGlobals(context, true, true, peerConnectionParameters.videoCodecHwAcceleration)) { observer.onPeerConnectionError("Failed to initializeAndroidGlobals"); } peerConnectionFactory = new PeerConnectionFactory(); // ToDo: What about these options? // if (options != null) { // Log.d(TAG, "Factory networkIgnoreMask option: " + options.networkIgnoreMask); // peerConnectionFactory.setOptions(options); // } Log.d(TAG, "Peer connection peerConnectionFactory created."); }
public void CargarLibreriaNativaWebRTC() { final ProgressDialog ringProgressDialog = ProgressDialog.show(MainActivity.this, "Por favor espere ...", "Mientras que se descarga la informacion del servidor ...", true); ringProgressDialog.setCancelable(true); new MainActivity().runOnUiThread(new Runnable() { @Override public void run() { try { // Here you should write your time consuming task... // Let the progress ring for 10 seconds... if (!factoryStaticInitialized) { abortarSi(PeerConnectionFactory.initializeAndroidGlobals(MainActivity.this, true, true)); factoryStaticInitialized = true; //Thread.sleep(200); } } catch (Exception e) { Log.i(TAG, "Error en funcion Iniciar Libreria: " + e.getMessage()); } ringProgressDialog.dismiss(); } }); }
private boolean createPeerConnection(Context context) { boolean success = false; if (PeerConnectionFactory.initializeAndroidGlobals(context)) { PeerConnectionFactory factory = new PeerConnectionFactory(); List<IceServer> iceServers = new ArrayList<IceServer>(); iceServers.add(new IceServer("stun:stun.l.google.com:19302")); // For TURN servers the format would be: // new IceServer("turn:url", user, password) MediaConstraints mediaConstraints = new MediaConstraints(); mediaConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "false")); mediaConstraints.optional.add(new MediaConstraints.KeyValuePair("RtpDataChannels", "true")); peerConnection = factory.createPeerConnection(iceServers, mediaConstraints, this); localStream = factory.createLocalMediaStream("WEBRTC_WORKSHOP_NS"); localStream.addTrack(factory.createAudioTrack("WEBRTC_WORKSHOP_NSa1", factory.createAudioSource(new MediaConstraints()))); peerConnection.addStream(localStream, new MediaConstraints()); success = true; } return success; }
/** * Initialize globals */ private static void initializeAndroidGlobals(Context context) { if (!mIsInitialized) { try { mIsInitialized = PeerConnectionFactory.initializeAndroidGlobals( context, true, // enable audio initializing true, // enable video initializing true // enable hardware acceleration ); PeerConnectionFactory.initializeFieldTrials(null); mIsSupported = true; Log.d(LOG_TAG, "## initializeAndroidGlobals(): mIsInitialized=" + mIsInitialized); } catch (Throwable e) { Log.e(LOG_TAG, "## initializeAndroidGlobals(): Exception Msg=" + e.getMessage()); mIsInitialized = true; mIsSupported = false; } } }
private void initializeResources() { ApplicationContext.getInstance(this).injectDependencies(this); this.callState = CallState.STATE_IDLE; this.lockManager = new LockManager(this); this.peerConnectionFactory = new PeerConnectionFactory(new PeerConnectionFactoryOptions()); this.audioManager = new SignalAudioManager(this); this.bluetoothStateManager = new BluetoothStateManager(this, this); this.messageSender = messageSenderFactory.create(); this.messageSender.setSoTimeoutMillis(TimeUnit.SECONDS.toMillis(10)); this.accountManager.setSoTimeoutMillis(TimeUnit.SECONDS.toMillis(10)); }
public PeerConnectionWrapper(@NonNull Context context, @NonNull PeerConnectionFactory factory, @NonNull PeerConnection.Observer observer, @NonNull VideoRenderer.Callbacks localRenderer, @NonNull List<PeerConnection.IceServer> turnServers, boolean hideIp) { List<PeerConnection.IceServer> iceServers = new LinkedList<>(); iceServers.add(STUN_SERVER); iceServers.addAll(turnServers); MediaConstraints constraints = new MediaConstraints(); MediaConstraints audioConstraints = new MediaConstraints(); PeerConnection.RTCConfiguration configuration = new PeerConnection.RTCConfiguration(iceServers); configuration.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE; configuration.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE; if (hideIp) { configuration.iceTransportsType = PeerConnection.IceTransportsType.RELAY; } constraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true")); audioConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true")); this.peerConnection = factory.createPeerConnection(configuration, constraints, observer); this.videoCapturer = createVideoCapturer(context); MediaStream mediaStream = factory.createLocalMediaStream("ARDAMS"); this.audioSource = factory.createAudioSource(audioConstraints); this.audioTrack = factory.createAudioTrack("ARDAMSa0", audioSource); this.audioTrack.setEnabled(false); mediaStream.addTrack(audioTrack); if (videoCapturer != null) { this.videoSource = factory.createVideoSource(videoCapturer); this.videoTrack = factory.createVideoTrack("ARDAMSv0", videoSource); this.videoTrack.addRenderer(new VideoRenderer(localRenderer)); this.videoTrack.setEnabled(false); mediaStream.addTrack(videoTrack); } else { this.videoSource = null; this.videoTrack = null; } this.peerConnection.addStream(mediaStream); }
public PnPeerConnectionClient(Pubnub pubnub, PnSignalingParams signalingParams, PnRTCListener rtcListener){ this.mPubNub = pubnub; this.signalingParams = signalingParams; this.mRtcListener = rtcListener; this.pcFactory = new PeerConnectionFactory(); // TODO: Check it allowed, else extra param this.peers = new HashMap<String, PnPeer>(); sessionID = this.mPubNub.uuid(); init(); }
/** * PeerConnection factory initialization */ private void initPeerConnectionFactory() { PeerConnectionFactory.initializeAndroidGlobals(getApplicationContext(), true); mOptions = new PeerConnectionFactory.Options(); mOptions.networkIgnoreMask = 0; mPeerConnectionFactory = new PeerConnectionFactory(mOptions); Log.d(TAG, "Created PeerConnectionFactory."); mPeerConnectionFactory.setVideoHwAccelerationOptions( rootEglBase.getEglBaseContext(), rootEglBase.getEglBaseContext() ); }
@Test @SmallTest public void testJniLoadsWithoutError() throws InterruptedException { PeerConnectionFactory.initializeAndroidGlobals(InstrumentationRegistry.getTargetContext(), true /* initializeAudio */, true /* initializeVideo */, false /* videoCodecHwAcceleration */); PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); new PeerConnectionFactory(options); }
public void start() { start.setEnabled(false); call.setEnabled(true); //Initialize PeerConnectionFactory globals. //Params are context, initAudio,initVideo and videoCodecHwAcceleration PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true); //Create a new PeerConnectionFactory instance. PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); peerConnectionFactory = new PeerConnectionFactory(options); //Now create a VideoCapturer instance. Callback methods are there if you want to do something! Duh! VideoCapturer videoCapturerAndroid = getVideoCapturer(new CustomCameraEventsHandler()); //Create MediaConstraints - Will be useful for specifying video and audio constraints. audioConstraints = new MediaConstraints(); videoConstraints = new MediaConstraints(); //Create a VideoSource instance videoSource = peerConnectionFactory.createVideoSource(videoCapturerAndroid); localVideoTrack = peerConnectionFactory.createVideoTrack("100", videoSource); //create an AudioSource instance audioSource = peerConnectionFactory.createAudioSource(audioConstraints); localAudioTrack = peerConnectionFactory.createAudioTrack("101", audioSource); localVideoView.setVisibility(View.VISIBLE); //create a videoRenderer based on SurfaceViewRenderer instance localRenderer = new VideoRenderer(localVideoView); // And finally, with our VideoRenderer ready, we // can add our renderer to the VideoTrack. localVideoTrack.addRenderer(localRenderer); }
public WebRtcClient(RtcListener listener, String host, PeerConnectionParameters params) { mListener = listener; pcParams = params; PeerConnectionFactory.initializeAndroidGlobals(listener, true, true, params.videoCodecHwAcceleration); factory = new PeerConnectionFactory(); MessageHandler messageHandler = new MessageHandler(); Log.d(TAG, "WebRtcClient..host:" + host); try { Manager man = new Manager(new URI(host)); // client = IO.socket(host); client = man.socket("/hello"); } catch (URISyntaxException e) { e.printStackTrace(); Log.d(TAG, "WebRtcClient..exception"); } client.on("id", messageHandler.onId); client.on("message", messageHandler.onMessage); client.connect(); // iceServers.add(new PeerConnection.IceServer("stun:23.21.150.121")); iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")); pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true")); }
public void onAnswerButtonClicked(final View view) { progressState.changeValue(ProgressState.NEGOTIATING); showHangButton(); final PeerConnectionFactory factory = ((Application) getApplication()).getWebRtcFactory(); final MediaStream stream = factory.createLocalMediaStream(UUID.randomUUID().toString()); stream.addTrack(factory.createAudioTrack( UUID.randomUUID().toString(), factory.createAudioSource(CONSTRAINTS) )); peerConnection.addStream(stream); peerConnection.createAnswer(sdpObserver, new MediaConstraints()); }
@Nonnull public synchronized PeerConnectionFactory getWebRtcFactory() { if (webRtcFactory == null) { initializeWebRtc(); } return webRtcFactory; }
/** * Constructor. * @param factory Instance of PeerConnectionFactory * @param option option of connection */ MediaConnection(final PeerConnectionFactory factory, final PeerOption option) { mFactory = factory; mOption = option; mConnectionId = PREFIX_MEDIA_PEERJS + PeerUtil.randomToken(16); createPeerConnection(createIceServerList(option.getIceServer())); }
MediaResourceManager(NBMWebRTCPeer.NBMPeerConnectionParameters peerConnectionParameters, LooperExecutor executor, PeerConnectionFactory factory){ this.peerConnectionParameters = peerConnectionParameters; this.localMediaStream = null; this.executor = executor; this.factory = factory; renderVideo = true; remoteVideoTracks = new HashMap<>(); remoteVideoRenderers = new HashMap<>(); remoteVideoMediaStreams = new HashMap<>(); videoCallEnabled = peerConnectionParameters.videoCallEnabled; }
PeerConnectionResourceManager(NBMPeerConnectionParameters peerConnectionParameters, LooperExecutor executor, PeerConnectionFactory factory) { this.peerConnectionParameters = peerConnectionParameters; this.executor = executor; this.factory = factory; videoCallEnabled = peerConnectionParameters.videoCallEnabled; // Check if H.264 is used by default. preferH264 = videoCallEnabled && peerConnectionParameters.videoCodec != null && peerConnectionParameters.videoCodec.equals(NBMMediaConfiguration.NBMVideoCodec.H264.toString()); // Check if ISAC is used by default. preferIsac = peerConnectionParameters.audioCodec != null && peerConnectionParameters.audioCodec.equals(NBMMediaConfiguration.NBMAudioCodec.ISAC.toString()); connections = new HashMap<>(); }
public WebRTCCliente(RTCListener listener, String host) { mListener = listener; factory = new PeerConnectionFactory(); SocketIOClient.connect(host, new ConnectCallback() { @Override public void onConnectCompleted(Exception ex, SocketIOClient socket) { if (ex != null) { mListener.onStatusChanged("No se puedo conectar al Servidor WebSocket en la direccion: " + ex.getMessage()); //Log.e(TAG,"WebRTCCliente connect failed: "+ex.getMessage()); return; } mListener.onStatusChanged("Conectado al Servidor WebSocket."); // Log.d(TAG, "Conectado al Servidor WebRTC."); MainActivity.conectado_servidor = true; client = socket; // specify which events you are interested in receiving client.addListener("id", messageHandler); client.addListener("message", messageHandler); } }, new Handler()); iceServers.add(new PeerConnection.IceServer("stun:23.21.150.121")); iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302")); // Habilitar el uso de Datachannels 30.09/2014 // pcConstraints.optional.add(new MediaConstraints.KeyValuePair("RtpDataChannels", "true")); // pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "false")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")); }
public PnPeerConnectionClient(Pubnub pubnub, PnSignalingParams signalingParams, PnRTCListener rtcListener){ this.mPubNub = pubnub; this.signalingParams = signalingParams; this.mRtcListener = rtcListener; this.pcFactory = new PeerConnectionFactory(); // TODO: Check it allowed, else extra param this.peers = new HashMap<String, PnPeer>(); init(); }
/** * Notify the shared SDK instance that the specified client has connected. This is for internal use only, and should never be called by your client application. * * @param client The client that just connected */ public void clientConnected(RespokeClient client) { if (null != pushToken) { registerPushServices(); } if (!factoryStaticInitialized) { // Perform a one-time WebRTC global initialization PeerConnectionFactory.initializeAndroidGlobals(context, true, true, true, VideoRendererGui.getEGLContext()); factoryStaticInitialized = true; } }
public void setPeerConnectionFactoryOptions(PeerConnectionFactory.Options options) { this.options = options; }
private void closeInternal() { if (factory != null && peerConnectionParameters.aecDump) { factory.stopAecDump(); } Log.d(TAG, "Closing peer connection."); statsTimer.cancel(); if (dataChannel != null) { dataChannel.dispose(); dataChannel = null; } if (peerConnection != null) { peerConnection.dispose(); peerConnection = null; } Log.d(TAG, "Closing audio source."); if (audioSource != null) { audioSource.dispose(); audioSource = null; } Log.d(TAG, "Stopping capture."); if (videoCapturer != null) { try { videoCapturer.stopCapture(); } catch (InterruptedException e) { throw new RuntimeException(e); } videoCapturerStopped = true; videoCapturer.dispose(); videoCapturer = null; } Log.d(TAG, "Closing video source."); if (videoSource != null) { videoSource.dispose(); videoSource = null; } localRender = null; remoteRenders = null; Log.d(TAG, "Closing peer connection factory."); if (factory != null) { factory.dispose(); factory = null; } options = null; Log.d(TAG, "Closing peer connection done."); events.onPeerConnectionClosed(); PeerConnectionFactory.stopInternalTracingCapture(); PeerConnectionFactory.shutdownInternalTracer(); events = null; }
private void closeInternal() { if (factory != null && peerConnectionParameters.aecDump) { factory.stopAecDump(); } Log.d(TAG, "Closing peer connection."); statsTimer.cancel(); if (dataChannel != null) { dataChannel.dispose(); dataChannel = null; } if (peerConnection != null) { peerConnection.dispose(); peerConnection = null; } Log.d(TAG, "Closing audio source."); if (audioSource != null) { audioSource.dispose(); audioSource = null; } Log.d(TAG, "Stopping capture."); if (videoCapturer != null) { try { videoCapturer.stopCapture(); } catch (InterruptedException e) { throw new RuntimeException(e); } videoCapturerStopped = true; videoCapturer.dispose(); videoCapturer = null; } Log.d(TAG, "Closing video source."); if (videoSource != null) { videoSource.dispose(); videoSource = null; } localRender = null; remoteRenders = null; Log.d(TAG, "Closing peer connection factory."); if (factory != null) { factory.dispose(); factory = null; } options = null; rootEglBase.release(); Log.d(TAG, "Closing peer connection done."); events.onPeerConnectionClosed(); PeerConnectionFactory.stopInternalTracingCapture(); PeerConnectionFactory.shutdownInternalTracer(); events = null; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Initialize PeerConnectionFactory globals. //Params are context, initAudio,initVideo and videoCodecHwAcceleration PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true); //Create a new PeerConnectionFactory instance. PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); PeerConnectionFactory peerConnectionFactory = new PeerConnectionFactory(options); //Now create a VideoCapturer instance. Callback methods are there if you want to do something! Duh! VideoCapturer videoCapturerAndroid = createVideoCapturer(); //Create MediaConstraints - Will be useful for specifying video and audio constraints. More on this later! MediaConstraints constraints = new MediaConstraints(); //Create a VideoSource instance VideoSource videoSource = peerConnectionFactory.createVideoSource(videoCapturerAndroid); VideoTrack localVideoTrack = peerConnectionFactory.createVideoTrack("100", videoSource); //create an AudioSource instance AudioSource audioSource = peerConnectionFactory.createAudioSource(constraints); AudioTrack localAudioTrack = peerConnectionFactory.createAudioTrack("101", audioSource); //we will start capturing the video from the camera //width,height and fps videoCapturerAndroid.startCapture(1000, 1000, 30); //create surface renderer, init it and add the renderer to the track SurfaceViewRenderer videoView = (SurfaceViewRenderer) findViewById(R.id.surface_rendeer); videoView.setMirror(true); EglBase rootEglBase = EglBase.create(); videoView.init(rootEglBase.getEglBaseContext(), null); localVideoTrack.addRenderer(new VideoRenderer(videoView)); }
private void createPeerConnectionFactoryInternal(Context context, String host) { PeerConnectionFactory.initializeInternalTracer(); if (peerConnectionParameters.tracing) { PeerConnectionFactory.startInternalTracingCapture( Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "webrtc-trace.txt"); } Log.d(TAG, "Create peer connection factory. Use video: " + peerConnectionParameters.videoCallEnabled); isError = false; // Initialize field trials. PeerConnectionFactory.initializeFieldTrials(FIELD_TRIAL_AUTOMATIC_RESIZE); // Check preferred video codec. preferredVideoCodec = VIDEO_CODEC_VP8; if (videoCallEnabled && peerConnectionParameters.videoCodec != null) { if (peerConnectionParameters.videoCodec.equals(VIDEO_CODEC_VP9)) { preferredVideoCodec = VIDEO_CODEC_VP9; } else if (peerConnectionParameters.videoCodec.equals(VIDEO_CODEC_H264)) { preferredVideoCodec = VIDEO_CODEC_H264; } } Log.d(TAG, "Pereferred video codec: " + preferredVideoCodec); // Check if ISAC is used by default. preferIsac = false; if (peerConnectionParameters.audioCodec != null && peerConnectionParameters.audioCodec.equals(AUDIO_CODEC_ISAC)) { preferIsac = true; } // Enable/disable OpenSL ES playback. if (!peerConnectionParameters.useOpenSLES) { Log.d(TAG, "Disable OpenSL ES audio even if device supports it"); WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true /* enable */); } else { Log.d(TAG, "Allow OpenSL ES audio if device supports it"); WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(false); } // Create peer connection factory. if (!PeerConnectionFactory.initializeAndroidGlobals(context, true, true, peerConnectionParameters.videoCodecHwAcceleration)) { events.onPeerConnectionError("Failed to initializeAndroidGlobals"); } if (options != null) { Log.d(TAG, "Factory networkIgnoreMask option: " + options.networkIgnoreMask); } factory = new PeerConnectionFactory(); Log.d(TAG, "Peer connection factory created."); }
private void initializeWebRtc() { PeerConnectionFactory.initialize( PeerConnectionFactory.InitializationOptions.builder(this).createInitializationOptions() ); this.webRtcFactory = new PeerConnectionFactory(new PeerConnectionFactory.Options()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); audioManager.setSpeakerphoneOn(true); PeerConnectionFactory.initializeAndroidGlobals( this, // Context true, // Audio Enabled true, // Video Enabled true, // Hardware Acceleration Enabled null); // Render EGL Context peerConnectionFactory = new PeerConnectionFactory(); VideoCapturerAndroid vc = VideoCapturerAndroid.create(VideoCapturerAndroid.getNameOfFrontFacingDevice(), null); localVideoSource = peerConnectionFactory.createVideoSource(vc, new MediaConstraints()); VideoTrack localVideoTrack = peerConnectionFactory.createVideoTrack(VIDEO_TRACK_ID, localVideoSource); localVideoTrack.setEnabled(true); AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints()); AudioTrack localAudioTrack = peerConnectionFactory.createAudioTrack(AUDIO_TRACK_ID, audioSource); localAudioTrack.setEnabled(true); localMediaStream = peerConnectionFactory.createLocalMediaStream(LOCAL_STREAM_ID); localMediaStream.addTrack(localVideoTrack); localMediaStream.addTrack(localAudioTrack); GLSurfaceView videoView = (GLSurfaceView) findViewById(R.id.glview_call); VideoRendererGui.setView(videoView, null); try { otherPeerRenderer = VideoRendererGui.createGui(0, 0, 100, 100, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true); VideoRenderer renderer = VideoRendererGui.createGui(50, 50, 50, 50, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true); localVideoTrack.addRenderer(renderer); } catch (Exception e) { e.printStackTrace(); } }
MediaStream(final PeerConnectionFactory factory, final PeerOption option) { mFactory = factory; mOption = option; createMediaConstraints(option); mMediaStream = createMediaStream(); }