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

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

Issue 843943002: Refactor VideoCapturerDelegate to use WeakPtr instead of refcount. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: And make it right. Created 5 years, 11 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 23 matching lines...) Expand all
34 const double kMaxScreenCastFrameRate = 120.0; 34 const double kMaxScreenCastFrameRate = 120.0;
35 35
36 } // namespace 36 } // namespace
37 37
38 namespace content { 38 namespace content {
39 39
40 VideoCapturerDelegate::VideoCapturerDelegate( 40 VideoCapturerDelegate::VideoCapturerDelegate(
41 const StreamDeviceInfo& device_info) 41 const StreamDeviceInfo& device_info)
42 : session_id_(device_info.session_id), 42 : session_id_(device_info.session_id),
43 is_screen_cast_(device_info.device.type == MEDIA_TAB_VIDEO_CAPTURE || 43 is_screen_cast_(device_info.device.type == MEDIA_TAB_VIDEO_CAPTURE ||
44 device_info.device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { 44 device_info.device.type == MEDIA_DESKTOP_VIDEO_CAPTURE),
45 weak_factory_(this) {
45 DVLOG(3) << "VideoCapturerDelegate::ctor"; 46 DVLOG(3) << "VideoCapturerDelegate::ctor";
46 47
47 // NULL in unit test. 48 // NULL in unit test.
48 if (RenderThreadImpl::current()) { 49 if (RenderThreadImpl::current()) {
49 VideoCaptureImplManager* manager = 50 VideoCaptureImplManager* manager =
50 RenderThreadImpl::current()->video_capture_impl_manager(); 51 RenderThreadImpl::current()->video_capture_impl_manager();
51 if (manager) 52 if (manager)
52 release_device_cb_ = manager->UseDevice(session_id_); 53 release_device_cb_ = manager->UseDevice(session_id_);
53 } 54 }
54 } 55 }
55 56
56 VideoCapturerDelegate::~VideoCapturerDelegate() { 57 VideoCapturerDelegate::~VideoCapturerDelegate() {
58 DCHECK(thread_checker_.CalledOnValidThread());
57 DVLOG(3) << "VideoCapturerDelegate::dtor"; 59 DVLOG(3) << "VideoCapturerDelegate::dtor";
58 if (!release_device_cb_.is_null()) 60 if (!release_device_cb_.is_null())
59 release_device_cb_.Run(); 61 release_device_cb_.Run();
60 } 62 }
61 63
62 void VideoCapturerDelegate::GetCurrentSupportedFormats( 64 void VideoCapturerDelegate::GetCurrentSupportedFormats(
63 int max_requested_width, 65 int max_requested_width,
64 int max_requested_height, 66 int max_requested_height,
65 double max_requested_frame_rate, 67 double max_requested_frame_rate,
66 const VideoCaptureDeviceFormatsCB& callback) { 68 const VideoCaptureDeviceFormatsCB& callback) {
(...skipping 18 matching lines...) Expand all
85 87
86 // NULL in unit test. 88 // NULL in unit test.
87 if (!RenderThreadImpl::current()) 89 if (!RenderThreadImpl::current())
88 return; 90 return;
89 VideoCaptureImplManager* manager = 91 VideoCaptureImplManager* manager =
90 RenderThreadImpl::current()->video_capture_impl_manager(); 92 RenderThreadImpl::current()->video_capture_impl_manager();
91 if (!manager) 93 if (!manager)
92 return; 94 return;
93 DCHECK(source_formats_callback_.is_null()); 95 DCHECK(source_formats_callback_.is_null());
94 source_formats_callback_ = callback; 96 source_formats_callback_ = callback;
97
magjed_chromium 2015/01/09 11:15:53 Is this new empty line on purpose?
perkj_chrome 2015/01/09 11:43:59 Done.
95 manager->GetDeviceFormatsInUse( 98 manager->GetDeviceFormatsInUse(
96 session_id_, 99 session_id_,
97 media::BindToCurrentLoop( 100 media::BindToCurrentLoop(
98 base::Bind( 101 base::Bind(
99 &VideoCapturerDelegate::OnDeviceFormatsInUseReceived, this))); 102 &VideoCapturerDelegate::OnDeviceFormatsInUseReceived,
103 weak_factory_.GetWeakPtr())));
100 } 104 }
101 105
102 void VideoCapturerDelegate::StartCapture( 106 void VideoCapturerDelegate::StartCapture(
103 const media::VideoCaptureParams& params, 107 const media::VideoCaptureParams& params,
104 const VideoCaptureDeliverFrameCB& new_frame_callback, 108 const VideoCaptureDeliverFrameCB& new_frame_callback,
105 const RunningCallback& running_callback) { 109 const RunningCallback& running_callback) {
106 DCHECK(params.requested_format.IsValid()); 110 DCHECK(params.requested_format.IsValid());
107 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
108 running_callback_ = running_callback; 112 running_callback_ = running_callback;
109 113
110 // NULL in unit test. 114 // NULL in unit test.
111 if (!RenderThreadImpl::current()) 115 if (!RenderThreadImpl::current())
112 return; 116 return;
113 VideoCaptureImplManager* manager = 117 VideoCaptureImplManager* manager =
114 RenderThreadImpl::current()->video_capture_impl_manager(); 118 RenderThreadImpl::current()->video_capture_impl_manager();
115 if (!manager) 119 if (!manager)
116 return; 120 return;
117 stop_capture_cb_ = 121 stop_capture_cb_ =
118 manager->StartCapture( 122 manager->StartCapture(
119 session_id_, 123 session_id_,
120 params, 124 params,
121 media::BindToCurrentLoop(base::Bind( 125 media::BindToCurrentLoop(base::Bind(
122 &VideoCapturerDelegate::OnStateUpdateOnRenderThread, this)), 126 &VideoCapturerDelegate::OnStateUpdateOnRenderThread,
127 weak_factory_.GetWeakPtr())),
123 new_frame_callback); 128 new_frame_callback);
124 } 129 }
125 130
126 void VideoCapturerDelegate::StopCapture() { 131 void VideoCapturerDelegate::StopCapture() {
127 // Immediately make sure we don't provide more frames. 132 // Immediately make sure we don't provide more frames.
128 DVLOG(3) << "VideoCapturerDelegate::StopCapture()"; 133 DVLOG(3) << "VideoCapturerDelegate::StopCapture()";
129 DCHECK(thread_checker_.CalledOnValidThread()); 134 DCHECK(thread_checker_.CalledOnValidThread());
130 if (!stop_capture_cb_.is_null()) { 135 if (!stop_capture_cb_.is_null()) {
131 base::ResetAndReturn(&stop_capture_cb_).Run(); 136 base::ResetAndReturn(&stop_capture_cb_).Run();
132 } 137 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return; 169 return;
165 } 170 }
166 171
167 // NULL in unit test. 172 // NULL in unit test.
168 if (!RenderThreadImpl::current()) 173 if (!RenderThreadImpl::current())
169 return; 174 return;
170 VideoCaptureImplManager* manager = 175 VideoCaptureImplManager* manager =
171 RenderThreadImpl::current()->video_capture_impl_manager(); 176 RenderThreadImpl::current()->video_capture_impl_manager();
172 if (!manager) 177 if (!manager)
173 return; 178 return;
179
magjed_chromium 2015/01/09 11:15:53 Two new empty lines.
perkj_chrome 2015/01/09 11:43:59 Done.
180
174 manager->GetDeviceSupportedFormats( 181 manager->GetDeviceSupportedFormats(
175 session_id_, 182 session_id_,
176 media::BindToCurrentLoop( 183 media::BindToCurrentLoop(
177 base::Bind( 184 base::Bind(
178 &VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated, 185 &VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated,
179 this))); 186 weak_factory_.GetWeakPtr())));
180 } 187 }
181 188
182 void VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated( 189 void VideoCapturerDelegate::OnDeviceSupportedFormatsEnumerated(
183 const media::VideoCaptureFormats& formats) { 190 const media::VideoCaptureFormats& formats) {
184 DVLOG(3) << "OnDeviceSupportedFormatsEnumerated: " << formats.size() 191 DVLOG(3) << "OnDeviceSupportedFormatsEnumerated: " << formats.size()
185 << " received"; 192 << " received";
186 DCHECK(thread_checker_.CalledOnValidThread()); 193 DCHECK(thread_checker_.CalledOnValidThread());
187 // StopCapture() might have destroyed |source_formats_callback_| before 194 // StopCapture() might have destroyed |source_formats_callback_| before
188 // arriving here. 195 // arriving here.
189 if (source_formats_callback_.is_null()) 196 if (source_formats_callback_.is_null())
(...skipping 12 matching lines...) Expand all
202 } 209 }
203 } 210 }
204 source_formats_callback_.Run(default_formats); 211 source_formats_callback_.Run(default_formats);
205 } 212 }
206 source_formats_callback_.Reset(); 213 source_formats_callback_.Reset();
207 } 214 }
208 215
209 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource( 216 MediaStreamVideoCapturerSource::MediaStreamVideoCapturerSource(
210 const StreamDeviceInfo& device_info, 217 const StreamDeviceInfo& device_info,
211 const SourceStoppedCallback& stop_callback, 218 const SourceStoppedCallback& stop_callback,
212 const scoped_refptr<VideoCapturerDelegate>& delegate) 219 scoped_ptr<VideoCapturerDelegate> delegate)
213 : delegate_(delegate) { 220 : delegate_(delegate.Pass()) {
214 SetDeviceInfo(device_info); 221 SetDeviceInfo(device_info);
215 SetStopCallback(stop_callback); 222 SetStopCallback(stop_callback);
216 } 223 }
217 224
218 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() { 225 MediaStreamVideoCapturerSource::~MediaStreamVideoCapturerSource() {
219 } 226 }
220 227
221 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats( 228 void MediaStreamVideoCapturerSource::GetCurrentSupportedFormats(
222 int max_requested_width, 229 int max_requested_width,
223 int max_requested_height, 230 int max_requested_height,
(...skipping 21 matching lines...) Expand all
245 frame_callback, 252 frame_callback,
246 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone, 253 base::Bind(&MediaStreamVideoCapturerSource::OnStartDone,
247 base::Unretained(this))); 254 base::Unretained(this)));
248 } 255 }
249 256
250 void MediaStreamVideoCapturerSource::StopSourceImpl() { 257 void MediaStreamVideoCapturerSource::StopSourceImpl() {
251 delegate_->StopCapture(); 258 delegate_->StopCapture();
252 } 259 }
253 260
254 } // namespace content 261 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_video_capturer_source.h ('k') | content/renderer/media/user_media_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698