diff options
author | henrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 14:05:09 +0000 |
---|---|---|
committer | henrika@chromium.org <henrika@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 14:05:09 +0000 |
commit | 71de10ee5b06eacf9ee72db449c15967878054b6 (patch) | |
tree | 9ebb1aee52769145eae83ec560ecedda1d62a015 /media/audio | |
parent | 45a23bb1659a609ebbd91c860f431de07090504e (diff) | |
download | chromium_src-71de10ee5b06eacf9ee72db449c15967878054b6.zip chromium_src-71de10ee5b06eacf9ee72db449c15967878054b6.tar.gz chromium_src-71de10ee5b06eacf9ee72db449c15967878054b6.tar.bz2 |
Revert 240885 "Revert 240883 "Refactor audio manager for Android..."
> Revert 240883 "Refactor audio manager for Android to avoid heavy..."
>
> > Refactor audio manager for Android to avoid heavy tasks at startup.
> >
> > Main goal of this CL is to avoid all demanding tasks (e.g. initiate audio routing, detect BT devices etc.) at Chrome startup.
> >
> > All we do now is to populate the list of available devices. BT support has been removed but will be added in an upcoming CL. Detection will not require BLUETOOTH permission.
> >
> > BUG=324464
> > TEST=media_unittests --gtest-filter=AudioAndroid*
> > R=bulach@chromium.org, tommi@chromium.org
> >
> > Review URL: https://codereview.chromium.org/110173003
>
> TBR=henrika@chromium.org
>
> Review URL: https://codereview.chromium.org/105893005
TBR=henrika@chromium.org
Review URL: https://codereview.chromium.org/102613007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240887 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r-- | media/audio/android/audio_android_unittest.cc | 53 | ||||
-rw-r--r-- | media/audio/android/audio_manager_android.cc | 56 | ||||
-rw-r--r-- | media/audio/android/audio_manager_android.h | 5 |
3 files changed, 96 insertions, 18 deletions
diff --git a/media/audio/android/audio_android_unittest.cc b/media/audio/android/audio_android_unittest.cc index e791326..8f453c6 100644 --- a/media/audio/android/audio_android_unittest.cc +++ b/media/audio/android/audio_android_unittest.cc @@ -85,6 +85,41 @@ static double ExpectedTimeBetweenCallbacks(AudioParameters params) { static_cast<double>(params.sample_rate()))).InMillisecondsF(); } +// Helper method which verifies that the device list starts with a valid +// default device name followed by non-default device names. +static void CheckDeviceNames(const AudioDeviceNames& device_names) { + VLOG(2) << "Got " << device_names.size() << " audio devices."; + if (device_names.empty()) { + // Log a warning so we can see the status on the build bots. No need to + // break the test though since this does successfully test the code and + // some failure cases. + LOG(WARNING) << "No input devices detected"; + return; + } + + AudioDeviceNames::const_iterator it = device_names.begin(); + + // The first device in the list should always be the default device. + EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), + it->device_name); + EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); + ++it; + + // Other devices should have non-empty name and id and should not contain + // default name or id. + while (it != device_names.end()) { + EXPECT_FALSE(it->device_name.empty()); + EXPECT_FALSE(it->unique_id.empty()); + VLOG(2) << "Device ID(" << it->unique_id + << "), label: " << it->device_name; + EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceName), + it->device_name); + EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), + it->unique_id); + ++it; + } +} + std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { using namespace std; os << endl << "format: " << FormatToString(params.format()) << endl @@ -567,6 +602,24 @@ TEST_F(AudioAndroidOutputTest, IsAudioLowLatencySupported) { : VLOG(0) << "Low latency output is *not* supported"; } +// Verify input device enumeration. +TEST_F(AudioAndroidInputTest, GetAudioInputDeviceNames) { + if (!audio_manager()->HasAudioInputDevices()) + return; + AudioDeviceNames devices; + audio_manager()->GetAudioInputDeviceNames(&devices); + CheckDeviceNames(devices); +} + +// Verify output device enumeration. +TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) { + if (!audio_manager()->HasAudioOutputDevices()) + return; + AudioDeviceNames devices; + audio_manager()->GetAudioOutputDeviceNames(&devices); + CheckDeviceNames(devices); +} + // Ensure that a default input stream can be created and closed. TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { AudioParameters params = GetInputStreamParameters(); diff --git a/media/audio/android/audio_manager_android.cc b/media/audio/android/audio_manager_android.cc index 3464d89..e67700c 100644 --- a/media/audio/android/audio_manager_android.cc +++ b/media/audio/android/audio_manager_android.cc @@ -37,9 +37,6 @@ static void AddDefaultDevice(AudioDeviceNames* device_names) { // Maximum number of output streams that can be open simultaneously. static const int kMaxOutputStreams = 10; -static const int kAudioModeNormal = 0x00000000; -static const int kAudioModeInCommunication = 0x00000003; - static const int kDefaultInputBufferSize = 1024; static const int kDefaultOutputBufferSize = 2048; @@ -126,12 +123,17 @@ AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( const AudioParameters& params, const std::string& device_id, const std::string& input_device_id) { + bool had_no_streams = HadNoAudioStreams(); AudioOutputStream* stream = AudioManagerBase::MakeAudioOutputStream(params, std::string(), std::string()); - if (stream && output_stream_count() == 1) { - SetAudioMode(kAudioModeInCommunication); - } + + // The audio manager for Android creates streams intended for real-time + // VoIP sessions and therefore sets the audio mode to MODE_IN_COMMUNICATION. + // If a Bluetooth headset is used, the audio stream will use the SCO + // channel and therefore have a limited bandwidth (8-16kHz). + if (stream && had_no_streams) + SetCommunicationAudioModeOn(true); { base::AutoLock lock(streams_lock_); @@ -143,22 +145,37 @@ AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( const AudioParameters& params, const std::string& device_id) { + bool had_no_streams = HadNoAudioStreams(); AudioInputStream* stream = AudioManagerBase::MakeAudioInputStream(params, device_id); + + // The audio manager for Android creates streams intended for real-time + // VoIP sessions and therefore sets the audio mode to MODE_IN_COMMUNICATION. + // If a Bluetooth headset is used, the audio stream will use the SCO + // channel and therefore have a limited bandwidth (8kHz). + if (stream && had_no_streams) + SetCommunicationAudioModeOn(true); return stream; } void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) { AudioManagerBase::ReleaseOutputStream(stream); - if (!output_stream_count()) { - SetAudioMode(kAudioModeNormal); - } + + // Restore the audio mode which was used before the first communication- + // mode stream was created. + if (HadNoAudioStreams()) + SetCommunicationAudioModeOn(false); base::AutoLock lock(streams_lock_); streams_.erase(static_cast<OpenSLESOutputStream*>(stream)); } void AudioManagerAndroid::ReleaseInputStream(AudioInputStream* stream) { AudioManagerBase::ReleaseInputStream(stream); + + // Restore the audio mode which was used before the first communication- + // mode stream was created. + if (HadNoAudioStreams()) + SetCommunicationAudioModeOn(false); } AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream( @@ -189,11 +206,14 @@ AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( const AudioParameters& params, const std::string& device_id) { DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); DLOG_IF(ERROR, device_id.empty()) << "Invalid device ID!"; - // Utilize the device ID to select the correct input device. + // Use the device ID to select the correct input device. // Note that the input device is always associated with a certain output // device, i.e., this selection does also switch the output device. // All input and output streams will be affected by the device selection. - SetAudioDevice(device_id); + if (!SetAudioDevice(device_id)) { + LOG(ERROR) << "Unable to select audio device!"; + return NULL; + } if (params.effects() != AudioParameters::NO_EFFECTS) { // Platform effects can only be enabled through the AudioRecord path. @@ -252,6 +272,10 @@ AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters( sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); } +bool AudioManagerAndroid::HadNoAudioStreams() { + return output_stream_count() == 0 && input_stream_count() == 0; +} + // static bool AudioManagerAndroid::RegisterAudioManager(JNIEnv* env) { return RegisterNativesImpl(env); @@ -286,13 +310,13 @@ void AudioManagerAndroid::DoSetMuteOnAudioThread(bool muted) { } } -void AudioManagerAndroid::SetAudioMode(int mode) { - Java_AudioManagerAndroid_setMode( +void AudioManagerAndroid::SetCommunicationAudioModeOn(bool on) { + Java_AudioManagerAndroid_setCommunicationAudioModeOn( base::android::AttachCurrentThread(), - j_audio_manager_.obj(), mode); + j_audio_manager_.obj(), on); } -void AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { +bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { JNIEnv* env = AttachCurrentThread(); // Send the unique device ID to the Java audio manager and make the @@ -302,7 +326,7 @@ void AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { env, device_id == AudioManagerBase::kDefaultDeviceId ? std::string() : device_id); - Java_AudioManagerAndroid_setDevice( + return Java_AudioManagerAndroid_setDevice( env, j_audio_manager_.obj(), j_device_id.obj()); } diff --git a/media/audio/android/audio_manager_android.h b/media/audio/android/audio_manager_android.h index 2900c0f..670c094 100644 --- a/media/audio/android/audio_manager_android.h +++ b/media/audio/android/audio_manager_android.h @@ -67,10 +67,11 @@ class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase { const AudioParameters& input_params) OVERRIDE; private: + bool HadNoAudioStreams(); void Init(); void Close(); - void SetAudioMode(int mode); - void SetAudioDevice(const std::string& device_id); + void SetCommunicationAudioModeOn(bool on); + bool SetAudioDevice(const std::string& device_id); int GetNativeOutputSampleRate(); bool IsAudioLowLatencySupported(); int GetAudioLowLatencyOutputFrameSize(); |