Index: content/renderer/media/webrtc/peer_connection_dependency_factory.cc |
diff --git a/content/renderer/media/webrtc/peer_connection_dependency_factory.cc b/content/renderer/media/webrtc/peer_connection_dependency_factory.cc |
index 966a295fdf8fdd3fa61f66ff58cc7a996eb21dc2..374ff9ce783dc46cdb741ab6a4638d82e945d0a8 100644 |
--- a/content/renderer/media/webrtc/peer_connection_dependency_factory.cc |
+++ b/content/renderer/media/webrtc/peer_connection_dependency_factory.cc |
@@ -9,6 +9,8 @@ |
#include <utility> |
#include <vector> |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
#include "base/command_line.h" |
#include "base/location.h" |
#include "base/logging.h" |
@@ -187,8 +189,8 @@ bool PeerConnectionDependencyFactory::InitializeMediaStreamAudioSource( |
HarmonizeConstraintsAndEffects(&constraints, |
&device_info.device.input.effects); |
- scoped_refptr<WebRtcAudioCapturer> capturer(CreateAudioCapturer( |
- render_frame_id, device_info, audio_constraints, source_data)); |
+ scoped_ptr<WebRtcAudioCapturer> capturer = CreateAudioCapturer( |
+ render_frame_id, device_info, audio_constraints, source_data); |
if (!capturer.get()) { |
const std::string log_string = |
"PCDF::InitializeMediaStreamAudioSource: fails to create capturer"; |
@@ -200,7 +202,7 @@ bool PeerConnectionDependencyFactory::InitializeMediaStreamAudioSource( |
// be called multiple times which is likely also a bug. |
return false; |
} |
- source_data->SetAudioCapturer(capturer.get()); |
+ source_data->SetAudioCapturer(std::move(capturer)); |
// Creates a LocalAudioSource object which holds audio options. |
// TODO(xians): The option should apply to the track instead of the source. |
@@ -537,20 +539,17 @@ void PeerConnectionDependencyFactory::CreateLocalAudioTrack( |
const blink::WebMediaStreamTrack& track) { |
blink::WebMediaStreamSource source = track.source(); |
DCHECK_EQ(source.type(), blink::WebMediaStreamSource::TypeAudio); |
- DCHECK(!source.remote()); |
- MediaStreamAudioSource* source_data = |
- static_cast<MediaStreamAudioSource*>(source.extraData()); |
+ MediaStreamAudioSource* source_data = MediaStreamAudioSource::From(source); |
- scoped_refptr<WebAudioCapturerSource> webaudio_source; |
+ scoped_ptr<WebAudioCapturerSource> webaudio_source; |
if (!source_data) { |
if (source.requiresAudioConsumer()) { |
// We're adding a WebAudio MediaStream. |
// Create a specific capturer for each WebAudio consumer. |
webaudio_source = CreateWebAudioSource(&source); |
- source_data = |
- static_cast<MediaStreamAudioSource*>(source.extraData()); |
+ source_data = MediaStreamAudioSource::From(source); |
} else { |
- NOTREACHED() << "Local track missing source extra data."; |
+ NOTREACHED() << "Local track missing MediaStreamAudioSource instance."; |
return; |
} |
} |
@@ -565,10 +564,25 @@ void PeerConnectionDependencyFactory::CreateLocalAudioTrack( |
// TODO(xians): Merge |source| to the capturer(). We can't do this today |
// because only one capturer() is supported while one |source| is created |
// for each audio track. |
- scoped_ptr<WebRtcLocalAudioTrack> audio_track(new WebRtcLocalAudioTrack( |
- adapter.get(), source_data->GetAudioCapturer(), webaudio_source.get())); |
- |
- StartLocalAudioTrack(audio_track.get()); |
+ scoped_ptr<WebRtcLocalAudioTrack> audio_track( |
+ new WebRtcLocalAudioTrack(adapter.get())); |
+ |
+ // Start the source and connect the audio data flow to the track. |
+ if (webaudio_source.get()) { |
+ webaudio_source->Start(audio_track.get()); |
+ // The stop callback takes ownership of the |webaudio_source|, which will |
+ // cause it to be auto-destroyed when the track is stopped. |
+ // |
+ // TODO(miu): In a future change, WebAudioCapturerSource will become a |
+ // subclass of MediaStreamAudioSource, and this will allow it to be owned by |
+ // the blink::WebMediaStreamSource so we don't need this hacky thing here. |
+ audio_track->AddStopObserver(base::Bind( |
+ &WebAudioCapturerSource::Stop, base::Owned(webaudio_source.release()))); |
+ } else if (WebRtcAudioCapturer* capturer = source_data->audio_capturer()) { |
+ capturer->AddTrack(audio_track.get()); |
+ } else { |
+ NOTREACHED(); |
+ } |
// Pass the ownership of the native local audio track to the blink track. |
blink::WebMediaStreamTrack writable_track = track; |
@@ -580,48 +594,26 @@ void PeerConnectionDependencyFactory::CreateRemoteAudioTrack( |
blink::WebMediaStreamSource source = track.source(); |
DCHECK_EQ(source.type(), blink::WebMediaStreamSource::TypeAudio); |
DCHECK(source.remote()); |
- DCHECK(source.extraData()); |
+ DCHECK(MediaStreamAudioSource::From(source)); |
blink::WebMediaStreamTrack writable_track = track; |
writable_track.setExtraData( |
new MediaStreamRemoteAudioTrack(source, track.isEnabled())); |
} |
-void PeerConnectionDependencyFactory::StartLocalAudioTrack( |
- WebRtcLocalAudioTrack* audio_track) { |
- // Start the audio track. This will hook the |audio_track| to the capturer |
- // as the sink of the audio, and only start the source of the capturer if |
- // it is the first audio track connecting to the capturer. |
- audio_track->Start(); |
-} |
- |
-scoped_refptr<WebAudioCapturerSource> |
+scoped_ptr<WebAudioCapturerSource> |
PeerConnectionDependencyFactory::CreateWebAudioSource( |
blink::WebMediaStreamSource* source) { |
DVLOG(1) << "PeerConnectionDependencyFactory::CreateWebAudioSource()"; |
- scoped_refptr<WebAudioCapturerSource> |
- webaudio_capturer_source(new WebAudioCapturerSource(*source)); |
MediaStreamAudioSource* source_data = new MediaStreamAudioSource(); |
- // Use the current default capturer for the WebAudio track so that the |
- // WebAudio track can pass a valid delay value and |need_audio_processing| |
- // flag to PeerConnection. |
- // TODO(xians): Remove this after moving APM to Chrome. |
- if (GetWebRtcAudioDevice()) { |
- source_data->SetAudioCapturer( |
- GetWebRtcAudioDevice()->GetDefaultCapturer()); |
- } |
- |
// Create a LocalAudioSource object which holds audio options. |
// SetLocalAudioSource() affects core audio parts in third_party/Libjingle. |
source_data->SetLocalAudioSource(CreateLocalAudioSource(NULL).get()); |
source->setExtraData(source_data); |
- // Replace the default source with WebAudio as source instead. |
- source->addAudioConsumer(webaudio_capturer_source.get()); |
- |
- return webaudio_capturer_source; |
+ return make_scoped_ptr(new WebAudioCapturerSource(source)); |
} |
scoped_refptr<webrtc::VideoTrackInterface> |
@@ -762,7 +754,7 @@ void PeerConnectionDependencyFactory::CleanupPeerConnectionFactory() { |
} |
} |
-scoped_refptr<WebRtcAudioCapturer> |
+scoped_ptr<WebRtcAudioCapturer> |
PeerConnectionDependencyFactory::CreateAudioCapturer( |
int render_frame_id, |
const StreamDeviceInfo& device_info, |