Home | History | Annotate | Download | only in win
      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_WIN_AUDIO_MANAGER_WIN_H_
      6 #define MEDIA_AUDIO_WIN_AUDIO_MANAGER_WIN_H_
      7 
      8 #include <string>
      9 
     10 #include "media/audio/audio_manager_base.h"
     11 
     12 namespace media {
     13 
     14 class AudioDeviceListenerWin;
     15 
     16 // Windows implementation of the AudioManager singleton. This class is internal
     17 // to the audio output and only internal users can call methods not exposed by
     18 // the AudioManager class.
     19 class MEDIA_EXPORT AudioManagerWin : public AudioManagerBase {
     20  public:
     21   AudioManagerWin(AudioLogFactory* audio_log_factory);
     22 
     23   // Implementation of AudioManager.
     24   virtual bool HasAudioOutputDevices() OVERRIDE;
     25   virtual bool HasAudioInputDevices() OVERRIDE;
     26   virtual base::string16 GetAudioInputDeviceModel() OVERRIDE;
     27   virtual void ShowAudioInputSettings() OVERRIDE;
     28   virtual void GetAudioInputDeviceNames(
     29       AudioDeviceNames* device_names) OVERRIDE;
     30   virtual void GetAudioOutputDeviceNames(
     31       AudioDeviceNames* device_names) OVERRIDE;
     32   virtual AudioParameters GetInputStreamParameters(
     33       const std::string& device_id) OVERRIDE;
     34   virtual std::string GetAssociatedOutputDeviceID(
     35       const std::string& input_device_id) OVERRIDE;
     36 
     37   // Implementation of AudioManagerBase.
     38   virtual AudioOutputStream* MakeLinearOutputStream(
     39       const AudioParameters& params) OVERRIDE;
     40   virtual AudioOutputStream* MakeLowLatencyOutputStream(
     41       const AudioParameters& params,
     42       const std::string& device_id) OVERRIDE;
     43   virtual AudioInputStream* MakeLinearInputStream(
     44       const AudioParameters& params, const std::string& device_id) OVERRIDE;
     45   virtual AudioInputStream* MakeLowLatencyInputStream(
     46       const AudioParameters& params, const std::string& device_id) OVERRIDE;
     47   virtual std::string GetDefaultOutputDeviceID() OVERRIDE;
     48 
     49  protected:
     50   virtual ~AudioManagerWin();
     51 
     52   virtual AudioParameters GetPreferredOutputStreamParameters(
     53       const std::string& output_device_id,
     54       const AudioParameters& input_params) OVERRIDE;
     55 
     56  private:
     57   enum EnumerationType {
     58     kMMDeviceEnumeration,
     59     kWaveEnumeration,
     60   };
     61 
     62   // Allow unit test to modify the utilized enumeration API.
     63   friend class AudioManagerTest;
     64 
     65   EnumerationType enumeration_type_;
     66   EnumerationType enumeration_type() { return enumeration_type_; }
     67   void SetEnumerationType(EnumerationType type) {
     68     enumeration_type_ = type;
     69   }
     70 
     71   inline bool core_audio_supported() const {
     72     return enumeration_type_ == kMMDeviceEnumeration;
     73   }
     74 
     75   // Returns a PCMWaveInAudioInputStream instance or NULL on failure.
     76   // This method converts MMDevice-style device ID to WaveIn-style device ID if
     77   // necessary.
     78   // (Please see device_enumeration_win.h for more info about the two kinds of
     79   // device IDs.)
     80   AudioInputStream* CreatePCMWaveInAudioInputStream(
     81       const AudioParameters& params,
     82       const std::string& device_id);
     83 
     84   // Helper methods for performing expensive initialization tasks on the audio
     85   // thread instead of on the UI thread which AudioManager is constructed on.
     86   void InitializeOnAudioThread();
     87   void ShutdownOnAudioThread();
     88 
     89   void GetAudioDeviceNamesImpl(bool input, AudioDeviceNames* device_names);
     90 
     91   // Listen for output device changes.
     92   scoped_ptr<AudioDeviceListenerWin> output_device_listener_;
     93 
     94   DISALLOW_COPY_AND_ASSIGN(AudioManagerWin);
     95 };
     96 
     97 }  // namespace media
     98 
     99 #endif  // MEDIA_AUDIO_WIN_AUDIO_MANAGER_WIN_H_
    100