| 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 "content/renderer/media/rtc_video_capture_delegate.h" | 5 #include "content/renderer/media/rtc_video_capture_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 RtcVideoCaptureDelegate::RtcVideoCaptureDelegate( | 11 RtcVideoCaptureDelegate::RtcVideoCaptureDelegate( |
| 12 const media::VideoCaptureSessionId id, | 12 const media::VideoCaptureSessionId id, |
| 13 VideoCaptureImplManager* vc_manager) | 13 VideoCaptureImplManager* vc_manager) |
| 14 : session_id_(id), | 14 : session_id_(id), |
| 15 vc_manager_(vc_manager), | 15 vc_manager_(vc_manager), |
| 16 capture_engine_(NULL), | 16 capture_engine_(NULL), |
| 17 got_first_frame_(false), | 17 got_first_frame_(false), |
| 18 error_occured_(false) { | 18 error_occured_(false) { |
| 19 DVLOG(3) << " RtcVideoCaptureDelegate::ctor"; | 19 DVLOG(3) << " RtcVideoCaptureDelegate::ctor"; |
| 20 capture_engine_ = vc_manager_->AddDevice(session_id_, this); | 20 capture_engine_ = vc_manager_->AddDevice(session_id_, this); |
| 21 } | 21 } |
| 22 | 22 |
| 23 RtcVideoCaptureDelegate::~RtcVideoCaptureDelegate() { | 23 RtcVideoCaptureDelegate::~RtcVideoCaptureDelegate() { |
| 24 DVLOG(3) << " RtcVideoCaptureDelegate::dtor"; | 24 DVLOG(3) << " RtcVideoCaptureDelegate::dtor"; |
| 25 vc_manager_->RemoveDevice(session_id_, this); | 25 vc_manager_->RemoveDevice(session_id_, this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void RtcVideoCaptureDelegate::StartCapture( | 28 void RtcVideoCaptureDelegate::StartCapture( |
| 29 const media::VideoCaptureCapability& capability, | 29 const media::VideoCaptureParams& params, |
| 30 const FrameCapturedCallback& captured_callback, | 30 const FrameCapturedCallback& captured_callback, |
| 31 const StateChangeCallback& state_callback) { | 31 const StateChangeCallback& state_callback) { |
| 32 DVLOG(3) << " RtcVideoCaptureDelegate::StartCapture "; | 32 DVLOG(3) << " RtcVideoCaptureDelegate::StartCapture "; |
| 33 message_loop_proxy_ = base::MessageLoopProxy::current(); | 33 message_loop_proxy_ = base::MessageLoopProxy::current(); |
| 34 captured_callback_ = captured_callback; | 34 captured_callback_ = captured_callback; |
| 35 state_callback_ = state_callback; | 35 state_callback_ = state_callback; |
| 36 got_first_frame_ = false; | 36 got_first_frame_ = false; |
| 37 error_occured_ = false; | 37 error_occured_ = false; |
| 38 | 38 |
| 39 // Increase the reference count to ensure we are not deleted until | 39 // Increase the reference count to ensure we are not deleted until |
| 40 // The we are unregistered in RtcVideoCaptureDelegate::OnRemoved. | 40 // The we are unregistered in RtcVideoCaptureDelegate::OnRemoved. |
| 41 AddRef(); | 41 AddRef(); |
| 42 capture_engine_->StartCapture(this, capability); | 42 capture_engine_->StartCapture(this, params); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void RtcVideoCaptureDelegate::StopCapture() { | 45 void RtcVideoCaptureDelegate::StopCapture() { |
| 46 // Immediately make sure we don't provide more frames. | 46 // Immediately make sure we don't provide more frames. |
| 47 captured_callback_.Reset(); | 47 captured_callback_.Reset(); |
| 48 state_callback_.Reset(); | 48 state_callback_.Reset(); |
| 49 capture_engine_->StopCapture(this); | 49 capture_engine_->StopCapture(this); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void RtcVideoCaptureDelegate::OnStarted(media::VideoCapture* capture) { | 52 void RtcVideoCaptureDelegate::OnStarted(media::VideoCapture* capture) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 message_loop_proxy_->PostTask( | 87 message_loop_proxy_->PostTask( |
| 88 FROM_HERE, | 88 FROM_HERE, |
| 89 base::Bind(&RtcVideoCaptureDelegate::OnFrameReadyOnCaptureThread, | 89 base::Bind(&RtcVideoCaptureDelegate::OnFrameReadyOnCaptureThread, |
| 90 this, | 90 this, |
| 91 capture, | 91 capture, |
| 92 frame)); | 92 frame)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void RtcVideoCaptureDelegate::OnDeviceInfoReceived( | 95 void RtcVideoCaptureDelegate::OnDeviceInfoReceived( |
| 96 media::VideoCapture* capture, | 96 media::VideoCapture* capture, |
| 97 const media::VideoCaptureParams& device_info) { | 97 const media::VideoCaptureFormat& device_info) { |
| 98 } | |
| 99 | |
| 100 void RtcVideoCaptureDelegate::OnDeviceInfoChanged( | |
| 101 media::VideoCapture* capture, | |
| 102 const media::VideoCaptureParams& device_info) { | |
| 103 } | 98 } |
| 104 | 99 |
| 105 void RtcVideoCaptureDelegate::OnFrameReadyOnCaptureThread( | 100 void RtcVideoCaptureDelegate::OnFrameReadyOnCaptureThread( |
| 106 media::VideoCapture* capture, | 101 media::VideoCapture* capture, |
| 107 const scoped_refptr<media::VideoFrame>& frame) { | 102 const scoped_refptr<media::VideoFrame>& frame) { |
| 108 if (!captured_callback_.is_null()) { | 103 if (!captured_callback_.is_null()) { |
| 109 if (!got_first_frame_) { | 104 if (!got_first_frame_) { |
| 110 got_first_frame_ = true; | 105 got_first_frame_ = true; |
| 111 if (!state_callback_.is_null()) | 106 if (!state_callback_.is_null()) |
| 112 state_callback_.Run(CAPTURE_RUNNING); | 107 state_callback_.Run(CAPTURE_RUNNING); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 124 } | 119 } |
| 125 | 120 |
| 126 | 121 |
| 127 void RtcVideoCaptureDelegate::OnRemovedOnCaptureThread( | 122 void RtcVideoCaptureDelegate::OnRemovedOnCaptureThread( |
| 128 media::VideoCapture* capture) { | 123 media::VideoCapture* capture) { |
| 129 if (!error_occured_ && !state_callback_.is_null()) | 124 if (!error_occured_ && !state_callback_.is_null()) |
| 130 state_callback_.Run(CAPTURE_STOPPED); | 125 state_callback_.Run(CAPTURE_STOPPED); |
| 131 } | 126 } |
| 132 | 127 |
| 133 } // namespace content | 128 } // namespace content |
| OLD | NEW |