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