Chromium Code Reviews| 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 // Notes about usage of this object by VideoCaptureImplManager. | 5 // Notes about usage of this object by VideoCaptureImplManager. |
| 6 // | 6 // |
| 7 // VideoCaptureImplManager access this object by using a Unretained() | 7 // VideoCaptureImplManager access this object by using a Unretained() |
| 8 // binding and tasks on the IO thread. It is then important that | 8 // binding and tasks on the IO thread. It is then important that |
| 9 // VideoCaptureImpl never post task to itself. All operations must be | 9 // VideoCaptureImpl never post task to itself. All operations must be |
| 10 // synchronous. | 10 // synchronous. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 VideoCaptureImpl::VideoCaptureImpl( | 45 VideoCaptureImpl::VideoCaptureImpl( |
| 46 const media::VideoCaptureSessionId session_id, | 46 const media::VideoCaptureSessionId session_id, |
| 47 VideoCaptureMessageFilter* filter) | 47 VideoCaptureMessageFilter* filter) |
| 48 : message_filter_(filter), | 48 : message_filter_(filter), |
| 49 device_id_(0), | 49 device_id_(0), |
| 50 session_id_(session_id), | 50 session_id_(session_id), |
| 51 suspended_(false), | 51 suspended_(false), |
| 52 state_(VIDEO_CAPTURE_STATE_STOPPED), | 52 state_(VIDEO_CAPTURE_STATE_STOPPED), |
| 53 weak_factory_(this) { | 53 weak_factory_(this) { |
| 54 DCHECK(filter); | 54 DCHECK(filter); |
| 55 render_io_thread_checker_.DetachFromThread(); | |
| 56 } | 55 } |
| 57 | 56 |
| 58 VideoCaptureImpl::~VideoCaptureImpl() { | 57 VideoCaptureImpl::~VideoCaptureImpl() { |
| 59 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 58 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 60 } | 59 } |
| 61 | 60 |
| 62 void VideoCaptureImpl::Init() { | 61 void VideoCaptureImpl::Init() { |
| 63 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 62 // For creating callbacks in unittest, this class may be constructed from a |
| 63 // different thread than the IO thread, e.g. wherever unittest runs on. | |
| 64 // Therefore, this function should define the thread ownership. | |
| 65 io_message_loop_ = base::MessageLoopProxy::current(); | |
|
mcasas
2015/03/16 20:34:06
My optimisation-seeker-me chills when seeing a mem
emircan
2015/03/19 00:40:44
I see there is no use for it in release builds. Th
| |
| 64 message_filter_->AddDelegate(this); | 66 message_filter_->AddDelegate(this); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void VideoCaptureImpl::DeInit() { | 69 void VideoCaptureImpl::DeInit() { |
| 68 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 70 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 69 if (state_ == VIDEO_CAPTURE_STATE_STARTED) | 71 if (state_ == VIDEO_CAPTURE_STATE_STARTED) |
| 70 Send(new VideoCaptureHostMsg_Stop(device_id_)); | 72 Send(new VideoCaptureHostMsg_Stop(device_id_)); |
| 71 message_filter_->RemoveDelegate(this); | 73 message_filter_->RemoveDelegate(this); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void VideoCaptureImpl::SuspendCapture(bool suspend) { | 76 void VideoCaptureImpl::SuspendCapture(bool suspend) { |
| 75 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 77 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 76 Send(suspend ? | 78 Send(suspend ? |
| 77 static_cast<IPC::Message*>(new VideoCaptureHostMsg_Pause(device_id_)) : | 79 static_cast<IPC::Message*>(new VideoCaptureHostMsg_Pause(device_id_)) : |
| 78 static_cast<IPC::Message*>( | 80 static_cast<IPC::Message*>( |
| 79 new VideoCaptureHostMsg_Resume(device_id_, session_id_, params_))); | 81 new VideoCaptureHostMsg_Resume(device_id_, session_id_, params_))); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void VideoCaptureImpl::StartCapture( | 84 void VideoCaptureImpl::StartCapture( |
| 83 int client_id, | 85 int client_id, |
| 84 const media::VideoCaptureParams& params, | 86 const media::VideoCaptureParams& params, |
| 85 const VideoCaptureStateUpdateCB& state_update_cb, | 87 const VideoCaptureStateUpdateCB& state_update_cb, |
| 86 const VideoCaptureDeliverFrameCB& deliver_frame_cb) { | 88 const VideoCaptureDeliverFrameCB& deliver_frame_cb) { |
| 87 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 89 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 88 ClientInfo client_info; | 90 ClientInfo client_info; |
| 89 client_info.params = params; | 91 client_info.params = params; |
| 90 client_info.state_update_cb = state_update_cb; | 92 client_info.state_update_cb = state_update_cb; |
| 91 client_info.deliver_frame_cb = deliver_frame_cb; | 93 client_info.deliver_frame_cb = deliver_frame_cb; |
| 92 | 94 |
| 93 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { | 95 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { |
| 94 state_update_cb.Run(VIDEO_CAPTURE_STATE_ERROR); | 96 state_update_cb.Run(VIDEO_CAPTURE_STATE_ERROR); |
| 95 } else if (clients_pending_on_filter_.count(client_id) || | 97 } else if (clients_pending_on_filter_.count(client_id) || |
| 96 clients_pending_on_restart_.count(client_id) || | 98 clients_pending_on_restart_.count(client_id) || |
| 97 clients_.count(client_id)) { | 99 clients_.count(client_id)) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 125 } | 127 } |
| 126 DVLOG(1) << "StartCapture: starting with first resolution " | 128 DVLOG(1) << "StartCapture: starting with first resolution " |
| 127 << params_.requested_format.frame_size.ToString(); | 129 << params_.requested_format.frame_size.ToString(); |
| 128 first_frame_timestamp_ = base::TimeTicks(); | 130 first_frame_timestamp_ = base::TimeTicks(); |
| 129 StartCaptureInternal(); | 131 StartCaptureInternal(); |
| 130 } | 132 } |
| 131 } | 133 } |
| 132 } | 134 } |
| 133 | 135 |
| 134 void VideoCaptureImpl::StopCapture(int client_id) { | 136 void VideoCaptureImpl::StopCapture(int client_id) { |
| 135 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 137 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 136 | 138 |
| 137 // A client ID can be in only one client list. | 139 // A client ID can be in only one client list. |
| 138 // If this ID is in any client list, we can just remove it from | 140 // If this ID is in any client list, we can just remove it from |
| 139 // that client list and don't have to run the other following RemoveClient(). | 141 // that client list and don't have to run the other following RemoveClient(). |
| 140 if (!RemoveClient(client_id, &clients_pending_on_filter_)) { | 142 if (!RemoveClient(client_id, &clients_pending_on_filter_)) { |
| 141 if (!RemoveClient(client_id, &clients_pending_on_restart_)) { | 143 if (!RemoveClient(client_id, &clients_pending_on_restart_)) { |
| 142 RemoveClient(client_id, &clients_); | 144 RemoveClient(client_id, &clients_); |
| 143 } | 145 } |
| 144 } | 146 } |
| 145 | 147 |
| 146 if (clients_.empty()) { | 148 if (clients_.empty()) { |
| 147 DVLOG(1) << "StopCapture: No more client, stopping ..."; | 149 DVLOG(1) << "StopCapture: No more client, stopping ..."; |
| 148 StopDevice(); | 150 StopDevice(); |
| 149 client_buffers_.clear(); | 151 client_buffers_.clear(); |
| 150 weak_factory_.InvalidateWeakPtrs(); | 152 weak_factory_.InvalidateWeakPtrs(); |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 | 155 |
| 154 void VideoCaptureImpl::GetDeviceSupportedFormats( | 156 void VideoCaptureImpl::GetDeviceSupportedFormats( |
| 155 const VideoCaptureDeviceFormatsCB& callback) { | 157 const VideoCaptureDeviceFormatsCB& callback) { |
| 156 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 158 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 157 device_formats_cb_queue_.push_back(callback); | 159 device_formats_cb_queue_.push_back(callback); |
| 158 if (device_formats_cb_queue_.size() == 1) | 160 if (device_formats_cb_queue_.size() == 1) |
| 159 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, | 161 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, |
| 160 session_id_)); | 162 session_id_)); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void VideoCaptureImpl::GetDeviceFormatsInUse( | 165 void VideoCaptureImpl::GetDeviceFormatsInUse( |
| 164 const VideoCaptureDeviceFormatsCB& callback) { | 166 const VideoCaptureDeviceFormatsCB& callback) { |
| 165 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 167 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 166 device_formats_in_use_cb_queue_.push_back(callback); | 168 device_formats_in_use_cb_queue_.push_back(callback); |
| 167 if (device_formats_in_use_cb_queue_.size() == 1) | 169 if (device_formats_in_use_cb_queue_.size() == 1) |
| 168 Send( | 170 Send( |
| 169 new VideoCaptureHostMsg_GetDeviceFormatsInUse(device_id_, session_id_)); | 171 new VideoCaptureHostMsg_GetDeviceFormatsInUse(device_id_, session_id_)); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void VideoCaptureImpl::OnBufferCreated( | 174 void VideoCaptureImpl::OnBufferCreated( |
| 173 base::SharedMemoryHandle handle, | 175 base::SharedMemoryHandle handle, |
| 174 int length, int buffer_id) { | 176 int length, int buffer_id) { |
| 175 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 177 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 176 | 178 |
| 177 // In case client calls StopCapture before the arrival of created buffer, | 179 // In case client calls StopCapture before the arrival of created buffer, |
| 178 // just close this buffer and return. | 180 // just close this buffer and return. |
| 179 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { | 181 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { |
| 180 base::SharedMemory::CloseHandle(handle); | 182 base::SharedMemory::CloseHandle(handle); |
| 181 return; | 183 return; |
| 182 } | 184 } |
| 183 | 185 |
| 184 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory(handle, false)); | 186 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory(handle, false)); |
| 185 if (!shm->Map(length)) { | 187 if (!shm->Map(length)) { |
| 186 DLOG(ERROR) << "OnBufferCreated: Map failed."; | 188 DLOG(ERROR) << "OnBufferCreated: Map failed."; |
| 187 return; | 189 return; |
| 188 } | 190 } |
| 189 | 191 |
| 190 bool inserted = | 192 bool inserted = |
| 191 client_buffers_.insert(std::make_pair( | 193 client_buffers_.insert(std::make_pair( |
| 192 buffer_id, | 194 buffer_id, |
| 193 new ClientBuffer(shm.Pass(), | 195 new ClientBuffer(shm.Pass(), |
| 194 length))).second; | 196 length))).second; |
| 195 DCHECK(inserted); | 197 DCHECK(inserted); |
| 196 } | 198 } |
| 197 | 199 |
| 198 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { | 200 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { |
| 199 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 201 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 200 | 202 |
| 201 const ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 203 const ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); |
| 202 if (iter == client_buffers_.end()) | 204 if (iter == client_buffers_.end()) |
| 203 return; | 205 return; |
| 204 | 206 |
| 205 DCHECK(!iter->second.get() || iter->second->HasOneRef()) | 207 DCHECK(!iter->second.get() || iter->second->HasOneRef()) |
| 206 << "Instructed to delete buffer we are still using."; | 208 << "Instructed to delete buffer we are still using."; |
| 207 client_buffers_.erase(iter); | 209 client_buffers_.erase(iter); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void VideoCaptureImpl::OnBufferReceived(int buffer_id, | 212 void VideoCaptureImpl::OnBufferReceived(int buffer_id, |
| 211 const gfx::Size& coded_size, | 213 const gfx::Size& coded_size, |
| 212 const gfx::Rect& visible_rect, | 214 const gfx::Rect& visible_rect, |
| 213 base::TimeTicks timestamp, | 215 base::TimeTicks timestamp, |
| 214 const base::DictionaryValue& metadata) { | 216 const base::DictionaryValue& metadata) { |
| 215 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 217 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 216 | 218 |
| 217 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 219 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
| 218 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); | 220 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); |
| 219 return; | 221 return; |
| 220 } | 222 } |
| 221 | 223 |
| 222 if (first_frame_timestamp_.is_null()) | 224 if (first_frame_timestamp_.is_null()) |
| 223 first_frame_timestamp_ = timestamp; | 225 first_frame_timestamp_ = timestamp; |
| 224 | 226 |
| 225 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 227 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 254 for (const auto& client : clients_) | 256 for (const auto& client : clients_) |
| 255 client.second.deliver_frame_cb.Run(frame, timestamp); | 257 client.second.deliver_frame_cb.Run(frame, timestamp); |
| 256 } | 258 } |
| 257 | 259 |
| 258 void VideoCaptureImpl::OnMailboxBufferReceived( | 260 void VideoCaptureImpl::OnMailboxBufferReceived( |
| 259 int buffer_id, | 261 int buffer_id, |
| 260 const gpu::MailboxHolder& mailbox_holder, | 262 const gpu::MailboxHolder& mailbox_holder, |
| 261 const gfx::Size& packed_frame_size, | 263 const gfx::Size& packed_frame_size, |
| 262 base::TimeTicks timestamp, | 264 base::TimeTicks timestamp, |
| 263 const base::DictionaryValue& metadata) { | 265 const base::DictionaryValue& metadata) { |
| 264 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 266 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 265 | 267 |
| 266 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 268 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
| 267 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); | 269 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); |
| 268 return; | 270 return; |
| 269 } | 271 } |
| 270 | 272 |
| 271 if (first_frame_timestamp_.is_null()) | 273 if (first_frame_timestamp_.is_null()) |
| 272 first_frame_timestamp_ = timestamp; | 274 first_frame_timestamp_ = timestamp; |
| 273 | 275 |
| 274 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( | 276 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( |
| 275 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), | 277 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), |
| 276 media::BindToCurrentLoop(base::Bind( | 278 media::BindToCurrentLoop(base::Bind( |
| 277 &VideoCaptureImpl::OnClientBufferFinished, weak_factory_.GetWeakPtr(), | 279 &VideoCaptureImpl::OnClientBufferFinished, weak_factory_.GetWeakPtr(), |
| 278 buffer_id, scoped_refptr<ClientBuffer>())), | 280 buffer_id, scoped_refptr<ClientBuffer>())), |
| 279 packed_frame_size, gfx::Rect(packed_frame_size), packed_frame_size, | 281 packed_frame_size, gfx::Rect(packed_frame_size), packed_frame_size, |
| 280 timestamp - first_frame_timestamp_, false); | 282 timestamp - first_frame_timestamp_, false); |
| 281 frame->metadata()->MergeInternalValuesFrom(metadata); | 283 frame->metadata()->MergeInternalValuesFrom(metadata); |
| 282 | 284 |
| 283 for (const auto& client : clients_) | 285 for (const auto& client : clients_) |
| 284 client.second.deliver_frame_cb.Run(frame, timestamp); | 286 client.second.deliver_frame_cb.Run(frame, timestamp); |
| 285 } | 287 } |
| 286 | 288 |
| 287 void VideoCaptureImpl::OnClientBufferFinished( | 289 void VideoCaptureImpl::OnClientBufferFinished( |
| 288 int buffer_id, | 290 int buffer_id, |
| 289 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 291 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
| 290 uint32 release_sync_point) { | 292 uint32 release_sync_point) { |
| 291 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 293 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 292 Send(new VideoCaptureHostMsg_BufferReady( | 294 Send(new VideoCaptureHostMsg_BufferReady( |
| 293 device_id_, buffer_id, release_sync_point)); | 295 device_id_, buffer_id, release_sync_point)); |
| 294 } | 296 } |
| 295 | 297 |
| 296 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 298 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
| 297 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 299 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 298 | 300 |
| 299 switch (state) { | 301 switch (state) { |
| 300 case VIDEO_CAPTURE_STATE_STARTED: | 302 case VIDEO_CAPTURE_STATE_STARTED: |
| 301 // Camera has started in the browser process. Since we have already | 303 // Camera has started in the browser process. Since we have already |
| 302 // told all clients that we have started there's nothing to do. | 304 // told all clients that we have started there's nothing to do. |
| 303 break; | 305 break; |
| 304 case VIDEO_CAPTURE_STATE_STOPPED: | 306 case VIDEO_CAPTURE_STATE_STOPPED: |
| 305 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 307 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
| 306 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; | 308 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; |
| 307 client_buffers_.clear(); | 309 client_buffers_.clear(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 329 clients_.clear(); | 331 clients_.clear(); |
| 330 state_ = VIDEO_CAPTURE_STATE_ENDED; | 332 state_ = VIDEO_CAPTURE_STATE_ENDED; |
| 331 break; | 333 break; |
| 332 default: | 334 default: |
| 333 break; | 335 break; |
| 334 } | 336 } |
| 335 } | 337 } |
| 336 | 338 |
| 337 void VideoCaptureImpl::OnDeviceSupportedFormatsEnumerated( | 339 void VideoCaptureImpl::OnDeviceSupportedFormatsEnumerated( |
| 338 const media::VideoCaptureFormats& supported_formats) { | 340 const media::VideoCaptureFormats& supported_formats) { |
| 339 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 341 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 340 for (size_t i = 0; i < device_formats_cb_queue_.size(); ++i) | 342 for (size_t i = 0; i < device_formats_cb_queue_.size(); ++i) |
| 341 device_formats_cb_queue_[i].Run(supported_formats); | 343 device_formats_cb_queue_[i].Run(supported_formats); |
| 342 device_formats_cb_queue_.clear(); | 344 device_formats_cb_queue_.clear(); |
| 343 } | 345 } |
| 344 | 346 |
| 345 void VideoCaptureImpl::OnDeviceFormatsInUseReceived( | 347 void VideoCaptureImpl::OnDeviceFormatsInUseReceived( |
| 346 const media::VideoCaptureFormats& formats_in_use) { | 348 const media::VideoCaptureFormats& formats_in_use) { |
| 347 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 349 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 348 for (size_t i = 0; i < device_formats_in_use_cb_queue_.size(); ++i) | 350 for (size_t i = 0; i < device_formats_in_use_cb_queue_.size(); ++i) |
| 349 device_formats_in_use_cb_queue_[i].Run(formats_in_use); | 351 device_formats_in_use_cb_queue_[i].Run(formats_in_use); |
| 350 device_formats_in_use_cb_queue_.clear(); | 352 device_formats_in_use_cb_queue_.clear(); |
| 351 } | 353 } |
| 352 | 354 |
| 353 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) { | 355 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) { |
| 354 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 356 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 355 DVLOG(1) << "OnDelegateAdded: device_id " << device_id; | 357 DVLOG(1) << "OnDelegateAdded: device_id " << device_id; |
| 356 | 358 |
| 357 device_id_ = device_id; | 359 device_id_ = device_id; |
| 358 ClientInfoMap::iterator it = clients_pending_on_filter_.begin(); | 360 ClientInfoMap::iterator it = clients_pending_on_filter_.begin(); |
| 359 while (it != clients_pending_on_filter_.end()) { | 361 while (it != clients_pending_on_filter_.end()) { |
| 360 const int client_id = it->first; | 362 const int client_id = it->first; |
| 361 const ClientInfo client_info = it->second; | 363 const ClientInfo client_info = it->second; |
| 362 clients_pending_on_filter_.erase(it++); | 364 clients_pending_on_filter_.erase(it++); |
| 363 StartCapture(client_id, client_info.params, client_info.state_update_cb, | 365 StartCapture(client_id, client_info.params, client_info.state_update_cb, |
| 364 client_info.deliver_frame_cb); | 366 client_info.deliver_frame_cb); |
| 365 } | 367 } |
| 366 } | 368 } |
| 367 | 369 |
| 368 void VideoCaptureImpl::StopDevice() { | 370 void VideoCaptureImpl::StopDevice() { |
| 369 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 371 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 370 | 372 |
| 371 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 373 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
| 372 state_ = VIDEO_CAPTURE_STATE_STOPPING; | 374 state_ = VIDEO_CAPTURE_STATE_STOPPING; |
| 373 Send(new VideoCaptureHostMsg_Stop(device_id_)); | 375 Send(new VideoCaptureHostMsg_Stop(device_id_)); |
| 374 params_.requested_format.frame_size.SetSize(0, 0); | 376 params_.requested_format.frame_size.SetSize(0, 0); |
| 375 } | 377 } |
| 376 } | 378 } |
| 377 | 379 |
| 378 void VideoCaptureImpl::RestartCapture() { | 380 void VideoCaptureImpl::RestartCapture() { |
| 379 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 381 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 380 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED); | 382 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED); |
| 381 | 383 |
| 382 int width = 0; | 384 int width = 0; |
| 383 int height = 0; | 385 int height = 0; |
| 384 clients_.insert(clients_pending_on_restart_.begin(), | 386 clients_.insert(clients_pending_on_restart_.begin(), |
| 385 clients_pending_on_restart_.end()); | 387 clients_pending_on_restart_.end()); |
| 386 clients_pending_on_restart_.clear(); | 388 clients_pending_on_restart_.clear(); |
| 387 for (const auto& client : clients_) { | 389 for (const auto& client : clients_) { |
| 388 width = std::max(width, | 390 width = std::max(width, |
| 389 client.second.params.requested_format.frame_size.width()); | 391 client.second.params.requested_format.frame_size.width()); |
| 390 height = std::max( | 392 height = std::max( |
| 391 height, client.second.params.requested_format.frame_size.height()); | 393 height, client.second.params.requested_format.frame_size.height()); |
| 392 } | 394 } |
| 393 params_.requested_format.frame_size.SetSize(width, height); | 395 params_.requested_format.frame_size.SetSize(width, height); |
| 394 DVLOG(1) << "RestartCapture, " | 396 DVLOG(1) << "RestartCapture, " |
| 395 << params_.requested_format.frame_size.ToString(); | 397 << params_.requested_format.frame_size.ToString(); |
| 396 StartCaptureInternal(); | 398 StartCaptureInternal(); |
| 397 } | 399 } |
| 398 | 400 |
| 399 void VideoCaptureImpl::StartCaptureInternal() { | 401 void VideoCaptureImpl::StartCaptureInternal() { |
| 400 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 402 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 401 DCHECK(device_id_); | 403 DCHECK(device_id_); |
| 402 | 404 |
| 403 Send(new VideoCaptureHostMsg_Start(device_id_, session_id_, params_)); | 405 Send(new VideoCaptureHostMsg_Start(device_id_, session_id_, params_)); |
| 404 state_ = VIDEO_CAPTURE_STATE_STARTED; | 406 state_ = VIDEO_CAPTURE_STATE_STARTED; |
| 405 } | 407 } |
| 406 | 408 |
| 407 void VideoCaptureImpl::Send(IPC::Message* message) { | 409 void VideoCaptureImpl::Send(IPC::Message* message) { |
| 408 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 410 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 409 message_filter_->Send(message); | 411 message_filter_->Send(message); |
| 410 } | 412 } |
| 411 | 413 |
| 412 bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) { | 414 bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) { |
| 413 DCHECK(render_io_thread_checker_.CalledOnValidThread()); | 415 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 414 bool found = false; | 416 bool found = false; |
| 415 | 417 |
| 416 const ClientInfoMap::iterator it = clients->find(client_id); | 418 const ClientInfoMap::iterator it = clients->find(client_id); |
| 417 if (it != clients->end()) { | 419 if (it != clients->end()) { |
| 418 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); | 420 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); |
| 419 clients->erase(it); | 421 clients->erase(it); |
| 420 found = true; | 422 found = true; |
| 421 } | 423 } |
| 422 return found; | 424 return found; |
| 423 } | 425 } |
| 424 | 426 |
| 425 } // namespace content | 427 } // namespace content |
| OLD | NEW |