Commit 10cf237d authored by wjia@chromium.org's avatar wjia@chromium.org

Enable audio capture on Android

Patch by leozwang@chromium.org (https://codereview.chromium.org/12218036/).

This CL JUST enables audio capture on Android, further tunning and
making audio work better might take extra time, I think it's better to
first enable it. A few TODOs are added and minor changes are added into
CL too.

BUG=161417

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181948 0039d316-1c4b-4281-b951-d872f2087c98
parent 9b3f7e24
......@@ -52,6 +52,9 @@ static int GetBufferSizeForSampleRate(int sample_rate) {
// TODO(henrika): It might be possible to reduce the input buffer
// size and reduce the delay even more.
buffer_size = 2 * sample_rate / 100;
#elif defined(OS_ANDROID)
// TODO(leozwang): Tune and adjust buffer size on Android.
buffer_size = 2 * sample_rate / 100;
#endif
return buffer_size;
......
......@@ -322,7 +322,15 @@ TEST_F(WebRTCAudioDeviceTest, DISABLED_StartPlayout) {
// to send encoded packets to the network. Our main interest here is to ensure
// that the audio capturing starts as it should.
// Disabled when running headless since the bots don't have the required config.
TEST_F(WebRTCAudioDeviceTest, StartRecording) {
// TODO(leozwang): Because ExternalMediaProcessing is disabled in webrtc,
// disable this unit test on Android for now.
#if defined(OS_ANDROID)
#define MAYBE_StartRecording DISABLED_StartRecording
#else
#define MAYBE_StartRecording StartRecording
#endif
TEST_F(WebRTCAudioDeviceTest, MAYBE_StartRecording) {
if (!has_input_devices_ || !has_output_devices_) {
LOG(WARNING) << "Missing audio devices.";
return;
......@@ -466,7 +474,13 @@ TEST_F(WebRTCAudioDeviceTest, DISABLED_PlayLocalFile) {
// Disabled when running headless since the bots don't have the required config.
// TODO(henrika): improve quality by using a wideband codec, enabling noise-
// suppressions etc.
TEST_F(WebRTCAudioDeviceTest, FullDuplexAudioWithAGC) {
// FullDuplexAudioWithAGC is flaky on Android, disable it for now.
#if defined(OS_ANDROID)
#define MAYBE_FullDuplexAudioWithAGC DISABLED_FullDuplexAudioWithAGC
#else
#define MAYBE_FullDuplexAudioWithAGC FullDuplexAudioWithAGC
#endif
TEST_F(WebRTCAudioDeviceTest, MAYBE_FullDuplexAudioWithAGC) {
if (!has_output_devices_ || !has_input_devices_) {
LOG(WARNING) << "Missing audio devices.";
return;
......@@ -505,11 +519,19 @@ TEST_F(WebRTCAudioDeviceTest, FullDuplexAudioWithAGC) {
ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get());
ASSERT_TRUE(audio_processing.valid());
#if defined(OS_ANDROID)
// On Android, by default AGC is off.
bool enabled = true;
webrtc::AgcModes agc_mode = webrtc::kAgcDefault;
EXPECT_EQ(0, audio_processing->GetAgcStatus(enabled, agc_mode));
EXPECT_FALSE(enabled);
#else
bool enabled = false;
webrtc::AgcModes agc_mode = webrtc::kAgcDefault;
webrtc::AgcModes agc_mode = webrtc::kAgcDefault;
EXPECT_EQ(0, audio_processing->GetAgcStatus(enabled, agc_mode));
EXPECT_TRUE(enabled);
EXPECT_EQ(agc_mode, webrtc::kAgcAdaptiveAnalog);
#endif
int ch = base->CreateChannel();
EXPECT_NE(-1, ch);
......
......@@ -34,7 +34,9 @@ const int kValidOutputRates[] = {96000, 48000, 44100, 32000, 16000};
#elif defined(OS_LINUX) || defined(OS_OPENBSD)
const int kValidOutputRates[] = {48000, 44100};
#elif defined(OS_ANDROID)
// On Android, the most popular sampling rate is 16000.
// TODO(leozwang): We want to use native sampling rate on Android to achieve
// low latency, currently 16000 is used to work around audio problem on some
// Android devices.
const int kValidOutputRates[] = {48000, 44100, 16000};
#else
const int kValidOutputRates[] = {44100};
......
......@@ -8,6 +8,7 @@
#include "media/audio/android/opensles_input.h"
#include "media/audio/android/opensles_output.h"
#include "media/audio/audio_manager.h"
#include "media/audio/audio_util.h"
#include "media/audio/fake_audio_input_stream.h"
namespace media {
......@@ -32,9 +33,36 @@ bool AudioManagerAndroid::HasAudioOutputDevices() {
}
bool AudioManagerAndroid::HasAudioInputDevices() {
return true;
}
bool AudioManagerAndroid::CanShowAudioInputSettings() {
return false;
}
void AudioManagerAndroid::GetAudioInputDeviceNames(
media::AudioDeviceNames* device_names) {
DCHECK(device_names->empty());
device_names->push_front(
media::AudioDeviceName(kDefaultDeviceName, kDefaultDeviceId));
}
AudioParameters
AudioManagerAndroid::GetPreferredLowLatencyOutputStreamParameters(
const AudioParameters& input_params) {
// TODO(leozwang): Android defines the minimal buffer size requirment
// we should follow it. From Android 4.1, a new audio low latency api
// set was introduced and is under development, we want to take advantage
// of it.
int buffer_size = GetAudioHardwareBufferSize();
if (input_params.frames_per_buffer() < buffer_size)
buffer_size = input_params.frames_per_buffer();
return AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(),
input_params.sample_rate(), 16, buffer_size);
}
AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream(
const AudioParameters& params) {
DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
......
......@@ -17,6 +17,9 @@ class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase {
// Implementation of AudioManager.
virtual bool HasAudioOutputDevices() OVERRIDE;
virtual bool HasAudioInputDevices() OVERRIDE;
virtual bool CanShowAudioInputSettings() OVERRIDE;
virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names)
OVERRIDE;
// Implementation of AudioManagerBase.
virtual AudioOutputStream* MakeLinearOutputStream(
......@@ -27,6 +30,8 @@ class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase {
const AudioParameters& params, const std::string& device_id) OVERRIDE;
virtual AudioInputStream* MakeLowLatencyInputStream(
const AudioParameters& params, const std::string& device_id) OVERRIDE;
virtual AudioParameters GetPreferredLowLatencyOutputStreamParameters(
const AudioParameters& input_params) OVERRIDE;
protected:
virtual ~AudioManagerAndroid();
......
......@@ -135,6 +135,7 @@ int GetAudioHardwareSampleRate() {
// Use the default device (same as for Wave) for now to be compatible.
return WASAPIAudioOutputStream::HardwareSampleRate();
#elif defined(OS_ANDROID)
// TODO(leozwang): return native sampling rate on Android.
return 16000;
#else
// Hardware for Linux is nearly always 48KHz.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment