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

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

Issue 11669004: Add chromium support for MediaStreamAudioDestinationNode - part II (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit Created 8 years 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
diff --git a/content/renderer/media/media_stream_dependency_factory.cc b/content/renderer/media/media_stream_dependency_factory.cc
index 69a35727ac7c413317e4292452788668680f0e03..e2cc83e53c75ce4bf754321cd67191fa8f3d2c88 100644
--- a/content/renderer/media/media_stream_dependency_factory.cc
+++ b/content/renderer/media/media_stream_dependency_factory.cc
@@ -228,35 +228,87 @@ void MediaStreamDependencyFactory::CreateNativeMediaSources(
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->SetCapturerSource(webaudio_capturer_source_);
+ capturer->Start();
+
+ // 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());
+
+ // Do we need to set a sessionId???
+ // SetAudioDeviceSessionId(99);
+ } 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 +387,7 @@ MediaStreamDependencyFactory::CreatePeerConnection(
scoped_refptr<webrtc::LocalMediaStreamInterface>
MediaStreamDependencyFactory::CreateLocalMediaStream(
const std::string& label) {
+ DVLOG(1) << "---MediaStreamDependencyFactory::CreateLocalMediaStream()";
return pc_factory_->CreateLocalMediaStream(label).get();
}
@@ -343,6 +396,7 @@ MediaStreamDependencyFactory::CreateVideoSource(
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 +410,7 @@ scoped_refptr<webrtc::VideoTrackInterface>
MediaStreamDependencyFactory::CreateLocalVideoTrack(
const std::string& label,
webrtc::VideoSourceInterface* source) {
+ DVLOG(1) << "---MediaStreamDependencyFactory::CreateLocalVideoTrack()";
return pc_factory_->CreateVideoTrack(label, source).get();
}
@@ -363,6 +418,7 @@ scoped_refptr<webrtc::LocalAudioTrackInterface>
MediaStreamDependencyFactory::CreateLocalAudioTrack(
const std::string& label,
webrtc::AudioDeviceModule* audio_device) {
+ DVLOG(1) << "---MediaStreamDependencyFactory::CreateLocalAudioTrack()";
return pc_factory_->CreateLocalAudioTrack(label, audio_device).get();
}
@@ -390,6 +446,8 @@ MediaStreamDependencyFactory::GetWebRtcAudioDevice() {
}
void MediaStreamDependencyFactory::SetAudioDeviceSessionId(int session_id) {
+ DVLOG(1) << "--- MediaStreamDependencyFactory::SetAudioDeviceSessionId()";
+ DVLOG(1) << "--- session_id: " << session_id;
audio_device_->SetSessionId(session_id);
}
@@ -416,6 +474,7 @@ void MediaStreamDependencyFactory::DeleteIpcNetworkManager() {
}
bool MediaStreamDependencyFactory::EnsurePeerConnectionFactory() {
+ DVLOG(1) << "--- MediaStreamDependencyFactory::EnsurePeerConnectionFactory()";
DCHECK(CalledOnValidThread());
if (PeerConnectionFactoryCreated())
return true;
« no previous file with comments | « content/renderer/media/media_stream_dependency_factory.h ('k') | content/renderer/media/media_stream_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698