| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/audio/ios/audio_manager_ios.h" |
| 6 |
| 7 #import <AudioToolbox/AudioToolbox.h> |
| 8 |
| 9 #include "base/sys_info.h" |
| 10 #include "media/audio/fake_audio_input_stream.h" |
| 11 #include "media/audio/mac/audio_input_mac.h" |
| 12 #include "media/base/limits.h" |
| 13 |
| 14 namespace media { |
| 15 |
| 16 enum { kMaxInputChannels = 2 }; |
| 17 |
| 18 // Initializes the audio session, returning a bool indicating whether |
| 19 // initialization was successful. Should only be called once. |
| 20 static bool InitAudioSessionInternal() { |
| 21 OSStatus error = AudioSessionInitialize(NULL, NULL, NULL, NULL); |
| 22 DCHECK(error != kAudioSessionAlreadyInitialized); |
| 23 return error == kAudioSessionNoError; |
| 24 } |
| 25 |
| 26 AudioManagerIOS::AudioManagerIOS() { |
| 27 } |
| 28 |
| 29 AudioManagerIOS::~AudioManagerIOS() { |
| 30 Shutdown(); |
| 31 } |
| 32 |
| 33 bool AudioManagerIOS::HasAudioOutputDevices() { |
| 34 return false; |
| 35 } |
| 36 |
| 37 bool AudioManagerIOS::HasAudioInputDevices() { |
| 38 if (!InitAudioSession()) |
| 39 return false; |
| 40 // Note that the |kAudioSessionProperty_AudioInputAvailable| property is a |
| 41 // 32-bit integer, not a boolean. |
| 42 UInt32 property_size; |
| 43 OSStatus error = |
| 44 AudioSessionGetPropertySize(kAudioSessionProperty_AudioInputAvailable, |
| 45 &property_size); |
| 46 if (error != kAudioSessionNoError) |
| 47 return false; |
| 48 UInt32 audio_input_is_available = false; |
| 49 DCHECK(property_size == sizeof(audio_input_is_available)); |
| 50 error = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, |
| 51 &property_size, |
| 52 &audio_input_is_available); |
| 53 return error == kAudioSessionNoError ? audio_input_is_available : false; |
| 54 } |
| 55 |
| 56 AudioOutputStream* AudioManagerIOS::MakeAudioOutputStream( |
| 57 const AudioParameters& params) { |
| 58 NOTIMPLEMENTED(); // Only input is supported on iOS. |
| 59 return NULL; |
| 60 } |
| 61 |
| 62 AudioInputStream* AudioManagerIOS::MakeAudioInputStream( |
| 63 const AudioParameters& params, const std::string& device_id) { |
| 64 // Current line of iOS devices has only one audio input. |
| 65 // Ignore the device_id (unittest uses a test value in it). |
| 66 if (!params.IsValid() || (params.channels() > kMaxInputChannels)) |
| 67 return NULL; |
| 68 |
| 69 if (params.format() == AudioParameters::AUDIO_MOCK) |
| 70 return FakeAudioInputStream::MakeFakeStream(this, params); |
| 71 else if (params.format() == AudioParameters::AUDIO_PCM_LINEAR) |
| 72 return new PCMQueueInAudioInputStream(this, params); |
| 73 return NULL; |
| 74 } |
| 75 |
| 76 AudioOutputStream* AudioManagerIOS::MakeLinearOutputStream( |
| 77 const AudioParameters& params) { |
| 78 NOTIMPLEMENTED(); // Only input is supported on iOS. |
| 79 return NULL; |
| 80 } |
| 81 |
| 82 AudioOutputStream* AudioManagerIOS::MakeLowLatencyOutputStream( |
| 83 const AudioParameters& params) { |
| 84 NOTIMPLEMENTED(); // Only input is supported on iOS. |
| 85 return NULL; |
| 86 } |
| 87 |
| 88 AudioInputStream* AudioManagerIOS::MakeLinearInputStream( |
| 89 const AudioParameters& params, const std::string& device_id) { |
| 90 return MakeAudioInputStream(params, device_id); |
| 91 } |
| 92 |
| 93 AudioInputStream* AudioManagerIOS::MakeLowLatencyInputStream( |
| 94 const AudioParameters& params, const std::string& device_id) { |
| 95 NOTIMPLEMENTED(); // Only linear audio input is supported on iOS. |
| 96 return MakeAudioInputStream(params, device_id); |
| 97 } |
| 98 |
| 99 // Called by the stream when it has been released by calling Close(). |
| 100 void AudioManagerIOS::ReleaseOutputStream(AudioOutputStream* stream) { |
| 101 NOTIMPLEMENTED(); // Only input is supported on iOS. |
| 102 } |
| 103 |
| 104 // Called by the stream when it has been released by calling Close(). |
| 105 void AudioManagerIOS::ReleaseInputStream(AudioInputStream* stream) { |
| 106 delete stream; |
| 107 } |
| 108 |
| 109 bool AudioManagerIOS::InitAudioSession() { |
| 110 static const bool kSessionInitialized = InitAudioSessionInternal(); |
| 111 return kSessionInitialized; |
| 112 } |
| 113 |
| 114 // static |
| 115 AudioManager* CreateAudioManager() { |
| 116 return new AudioManagerIOS(); |
| 117 } |
| 118 |
| 119 } // namespace media |
| OLD | NEW |