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/media_stream_video_capturer_source.h" | 5 #include "content/renderer/media/media_stream_video_capturer_source.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 void GetCurrentSupportedFormats( | 205 void GetCurrentSupportedFormats( |
206 int max_requested_width, | 206 int max_requested_width, |
207 int max_requested_height, | 207 int max_requested_height, |
208 double max_requested_frame_rate, | 208 double max_requested_frame_rate, |
209 const VideoCaptureDeviceFormatsCB& callback) override; | 209 const VideoCaptureDeviceFormatsCB& callback) override; |
210 void StartCapture(const media::VideoCaptureParams& params, | 210 void StartCapture(const media::VideoCaptureParams& params, |
211 const VideoCaptureDeliverFrameCB& new_frame_callback, | 211 const VideoCaptureDeliverFrameCB& new_frame_callback, |
212 const RunningCallback& running_callback) override; | 212 const RunningCallback& running_callback) override; |
213 void RequestRefreshFrame() override; | 213 void RequestRefreshFrame() override; |
214 void StopCapture() override; | 214 void StopCapture() override; |
| 215 void SetCapturingLinkSecured(bool is_secure); |
215 | 216 |
216 private: | 217 private: |
217 void OnStateUpdate(VideoCaptureState state); | 218 void OnStateUpdate(VideoCaptureState state); |
218 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); | 219 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); |
219 void OnDeviceSupportedFormatsEnumerated( | 220 void OnDeviceSupportedFormatsEnumerated( |
220 const media::VideoCaptureFormats& formats); | 221 const media::VideoCaptureFormats& formats); |
221 | 222 |
222 // |session_id_| identifies the capture device used for this capture session. | 223 // |session_id_| identifies the capture device used for this capture session. |
223 const media::VideoCaptureSessionId session_id_; | 224 const media::VideoCaptureSessionId session_id_; |
224 | 225 |
| 226 const std::string stream_device_id_; |
| 227 |
225 VideoCaptureImplManager* const manager_; | 228 VideoCaptureImplManager* const manager_; |
226 | 229 |
227 const base::Closure release_device_cb_; | 230 const base::Closure release_device_cb_; |
228 | 231 |
229 // Indicates if we are capturing generated content, e.g. Tab or Desktop. | 232 // Indicates if we are capturing generated content, e.g. Tab or Desktop. |
230 const bool is_content_capture_; | 233 const bool is_content_capture_; |
231 | 234 |
232 // These two are valid between StartCapture() and StopCapture(). | 235 // These two are valid between StartCapture() and StopCapture(). |
233 base::Closure stop_capture_cb_; | 236 base::Closure stop_capture_cb_; |
234 RunningCallback running_callback_; | 237 RunningCallback running_callback_; |
235 | 238 |
236 // Placeholder keeping the callback between asynchronous device enumeration | 239 // Placeholder keeping the callback between asynchronous device enumeration |
237 // calls. | 240 // calls. |
238 VideoCaptureDeviceFormatsCB formats_enumerated_callback_; | 241 VideoCaptureDeviceFormatsCB formats_enumerated_callback_; |
239 | 242 |
240 // Bound to the main render thread. | 243 // Bound to the main render thread. |
241 base::ThreadChecker thread_checker_; | 244 base::ThreadChecker thread_checker_; |
242 | 245 |
243 base::WeakPtrFactory<LocalVideoCapturerSource> weak_factory_; | 246 base::WeakPtrFactory<LocalVideoCapturerSource> weak_factory_; |
244 | 247 |
245 DISALLOW_COPY_AND_ASSIGN(LocalVideoCapturerSource); | 248 DISALLOW_COPY_AND_ASSIGN(LocalVideoCapturerSource); |
246 }; | 249 }; |
247 | 250 |
248 } // namespace | 251 } // namespace |
249 | 252 |
250 LocalVideoCapturerSource::LocalVideoCapturerSource( | 253 LocalVideoCapturerSource::LocalVideoCapturerSource( |
251 const StreamDeviceInfo& device_info) | 254 const StreamDeviceInfo& device_info) |
252 : session_id_(device_info.session_id), | 255 : session_id_(device_info.session_id), |
| 256 stream_device_id_(device_info.device.id), |
253 manager_(RenderThreadImpl::current()->video_capture_impl_manager()), | 257 manager_(RenderThreadImpl::current()->video_capture_impl_manager()), |
254 release_device_cb_(manager_->UseDevice(session_id_)), | 258 release_device_cb_(manager_->UseDevice(session_id_)), |
255 is_content_capture_(IsContentVideoCaptureDevice(device_info)), | 259 is_content_capture_(IsContentVideoCaptureDevice(device_info)), |
256 weak_factory_(this) { | 260 weak_factory_(this) { |
257 DCHECK(RenderThreadImpl::current()); | 261 DCHECK(RenderThreadImpl::current()); |
258 } | 262 } |
259 | 263 |
260 LocalVideoCapturerSource::~LocalVideoCapturerSource() { | 264 LocalVideoCapturerSource::~LocalVideoCapturerSource() { |
261 DCHECK(thread_checker_.CalledOnValidThread()); | 265 DCHECK(thread_checker_.CalledOnValidThread()); |
262 release_device_cb_.Run(); | 266 release_device_cb_.Run(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 315 } |
312 | 316 |
313 void LocalVideoCapturerSource::RequestRefreshFrame() { | 317 void LocalVideoCapturerSource::RequestRefreshFrame() { |
314 DVLOG(3) << __FUNCTION__; | 318 DVLOG(3) << __FUNCTION__; |
315 DCHECK(thread_checker_.CalledOnValidThread()); | 319 DCHECK(thread_checker_.CalledOnValidThread()); |
316 if (stop_capture_cb_.is_null()) | 320 if (stop_capture_cb_.is_null()) |
317 return; // Do not request frames if the source is stopped. | 321 return; // Do not request frames if the source is stopped. |
318 manager_->RequestRefreshFrame(session_id_); | 322 manager_->RequestRefreshFrame(session_id_); |
319 } | 323 } |
320 | 324 |
| 325 void LocalVideoCapturerSource::SetCapturingLinkSecured(bool is_secure) { |
| 326 DCHECK(thread_checker_.CalledOnValidThread()); |
| 327 manager_->SetCapturingLinkSecured(session_id_, stream_device_id_, is_secure); |
| 328 } |
321 | 329 |
322 void LocalVideoCapturerSource::StopCapture() { | 330 void LocalVideoCapturerSource::StopCapture() { |
323 DVLOG(3) << __FUNCTION__; | 331 DVLOG(3) << __FUNCTION__; |
324 DCHECK(thread_checker_.CalledOnValidThread()); | 332 DCHECK(thread_checker_.CalledOnValidThread()); |
325 // Immediately make sure we don't provide more frames. | 333 // Immediately make sure we don't provide more frames. |
326 if (!stop_capture_cb_.is_null()) | 334 if (!stop_capture_cb_.is_null()) |
327 base::ResetAndReturn(&stop_capture_cb_).Run(); | 335 base::ResetAndReturn(&stop_capture_cb_).Run(); |
328 running_callback_.Reset(); | 336 running_callback_.Reset(); |
329 // Invalidate any potential format enumerations going on. | 337 // Invalidate any potential format enumerations going on. |
330 formats_enumerated_callback_.Reset(); | 338 formats_enumerated_callback_.Reset(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 gfx::Size(resolution.width, resolution.height), frame_rate, | 394 gfx::Size(resolution.width, resolution.height), frame_rate, |
387 media::PIXEL_FORMAT_I420)); | 395 media::PIXEL_FORMAT_I420)); |
388 } | 396 } |
389 } | 397 } |
390 base::ResetAndReturn(&formats_enumerated_callback_).Run(default_formats); | 398 base::ResetAndReturn(&formats_enumerated_callback_).Run(default_formats); |
391 } | 399 } |
392 | 400 |
393 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( | 401 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( |
394 const SourceStoppedCallback& stop_callback, | 402 const SourceStoppedCallback& stop_callback, |
395 std::unique_ptr<media::VideoCapturerSource> source) | 403 std::unique_ptr<media::VideoCapturerSource> source) |
396 : source_(std::move(source)) { | 404 : source_(std::move(source)), is_local_video_capturer_source_(false) { |
397 SetStopCallback(stop_callback); | 405 SetStopCallback(stop_callback); |
398 } | 406 } |
399 | 407 |
400 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( | 408 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( |
401 const SourceStoppedCallback& stop_callback, | 409 const SourceStoppedCallback& stop_callback, |
402 const StreamDeviceInfo& device_info) | 410 const StreamDeviceInfo& device_info) |
403 : source_(new LocalVideoCapturerSource(device_info)) { | 411 : source_(new LocalVideoCapturerSource(device_info)), |
| 412 is_local_video_capturer_source_(true) { |
404 SetStopCallback(stop_callback); | 413 SetStopCallback(stop_callback); |
405 SetDeviceInfo(device_info); | 414 SetDeviceInfo(device_info); |
406 } | 415 } |
407 | 416 |
408 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { | 417 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { |
409 } | 418 } |
410 | 419 |
411 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { | 420 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { |
412 source_->RequestRefreshFrame(); | 421 source_->RequestRefreshFrame(); |
413 } | 422 } |
414 | 423 |
| 424 void MediaStreamVideoCapturerSource::SetCapturingLinkSecured(bool is_secure) { |
| 425 if (source_ && is_local_video_capturer_source_) |
| 426 static_cast<LocalVideoCapturerSource*>(source_.get()) |
| 427 ->SetCapturingLinkSecured(is_secure); |
| 428 } |
| 429 |
415 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( | 430 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( |
416 int max_requested_width, | 431 int max_requested_width, |
417 int max_requested_height, | 432 int max_requested_height, |
418 double max_requested_frame_rate, | 433 double max_requested_frame_rate, |
419 const VideoCaptureDeviceFormatsCB& callback) { | 434 const VideoCaptureDeviceFormatsCB& callback) { |
420 source_->GetCurrentSupportedFormats( | 435 source_->GetCurrentSupportedFormats( |
421 max_requested_width, | 436 max_requested_width, |
422 max_requested_height, | 437 max_requested_height, |
423 max_requested_frame_rate, | 438 max_requested_frame_rate, |
424 callback); | 439 callback); |
(...skipping 25 matching lines...) Expand all Loading... |
450 void MediaStreamVideoCapturerSource::OnStarted(bool result) { | 465 void MediaStreamVideoCapturerSource::OnStarted(bool result) { |
451 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE); | 466 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE); |
452 } | 467 } |
453 | 468 |
454 const char* | 469 const char* |
455 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { | 470 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { |
456 return kPowerLineFrequency; | 471 return kPowerLineFrequency; |
457 } | 472 } |
458 | 473 |
459 } // namespace content | 474 } // namespace content |
OLD | NEW |