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