| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 6 #define MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/atomic_ref_count.h" |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 12 #include "media/audio/audio_manager.h" | 13 #include "media/audio/audio_manager.h" |
| 13 | 14 |
| 14 class AudioOutputDispatcher; | 15 class AudioOutputDispatcher; |
| 15 | 16 |
| 16 // AudioManagerBase provides AudioManager functions common for all platforms. | 17 // AudioManagerBase provides AudioManager functions common for all platforms. |
| 17 class MEDIA_EXPORT AudioManagerBase : public AudioManager { | 18 class MEDIA_EXPORT AudioManagerBase : public AudioManager { |
| 18 public: | 19 public: |
| 19 // Name of the generic "default" device. | 20 // Name of the generic "default" device. |
| 20 static const char kDefaultDeviceName[]; | 21 static const char kDefaultDeviceName[]; |
| 21 // Unique Id of the generic "default" device. | 22 // Unique Id of the generic "default" device. |
| 22 static const char kDefaultDeviceId[]; | 23 static const char kDefaultDeviceId[]; |
| 23 | 24 |
| 24 AudioManagerBase(); | 25 AudioManagerBase(); |
| 25 | 26 |
| 27 #ifndef NDEBUG |
| 28 // Overridden to make sure we don't accidentally get added reference counts on |
| 29 // the audio thread. The AudioManagerBase instance must always be deleted |
| 30 // from outside the audio thread. |
| 31 virtual void AddRef() const OVERRIDE; |
| 32 virtual void Release() const OVERRIDE; |
| 33 #endif |
| 34 |
| 26 virtual void Init() OVERRIDE; | 35 virtual void Init() OVERRIDE; |
| 27 virtual void Cleanup() OVERRIDE; | |
| 28 | 36 |
| 29 virtual MessageLoop* GetMessageLoop() OVERRIDE; | 37 virtual MessageLoop* GetMessageLoop() OVERRIDE; |
| 30 | 38 |
| 31 virtual string16 GetAudioInputDeviceModel() OVERRIDE; | 39 virtual string16 GetAudioInputDeviceModel() OVERRIDE; |
| 32 | 40 |
| 33 virtual bool CanShowAudioInputSettings() OVERRIDE; | 41 virtual bool CanShowAudioInputSettings() OVERRIDE; |
| 34 virtual void ShowAudioInputSettings() OVERRIDE; | 42 virtual void ShowAudioInputSettings() OVERRIDE; |
| 35 | 43 |
| 36 virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names) | 44 virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names) |
| 37 OVERRIDE; | 45 OVERRIDE; |
| 38 | 46 |
| 39 virtual AudioOutputStream* MakeAudioOutputStreamProxy( | 47 virtual AudioOutputStream* MakeAudioOutputStreamProxy( |
| 40 const AudioParameters& params) OVERRIDE; | 48 const AudioParameters& params) OVERRIDE; |
| 41 | 49 |
| 42 virtual bool IsRecordingInProcess() OVERRIDE; | 50 virtual bool IsRecordingInProcess() OVERRIDE; |
| 43 | 51 |
| 44 void IncreaseActiveInputStreamCount(); | 52 void IncreaseActiveInputStreamCount(); |
| 45 void DecreaseActiveInputStreamCount(); | 53 void DecreaseActiveInputStreamCount(); |
| 54 void Shutdown(); |
| 46 | 55 |
| 47 protected: | 56 protected: |
| 48 virtual ~AudioManagerBase(); | 57 virtual ~AudioManagerBase(); |
| 49 | 58 |
| 59 // The map holds a weak reference to the AudioOutputDispatcher objects |
| 60 // to avoid circular dependencies. When the dispatcher dies, it notifies |
| 61 // us via ClearOutputDispatcher. |
| 50 typedef std::map<AudioParameters, scoped_refptr<AudioOutputDispatcher>, | 62 typedef std::map<AudioParameters, scoped_refptr<AudioOutputDispatcher>, |
| 51 AudioParameters::Compare> | 63 AudioParameters::Compare> |
| 52 AudioOutputDispatchersMap; | 64 AudioOutputDispatchersMap; |
| 53 | 65 |
| 54 bool initialized() { return initialized_; } | 66 void ShutdownOnAudioThread(); |
| 67 |
| 68 bool initialized() { return audio_thread_.IsRunning(); } |
| 55 | 69 |
| 56 // Thread used to interact with AudioOutputStreams created by this | 70 // Thread used to interact with AudioOutputStreams created by this |
| 57 // audio manger. | 71 // audio manger. |
| 58 base::Thread audio_thread_; | 72 base::Thread audio_thread_; |
| 59 | 73 |
| 60 bool initialized_; | |
| 61 | |
| 62 AudioOutputDispatchersMap output_dispatchers_; | 74 AudioOutputDispatchersMap output_dispatchers_; |
| 63 | 75 |
| 64 // Counts the number of active input streams to find out if something else | 76 // Counts the number of active input streams to find out if something else |
| 65 // is currently recording in Chrome. | 77 // is currently recording in Chrome. |
| 66 int num_active_input_streams_; | 78 base::AtomicRefCount num_active_input_streams_; |
| 67 | |
| 68 // Lock used to synchronize the access to num_active_input_streams_. | |
| 69 // Do not use for anything else and try to avoid using other locks | |
| 70 // in this code whenever possible. | |
| 71 base::Lock active_input_streams_lock_; | |
| 72 | 79 |
| 73 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); | 80 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 83 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| OLD | NEW |