Chromium Code Reviews| Index: media/audio/audio_manager_base.cc |
| diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc |
| index 41c226d8e543b7aa469815f7edd103e839f7c9ee..6c7a70b7153c0532e01d3c8055c01373f6d799e1 100644 |
| --- a/media/audio/audio_manager_base.cc |
| +++ b/media/audio/audio_manager_base.cc |
| @@ -5,6 +5,7 @@ |
| #include "media/audio/audio_manager_base.h" |
| #include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| #include "base/command_line.h" |
| #include "base/message_loop_proxy.h" |
| #include "base/threading/thread.h" |
| @@ -122,8 +123,16 @@ AudioOutputStream* AudioManagerBase::MakeAudioOutputStream( |
| NOTIMPLEMENTED(); |
| return NULL; |
| #else |
| - stream = VirtualAudioOutputStream::MakeStream(this, params, message_loop_, |
| - virtual_audio_input_stream_); |
| + struct Adapter { |
|
DaleCurtis
2013/01/17 01:15:52
Why is this necessary? What was wrong with your or
miu
2013/01/17 05:33:55
Two things going on here:
1. Bind() needs to retu
DaleCurtis
2013/01/17 21:11:11
I still don't follow why the VirtualAudioOutputStr
miu
2013/01/17 22:44:11
Because VAOS is not always created/owned by AudioM
|
| + static void ReleaseVirtualOutputStream(AudioManagerBase* audio_manager, |
| + VirtualAudioOutputStream* stream) { |
| + audio_manager->ReleaseOutputStream(stream); |
| + } |
| + }; |
| + stream = new VirtualAudioOutputStream( |
| + params, message_loop_, virtual_audio_input_stream_, |
| + base::Bind(&Adapter::ReleaseVirtualOutputStream, |
| + base::Unretained(this))); |
| #endif |
| } else if (audio_output_disabled) { |
| stream = FakeAudioOutputStream::MakeFakeStream(this, params); |
| @@ -168,8 +177,10 @@ AudioInputStream* AudioManagerBase::MakeAudioInputStream( |
| // TODO(justinlin): Currently, audio mirroring will only work for the first |
| // request. Subsequent requests will not get audio. |
| if (!virtual_audio_input_stream_) { |
| - virtual_audio_input_stream_ = |
| - VirtualAudioInputStream::MakeStream(this, params, message_loop_); |
| + virtual_audio_input_stream_ = new VirtualAudioInputStream( |
| + params, message_loop_, |
| + base::Bind(&AudioManagerBase::ReleaseVirtualInputStream, |
| + base::Unretained(this))); |
| stream = virtual_audio_input_stream_; |
| DVLOG(1) << "Virtual audio input stream created."; |
| @@ -288,26 +299,31 @@ void AudioManagerBase::ReleaseOutputStream(AudioOutputStream* stream) { |
| // TODO(xians) : Have a clearer destruction path for the AudioOutputStream. |
| // For example, pass the ownership to AudioManager so it can delete the |
| // streams. |
| - num_output_streams_--; |
| + --num_output_streams_; |
| delete stream; |
| } |
| void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { |
| DCHECK(stream); |
| // TODO(xians) : Have a clearer destruction path for the AudioInputStream. |
| + --num_input_streams_; |
| + delete stream; |
| +} |
| - if (virtual_audio_input_stream_ == stream) { |
| - DVLOG(1) << "Virtual audio input stream stopping."; |
| - virtual_audio_input_stream_->Stop(); |
| - virtual_audio_input_stream_ = NULL; |
| +void AudioManagerBase::ReleaseVirtualInputStream( |
| + VirtualAudioInputStream* stream) { |
| + DCHECK_EQ(virtual_audio_input_stream_, stream); |
| - // Make all VirtualAudioOutputStreams unregister from the |
| - // VirtualAudioInputStream and recreate themselves as regular audio streams |
| - // to return sound to hardware. |
| - NotifyAllOutputDeviceChangeListeners(); |
| - } |
| + virtual_audio_input_stream_ = NULL; |
| + |
| + // Notify listeners to re-create output streams. This will cause all |
| + // outstanding VirtualAudioOutputStreams pointing at the |
| + // VirtualAudioInputStream to be closed and destroyed. Once this has |
| + // happened, there will be no other references to the input stream, and it |
| + // will then be safe to delete it. |
| + NotifyAllOutputDeviceChangeListeners(); |
| - num_input_streams_--; |
| + --num_input_streams_; |
|
DaleCurtis
2013/01/17 01:15:52
Funnel to ReleaseInputStream() ?
miu
2013/01/17 05:33:55
Done. Good idea.
|
| delete stream; |
| } |