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 23 matching lines...) Expand all Loading... |
34 #endif | 34 #endif |
35 | 35 |
36 namespace content { | 36 namespace content { |
37 | 37 |
38 // Constant constraint keys which disables all audio constraints. | 38 // Constant constraint keys which disables all audio constraints. |
39 // Only used in combination with WebAudio sources. | 39 // Only used in combination with WebAudio sources. |
40 struct { | 40 struct { |
41 const char* key; | 41 const char* key; |
42 const char* value; | 42 const char* value; |
43 } const kWebAudioConstraints[] = { | 43 } const kWebAudioConstraints[] = { |
44 {webrtc::MediaConstraintsInterface::kEchoCancellation, | 44 {webrtc::MediaConstraintsInterface::kEchoCancellation, |
45 webrtc::MediaConstraintsInterface::kValueFalse}, | 45 webrtc::MediaConstraintsInterface::kValueFalse}, |
46 {webrtc::MediaConstraintsInterface::kAutoGainControl, | 46 {webrtc::MediaConstraintsInterface::kAutoGainControl, |
47 webrtc::MediaConstraintsInterface::kValueFalse}, | 47 webrtc::MediaConstraintsInterface::kValueFalse}, |
48 {webrtc::MediaConstraintsInterface::kNoiseSuppression, | 48 {webrtc::MediaConstraintsInterface::kNoiseSuppression, |
49 webrtc::MediaConstraintsInterface::kValueFalse}, | 49 webrtc::MediaConstraintsInterface::kValueFalse}, |
50 {webrtc::MediaConstraintsInterface::kHighpassFilter, | 50 {webrtc::MediaConstraintsInterface::kHighpassFilter, |
51 webrtc::MediaConstraintsInterface::kValueFalse}, | 51 webrtc::MediaConstraintsInterface::kValueFalse}, |
52 }; | 52 }; |
53 | 53 |
54 class WebAudioConstraints : public RTCMediaConstraints { | 54 class WebAudioConstraints : public RTCMediaConstraints { |
55 public: | 55 public: |
56 WebAudioConstraints() | 56 WebAudioConstraints() |
57 : RTCMediaConstraints(WebKit::WebMediaConstraints()) { | 57 : RTCMediaConstraints(WebKit::WebMediaConstraints()) { |
58 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWebAudioConstraints); ++i) { | 58 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWebAudioConstraints); ++i) { |
59 webrtc::MediaConstraintsInterface::Constraint constraint; | 59 webrtc::MediaConstraintsInterface::Constraint constraint; |
60 constraint.key = kWebAudioConstraints[i].key; | 60 constraint.key = kWebAudioConstraints[i].key; |
61 constraint.value = kWebAudioConstraints[i].value; | 61 constraint.value = kWebAudioConstraints[i].value; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 } | 395 } |
396 return native_stream->AddTrack(audio_track); | 396 return native_stream->AddTrack(audio_track); |
397 } else { | 397 } else { |
398 scoped_refptr<webrtc::VideoTrackInterface> video_track( | 398 scoped_refptr<webrtc::VideoTrackInterface> video_track( |
399 CreateLocalVideoTrack(track_id, source_data->video_source())); | 399 CreateLocalVideoTrack(track_id, source_data->video_source())); |
400 video_track->set_enabled(track.isEnabled()); | 400 video_track->set_enabled(track.isEnabled()); |
401 return native_stream->AddTrack(video_track); | 401 return native_stream->AddTrack(video_track); |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
| 405 bool MediaStreamDependencyFactory::AddNativeVideoMediaTrack( |
| 406 const std::string& track_id, |
| 407 WebKit::WebMediaStream* stream, |
| 408 cricket::VideoCapturer* capturer) { |
| 409 if (!stream) { |
| 410 LOG(ERROR) << "AddNativeVideoMediaTrack called with null WebMediaStream."; |
| 411 return false; |
| 412 } |
| 413 |
| 414 // Create native track from the source. |
| 415 scoped_refptr<webrtc::VideoTrackInterface> native_track = |
| 416 CreateLocalVideoTrack(track_id, capturer); |
| 417 |
| 418 // Add the native track to native stream |
| 419 MediaStreamExtraData* extra_data = |
| 420 static_cast<MediaStreamExtraData*>(stream->extraData()); |
| 421 DCHECK(extra_data); |
| 422 webrtc::MediaStreamInterface* native_stream = extra_data->stream(); |
| 423 native_stream->AddTrack(native_track); |
| 424 |
| 425 // Create a new webkit video track. |
| 426 WebKit::WebMediaStreamTrack webkit_track; |
| 427 WebKit::WebMediaStreamSource webkit_source; |
| 428 WebKit::WebString webkit_track_id(UTF8ToUTF16(track_id)); |
| 429 WebKit::WebMediaStreamSource::Type type = |
| 430 WebKit::WebMediaStreamSource::TypeVideo; |
| 431 webkit_source.initialize(webkit_track_id, type, webkit_track_id); |
| 432 webkit_track.initialize(webkit_track_id, webkit_source); |
| 433 |
| 434 // Add the track to WebMediaStream. |
| 435 stream->addTrack(webkit_track); |
| 436 return true; |
| 437 } |
| 438 |
405 bool MediaStreamDependencyFactory::RemoveNativeMediaStreamTrack( | 439 bool MediaStreamDependencyFactory::RemoveNativeMediaStreamTrack( |
406 const WebKit::WebMediaStream& stream, | 440 const WebKit::WebMediaStream& stream, |
407 const WebKit::WebMediaStreamTrack& track) { | 441 const WebKit::WebMediaStreamTrack& track) { |
408 MediaStreamExtraData* extra_data = | 442 MediaStreamExtraData* extra_data = |
409 static_cast<MediaStreamExtraData*>(stream.extraData()); | 443 static_cast<MediaStreamExtraData*>(stream.extraData()); |
410 webrtc::MediaStreamInterface* native_stream = extra_data->stream(); | 444 webrtc::MediaStreamInterface* native_stream = extra_data->stream(); |
411 DCHECK(native_stream); | 445 DCHECK(native_stream); |
412 | 446 |
413 WebKit::WebMediaStreamSource::Type type = track.source().type(); | 447 WebKit::WebMediaStreamSource::Type type = track.source().type(); |
414 DCHECK(type == WebKit::WebMediaStreamSource::TypeAudio || | 448 DCHECK(type == WebKit::WebMediaStreamSource::TypeAudio || |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 return true; | 581 return true; |
548 } | 582 } |
549 | 583 |
550 scoped_refptr<webrtc::VideoTrackInterface> | 584 scoped_refptr<webrtc::VideoTrackInterface> |
551 MediaStreamDependencyFactory::CreateLocalVideoTrack( | 585 MediaStreamDependencyFactory::CreateLocalVideoTrack( |
552 const std::string& id, | 586 const std::string& id, |
553 webrtc::VideoSourceInterface* source) { | 587 webrtc::VideoSourceInterface* source) { |
554 return pc_factory_->CreateVideoTrack(id, source).get(); | 588 return pc_factory_->CreateVideoTrack(id, source).get(); |
555 } | 589 } |
556 | 590 |
| 591 scoped_refptr<webrtc::VideoTrackInterface> |
| 592 MediaStreamDependencyFactory::CreateLocalVideoTrack( |
| 593 const std::string& id, cricket::VideoCapturer* capturer) { |
| 594 if (!capturer) { |
| 595 LOG(ERROR) << "CreateLocalVideoTrack called with null VideoCapturer."; |
| 596 return NULL; |
| 597 } |
| 598 |
| 599 // Create video source from the |capturer|. |
| 600 scoped_refptr<webrtc::VideoSourceInterface> source = |
| 601 pc_factory_->CreateVideoSource(capturer, NULL).get(); |
| 602 |
| 603 // Create native track from the source. |
| 604 return pc_factory_->CreateVideoTrack(id, source).get(); |
| 605 } |
| 606 |
557 scoped_refptr<webrtc::AudioTrackInterface> | 607 scoped_refptr<webrtc::AudioTrackInterface> |
558 MediaStreamDependencyFactory::CreateLocalAudioTrack( | 608 MediaStreamDependencyFactory::CreateLocalAudioTrack( |
559 const std::string& id, | 609 const std::string& id, |
560 webrtc::AudioSourceInterface* source) { | 610 webrtc::AudioSourceInterface* source) { |
561 // TODO(xians): Merge |source| to the capturer(). We can't do this today | 611 // TODO(xians): Merge |source| to the capturer(). We can't do this today |
562 // because only one capturer() is supported while one |source| is created | 612 // because only one capturer() is supported while one |source| is created |
563 // for each audio track. | 613 // for each audio track. |
564 return WebRtcLocalAudioTrack::Create(id, GetWebRtcAudioDevice()->capturer(), | 614 return WebRtcLocalAudioTrack::Create(id, GetWebRtcAudioDevice()->capturer(), |
565 source); | 615 source); |
566 } | 616 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 // processed before returning. We wait for the above task to finish before | 747 // processed before returning. We wait for the above task to finish before |
698 // letting the the function continue to avoid any potential race issues. | 748 // letting the the function continue to avoid any potential race issues. |
699 chrome_worker_thread_.Stop(); | 749 chrome_worker_thread_.Stop(); |
700 } else { | 750 } else { |
701 NOTREACHED() << "Worker thread not running."; | 751 NOTREACHED() << "Worker thread not running."; |
702 } | 752 } |
703 } | 753 } |
704 } | 754 } |
705 | 755 |
706 } // namespace content | 756 } // namespace content |
OLD | NEW |