Chromium Code Reviews| 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); |
| } |
| } |