Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: content/renderer/media/media_stream_video_capturer_source.cc

Issue 883293005: Cast: Basic cast_receiver API for chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed extra BUILD.gn line Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 session_id_, 98 session_id_,
99 media::BindToCurrentLoop( 99 media::BindToCurrentLoop(
100 base::Bind( 100 base::Bind(
101 &VideoCapturerDelegate::OnDeviceFormatsInUseReceived, 101 &VideoCapturerDelegate::OnDeviceFormatsInUseReceived,
102 weak_factory_.GetWeakPtr()))); 102 weak_factory_.GetWeakPtr())));
103 } 103 }
104 104
105 void VideoCapturerDelegate::StartCapture( 105 void VideoCapturerDelegate::StartCapture(
106 const media::VideoCaptureParams& params, 106 const media::VideoCaptureParams& params,
107 const VideoCaptureDeliverFrameCB& new_frame_callback, 107 const VideoCaptureDeliverFrameCB& new_frame_callback,
108 scoped_refptr<base::SingleThreadTaskRunner> frame_callback_task_runner,
108 const RunningCallback& running_callback) { 109 const RunningCallback& running_callback) {
109 DCHECK(params.requested_format.IsValid()); 110 DCHECK(params.requested_format.IsValid());
110 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
111 running_callback_ = running_callback; 112 running_callback_ = running_callback;
112 113
113 // NULL in unit test. 114 // NULL in unit test.
114 if (!RenderThreadImpl::current()) 115 if (!RenderThreadImpl::current())
115 return; 116 return;
116 VideoCaptureImplManager* manager = 117 VideoCaptureImplManager* manager =
117 RenderThreadImpl::current()->video_capture_impl_manager(); 118 RenderThreadImpl::current()->video_capture_impl_manager();
118 if (!manager) 119 if (!manager)
119 return; 120 return;
121 if (frame_callback_task_runner !=
122 RenderThreadImpl::current()->GetIOMessageLoopProxy()) {
123 DCHECK(false) << "Only IO thread supported right now.";
124 running_callback.Run(false);
125 return;
126 }
127
120 stop_capture_cb_ = 128 stop_capture_cb_ =
121 manager->StartCapture( 129 manager->StartCapture(
122 session_id_, 130 session_id_,
123 params, 131 params,
124 media::BindToCurrentLoop(base::Bind( 132 media::BindToCurrentLoop(base::Bind(
125 &VideoCapturerDelegate::OnStateUpdateOnRenderThread, 133 &VideoCapturerDelegate::OnStateUpdateOnRenderThread,
126 weak_factory_.GetWeakPtr())), 134 weak_factory_.GetWeakPtr())),
127 new_frame_callback); 135 new_frame_callback);
128 } 136 }
129 137
130 void VideoCapturerDelegate::StopCapture() { 138 void VideoCapturerDelegate::StopCapture() {
131 // Immediately make sure we don't provide more frames. 139 // Immediately make sure we don't provide more frames.
132 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; 140 DVLOG(3) << "VideoCapturerDelegate::StopCapture()";
133 DCHECK(thread_checker_.CalledOnValidThread()); 141 DCHECK(thread_checker_.CalledOnValidThread());
134 if (!stop_capture_cb_.is_null()) { 142 if (!stop_capture_cb_.is_null()) {
135 base::ResetAndReturn(&stop_capture_cb_).Run(); 143 base::ResetAndReturn(&stop_capture_cb_).Run();
136 } 144 }
137 running_callback_.Reset(); 145 running_callback_.Reset();
138 source_formats_callback_.Reset(); 146 source_formats_callback_.Reset();
139 } 147 }
140 148
141 void VideoCapturerDelegate::OnStateUpdateOnRenderThread( 149 void VideoCapturerDelegate::OnStateUpdateOnRenderThread(
142 VideoCaptureState state) { 150 VideoCaptureState state) {
143 DCHECK(thread_checker_.CalledOnValidThread()); 151 DCHECK(thread_checker_.CalledOnValidThread());
144 DVLOG(3) << "OnStateUpdateOnRenderThread state = " << state; 152 DVLOG(3) << "OnStateUpdateOnRenderThread state = " << state;
145 if (state == VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) { 153 if (state == VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) {
146 running_callback_.Run(MEDIA_DEVICE_OK); 154 running_callback_.Run(true);
147 return; 155 return;
148 } 156 }
149 if (state > VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) { 157 if (state > VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) {
150 base::ResetAndReturn(&running_callback_).Run( 158 base::ResetAndReturn(&running_callback_).Run(false);
151 MEDIA_DEVICE_TRACK_START_FAILURE);
152 } 159 }
153 } 160 }
154 161
155 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( 162 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived(
156 const media::VideoCaptureFormats& formats_in_use) { 163 const media::VideoCaptureFormats& formats_in_use) {
157 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); 164 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size();
158 DCHECK(thread_checker_.CalledOnValidThread()); 165 DCHECK(thread_checker_.CalledOnValidThread());
159 // StopCapture() might have destroyed |source_formats_callback_| before 166 // StopCapture() might have destroyed |source_formats_callback_| before
160 // arriving here. 167 // arriving here.
161 if (source_formats_callback_.is_null()) 168 if (source_formats_callback_.is_null())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 default_formats.push_back(media::VideoCaptureFormat( 211 default_formats.push_back(media::VideoCaptureFormat(
205 gfx::Size(kVideoResolutions[i].width, kVideoResolutions[i].height), 212 gfx::Size(kVideoResolutions[i].width, kVideoResolutions[i].height),
206 kVideoFrameRates[j], media::PIXEL_FORMAT_I420)); 213 kVideoFrameRates[j], media::PIXEL_FORMAT_I420));
207 } 214 }
208 } 215 }
209 base::ResetAndReturn(&source_formats_callback_).Run(default_formats); 216 base::ResetAndReturn(&source_formats_callback_).Run(default_formats);
210 } 217 }
211 } 218 }
212 219
213 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( 220 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource(
214 const StreamDeviceInfo& device_info,
215 const SourceStoppedCallback& stop_callback, 221 const SourceStoppedCallback& stop_callback,
216 scoped_ptr<VideoCapturerDelegate> delegate) 222 scoped_ptr<media::VideoCapturerSource> delegate)
217 : delegate_(delegate.Pass()) { 223 : delegate_(delegate.Pass()) {
218 SetDeviceInfo(device_info);
219 SetStopCallback(stop_callback); 224 SetStopCallback(stop_callback);
220 } 225 }
221 226
227 void MediaStreamVideoCapturerSource::SetDeviceInfo(
228 const StreamDeviceInfo& device_info) {
229 MediaStreamVideoSource::SetDeviceInfo(device_info);
230 }
231
222 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { 232 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() {
223 } 233 }
224 234
225 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( 235 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats(
226 int max_requested_width, 236 int max_requested_width,
227 int max_requested_height, 237 int max_requested_height,
228 double max_requested_frame_rate, 238 double max_requested_frame_rate,
229 const VideoCaptureDeviceFormatsCB& callback) { 239 const VideoCaptureDeviceFormatsCB& callback) {
230 delegate_->GetCurrentSupportedFormats( 240 delegate_->GetCurrentSupportedFormats(
231 max_requested_width, 241 max_requested_width,
232 max_requested_height, 242 max_requested_height,
233 max_requested_frame_rate, 243 max_requested_frame_rate,
234 callback); 244 callback);
235 } 245 }
236 246
237 void MediaStreamVideoCapturerSource::StartSourceImpl( 247 void MediaStreamVideoCapturerSource::StartSourceImpl(
238 const media::VideoCaptureFormat& format, 248 const media::VideoCaptureFormat& format,
239 const VideoCaptureDeliverFrameCB& frame_callback) { 249 const VideoCaptureDeliverFrameCB& frame_callback) {
240 media::VideoCaptureParams new_params; 250 media::VideoCaptureParams new_params;
241 new_params.requested_format = format; 251 new_params.requested_format = format;
242 if (device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE || 252 if (device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE ||
243 device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { 253 device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) {
244 new_params.resolution_change_policy = 254 new_params.resolution_change_policy =
245 media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT; 255 media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT;
246 } 256 }
247 delegate_->StartCapture( 257 delegate_->StartCapture(
248 new_params, 258 new_params,
249 frame_callback, 259 frame_callback,
250 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, 260 RenderThreadImpl::current() ?
261 RenderThreadImpl::current()->GetIOMessageLoopProxy() :
262 nullptr,
263 base::Bind(&MediaStreamVideoCapturerSource::OnStarted,
251 base::Unretained(this))); 264 base::Unretained(this)));
252 } 265 }
253 266
267 void MediaStreamVideoCapturerSource::OnStarted(bool result) {
268 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE);
269 }
270
254 void MediaStreamVideoCapturerSource::StopSourceImpl() { 271 void MediaStreamVideoCapturerSource::StopSourceImpl() {
255 delegate_->StopCapture(); 272 delegate_->StopCapture();
256 } 273 }
257 274
258 } // namespace content 275 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_video_capturer_source.h ('k') | content/renderer/media/media_stream_video_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698