OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 import java.util.Set; | 38 import java.util.Set; |
39 import org.appspot.apprtc.AppRTCAudioManager.AudioDevice; | 39 import org.appspot.apprtc.AppRTCAudioManager.AudioDevice; |
40 import org.appspot.apprtc.AppRTCAudioManager.AudioManagerEvents; | 40 import org.appspot.apprtc.AppRTCAudioManager.AudioManagerEvents; |
41 import org.appspot.apprtc.AppRTCClient.RoomConnectionParameters; | 41 import org.appspot.apprtc.AppRTCClient.RoomConnectionParameters; |
42 import org.appspot.apprtc.AppRTCClient.SignalingParameters; | 42 import org.appspot.apprtc.AppRTCClient.SignalingParameters; |
43 import org.appspot.apprtc.PeerConnectionClient.DataChannelParameters; | 43 import org.appspot.apprtc.PeerConnectionClient.DataChannelParameters; |
44 import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters; | 44 import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters; |
45 import org.webrtc.Camera1Enumerator; | 45 import org.webrtc.Camera1Enumerator; |
46 import org.webrtc.Camera2Enumerator; | 46 import org.webrtc.Camera2Enumerator; |
47 import org.webrtc.CameraEnumerator; | 47 import org.webrtc.CameraEnumerator; |
48 import org.webrtc.EglBase; | |
49 import org.webrtc.FileVideoCapturer; | 48 import org.webrtc.FileVideoCapturer; |
50 import org.webrtc.IceCandidate; | 49 import org.webrtc.IceCandidate; |
51 import org.webrtc.Logging; | 50 import org.webrtc.Logging; |
52 import org.webrtc.PeerConnectionFactory; | 51 import org.webrtc.PeerConnectionFactory; |
53 import org.webrtc.RendererCommon.ScalingType; | 52 import org.webrtc.RendererCommon.ScalingType; |
54 import org.webrtc.ScreenCapturerAndroid; | 53 import org.webrtc.ScreenCapturerAndroid; |
55 import org.webrtc.SessionDescription; | 54 import org.webrtc.SessionDescription; |
56 import org.webrtc.StatsReport; | 55 import org.webrtc.StatsReport; |
57 import org.webrtc.SurfaceViewRenderer; | 56 import org.webrtc.SurfaceViewRenderer; |
58 import org.webrtc.VideoCapturer; | 57 import org.webrtc.VideoCapturer; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 this.target = target; | 154 this.target = target; |
156 } | 155 } |
157 } | 156 } |
158 | 157 |
159 private final ProxyRenderer remoteProxyRenderer = new ProxyRenderer(); | 158 private final ProxyRenderer remoteProxyRenderer = new ProxyRenderer(); |
160 private final ProxyRenderer localProxyRenderer = new ProxyRenderer(); | 159 private final ProxyRenderer localProxyRenderer = new ProxyRenderer(); |
161 private PeerConnectionClient peerConnectionClient = null; | 160 private PeerConnectionClient peerConnectionClient = null; |
162 private AppRTCClient appRtcClient; | 161 private AppRTCClient appRtcClient; |
163 private SignalingParameters signalingParameters; | 162 private SignalingParameters signalingParameters; |
164 private AppRTCAudioManager audioManager = null; | 163 private AppRTCAudioManager audioManager = null; |
165 private EglBase rootEglBase; | |
166 private SurfaceViewRenderer pipRenderer; | 164 private SurfaceViewRenderer pipRenderer; |
167 private SurfaceViewRenderer fullscreenRenderer; | 165 private SurfaceViewRenderer fullscreenRenderer; |
168 private VideoFileRenderer videoFileRenderer; | 166 private VideoFileRenderer videoFileRenderer; |
169 private final List<VideoRenderer.Callbacks> remoteRenderers = | 167 private final List<VideoRenderer.Callbacks> remoteRenderers = |
170 new ArrayList<VideoRenderer.Callbacks>(); | 168 new ArrayList<VideoRenderer.Callbacks>(); |
171 private Toast logToast; | 169 private Toast logToast; |
172 private boolean commandLineRun; | 170 private boolean commandLineRun; |
173 private int runTimeMs; | 171 private int runTimeMs; |
174 private boolean activityRunning; | 172 private boolean activityRunning; |
175 private RoomConnectionParameters roomConnectionParameters; | 173 private RoomConnectionParameters roomConnectionParameters; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 public void onClick(View view) { | 225 public void onClick(View view) { |
228 setSwappedFeeds(!isSwappedFeeds); | 226 setSwappedFeeds(!isSwappedFeeds); |
229 } | 227 } |
230 }); | 228 }); |
231 | 229 |
232 fullscreenRenderer.setOnClickListener(listener); | 230 fullscreenRenderer.setOnClickListener(listener); |
233 remoteRenderers.add(remoteProxyRenderer); | 231 remoteRenderers.add(remoteProxyRenderer); |
234 | 232 |
235 final Intent intent = getIntent(); | 233 final Intent intent = getIntent(); |
236 | 234 |
| 235 // Create peer connection client. |
| 236 peerConnectionClient = new PeerConnectionClient(); |
| 237 |
237 // Create video renderers. | 238 // Create video renderers. |
238 rootEglBase = EglBase.create(); | 239 pipRenderer.init(peerConnectionClient.getRenderContext(), null); |
239 pipRenderer.init(rootEglBase.getEglBaseContext(), null); | |
240 pipRenderer.setScalingType(ScalingType.SCALE_ASPECT_FIT); | 240 pipRenderer.setScalingType(ScalingType.SCALE_ASPECT_FIT); |
241 String saveRemoteVideoToFile = intent.getStringExtra(EXTRA_SAVE_REMOTE_VIDEO
_TO_FILE); | 241 String saveRemoteVideoToFile = intent.getStringExtra(EXTRA_SAVE_REMOTE_VIDEO
_TO_FILE); |
242 | 242 |
243 // When saveRemoteVideoToFile is set we save the video from the remote to a
file. | 243 // When saveRemoteVideoToFile is set we save the video from the remote to a
file. |
244 if (saveRemoteVideoToFile != null) { | 244 if (saveRemoteVideoToFile != null) { |
245 int videoOutWidth = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WID
TH, 0); | 245 int videoOutWidth = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WID
TH, 0); |
246 int videoOutHeight = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HE
IGHT, 0); | 246 int videoOutHeight = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HE
IGHT, 0); |
247 try { | 247 try { |
248 videoFileRenderer = new VideoFileRenderer( | 248 videoFileRenderer = new VideoFileRenderer(saveRemoteVideoToFile, videoOu
tWidth, |
249 saveRemoteVideoToFile, videoOutWidth, videoOutHeight, rootEglBase.ge
tEglBaseContext()); | 249 videoOutHeight, peerConnectionClient.getRenderContext()); |
250 remoteRenderers.add(videoFileRenderer); | 250 remoteRenderers.add(videoFileRenderer); |
251 } catch (IOException e) { | 251 } catch (IOException e) { |
252 throw new RuntimeException( | 252 throw new RuntimeException( |
253 "Failed to open video file for output: " + saveRemoteVideoToFile, e)
; | 253 "Failed to open video file for output: " + saveRemoteVideoToFile, e)
; |
254 } | 254 } |
255 } | 255 } |
256 fullscreenRenderer.init(rootEglBase.getEglBaseContext(), null); | 256 fullscreenRenderer.init(peerConnectionClient.getRenderContext(), null); |
257 fullscreenRenderer.setScalingType(ScalingType.SCALE_ASPECT_FILL); | 257 fullscreenRenderer.setScalingType(ScalingType.SCALE_ASPECT_FILL); |
258 | 258 |
259 pipRenderer.setZOrderMediaOverlay(true); | 259 pipRenderer.setZOrderMediaOverlay(true); |
260 pipRenderer.setEnableHardwareScaler(true /* enabled */); | 260 pipRenderer.setEnableHardwareScaler(true /* enabled */); |
261 fullscreenRenderer.setEnableHardwareScaler(true /* enabled */); | 261 fullscreenRenderer.setEnableHardwareScaler(true /* enabled */); |
262 // Start with local feed in fullscreen and swap it to the pip when the call
is connected. | 262 // Start with local feed in fullscreen and swap it to the pip when the call
is connected. |
263 setSwappedFeeds(true /* isSwappedFeeds */); | 263 setSwappedFeeds(true /* isSwappedFeeds */); |
264 | 264 |
265 // Check for mandatory permissions. | 265 // Check for mandatory permissions. |
266 for (String permission : MANDATORY_PERMISSIONS) { | 266 for (String permission : MANDATORY_PERMISSIONS) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 // For command line execution run connection for <runTimeMs> and exit. | 361 // For command line execution run connection for <runTimeMs> and exit. |
362 if (commandLineRun && runTimeMs > 0) { | 362 if (commandLineRun && runTimeMs > 0) { |
363 (new Handler()).postDelayed(new Runnable() { | 363 (new Handler()).postDelayed(new Runnable() { |
364 @Override | 364 @Override |
365 public void run() { | 365 public void run() { |
366 disconnect(); | 366 disconnect(); |
367 } | 367 } |
368 }, runTimeMs); | 368 }, runTimeMs); |
369 } | 369 } |
370 | 370 |
371 peerConnectionClient = PeerConnectionClient.getInstance(); | |
372 if (loopback) { | 371 if (loopback) { |
373 PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(
); | 372 PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(
); |
374 options.networkIgnoreMask = 0; | 373 options.networkIgnoreMask = 0; |
375 peerConnectionClient.setPeerConnectionFactoryOptions(options); | 374 peerConnectionClient.setPeerConnectionFactoryOptions(options); |
376 } | 375 } |
377 peerConnectionClient.createPeerConnectionFactory( | 376 peerConnectionClient.createPeerConnectionFactory( |
378 getApplicationContext(), peerConnectionParameters, CallActivity.this); | 377 getApplicationContext(), peerConnectionParameters, CallActivity.this); |
379 | 378 |
380 if (screencaptureEnabled) { | 379 if (screencaptureEnabled) { |
381 startScreenCapture(); | 380 startScreenCapture(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 } | 499 } |
501 | 500 |
502 @Override | 501 @Override |
503 protected void onDestroy() { | 502 protected void onDestroy() { |
504 Thread.setDefaultUncaughtExceptionHandler(null); | 503 Thread.setDefaultUncaughtExceptionHandler(null); |
505 disconnect(); | 504 disconnect(); |
506 if (logToast != null) { | 505 if (logToast != null) { |
507 logToast.cancel(); | 506 logToast.cancel(); |
508 } | 507 } |
509 activityRunning = false; | 508 activityRunning = false; |
510 rootEglBase.release(); | |
511 super.onDestroy(); | 509 super.onDestroy(); |
512 } | 510 } |
513 | 511 |
514 // CallFragment.OnCallEvents interface implementation. | 512 // CallFragment.OnCallEvents interface implementation. |
515 @Override | 513 @Override |
516 public void onCallHangUp() { | 514 public void onCallHangUp() { |
517 disconnect(); | 515 disconnect(); |
518 } | 516 } |
519 | 517 |
520 @Override | 518 @Override |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 614 |
617 // Disconnect from remote resources, dispose of local resources, and exit. | 615 // Disconnect from remote resources, dispose of local resources, and exit. |
618 private void disconnect() { | 616 private void disconnect() { |
619 activityRunning = false; | 617 activityRunning = false; |
620 remoteProxyRenderer.setTarget(null); | 618 remoteProxyRenderer.setTarget(null); |
621 localProxyRenderer.setTarget(null); | 619 localProxyRenderer.setTarget(null); |
622 if (appRtcClient != null) { | 620 if (appRtcClient != null) { |
623 appRtcClient.disconnectFromRoom(); | 621 appRtcClient.disconnectFromRoom(); |
624 appRtcClient = null; | 622 appRtcClient = null; |
625 } | 623 } |
626 if (peerConnectionClient != null) { | |
627 peerConnectionClient.close(); | |
628 peerConnectionClient = null; | |
629 } | |
630 if (pipRenderer != null) { | 624 if (pipRenderer != null) { |
631 pipRenderer.release(); | 625 pipRenderer.release(); |
632 pipRenderer = null; | 626 pipRenderer = null; |
633 } | 627 } |
634 if (videoFileRenderer != null) { | 628 if (videoFileRenderer != null) { |
635 videoFileRenderer.release(); | 629 videoFileRenderer.release(); |
636 videoFileRenderer = null; | 630 videoFileRenderer = null; |
637 } | 631 } |
638 if (fullscreenRenderer != null) { | 632 if (fullscreenRenderer != null) { |
639 fullscreenRenderer.release(); | 633 fullscreenRenderer.release(); |
640 fullscreenRenderer = null; | 634 fullscreenRenderer = null; |
641 } | 635 } |
| 636 if (peerConnectionClient != null) { |
| 637 peerConnectionClient.close(); |
| 638 peerConnectionClient = null; |
| 639 } |
642 if (audioManager != null) { | 640 if (audioManager != null) { |
643 audioManager.stop(); | 641 audioManager.stop(); |
644 audioManager = null; | 642 audioManager = null; |
645 } | 643 } |
646 if (iceConnected && !isError) { | 644 if (iceConnected && !isError) { |
647 setResult(RESULT_OK); | 645 setResult(RESULT_OK); |
648 } else { | 646 } else { |
649 setResult(RESULT_CANCELED); | 647 setResult(RESULT_CANCELED); |
650 } | 648 } |
651 finish(); | 649 finish(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 // are routed to UI thread. | 738 // are routed to UI thread. |
741 private void onConnectedToRoomInternal(final SignalingParameters params) { | 739 private void onConnectedToRoomInternal(final SignalingParameters params) { |
742 final long delta = System.currentTimeMillis() - callStartedTimeMs; | 740 final long delta = System.currentTimeMillis() - callStartedTimeMs; |
743 | 741 |
744 signalingParameters = params; | 742 signalingParameters = params; |
745 logAndToast("Creating peer connection, delay=" + delta + "ms"); | 743 logAndToast("Creating peer connection, delay=" + delta + "ms"); |
746 VideoCapturer videoCapturer = null; | 744 VideoCapturer videoCapturer = null; |
747 if (peerConnectionParameters.videoCallEnabled) { | 745 if (peerConnectionParameters.videoCallEnabled) { |
748 videoCapturer = createVideoCapturer(); | 746 videoCapturer = createVideoCapturer(); |
749 } | 747 } |
750 peerConnectionClient.createPeerConnection(rootEglBase.getEglBaseContext(), l
ocalProxyRenderer, | 748 peerConnectionClient.createPeerConnection( |
751 remoteRenderers, videoCapturer, signalingParameters); | 749 localProxyRenderer, remoteRenderers, videoCapturer, signalingParameters)
; |
752 | 750 |
753 if (signalingParameters.initiator) { | 751 if (signalingParameters.initiator) { |
754 logAndToast("Creating OFFER..."); | 752 logAndToast("Creating OFFER..."); |
755 // Create offer. Offer SDP will be sent to answering client in | 753 // Create offer. Offer SDP will be sent to answering client in |
756 // PeerConnectionEvents.onLocalDescription event. | 754 // PeerConnectionEvents.onLocalDescription event. |
757 peerConnectionClient.createOffer(); | 755 peerConnectionClient.createOffer(); |
758 } else { | 756 } else { |
759 if (params.offerSdp != null) { | 757 if (params.offerSdp != null) { |
760 peerConnectionClient.setRemoteDescription(params.offerSdp); | 758 peerConnectionClient.setRemoteDescription(params.offerSdp); |
761 logAndToast("Creating ANSWER..."); | 759 logAndToast("Creating ANSWER..."); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 } | 934 } |
937 } | 935 } |
938 }); | 936 }); |
939 } | 937 } |
940 | 938 |
941 @Override | 939 @Override |
942 public void onPeerConnectionError(final String description) { | 940 public void onPeerConnectionError(final String description) { |
943 reportError(description); | 941 reportError(description); |
944 } | 942 } |
945 } | 943 } |
OLD | NEW |