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

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: missed include file changes Created 5 years, 10 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
114
perkj_chrome 2015/02/09 14:50:27 remove
hubbe 2015/02/09 20:13:32 Done.
113 // NULL in unit test. 115 // NULL in unit test.
114 if (!RenderThreadImpl::current()) 116 if (!RenderThreadImpl::current())
115 return; 117 return;
116 VideoCaptureImplManager* manager = 118 VideoCaptureImplManager* manager =
117 RenderThreadImpl::current()->video_capture_impl_manager(); 119 RenderThreadImpl::current()->video_capture_impl_manager();
118 if (!manager) 120 if (!manager)
119 return; 121 return;
122 if (frame_callback_task_runner !=
123 RenderThreadImpl::current()->GetIOMessageLoopProxy()) {
124 DCHECK(false) << "Only IO thread supported right now.";
125 running_callback.Run(false);
126 return;
127 }
128
120 stop_capture_cb_ = 129 stop_capture_cb_ =
121 manager->StartCapture( 130 manager->StartCapture(
122 session_id_, 131 session_id_,
123 params, 132 params,
124 media::BindToCurrentLoop(base::Bind( 133 media::BindToCurrentLoop(base::Bind(
125 &VideoCapturerDelegate::OnStateUpdateOnRenderThread, 134 &VideoCapturerDelegate::OnStateUpdateOnRenderThread,
126 weak_factory_.GetWeakPtr())), 135 weak_factory_.GetWeakPtr())),
127 new_frame_callback); 136 new_frame_callback);
128 } 137 }
129 138
130 void VideoCapturerDelegate::StopCapture() { 139 void VideoCapturerDelegate::StopCapture() {
131 // Immediately make sure we don't provide more frames. 140 // Immediately make sure we don't provide more frames.
132 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; 141 DVLOG(3) << "VideoCapturerDelegate::StopCapture()";
133 DCHECK(thread_checker_.CalledOnValidThread()); 142 DCHECK(thread_checker_.CalledOnValidThread());
134 if (!stop_capture_cb_.is_null()) { 143 if (!stop_capture_cb_.is_null()) {
135 base::ResetAndReturn(&stop_capture_cb_).Run(); 144 base::ResetAndReturn(&stop_capture_cb_).Run();
136 } 145 }
137 running_callback_.Reset(); 146 running_callback_.Reset();
138 source_formats_callback_.Reset(); 147 source_formats_callback_.Reset();
139 } 148 }
140 149
141 void VideoCapturerDelegate::OnStateUpdateOnRenderThread( 150 void VideoCapturerDelegate::OnStateUpdateOnRenderThread(
142 VideoCaptureState state) { 151 VideoCaptureState state) {
143 DCHECK(thread_checker_.CalledOnValidThread()); 152 DCHECK(thread_checker_.CalledOnValidThread());
144 DVLOG(3) << "OnStateUpdateOnRenderThread state = " << state; 153 DVLOG(3) << "OnStateUpdateOnRenderThread state = " << state;
145 if (state == VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) { 154 if (state == VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) {
146 running_callback_.Run(MEDIA_DEVICE_OK); 155 running_callback_.Run(true);
147 return; 156 return;
148 } 157 }
149 if (state > VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) { 158 if (state > VIDEO_CAPTURE_STATE_STARTED && !running_callback_.is_null()) {
150 base::ResetAndReturn(&running_callback_).Run( 159 base::ResetAndReturn(&running_callback_).Run(false);
151 MEDIA_DEVICE_TRACK_START_FAILURE);
152 } 160 }
153 } 161 }
154 162
155 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived( 163 void VideoCapturerDelegate::OnDeviceFormatsInUseReceived(
156 const media::VideoCaptureFormats& formats_in_use) { 164 const media::VideoCaptureFormats& formats_in_use) {
157 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size(); 165 DVLOG(3) << "OnDeviceFormatsInUseReceived: " << formats_in_use.size();
158 DCHECK(thread_checker_.CalledOnValidThread()); 166 DCHECK(thread_checker_.CalledOnValidThread());
159 // StopCapture() might have destroyed |source_formats_callback_| before 167 // StopCapture() might have destroyed |source_formats_callback_| before
160 // arriving here. 168 // arriving here.
161 if (source_formats_callback_.is_null()) 169 if (source_formats_callback_.is_null())
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 kVideoFrameRates[j], media::PIXEL_FORMAT_I420)); 214 kVideoFrameRates[j], media::PIXEL_FORMAT_I420));
207 } 215 }
208 } 216 }
209 base::ResetAndReturn(&source_formats_callback_).Run(default_formats); 217 base::ResetAndReturn(&source_formats_callback_).Run(default_formats);
210 } 218 }
211 } 219 }
212 220
213 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( 221 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource(
214 const StreamDeviceInfo& device_info, 222 const StreamDeviceInfo& device_info,
215 const SourceStoppedCallback& stop_callback, 223 const SourceStoppedCallback& stop_callback,
216 scoped_ptr<VideoCapturerDelegate> delegate) 224 scoped_refptr<media::VideoCapturerSource> delegate)
217 : delegate_(delegate.Pass()) { 225 : delegate_(delegate) {
218 SetDeviceInfo(device_info); 226 SetDeviceInfo(device_info);
219 SetStopCallback(stop_callback); 227 SetStopCallback(stop_callback);
220 } 228 }
221 229
222 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { 230 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() {
223 } 231 }
224 232
225 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( 233 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats(
226 int max_requested_width, 234 int max_requested_width,
227 int max_requested_height, 235 int max_requested_height,
(...skipping 12 matching lines...) Expand all
240 media::VideoCaptureParams new_params; 248 media::VideoCaptureParams new_params;
241 new_params.requested_format = format; 249 new_params.requested_format = format;
242 if (device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE || 250 if (device_info().device.type == MEDIA_TAB_VIDEO_CAPTURE ||
243 device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { 251 device_info().device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) {
244 new_params.resolution_change_policy = 252 new_params.resolution_change_policy =
245 media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT; 253 media::RESOLUTION_POLICY_DYNAMIC_WITHIN_LIMIT;
246 } 254 }
247 delegate_->StartCapture( 255 delegate_->StartCapture(
248 new_params, 256 new_params,
249 frame_callback, 257 frame_callback,
250 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, 258 RenderThreadImpl::current() ?
259 RenderThreadImpl::current()->GetIOMessageLoopProxy() :
260 NULL,
261 base::Bind(&MediaStreamVideoCapturerSource::OnStarted,
251 base::Unretained(this))); 262 base::Unretained(this)));
252 } 263 }
253 264
265 void MediaStreamVideoCapturerSource::OnStarted(bool result) {
266 OnStartDone(result ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE);
267 }
268
254 void MediaStreamVideoCapturerSource::StopSourceImpl() { 269 void MediaStreamVideoCapturerSource::StopSourceImpl() {
255 delegate_->StopCapture(); 270 delegate_->StopCapture();
256 } 271 }
257 272
258 } // namespace content 273 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698