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::mojom::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_; | |
jochen (gone - plz use gerrit)
2017/01/12 11:54:42
why not use media::mojom::VideoFacingMode ?
shenghao
2017/01/13 11:09:34
deleted
| |
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), | |
hta - Chromium
2017/01/12 19:36:41
Why are you making a copy of this information?
shenghao
2017/01/13 11:09:34
deleted
| |
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::mojom::VideoFacingMode LocalVideoCapturerSource::GetVideoFacing() const { | |
355 if (is_content_capture_) | |
356 return media::mojom::VideoFacingMode::NONE; | |
357 | |
358 switch (facing_) { | |
359 case VideoFacingMode::MEDIA_VIDEO_FACING_USER: | |
360 return media::mojom::VideoFacingMode::USER; | |
361 case VideoFacingMode::MEDIA_VIDEO_FACING_ENVIRONMENT: | |
362 return media::mojom::VideoFacingMode::ENVIRONMENT; | |
363 case VideoFacingMode::MEDIA_VIDEO_FACING_NONE: | |
364 case VideoFacingMode::NUM_MEDIA_VIDEO_FACING_MODE: | |
365 return media::mojom::VideoFacingMode::USER; | |
366 } | |
367 return media::mojom::VideoFacingMode::USER; | |
368 } | |
369 | |
350 void LocalVideoCapturerSource::OnStateUpdate(VideoCaptureState state) { | 370 void LocalVideoCapturerSource::OnStateUpdate(VideoCaptureState state) { |
351 DVLOG(3) << __func__ << " state = " << state; | 371 DVLOG(3) << __func__ << " state = " << state; |
352 DCHECK(thread_checker_.CalledOnValidThread()); | 372 DCHECK(thread_checker_.CalledOnValidThread()); |
353 if (running_callback_.is_null()) | 373 if (running_callback_.is_null()) |
354 return; | 374 return; |
355 switch (state) { | 375 switch (state) { |
356 case VIDEO_CAPTURE_STATE_STARTED: | 376 case VIDEO_CAPTURE_STATE_STARTED: |
357 running_callback_.Run(true); | 377 running_callback_.Run(true); |
358 break; | 378 break; |
359 | 379 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 RenderFrame* render_frame) | 453 RenderFrame* render_frame) |
434 : RenderFrameObserver(render_frame), | 454 : RenderFrameObserver(render_frame), |
435 source_(new LocalVideoCapturerSource(device_info)) { | 455 source_(new LocalVideoCapturerSource(device_info)) { |
436 SetStopCallback(stop_callback); | 456 SetStopCallback(stop_callback); |
437 SetDeviceInfo(device_info); | 457 SetDeviceInfo(device_info); |
438 } | 458 } |
439 | 459 |
440 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { | 460 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { |
441 } | 461 } |
442 | 462 |
463 media::mojom::VideoFacingMode MediaStreamVideoCapturerSource::GetVideoFacing() { | |
464 return source_->GetVideoFacing(); | |
465 } | |
466 | |
443 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { | 467 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { |
444 source_->RequestRefreshFrame(); | 468 source_->RequestRefreshFrame(); |
445 } | 469 } |
446 | 470 |
447 void MediaStreamVideoCapturerSource::OnHasConsumers(bool has_consumers) { | 471 void MediaStreamVideoCapturerSource::OnHasConsumers(bool has_consumers) { |
448 if (has_consumers) | 472 if (has_consumers) |
449 source_->Resume(); | 473 source_->Resume(); |
450 else | 474 else |
451 source_->MaybeSuspend(); | 475 source_->MaybeSuspend(); |
452 } | 476 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 StopSource(); | 525 StopSource(); |
502 } | 526 } |
503 } | 527 } |
504 | 528 |
505 const char* | 529 const char* |
506 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { | 530 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { |
507 return kPowerLineFrequency; | 531 return kPowerLineFrequency; |
508 } | 532 } |
509 | 533 |
510 } // namespace content | 534 } // namespace content |
OLD | NEW |