| 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 7318cba1ba5e32b5c89f6aacfc41fa94f2106f9e..6aaa352241236340631419e437b9ff68a69281cd 100644
|
| --- a/content/renderer/media/webrtc_audio_capturer.cc
|
| +++ b/content/renderer/media/webrtc_audio_capturer.cc
|
| @@ -13,6 +13,7 @@
|
| #include "content/renderer/media/audio_device_factory.h"
|
| #include "content/renderer/media/media_stream_audio_processor.h"
|
| #include "content/renderer/media/media_stream_audio_processor_options.h"
|
| +#include "content/renderer/media/media_stream_audio_source.h"
|
| #include "content/renderer/media/webrtc_audio_device_impl.h"
|
| #include "content/renderer/media/webrtc_local_audio_track.h"
|
| #include "content/renderer/media/webrtc_logging.h"
|
| @@ -124,9 +125,10 @@ class WebRtcAudioCapturer::TrackOwner
|
| scoped_refptr<WebRtcAudioCapturer> WebRtcAudioCapturer::CreateCapturer(
|
| int render_view_id, const StreamDeviceInfo& device_info,
|
| const blink::WebMediaConstraints& constraints,
|
| - WebRtcAudioDeviceImpl* audio_device) {
|
| + WebRtcAudioDeviceImpl* audio_device,
|
| + MediaStreamAudioSource* audio_source) {
|
| scoped_refptr<WebRtcAudioCapturer> capturer = new WebRtcAudioCapturer(
|
| - render_view_id, device_info, constraints, audio_device);
|
| + render_view_id, device_info, constraints, audio_device, audio_source);
|
| if (capturer->Initialize())
|
| return capturer;
|
|
|
| @@ -209,7 +211,8 @@ WebRtcAudioCapturer::WebRtcAudioCapturer(
|
| int render_view_id,
|
| const StreamDeviceInfo& device_info,
|
| const blink::WebMediaConstraints& constraints,
|
| - WebRtcAudioDeviceImpl* audio_device)
|
| + WebRtcAudioDeviceImpl* audio_device,
|
| + MediaStreamAudioSource* audio_source)
|
| : constraints_(constraints),
|
| audio_processor_(
|
| new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
|
| @@ -222,15 +225,16 @@ WebRtcAudioCapturer::WebRtcAudioCapturer(
|
| peer_connection_mode_(false),
|
| key_pressed_(false),
|
| need_audio_processing_(false),
|
| - audio_device_(audio_device) {
|
| + audio_device_(audio_device),
|
| + audio_source_(audio_source) {
|
| DVLOG(1) << "WebRtcAudioCapturer::WebRtcAudioCapturer()";
|
| }
|
|
|
| WebRtcAudioCapturer::~WebRtcAudioCapturer() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(tracks_.IsEmpty());
|
| - DCHECK(!running_);
|
| DVLOG(1) << "WebRtcAudioCapturer::~WebRtcAudioCapturer()";
|
| + Stop();
|
| }
|
|
|
| void WebRtcAudioCapturer::AddTrack(WebRtcLocalAudioTrack* track) {
|
| @@ -247,25 +251,34 @@ void WebRtcAudioCapturer::AddTrack(WebRtcLocalAudioTrack* track) {
|
| scoped_refptr<TrackOwner> track_owner(new TrackOwner(track));
|
| tracks_.AddAndTag(track_owner);
|
| }
|
| -
|
| - // Start the source if the first audio track is connected to the capturer.
|
| - // Start() will do nothing if the capturer has already been started.
|
| - Start();
|
| -
|
| }
|
|
|
| void WebRtcAudioCapturer::RemoveTrack(WebRtcLocalAudioTrack* track) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - base::AutoLock auto_lock(lock_);
|
| + DVLOG(1) << "WebRtcAudioCapturer::RemoveTrack()";
|
| + bool stop_source = false;
|
| + {
|
| + base::AutoLock auto_lock(lock_);
|
|
|
| - scoped_refptr<TrackOwner> removed_item =
|
| - tracks_.Remove(TrackOwner::TrackWrapper(track));
|
| + scoped_refptr<TrackOwner> removed_item =
|
| + tracks_.Remove(TrackOwner::TrackWrapper(track));
|
|
|
| - // 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.
|
| - if (removed_item.get())
|
| - removed_item->Reset();
|
| + // 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.
|
| + if (removed_item.get()) {
|
| + removed_item->Reset();
|
| + stop_source = tracks_.IsEmpty();
|
| + }
|
| + }
|
| + if (stop_source) {
|
| + // Since WebRtcAudioCapturer does not inherit MediaStreamAudioSource,
|
| + // and instead MediaStreamAudioSource is composed of a WebRtcAudioCapturer,
|
| + // we have to call StopSource on the MediaStreamSource. This will call
|
| + // MediaStreamAudioSource::DoStopSource which in turn call
|
| + // WebRtcAudioCapturerer::Stop();
|
| + audio_source_->StopSource();
|
| + }
|
| }
|
|
|
| void WebRtcAudioCapturer::SetCapturerSource(
|
| @@ -276,7 +289,6 @@ void WebRtcAudioCapturer::SetCapturerSource(
|
| DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << ","
|
| << "sample_rate=" << sample_rate << ")";
|
| scoped_refptr<media::AudioCapturerSource> old_source;
|
| - bool restart_source = false;
|
| {
|
| base::AutoLock auto_lock(lock_);
|
| if (source_.get() == source.get())
|
| @@ -286,7 +298,6 @@ void WebRtcAudioCapturer::SetCapturerSource(
|
| source_ = source;
|
|
|
| // Reset the flag to allow starting the new source.
|
| - restart_source = running_;
|
| running_ = false;
|
| }
|
|
|
| @@ -319,8 +330,7 @@ void WebRtcAudioCapturer::SetCapturerSource(
|
| if (source.get())
|
| source->Initialize(params, this, session_id());
|
|
|
| - if (restart_source)
|
| - Start();
|
| + Start();
|
| }
|
|
|
| void WebRtcAudioCapturer::EnablePeerConnectionMode() {
|
|
|