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

Side by Side Diff: content/renderer/media/media_stream_dependency_factory.cc

Issue 13496009: Hookup the MediaStream glue for Adding and Removing tracks to an existing MediaStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 WebKit::WebMediaStream* description) { 304 WebKit::WebMediaStream* description) {
305 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; 305 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()";
306 if (!EnsurePeerConnectionFactory()) { 306 if (!EnsurePeerConnectionFactory()) {
307 DVLOG(1) << "EnsurePeerConnectionFactory() failed!"; 307 DVLOG(1) << "EnsurePeerConnectionFactory() failed!";
308 return; 308 return;
309 } 309 }
310 310
311 std::string label = UTF16ToUTF8(description->label()); 311 std::string label = UTF16ToUTF8(description->label());
312 scoped_refptr<webrtc::MediaStreamInterface> native_stream = 312 scoped_refptr<webrtc::MediaStreamInterface> native_stream =
313 CreateLocalMediaStream(label); 313 CreateLocalMediaStream(label);
314 MediaStreamExtraData* extra_data = new MediaStreamExtraData(native_stream,
315 true);
316 description->setExtraData(extra_data);
314 317
315 // Add audio tracks. 318 // Add audio tracks.
316 WebKit::WebVector<WebKit::WebMediaStreamTrack> audio_tracks; 319 WebKit::WebVector<WebKit::WebMediaStreamTrack> audio_tracks;
317 description->audioSources(audio_tracks); 320 description->audioTracks(audio_tracks);
318
319 bool start_stream = false;
320 for (size_t i = 0; i < audio_tracks.size(); ++i) { 321 for (size_t i = 0; i < audio_tracks.size(); ++i) {
henrika (OOO until Aug 14) 2013/04/09 16:53:43 Nice! Much better structure even if I find it a bi
perkj_chrome 2013/04/10 19:58:00 .. audioSources(audio_tracks) has changed name to
321 WebKit::WebMediaStreamSource source = audio_tracks[i].source(); 322 AddNativeLocalMediaTrack(*description, audio_tracks[i]);
322
323 // See if we're adding a WebAudio MediaStream.
324 if (source.requiresAudioConsumer()) {
325 // TODO(crogers, xians): In reality we should be able to send a unique
326 // audio stream to each PeerConnection separately. But currently WebRTC
327 // is only able to handle a global audio stream sent to ALL peers.
328
329 // Create a special source where default WebAudio constraints are used.
330 if (!CreateWebAudioSource(&source)) {
331 LOG(ERROR) << "Failed to create WebAudio source";
332 continue;
333 }
334 }
335
336 MediaStreamSourceExtraData* source_data =
337 static_cast<MediaStreamSourceExtraData*>(source.extraData());
338
339 if (!source_data) {
340 // TODO(perkj): Implement support for sources from
341 // remote MediaStreams.
342 NOTIMPLEMENTED();
343 continue;
344 }
345
346 scoped_refptr<webrtc::AudioTrackInterface> audio_track(
347 CreateLocalAudioTrack(UTF16ToUTF8(audio_tracks[i].id()),
348 source_data->local_audio_source()));
349 native_stream->AddTrack(audio_track);
350 audio_track->set_enabled(audio_tracks[i].isEnabled());
351 start_stream = true;
352 }
353
354 if (start_stream && GetWebRtcAudioDevice()) {
355 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer();
356 capturer->Start();
357 } 323 }
358 324
359 // Add video tracks. 325 // Add video tracks.
360 WebKit::WebVector<WebKit::WebMediaStreamTrack> video_tracks; 326 WebKit::WebVector<WebKit::WebMediaStreamTrack> video_tracks;
361 description->videoSources(video_tracks); 327 description->videoTracks(video_tracks);
362 for (size_t i = 0; i < video_tracks.size(); ++i) { 328 for (size_t i = 0; i < video_tracks.size(); ++i) {
363 const WebKit::WebMediaStreamSource& source = video_tracks[i].source(); 329 AddNativeLocalMediaTrack(*description, video_tracks[i]);
364 MediaStreamSourceExtraData* source_data =
365 static_cast<MediaStreamSourceExtraData*>(source.extraData());
366 if (!source_data || !source_data->video_source()) {
367 // TODO(perkj): Implement support for sources from remote MediaStreams.
368 NOTIMPLEMENTED();
369 continue;
370 }
371
372 scoped_refptr<webrtc::VideoTrackInterface> video_track(
373 CreateLocalVideoTrack(UTF16ToUTF8(video_tracks[i].id()),
374 source_data->video_source()));
375
376 native_stream->AddTrack(video_track);
377 video_track->set_enabled(video_tracks[i].isEnabled());
378 } 330 }
379
380 MediaStreamExtraData* extra_data = new MediaStreamExtraData(native_stream,
381 true);
382 description->setExtraData(extra_data);
383 } 331 }
384 332
385 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream( 333 void MediaStreamDependencyFactory::CreateNativeLocalMediaStream(
386 WebKit::WebMediaStream* description, 334 WebKit::WebMediaStream* description,
387 const MediaStreamExtraData::StreamStopCallback& stream_stop) { 335 const MediaStreamExtraData::StreamStopCallback& stream_stop) {
388 CreateNativeLocalMediaStream(description); 336 CreateNativeLocalMediaStream(description);
389 337
390 MediaStreamExtraData* extra_data = 338 MediaStreamExtraData* extra_data =
391 static_cast<MediaStreamExtraData*>(description->extraData()); 339 static_cast<MediaStreamExtraData*>(description->extraData());
392 extra_data->SetLocalStreamStopCallback(stream_stop); 340 extra_data->SetLocalStreamStopCallback(stream_stop);
393 } 341 }
394 342
343 bool MediaStreamDependencyFactory::AddNativeLocalMediaTrack(
344 const WebKit::WebMediaStream& stream,
345 const WebKit::WebMediaStreamTrack& track) {
346 MediaStreamExtraData* extra_data =
347 static_cast<MediaStreamExtraData*>(stream.extraData());
348 webrtc::MediaStreamInterface* native_stream = extra_data->stream();
349 if (!native_stream) {
350 NOTREACHED();
tommi (sloooow) - chröme 2013/04/09 13:28:49 if this is something that will never happen, this
perkj_chrome 2013/04/10 19:58:00 Done.
351 return false;
352 }
353
354 WebKit::WebMediaStreamSource source = track.source();
355 MediaStreamSourceExtraData* source_data =
356 static_cast<MediaStreamSourceExtraData*>(source.extraData());
357
358 if (!source_data) {
359 if (!source.requiresAudioConsumer()) {
360 // TODO(perkj): Implement support for sources from
361 // remote MediaStreams.
362 NOTIMPLEMENTED();
henrika (OOO until Aug 14) 2013/04/09 16:53:43 What does the combo of NOTIMPLEMENTED() + return f
perkj_chrome 2013/04/10 19:58:00 NOTIMPLEMENTED prints a warning in the log output.
363 return false;
364 } else
365 // We're adding a WebAudio MediaStream.
tommi (sloooow) - chröme 2013/04/09 13:28:49 Is that the only possibility? Is there a way to ve
perkj_chrome 2013/04/10 19:58:00 source.requiresAudioConsumer() means WebAudio in B
366 // TODO(crogers, xians): In reality we should be able to send a unique
367 // audio stream to each PeerConnection separately. But currently WebRTC
368 // is only able to handle a global audio stream sent to ALL peers.
369 // Create a special source where default WebAudio constraints are used.
henrika (OOO until Aug 14) 2013/04/09 16:53:43 Nit, the TODO is not really connected to the audio
perkj_chrome 2013/04/10 19:58:00 Done.
370 if (CreateWebAudioSource(&source)) {
371 source_data =
372 static_cast<MediaStreamSourceExtraData*>(source.extraData());
373 } else {
374 LOG(ERROR) << "Failed to create WebAudio source";
375 return false;
376 }
377 }
378
379 if (source.type() == WebKit::WebMediaStreamSource::TypeAudio) {
tommi (sloooow) - chröme 2013/04/09 13:28:49 nit: if type() can only ever be audio or video, th
perkj_chrome 2013/04/10 19:58:00 Done.
380 scoped_refptr<webrtc::AudioTrackInterface> audio_track(
381 CreateLocalAudioTrack(UTF16ToUTF8(track.id()),
382 source_data->local_audio_source()));
383 audio_track->set_enabled(track.isEnabled());
384 if (GetWebRtcAudioDevice()) {
henrika (OOO until Aug 14) 2013/04/09 16:53:43 Could you add a TODO(henrika,xians) here saying th
385 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer();
386 if (!capturer->is_recording())
387 capturer->Start();
388 }
389 return native_stream->AddTrack(audio_track);
390
391 } else if (source.type() == WebKit::WebMediaStreamSource::TypeVideo) {
392 scoped_refptr<webrtc::VideoTrackInterface> video_track(
393 CreateLocalVideoTrack(UTF16ToUTF8(track.id()),
394 source_data->video_source()));
395 video_track->set_enabled(track.isEnabled());
396 return native_stream->AddTrack(video_track);
397 }
398 NOTREACHED();
399 return false;
400 }
401
395 bool MediaStreamDependencyFactory::CreatePeerConnectionFactory() { 402 bool MediaStreamDependencyFactory::CreatePeerConnectionFactory() {
396 DVLOG(1) << "MediaStreamDependencyFactory::CreatePeerConnectionFactory()"; 403 DVLOG(1) << "MediaStreamDependencyFactory::CreatePeerConnectionFactory()";
397 if (!pc_factory_.get()) { 404 if (!pc_factory_.get()) {
398 DCHECK(!audio_device_); 405 DCHECK(!audio_device_);
399 audio_device_ = new WebRtcAudioDeviceImpl(); 406 audio_device_ = new WebRtcAudioDeviceImpl();
400 scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 407 scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory(
401 webrtc::CreatePeerConnectionFactory(worker_thread_, 408 webrtc::CreatePeerConnectionFactory(worker_thread_,
402 signaling_thread_, 409 signaling_thread_,
403 audio_device_)); 410 audio_device_));
404 if (factory.get()) 411 if (factory.get())
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 // processed before returning. We wait for the above task to finish before 670 // processed before returning. We wait for the above task to finish before
664 // letting the the function continue to avoid any potential race issues. 671 // letting the the function continue to avoid any potential race issues.
665 chrome_worker_thread_.Stop(); 672 chrome_worker_thread_.Stop();
666 } else { 673 } else {
667 NOTREACHED() << "Worker thread not running."; 674 NOTREACHED() << "Worker thread not running.";
668 } 675 }
669 } 676 }
670 } 677 }
671 678
672 } // namespace content 679 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698