Changes default audio mode in AppRTCDemo to MODE_RINGTONE.
Also prevents that we try to restore audio mode when it has not been changed. TBR=glaznev BUG=NONE TEST=AppRTCDemo and verify that volume control switches from "Ringtone to Phone" mode when call starts and switches back to Ringtone mode when call ends. Review URL: https://webrtc-codereview.appspot.com/46879004 Cr-Commit-Position: refs/heads/master@{#8975}
This commit is contained in:
@ -151,10 +151,10 @@ public class AppRTCAudioManager {
|
||||
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
|
||||
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
|
||||
|
||||
// The AppRTC demo shall always run in COMMUNICATION mode since it will
|
||||
// result in best possible "VoIP settings", like audio routing, volume
|
||||
// control etc.
|
||||
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||
// Start by setting RINGTONE as default audio mode. The native WebRTC
|
||||
// audio layer will switch to COMMUNICATION mode when the first streaming
|
||||
// session starts and return to RINGTONE mode when all streaming stops.
|
||||
audioManager.setMode(AudioManager.MODE_RINGTONE);
|
||||
|
||||
// Always disable microphone mute during a WebRTC call.
|
||||
setMicrophoneMute(false);
|
||||
|
@ -145,6 +145,9 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
||||
}
|
||||
|
||||
int32_t StopPlayout() override {
|
||||
// Avoid using audio manger (JNI/Java cost) if playout was inactive.
|
||||
if (!Playing())
|
||||
return 0;
|
||||
int32_t err = output_.StopPlayout();
|
||||
if (!Recording()) {
|
||||
// Restore initial audio mode since all audio streaming is disabled.
|
||||
@ -163,6 +166,9 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
||||
}
|
||||
|
||||
int32_t StopRecording() override {
|
||||
// Avoid using audio manger (JNI/Java cost) if recording was inactive.
|
||||
if (!Recording())
|
||||
return 0;
|
||||
int32_t err = input_.StopRecording();
|
||||
if (!Playing()) {
|
||||
// Restore initial audio mode since all audio streaming is disabled.
|
||||
|
@ -50,6 +50,7 @@ class WebRtcAudioManager {
|
||||
private final AudioManager audioManager;
|
||||
|
||||
private boolean initialized = false;
|
||||
private boolean audioModeNeedsRestore = false;
|
||||
private int nativeSampleRate;
|
||||
private int nativeChannels;
|
||||
private int savedAudioMode = AudioManager.MODE_INVALID;
|
||||
@ -97,7 +98,9 @@ class WebRtcAudioManager {
|
||||
return;
|
||||
}
|
||||
// Restore previously stored audio states.
|
||||
setSpeakerphoneOn(savedIsSpeakerPhoneOn);
|
||||
if (audioModeNeedsRestore) {
|
||||
setSpeakerphoneOn(savedIsSpeakerPhoneOn);
|
||||
}
|
||||
audioManager.setMode(savedAudioMode);
|
||||
}
|
||||
|
||||
@ -112,11 +115,14 @@ class WebRtcAudioManager {
|
||||
}
|
||||
// Switch to COMMUNICATION mode for best possible VoIP performance.
|
||||
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||
} else {
|
||||
audioModeNeedsRestore = true;
|
||||
Logd("changing audio mode to: " + AUDIO_MODES[audioManager.getMode()]);
|
||||
} else if (audioModeNeedsRestore) {
|
||||
// Restore audio mode that was stored in init().
|
||||
audioManager.setMode(savedAudioMode);
|
||||
audioModeNeedsRestore = false;
|
||||
Logd("restoring audio mode to: " + AUDIO_MODES[audioManager.getMode()]);
|
||||
}
|
||||
Logd("changing audio mode to: " + AUDIO_MODES[audioManager.getMode()]);
|
||||
}
|
||||
|
||||
private void storeAudioParameters() {
|
||||
|
Reference in New Issue
Block a user