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/renderer/media/video_capture_impl.h" | 5 #include "content/renderer/media/video_capture_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "content/child/child_process.h" | 9 #include "content/child/child_process.h" |
10 #include "content/common/media/video_capture_messages.h" | 10 #include "content/common/media/video_capture_messages.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 VideoCaptureImpl::VideoCaptureImpl( | 43 VideoCaptureImpl::VideoCaptureImpl( |
44 const media::VideoCaptureSessionId session_id, | 44 const media::VideoCaptureSessionId session_id, |
45 VideoCaptureMessageFilter* filter) | 45 VideoCaptureMessageFilter* filter) |
46 : VideoCapture(), | 46 : VideoCapture(), |
47 message_filter_(filter), | 47 message_filter_(filter), |
48 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()), | 48 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()), |
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_this_factory_(this) { | 53 weak_factory_(this) { |
54 DCHECK(filter); | 54 DCHECK(filter); |
55 } | 55 } |
56 | 56 |
57 VideoCaptureImpl::~VideoCaptureImpl() {} | 57 VideoCaptureImpl::~VideoCaptureImpl() {} |
58 | 58 |
59 void VideoCaptureImpl::Init() { | 59 void VideoCaptureImpl::Init() { |
60 io_message_loop_proxy_->PostTask(FROM_HERE, | 60 io_message_loop_proxy_->PostTask(FROM_HERE, |
61 base::Bind(&VideoCaptureImpl::InitOnIOThread, | 61 base::Bind(&VideoCaptureImpl::InitOnIOThread, |
62 base::Unretained(this))); | 62 base::Unretained(this))); |
63 } | 63 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // If this handler is in any client list, we can just remove it from | 178 // If this handler is in any client list, we can just remove it from |
179 // that client list and don't have to run the other following RemoveClient(). | 179 // that client list and don't have to run the other following RemoveClient(). |
180 RemoveClient(handler, &clients_pending_on_filter_) || | 180 RemoveClient(handler, &clients_pending_on_filter_) || |
181 RemoveClient(handler, &clients_pending_on_restart_) || | 181 RemoveClient(handler, &clients_pending_on_restart_) || |
182 RemoveClient(handler, &clients_); | 182 RemoveClient(handler, &clients_); |
183 | 183 |
184 if (clients_.empty()) { | 184 if (clients_.empty()) { |
185 DVLOG(1) << "StopCapture: No more client, stopping ..."; | 185 DVLOG(1) << "StopCapture: No more client, stopping ..."; |
186 StopDevice(); | 186 StopDevice(); |
187 client_buffers_.clear(); | 187 client_buffers_.clear(); |
188 weak_this_factory_.InvalidateWeakPtrs(); | 188 weak_factory_.InvalidateWeakPtrs(); |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 void VideoCaptureImpl::GetDeviceSupportedFormatsOnIOThread( | 192 void VideoCaptureImpl::GetDeviceSupportedFormatsOnIOThread( |
193 const DeviceFormatsCallback& callback) { | 193 const DeviceFormatsCallback& callback) { |
194 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 194 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
195 device_formats_callback_queue_.push_back(callback); | 195 device_formats_callback_queue_.push_back(callback); |
196 if (device_formats_callback_queue_.size() == 1) | 196 if (device_formats_callback_queue_.size() == 1) |
197 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, | 197 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, |
198 session_id_)); | 198 session_id_)); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 media::VideoFrame::I420, | 270 media::VideoFrame::I420, |
271 last_frame_format_.frame_size, | 271 last_frame_format_.frame_size, |
272 gfx::Rect(last_frame_format_.frame_size), | 272 gfx::Rect(last_frame_format_.frame_size), |
273 last_frame_format_.frame_size, | 273 last_frame_format_.frame_size, |
274 reinterpret_cast<uint8*>(buffer->buffer->memory()), | 274 reinterpret_cast<uint8*>(buffer->buffer->memory()), |
275 buffer->buffer_size, | 275 buffer->buffer_size, |
276 buffer->buffer->handle(), | 276 buffer->buffer->handle(), |
277 timestamp - first_frame_timestamp_, | 277 timestamp - first_frame_timestamp_, |
278 media::BindToCurrentLoop(base::Bind( | 278 media::BindToCurrentLoop(base::Bind( |
279 &VideoCaptureImpl::OnClientBufferFinished, | 279 &VideoCaptureImpl::OnClientBufferFinished, |
280 weak_this_factory_.GetWeakPtr(), | 280 weak_factory_.GetWeakPtr(), |
281 buffer_id, | 281 buffer_id, |
282 buffer, | 282 buffer, |
283 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass())))); | 283 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass())))); |
284 | 284 |
285 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 285 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
286 it->first->OnFrameReady(this, frame); | 286 it->first->OnFrameReady(this, frame); |
287 } | 287 } |
288 | 288 |
289 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } | 289 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } |
290 | 290 |
(...skipping 11 matching lines...) Expand all Loading... |
302 } | 302 } |
303 | 303 |
304 last_frame_format_ = format; | 304 last_frame_format_ = format; |
305 if (first_frame_timestamp_.is_null()) | 305 if (first_frame_timestamp_.is_null()) |
306 first_frame_timestamp_ = timestamp; | 306 first_frame_timestamp_ = timestamp; |
307 | 307 |
308 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( | 308 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( |
309 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), | 309 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), |
310 media::BindToCurrentLoop( | 310 media::BindToCurrentLoop( |
311 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 311 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
312 weak_this_factory_.GetWeakPtr(), | 312 weak_factory_.GetWeakPtr(), |
313 buffer_id, | 313 buffer_id, |
314 scoped_refptr<ClientBuffer>())), | 314 scoped_refptr<ClientBuffer>())), |
315 last_frame_format_.frame_size, | 315 last_frame_format_.frame_size, |
316 gfx::Rect(last_frame_format_.frame_size), | 316 gfx::Rect(last_frame_format_.frame_size), |
317 last_frame_format_.frame_size, | 317 last_frame_format_.frame_size, |
318 timestamp - first_frame_timestamp_, | 318 timestamp - first_frame_timestamp_, |
319 base::Bind(&NullReadPixelsCB)); | 319 base::Bind(&NullReadPixelsCB)); |
320 | 320 |
321 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 321 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
322 it->first->OnFrameReady(this, frame); | 322 it->first->OnFrameReady(this, frame); |
(...skipping 11 matching lines...) Expand all Loading... |
334 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 334 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
335 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 335 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
336 | 336 |
337 switch (state) { | 337 switch (state) { |
338 case VIDEO_CAPTURE_STATE_STARTED: | 338 case VIDEO_CAPTURE_STATE_STARTED: |
339 break; | 339 break; |
340 case VIDEO_CAPTURE_STATE_STOPPED: | 340 case VIDEO_CAPTURE_STATE_STOPPED: |
341 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 341 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
342 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; | 342 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; |
343 client_buffers_.clear(); | 343 client_buffers_.clear(); |
344 weak_this_factory_.InvalidateWeakPtrs(); | 344 weak_factory_.InvalidateWeakPtrs(); |
345 if (!clients_.empty() || !clients_pending_on_restart_.empty()) | 345 if (!clients_.empty() || !clients_pending_on_restart_.empty()) |
346 RestartCapture(); | 346 RestartCapture(); |
347 break; | 347 break; |
348 case VIDEO_CAPTURE_STATE_PAUSED: | 348 case VIDEO_CAPTURE_STATE_PAUSED: |
349 for (ClientInfo::iterator it = clients_.begin(); | 349 for (ClientInfo::iterator it = clients_.begin(); |
350 it != clients_.end(); ++it) { | 350 it != clients_.end(); ++it) { |
351 it->first->OnPaused(this); | 351 it->first->OnPaused(this); |
352 } | 352 } |
353 break; | 353 break; |
354 case VIDEO_CAPTURE_STATE_ERROR: | 354 case VIDEO_CAPTURE_STATE_ERROR: |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 if (it != clients->end()) { | 464 if (it != clients->end()) { |
465 handler->OnStopped(this); | 465 handler->OnStopped(this); |
466 handler->OnRemoved(this); | 466 handler->OnRemoved(this); |
467 clients->erase(it); | 467 clients->erase(it); |
468 found = true; | 468 found = true; |
469 } | 469 } |
470 return found; | 470 return found; |
471 } | 471 } |
472 | 472 |
473 } // namespace content | 473 } // namespace content |
OLD | NEW |