| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/webrtc/media_stream_video_webrtc_sink.h" | 5 #include "content/renderer/media/webrtc/media_stream_video_webrtc_sink.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "content/common/media/media_stream_options.h" | 12 #include "content/common/media/media_stream_options.h" |
| 13 #include "content/renderer/media/media_stream_constraints_util.h" |
| 13 #include "content/renderer/media/media_stream_video_track.h" | 14 #include "content/renderer/media/media_stream_video_track.h" |
| 14 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 15 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
| 15 | 16 |
| 16 namespace { | |
| 17 | |
| 18 bool ConstraintKeyExists(const blink::WebMediaConstraints& constraints, | |
| 19 const blink::WebString& name) { | |
| 20 blink::WebString value_str; | |
| 21 return constraints.getMandatoryConstraintValue(name, value_str) || | |
| 22 constraints.getOptionalConstraintValue(name, value_str); | |
| 23 } | |
| 24 | |
| 25 } // anonymouse namespace | |
| 26 | |
| 27 namespace content { | 17 namespace content { |
| 28 | 18 |
| 29 // Simple help class used for receiving video frames on the IO-thread from a | 19 // Simple help class used for receiving video frames on the IO-thread from a |
| 30 // MediaStreamVideoTrack and forward the frames to a WebRtcVideoCapturerAdapter | 20 // MediaStreamVideoTrack and forward the frames to a WebRtcVideoCapturerAdapter |
| 31 // on libjingle's worker thread. WebRtcVideoCapturerAdapter implements a video | 21 // on libjingle's worker thread. WebRtcVideoCapturerAdapter implements a video |
| 32 // capturer for libjingle. | 22 // capturer for libjingle. |
| 33 class MediaStreamVideoWebRtcSink::WebRtcVideoSourceAdapter | 23 class MediaStreamVideoWebRtcSink::WebRtcVideoSourceAdapter |
| 34 : public base::RefCountedThreadSafe<WebRtcVideoSourceAdapter> { | 24 : public base::RefCountedThreadSafe<WebRtcVideoSourceAdapter> { |
| 35 public: | 25 public: |
| 36 WebRtcVideoSourceAdapter( | 26 WebRtcVideoSourceAdapter( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 capture_adapter_->OnFrameCaptured(frame); | 121 capture_adapter_->OnFrameCaptured(frame); |
| 132 } | 122 } |
| 133 | 123 |
| 134 MediaStreamVideoWebRtcSink::MediaStreamVideoWebRtcSink( | 124 MediaStreamVideoWebRtcSink::MediaStreamVideoWebRtcSink( |
| 135 const blink::WebMediaStreamTrack& track, | 125 const blink::WebMediaStreamTrack& track, |
| 136 PeerConnectionDependencyFactory* factory) | 126 PeerConnectionDependencyFactory* factory) |
| 137 : web_track_(track) { | 127 : web_track_(track) { |
| 138 const blink::WebMediaConstraints& constraints = | 128 const blink::WebMediaConstraints& constraints = |
| 139 MediaStreamVideoTrack::GetVideoTrack(track)->constraints(); | 129 MediaStreamVideoTrack::GetVideoTrack(track)->constraints(); |
| 140 | 130 |
| 141 bool is_screencast = ConstraintKeyExists( | 131 // Check for presence of mediaStreamSource constraint. The value is ignored. |
| 142 constraints, base::UTF8ToUTF16(kMediaStreamSource)); | 132 std::string value; |
| 133 bool is_screencast = GetConstraintValueAsString( |
| 134 constraints, &blink::WebMediaTrackConstraintSet::mediaStreamSource, |
| 135 &value); |
| 143 WebRtcVideoCapturerAdapter* capture_adapter = | 136 WebRtcVideoCapturerAdapter* capture_adapter = |
| 144 factory->CreateVideoCapturer(is_screencast); | 137 factory->CreateVideoCapturer(is_screencast); |
| 145 | 138 |
| 146 // |video_source| owns |capture_adapter| | 139 // |video_source| owns |capture_adapter| |
| 147 scoped_refptr<webrtc::VideoTrackSourceInterface> video_source( | 140 scoped_refptr<webrtc::VideoTrackSourceInterface> video_source( |
| 148 factory->CreateVideoSource(capture_adapter, | 141 factory->CreateVideoSource(capture_adapter)); |
| 149 track.source().constraints())); | |
| 150 | 142 |
| 151 video_track_ = factory->CreateLocalVideoTrack(web_track_.id().utf8(), | 143 video_track_ = factory->CreateLocalVideoTrack(web_track_.id().utf8(), |
| 152 video_source.get()); | 144 video_source.get()); |
| 153 | 145 |
| 154 video_track_->set_enabled(web_track_.isEnabled()); | 146 video_track_->set_enabled(web_track_.isEnabled()); |
| 155 | 147 |
| 156 source_adapter_ = new WebRtcVideoSourceAdapter( | 148 source_adapter_ = new WebRtcVideoSourceAdapter( |
| 157 factory->GetWebRtcWorkerThread(), | 149 factory->GetWebRtcWorkerThread(), |
| 158 video_source, | 150 video_source, |
| 159 capture_adapter); | 151 capture_adapter); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 RemoveFromVideoTrack(this, web_track_); | 165 RemoveFromVideoTrack(this, web_track_); |
| 174 source_adapter_->ReleaseSourceOnMainThread(); | 166 source_adapter_->ReleaseSourceOnMainThread(); |
| 175 } | 167 } |
| 176 | 168 |
| 177 void MediaStreamVideoWebRtcSink::OnEnabledChanged(bool enabled) { | 169 void MediaStreamVideoWebRtcSink::OnEnabledChanged(bool enabled) { |
| 178 DCHECK(thread_checker_.CalledOnValidThread()); | 170 DCHECK(thread_checker_.CalledOnValidThread()); |
| 179 video_track_->set_enabled(enabled); | 171 video_track_->set_enabled(enabled); |
| 180 } | 172 } |
| 181 | 173 |
| 182 } // namespace content | 174 } // namespace content |
| OLD | NEW |