Chromium Code Reviews| 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 #import <AudioToolbox/AudioToolbox.h> | |
| 6 | |
| 7 #include "base/sys_info.h" | |
| 8 #include "media/audio/fake_audio_input_stream.h" | |
| 9 #include "media/audio/mac/audio_input_mac.h" | |
| 10 #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.
| |
| 11 #include "media/base/limits.h" | |
| 12 | |
| 13 namespace media { | |
| 14 | |
| 15 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.
| |
| 16 | |
| 17 bool AudioManagerIOS::isAudioSessionInitialized_ = false; | |
| 18 | |
| 19 AudioManagerIOS::AudioManagerIOS() { | |
| 20 } | |
| 21 | |
| 22 AudioManagerIOS::~AudioManagerIOS() { | |
| 23 Shutdown(); | |
| 24 } | |
| 25 | |
| 26 bool AudioManagerIOS::HasAudioOutputDevices() { | |
| 27 return false; | |
| 28 } | |
| 29 | |
| 30 bool AudioManagerIOS::HasAudioInputDevices() { | |
| 31 if (InitAudioSession()) { | |
| 32 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
| |
| 33 UInt32 propertySize = sizeof(audioInputIsAvailable); | |
| 34 OSStatus error = | |
| 35 AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, | |
| 36 &propertySize, | |
| 37 &audioInputIsAvailable); | |
| 38 return error == kAudioSessionNoError ? audioInputIsAvailable : false; | |
| 39 } else { | |
| 40 return false; | |
|
stuartmorgan
2012/09/07 11:09:26
Change to:
if (!InitAudioSession())
return fals
blundell
2012/09/07 12:35:39
Done.
| |
| 41 } | |
| 42 } | |
| 43 | |
| 44 AudioOutputStream* AudioManagerIOS::MakeAudioOutputStream( | |
| 45 const AudioParameters& params) { | |
| 46 NOTIMPLEMENTED(); // Only input is supported on iOS. | |
| 47 return NULL; | |
| 48 } | |
| 49 | |
| 50 AudioInputStream* AudioManagerIOS::MakeAudioInputStream( | |
| 51 const AudioParameters& params, const std::string& device_id) { | |
| 52 // Current line of iOS devices has only one audio input. | |
| 53 // Ignore the device_id (unittest uses a test value in it). | |
| 54 if (!params.IsValid() || (params.channels() > kMaxInputChannels)) | |
| 55 return NULL; | |
| 56 | |
| 57 if (params.format() == AudioParameters::AUDIO_MOCK) { | |
| 58 return FakeAudioInputStream::MakeFakeStream(this, params); | |
| 59 } else if (params.format() == AudioParameters::AUDIO_PCM_LINEAR) { | |
| 60 return new PCMQueueInAudioInputStream(this, params); | |
| 61 } | |
|
stuartmorgan
2012/09/07 11:09:26
Remove the {} for both
blundell
2012/09/07 12:35:39
Done.
| |
| 62 return NULL; | |
| 63 } | |
| 64 | |
| 65 AudioOutputStream* AudioManagerIOS::MakeLinearOutputStream( | |
| 66 const AudioParameters& params) { | |
| 67 NOTIMPLEMENTED(); // Only input is supported on iOS. | |
| 68 return NULL; | |
| 69 } | |
| 70 | |
| 71 AudioOutputStream* AudioManagerIOS::MakeLowLatencyOutputStream( | |
| 72 const AudioParameters& params) { | |
| 73 NOTIMPLEMENTED(); // Only input is supported on iOS. | |
| 74 return NULL; | |
| 75 } | |
| 76 | |
| 77 AudioInputStream* AudioManagerIOS::MakeLinearInputStream( | |
| 78 const AudioParameters& params, const std::string& device_id) { | |
| 79 return MakeAudioInputStream(params, device_id); | |
| 80 } | |
| 81 | |
| 82 AudioInputStream* AudioManagerIOS::MakeLowLatencyInputStream( | |
| 83 const AudioParameters& params, const std::string& device_id) { | |
| 84 NOTIMPLEMENTED(); // Only linear audio input is supported on iOS. | |
| 85 return MakeAudioInputStream(params, device_id); | |
| 86 } | |
| 87 | |
| 88 // Called by the stream when it has been released by calling Close(). | |
| 89 void AudioManagerIOS::ReleaseOutputStream(AudioOutputStream* stream) { | |
|
DaleCurtis
2012/09/07 11:31:12
Should this have a NOTREACHED() ?
| |
| 90 } | |
| 91 | |
| 92 // Called by the stream when it has been released by calling Close(). | |
| 93 void AudioManagerIOS::ReleaseInputStream(AudioInputStream* stream) { | |
| 94 delete stream; | |
| 95 } | |
| 96 | |
| 97 bool AudioManagerIOS::InitAudioSession() { | |
| 98 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
| |
| 99 OSStatus error = AudioSessionInitialize(NULL, NULL, NULL, NULL); | |
| 100 isAudioSessionInitialized_ = error == kAudioSessionNoError || | |
| 101 error == kAudioSessionAlreadyInitialized; | |
| 102 } | |
| 103 return isAudioSessionInitialized_; | |
| 104 } | |
| 105 | |
| 106 // static | |
| 107 AudioManager* CreateAudioManager() { | |
| 108 return new AudioManagerIOS(); | |
| 109 } | |
| 110 | |
| 111 } // namespace media | |
| OLD | NEW |