| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // VideoCaptureDelegate Implementation. | 204 // VideoCaptureDelegate Implementation. |
| 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 SetCapturingLinkSecured(bool is_secure) override; |
| 214 void StopCapture() override; | 215 void StopCapture() override; |
| 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 content::MediaStreamType stream_type_; |
| 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_type_(device_info.device.type), |
| 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(stream_type_, session_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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 SetDeviceInfo(device_info); | 413 SetDeviceInfo(device_info); |
| 406 } | 414 } |
| 407 | 415 |
| 408 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { | 416 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { |
| 409 } | 417 } |
| 410 | 418 |
| 411 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { | 419 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { |
| 412 source_->RequestRefreshFrame(); | 420 source_->RequestRefreshFrame(); |
| 413 } | 421 } |
| 414 | 422 |
| 423 void MediaStreamVideoCapturerSource::SetCapturingLinkSecured(bool is_secure) { |
| 424 source_->SetCapturingLinkSecured(is_secure); |
| 425 } |
| 426 |
| 415 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( | 427 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( |
| 416 int max_requested_width, | 428 int max_requested_width, |
| 417 int max_requested_height, | 429 int max_requested_height, |
| 418 double max_requested_frame_rate, | 430 double max_requested_frame_rate, |
| 419 const VideoCaptureDeviceFormatsCB& callback) { | 431 const VideoCaptureDeviceFormatsCB& callback) { |
| 420 source_->GetCurrentSupportedFormats( | 432 source_->GetCurrentSupportedFormats( |
| 421 max_requested_width, | 433 max_requested_width, |
| 422 max_requested_height, | 434 max_requested_height, |
| 423 max_requested_frame_rate, | 435 max_requested_frame_rate, |
| 424 callback); | 436 callback); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 450 void MediaStreamVideoCapturerSource::OnStarted(bool result) { | 462 void MediaStreamVideoCapturerSource::OnStarted(bool result) { |
| 451 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE); | 463 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE); |
| 452 } | 464 } |
| 453 | 465 |
| 454 const char* | 466 const char* |
| 455 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { | 467 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { |
| 456 return kPowerLineFrequency; | 468 return kPowerLineFrequency; |
| 457 } | 469 } |
| 458 | 470 |
| 459 } // namespace content | 471 } // namespace content |
| OLD | NEW |