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(); |
46 | 54 |
| 55 // Shuts down the audio thread and releases all the audio output dispatchers |
| 56 // on the audio thread. All AudioOutputProxy instances should be freed before |
| 57 // Shutdown is called. |
| 58 void Shutdown(); |
| 59 |
47 protected: | 60 protected: |
48 virtual ~AudioManagerBase(); | 61 virtual ~AudioManagerBase(); |
49 | 62 |
50 typedef std::map<AudioParameters, scoped_refptr<AudioOutputDispatcher>, | 63 typedef std::map<AudioParameters, scoped_refptr<AudioOutputDispatcher>, |
51 AudioParameters::Compare> | 64 AudioParameters::Compare> |
52 AudioOutputDispatchersMap; | 65 AudioOutputDispatchersMap; |
53 | 66 |
54 bool initialized() { return initialized_; } | 67 void ShutdownOnAudioThread(); |
| 68 |
| 69 bool initialized() { return audio_thread_.IsRunning(); } |
55 | 70 |
56 // Thread used to interact with AudioOutputStreams created by this | 71 // Thread used to interact with AudioOutputStreams created by this |
57 // audio manger. | 72 // audio manger. |
58 base::Thread audio_thread_; | 73 base::Thread audio_thread_; |
59 | 74 |
60 bool initialized_; | |
61 | |
62 AudioOutputDispatchersMap output_dispatchers_; | 75 AudioOutputDispatchersMap output_dispatchers_; |
63 | 76 |
64 // Counts the number of active input streams to find out if something else | 77 // Counts the number of active input streams to find out if something else |
65 // is currently recording in Chrome. | 78 // is currently recording in Chrome. |
66 int num_active_input_streams_; | 79 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 | 80 |
73 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); | 81 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); |
74 }; | 82 }; |
75 | 83 |
76 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 84 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
OLD | NEW |