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

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

Issue 10451087: for readability review. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: code review Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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/video_capture_impl.h" 5 #include "content/renderer/media/video_capture_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/common/child_process.h" 9 #include "content/common/child_process.h"
10 #include "content/common/media/video_capture_messages.h" 10 #include "content/common/media/video_capture_messages.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 video_type_(media::VideoCaptureCapability::kI420), 54 video_type_(media::VideoCaptureCapability::kI420),
55 device_info_available_(false), 55 device_info_available_(false),
56 state_(video_capture::kStopped) { 56 state_(video_capture::kStopped) {
57 DCHECK(filter); 57 DCHECK(filter);
58 memset(&current_params_, 0, sizeof(current_params_)); 58 memset(&current_params_, 0, sizeof(current_params_));
59 memset(&device_info_, 0, sizeof(device_info_)); 59 memset(&device_info_, 0, sizeof(device_info_));
60 current_params_.session_id = id; 60 current_params_.session_id = id;
61 } 61 }
62 62
63 VideoCaptureImpl::~VideoCaptureImpl() { 63 VideoCaptureImpl::~VideoCaptureImpl() {
64 STLDeleteContainerPairSecondPointers(cached_dibs_.begin(), 64 STLDeleteValues(&cached_dibs_);
65 cached_dibs_.end());
66 } 65 }
67 66
68 void VideoCaptureImpl::Init() { 67 void VideoCaptureImpl::Init() {
69 io_message_loop_proxy_ = ChildProcess::current()->io_message_loop_proxy(); 68 io_message_loop_proxy_ = ChildProcess::current()->io_message_loop_proxy();
70 if (!io_message_loop_proxy_->BelongsToCurrentThread()) { 69 if (!io_message_loop_proxy_->BelongsToCurrentThread()) {
71 io_message_loop_proxy_->PostTask(FROM_HERE, 70 io_message_loop_proxy_->PostTask(FROM_HERE,
72 base::Bind(&VideoCaptureImpl::AddDelegateOnIOThread, 71 base::Bind(&VideoCaptureImpl::AddDelegateOnIOThread,
73 base::Unretained(this))); 72 base::Unretained(this)));
74 return; 73 } else {
74 AddDelegateOnIOThread();
75 } 75 }
76
77 AddDelegateOnIOThread();
78 } 76 }
79 77
80 void VideoCaptureImpl::DeInit(base::Closure task) { 78 void VideoCaptureImpl::DeInit(base::Closure task) {
81 capture_message_loop_proxy_->PostTask(FROM_HERE, 79 capture_message_loop_proxy_->PostTask(FROM_HERE,
82 base::Bind(&VideoCaptureImpl::DoDeInit, 80 base::Bind(&VideoCaptureImpl::DoDeInitOnCaptureThread,
83 base::Unretained(this), task));
84 }
85
86 void VideoCaptureImpl::DoDeInit(base::Closure task) {
87 if (state_ == video_capture::kStarted)
88 Send(new VideoCaptureHostMsg_Stop(device_id_));
89
90 io_message_loop_proxy_->PostTask(FROM_HERE,
91 base::Bind(&VideoCaptureImpl::RemoveDelegateOnIOThread,
92 base::Unretained(this), task)); 81 base::Unretained(this), task));
93 } 82 }
94 83
95 void VideoCaptureImpl::StartCapture( 84 void VideoCaptureImpl::StartCapture(
96 media::VideoCapture::EventHandler* handler, 85 media::VideoCapture::EventHandler* handler,
97 const media::VideoCaptureCapability& capability) { 86 const media::VideoCaptureCapability& capability) {
98 DCHECK_EQ(capability.color, media::VideoCaptureCapability::kI420); 87 DCHECK_EQ(capability.color, media::VideoCaptureCapability::kI420);
99 88
100 capture_message_loop_proxy_->PostTask(FROM_HERE, 89 capture_message_loop_proxy_->PostTask(FROM_HERE,
101 base::Bind(&VideoCaptureImpl::DoStartCapture, 90 base::Bind(&VideoCaptureImpl::DoStartCaptureOnCaptureThread,
102 base::Unretained(this), handler, capability)); 91 base::Unretained(this), handler, capability));
103 } 92 }
104 93
105 void VideoCaptureImpl::StopCapture(media::VideoCapture::EventHandler* handler) { 94 void VideoCaptureImpl::StopCapture(media::VideoCapture::EventHandler* handler) {
106 capture_message_loop_proxy_->PostTask(FROM_HERE, 95 capture_message_loop_proxy_->PostTask(FROM_HERE,
107 base::Bind(&VideoCaptureImpl::DoStopCapture, 96 base::Bind(&VideoCaptureImpl::DoStopCaptureOnCaptureThread,
108 base::Unretained(this), handler)); 97 base::Unretained(this), handler));
109 } 98 }
110 99
111 void VideoCaptureImpl::FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) { 100 void VideoCaptureImpl::FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) {
112 capture_message_loop_proxy_->PostTask(FROM_HERE, 101 capture_message_loop_proxy_->PostTask(FROM_HERE,
113 base::Bind(&VideoCaptureImpl::DoFeedBuffer, 102 base::Bind(&VideoCaptureImpl::DoFeedBufferOnCaptureThread,
114 base::Unretained(this), buffer)); 103 base::Unretained(this), buffer));
115 } 104 }
116 105
117 void VideoCaptureImpl::OnBufferCreated( 106 void VideoCaptureImpl::OnBufferCreated(
118 base::SharedMemoryHandle handle, 107 base::SharedMemoryHandle handle,
119 int length, int buffer_id) { 108 int length, int buffer_id) {
120 capture_message_loop_proxy_->PostTask(FROM_HERE, 109 capture_message_loop_proxy_->PostTask(FROM_HERE,
121 base::Bind(&VideoCaptureImpl::DoBufferCreated, 110 base::Bind(&VideoCaptureImpl::DoBufferCreatedOnCaptureThread,
122 base::Unretained(this), handle, length, buffer_id)); 111 base::Unretained(this), handle, length, buffer_id));
123 } 112 }
124 113
125 void VideoCaptureImpl::OnBufferReceived(int buffer_id, base::Time timestamp) { 114 void VideoCaptureImpl::OnBufferReceived(int buffer_id, base::Time timestamp) {
126 capture_message_loop_proxy_->PostTask(FROM_HERE, 115 capture_message_loop_proxy_->PostTask(FROM_HERE,
127 base::Bind(&VideoCaptureImpl::DoBufferReceived, 116 base::Bind(&VideoCaptureImpl::DoBufferReceivedOnCaptureThread,
128 base::Unretained(this), buffer_id, timestamp)); 117 base::Unretained(this), buffer_id, timestamp));
129 } 118 }
130 119
131 void VideoCaptureImpl::OnStateChanged(video_capture::State state) { 120 void VideoCaptureImpl::OnStateChanged(video_capture::State state) {
132 capture_message_loop_proxy_->PostTask(FROM_HERE, 121 capture_message_loop_proxy_->PostTask(FROM_HERE,
133 base::Bind(&VideoCaptureImpl::DoStateChanged, 122 base::Bind(&VideoCaptureImpl::DoStateChangedOnCaptureThread,
134 base::Unretained(this), state)); 123 base::Unretained(this), state));
135 } 124 }
136 125
137 void VideoCaptureImpl::OnDeviceInfoReceived( 126 void VideoCaptureImpl::OnDeviceInfoReceived(
138 const media::VideoCaptureParams& device_info) { 127 const media::VideoCaptureParams& device_info) {
139 capture_message_loop_proxy_->PostTask(FROM_HERE, 128 capture_message_loop_proxy_->PostTask(FROM_HERE,
140 base::Bind(&VideoCaptureImpl::DoDeviceInfoReceived, 129 base::Bind(&VideoCaptureImpl::DoDeviceInfoReceivedOnCaptureThread,
141 base::Unretained(this), device_info)); 130 base::Unretained(this), device_info));
142 } 131 }
143 132
144 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) { 133 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) {
145 capture_message_loop_proxy_->PostTask(FROM_HERE, 134 capture_message_loop_proxy_->PostTask(FROM_HERE,
146 base::Bind(&VideoCaptureImpl::DoDelegateAdded, 135 base::Bind(&VideoCaptureImpl::DoDelegateAddedOnCaptureThread,
147 base::Unretained(this), device_id)); 136 base::Unretained(this), device_id));
148 } 137 }
149 138
150 void VideoCaptureImpl::DoStartCapture( 139 void VideoCaptureImpl::DoDeInitOnCaptureThread(base::Closure task) {
140 if (state_ == video_capture::kStarted)
141 Send(new VideoCaptureHostMsg_Stop(device_id_));
142
143 io_message_loop_proxy_->PostTask(FROM_HERE,
144 base::Bind(&VideoCaptureImpl::RemoveDelegateOnIOThread,
145 base::Unretained(this), task));
146 }
147
148 void VideoCaptureImpl::DoStartCaptureOnCaptureThread(
151 media::VideoCapture::EventHandler* handler, 149 media::VideoCapture::EventHandler* handler,
152 const media::VideoCaptureCapability& capability) { 150 const media::VideoCaptureCapability& capability) {
153 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 151 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
154 152
155 if (state_ == video_capture::kError) { 153 if (state_ == video_capture::kError) {
156 handler->OnError(this, 1); 154 handler->OnError(this, 1);
157 handler->OnRemoved(this); 155 handler->OnRemoved(this);
158 return; 156 } else if ((clients_pending_on_filter_.find(handler) !=
zunger 2012/07/10 23:34:30 Oh, wow. This function is a *lot* clearer now.
157 clients_pending_on_filter_.end()) ||
158 (clients_pending_on_restart_.find(handler) !=
159 clients_pending_on_restart_.end()) ||
160 clients_.find(handler) != clients_.end() ) {
161 // This client has started.
162 } else if (!device_id_) {
163 clients_pending_on_filter_[handler] = capability;
164 } else {
165 handler->OnStarted(this);
166 if (state_ == video_capture::kStarted) {
167 if (capability.width > current_params_.width ||
168 capability.height > current_params_.height) {
169 StopDevice();
170 DVLOG(1) << "StartCapture: Got client with higher resolution ("
171 << capability.width << ", " << capability.height << ") "
172 << "after started, try to restart.";
173 clients_pending_on_restart_[handler] = capability;
174 } else {
175 if (device_info_available_) {
176 handler->OnDeviceInfoReceived(this, device_info_);
177 }
178
179 clients_[handler] = capability;
180 }
181 } else if (state_ == video_capture::kStopping) {
182 clients_pending_on_restart_[handler] = capability;
183 DVLOG(1) << "StartCapture: Got new resolution ("
184 << capability.width << ", " << capability.height << ") "
185 << ", during stopping.";
186 } else {
187 clients_[handler] = capability;
188 DCHECK_EQ(clients_.size(), 1ul);
zunger 2012/07/10 23:34:30 Expected value has to be on the left or the error
wjia(left Chromium) 2012/07/12 22:57:30 I checked how DCHECK_EQ is defined in Chromium and
189 video_type_ = capability.color;
190 current_params_.width = capability.width;
191 current_params_.height = capability.height;
192 current_params_.frame_per_second = capability.frame_rate;
193 DVLOG(1) << "StartCapture: starting with first resolution ("
194 << current_params_.width << "," << current_params_.height << ")";
195
196 StartCaptureInternal();
197 }
159 } 198 }
160
161 ClientInfo::iterator it1 = clients_pending_on_filter_.find(handler);
162 ClientInfo::iterator it2 = clients_pending_on_restart_.find(handler);
163 if (it1 != clients_pending_on_filter_.end() ||
164 it2 != clients_pending_on_restart_.end() ||
165 clients_.find(handler) != clients_.end() ) {
166 // This client has started.
167 return;
168 }
169
170 if (!device_id_) {
171 clients_pending_on_filter_[handler] = capability;
172 return;
173 }
174
175 handler->OnStarted(this);
176 if (state_ == video_capture::kStarted) {
177 if (capability.width > current_params_.width ||
178 capability.height > current_params_.height) {
179 StopDevice();
180 DVLOG(1) << "StartCapture: Got client with higher resolution ("
181 << capability.width << ", " << capability.height << ") "
182 << "after started, try to restart.";
183 clients_pending_on_restart_[handler] = capability;
184 return;
185 }
186
187 if (device_info_available_) {
188 handler->OnDeviceInfoReceived(this, device_info_);
189 }
190
191 clients_[handler] = capability;
192 return;
193 }
194
195 if (state_ == video_capture::kStopping) {
196 clients_pending_on_restart_[handler] = capability;
197 DVLOG(1) << "StartCapture: Got new resolution ("
198 << capability.width << ", " << capability.height << ") "
199 << ", during stopping.";
200 return;
201 }
202
203 clients_[handler] = capability;
204 DCHECK_EQ(clients_.size(), 1ul);
205 video_type_ = capability.color;
206 current_params_.width = capability.width;
207 current_params_.height = capability.height;
208 current_params_.frame_per_second = capability.frame_rate;
209 DVLOG(1) << "StartCapture: starting with first resolution ("
210 << current_params_.width << ", " << current_params_.height << ")";
211
212 StartCaptureInternal();
213 } 199 }
214 200
215 void VideoCaptureImpl::DoStopCapture( 201 void VideoCaptureImpl::DoStopCaptureOnCaptureThread(
216 media::VideoCapture::EventHandler* handler) { 202 media::VideoCapture::EventHandler* handler) {
217 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 203 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
218 204
zunger 2012/07/10 23:34:30 You may want to comment why this is an OR and we'r
wjia(left Chromium) 2012/07/12 22:57:30 I am not sure if I understand the comment. This fu
219 ClientInfo::iterator it = clients_pending_on_filter_.find(handler); 205 RemoveClient(handler, clients_pending_on_filter_) ||
220 if (it != clients_pending_on_filter_.end()) { 206 RemoveClient(handler, clients_pending_on_restart_) ||
221 handler->OnStopped(this); 207 RemoveClient(handler, clients_);
222 handler->OnRemoved(this);
223 clients_pending_on_filter_.erase(it);
224 return;
225 }
226 it = clients_pending_on_restart_.find(handler);
227 if (it != clients_pending_on_restart_.end()) {
228 handler->OnStopped(this);
229 handler->OnRemoved(this);
230 clients_pending_on_filter_.erase(it);
231 return;
232 }
233
234 if (clients_.find(handler) == clients_.end())
235 return;
236
237 clients_.erase(handler);
238 208
239 if (clients_.empty()) { 209 if (clients_.empty()) {
240 DVLOG(1) << "StopCapture: No more client, stopping ..."; 210 DVLOG(1) << "StopCapture: No more client, stopping ...";
241 StopDevice(); 211 StopDevice();
242 } 212 }
243 handler->OnStopped(this);
244 handler->OnRemoved(this);
245 } 213 }
246 214
247 void VideoCaptureImpl::DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) { 215 void VideoCaptureImpl::DoFeedBufferOnCaptureThread(
216 scoped_refptr<VideoFrameBuffer> buffer) {
248 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 217 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
249 218
250 CachedDIB::iterator it; 219 CachedDIB::iterator it;
251 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) { 220 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); ++it) {
252 if (buffer == it->second->mapped_memory) 221 if (buffer == it->second->mapped_memory)
253 break; 222 break;
254 } 223 }
255 224
256 DCHECK(it != cached_dibs_.end()); 225 if (it != cached_dibs_.end() && it->second) {
257 DCHECK_GT(it->second->references, 0); 226 DCHECK_GT(it->second->references, 0);
258 it->second->references--; 227 --it->second->references;
259 if (it->second->references == 0) { 228 if (it->second->references == 0) {
260 Send(new VideoCaptureHostMsg_BufferReady(device_id_, it->first)); 229 Send(new VideoCaptureHostMsg_BufferReady(device_id_, it->first));
230 }
261 } 231 }
262 } 232 }
263 233
264 void VideoCaptureImpl::DoBufferCreated( 234 void VideoCaptureImpl::DoBufferCreatedOnCaptureThread(
265 base::SharedMemoryHandle handle, 235 base::SharedMemoryHandle handle,
266 int length, int buffer_id) { 236 int length, int buffer_id) {
267 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 237 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
268 DCHECK(device_info_available_); 238 DCHECK(device_info_available_);
269 239
270 media::VideoCapture::VideoFrameBuffer* buffer; 240 media::VideoCapture::VideoFrameBuffer* buffer;
271 DCHECK(cached_dibs_.find(buffer_id) == cached_dibs_.end()); 241 DCHECK(cached_dibs_.find(buffer_id) == cached_dibs_.end());
272 242
273 base::SharedMemory* dib = new base::SharedMemory(handle, false); 243 base::SharedMemory* dib = new base::SharedMemory(handle, false);
274 dib->Map(length); 244 dib->Map(length);
275 buffer = new VideoFrameBuffer(); 245 buffer = new VideoFrameBuffer();
276 buffer->memory_pointer = static_cast<uint8*>(dib->memory()); 246 buffer->memory_pointer = static_cast<uint8*>(dib->memory());
277 buffer->buffer_size = length; 247 buffer->buffer_size = length;
278 buffer->width = device_info_.width; 248 buffer->width = device_info_.width;
279 buffer->height = device_info_.height; 249 buffer->height = device_info_.height;
280 buffer->stride = device_info_.width; 250 buffer->stride = device_info_.width;
281 251
282 DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer); 252 DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer);
283 cached_dibs_[buffer_id] = dib_buffer; 253 cached_dibs_[buffer_id] = dib_buffer;
284 } 254 }
285 255
286 void VideoCaptureImpl::DoBufferReceived(int buffer_id, base::Time timestamp) { 256 void VideoCaptureImpl::DoBufferReceivedOnCaptureThread(
257 int buffer_id, base::Time timestamp) {
287 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 258 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
288 259
289 if (state_ != video_capture::kStarted) { 260 if (state_ != video_capture::kStarted) {
290 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); 261 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id));
291 return; 262 return;
292 } 263 }
293 264
294 media::VideoCapture::VideoFrameBuffer* buffer; 265 media::VideoCapture::VideoFrameBuffer* buffer;
295 DCHECK(cached_dibs_.find(buffer_id) != cached_dibs_.end()); 266 DCHECK(cached_dibs_.find(buffer_id) != cached_dibs_.end());
296 buffer = cached_dibs_[buffer_id]->mapped_memory; 267 buffer = cached_dibs_[buffer_id]->mapped_memory;
297 buffer->timestamp = timestamp; 268 buffer->timestamp = timestamp;
298 269
299 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { 270 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) {
300 it->first->OnBufferReady(this, buffer); 271 it->first->OnBufferReady(this, buffer);
301 } 272 }
302 cached_dibs_[buffer_id]->references = clients_.size(); 273 cached_dibs_[buffer_id]->references = clients_.size();
303 } 274 }
304 275
305 void VideoCaptureImpl::DoStateChanged(video_capture::State state) { 276 void VideoCaptureImpl::DoStateChangedOnCaptureThread(
277 video_capture::State state) {
306 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 278 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
307 279
308 switch (state) { 280 switch (state) {
309 case video_capture::kStarted: 281 case video_capture::kStarted:
310 break; 282 break;
311 case video_capture::kStopped: 283 case video_capture::kStopped:
312 state_ = video_capture::kStopped; 284 state_ = video_capture::kStopped;
313 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; 285 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_;
314 STLDeleteValues(&cached_dibs_); 286 STLDeleteValues(&cached_dibs_);
315 if (!clients_.empty() || !clients_pending_on_restart_.empty()) 287 if (!clients_.empty() || !clients_pending_on_restart_.empty())
316 RestartCapture(); 288 RestartCapture();
317 break; 289 break;
318 case video_capture::kPaused: 290 case video_capture::kPaused:
319 for (ClientInfo::iterator it = clients_.begin(); 291 for (ClientInfo::iterator it = clients_.begin();
320 it != clients_.end(); it++) { 292 it != clients_.end(); ++it) {
321 it->first->OnPaused(this); 293 it->first->OnPaused(this);
322 } 294 }
323 break; 295 break;
324 case video_capture::kError: 296 case video_capture::kError:
325 DVLOG(1) << "OnStateChanged: error!, device_id = " << device_id_; 297 DVLOG(1) << "OnStateChanged: error!, device_id = " << device_id_;
326 for (ClientInfo::iterator it = clients_.begin(); 298 for (ClientInfo::iterator it = clients_.begin();
327 it != clients_.end(); it++) { 299 it != clients_.end(); ++it) {
328 // TODO(wjia): browser process would send error code. 300 // TODO(wjia): browser process would send error code.
329 it->first->OnError(this, 1); 301 it->first->OnError(this, 1);
330 it->first->OnRemoved(this); 302 it->first->OnRemoved(this);
331 } 303 }
332 clients_.clear(); 304 clients_.clear();
333 state_ = video_capture::kError; 305 state_ = video_capture::kError;
334 break; 306 break;
335 default: 307 default:
336 break; 308 break;
337 } 309 }
338 } 310 }
339 311
340 void VideoCaptureImpl::DoDeviceInfoReceived( 312 void VideoCaptureImpl::DoDeviceInfoReceivedOnCaptureThread(
341 const media::VideoCaptureParams& device_info) { 313 const media::VideoCaptureParams& device_info) {
342 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 314 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
343 DCHECK(!ClientHasDIB()); 315 DCHECK(!ClientHasDIB());
344 316
345 STLDeleteValues(&cached_dibs_); 317 STLDeleteValues(&cached_dibs_);
346 318
347 device_info_ = device_info; 319 device_info_ = device_info;
348 device_info_available_ = true; 320 device_info_available_ = true;
349 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { 321 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) {
350 it->first->OnDeviceInfoReceived(this, device_info); 322 it->first->OnDeviceInfoReceived(this, device_info);
351 } 323 }
352 } 324 }
353 325
354 void VideoCaptureImpl::DoDelegateAdded(int32 device_id) { 326 void VideoCaptureImpl::DoDelegateAddedOnCaptureThread(int32 device_id) {
355 DVLOG(1) << "DoDelegateAdded: device_id " << device_id; 327 DVLOG(1) << "DoDelegateAdded: device_id " << device_id;
356 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 328 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
357 329
358 device_id_ = device_id; 330 device_id_ = device_id;
359 for (ClientInfo::iterator it = clients_pending_on_filter_.begin(); 331 for (ClientInfo::iterator it = clients_pending_on_filter_.begin();
360 it != clients_pending_on_filter_.end(); ) { 332 it != clients_pending_on_filter_.end(); ) {
361 media::VideoCapture::EventHandler* handler = it->first; 333 media::VideoCapture::EventHandler* handler = it->first;
362 const media::VideoCaptureCapability capability = it->second; 334 const media::VideoCaptureCapability capability = it->second;
363 clients_pending_on_filter_.erase(it++); 335 clients_pending_on_filter_.erase(it++);
364 StartCapture(handler, capability); 336 StartCapture(handler, capability);
(...skipping 11 matching lines...) Expand all
376 } 348 }
377 } 349 }
378 350
379 void VideoCaptureImpl::RestartCapture() { 351 void VideoCaptureImpl::RestartCapture() {
380 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 352 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
381 DCHECK_EQ(state_, video_capture::kStopped); 353 DCHECK_EQ(state_, video_capture::kStopped);
382 354
383 int width = 0; 355 int width = 0;
384 int height = 0; 356 int height = 0;
385 for (ClientInfo::iterator it = clients_.begin(); 357 for (ClientInfo::iterator it = clients_.begin();
386 it != clients_.end(); it++) { 358 it != clients_.end(); ++it) {
387 if (it->second.width > width) 359 width = std::max(width, it->second.width);
388 width = it->second.width; 360 height = std::max(height, it->second.height);
389 if (it->second.height > height)
390 height = it->second.height;
391 } 361 }
392 for (ClientInfo::iterator it = clients_pending_on_restart_.begin(); 362 for (ClientInfo::iterator it = clients_pending_on_restart_.begin();
393 it != clients_pending_on_restart_.end(); ) { 363 it != clients_pending_on_restart_.end(); ) {
394 if (it->second.width > width) 364 width = std::max(width, it->second.width);
395 width = it->second.width; 365 height = std::max(height, it->second.height);
396 if (it->second.height > height)
397 height = it->second.height;
398 clients_[it->first] = it->second; 366 clients_[it->first] = it->second;
399 clients_pending_on_restart_.erase(it++); 367 clients_pending_on_restart_.erase(it++);
400 } 368 }
401 current_params_.width = width; 369 current_params_.width = width;
402 current_params_.height = height; 370 current_params_.height = height;
403 DVLOG(1) << "RestartCapture, " << current_params_.width << ", " 371 DVLOG(1) << "RestartCapture, " << current_params_.width << ", "
404 << current_params_.height; 372 << current_params_.height;
405 StartCaptureInternal(); 373 StartCaptureInternal();
406 } 374 }
407 375
(...skipping 16 matching lines...) Expand all
424 capture_message_loop_proxy_->PostTask(FROM_HERE, task); 392 capture_message_loop_proxy_->PostTask(FROM_HERE, task);
425 } 393 }
426 394
427 void VideoCaptureImpl::Send(IPC::Message* message) { 395 void VideoCaptureImpl::Send(IPC::Message* message) {
428 io_message_loop_proxy_->PostTask(FROM_HERE, 396 io_message_loop_proxy_->PostTask(FROM_HERE,
429 base::Bind(base::IgnoreResult(&VideoCaptureMessageFilter::Send), 397 base::Bind(base::IgnoreResult(&VideoCaptureMessageFilter::Send),
430 message_filter_.get(), message)); 398 message_filter_.get(), message));
431 } 399 }
432 400
433 bool VideoCaptureImpl::ClientHasDIB() { 401 bool VideoCaptureImpl::ClientHasDIB() {
402 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
434 CachedDIB::iterator it; 403 CachedDIB::iterator it;
435 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) { 404 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); ++it) {
zunger 2012/07/10 23:34:30 for (CachedDIB::iterator it ...) or even for (co
wjia(left Chromium) 2012/07/12 22:57:30 Done. Can not use auto since the compiler doesn't
436 if (it->second->references > 0) 405 if (it->second->references > 0)
437 return true; 406 return true;
438 } 407 }
439 return false; 408 return false;
440 } 409 }
410
411 bool VideoCaptureImpl::RemoveClient(
412 media::VideoCapture::EventHandler* handler,
413 ClientInfo& clients) {
zunger 2012/07/10 23:34:30 No non-const references! Use a pointer.
zunger 2012/07/10 23:34:30 This function can be const. (Make every function c
wjia(left Chromium) 2012/07/12 22:57:30 Done.
wjia(left Chromium) 2012/07/12 22:57:30 This function RemoveClient() can't be const since
414 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
415 bool found = false;
416
417 ClientInfo::iterator it = clients.find(handler);
418 if (it != clients.end()) {
419 handler->OnStopped(this);
420 handler->OnRemoved(this);
421 clients.erase(it);
422 found = true;
423 }
424 return found;
425 }
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698