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

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

Issue 2721113002: getUserMedia: handle the device starting status report. (Closed)
Patch Set: Created 3 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 mojo::ScopedSharedBufferHandle 143 mojo::ScopedSharedBufferHandle
144 VideoCaptureController::BufferContext::CloneHandle() { 144 VideoCaptureController::BufferContext::CloneHandle() {
145 return buffer_handle_->Clone(); 145 return buffer_handle_->Clone();
146 } 146 }
147 147
148 VideoCaptureController::VideoCaptureController() 148 VideoCaptureController::VideoCaptureController()
149 : consumer_feedback_observer_(nullptr), 149 : consumer_feedback_observer_(nullptr),
150 state_(VIDEO_CAPTURE_STATE_STARTED), 150 state_(VIDEO_CAPTURE_STATE_STARTED),
151 has_received_frames_(false), 151 has_received_frames_(false),
152 has_received_onstarted_(false),
152 weak_ptr_factory_(this) { 153 weak_ptr_factory_(this) {
153 DCHECK_CURRENTLY_ON(BrowserThread::IO); 154 DCHECK_CURRENTLY_ON(BrowserThread::IO);
154 } 155 }
155 156
156 VideoCaptureController::~VideoCaptureController() = default; 157 VideoCaptureController::~VideoCaptureController() = default;
157 158
158 base::WeakPtr<VideoCaptureController> 159 base::WeakPtr<VideoCaptureController>
159 VideoCaptureController::GetWeakPtrForIOThread() { 160 VideoCaptureController::GetWeakPtrForIOThread() {
160 return weak_ptr_factory_.GetWeakPtr(); 161 return weak_ptr_factory_.GetWeakPtr();
161 } 162 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Signal error in case device is already in error state. 202 // Signal error in case device is already in error state.
202 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { 203 if (state_ == VIDEO_CAPTURE_STATE_ERROR) {
203 event_handler->OnError(id); 204 event_handler->OnError(id);
204 return; 205 return;
205 } 206 }
206 207
207 // Do nothing if this client has called AddClient before. 208 // Do nothing if this client has called AddClient before.
208 if (FindClient(id, event_handler, controller_clients_)) 209 if (FindClient(id, event_handler, controller_clients_))
209 return; 210 return;
210 211
212 // If the device has reported OnStarted event, report it to this client here.
213 if (has_received_onstarted_)
214 event_handler->OnStarted(id);
215
211 std::unique_ptr<ControllerClient> client = 216 std::unique_ptr<ControllerClient> client =
212 base::MakeUnique<ControllerClient>(id, event_handler, session_id, params); 217 base::MakeUnique<ControllerClient>(id, event_handler, session_id, params);
213 // If we already have gotten frame_info from the device, repeat it to the new 218 // If we already have gotten frame_info from the device, repeat it to the new
214 // client. 219 // client.
215 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 220 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
216 controller_clients_.push_back(std::move(client)); 221 controller_clients_.push_back(std::move(client));
217 return;
218 } 222 }
219 } 223 }
220 224
221 int VideoCaptureController::RemoveClient( 225 int VideoCaptureController::RemoveClient(
222 VideoCaptureControllerID id, 226 VideoCaptureControllerID id,
223 VideoCaptureControllerEventHandler* event_handler) { 227 VideoCaptureControllerEventHandler* event_handler) {
224 DCHECK_CURRENTLY_ON(BrowserThread::IO); 228 DCHECK_CURRENTLY_ON(BrowserThread::IO);
225 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id; 229 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id;
226 230
227 ControllerClient* client = FindClient(id, event_handler, controller_clients_); 231 ControllerClient* client = FindClient(id, event_handler, controller_clients_);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 460 }
457 } 461 }
458 462
459 void VideoCaptureController::OnLog(const std::string& message) { 463 void VideoCaptureController::OnLog(const std::string& message) {
460 DCHECK_CURRENTLY_ON(BrowserThread::IO); 464 DCHECK_CURRENTLY_ON(BrowserThread::IO);
461 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); 465 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message);
462 } 466 }
463 467
464 void VideoCaptureController::OnStarted() { 468 void VideoCaptureController::OnStarted() {
465 DCHECK_CURRENTLY_ON(BrowserThread::IO); 469 DCHECK_CURRENTLY_ON(BrowserThread::IO);
470 has_received_onstarted_ = true;
466 471
467 for (const auto& client : controller_clients_) { 472 for (const auto& client : controller_clients_) {
468 if (client->session_closed) 473 if (client->session_closed)
469 continue; 474 continue;
470 client->event_handler->OnStarted(client->controller_id); 475 client->event_handler->OnStarted(client->controller_id);
471 } 476 }
472 } 477 }
473 478
474 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( 479 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient(
475 VideoCaptureControllerID id, 480 VideoCaptureControllerID id,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (entry_iter != std::end(client->known_buffer_context_ids)) { 542 if (entry_iter != std::end(client->known_buffer_context_ids)) {
538 client->known_buffer_context_ids.erase(entry_iter); 543 client->known_buffer_context_ids.erase(entry_iter);
539 client->event_handler->OnBufferDestroyed( 544 client->event_handler->OnBufferDestroyed(
540 client->controller_id, buffer_context_iter->buffer_context_id()); 545 client->controller_id, buffer_context_iter->buffer_context_id());
541 } 546 }
542 } 547 }
543 buffer_contexts_.erase(buffer_context_iter); 548 buffer_contexts_.erase(buffer_context_iter);
544 } 549 }
545 550
546 } // namespace content 551 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698