Chromium Code Reviews| Index: media/audio/ios/audio_manager_ios.mm |
| diff --git a/media/audio/ios/audio_manager_ios.mm b/media/audio/ios/audio_manager_ios.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7dda963a15911430b6f885644e588086feed2e08 |
| --- /dev/null |
| +++ b/media/audio/ios/audio_manager_ios.mm |
| @@ -0,0 +1,111 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import <AudioToolbox/AudioToolbox.h> |
| + |
| +#include "base/sys_info.h" |
| +#include "media/audio/fake_audio_input_stream.h" |
| +#include "media/audio/mac/audio_input_mac.h" |
| +#include "media/audio/ios/audio_manager_ios.h" |
|
DaleCurtis
2012/09/07 11:31:12
Should be first header; above everything.
blundell
2012/09/07 12:35:39
Done.
|
| +#include "media/base/limits.h" |
| + |
| +namespace media { |
| + |
| +static const int kMaxInputChannels = 2; |
|
stuartmorgan
2012/09/07 11:09:26
remove static, and put in an anonymous namespace.
DaleCurtis
2012/09/07 11:31:12
Better, just make it an enum { kMaxInputChannels =
blundell
2012/09/07 12:35:39
Done.
blundell
2012/09/07 12:35:39
Done.
|
| + |
| +bool AudioManagerIOS::isAudioSessionInitialized_ = false; |
| + |
| +AudioManagerIOS::AudioManagerIOS() { |
| +} |
| + |
| +AudioManagerIOS::~AudioManagerIOS() { |
| + Shutdown(); |
| +} |
| + |
| +bool AudioManagerIOS::HasAudioOutputDevices() { |
| + return false; |
| +} |
| + |
| +bool AudioManagerIOS::HasAudioInputDevices() { |
| + if (InitAudioSession()) { |
| + UInt32 audioInputIsAvailable = false; |
|
stuartmorgan
2012/09/07 11:09:26
All the local variables need style fixing too.
Al
blundell
2012/09/07 12:35:39
Done. This property is actually a 32-bit integer t
|
| + UInt32 propertySize = sizeof(audioInputIsAvailable); |
| + OSStatus error = |
| + AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, |
| + &propertySize, |
| + &audioInputIsAvailable); |
| + return error == kAudioSessionNoError ? audioInputIsAvailable : false; |
| + } else { |
| + return false; |
|
stuartmorgan
2012/09/07 11:09:26
Change to:
if (!InitAudioSession())
return fals
blundell
2012/09/07 12:35:39
Done.
|
| + } |
| +} |
| + |
| +AudioOutputStream* AudioManagerIOS::MakeAudioOutputStream( |
| + const AudioParameters& params) { |
| + NOTIMPLEMENTED(); // Only input is supported on iOS. |
| + return NULL; |
| +} |
| + |
| +AudioInputStream* AudioManagerIOS::MakeAudioInputStream( |
| + const AudioParameters& params, const std::string& device_id) { |
| + // Current line of iOS devices has only one audio input. |
| + // Ignore the device_id (unittest uses a test value in it). |
| + if (!params.IsValid() || (params.channels() > kMaxInputChannels)) |
| + return NULL; |
| + |
| + if (params.format() == AudioParameters::AUDIO_MOCK) { |
| + return FakeAudioInputStream::MakeFakeStream(this, params); |
| + } else if (params.format() == AudioParameters::AUDIO_PCM_LINEAR) { |
| + return new PCMQueueInAudioInputStream(this, params); |
| + } |
|
stuartmorgan
2012/09/07 11:09:26
Remove the {} for both
blundell
2012/09/07 12:35:39
Done.
|
| + return NULL; |
| +} |
| + |
| +AudioOutputStream* AudioManagerIOS::MakeLinearOutputStream( |
| + const AudioParameters& params) { |
| + NOTIMPLEMENTED(); // Only input is supported on iOS. |
| + return NULL; |
| +} |
| + |
| +AudioOutputStream* AudioManagerIOS::MakeLowLatencyOutputStream( |
| + const AudioParameters& params) { |
| + NOTIMPLEMENTED(); // Only input is supported on iOS. |
| + return NULL; |
| +} |
| + |
| +AudioInputStream* AudioManagerIOS::MakeLinearInputStream( |
| + const AudioParameters& params, const std::string& device_id) { |
| + return MakeAudioInputStream(params, device_id); |
| +} |
| + |
| +AudioInputStream* AudioManagerIOS::MakeLowLatencyInputStream( |
| + const AudioParameters& params, const std::string& device_id) { |
| + NOTIMPLEMENTED(); // Only linear audio input is supported on iOS. |
| + return MakeAudioInputStream(params, device_id); |
| +} |
| + |
| +// Called by the stream when it has been released by calling Close(). |
| +void AudioManagerIOS::ReleaseOutputStream(AudioOutputStream* stream) { |
|
DaleCurtis
2012/09/07 11:31:12
Should this have a NOTREACHED() ?
|
| +} |
| + |
| +// Called by the stream when it has been released by calling Close(). |
| +void AudioManagerIOS::ReleaseInputStream(AudioInputStream* stream) { |
| + delete stream; |
| +} |
| + |
| +bool AudioManagerIOS::InitAudioSession() { |
| + if (!isAudioSessionInitialized_) { |
|
DaleCurtis
2012/09/07 11:31:12
Do you expect to retry this call if it fails? Othe
blundell
2012/09/07 12:35:39
Much cleaner, thanks. Done.
On 2012/09/07 11:31:1
|
| + OSStatus error = AudioSessionInitialize(NULL, NULL, NULL, NULL); |
| + isAudioSessionInitialized_ = error == kAudioSessionNoError || |
| + error == kAudioSessionAlreadyInitialized; |
| + } |
| + return isAudioSessionInitialized_; |
| +} |
| + |
| +// static |
| +AudioManager* CreateAudioManager() { |
| + return new AudioManagerIOS(); |
| +} |
| + |
| +} // namespace media |