1 // Copyright (c) 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 #ifndef MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ 6 #define MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ 7 8 #include <CoreAudio/AudioHardware.h> 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "base/compiler_specific.h" 13 #include "base/message_loop/message_loop_proxy.h" 14 #include "media/audio/audio_manager_base.h" 15 #include "media/audio/mac/aggregate_device_manager.h" 16 #include "media/audio/mac/audio_device_listener_mac.h" 17 18 namespace media { 19 20 // Mac OS X implementation of the AudioManager singleton. This class is internal 21 // to the audio output and only internal users can call methods not exposed by 22 // the AudioManager class. 23 class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase { 24 public: 25 AudioManagerMac(); 26 27 // Implementation of AudioManager. 28 virtual bool HasAudioOutputDevices() OVERRIDE; 29 virtual bool HasAudioInputDevices() OVERRIDE; 30 virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names) 31 OVERRIDE; 32 virtual AudioParameters GetInputStreamParameters( 33 const std::string& device_id) OVERRIDE; 34 35 // Implementation of AudioManagerBase. 36 virtual AudioOutputStream* MakeLinearOutputStream( 37 const AudioParameters& params) OVERRIDE; 38 virtual AudioOutputStream* MakeLowLatencyOutputStream( 39 const AudioParameters& params, 40 const std::string& input_device_id) OVERRIDE; 41 virtual AudioInputStream* MakeLinearInputStream( 42 const AudioParameters& params, const std::string& device_id) OVERRIDE; 43 virtual AudioInputStream* MakeLowLatencyInputStream( 44 const AudioParameters& params, const std::string& device_id) OVERRIDE; 45 46 static bool GetDefaultInputDevice(AudioDeviceID* device); 47 static bool GetDefaultOutputDevice(AudioDeviceID* device); 48 static bool GetDefaultDevice(AudioDeviceID* device, bool input); 49 50 static bool GetDefaultOutputChannels(int* channels); 51 52 static bool GetDeviceChannels(AudioDeviceID device, 53 AudioObjectPropertyScope scope, 54 int* channels); 55 56 static int HardwareSampleRateForDevice(AudioDeviceID device_id); 57 static int HardwareSampleRate(); 58 59 // Notify streams of a device change if the default output device or its 60 // sample rate has changed, otherwise does nothing. 61 void HandleDeviceChanges(); 62 63 protected: 64 virtual ~AudioManagerMac(); 65 66 virtual AudioParameters GetPreferredOutputStreamParameters( 67 const AudioParameters& input_params) OVERRIDE; 68 69 private: 70 bool HasUnifiedDefaultIO(); 71 72 // Helper methods for constructing AudioDeviceListenerMac on the audio thread. 73 void CreateDeviceListener(); 74 void DestroyDeviceListener(); 75 76 scoped_ptr<AudioDeviceListenerMac> output_device_listener_; 77 78 // Track the output sample-rate and the default output device 79 // so we can intelligently handle device notifications only when necessary. 80 int current_sample_rate_; 81 AudioDeviceID current_output_device_; 82 83 AggregateDeviceManager aggregate_device_manager_; 84 85 DISALLOW_COPY_AND_ASSIGN(AudioManagerMac); 86 }; 87 88 } // namespace media 89 90 #endif // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ 91