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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "content/renderer/media/video_capture_impl_manager.h" | 10 #include "content/renderer/media/video_capture_impl_manager.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 manager->GetDeviceFormatsInUse( | 91 manager->GetDeviceFormatsInUse( |
92 session_id_, | 92 session_id_, |
93 media::BindToCurrentLoop( | 93 media::BindToCurrentLoop( |
94 base::Bind( | 94 base::Bind( |
95 &VideoCapturerDelegate::OnDeviceFormatsInUseReceived, this))); | 95 &VideoCapturerDelegate::OnDeviceFormatsInUseReceived, this))); |
96 } | 96 } |
97 | 97 |
98 void VideoCapturerDelegate::StartCapture( | 98 void VideoCapturerDelegate::StartCapture( |
99 const media::VideoCaptureParams& params, | 99 const media::VideoCaptureParams& params, |
100 const VideoCaptureDeliverFrameCB& new_frame_callback, | 100 const VideoCaptureDeliverFrameCB& new_frame_callback, |
101 const StartedCallback& started_callback) { | 101 const RunningCallback& running_callback) { |
102 DCHECK(params.requested_format.IsValid()); | 102 DCHECK(params.requested_format.IsValid()); |
103 DCHECK(thread_checker_.CalledOnValidThread()); | 103 DCHECK(thread_checker_.CalledOnValidThread()); |
104 started_callback_ = started_callback; | 104 running_callback_ = running_callback; |
105 got_first_frame_ = false; | 105 got_first_frame_ = false; |
106 | 106 |
107 // NULL in unit test. | 107 // NULL in unit test. |
108 if (!RenderThreadImpl::current()) | 108 if (!RenderThreadImpl::current()) |
109 return; | 109 return; |
110 VideoCaptureImplManager* manager = | 110 VideoCaptureImplManager* manager = |
111 RenderThreadImpl::current()->video_capture_impl_manager(); | 111 RenderThreadImpl::current()->video_capture_impl_manager(); |
112 if (!manager) | 112 if (!manager) |
113 return; | 113 return; |
114 stop_capture_cb_ = | 114 stop_capture_cb_ = |
115 manager->StartCapture( | 115 manager->StartCapture( |
116 session_id_, | 116 session_id_, |
117 params, | 117 params, |
118 media::BindToCurrentLoop(base::Bind( | 118 media::BindToCurrentLoop(base::Bind( |
119 &VideoCapturerDelegate::OnStateUpdateOnRenderThread, this)), | 119 &VideoCapturerDelegate::OnStateUpdateOnRenderThread, this)), |
120 new_frame_callback); | 120 new_frame_callback); |
121 } | 121 } |
122 | 122 |
123 void VideoCapturerDelegate::StopCapture() { | 123 void VideoCapturerDelegate::StopCapture() { |
124 // Immediately make sure we don't provide more frames. | 124 // Immediately make sure we don't provide more frames. |
125 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; | 125 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; |
126 DCHECK(thread_checker_.CalledOnValidThread()); | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
127 if (!stop_capture_cb_.is_null()) { | 127 if (!stop_capture_cb_.is_null()) { |
128 base::ResetAndReturn(&stop_capture_cb_).Run(); | 128 base::ResetAndReturn(&stop_capture_cb_).Run(); |
129 } | 129 } |
130 started_callback_.Reset(); | 130 running_callback_.Reset(); |
131 source_formats_callback_.Reset(); | 131 source_formats_callback_.Reset(); |
132 } | 132 } |
133 | 133 |
134 void VideoCapturerDelegate::OnStateUpdateOnRenderThread( | 134 void VideoCapturerDelegate::OnStateUpdateOnRenderThread( |
135 VideoCaptureState state) { | 135 VideoCaptureState state) { |
136 DCHECK(thread_checker_.CalledOnValidThread()); | 136 DCHECK(thread_checker_.CalledOnValidThread()); |
137 DVLOG(3) << "OnStateUpdateOnRenderThread state = " << state; | 137 DVLOG(3) << "OnStateUpdateOnRenderThread state = " << state; |
138 if (state > VIDEO_CAPTURE_STATE_STARTING && !started_callback_.is_null()) { | 138 if (state == VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) { |
139 base::ResetAndReturn(&started_callback_).Run( | 139 running_callback_.Run(true); |
140 state == VIDEO_CAPTURE_STATE_STARTED); | 140 return; |
| 141 } |
| 142 if (state > VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) { |
| 143 base::ResetAndReturn(&running_callback_).Run(false); |
141 } | 144 } |
142 } | 145 } |
143 | 146 |
144 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( | 147 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( |
145 const media::VideoCaptureFormats& formats_in_use) { | 148 const media::VideoCaptureFormats& formats_in_use) { |
146 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); | 149 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); |
147 DCHECK(thread_checker_.CalledOnValidThread()); | 150 DCHECK(thread_checker_.CalledOnValidThread()); |
148 // StopCapture() might have destroyed |source_formats_callback_| before | 151 // StopCapture() might have destroyed |source_formats_callback_| before |
149 // arriving here. | 152 // arriving here. |
150 if (source_formats_callback_.is_null()) | 153 if (source_formats_callback_.is_null()) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 frame_callback, | 236 frame_callback, |
234 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, | 237 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, |
235 base::Unretained(this))); | 238 base::Unretained(this))); |
236 } | 239 } |
237 | 240 |
238 void MediaStreamVideoCapturerSource::StopSourceImpl() { | 241 void MediaStreamVideoCapturerSource::StopSourceImpl() { |
239 delegate_->StopCapture(); | 242 delegate_->StopCapture(); |
240 } | 243 } |
241 | 244 |
242 } // namespace content | 245 } // namespace content |
OLD | NEW |