| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 config.relay_server = turn_configurations[0].server.hostname(); | 106 config.relay_server = turn_configurations[0].server.hostname(); |
| 107 config.relay_server_port = turn_configurations[0].server.port(); | 107 config.relay_server_port = turn_configurations[0].server.port(); |
| 108 config.relay_username = turn_configurations[0].username; | 108 config.relay_username = turn_configurations[0].username; |
| 109 config.relay_password = turn_configurations[0].password; | 109 config.relay_password = turn_configurations[0].password; |
| 110 // Use the turn server as the stun server. | 110 // Use the turn server as the stun server. |
| 111 config.stun_server = config.relay_server; | 111 config.stun_server = config.relay_server; |
| 112 config.stun_server_port = config.relay_server_port; | 112 config.stun_server_port = config.relay_server_port; |
| 113 } | 113 } |
| 114 | 114 |
| 115 return new P2PPortAllocator(web_frame_, | 115 return new P2PPortAllocator(web_frame_, |
| 116 socket_dispatcher_, | 116 socket_dispatcher_.get(), |
| 117 network_manager_, | 117 network_manager_, |
| 118 socket_factory_, | 118 socket_factory_, |
| 119 config); | 119 config); |
| 120 } | 120 } |
| 121 | 121 |
| 122 protected: | 122 protected: |
| 123 virtual ~P2PPortAllocatorFactory() {} | 123 virtual ~P2PPortAllocatorFactory() {} |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 scoped_refptr<P2PSocketDispatcher> socket_dispatcher_; | 126 scoped_refptr<P2PSocketDispatcher> socket_dispatcher_; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 WebKit::WebMediaStream* description) { | 324 WebKit::WebMediaStream* description) { |
| 325 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; | 325 DVLOG(1) << "MediaStreamDependencyFactory::CreateNativeLocalMediaStream()"; |
| 326 if (!EnsurePeerConnectionFactory()) { | 326 if (!EnsurePeerConnectionFactory()) { |
| 327 DVLOG(1) << "EnsurePeerConnectionFactory() failed!"; | 327 DVLOG(1) << "EnsurePeerConnectionFactory() failed!"; |
| 328 return; | 328 return; |
| 329 } | 329 } |
| 330 | 330 |
| 331 std::string label = UTF16ToUTF8(description->label()); | 331 std::string label = UTF16ToUTF8(description->label()); |
| 332 scoped_refptr<webrtc::MediaStreamInterface> native_stream = | 332 scoped_refptr<webrtc::MediaStreamInterface> native_stream = |
| 333 CreateLocalMediaStream(label); | 333 CreateLocalMediaStream(label); |
| 334 MediaStreamExtraData* extra_data = new MediaStreamExtraData(native_stream, | 334 MediaStreamExtraData* extra_data = |
| 335 true); | 335 new MediaStreamExtraData(native_stream.get(), true); |
| 336 description->setExtraData(extra_data); | 336 description->setExtraData(extra_data); |
| 337 | 337 |
| 338 // Add audio tracks. | 338 // Add audio tracks. |
| 339 WebKit::WebVector<WebKit::WebMediaStreamTrack> audio_tracks; | 339 WebKit::WebVector<WebKit::WebMediaStreamTrack> audio_tracks; |
| 340 description->audioTracks(audio_tracks); | 340 description->audioTracks(audio_tracks); |
| 341 for (size_t i = 0; i < audio_tracks.size(); ++i) { | 341 for (size_t i = 0; i < audio_tracks.size(); ++i) { |
| 342 AddNativeMediaStreamTrack(*description, audio_tracks[i]); | 342 AddNativeMediaStreamTrack(*description, audio_tracks[i]); |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Add video tracks. | 345 // Add video tracks. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 358 MediaStreamExtraData* extra_data = | 358 MediaStreamExtraData* extra_data = |
| 359 static_cast<MediaStreamExtraData*>(description->extraData()); | 359 static_cast<MediaStreamExtraData*>(description->extraData()); |
| 360 extra_data->SetLocalStreamStopCallback(stream_stop); | 360 extra_data->SetLocalStreamStopCallback(stream_stop); |
| 361 } | 361 } |
| 362 | 362 |
| 363 bool MediaStreamDependencyFactory::AddNativeMediaStreamTrack( | 363 bool MediaStreamDependencyFactory::AddNativeMediaStreamTrack( |
| 364 const WebKit::WebMediaStream& stream, | 364 const WebKit::WebMediaStream& stream, |
| 365 const WebKit::WebMediaStreamTrack& track) { | 365 const WebKit::WebMediaStreamTrack& track) { |
| 366 MediaStreamExtraData* extra_data = | 366 MediaStreamExtraData* extra_data = |
| 367 static_cast<MediaStreamExtraData*>(stream.extraData()); | 367 static_cast<MediaStreamExtraData*>(stream.extraData()); |
| 368 webrtc::MediaStreamInterface* native_stream = extra_data->stream(); | 368 webrtc::MediaStreamInterface* native_stream = extra_data->stream().get(); |
| 369 DCHECK(native_stream); | 369 DCHECK(native_stream); |
| 370 | 370 |
| 371 WebKit::WebMediaStreamSource source = track.source(); | 371 WebKit::WebMediaStreamSource source = track.source(); |
| 372 MediaStreamSourceExtraData* source_data = | 372 MediaStreamSourceExtraData* source_data = |
| 373 static_cast<MediaStreamSourceExtraData*>(source.extraData()); | 373 static_cast<MediaStreamSourceExtraData*>(source.extraData()); |
| 374 | 374 |
| 375 if (!source_data) { | 375 if (!source_data) { |
| 376 if (source.requiresAudioConsumer()) { | 376 if (source.requiresAudioConsumer()) { |
| 377 // We're adding a WebAudio MediaStream. | 377 // We're adding a WebAudio MediaStream. |
| 378 // TODO(crogers, xians): In reality we should be able to send a unique | 378 // TODO(crogers, xians): In reality we should be able to send a unique |
| (...skipping 21 matching lines...) Expand all Loading... |
| 400 type == WebKit::WebMediaStreamSource::TypeVideo); | 400 type == WebKit::WebMediaStreamSource::TypeVideo); |
| 401 | 401 |
| 402 std::string track_id = UTF16ToUTF8(track.id()); | 402 std::string track_id = UTF16ToUTF8(track.id()); |
| 403 if (source.type() == WebKit::WebMediaStreamSource::TypeAudio) { | 403 if (source.type() == WebKit::WebMediaStreamSource::TypeAudio) { |
| 404 // TODO(henrika,xians): Refactor how an audio track is created to harmonize | 404 // TODO(henrika,xians): Refactor how an audio track is created to harmonize |
| 405 // with video tracks. | 405 // with video tracks. |
| 406 scoped_refptr<webrtc::AudioTrackInterface> audio_track( | 406 scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 407 CreateLocalAudioTrack(track_id, source_data->local_audio_source())); | 407 CreateLocalAudioTrack(track_id, source_data->local_audio_source())); |
| 408 audio_track->set_enabled(track.isEnabled()); | 408 audio_track->set_enabled(track.isEnabled()); |
| 409 if (GetWebRtcAudioDevice()) { | 409 if (GetWebRtcAudioDevice()) { |
| 410 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer(); | 410 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer().get(); |
| 411 if (!capturer->is_recording()) | 411 if (!capturer->is_recording()) |
| 412 capturer->Start(); | 412 capturer->Start(); |
| 413 } | 413 } |
| 414 return native_stream->AddTrack(audio_track); | 414 return native_stream->AddTrack(audio_track.get()); |
| 415 } else { | 415 } else { |
| 416 scoped_refptr<webrtc::VideoTrackInterface> video_track( | 416 scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 417 CreateLocalVideoTrack(track_id, source_data->video_source())); | 417 CreateLocalVideoTrack(track_id, source_data->video_source())); |
| 418 video_track->set_enabled(track.isEnabled()); | 418 video_track->set_enabled(track.isEnabled()); |
| 419 return native_stream->AddTrack(video_track); | 419 return native_stream->AddTrack(video_track.get()); |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 bool MediaStreamDependencyFactory::AddNativeVideoMediaTrack( | 423 bool MediaStreamDependencyFactory::AddNativeVideoMediaTrack( |
| 424 const std::string& track_id, | 424 const std::string& track_id, |
| 425 WebKit::WebMediaStream* stream, | 425 WebKit::WebMediaStream* stream, |
| 426 cricket::VideoCapturer* capturer) { | 426 cricket::VideoCapturer* capturer) { |
| 427 if (!stream) { | 427 if (!stream) { |
| 428 LOG(ERROR) << "AddNativeVideoMediaTrack called with null WebMediaStream."; | 428 LOG(ERROR) << "AddNativeVideoMediaTrack called with null WebMediaStream."; |
| 429 return false; | 429 return false; |
| 430 } | 430 } |
| 431 | 431 |
| 432 // Create native track from the source. | 432 // Create native track from the source. |
| 433 scoped_refptr<webrtc::VideoTrackInterface> native_track = | 433 scoped_refptr<webrtc::VideoTrackInterface> native_track = |
| 434 CreateLocalVideoTrack(track_id, capturer); | 434 CreateLocalVideoTrack(track_id, capturer); |
| 435 | 435 |
| 436 // Add the native track to native stream | 436 // Add the native track to native stream |
| 437 MediaStreamExtraData* extra_data = | 437 MediaStreamExtraData* extra_data = |
| 438 static_cast<MediaStreamExtraData*>(stream->extraData()); | 438 static_cast<MediaStreamExtraData*>(stream->extraData()); |
| 439 DCHECK(extra_data); | 439 DCHECK(extra_data); |
| 440 webrtc::MediaStreamInterface* native_stream = extra_data->stream(); | 440 webrtc::MediaStreamInterface* native_stream = extra_data->stream().get(); |
| 441 native_stream->AddTrack(native_track); | 441 native_stream->AddTrack(native_track.get()); |
| 442 | 442 |
| 443 // Create a new webkit video track. | 443 // Create a new webkit video track. |
| 444 WebKit::WebMediaStreamTrack webkit_track; | 444 WebKit::WebMediaStreamTrack webkit_track; |
| 445 WebKit::WebMediaStreamSource webkit_source; | 445 WebKit::WebMediaStreamSource webkit_source; |
| 446 WebKit::WebString webkit_track_id(UTF8ToUTF16(track_id)); | 446 WebKit::WebString webkit_track_id(UTF8ToUTF16(track_id)); |
| 447 WebKit::WebMediaStreamSource::Type type = | 447 WebKit::WebMediaStreamSource::Type type = |
| 448 WebKit::WebMediaStreamSource::TypeVideo; | 448 WebKit::WebMediaStreamSource::TypeVideo; |
| 449 webkit_source.initialize(webkit_track_id, type, webkit_track_id); | 449 webkit_source.initialize(webkit_track_id, type, webkit_track_id); |
| 450 webkit_track.initialize(webkit_track_id, webkit_source); | 450 webkit_track.initialize(webkit_track_id, webkit_source); |
| 451 | 451 |
| 452 // Add the track to WebMediaStream. | 452 // Add the track to WebMediaStream. |
| 453 stream->addTrack(webkit_track); | 453 stream->addTrack(webkit_track); |
| 454 return true; | 454 return true; |
| 455 } | 455 } |
| 456 | 456 |
| 457 bool MediaStreamDependencyFactory::RemoveNativeMediaStreamTrack( | 457 bool MediaStreamDependencyFactory::RemoveNativeMediaStreamTrack( |
| 458 const WebKit::WebMediaStream& stream, | 458 const WebKit::WebMediaStream& stream, |
| 459 const WebKit::WebMediaStreamTrack& track) { | 459 const WebKit::WebMediaStreamTrack& track) { |
| 460 MediaStreamExtraData* extra_data = | 460 MediaStreamExtraData* extra_data = |
| 461 static_cast<MediaStreamExtraData*>(stream.extraData()); | 461 static_cast<MediaStreamExtraData*>(stream.extraData()); |
| 462 webrtc::MediaStreamInterface* native_stream = extra_data->stream(); | 462 webrtc::MediaStreamInterface* native_stream = extra_data->stream().get(); |
| 463 DCHECK(native_stream); | 463 DCHECK(native_stream); |
| 464 | 464 |
| 465 WebKit::WebMediaStreamSource::Type type = track.source().type(); | 465 WebKit::WebMediaStreamSource::Type type = track.source().type(); |
| 466 DCHECK(type == WebKit::WebMediaStreamSource::TypeAudio || | 466 DCHECK(type == WebKit::WebMediaStreamSource::TypeAudio || |
| 467 type == WebKit::WebMediaStreamSource::TypeVideo); | 467 type == WebKit::WebMediaStreamSource::TypeVideo); |
| 468 | 468 |
| 469 std::string track_id = UTF16ToUTF8(track.id()); | 469 std::string track_id = UTF16ToUTF8(track.id()); |
| 470 return type == WebKit::WebMediaStreamSource::TypeAudio ? | 470 return type == WebKit::WebMediaStreamSource::TypeAudio ? |
| 471 native_stream->RemoveTrack(native_stream->FindAudioTrack(track_id)) : | 471 native_stream->RemoveTrack(native_stream->FindAudioTrack(track_id)) : |
| 472 native_stream->RemoveTrack(native_stream->FindVideoTrack(track_id)); | 472 native_stream->RemoveTrack(native_stream->FindVideoTrack(track_id)); |
| 473 } | 473 } |
| 474 | 474 |
| 475 bool MediaStreamDependencyFactory::CreatePeerConnectionFactory() { | 475 bool MediaStreamDependencyFactory::CreatePeerConnectionFactory() { |
| 476 DVLOG(1) << "MediaStreamDependencyFactory::CreatePeerConnectionFactory()"; | 476 DVLOG(1) << "MediaStreamDependencyFactory::CreatePeerConnectionFactory()"; |
| 477 if (!pc_factory_) { | 477 if (!pc_factory_.get()) { |
| 478 DCHECK(!audio_device_); | 478 DCHECK(!audio_device_.get()); |
| 479 audio_device_ = new WebRtcAudioDeviceImpl(); | 479 audio_device_ = new WebRtcAudioDeviceImpl(); |
| 480 scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( | 480 scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( |
| 481 webrtc::CreatePeerConnectionFactory( | 481 webrtc::CreatePeerConnectionFactory(worker_thread_, |
| 482 worker_thread_, signaling_thread_, audio_device_, NULL, NULL)); | 482 signaling_thread_, |
| 483 if (factory) | 483 audio_device_.get(), |
| 484 NULL, |
| 485 NULL)); |
| 486 if (factory.get()) |
| 484 pc_factory_ = factory; | 487 pc_factory_ = factory; |
| 485 else | 488 else |
| 486 audio_device_ = NULL; | 489 audio_device_ = NULL; |
| 487 } | 490 } |
| 488 return pc_factory_.get() != NULL; | 491 return pc_factory_.get() != NULL; |
| 489 } | 492 } |
| 490 | 493 |
| 491 bool MediaStreamDependencyFactory::PeerConnectionFactoryCreated() { | 494 bool MediaStreamDependencyFactory::PeerConnectionFactoryCreated() { |
| 492 return pc_factory_.get() != NULL; | 495 return pc_factory_.get() != NULL; |
| 493 } | 496 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 514 url)); | 517 url)); |
| 515 } | 518 } |
| 516 | 519 |
| 517 scoped_refptr<P2PPortAllocatorFactory> pa_factory = | 520 scoped_refptr<P2PPortAllocatorFactory> pa_factory = |
| 518 new talk_base::RefCountedObject<P2PPortAllocatorFactory>( | 521 new talk_base::RefCountedObject<P2PPortAllocatorFactory>( |
| 519 p2p_socket_dispatcher_.get(), | 522 p2p_socket_dispatcher_.get(), |
| 520 network_manager_, | 523 network_manager_, |
| 521 socket_factory_.get(), | 524 socket_factory_.get(), |
| 522 web_frame); | 525 web_frame); |
| 523 return pc_factory_->CreatePeerConnection( | 526 return pc_factory_->CreatePeerConnection( |
| 524 ice_servers, constraints, pa_factory, observer).get(); | 527 ice_servers, constraints, pa_factory.get(), observer) |
| 528 .get(); |
| 525 } | 529 } |
| 526 | 530 |
| 527 scoped_refptr<webrtc::MediaStreamInterface> | 531 scoped_refptr<webrtc::MediaStreamInterface> |
| 528 MediaStreamDependencyFactory::CreateLocalMediaStream( | 532 MediaStreamDependencyFactory::CreateLocalMediaStream( |
| 529 const std::string& label) { | 533 const std::string& label) { |
| 530 return pc_factory_->CreateLocalMediaStream(label).get(); | 534 return pc_factory_->CreateLocalMediaStream(label).get(); |
| 531 } | 535 } |
| 532 | 536 |
| 533 scoped_refptr<webrtc::AudioSourceInterface> | 537 scoped_refptr<webrtc::AudioSourceInterface> |
| 534 MediaStreamDependencyFactory::CreateLocalAudioSource( | 538 MediaStreamDependencyFactory::CreateLocalAudioSource( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 557 const StreamDeviceInfo& device_info) { | 561 const StreamDeviceInfo& device_info) { |
| 558 DVLOG(1) << "MediaStreamDependencyFactory::InitializeAudioSource()"; | 562 DVLOG(1) << "MediaStreamDependencyFactory::InitializeAudioSource()"; |
| 559 | 563 |
| 560 // TODO(henrika): the current design does not support a unique source | 564 // TODO(henrika): the current design does not support a unique source |
| 561 // for each audio track. | 565 // for each audio track. |
| 562 if (device_info.session_id <= 0) | 566 if (device_info.session_id <= 0) |
| 563 return false; | 567 return false; |
| 564 | 568 |
| 565 // Initialize the source using audio parameters for the selected | 569 // Initialize the source using audio parameters for the selected |
| 566 // capture device. | 570 // capture device. |
| 567 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer(); | 571 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer().get(); |
| 568 // TODO(henrika): refactor \content\public\common\media_stream_request.h | 572 // TODO(henrika): refactor \content\public\common\media_stream_request.h |
| 569 // to allow dependency of media::ChannelLayout and avoid static_cast. | 573 // to allow dependency of media::ChannelLayout and avoid static_cast. |
| 570 if (!capturer->Initialize( | 574 if (!capturer->Initialize( |
| 571 render_view_id, | 575 render_view_id, |
| 572 static_cast<media::ChannelLayout>(device_info.device.channel_layout), | 576 static_cast<media::ChannelLayout>(device_info.device.channel_layout), |
| 573 device_info.device.sample_rate, device_info.session_id)) | 577 device_info.device.sample_rate, device_info.session_id)) |
| 574 return false; | 578 return false; |
| 575 | 579 |
| 576 return true; | 580 return true; |
| 577 } | 581 } |
| 578 | 582 |
| 579 bool MediaStreamDependencyFactory::CreateWebAudioSource( | 583 bool MediaStreamDependencyFactory::CreateWebAudioSource( |
| 580 WebKit::WebMediaStreamSource* source) { | 584 WebKit::WebMediaStreamSource* source) { |
| 581 DVLOG(1) << "MediaStreamDependencyFactory::CreateWebAudioSource()"; | 585 DVLOG(1) << "MediaStreamDependencyFactory::CreateWebAudioSource()"; |
| 582 DCHECK(GetWebRtcAudioDevice()); | 586 DCHECK(GetWebRtcAudioDevice()); |
| 583 | 587 |
| 584 // WebAudio needs the WebRtcAudioCapturer to be able to send its data | 588 // WebAudio needs the WebRtcAudioCapturer to be able to send its data |
| 585 // over a PeerConnection. The microphone source is not utilized in this | 589 // over a PeerConnection. The microphone source is not utilized in this |
| 586 // case; instead the WebRtcAudioCapturer is driving. | 590 // case; instead the WebRtcAudioCapturer is driving. |
| 587 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer(); | 591 WebRtcAudioCapturer* capturer = GetWebRtcAudioDevice()->capturer().get(); |
| 588 if (!capturer) | 592 if (!capturer) |
| 589 return false; | 593 return false; |
| 590 | 594 |
| 591 // Set up the source and ensure that WebAudio is driving things instead of | 595 // Set up the source and ensure that WebAudio is driving things instead of |
| 592 // a microphone. | 596 // a microphone. |
| 593 | 597 |
| 594 scoped_refptr<WebAudioCapturerSource> | 598 scoped_refptr<WebAudioCapturerSource> |
| 595 webaudio_capturer_source(new WebAudioCapturerSource(capturer)); | 599 webaudio_capturer_source(new WebAudioCapturerSource(capturer)); |
| 596 MediaStreamSourceExtraData* source_data = | 600 MediaStreamSourceExtraData* source_data = |
| 597 new content::MediaStreamSourceExtraData(webaudio_capturer_source); | 601 new content::MediaStreamSourceExtraData(webaudio_capturer_source.get()); |
| 598 | 602 |
| 599 // Create a LocalAudioSource object which holds audio options. | 603 // Create a LocalAudioSource object which holds audio options. |
| 600 // Use audio constraints where all values are false, i.e., disable | 604 // Use audio constraints where all values are false, i.e., disable |
| 601 // echo cancellation, automatic gain control, noise suppression and | 605 // echo cancellation, automatic gain control, noise suppression and |
| 602 // high-pass filter. SetLocalAudioSource() affects core audio parts in | 606 // high-pass filter. SetLocalAudioSource() affects core audio parts in |
| 603 // third_party/Libjingle. | 607 // third_party/Libjingle. |
| 604 WebAudioConstraints webaudio_audio_constraints_all_false; | 608 WebAudioConstraints webaudio_audio_constraints_all_false; |
| 605 source_data->SetLocalAudioSource( | 609 source_data->SetLocalAudioSource( |
| 606 CreateLocalAudioSource(&webaudio_audio_constraints_all_false)); | 610 CreateLocalAudioSource(&webaudio_audio_constraints_all_false)); |
| 607 source->setExtraData(source_data); | 611 source->setExtraData(source_data); |
| 608 | 612 |
| 609 // Replace the default source with WebAudio as source instead. | 613 // Replace the default source with WebAudio as source instead. |
| 610 source->addAudioConsumer(webaudio_capturer_source); | 614 source->addAudioConsumer(webaudio_capturer_source.get()); |
| 611 | 615 |
| 612 return true; | 616 return true; |
| 613 } | 617 } |
| 614 | 618 |
| 615 scoped_refptr<webrtc::VideoTrackInterface> | 619 scoped_refptr<webrtc::VideoTrackInterface> |
| 616 MediaStreamDependencyFactory::CreateLocalVideoTrack( | 620 MediaStreamDependencyFactory::CreateLocalVideoTrack( |
| 617 const std::string& id, | 621 const std::string& id, |
| 618 webrtc::VideoSourceInterface* source) { | 622 webrtc::VideoSourceInterface* source) { |
| 619 return pc_factory_->CreateVideoTrack(id, source).get(); | 623 return pc_factory_->CreateVideoTrack(id, source).get(); |
| 620 } | 624 } |
| 621 | 625 |
| 622 scoped_refptr<webrtc::VideoTrackInterface> | 626 scoped_refptr<webrtc::VideoTrackInterface> |
| 623 MediaStreamDependencyFactory::CreateLocalVideoTrack( | 627 MediaStreamDependencyFactory::CreateLocalVideoTrack( |
| 624 const std::string& id, cricket::VideoCapturer* capturer) { | 628 const std::string& id, cricket::VideoCapturer* capturer) { |
| 625 if (!capturer) { | 629 if (!capturer) { |
| 626 LOG(ERROR) << "CreateLocalVideoTrack called with null VideoCapturer."; | 630 LOG(ERROR) << "CreateLocalVideoTrack called with null VideoCapturer."; |
| 627 return NULL; | 631 return NULL; |
| 628 } | 632 } |
| 629 | 633 |
| 630 // Create video source from the |capturer|. | 634 // Create video source from the |capturer|. |
| 631 scoped_refptr<webrtc::VideoSourceInterface> source = | 635 scoped_refptr<webrtc::VideoSourceInterface> source = |
| 632 pc_factory_->CreateVideoSource(capturer, NULL).get(); | 636 pc_factory_->CreateVideoSource(capturer, NULL).get(); |
| 633 | 637 |
| 634 // Create native track from the source. | 638 // Create native track from the source. |
| 635 return pc_factory_->CreateVideoTrack(id, source).get(); | 639 return pc_factory_->CreateVideoTrack(id, source.get()).get(); |
| 636 } | 640 } |
| 637 | 641 |
| 638 scoped_refptr<webrtc::AudioTrackInterface> | 642 scoped_refptr<webrtc::AudioTrackInterface> |
| 639 MediaStreamDependencyFactory::CreateLocalAudioTrack( | 643 MediaStreamDependencyFactory::CreateLocalAudioTrack( |
| 640 const std::string& id, | 644 const std::string& id, |
| 641 webrtc::AudioSourceInterface* source) { | 645 webrtc::AudioSourceInterface* source) { |
| 642 // TODO(xians): Merge |source| to the capturer(). We can't do this today | 646 // TODO(xians): Merge |source| to the capturer(). We can't do this today |
| 643 // because only one capturer() is supported while one |source| is created | 647 // because only one capturer() is supported while one |source| is created |
| 644 // for each audio track. | 648 // for each audio track. |
| 645 return WebRtcLocalAudioTrack::Create(id, GetWebRtcAudioDevice()->capturer(), | 649 return WebRtcLocalAudioTrack::Create(id, GetWebRtcAudioDevice()->capturer(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 656 | 660 |
| 657 webrtc::IceCandidateInterface* MediaStreamDependencyFactory::CreateIceCandidate( | 661 webrtc::IceCandidateInterface* MediaStreamDependencyFactory::CreateIceCandidate( |
| 658 const std::string& sdp_mid, | 662 const std::string& sdp_mid, |
| 659 int sdp_mline_index, | 663 int sdp_mline_index, |
| 660 const std::string& sdp) { | 664 const std::string& sdp) { |
| 661 return webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, sdp); | 665 return webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, sdp); |
| 662 } | 666 } |
| 663 | 667 |
| 664 WebRtcAudioDeviceImpl* | 668 WebRtcAudioDeviceImpl* |
| 665 MediaStreamDependencyFactory::GetWebRtcAudioDevice() { | 669 MediaStreamDependencyFactory::GetWebRtcAudioDevice() { |
| 666 return audio_device_; | 670 return audio_device_.get(); |
| 667 } | 671 } |
| 668 | 672 |
| 669 void MediaStreamDependencyFactory::StopLocalAudioSource( | 673 void MediaStreamDependencyFactory::StopLocalAudioSource( |
| 670 const WebKit::WebMediaStream& description) { | 674 const WebKit::WebMediaStream& description) { |
| 671 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>( | 675 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>( |
| 672 description.extraData()); | 676 description.extraData()); |
| 673 if (extra_data && extra_data->is_local() && extra_data->stream() && | 677 if (extra_data && extra_data->is_local() && extra_data->stream().get() && |
| 674 !extra_data->stream()->GetAudioTracks().empty()) { | 678 !extra_data->stream()->GetAudioTracks().empty()) { |
| 675 if (GetWebRtcAudioDevice()) { | 679 if (GetWebRtcAudioDevice()) { |
| 676 scoped_refptr<WebRtcAudioCapturer> capturer = | 680 scoped_refptr<WebRtcAudioCapturer> capturer = |
| 677 GetWebRtcAudioDevice()->capturer(); | 681 GetWebRtcAudioDevice()->capturer(); |
| 678 if (capturer) | 682 if (capturer.get()) |
| 679 capturer->Stop(); | 683 capturer->Stop(); |
| 680 } | 684 } |
| 681 } | 685 } |
| 682 } | 686 } |
| 683 | 687 |
| 684 void MediaStreamDependencyFactory::InitializeWorkerThread( | 688 void MediaStreamDependencyFactory::InitializeWorkerThread( |
| 685 talk_base::Thread** thread, | 689 talk_base::Thread** thread, |
| 686 base::WaitableEvent* event) { | 690 base::WaitableEvent* event) { |
| 687 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); | 691 jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); |
| 688 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); | 692 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); |
| 689 *thread = jingle_glue::JingleThreadWrapper::current(); | 693 *thread = jingle_glue::JingleThreadWrapper::current(); |
| 690 event->Signal(); | 694 event->Signal(); |
| 691 } | 695 } |
| 692 | 696 |
| 693 void MediaStreamDependencyFactory::CreateIpcNetworkManagerOnWorkerThread( | 697 void MediaStreamDependencyFactory::CreateIpcNetworkManagerOnWorkerThread( |
| 694 base::WaitableEvent* event) { | 698 base::WaitableEvent* event) { |
| 695 DCHECK_EQ(base::MessageLoop::current(), chrome_worker_thread_.message_loop()); | 699 DCHECK_EQ(base::MessageLoop::current(), chrome_worker_thread_.message_loop()); |
| 696 network_manager_ = new IpcNetworkManager(p2p_socket_dispatcher_); | 700 network_manager_ = new IpcNetworkManager(p2p_socket_dispatcher_.get()); |
| 697 event->Signal(); | 701 event->Signal(); |
| 698 } | 702 } |
| 699 | 703 |
| 700 void MediaStreamDependencyFactory::DeleteIpcNetworkManager() { | 704 void MediaStreamDependencyFactory::DeleteIpcNetworkManager() { |
| 701 DCHECK_EQ(base::MessageLoop::current(), chrome_worker_thread_.message_loop()); | 705 DCHECK_EQ(base::MessageLoop::current(), chrome_worker_thread_.message_loop()); |
| 702 delete network_manager_; | 706 delete network_manager_; |
| 703 network_manager_ = NULL; | 707 network_manager_ = NULL; |
| 704 } | 708 } |
| 705 | 709 |
| 706 bool MediaStreamDependencyFactory::EnsurePeerConnectionFactory() { | 710 bool MediaStreamDependencyFactory::EnsurePeerConnectionFactory() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 737 base::WaitableEvent event(true, false); | 741 base::WaitableEvent event(true, false); |
| 738 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 742 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
| 739 &MediaStreamDependencyFactory::CreateIpcNetworkManagerOnWorkerThread, | 743 &MediaStreamDependencyFactory::CreateIpcNetworkManagerOnWorkerThread, |
| 740 base::Unretained(this), | 744 base::Unretained(this), |
| 741 &event)); | 745 &event)); |
| 742 event.Wait(); | 746 event.Wait(); |
| 743 } | 747 } |
| 744 | 748 |
| 745 if (!socket_factory_) { | 749 if (!socket_factory_) { |
| 746 socket_factory_.reset( | 750 socket_factory_.reset( |
| 747 new IpcPacketSocketFactory(p2p_socket_dispatcher_)); | 751 new IpcPacketSocketFactory(p2p_socket_dispatcher_.get())); |
| 748 } | 752 } |
| 749 | 753 |
| 750 // Init SSL, which will be needed by PeerConnection. | 754 // Init SSL, which will be needed by PeerConnection. |
| 751 #if defined(USE_OPENSSL) | 755 #if defined(USE_OPENSSL) |
| 752 if (!talk_base::InitializeSSL()) { | 756 if (!talk_base::InitializeSSL()) { |
| 753 LOG(ERROR) << "Failed on InitializeSSL."; | 757 LOG(ERROR) << "Failed on InitializeSSL."; |
| 754 return false; | 758 return false; |
| 755 } | 759 } |
| 756 #else | 760 #else |
| 757 // TODO(ronghuawu): Replace this call with InitializeSSL. | 761 // TODO(ronghuawu): Replace this call with InitializeSSL. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 778 // processed before returning. We wait for the above task to finish before | 782 // processed before returning. We wait for the above task to finish before |
| 779 // letting the the function continue to avoid any potential race issues. | 783 // letting the the function continue to avoid any potential race issues. |
| 780 chrome_worker_thread_.Stop(); | 784 chrome_worker_thread_.Stop(); |
| 781 } else { | 785 } else { |
| 782 NOTREACHED() << "Worker thread not running."; | 786 NOTREACHED() << "Worker thread not running."; |
| 783 } | 787 } |
| 784 } | 788 } |
| 785 } | 789 } |
| 786 | 790 |
| 787 } // namespace content | 791 } // namespace content |
| OLD | NEW |