Removes automatic setting of COMM mode in WebRTC.
It is now up to the application to ensure that it is in COMM mode before any audio streaming is started. BUG=b/21571563 R=glaznev@webrtc.org Review URL: https://codereview.webrtc.org/1165923002 Cr-Commit-Position: refs/heads/master@{#9383}
This commit is contained in:
parent
3b2f67d90f
commit
fe55c38eff
@ -151,10 +151,11 @@ public class AppRTCAudioManager {
|
|||||||
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
|
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
|
||||||
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
|
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
|
||||||
|
|
||||||
// Start by setting RINGTONE as default audio mode. The native WebRTC
|
// Start by setting MODE_IN_COMMUNICATION as default audio mode. It is
|
||||||
// audio layer will switch to COMMUNICATION mode when the first streaming
|
// required to be in this mode when playout and/or recording starts for
|
||||||
// session starts and return to RINGTONE mode when all streaming stops.
|
// best possible VoIP performance.
|
||||||
audioManager.setMode(AudioManager.MODE_RINGTONE);
|
// TODO(henrika): we migh want to start with RINGTONE mode here instead.
|
||||||
|
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||||
|
|
||||||
// Always disable microphone mute during a WebRTC call.
|
// Always disable microphone mute during a WebRTC call.
|
||||||
setMicrophoneMute(false);
|
setMicrophoneMute(false);
|
||||||
|
@ -11,12 +11,17 @@
|
|||||||
#ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
|
#ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
|
||||||
#define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
|
#define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
|
||||||
|
|
||||||
|
#include <android/log.h>
|
||||||
|
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
#include "webrtc/base/thread_checker.h"
|
#include "webrtc/base/thread_checker.h"
|
||||||
#include "webrtc/modules/audio_device/android/audio_manager.h"
|
#include "webrtc/modules/audio_device/android/audio_manager.h"
|
||||||
#include "webrtc/modules/audio_device/audio_device_generic.h"
|
#include "webrtc/modules/audio_device/audio_device_generic.h"
|
||||||
#include "webrtc/system_wrappers/interface/trace.h"
|
#include "webrtc/system_wrappers/interface/trace.h"
|
||||||
|
|
||||||
|
#define TAG "AudioDeviceTemplate"
|
||||||
|
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
// InputType/OutputType can be any class that implements the capturing/rendering
|
// InputType/OutputType can be any class that implements the capturing/rendering
|
||||||
@ -125,12 +130,6 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t InitPlayout() override {
|
int32_t InitPlayout() override {
|
||||||
// Switches the Android audio mode to MODE_IN_COMMUNICATION to ensure that
|
|
||||||
// audio routing, volume control and echo performance are the best possible
|
|
||||||
// for VoIP. InitRecording() does the same type of call but only the first
|
|
||||||
// call has any effect.
|
|
||||||
// This call does nothing if MODE_IN_COMMUNICATION was already set.
|
|
||||||
audio_manager_->SetCommunicationMode(true);
|
|
||||||
return output_.InitPlayout();
|
return output_.InitPlayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,12 +143,6 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t InitRecording() override {
|
int32_t InitRecording() override {
|
||||||
// Switches the Android audio mode to MODE_IN_COMMUNICATION to ensure that
|
|
||||||
// audio routing, volume control and echo performance are the best possible
|
|
||||||
// for VoIP. InitRecording() does the same type of call but only the first
|
|
||||||
// call has any effect.
|
|
||||||
// This call does nothing if MODE_IN_COMMUNICATION was already set.
|
|
||||||
audio_manager_->SetCommunicationMode(true);
|
|
||||||
return input_.InitRecording();
|
return input_.InitRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,6 +151,9 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t StartPlayout() override {
|
int32_t StartPlayout() override {
|
||||||
|
if (!audio_manager_->IsCommunicationModeEnabled()) {
|
||||||
|
ALOGW("The application should use MODE_IN_COMMUNICATION audio mode!");
|
||||||
|
}
|
||||||
return output_.StartPlayout();
|
return output_.StartPlayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,11 +162,6 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
|||||||
if (!Playing())
|
if (!Playing())
|
||||||
return 0;
|
return 0;
|
||||||
int32_t err = output_.StopPlayout();
|
int32_t err = output_.StopPlayout();
|
||||||
if (!Recording()) {
|
|
||||||
// Restore initial audio mode since all audio streaming is disabled.
|
|
||||||
// The default mode was stored in Init().
|
|
||||||
audio_manager_->SetCommunicationMode(false);
|
|
||||||
}
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +170,9 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t StartRecording() override {
|
int32_t StartRecording() override {
|
||||||
|
if (!audio_manager_->IsCommunicationModeEnabled()) {
|
||||||
|
ALOGW("The application should use MODE_IN_COMMUNICATION audio mode!");
|
||||||
|
}
|
||||||
return input_.StartRecording();
|
return input_.StartRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,11 +181,6 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
|
|||||||
if (!Recording())
|
if (!Recording())
|
||||||
return 0;
|
return 0;
|
||||||
int32_t err = input_.StopRecording();
|
int32_t err = input_.StopRecording();
|
||||||
if (!Playing()) {
|
|
||||||
// Restore initial audio mode since all audio streaming is disabled.
|
|
||||||
// The default mode was is stored in Init().
|
|
||||||
audio_manager_->SetCommunicationMode(false);
|
|
||||||
}
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ AudioManager::JavaAudioManager::JavaAudioManager(
|
|||||||
: audio_manager_(audio_manager.Pass()),
|
: audio_manager_(audio_manager.Pass()),
|
||||||
init_(native_reg->GetMethodId("init", "()Z")),
|
init_(native_reg->GetMethodId("init", "()Z")),
|
||||||
dispose_(native_reg->GetMethodId("dispose", "()V")),
|
dispose_(native_reg->GetMethodId("dispose", "()V")),
|
||||||
set_communication_mode_(
|
is_communication_mode_enabled_(
|
||||||
native_reg->GetMethodId("setCommunicationMode", "(Z)V")) {
|
native_reg->GetMethodId("isCommunicationModeEnabled", "()Z")) {
|
||||||
ALOGD("JavaAudioManager::ctor%s", GetThreadInfo().c_str());
|
ALOGD("JavaAudioManager::ctor%s", GetThreadInfo().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,9 +50,8 @@ void AudioManager::JavaAudioManager::Close() {
|
|||||||
audio_manager_->CallVoidMethod(dispose_);
|
audio_manager_->CallVoidMethod(dispose_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioManager::JavaAudioManager::SetCommunicationMode(bool enable) {
|
bool AudioManager::JavaAudioManager::IsCommunicationModeEnabled() {
|
||||||
audio_manager_->CallVoidMethod(set_communication_mode_,
|
return audio_manager_->CallBooleanMethod(is_communication_mode_enabled_);
|
||||||
static_cast<jboolean>(enable));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AudioManager implementation
|
// AudioManager implementation
|
||||||
@ -126,11 +125,10 @@ bool AudioManager::Close() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioManager::SetCommunicationMode(bool enable) {
|
bool AudioManager::IsCommunicationModeEnabled() const {
|
||||||
ALOGD("SetCommunicationMode(%d)%s", enable, GetThreadInfo().c_str());
|
ALOGD("IsCommunicationModeEnabled()");
|
||||||
DCHECK(thread_checker_.CalledOnValidThread());
|
DCHECK(thread_checker_.CalledOnValidThread());
|
||||||
DCHECK(initialized_);
|
return j_audio_manager_->IsCommunicationModeEnabled();
|
||||||
j_audio_manager_->SetCommunicationMode(enable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioManager::IsAcousticEchoCancelerSupported() const {
|
bool AudioManager::IsAcousticEchoCancelerSupported() const {
|
||||||
|
@ -97,13 +97,13 @@ class AudioManager {
|
|||||||
|
|
||||||
bool Init();
|
bool Init();
|
||||||
void Close();
|
void Close();
|
||||||
void SetCommunicationMode(bool enable);
|
bool IsCommunicationModeEnabled();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rtc::scoped_ptr<GlobalRef> audio_manager_;
|
rtc::scoped_ptr<GlobalRef> audio_manager_;
|
||||||
jmethodID init_;
|
jmethodID init_;
|
||||||
jmethodID dispose_;
|
jmethodID dispose_;
|
||||||
jmethodID set_communication_mode_;
|
jmethodID is_communication_mode_enabled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
AudioManager();
|
AudioManager();
|
||||||
@ -118,9 +118,8 @@ class AudioManager {
|
|||||||
// Revert any setting done by Init().
|
// Revert any setting done by Init().
|
||||||
bool Close();
|
bool Close();
|
||||||
|
|
||||||
// Sets audio mode to AudioManager.MODE_IN_COMMUNICATION if |enable| is true.
|
// Returns true if current audio mode is AudioManager.MODE_IN_COMMUNICATION.
|
||||||
// Restores audio mode that was stored in Init() if |enable| is false.
|
bool IsCommunicationModeEnabled() const;
|
||||||
void SetCommunicationMode(bool enable);
|
|
||||||
|
|
||||||
// Native audio parameters stored during construction.
|
// Native audio parameters stored during construction.
|
||||||
const AudioParameters& GetPlayoutAudioParameters();
|
const AudioParameters& GetPlayoutAudioParameters();
|
||||||
|
@ -62,10 +62,8 @@ class WebRtcAudioManager {
|
|||||||
private final AudioManager audioManager;
|
private final AudioManager audioManager;
|
||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
private boolean audioModeNeedsRestore = false;
|
|
||||||
private int nativeSampleRate;
|
private int nativeSampleRate;
|
||||||
private int nativeChannels;
|
private int nativeChannels;
|
||||||
private int savedAudioMode = AudioManager.MODE_INVALID;
|
|
||||||
|
|
||||||
private boolean hardwareAEC;
|
private boolean hardwareAEC;
|
||||||
private boolean lowLatencyOutput;
|
private boolean lowLatencyOutput;
|
||||||
@ -94,16 +92,7 @@ class WebRtcAudioManager {
|
|||||||
if (initialized) {
|
if (initialized) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Logd("audio mode is: " + AUDIO_MODES[audioManager.getMode()]);
|
||||||
// Store current audio state so we can restore it when close() or
|
|
||||||
// setCommunicationMode(false) is called.
|
|
||||||
savedAudioMode = audioManager.getMode();
|
|
||||||
|
|
||||||
if (DEBUG) {
|
|
||||||
Logd("savedAudioMode: " + savedAudioMode);
|
|
||||||
Logd("hasEarpiece: " + hasEarpiece());
|
|
||||||
}
|
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -113,31 +102,10 @@ class WebRtcAudioManager {
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Restore previously stored audio states.
|
|
||||||
if (audioModeNeedsRestore) {
|
|
||||||
audioManager.setMode(savedAudioMode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCommunicationMode(boolean enable) {
|
private boolean isCommunicationModeEnabled() {
|
||||||
Logd("setCommunicationMode(" + enable + ")"
|
return (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION);
|
||||||
+ WebRtcAudioUtils.getThreadInfo());
|
|
||||||
assertTrue(initialized);
|
|
||||||
if (enable) {
|
|
||||||
// Avoid switching mode if MODE_IN_COMMUNICATION is already in use.
|
|
||||||
if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Switch to COMMUNICATION mode for best possible VoIP performance.
|
|
||||||
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
|
||||||
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()]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeAudioParameters() {
|
private void storeAudioParameters() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user