Home | History | Annotate | Download | only in mac
      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(AudioLogFactory* audio_log_factory);
     26 
     27   // Implementation of AudioManager.
     28   virtual bool HasAudioOutputDevices() OVERRIDE;
     29   virtual bool HasAudioInputDevices() OVERRIDE;
     30   virtual void GetAudioInputDeviceNames(
     31       AudioDeviceNames* device_names) OVERRIDE;
     32   virtual void GetAudioOutputDeviceNames(
     33       AudioDeviceNames* device_names) OVERRIDE;
     34   virtual AudioParameters GetInputStreamParameters(
     35       const std::string& device_id) OVERRIDE;
     36   virtual std::string GetAssociatedOutputDeviceID(
     37       const std::string& input_device_id) OVERRIDE;
     38 
     39   // Implementation of AudioManagerBase.
     40   virtual AudioOutputStream* MakeLinearOutputStream(
     41       const AudioParameters& params) OVERRIDE;
     42   virtual AudioOutputStream* MakeLowLatencyOutputStream(
     43       const AudioParameters& params,
     44       const std::string& device_id,
     45       const std::string& input_device_id) OVERRIDE;
     46   virtual AudioInputStream* MakeLinearInputStream(
     47       const AudioParameters& params, const std::string& device_id) OVERRIDE;
     48   virtual AudioInputStream* MakeLowLatencyInputStream(
     49       const AudioParameters& params, const std::string& device_id) OVERRIDE;
     50   virtual std::string GetDefaultOutputDeviceID() OVERRIDE;
     51 
     52   static bool GetDefaultInputDevice(AudioDeviceID* device);
     53   static bool GetDefaultOutputDevice(AudioDeviceID* device);
     54   static bool GetDefaultDevice(AudioDeviceID* device, bool input);
     55 
     56   static bool GetDefaultOutputChannels(int* channels);
     57 
     58   static bool GetDeviceChannels(AudioDeviceID device,
     59                                 AudioObjectPropertyScope scope,
     60                                 int* channels);
     61 
     62   static int HardwareSampleRateForDevice(AudioDeviceID device_id);
     63   static int HardwareSampleRate();
     64 
     65  protected:
     66   virtual ~AudioManagerMac();
     67 
     68   virtual AudioParameters GetPreferredOutputStreamParameters(
     69       const std::string& output_device_id,
     70       const AudioParameters& input_params) OVERRIDE;
     71 
     72  private:
     73   bool HasUnifiedDefaultIO();
     74 
     75   // Helper methods for constructing AudioDeviceListenerMac on the audio thread.
     76   void CreateDeviceListener();
     77   void DestroyDeviceListener();
     78 
     79   int ChooseBufferSize(int output_sample_rate);
     80 
     81   // Notify streams of a device change if the default output device or its
     82   // sample rate has changed, otherwise does nothing.
     83   void HandleDeviceChanges();
     84 
     85   scoped_ptr<AudioDeviceListenerMac> output_device_listener_;
     86 
     87   // Track the output sample-rate and the default output device
     88   // so we can intelligently handle device notifications only when necessary.
     89   int current_sample_rate_;
     90   AudioDeviceID current_output_device_;
     91 
     92   AggregateDeviceManager aggregate_device_manager_;
     93 
     94   DISALLOW_COPY_AND_ASSIGN(AudioManagerMac);
     95 };
     96 
     97 }  // namespace media
     98 
     99 #endif  // MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_
    100