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..f7304294afc7794ad3afd5848cf8a97b8347e80a |
| --- /dev/null |
| +++ b/media/audio/ios/audio_manager_ios.mm |
| @@ -0,0 +1,121 @@ |
| +// 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. |
| + |
| +#include "media/audio/ios/audio_manager_ios.h" |
| + |
| +#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/base/limits.h" |
| + |
| +namespace media { |
| + |
| +enum { |
|
DaleCurtis
2012/09/07 12:55:58
nit: We generally place this all on one line for a
blundell
2012/09/07 13:03:21
Done.
|
| + kMaxInputChannels = 2, |
| +}; |
| + |
| +AudioManagerIOS::AudioManagerIOS() { |
| +} |
| + |
| +AudioManagerIOS::~AudioManagerIOS() { |
| + Shutdown(); |
| +} |
| + |
| +bool AudioManagerIOS::HasAudioOutputDevices() { |
| + return false; |
| +} |
| + |
| +bool AudioManagerIOS::HasAudioInputDevices() { |
| + if (!InitAudioSession()) |
| + return false; |
| + // Note that the |kAudioSessionProperty_AudioInputAvailable| property is a |
| + // 32-bit integer, not a boolean (http://developer.apple.com/library/ios/#documentation/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html). |
|
stuartmorgan
2012/09/07 12:47:34
Remove this link; Apple's docs are notorious for c
blundell
2012/09/07 12:53:06
Done.
|
| + UInt32 property_size; |
| + OSStatus error = |
| + AudioSessionGetPropertySize(kAudioSessionProperty_AudioInputAvailable, |
| + &property_size); |
| + if (error != kAudioSessionNoError) |
| + return false; |
| + UInt32 audio_input_is_available = false; |
| + DCHECK(property_size == sizeof(audio_input_is_available)); |
| + error = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, |
| + &property_size, |
| + &audio_input_is_available); |
| + return error == kAudioSessionNoError ? audio_input_is_available : false; |
| +} |
| + |
| +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); |
| + 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) { |
| + NOTIMPLEMENTED(); // Only input is supported on iOS. |
| +} |
| + |
| +// Called by the stream when it has been released by calling Close(). |
| +void AudioManagerIOS::ReleaseInputStream(AudioInputStream* stream) { |
| + delete stream; |
| +} |
| + |
| +// Initializes the audio session, returning a bool indicating whether |
| +// initialization was successful. Should only be called once. |
| +static bool InitAudioSessionInternal() { |
|
DaleCurtis
2012/09/07 12:55:58
nit: static functions at the top of the file.
blundell
2012/09/07 13:03:21
Done.
|
| + OSStatus error = AudioSessionInitialize(NULL, NULL, NULL, NULL); |
| + DCHECK(error != kAudioSessionAlreadyInitialized); |
| + return error == kAudioSessionNoError; |
| +} |
| + |
| +bool AudioManagerIOS::InitAudioSession() { |
| + static const bool kSessionInitialized = InitAudioSessionInternal(); |
| + return kSessionInitialized; |
| +} |
| + |
| +// static |
| +AudioManager* CreateAudioManager() { |
| + return new AudioManagerIOS(); |
| +} |
| + |
| +} // namespace media |