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

Unified Diff: media/audio/linux/audio_manager_linux.cc

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Made ResourceContext::audio_manager() abide the same rules as other accessors Created 9 years 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/linux/audio_manager_linux.cc
===================================================================
--- media/audio/linux/audio_manager_linux.cc (revision 113173)
+++ media/audio/linux/audio_manager_linux.cc (working copy)
@@ -56,13 +56,14 @@
}
if (!initialized()) {
+ // We should never get here since this method is called on the audio thread.
+ NOTREACHED();
return NULL;
}
// Don't allow opening more than |kMaxOutputStreams| streams.
- if (active_streams_.size() >= kMaxOutputStreams) {
+ if (active_output_stream_count_ >= kMaxOutputStreams)
return NULL;
- }
AudioOutputStream* stream;
#if defined(USE_PULSEAUDIO)
@@ -81,15 +82,16 @@
#if defined(USE_PULSEAUDIO)
}
#endif
- active_streams_.insert(stream);
+ ++active_output_stream_count_;
scherkus (not reviewing) 2011/12/09 22:47:30 we should probably re-think this active stream cou
tommi (sloooow) - chröme 2011/12/10 00:11:14 It's checked against kMaxOutputStreams above. Oth
tommi (sloooow) - chröme 2011/12/10 09:59:57 bug filed: crbug.com/107088
return stream;
}
AudioInputStream* AudioManagerLinux::MakeAudioInputStream(
const AudioParameters& params, const std::string& device_id) {
if (!params.IsValid() || params.channels > kMaxInputChannels ||
- device_id.empty())
+ device_id.empty()) {
return NULL;
+ }
if (params.format == AudioParameters::AUDIO_MOCK) {
return FakeAudioInputStream::MakeFakeStream(params);
@@ -107,29 +109,19 @@
switches::kAlsaInputDevice);
}
- AlsaPcmInputStream* stream = new AlsaPcmInputStream(
+ AlsaPcmInputStream* stream = new AlsaPcmInputStream(this,
device_name, params, wrapper_.get());
return stream;
}
-AudioManagerLinux::AudioManagerLinux() {
+AudioManagerLinux::AudioManagerLinux() : active_output_stream_count_(0U) {
scherkus (not reviewing) 2011/12/09 22:47:30 nit: collapse into {}
tommi (sloooow) - chröme 2011/12/10 00:11:14 Done.
}
AudioManagerLinux::~AudioManagerLinux() {
- // Make sure we stop the thread first. If we allow the default destructor to
- // destroy the members, we may destroy audio streams before stopping the
- // thread, resulting an unexpected behavior.
- // This way we make sure activities of the audio streams are all stopped
- // before we destroy them.
- audio_thread_.Stop();
-
- // Free output dispatchers, closing all remaining open streams.
- output_dispatchers_.clear();
-
- // Delete all the streams. Have to do it manually, we don't have ScopedSet<>,
- // and we are not using ScopedVector<> because search there is slow.
- STLDeleteElements(&active_streams_);
+ Shutdown();
+ // All the streams should have been deleted on the audio thread via Shutdown.
+ CHECK_EQ(active_output_stream_count_, 0U);
}
void AudioManagerLinux::Init() {
@@ -147,8 +139,9 @@
void AudioManagerLinux::ReleaseOutputStream(AudioOutputStream* stream) {
if (stream) {
- active_streams_.erase(stream);
delete stream;
+ --active_output_stream_count_;
+ DCHECK_GE(active_output_stream_count_, 0U);
}
}

Powered by Google App Engine
This is Rietveld 408576698