OLD | NEW |
---|---|
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 ControllerClient(const VideoCaptureControllerID& id, | 96 ControllerClient(const VideoCaptureControllerID& id, |
97 VideoCaptureControllerEventHandler* handler, | 97 VideoCaptureControllerEventHandler* handler, |
98 base::ProcessHandle render_process, | 98 base::ProcessHandle render_process, |
99 media::VideoCaptureSessionId session_id, | 99 media::VideoCaptureSessionId session_id, |
100 const media::VideoCaptureParams& params) | 100 const media::VideoCaptureParams& params) |
101 : controller_id(id), | 101 : controller_id(id), |
102 event_handler(handler), | 102 event_handler(handler), |
103 render_process_handle(render_process), | 103 render_process_handle(render_process), |
104 session_id(session_id), | 104 session_id(session_id), |
105 parameters(params), | 105 parameters(params), |
106 session_closed(false) {} | 106 session_closed(false), |
107 paused(false) {} | |
107 | 108 |
108 ~ControllerClient() {} | 109 ~ControllerClient() {} |
109 | 110 |
110 // ID used for identifying this object. | 111 // ID used for identifying this object. |
111 const VideoCaptureControllerID controller_id; | 112 const VideoCaptureControllerID controller_id; |
112 VideoCaptureControllerEventHandler* const event_handler; | 113 VideoCaptureControllerEventHandler* const event_handler; |
113 | 114 |
114 // Handle to the render process that will receive the capture buffers. | 115 // Handle to the render process that will receive the capture buffers. |
115 const base::ProcessHandle render_process_handle; | 116 const base::ProcessHandle render_process_handle; |
116 const media::VideoCaptureSessionId session_id; | 117 const media::VideoCaptureSessionId session_id; |
(...skipping 11 matching lines...) Expand all Loading... | |
128 // transitions to true as soon as StopSession() occurs, at which point the | 129 // transitions to true as soon as StopSession() occurs, at which point the |
129 // client is sent an OnEnded() event. However, because the client retains a | 130 // client is sent an OnEnded() event. However, because the client retains a |
130 // VideoCaptureController* pointer, its ControllerClient entry lives on until | 131 // VideoCaptureController* pointer, its ControllerClient entry lives on until |
131 // it unregisters itself via RemoveClient(), which may happen asynchronously. | 132 // it unregisters itself via RemoveClient(), which may happen asynchronously. |
132 // | 133 // |
133 // TODO(nick): If we changed the semantics of VideoCaptureHost so that | 134 // TODO(nick): If we changed the semantics of VideoCaptureHost so that |
134 // OnEnded() events were processed synchronously (with the RemoveClient() done | 135 // OnEnded() events were processed synchronously (with the RemoveClient() done |
135 // implicitly), we could avoid tracking this state here in the Controller, and | 136 // implicitly), we could avoid tracking this state here in the Controller, and |
136 // simplify the code in both places. | 137 // simplify the code in both places. |
137 bool session_closed; | 138 bool session_closed; |
139 | |
140 // Indicates whether the client is paused, if true, VideoCaptureController | |
141 // stops updating its buffer. | |
142 bool paused; | |
138 }; | 143 }; |
139 | 144 |
140 // Receives events from the VideoCaptureDevice and posts them to a | 145 // Receives events from the VideoCaptureDevice and posts them to a |
141 // VideoCaptureController on the IO thread. An instance of this class may safely | 146 // VideoCaptureController on the IO thread. An instance of this class may safely |
142 // outlive its target VideoCaptureController. | 147 // outlive its target VideoCaptureController. |
143 // | 148 // |
144 // Methods of this class may be called from any thread, and in practice will | 149 // Methods of this class may be called from any thread, and in practice will |
145 // often be called on some auxiliary thread depending on the platform and the | 150 // often be called on some auxiliary thread depending on the platform and the |
146 // device type; including, for example, the DirectShow thread on Windows, the | 151 // device type; including, for example, the DirectShow thread on Windows, the |
147 // v4l2_thread on Linux, and the UI thread for tab capture. | 152 // v4l2_thread on Linux, and the UI thread for tab capture. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 } | 267 } |
263 client->active_buffers.clear(); | 268 client->active_buffers.clear(); |
264 | 269 |
265 int session_id = client->session_id; | 270 int session_id = client->session_id; |
266 controller_clients_.remove(client); | 271 controller_clients_.remove(client); |
267 delete client; | 272 delete client; |
268 | 273 |
269 return session_id; | 274 return session_id; |
270 } | 275 } |
271 | 276 |
277 void VideoCaptureController::PauseOrResumeClient( | |
278 const VideoCaptureControllerID& id, | |
279 VideoCaptureControllerEventHandler* event_handler, | |
280 bool pause) { | |
281 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
282 DVLOG(1) << "VideoCaptureController::PauseOrResumeClient, id " | |
283 << id.device_id << ", " << pause; | |
284 | |
285 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | |
286 if (!client) | |
287 return; | |
tommi (sloooow) - chröme
2014/10/01 07:17:03
should the event handler be notified of this someh
michaelbai
2014/10/01 22:09:33
That's what I wondered in the first place, I think
tommi (sloooow) - chröme
2014/10/02 11:10:39
Acknowledged.
| |
288 | |
289 client->paused = pause; | |
290 } | |
291 | |
272 void VideoCaptureController::StopSession(int session_id) { | 292 void VideoCaptureController::StopSession(int session_id) { |
273 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 293 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
274 DVLOG(1) << "VideoCaptureController::StopSession, id " << session_id; | 294 DVLOG(1) << "VideoCaptureController::StopSession, id " << session_id; |
275 | 295 |
276 ControllerClient* client = FindClient(session_id, controller_clients_); | 296 ControllerClient* client = FindClient(session_id, controller_clients_); |
277 | 297 |
278 if (client) { | 298 if (client) { |
279 client->session_closed = true; | 299 client->session_closed = true; |
280 client->event_handler->OnEnded(client->controller_id); | 300 client->event_handler->OnEnded(client->controller_id); |
281 } | 301 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 const scoped_refptr<media::VideoFrame>& frame, | 586 const scoped_refptr<media::VideoFrame>& frame, |
567 base::TimeTicks timestamp) { | 587 base::TimeTicks timestamp) { |
568 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 588 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
569 DCHECK_NE(buffer->id(), VideoCaptureBufferPool::kInvalidId); | 589 DCHECK_NE(buffer->id(), VideoCaptureBufferPool::kInvalidId); |
570 | 590 |
571 int count = 0; | 591 int count = 0; |
572 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 592 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
573 for (ControllerClients::iterator client_it = controller_clients_.begin(); | 593 for (ControllerClients::iterator client_it = controller_clients_.begin(); |
574 client_it != controller_clients_.end(); ++client_it) { | 594 client_it != controller_clients_.end(); ++client_it) { |
575 ControllerClient* client = *client_it; | 595 ControllerClient* client = *client_it; |
576 if (client->session_closed) | 596 if (client->session_closed || client->paused) |
577 continue; | 597 continue; |
578 | 598 |
579 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { | 599 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { |
580 client->event_handler->OnMailboxBufferReady(client->controller_id, | 600 client->event_handler->OnMailboxBufferReady(client->controller_id, |
581 buffer->id(), | 601 buffer->id(), |
582 *frame->mailbox_holder(), | 602 *frame->mailbox_holder(), |
583 buffer_format, | 603 buffer_format, |
584 timestamp); | 604 timestamp); |
585 } else { | 605 } else { |
586 bool is_new_buffer = client->known_buffers.insert(buffer->id()).second; | 606 bool is_new_buffer = client->known_buffers.insert(buffer->id()).second; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 } | 702 } |
683 } | 703 } |
684 return NULL; | 704 return NULL; |
685 } | 705 } |
686 | 706 |
687 int VideoCaptureController::GetClientCount() { | 707 int VideoCaptureController::GetClientCount() { |
688 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 708 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
689 return controller_clients_.size(); | 709 return controller_clients_.size(); |
690 } | 710 } |
691 | 711 |
712 int VideoCaptureController::GetActiveClientCount() { | |
713 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
714 int active_client_count = 0; | |
715 for (ControllerClient* client : controller_clients_) { | |
tommi (sloooow) - chröme
2014/10/01 07:17:03
oooh...! :)
michaelbai
2014/10/01 22:09:33
I am happy that how simple it is :)
| |
716 if (!client->paused) | |
717 active_client_count++; | |
tommi (sloooow) - chröme
2014/10/01 07:17:02
++active_client_count
michaelbai
2014/10/01 22:09:33
Done.
| |
718 } | |
719 return active_client_count; | |
720 } | |
721 | |
692 } // namespace content | 722 } // namespace content |
OLD | NEW |