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

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller.cc

Issue 1017503002: VideoCaptureHost/VideoCaptureControllerEventHandler cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unneeded BindToCurrentLoop() 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 (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/browser/renderer_host/media/video_capture_controller.h" 5 #include "content/browser/renderer_host/media/video_capture_controller.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 gl_helper->WaitSyncPoint(sync_point); 70 gl_helper->WaitSyncPoint(sync_point);
71 SyncPointClientImpl client(gl_helper); 71 SyncPointClientImpl client(gl_helper);
72 video_frame->UpdateReleaseSyncPoint(&client); 72 video_frame->UpdateReleaseSyncPoint(&client);
73 } 73 }
74 #endif 74 #endif
75 } 75 }
76 76
77 } // anonymous namespace 77 } // anonymous namespace
78 78
79 struct VideoCaptureController::ControllerClient { 79 struct VideoCaptureController::ControllerClient {
80 ControllerClient(const VideoCaptureControllerID& id, 80 ControllerClient(VideoCaptureControllerID id,
81 VideoCaptureControllerEventHandler* handler, 81 VideoCaptureControllerEventHandler* handler,
82 base::ProcessHandle render_process, 82 base::ProcessHandle render_process,
83 media::VideoCaptureSessionId session_id, 83 media::VideoCaptureSessionId session_id,
84 const media::VideoCaptureParams& params) 84 const media::VideoCaptureParams& params)
85 : controller_id(id), 85 : controller_id(id),
86 event_handler(handler), 86 event_handler(handler),
87 render_process_handle(render_process), 87 render_process_handle(render_process),
88 session_id(session_id), 88 session_id(session_id),
89 parameters(params), 89 parameters(params),
90 session_closed(false), 90 session_closed(false),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 format)); 152 format));
153 DVLOG(1) << "TextureWrapper, format " << format.ToString(); 153 DVLOG(1) << "TextureWrapper, format " << format.ToString();
154 } 154 }
155 #endif 155 #endif
156 return make_scoped_ptr( 156 return make_scoped_ptr(
157 new VideoCaptureDeviceClient(this->GetWeakPtrForIOThread(), 157 new VideoCaptureDeviceClient(this->GetWeakPtrForIOThread(),
158 buffer_pool_)); 158 buffer_pool_));
159 } 159 }
160 160
161 void VideoCaptureController::AddClient( 161 void VideoCaptureController::AddClient(
162 const VideoCaptureControllerID& id, 162 VideoCaptureControllerID id,
163 VideoCaptureControllerEventHandler* event_handler, 163 VideoCaptureControllerEventHandler* event_handler,
164 base::ProcessHandle render_process, 164 base::ProcessHandle render_process,
165 media::VideoCaptureSessionId session_id, 165 media::VideoCaptureSessionId session_id,
166 const media::VideoCaptureParams& params) { 166 const media::VideoCaptureParams& params) {
167 DCHECK_CURRENTLY_ON(BrowserThread::IO); 167 DCHECK_CURRENTLY_ON(BrowserThread::IO);
168 DVLOG(1) << "VideoCaptureController::AddClient, id " << id.device_id 168 DVLOG(1) << "VideoCaptureController::AddClient, id " << id
169 << ", " << params.requested_format.frame_size.ToString() 169 << ", " << params.requested_format.frame_size.ToString()
170 << ", " << params.requested_format.frame_rate 170 << ", " << params.requested_format.frame_rate
171 << ", " << session_id 171 << ", " << session_id
172 << ")"; 172 << ")";
173 173
174 // If this is the first client added to the controller, cache the parameters. 174 // If this is the first client added to the controller, cache the parameters.
175 if (!controller_clients_.size()) 175 if (!controller_clients_.size())
176 video_capture_format_ = params.requested_format; 176 video_capture_format_ = params.requested_format;
177 177
178 // Signal error in case device is already in error state. 178 // Signal error in case device is already in error state.
(...skipping 10 matching lines...) Expand all
189 id, event_handler, render_process, session_id, params); 189 id, event_handler, render_process, session_id, params);
190 // If we already have gotten frame_info from the device, repeat it to the new 190 // If we already have gotten frame_info from the device, repeat it to the new
191 // client. 191 // client.
192 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 192 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
193 controller_clients_.push_back(client); 193 controller_clients_.push_back(client);
194 return; 194 return;
195 } 195 }
196 } 196 }
197 197
198 int VideoCaptureController::RemoveClient( 198 int VideoCaptureController::RemoveClient(
199 const VideoCaptureControllerID& id, 199 VideoCaptureControllerID id,
200 VideoCaptureControllerEventHandler* event_handler) { 200 VideoCaptureControllerEventHandler* event_handler) {
201 DCHECK_CURRENTLY_ON(BrowserThread::IO); 201 DCHECK_CURRENTLY_ON(BrowserThread::IO);
202 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id.device_id; 202 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id;
203 203
204 ControllerClient* client = FindClient(id, event_handler, controller_clients_); 204 ControllerClient* client = FindClient(id, event_handler, controller_clients_);
205 if (!client) 205 if (!client)
206 return kInvalidMediaCaptureSessionId; 206 return kInvalidMediaCaptureSessionId;
207 207
208 // Take back all buffers held by the |client|. 208 // Take back all buffers held by the |client|.
209 for (ControllerClient::ActiveBufferMap::iterator buffer_it = 209 for (const auto& buffer : client->active_buffers)
210 client->active_buffers.begin(); 210 buffer_pool_->RelinquishConsumerHold(buffer.first, 1);
211 buffer_it != client->active_buffers.end();
212 ++buffer_it) {
213 buffer_pool_->RelinquishConsumerHold(buffer_it->first, 1);
214 }
215 client->active_buffers.clear(); 211 client->active_buffers.clear();
216 212
217 int session_id = client->session_id; 213 int session_id = client->session_id;
218 controller_clients_.remove(client); 214 controller_clients_.remove(client);
219 delete client; 215 delete client;
220 216
221 return session_id; 217 return session_id;
222 } 218 }
223 219
224 void VideoCaptureController::PauseOrResumeClient( 220 void VideoCaptureController::PauseOrResumeClient(
225 const VideoCaptureControllerID& id, 221 VideoCaptureControllerID id,
226 VideoCaptureControllerEventHandler* event_handler, 222 VideoCaptureControllerEventHandler* event_handler,
227 bool pause) { 223 bool pause) {
228 DCHECK_CURRENTLY_ON(BrowserThread::IO); 224 DCHECK_CURRENTLY_ON(BrowserThread::IO);
229 DVLOG(1) << "VideoCaptureController::PauseOrResumeClient, id " 225 DVLOG(1) << "VideoCaptureController::PauseOrResumeClient, id "
230 << id.device_id << ", " << pause; 226 << id << ", " << pause;
231 227
232 ControllerClient* client = FindClient(id, event_handler, controller_clients_); 228 ControllerClient* client = FindClient(id, event_handler, controller_clients_);
233 if (!client) 229 if (!client)
234 return; 230 return;
235 231
236 DCHECK(client->paused != pause); 232 DCHECK(client->paused != pause);
237 client->paused = pause; 233 client->paused = pause;
238 } 234 }
239 235
240 void VideoCaptureController::StopSession(int session_id) { 236 void VideoCaptureController::StopSession(int session_id) {
241 DCHECK_CURRENTLY_ON(BrowserThread::IO); 237 DCHECK_CURRENTLY_ON(BrowserThread::IO);
242 DVLOG(1) << "VideoCaptureController::StopSession, id " << session_id; 238 DVLOG(1) << "VideoCaptureController::StopSession, id " << session_id;
243 239
244 ControllerClient* client = FindClient(session_id, controller_clients_); 240 ControllerClient* client = FindClient(session_id, controller_clients_);
245 241
246 if (client) { 242 if (client) {
247 client->session_closed = true; 243 client->session_closed = true;
248 client->event_handler->OnEnded(client->controller_id); 244 client->event_handler->OnEnded(client->controller_id);
249 } 245 }
250 } 246 }
251 247
252 void VideoCaptureController::ReturnBuffer( 248 void VideoCaptureController::ReturnBuffer(
253 const VideoCaptureControllerID& id, 249 VideoCaptureControllerID id,
254 VideoCaptureControllerEventHandler* event_handler, 250 VideoCaptureControllerEventHandler* event_handler,
255 int buffer_id, 251 int buffer_id,
256 uint32 sync_point) { 252 uint32 sync_point) {
257 DCHECK_CURRENTLY_ON(BrowserThread::IO); 253 DCHECK_CURRENTLY_ON(BrowserThread::IO);
258 254
259 ControllerClient* client = FindClient(id, event_handler, controller_clients_); 255 ControllerClient* client = FindClient(id, event_handler, controller_clients_);
260 256
261 // If this buffer is not held by this client, or this client doesn't exist 257 // If this buffer is not held by this client, or this client doesn't exist
262 // in controller, do nothing. 258 // in controller, do nothing.
263 ControllerClient::ActiveBufferMap::iterator iter; 259 ControllerClient::ActiveBufferMap::iterator iter;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 has_received_frames_ = true; 365 has_received_frames_ = true;
370 } 366 }
371 367
372 buffer_pool_->HoldForConsumers(buffer->id(), count); 368 buffer_pool_->HoldForConsumers(buffer->id(), count);
373 } 369 }
374 370
375 void VideoCaptureController::DoErrorOnIOThread() { 371 void VideoCaptureController::DoErrorOnIOThread() {
376 DCHECK_CURRENTLY_ON(BrowserThread::IO); 372 DCHECK_CURRENTLY_ON(BrowserThread::IO);
377 state_ = VIDEO_CAPTURE_STATE_ERROR; 373 state_ = VIDEO_CAPTURE_STATE_ERROR;
378 374
379 for (ControllerClients::iterator client_it = controller_clients_.begin(); 375 for (const auto* client : controller_clients_) {
380 client_it != controller_clients_.end(); ++client_it) {
381 ControllerClient* client = *client_it;
382 if (client->session_closed) 376 if (client->session_closed)
383 continue; 377 continue;
384
385 client->event_handler->OnError(client->controller_id); 378 client->event_handler->OnError(client->controller_id);
386 } 379 }
387 } 380 }
388 381
389 void VideoCaptureController::DoLogOnIOThread(const std::string& message) { 382 void VideoCaptureController::DoLogOnIOThread(const std::string& message) {
390 DCHECK_CURRENTLY_ON(BrowserThread::IO); 383 DCHECK_CURRENTLY_ON(BrowserThread::IO);
391 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); 384 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message);
392 } 385 }
393 386
394 void VideoCaptureController::DoBufferDestroyedOnIOThread( 387 void VideoCaptureController::DoBufferDestroyedOnIOThread(
395 int buffer_id_to_drop) { 388 int buffer_id_to_drop) {
396 DCHECK_CURRENTLY_ON(BrowserThread::IO); 389 DCHECK_CURRENTLY_ON(BrowserThread::IO);
397 390
398 for (ControllerClients::iterator client_it = controller_clients_.begin(); 391 for (auto* client : controller_clients_) {
399 client_it != controller_clients_.end(); ++client_it) {
400 ControllerClient* client = *client_it;
401 if (client->session_closed) 392 if (client->session_closed)
402 continue; 393 continue;
403 394
404 if (client->known_buffers.erase(buffer_id_to_drop)) { 395 if (client->known_buffers.erase(buffer_id_to_drop)) {
405 client->event_handler->OnBufferDestroyed(client->controller_id, 396 client->event_handler->OnBufferDestroyed(client->controller_id,
406 buffer_id_to_drop); 397 buffer_id_to_drop);
407 } 398 }
408 } 399 }
409 } 400 }
410 401
411 VideoCaptureController::ControllerClient* 402 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient(
412 VideoCaptureController::FindClient( 403 VideoCaptureControllerID id,
413 const VideoCaptureControllerID& id,
414 VideoCaptureControllerEventHandler* handler, 404 VideoCaptureControllerEventHandler* handler,
415 const ControllerClients& clients) { 405 const ControllerClients& clients) {
416 for (ControllerClients::const_iterator client_it = clients.begin(); 406 for (auto* client : clients) {
417 client_it != clients.end(); ++client_it) { 407 if (client->controller_id == id && client->event_handler == handler)
418 if ((*client_it)->controller_id == id && 408 return client;
419 (*client_it)->event_handler == handler) {
420 return *client_it;
421 }
422 } 409 }
423 return NULL; 410 return NULL;
424 } 411 }
425 412
426 VideoCaptureController::ControllerClient* 413 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient(
427 VideoCaptureController::FindClient(
428 int session_id, 414 int session_id,
429 const ControllerClients& clients) { 415 const ControllerClients& clients) {
430 for (ControllerClients::const_iterator client_it = clients.begin(); 416 for (auto client : clients) {
431 client_it != clients.end(); ++client_it) { 417 if (client->session_id == session_id)
432 if ((*client_it)->session_id == session_id) { 418 return client;
433 return *client_it;
434 }
435 } 419 }
436 return NULL; 420 return NULL;
437 } 421 }
438 422
439 int VideoCaptureController::GetClientCount() const { 423 int VideoCaptureController::GetClientCount() const {
440 DCHECK_CURRENTLY_ON(BrowserThread::IO); 424 DCHECK_CURRENTLY_ON(BrowserThread::IO);
441 return controller_clients_.size(); 425 return controller_clients_.size();
442 } 426 }
443 427
444 int VideoCaptureController::GetActiveClientCount() const { 428 int VideoCaptureController::GetActiveClientCount() const {
445 DCHECK_CURRENTLY_ON(BrowserThread::IO); 429 DCHECK_CURRENTLY_ON(BrowserThread::IO);
446 int active_client_count = 0; 430 int active_client_count = 0;
447 for (ControllerClient* client : controller_clients_) { 431 for (ControllerClient* client : controller_clients_) {
448 if (!client->paused) 432 if (!client->paused)
449 ++active_client_count; 433 ++active_client_count;
450 } 434 }
451 return active_client_count; 435 return active_client_count;
452 } 436 }
453 437
454 } // namespace content 438 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698