Chromium Code Reviews| Index: content/renderer/media/webrtc_audio_capturer.cc |
| diff --git a/content/renderer/media/webrtc_audio_capturer.cc b/content/renderer/media/webrtc_audio_capturer.cc |
| index 0f35b4f59f1118bd3fafdafbb9975b4c3160ca6b..6fb21eb2e30f11ae525cc9aecd652a70163d0fb1 100644 |
| --- a/content/renderer/media/webrtc_audio_capturer.cc |
| +++ b/content/renderer/media/webrtc_audio_capturer.cc |
| @@ -164,7 +164,8 @@ bool WebRtcAudioCapturer::Initialize(int render_view_id, |
| } |
| WebRtcAudioCapturer::WebRtcAudioCapturer() |
| - : source_(NULL), |
| + : default_sink_(NULL), |
| + source_(NULL), |
| running_(false), |
| agc_is_enabled_(false), |
| session_id_(0) { |
| @@ -175,14 +176,31 @@ WebRtcAudioCapturer::~WebRtcAudioCapturer() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(tracks_.empty()); |
| DCHECK(!running_); |
| + DCHECK(!default_sink_); |
| DVLOG(1) << "WebRtcAudioCapturer::~WebRtcAudioCapturer()"; |
| } |
| -void WebRtcAudioCapturer::AddSink( |
| - WebRtcAudioCapturerSink* track) { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| +void WebRtcAudioCapturer::SetDefaultSink(WebRtcAudioCapturerSink* sink) { |
| + DVLOG(1) << "WebRtcAudioCapturer::SetDefaultSink()"; |
| + if (sink) { |
| + DCHECK(!default_sink_); |
| + default_sink_ = sink; |
| + AddSink(sink); |
| + } else { |
| + DCHECK(default_sink_); |
| + RemoveSink(default_sink_); |
| + default_sink_ = NULL; |
| + } |
| +} |
| + |
| +void WebRtcAudioCapturer::AddSink(WebRtcAudioCapturerSink* track) { |
| DCHECK(track); |
| DVLOG(1) << "WebRtcAudioCapturer::AddSink()"; |
| + |
| + // Start the source if a real audio track is connected to the capturer. |
|
henrika (OOO until Aug 14)
2013/06/05 09:09:20
Can you please extend the comment and give an exam
no longer working on chromium
2013/06/05 16:29:45
Done.
|
| + if (track != default_sink_) |
| + Start(); |
| + |
| base::AutoLock auto_lock(lock_); |
| // Verify that |track| is not already added to the list. |
|
henrika (OOO until Aug 14)
2013/06/05 09:09:20
What happens if it is (in release mode)?
no longer working on chromium
2013/06/05 16:29:45
It is a push_back, then we will have two reference
|
| DCHECK(std::find_if( |
| @@ -208,19 +226,33 @@ void WebRtcAudioCapturer::RemoveSink( |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DVLOG(1) << "WebRtcAudioCapturer::RemoveSink()"; |
| - base::AutoLock auto_lock(lock_); |
| + bool stop_source = false; |
| + { |
| + base::AutoLock auto_lock(lock_); |
| - // Get iterator to the first element for which WrapsSink(track) returns true. |
| - TrackList::iterator it = std::find_if( |
| - tracks_.begin(), tracks_.end(), |
| - WebRtcAudioCapturerSinkOwner::WrapsSink(track)); |
| - if (it != tracks_.end()) { |
| - // Clear the delegate to ensure that no more capture callbacks will |
| - // be sent to this sink. Also avoids a possible crash which can happen |
| - // if this method is called while capturing is active. |
| - (*it)->Reset(); |
| - tracks_.erase(it); |
| + // Get iterator to the first element for which WrapsSink(track) returns |
| + // true. |
| + TrackList::iterator it = std::find_if( |
| + tracks_.begin(), tracks_.end(), |
| + WebRtcAudioCapturerSinkOwner::WrapsSink(track)); |
| + if (it != tracks_.end()) { |
| + // Clear the delegate to ensure that no more capture callbacks will |
| + // be sent to this sink. Also avoids a possible crash which can happen |
| + // if this method is called while capturing is active. |
| + (*it)->Reset(); |
| + tracks_.erase(it); |
| + } |
| + |
| + if (tracks_.size() == 1 && default_sink_ && |
|
henrika (OOO until Aug 14)
2013/06/05 09:09:20
You must really add clear comments here explaining
no longer working on chromium
2013/06/05 16:29:45
Done.
|
| + (*tracks_.begin())->IsEqual(default_sink_)) { |
| + stop_source = true; |
| + } else { |
| + stop_source = tracks_.empty(); |
| + } |
| } |
| + |
| + if (stop_source) |
| + Stop(); |
| } |
| void WebRtcAudioCapturer::SetCapturerSource( |