| 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 15 matching lines...) Expand all Loading... |
| 26 import android.util.Log; | 26 import android.util.Log; |
| 27 import android.view.View; | 27 import android.view.View; |
| 28 import android.view.Window; | 28 import android.view.Window; |
| 29 import android.view.WindowManager; | 29 import android.view.WindowManager; |
| 30 import android.view.WindowManager.LayoutParams; | 30 import android.view.WindowManager.LayoutParams; |
| 31 import android.widget.Toast; | 31 import android.widget.Toast; |
| 32 import java.io.IOException; | 32 import java.io.IOException; |
| 33 import java.lang.RuntimeException; | 33 import java.lang.RuntimeException; |
| 34 import java.util.ArrayList; | 34 import java.util.ArrayList; |
| 35 import java.util.List; | 35 import java.util.List; |
| 36 import java.util.Set; |
| 37 import org.appspot.apprtc.AppRTCAudioManager.AudioDevice; |
| 38 import org.appspot.apprtc.AppRTCAudioManager.AudioManagerEvents; |
| 36 import org.appspot.apprtc.AppRTCClient.RoomConnectionParameters; | 39 import org.appspot.apprtc.AppRTCClient.RoomConnectionParameters; |
| 37 import org.appspot.apprtc.AppRTCClient.SignalingParameters; | 40 import org.appspot.apprtc.AppRTCClient.SignalingParameters; |
| 38 import org.appspot.apprtc.PeerConnectionClient.DataChannelParameters; | 41 import org.appspot.apprtc.PeerConnectionClient.DataChannelParameters; |
| 39 import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters; | 42 import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters; |
| 40 import org.webrtc.Camera1Enumerator; | 43 import org.webrtc.Camera1Enumerator; |
| 41 import org.webrtc.Camera2Enumerator; | 44 import org.webrtc.Camera2Enumerator; |
| 42 import org.webrtc.CameraEnumerator; | 45 import org.webrtc.CameraEnumerator; |
| 43 import org.webrtc.EglBase; | 46 import org.webrtc.EglBase; |
| 44 import org.webrtc.FileVideoCapturer; | 47 import org.webrtc.FileVideoCapturer; |
| 45 import org.webrtc.IceCandidate; | 48 import org.webrtc.IceCandidate; |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 return; | 523 return; |
| 521 } | 524 } |
| 522 callStartedTimeMs = System.currentTimeMillis(); | 525 callStartedTimeMs = System.currentTimeMillis(); |
| 523 | 526 |
| 524 // Start room connection. | 527 // Start room connection. |
| 525 logAndToast(getString(R.string.connecting_to, roomConnectionParameters.roomU
rl)); | 528 logAndToast(getString(R.string.connecting_to, roomConnectionParameters.roomU
rl)); |
| 526 appRtcClient.connectToRoom(roomConnectionParameters); | 529 appRtcClient.connectToRoom(roomConnectionParameters); |
| 527 | 530 |
| 528 // Create and audio manager that will take care of audio routing, | 531 // Create and audio manager that will take care of audio routing, |
| 529 // audio modes, audio device enumeration etc. | 532 // audio modes, audio device enumeration etc. |
| 530 audioManager = AppRTCAudioManager.create(this, new Runnable() { | 533 audioManager = AppRTCAudioManager.create(this); |
| 531 // This method will be called each time the audio state (number and | 534 // Store existing audio settings and change audio mode to |
| 532 // type of devices) has been changed. | 535 // MODE_IN_COMMUNICATION for best possible VoIP performance. |
| 536 Log.d(TAG, "Starting the audio manager..."); |
| 537 audioManager.start(new AudioManagerEvents() { |
| 538 // This method will be called each time the number of available audio |
| 539 // devices has changed. |
| 533 @Override | 540 @Override |
| 534 public void run() { | 541 public void onAudioDeviceChanged( |
| 535 onAudioManagerChangedState(); | 542 AudioDevice audioDevice, Set<AudioDevice> availableAudioDevices) { |
| 543 onAudioManagerDevicesChanged(audioDevice, availableAudioDevices); |
| 536 } | 544 } |
| 537 }); | 545 }); |
| 538 // Store existing audio settings and change audio mode to | |
| 539 // MODE_IN_COMMUNICATION for best possible VoIP performance. | |
| 540 Log.d(TAG, "Initializing the audio manager..."); | |
| 541 audioManager.init(); | |
| 542 } | 546 } |
| 543 | 547 |
| 544 // Should be called from UI thread | 548 // Should be called from UI thread |
| 545 private void callConnected() { | 549 private void callConnected() { |
| 546 final long delta = System.currentTimeMillis() - callStartedTimeMs; | 550 final long delta = System.currentTimeMillis() - callStartedTimeMs; |
| 547 Log.i(TAG, "Call connected: delay=" + delta + "ms"); | 551 Log.i(TAG, "Call connected: delay=" + delta + "ms"); |
| 548 if (peerConnectionClient == null || isError) { | 552 if (peerConnectionClient == null || isError) { |
| 549 Log.w(TAG, "Call is connected in closed or error state"); | 553 Log.w(TAG, "Call is connected in closed or error state"); |
| 550 return; | 554 return; |
| 551 } | 555 } |
| 552 // Update video view. | 556 // Update video view. |
| 553 updateVideoView(); | 557 updateVideoView(); |
| 554 // Enable statistics callback. | 558 // Enable statistics callback. |
| 555 peerConnectionClient.enableStatsEvents(true, STAT_CALLBACK_PERIOD); | 559 peerConnectionClient.enableStatsEvents(true, STAT_CALLBACK_PERIOD); |
| 556 } | 560 } |
| 557 | 561 |
| 558 private void onAudioManagerChangedState() { | 562 // This method is called when the audio manager reports audio device change, |
| 559 // TODO(henrika): disable video if AppRTCAudioManager.AudioDevice.EARPIECE | 563 // e.g. from wired headset to speakerphone. |
| 560 // is active. | 564 private void onAudioManagerDevicesChanged( |
| 565 final AudioDevice device, final Set<AudioDevice> availableDevices) { |
| 566 Log.d(TAG, "onAudioManagerDevicesChanged: " + availableDevices + ", " |
| 567 + "selected: " + device); |
| 568 // TODO(henrika): add callback handler. |
| 561 } | 569 } |
| 562 | 570 |
| 563 // Disconnect from remote resources, dispose of local resources, and exit. | 571 // Disconnect from remote resources, dispose of local resources, and exit. |
| 564 private void disconnect() { | 572 private void disconnect() { |
| 565 activityRunning = false; | 573 activityRunning = false; |
| 566 if (appRtcClient != null) { | 574 if (appRtcClient != null) { |
| 567 appRtcClient.disconnectFromRoom(); | 575 appRtcClient.disconnectFromRoom(); |
| 568 appRtcClient = null; | 576 appRtcClient = null; |
| 569 } | 577 } |
| 570 if (peerConnectionClient != null) { | 578 if (peerConnectionClient != null) { |
| 571 peerConnectionClient.close(); | 579 peerConnectionClient.close(); |
| 572 peerConnectionClient = null; | 580 peerConnectionClient = null; |
| 573 } | 581 } |
| 574 if (localRender != null) { | 582 if (localRender != null) { |
| 575 localRender.release(); | 583 localRender.release(); |
| 576 localRender = null; | 584 localRender = null; |
| 577 } | 585 } |
| 578 if (videoFileRenderer != null) { | 586 if (videoFileRenderer != null) { |
| 579 videoFileRenderer.release(); | 587 videoFileRenderer.release(); |
| 580 videoFileRenderer = null; | 588 videoFileRenderer = null; |
| 581 } | 589 } |
| 582 if (remoteRenderScreen != null) { | 590 if (remoteRenderScreen != null) { |
| 583 remoteRenderScreen.release(); | 591 remoteRenderScreen.release(); |
| 584 remoteRenderScreen = null; | 592 remoteRenderScreen = null; |
| 585 } | 593 } |
| 586 if (audioManager != null) { | 594 if (audioManager != null) { |
| 587 audioManager.close(); | 595 audioManager.stop(); |
| 588 audioManager = null; | 596 audioManager = null; |
| 589 } | 597 } |
| 590 if (iceConnected && !isError) { | 598 if (iceConnected && !isError) { |
| 591 setResult(RESULT_OK); | 599 setResult(RESULT_OK); |
| 592 } else { | 600 } else { |
| 593 setResult(RESULT_CANCELED); | 601 setResult(RESULT_CANCELED); |
| 594 } | 602 } |
| 595 finish(); | 603 finish(); |
| 596 } | 604 } |
| 597 | 605 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 } | 889 } |
| 882 } | 890 } |
| 883 }); | 891 }); |
| 884 } | 892 } |
| 885 | 893 |
| 886 @Override | 894 @Override |
| 887 public void onPeerConnectionError(final String description) { | 895 public void onPeerConnectionError(final String description) { |
| 888 reportError(description); | 896 reportError(description); |
| 889 } | 897 } |
| 890 } | 898 } |
| OLD | NEW |