OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/capture/video/win/video_capture_device_win.h" | 5 #include "media/capture/video/win/video_capture_device_win.h" |
6 | 6 |
7 #include <ks.h> | 7 #include <ks.h> |
8 #include <ksmedia.h> | 8 #include <ksmedia.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 return; | 415 return; |
416 } | 416 } |
417 | 417 |
418 // Start capturing. | 418 // Start capturing. |
419 hr = media_control_->Run(); | 419 hr = media_control_->Run(); |
420 if (FAILED(hr)) { | 420 if (FAILED(hr)) { |
421 SetErrorState(FROM_HERE, "Failed to start the Capture device.", hr); | 421 SetErrorState(FROM_HERE, "Failed to start the Capture device.", hr); |
422 return; | 422 return; |
423 } | 423 } |
424 | 424 |
425 client_->OnStarted(); | |
425 state_ = kCapturing; | 426 state_ = kCapturing; |
426 } | 427 } |
427 | 428 |
428 void VideoCaptureDeviceWin::StopAndDeAllocate() { | 429 void VideoCaptureDeviceWin::StopAndDeAllocate() { |
429 DCHECK(thread_checker_.CalledOnValidThread()); | 430 DCHECK(thread_checker_.CalledOnValidThread()); |
430 if (state_ != kCapturing) | 431 if (state_ != kCapturing) |
431 return; | 432 return; |
432 | 433 |
433 HRESULT hr = media_control_->Stop(); | 434 HRESULT hr = media_control_->Stop(); |
434 if (FAILED(hr)) { | 435 if (FAILED(hr)) { |
(...skipping 15 matching lines...) Expand all Loading... | |
450 // way, however, is not widespread and proves too cumbersome, so we just grab | 451 // way, however, is not widespread and proves too cumbersome, so we just grab |
451 // the next captured frame instead. | 452 // the next captured frame instead. |
452 take_photo_callbacks_.push(std::move(callback)); | 453 take_photo_callbacks_.push(std::move(callback)); |
453 } | 454 } |
454 | 455 |
455 // Implements SinkFilterObserver::SinkFilterObserver. | 456 // Implements SinkFilterObserver::SinkFilterObserver. |
456 void VideoCaptureDeviceWin::FrameReceived(const uint8_t* buffer, | 457 void VideoCaptureDeviceWin::FrameReceived(const uint8_t* buffer, |
457 int length, | 458 int length, |
458 const VideoCaptureFormat& format, | 459 const VideoCaptureFormat& format, |
459 base::TimeDelta timestamp) { | 460 base::TimeDelta timestamp) { |
461 if (state_ != kCapturing) | |
chfremer
2017/02/17 23:51:15
Unless this runs on the same thread as AllocateAnd
braveyao
2017/02/22 18:06:44
Done.
| |
462 return; | |
463 | |
460 if (first_ref_time_.is_null()) | 464 if (first_ref_time_.is_null()) |
461 first_ref_time_ = base::TimeTicks::Now(); | 465 first_ref_time_ = base::TimeTicks::Now(); |
462 | 466 |
463 // There is a chance that the platform does not provide us with the timestamp, | 467 // There is a chance that the platform does not provide us with the timestamp, |
464 // in which case, we use reference time to calculate a timestamp. | 468 // in which case, we use reference time to calculate a timestamp. |
465 if (timestamp == media::kNoTimestamp) | 469 if (timestamp == media::kNoTimestamp) |
466 timestamp = base::TimeTicks::Now() - first_ref_time_; | 470 timestamp = base::TimeTicks::Now() - first_ref_time_; |
467 | 471 |
468 client_->OnIncomingCapturedData(buffer, length, format, 0, | 472 client_->OnIncomingCapturedData(buffer, length, format, 0, |
469 base::TimeTicks::Now(), timestamp); | 473 base::TimeTicks::Now(), timestamp); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 void VideoCaptureDeviceWin::SetErrorState( | 593 void VideoCaptureDeviceWin::SetErrorState( |
590 const tracked_objects::Location& from_here, | 594 const tracked_objects::Location& from_here, |
591 const std::string& reason, | 595 const std::string& reason, |
592 HRESULT hr) { | 596 HRESULT hr) { |
593 DCHECK(thread_checker_.CalledOnValidThread()); | 597 DCHECK(thread_checker_.CalledOnValidThread()); |
594 DLOG_IF_FAILED_WITH_HRESULT(reason, hr); | 598 DLOG_IF_FAILED_WITH_HRESULT(reason, hr); |
595 state_ = kError; | 599 state_ = kError; |
596 client_->OnError(from_here, reason); | 600 client_->OnError(from_here, reason); |
597 } | 601 } |
598 } // namespace media | 602 } // namespace media |
OLD | NEW |