Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/media_stream_dependency_factory.h" | 5 #include "content/renderer/media/media_stream_dependency_factory.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 CreateVideoSource(source_data->device_info().session_id, | 221 CreateVideoSource(source_data->device_info().session_id, |
| 222 is_screencast, | 222 is_screencast, |
| 223 &native_video_constraints)); | 223 &native_video_constraints)); |
| 224 source_observer->AddSource(source_data->video_source()); | 224 source_observer->AddSource(source_data->video_source()); |
| 225 } | 225 } |
| 226 source_observer->StartObservering(); | 226 source_observer->StartObservering(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( | 229 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( |
| 230 WebKit::WebMediaStreamDescriptor* description) { | 230 WebKit::WebMediaStreamDescriptor* description) { |
| 231 DCHECK(PeerConnectionFactoryCreated()); | 231 if (!EnsurePeerConnectionFactory()) { |
| 232 DVLOG(1) << "EnsurePeerConnectionFactory() failed!"; | |
| 233 return; | |
| 234 } | |
| 232 | 235 |
| 233 std::string label = UTF16ToUTF8(description->label()); | 236 std::string label = UTF16ToUTF8(description->label()); |
| 234 scoped_refptr<webrtc::LocalMediaStreamInterface> native_stream = | 237 scoped_refptr<webrtc::LocalMediaStreamInterface> native_stream = |
| 235 CreateLocalMediaStream(label); | 238 CreateLocalMediaStream(label); |
| 236 | 239 |
| 240 WebRtcAudioCapturer* capturer = | |
| 241 GetWebRtcAudioDevice() ? GetWebRtcAudioDevice()->capturer() : 0; | |
| 242 if (!capturer) | |
| 243 DVLOG(1) << "CreateNativeLocalMediaStream: missing WebRtcAudioCapturer."; | |
| 244 | |
| 237 // Add audio tracks. | 245 // Add audio tracks. |
| 238 WebKit::WebVector<WebKit::WebMediaStreamComponent> audio_components; | 246 WebKit::WebVector<WebKit::WebMediaStreamComponent> audio_components; |
| 239 description->audioSources(audio_components); | 247 description->audioSources(audio_components); |
| 248 | |
| 240 for (size_t i = 0; i < audio_components.size(); ++i) { | 249 for (size_t i = 0; i < audio_components.size(); ++i) { |
| 241 const WebKit::WebMediaStreamSource& source = audio_components[i].source(); | 250 WebKit::WebMediaStreamSource source = audio_components[i].source(); |
| 242 MediaStreamSourceExtraData* source_data = | 251 |
| 243 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 252 // See if we're adding a WebAudio MediaStream. |
| 244 if (!source_data) { | 253 if (source.requiresAudioConsumer()) { |
| 245 // TODO(perkj): Implement support for sources from remote MediaStreams. | 254 if (!webaudio_capturer_source_.get() && capturer) { |
| 246 NOTIMPLEMENTED(); | 255 DCHECK(GetWebRtcAudioDevice()); |
| 247 continue; | 256 |
| 257 // TODO(crogers, xians): In reality we should be able to send a unique | |
| 258 // audio stream to each PeerConnection separately. But currently WebRTC | |
| 259 // is only able to handle a global audio stream sent to ALL peers. | |
| 260 | |
| 261 // For lifetime, we're relying on the fact that | |
| 262 // |webaudio_capturer_source_| will live longer than any | |
| 263 // MediaStreamSource, since we're never calling removeAudioConsumer(). | |
| 264 webaudio_capturer_source_ = new WebAudioCapturerSource(capturer); | |
| 265 source.addAudioConsumer(webaudio_capturer_source_.get()); | |
| 266 | |
| 267 scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track( | |
|
henrika (OOO until Aug 14)
2013/01/16 17:25:15
This part is kind of magic. Could you sort out the
Chris Rogers
2013/01/16 18:38:54
This is code you gave me :) I think Per helped yo
henrika (OOO until Aug 14)
2013/01/17 08:13:09
I will check with Per and perhaps add more comment
| |
| 268 CreateLocalAudioTrack(label + "a0", NULL)); | |
| 269 native_stream->AddTrack(audio_track); | |
| 270 audio_track->set_enabled(audio_components[i].isEnabled()); | |
| 271 } else { | |
| 272 // TODO(crogers): this is very likely to be less important, but | |
| 273 // in theory we should be able to "connect" multiple WebAudio | |
| 274 // MediaStreams to a single peer, mixing their results. | |
| 275 // Instead we just ignore additional ones after the first. | |
| 276 LOG(WARNING) | |
| 277 << "Multiple MediaStreamAudioDestinationNodes not yet supported!"; | |
| 278 } | |
| 279 } else { | |
| 280 MediaStreamSourceExtraData* source_data = | |
| 281 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | |
| 282 | |
| 283 if (!source_data) { | |
| 284 // TODO(perkj): Implement support for sources from | |
| 285 // remote MediaStreams. | |
| 286 NOTIMPLEMENTED(); | |
| 287 continue; | |
| 288 } | |
| 289 | |
| 290 // TODO(perkj): Refactor the creation of audio tracks to use a proper | |
| 291 // interface for receiving audio input data. Currently NULL is passed | |
| 292 // since the |audio_device| is the wrong class and is unused. | |
| 293 scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track( | |
| 294 CreateLocalAudioTrack(UTF16ToUTF8(source.id()), NULL)); | |
| 295 native_stream->AddTrack(audio_track); | |
| 296 audio_track->set_enabled(audio_components[i].isEnabled()); | |
| 297 // TODO(xians): This set the source of all audio tracks to the same | |
| 298 // microphone. Implement support for setting the source per audio track | |
| 299 // instead. | |
| 300 SetAudioDeviceSessionId(source_data->device_info().session_id); | |
| 248 } | 301 } |
| 249 // TODO(perkj): Refactor the creation of audio tracks to use a proper | |
| 250 // interface for receiving audio input data. Currently NULL is passed since | |
| 251 // the |audio_device| is the wrong class and is unused. | |
| 252 scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track( | |
| 253 CreateLocalAudioTrack(UTF16ToUTF8(source.id()), NULL)); | |
| 254 native_stream->AddTrack(audio_track); | |
| 255 audio_track->set_enabled(audio_components[i].isEnabled()); | |
| 256 // TODO(xians): This set the source of all audio tracks to the same | |
| 257 // microphone. Implement support for setting the source per audio track | |
| 258 // instead. | |
| 259 SetAudioDeviceSessionId(source_data->device_info().session_id); | |
| 260 } | 302 } |
| 261 | 303 |
| 262 // Add video tracks. | 304 // Add video tracks. |
| 263 WebKit::WebVector<WebKit::WebMediaStreamComponent> video_components; | 305 WebKit::WebVector<WebKit::WebMediaStreamComponent> video_components; |
| 264 description->videoSources(video_components); | 306 description->videoSources(video_components); |
| 265 for (size_t i = 0; i < video_components.size(); ++i) { | 307 for (size_t i = 0; i < video_components.size(); ++i) { |
| 266 const WebKit::WebMediaStreamSource& source = video_components[i].source(); | 308 const WebKit::WebMediaStreamSource& source = video_components[i].source(); |
| 267 MediaStreamSourceExtraData* source_data = | 309 MediaStreamSourceExtraData* source_data = |
| 268 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 310 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
| 269 if (!source_data || !source_data->video_source()) { | 311 if (!source_data || !source_data->video_source()) { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 // processed before returning. We wait for the above task to finish before | 526 // processed before returning. We wait for the above task to finish before |
| 485 // letting the the function continue to avoid any potential race issues. | 527 // letting the the function continue to avoid any potential race issues. |
| 486 chrome_worker_thread_.Stop(); | 528 chrome_worker_thread_.Stop(); |
| 487 } else { | 529 } else { |
| 488 NOTREACHED() << "Worker thread not running."; | 530 NOTREACHED() << "Worker thread not running."; |
| 489 } | 531 } |
| 490 } | 532 } |
| 491 } | 533 } |
| 492 | 534 |
| 493 } // namespace content | 535 } // namespace content |
| OLD | NEW |