Chromium Code Reviews| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 int max_requested_height, | 209 int max_requested_height, |
| 210 double max_requested_frame_rate, | 210 double max_requested_frame_rate, |
| 211 const VideoCaptureDeviceFormatsCB& callback) override; | 211 const VideoCaptureDeviceFormatsCB& callback) override; |
| 212 void StartCapture(const media::VideoCaptureParams& params, | 212 void StartCapture(const media::VideoCaptureParams& params, |
| 213 const VideoCaptureDeliverFrameCB& new_frame_callback, | 213 const VideoCaptureDeliverFrameCB& new_frame_callback, |
| 214 const RunningCallback& running_callback) override; | 214 const RunningCallback& running_callback) override; |
| 215 void RequestRefreshFrame() override; | 215 void RequestRefreshFrame() override; |
| 216 void MaybeSuspend() override; | 216 void MaybeSuspend() override; |
| 217 void Resume() override; | 217 void Resume() override; |
| 218 void StopCapture() override; | 218 void StopCapture() override; |
| 219 media::VideoFacingMode GetVideoFacing() const override; | |
| 219 | 220 |
| 220 private: | 221 private: |
| 221 void OnStateUpdate(VideoCaptureState state); | 222 void OnStateUpdate(VideoCaptureState state); |
| 222 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); | 223 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); |
| 223 void OnDeviceSupportedFormatsEnumerated( | 224 void OnDeviceSupportedFormatsEnumerated( |
| 224 const media::VideoCaptureFormats& formats); | 225 const media::VideoCaptureFormats& formats); |
| 225 | 226 |
| 226 // |session_id_| identifies the capture device used for this capture session. | 227 // |session_id_| identifies the capture device used for this capture session. |
| 227 const media::VideoCaptureSessionId session_id_; | 228 const media::VideoCaptureSessionId session_id_; |
| 228 | 229 |
| 230 const VideoFacingMode facing_; | |
| 231 | |
| 229 VideoCaptureImplManager* const manager_; | 232 VideoCaptureImplManager* const manager_; |
| 230 | 233 |
| 231 const base::Closure release_device_cb_; | 234 const base::Closure release_device_cb_; |
| 232 | 235 |
| 233 // Indicates if we are capturing generated content, e.g. Tab or Desktop. | 236 // Indicates if we are capturing generated content, e.g. Tab or Desktop. |
| 234 const bool is_content_capture_; | 237 const bool is_content_capture_; |
| 235 | 238 |
| 236 // These two are valid between StartCapture() and StopCapture(). | 239 // These two are valid between StartCapture() and StopCapture(). |
| 237 // |running_call_back_| is run when capture is successfully started, and when | 240 // |running_call_back_| is run when capture is successfully started, and when |
| 238 // it is stopped or error happens. | 241 // it is stopped or error happens. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 249 base::WeakPtrFactory<LocalVideoCapturerSource> weak_factory_; | 252 base::WeakPtrFactory<LocalVideoCapturerSource> weak_factory_; |
| 250 | 253 |
| 251 DISALLOW_COPY_AND_ASSIGN(LocalVideoCapturerSource); | 254 DISALLOW_COPY_AND_ASSIGN(LocalVideoCapturerSource); |
| 252 }; | 255 }; |
| 253 | 256 |
| 254 } // namespace | 257 } // namespace |
| 255 | 258 |
| 256 LocalVideoCapturerSource::LocalVideoCapturerSource( | 259 LocalVideoCapturerSource::LocalVideoCapturerSource( |
| 257 const StreamDeviceInfo& device_info) | 260 const StreamDeviceInfo& device_info) |
| 258 : session_id_(device_info.session_id), | 261 : session_id_(device_info.session_id), |
| 262 facing_(device_info.device.video_facing), | |
| 259 manager_(RenderThreadImpl::current()->video_capture_impl_manager()), | 263 manager_(RenderThreadImpl::current()->video_capture_impl_manager()), |
| 260 release_device_cb_(manager_->UseDevice(session_id_)), | 264 release_device_cb_(manager_->UseDevice(session_id_)), |
| 261 is_content_capture_(IsContentVideoCaptureDevice(device_info)), | 265 is_content_capture_(IsContentVideoCaptureDevice(device_info)), |
| 262 weak_factory_(this) { | 266 weak_factory_(this) { |
| 263 DCHECK(RenderThreadImpl::current()); | 267 DCHECK(RenderThreadImpl::current()); |
| 264 } | 268 } |
| 265 | 269 |
| 266 LocalVideoCapturerSource::~LocalVideoCapturerSource() { | 270 LocalVideoCapturerSource::~LocalVideoCapturerSource() { |
| 267 DCHECK(thread_checker_.CalledOnValidThread()); | 271 DCHECK(thread_checker_.CalledOnValidThread()); |
| 268 release_device_cb_.Run(); | 272 release_device_cb_.Run(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 DVLOG(3) << __func__; | 344 DVLOG(3) << __func__; |
| 341 DCHECK(thread_checker_.CalledOnValidThread()); | 345 DCHECK(thread_checker_.CalledOnValidThread()); |
| 342 // Immediately make sure we don't provide more frames. | 346 // Immediately make sure we don't provide more frames. |
| 343 if (!stop_capture_cb_.is_null()) | 347 if (!stop_capture_cb_.is_null()) |
| 344 base::ResetAndReturn(&stop_capture_cb_).Run(); | 348 base::ResetAndReturn(&stop_capture_cb_).Run(); |
| 345 running_callback_.Reset(); | 349 running_callback_.Reset(); |
| 346 // Invalidate any potential format enumerations going on. | 350 // Invalidate any potential format enumerations going on. |
| 347 formats_enumerated_callback_.Reset(); | 351 formats_enumerated_callback_.Reset(); |
| 348 } | 352 } |
| 349 | 353 |
| 354 media::VideoFacingMode LocalVideoCapturerSource::GetVideoFacing() const { | |
| 355 switch (facing_) { | |
|
mcasas
2017/01/11 22:24:58
I'd add here
if (is_content_capture_)
retur
shenghao
2017/01/12 08:10:48
Done.
| |
| 356 case VideoFacingMode::MEDIA_VIDEO_FACING_USER: | |
| 357 return media::VideoFacingMode::USER; | |
| 358 case VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT: | |
| 359 return media::VideoFacingMode::ENVIRONMENT; | |
| 360 case VideoFacingMode::MEDIA_VIDEO_FACING_NONE: | |
| 361 case VideoFacingMode::NUM_MEDIA_VIDEO_FACING_MODE: | |
| 362 return media::VideoFacingMode::USER; | |
| 363 } | |
| 364 return media::VideoFacingMode::USER; | |
| 365 } | |
| 366 | |
| 350 void LocalVideoCapturerSource::OnStateUpdate(VideoCaptureState state) { | 367 void LocalVideoCapturerSource::OnStateUpdate(VideoCaptureState state) { |
| 351 DVLOG(3) << __func__ << " state = " << state; | 368 DVLOG(3) << __func__ << " state = " << state; |
| 352 DCHECK(thread_checker_.CalledOnValidThread()); | 369 DCHECK(thread_checker_.CalledOnValidThread()); |
| 353 if (running_callback_.is_null()) | 370 if (running_callback_.is_null()) |
| 354 return; | 371 return; |
| 355 switch (state) { | 372 switch (state) { |
| 356 case VIDEO_CAPTURE_STATE_STARTED: | 373 case VIDEO_CAPTURE_STATE_STARTED: |
| 357 running_callback_.Run(true); | 374 running_callback_.Run(true); |
| 358 break; | 375 break; |
| 359 | 376 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 RenderFrame* render_frame) | 450 RenderFrame* render_frame) |
| 434 : RenderFrameObserver(render_frame), | 451 : RenderFrameObserver(render_frame), |
| 435 source_(new LocalVideoCapturerSource(device_info)) { | 452 source_(new LocalVideoCapturerSource(device_info)) { |
| 436 SetStopCallback(stop_callback); | 453 SetStopCallback(stop_callback); |
| 437 SetDeviceInfo(device_info); | 454 SetDeviceInfo(device_info); |
| 438 } | 455 } |
| 439 | 456 |
| 440 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { | 457 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { |
| 441 } | 458 } |
| 442 | 459 |
| 460 media::VideoFacingMode MediaStreamVideoCapturerSource::GetVideoFacing() { | |
| 461 return source_->GetVideoFacing(); | |
| 462 } | |
| 463 | |
| 443 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { | 464 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { |
| 444 source_->RequestRefreshFrame(); | 465 source_->RequestRefreshFrame(); |
| 445 } | 466 } |
| 446 | 467 |
| 447 void MediaStreamVideoCapturerSource::OnHasConsumers(bool has_consumers) { | 468 void MediaStreamVideoCapturerSource::OnHasConsumers(bool has_consumers) { |
| 448 if (has_consumers) | 469 if (has_consumers) |
| 449 source_->Resume(); | 470 source_->Resume(); |
| 450 else | 471 else |
| 451 source_->MaybeSuspend(); | 472 source_->MaybeSuspend(); |
| 452 } | 473 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 StopSource(); | 522 StopSource(); |
| 502 } | 523 } |
| 503 } | 524 } |
| 504 | 525 |
| 505 const char* | 526 const char* |
| 506 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { | 527 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { |
| 507 return kPowerLineFrequency; | 528 return kPowerLineFrequency; |
| 508 } | 529 } |
| 509 | 530 |
| 510 } // namespace content | 531 } // namespace content |
| OLD | NEW |