Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2342)

Unified Diff: content/renderer/media/media_stream_dependency_factory.cc

Issue 11369171: Add chromium support for MediaStreamAudioDestinationNode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_dependency_factory.cc
===================================================================
--- content/renderer/media/media_stream_dependency_factory.cc (revision 175011)
+++ content/renderer/media/media_stream_dependency_factory.cc (working copy)
@@ -228,35 +228,82 @@
void MediaStreamDependencyFactory::CreateNativeLocalMediaStream(
WebKit::WebMediaStreamDescriptor* description) {
- DCHECK(PeerConnectionFactoryCreated());
+ if (!EnsurePeerConnectionFactory()) {
+ DVLOG(1) << "EnsurePeerConnectionFactory() failed!";
+ return;
+ }
+ DVLOG(1) << "---MediaStreamDependencyFactory::CreateNativeLocalMediaStream()";
+
std::string label = UTF16ToUTF8(description->label());
scoped_refptr<webrtc::LocalMediaStreamInterface> native_stream =
CreateLocalMediaStream(label);
+ WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer();
+ if (!capturer)
+ DVLOG(1) << "CreateNativeLocalMediaStream: missing WebRtcAudioCapturer.";
+
// Add audio tracks.
WebKit::WebVector<WebKit::WebMediaStreamComponent> audio_components;
description->audioSources(audio_components);
+
for (size_t i = 0; i < audio_components.size(); ++i) {
- const WebKit::WebMediaStreamSource& source = audio_components[i].source();
- MediaStreamSourceExtraData* source_data =
- static_cast<MediaStreamSourceExtraData*>(source.extraData());
- if (!source_data) {
- // TODO(perkj): Implement support for sources from remote MediaStreams.
- NOTIMPLEMENTED();
- continue;
+ WebKit::WebMediaStreamSource source = audio_components[i].source();
+
+ // See if we're adding a WebAudio MediaStream.
+ if (source.requiresAudioConsumer()) {
+ if (!webaudio_capturer_source_.get() && capturer) {
+ DVLOG(1) << "CreateNativeLocalMediaStream: WebAudio MediaStream.";
+ DCHECK(GetWebRtcAudioDevice());
+
+ // TODO(crogers, xians): In reality we should be able to send a unique
+ // audio stream to each PeerConnection separately. But currently WebRTC
+ // is only able to handle a global audio stream sent to ALL peers.
+
+ // TODO(henrika) - why store it here webaudio_capturer_source_?
+
+ webaudio_capturer_source_ = new WebAudioCapturerSource(capturer);
+
+ // For lifetime, we're relying on the fact that
+ // |webaudio_capturer_source_| will live longer than any
+ // MediaStreamSource, since we're never calling removeAudioConsumer().
+ source.addAudioConsumer(webaudio_capturer_source_.get());
+
+ scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track(
+ CreateLocalAudioTrack(label + "a0", NULL));
+ native_stream->AddTrack(audio_track);
+ audio_track->set_enabled(audio_components[i].isEnabled());
+ } else {
+ // TODO(crogers): this is very likely to be less important, but
+ // in theory we should be able to "connect" multiple WebAudio
+ // MediaStreams to a single peer, mixing their results.
+ // Instead we just ignore additional ones after the first.
+ DVLOG(1)
+ << "Multiple MediaStreamAudioDestinationNodes not yet supported!";
+ }
+ } else {
+ MediaStreamSourceExtraData* source_data =
+ static_cast<MediaStreamSourceExtraData*>(source.extraData());
+
+ if (!source_data) {
+ // TODO(perkj): Implement support for sources from
+ // remote MediaStreams.
+ NOTIMPLEMENTED();
+ continue;
+ }
+
+ // TODO(perkj): Refactor the creation of audio tracks to use a proper
+ // interface for receiving audio input data. Currently NULL is passed
+ // since the |audio_device| is the wrong class and is unused.
+ scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track(
+ CreateLocalAudioTrack(UTF16ToUTF8(source.id()), NULL));
+ native_stream->AddTrack(audio_track);
+ audio_track->set_enabled(audio_components[i].isEnabled());
+ // TODO(xians): This set the source of all audio tracks to the same
+ // microphone. Implement support for setting the source per audio track
+ // instead.
+ SetAudioDeviceSessionId(source_data->device_info().session_id);
}
- // TODO(perkj): Refactor the creation of audio tracks to use a proper
- // interface for receiving audio input data. Currently NULL is passed since
- // the |audio_device| is the wrong class and is unused.
- scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track(
- CreateLocalAudioTrack(UTF16ToUTF8(source.id()), NULL));
- native_stream->AddTrack(audio_track);
- audio_track->set_enabled(audio_components[i].isEnabled());
- // TODO(xians): This set the source of all audio tracks to the same
- // microphone. Implement support for setting the source per audio track
- // instead.
- SetAudioDeviceSessionId(source_data->device_info().session_id);
}
// Add video tracks.
@@ -335,6 +382,7 @@
scoped_refptr<webrtc::LocalMediaStreamInterface>
MediaStreamDependencyFactory::CreateLocalMediaStream(
const std::string& label) {
+ DVLOG(1) << "---MediaStreamDependencyFactory::CreateLocalMediaStream()";
return pc_factory_->CreateLocalMediaStream(label).get();
}
@@ -343,6 +391,7 @@
int video_session_id,
bool is_screencast,
const webrtc::MediaConstraintsInterface* constraints) {
+ DVLOG(1) << "---MediaStreamDependencyFactory::CreateVideoSource()";
RtcVideoCapturer* capturer = new RtcVideoCapturer(
video_session_id, vc_manager_.get(), is_screencast);
@@ -356,6 +405,7 @@
MediaStreamDependencyFactory::CreateLocalVideoTrack(
const std::string& label,
webrtc::VideoSourceInterface* source) {
+ DVLOG(1) << "---MediaStreamDependencyFactory::CreateLocalVideoTrack()";
return pc_factory_->CreateVideoTrack(label, source).get();
}
@@ -363,6 +413,7 @@
MediaStreamDependencyFactory::CreateLocalAudioTrack(
const std::string& label,
webrtc::AudioDeviceModule* audio_device) {
+ DVLOG(1) << "---MediaStreamDependencyFactory::CreateLocalAudioTrack()";
return pc_factory_->CreateLocalAudioTrack(label, audio_device).get();
}
@@ -390,6 +441,8 @@
}
void MediaStreamDependencyFactory::SetAudioDeviceSessionId(int session_id) {
+ DVLOG(1) << "--- MediaStreamDependencyFactory::SetAudioDeviceSessionId()";
+ DVLOG(1) << "--- session_id: " << session_id;
audio_device_->SetSessionId(session_id);
}
@@ -416,6 +469,7 @@
}
bool MediaStreamDependencyFactory::EnsurePeerConnectionFactory() {
+ DVLOG(1) << "--- MediaStreamDependencyFactory::EnsurePeerConnectionFactory()";
DCHECK(CalledOnValidThread());
if (PeerConnectionFactoryCreated())
return true;

Powered by Google App Engine
This is Rietveld 408576698