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" |
| 11 #include "base/debug/stack_trace.h" |
11 #include "base/location.h" | 12 #include "base/location.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "content/common/media/media_stream_messages.h" | 15 #include "content/common/media/media_stream_messages.h" |
15 #include "content/public/common/media_stream_request.h" | 16 #include "content/public/common/media_stream_request.h" |
16 #include "content/renderer/media/media_stream_constraints_util.h" | 17 #include "content/renderer/media/media_stream_constraints_util.h" |
17 #include "content/renderer/media/video_capture_impl_manager.h" | 18 #include "content/renderer/media/video_capture_impl_manager.h" |
18 #include "content/renderer/render_thread_impl.h" | 19 #include "content/renderer/render_thread_impl.h" |
19 #include "media/base/bind_to_current_loop.h" | 20 #include "media/base/bind_to_current_loop.h" |
20 #include "media/base/limits.h" | 21 #include "media/base/limits.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // VideoCaptureDelegate Implementation. | 206 // VideoCaptureDelegate Implementation. |
206 void GetCurrentSupportedFormats( | 207 void GetCurrentSupportedFormats( |
207 int max_requested_width, | 208 int max_requested_width, |
208 int max_requested_height, | 209 int max_requested_height, |
209 double max_requested_frame_rate, | 210 double max_requested_frame_rate, |
210 const VideoCaptureDeviceFormatsCB& callback) override; | 211 const VideoCaptureDeviceFormatsCB& callback) override; |
211 void StartCapture(const media::VideoCaptureParams& params, | 212 void StartCapture(const media::VideoCaptureParams& params, |
212 const VideoCaptureDeliverFrameCB& new_frame_callback, | 213 const VideoCaptureDeliverFrameCB& new_frame_callback, |
213 const RunningCallback& running_callback) override; | 214 const RunningCallback& running_callback) override; |
214 void RequestRefreshFrame() override; | 215 void RequestRefreshFrame() override; |
| 216 void MaybeSuspend() override; |
| 217 void Resume() override; |
215 void StopCapture() override; | 218 void StopCapture() override; |
216 | 219 |
217 private: | 220 private: |
218 void OnStateUpdate(VideoCaptureState state); | 221 void OnStateUpdate(VideoCaptureState state); |
219 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); | 222 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); |
220 void OnDeviceSupportedFormatsEnumerated( | 223 void OnDeviceSupportedFormatsEnumerated( |
221 const media::VideoCaptureFormats& formats); | 224 const media::VideoCaptureFormats& formats); |
222 | 225 |
223 // |session_id_| identifies the capture device used for this capture session. | 226 // |session_id_| identifies the capture device used for this capture session. |
224 const media::VideoCaptureSessionId session_id_; | 227 const media::VideoCaptureSessionId session_id_; |
225 | 228 |
226 VideoCaptureImplManager* const manager_; | 229 VideoCaptureImplManager* const manager_; |
227 | 230 |
228 const base::Closure release_device_cb_; | 231 const base::Closure release_device_cb_; |
229 | 232 |
230 // Indicates if we are capturing generated content, e.g. Tab or Desktop. | 233 // Indicates if we are capturing generated content, e.g. Tab or Desktop. |
231 const bool is_content_capture_; | 234 const bool is_content_capture_; |
232 | 235 |
233 // These two are valid between StartCapture() and StopCapture(). | 236 // This is run once to report whether the device was successfully started |
| 237 // after a call to StartCapture(). |
| 238 RunningCallback running_callback_; |
| 239 |
| 240 // This is valid between StartCapture() and StopCapture(). |
234 base::Closure stop_capture_cb_; | 241 base::Closure stop_capture_cb_; |
235 RunningCallback running_callback_; | |
236 | 242 |
237 // Placeholder keeping the callback between asynchronous device enumeration | 243 // Placeholder keeping the callback between asynchronous device enumeration |
238 // calls. | 244 // calls. |
239 VideoCaptureDeviceFormatsCB formats_enumerated_callback_; | 245 VideoCaptureDeviceFormatsCB formats_enumerated_callback_; |
240 | 246 |
241 // Bound to the main render thread. | 247 // Bound to the main render thread. |
242 base::ThreadChecker thread_checker_; | 248 base::ThreadChecker thread_checker_; |
243 | 249 |
244 base::WeakPtrFactory<LocalVideoCapturerSource> weak_factory_; | 250 base::WeakPtrFactory<LocalVideoCapturerSource> weak_factory_; |
245 | 251 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 318 } |
313 | 319 |
314 void LocalVideoCapturerSource::RequestRefreshFrame() { | 320 void LocalVideoCapturerSource::RequestRefreshFrame() { |
315 DVLOG(3) << __func__; | 321 DVLOG(3) << __func__; |
316 DCHECK(thread_checker_.CalledOnValidThread()); | 322 DCHECK(thread_checker_.CalledOnValidThread()); |
317 if (stop_capture_cb_.is_null()) | 323 if (stop_capture_cb_.is_null()) |
318 return; // Do not request frames if the source is stopped. | 324 return; // Do not request frames if the source is stopped. |
319 manager_->RequestRefreshFrame(session_id_); | 325 manager_->RequestRefreshFrame(session_id_); |
320 } | 326 } |
321 | 327 |
| 328 void LocalVideoCapturerSource::MaybeSuspend() { |
| 329 DVLOG(3) << __func__; |
| 330 DCHECK(thread_checker_.CalledOnValidThread()); |
| 331 manager_->Suspend(session_id_); |
| 332 } |
| 333 |
| 334 void LocalVideoCapturerSource::Resume() { |
| 335 DVLOG(3) << __func__; |
| 336 DCHECK(thread_checker_.CalledOnValidThread()); |
| 337 manager_->Resume(session_id_); |
| 338 } |
| 339 |
322 void LocalVideoCapturerSource::StopCapture() { | 340 void LocalVideoCapturerSource::StopCapture() { |
323 DVLOG(3) << __func__; | 341 DVLOG(3) << __func__; |
324 DCHECK(thread_checker_.CalledOnValidThread()); | 342 DCHECK(thread_checker_.CalledOnValidThread()); |
325 // Immediately make sure we don't provide more frames. | 343 // Immediately make sure we don't provide more frames. |
326 if (!stop_capture_cb_.is_null()) | 344 if (!stop_capture_cb_.is_null()) |
327 base::ResetAndReturn(&stop_capture_cb_).Run(); | 345 base::ResetAndReturn(&stop_capture_cb_).Run(); |
328 running_callback_.Reset(); | 346 running_callback_.Reset(); |
329 // Invalidate any potential format enumerations going on. | 347 // Invalidate any potential format enumerations going on. |
330 formats_enumerated_callback_.Reset(); | 348 formats_enumerated_callback_.Reset(); |
331 } | 349 } |
332 | 350 |
333 void LocalVideoCapturerSource::OnStateUpdate(VideoCaptureState state) { | 351 void LocalVideoCapturerSource::OnStateUpdate(VideoCaptureState state) { |
334 DVLOG(3) << __func__ << " state = " << state; | 352 DVLOG(3) << __func__ << " state = " << state; |
335 DCHECK(thread_checker_.CalledOnValidThread()); | 353 DCHECK(thread_checker_.CalledOnValidThread()); |
336 if (running_callback_.is_null()) | 354 if (running_callback_.is_null()) |
337 return; | 355 return; |
338 const bool is_started_ok = state == VIDEO_CAPTURE_STATE_STARTED; | 356 switch (state) { |
339 running_callback_.Run(is_started_ok); | 357 case VIDEO_CAPTURE_STATE_STARTED: |
340 if (!is_started_ok) | 358 base::ResetAndReturn(&running_callback_).Run(true); |
341 running_callback_.Reset(); | 359 break; |
| 360 |
| 361 case VIDEO_CAPTURE_STATE_STOPPING: |
| 362 case VIDEO_CAPTURE_STATE_STOPPED: |
| 363 case VIDEO_CAPTURE_STATE_ERROR: |
| 364 case VIDEO_CAPTURE_STATE_ENDED: |
| 365 base::ResetAndReturn(&running_callback_).Run(false); |
| 366 break; |
| 367 |
| 368 case VIDEO_CAPTURE_STATE_STARTING: |
| 369 case VIDEO_CAPTURE_STATE_PAUSED: |
| 370 case VIDEO_CAPTURE_STATE_RESUMED: |
| 371 // Not applicable to reporting on device start success/failure. |
| 372 break; |
| 373 } |
342 } | 374 } |
343 | 375 |
344 void LocalVideoCapturerSource::OnDeviceFormatsInUseReceived( | 376 void LocalVideoCapturerSource::OnDeviceFormatsInUseReceived( |
345 const media::VideoCaptureFormats& formats_in_use) { | 377 const media::VideoCaptureFormats& formats_in_use) { |
346 DVLOG(3) << __func__ << ", #formats received: " << formats_in_use.size(); | 378 DVLOG(3) << __func__ << ", #formats received: " << formats_in_use.size(); |
347 DCHECK(thread_checker_.CalledOnValidThread()); | 379 DCHECK(thread_checker_.CalledOnValidThread()); |
348 // StopCapture() might have destroyed |formats_enumerated_callback_| before | 380 // StopCapture() might have destroyed |formats_enumerated_callback_| before |
349 // arriving here. | 381 // arriving here. |
350 if (formats_enumerated_callback_.is_null()) | 382 if (formats_enumerated_callback_.is_null()) |
351 return; | 383 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 SetDeviceInfo(device_info); | 439 SetDeviceInfo(device_info); |
408 } | 440 } |
409 | 441 |
410 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { | 442 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { |
411 } | 443 } |
412 | 444 |
413 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { | 445 void MediaStreamVideoCapturerSource::RequestRefreshFrame() { |
414 source_->RequestRefreshFrame(); | 446 source_->RequestRefreshFrame(); |
415 } | 447 } |
416 | 448 |
417 void MediaStreamVideoCapturerSource::SetCapturingLinkSecured(bool is_secure) { | 449 void MediaStreamVideoCapturerSource::OnHasConsumers(bool has_consumers) { |
| 450 if (has_consumers) |
| 451 source_->Resume(); |
| 452 else |
| 453 source_->MaybeSuspend(); |
| 454 } |
| 455 |
| 456 void MediaStreamVideoCapturerSource::OnCapturingLinkSecured(bool is_secure) { |
418 Send(new MediaStreamHostMsg_SetCapturingLinkSecured( | 457 Send(new MediaStreamHostMsg_SetCapturingLinkSecured( |
419 device_info().session_id, device_info().device.type, is_secure)); | 458 device_info().session_id, device_info().device.type, is_secure)); |
420 } | 459 } |
421 | 460 |
422 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( | 461 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( |
423 int max_requested_width, | 462 int max_requested_width, |
424 int max_requested_height, | 463 int max_requested_height, |
425 double max_requested_frame_rate, | 464 double max_requested_frame_rate, |
426 const VideoCaptureDeviceFormatsCB& callback) { | 465 const VideoCaptureDeviceFormatsCB& callback) { |
427 source_->GetCurrentSupportedFormats( | 466 source_->GetCurrentSupportedFormats( |
(...skipping 29 matching lines...) Expand all Loading... |
457 void MediaStreamVideoCapturerSource::OnStarted(bool result) { | 496 void MediaStreamVideoCapturerSource::OnStarted(bool result) { |
458 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE); | 497 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE); |
459 } | 498 } |
460 | 499 |
461 const char* | 500 const char* |
462 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { | 501 MediaStreamVideoCapturerSource::GetPowerLineFrequencyForTesting() const { |
463 return kPowerLineFrequency; | 502 return kPowerLineFrequency; |
464 } | 503 } |
465 | 504 |
466 } // namespace content | 505 } // namespace content |
OLD | NEW |