Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1011)

Side by Side Diff: media/audio/audio_manager_base.h

Issue 9692038: stopping the audio thread before destroying the AudioManager<Platform> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and fixed the speech recognition unittest Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/atomic_ref_count.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 virtual bool IsRecordingInProcess() OVERRIDE; 53 virtual bool IsRecordingInProcess() OVERRIDE;
54 54
55 // Called internally by the audio stream when it has been closed. 55 // Called internally by the audio stream when it has been closed.
56 virtual void ReleaseOutputStream(AudioOutputStream* stream); 56 virtual void ReleaseOutputStream(AudioOutputStream* stream);
57 virtual void ReleaseInputStream(AudioInputStream* stream); 57 virtual void ReleaseInputStream(AudioInputStream* stream);
58 58
59 void IncreaseActiveInputStreamCount(); 59 void IncreaseActiveInputStreamCount();
60 void DecreaseActiveInputStreamCount(); 60 void DecreaseActiveInputStreamCount();
61 61
62 // Shuts down the audio thread and releases all the audio output dispatchers
63 // on the audio thread. All AudioOutputProxy instances should be freed before
64 // Shutdown is called.
65 void Shutdown();
66
67 // Creates the output stream for the |AUDIO_PCM_LINEAR| format. The legacy 62 // Creates the output stream for the |AUDIO_PCM_LINEAR| format. The legacy
68 // name is also from |AUDIO_PCM_LINEAR|. 63 // name is also from |AUDIO_PCM_LINEAR|.
69 virtual AudioOutputStream* MakeLinearOutputStream( 64 virtual AudioOutputStream* MakeLinearOutputStream(
70 const AudioParameters& params) = 0; 65 const AudioParameters& params) = 0;
71 66
72 // Creates the output stream for the |AUDIO_PCM_LOW_LATENCY| format. 67 // Creates the output stream for the |AUDIO_PCM_LOW_LATENCY| format.
73 virtual AudioOutputStream* MakeLowLatencyOutputStream( 68 virtual AudioOutputStream* MakeLowLatencyOutputStream(
74 const AudioParameters& params) = 0; 69 const AudioParameters& params) = 0;
75 70
76 // Creates the input stream for the |AUDIO_PCM_LINEAR| format. The legacy 71 // Creates the input stream for the |AUDIO_PCM_LINEAR| format. The legacy
77 // name is also from |AUDIO_PCM_LINEAR|. 72 // name is also from |AUDIO_PCM_LINEAR|.
78 virtual AudioInputStream* MakeLinearInputStream( 73 virtual AudioInputStream* MakeLinearInputStream(
79 const AudioParameters& params, const std::string& device_id) = 0; 74 const AudioParameters& params, const std::string& device_id) = 0;
80 75
81 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. 76 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format.
82 virtual AudioInputStream* MakeLowLatencyInputStream( 77 virtual AudioInputStream* MakeLowLatencyInputStream(
83 const AudioParameters& params, const std::string& device_id) = 0; 78 const AudioParameters& params, const std::string& device_id) = 0;
84 79
85 protected: 80 protected:
86 AudioManagerBase(); 81 AudioManagerBase();
87 82
88 typedef std::map<AudioParameters, scoped_refptr<AudioOutputDispatcher>, 83 typedef std::map<AudioParameters, scoped_refptr<AudioOutputDispatcher>,
89 AudioParameters::Compare> 84 AudioParameters::Compare>
90 AudioOutputDispatchersMap; 85 AudioOutputDispatchersMap;
91 86
87 // Shuts down the audio thread and releases all the audio output dispatchers
88 // on the audio thread. All audio streams should be freed before
89 // Shutdown is called.
90 // This must be called in the destructor of the AudioManager<Platform>.
91 void Shutdown();
92
92 void ShutdownOnAudioThread(); 93 void ShutdownOnAudioThread();
93 94
94 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } 95 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; }
95 96
96 // Thread used to interact with AudioOutputStreams created by this 97 // Thread used to interact with AudioOutputStreams created by this
97 // audio manger. 98 // audio manger.
98 scoped_ptr<base::Thread> audio_thread_; 99 scoped_ptr<base::Thread> audio_thread_;
99 mutable base::Lock audio_thread_lock_; 100 mutable base::Lock audio_thread_lock_;
100 101
101 // Map of cached AudioOutputDispatcher instances. Must only be touched 102 // Map of cached AudioOutputDispatcher instances. Must only be touched
102 // from the audio thread (no locking). 103 // from the audio thread (no locking).
103 AudioOutputDispatchersMap output_dispatchers_; 104 AudioOutputDispatchersMap output_dispatchers_;
104 105
105 private: 106 private:
106 // Counts the number of active input streams to find out if something else 107 // Counts the number of active input streams to find out if something else
107 // is currently recording in Chrome. 108 // is currently recording in Chrome.
108 base::AtomicRefCount num_active_input_streams_; 109 base::AtomicRefCount num_active_input_streams_;
109 110
110 // Max number of open output streams, modified by 111 // Max number of open output streams, modified by
111 // SetMaxOutputStreamsAllowed(). 112 // SetMaxOutputStreamsAllowed().
112 int max_num_output_streams_; 113 int max_num_output_streams_;
113 114
115 // Max number of open input streams.
116 int max_num_input_streams_;
117
114 // Number of currently open output streams. 118 // Number of currently open output streams.
115 int num_output_streams_; 119 int num_output_streams_;
116 120
121 // Number of currently open input streams.
122 int num_input_streams_;
123
117 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); 124 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase);
118 }; 125 };
119 126
120 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ 127 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698