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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 } | 97 } |
98 | 98 |
99 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { | 99 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { |
100 capture_message_loop_proxy_->PostTask(FROM_HERE, | 100 capture_message_loop_proxy_->PostTask(FROM_HERE, |
101 base::Bind(&VideoCaptureImpl::DoBufferDestroyedOnCaptureThread, | 101 base::Bind(&VideoCaptureImpl::DoBufferDestroyedOnCaptureThread, |
102 base::Unretained(this), buffer_id)); | 102 base::Unretained(this), buffer_id)); |
103 } | 103 } |
104 | 104 |
105 void VideoCaptureImpl::OnBufferReceived( | 105 void VideoCaptureImpl::OnBufferReceived( |
106 int buffer_id, | 106 int buffer_id, |
107 base::Time timestamp, | 107 base::TimeTicks timestamp, |
108 const media::VideoCaptureFormat& format) { | 108 const media::VideoCaptureFormat& format) { |
109 capture_message_loop_proxy_->PostTask(FROM_HERE, | 109 capture_message_loop_proxy_->PostTask(FROM_HERE, |
110 base::Bind(&VideoCaptureImpl::DoBufferReceivedOnCaptureThread, | 110 base::Bind(&VideoCaptureImpl::DoBufferReceivedOnCaptureThread, |
111 base::Unretained(this), buffer_id, timestamp, format)); | 111 base::Unretained(this), buffer_id, timestamp, format)); |
112 } | 112 } |
113 | 113 |
114 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 114 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
115 capture_message_loop_proxy_->PostTask(FROM_HERE, | 115 capture_message_loop_proxy_->PostTask(FROM_HERE, |
116 base::Bind(&VideoCaptureImpl::DoStateChangedOnCaptureThread, | 116 base::Bind(&VideoCaptureImpl::DoStateChangedOnCaptureThread, |
117 base::Unretained(this), state)); | 117 base::Unretained(this), state)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 clients_[handler] = params; | 170 clients_[handler] = params; |
171 DCHECK_EQ(1ul, clients_.size()); | 171 DCHECK_EQ(1ul, clients_.size()); |
172 params_ = params; | 172 params_ = params; |
173 if (params_.requested_format.frame_rate > | 173 if (params_.requested_format.frame_rate > |
174 media::limits::kMaxFramesPerSecond) { | 174 media::limits::kMaxFramesPerSecond) { |
175 params_.requested_format.frame_rate = | 175 params_.requested_format.frame_rate = |
176 media::limits::kMaxFramesPerSecond; | 176 media::limits::kMaxFramesPerSecond; |
177 } | 177 } |
178 DVLOG(1) << "StartCapture: starting with first resolution " | 178 DVLOG(1) << "StartCapture: starting with first resolution " |
179 << params_.requested_format.frame_size.ToString(); | 179 << params_.requested_format.frame_size.ToString(); |
180 | 180 last_frame_timestamp_ = base::TimeTicks(); |
181 StartCaptureInternal(); | 181 StartCaptureInternal(); |
182 } | 182 } |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 void VideoCaptureImpl::DoStopCaptureOnCaptureThread( | 186 void VideoCaptureImpl::DoStopCaptureOnCaptureThread( |
187 media::VideoCapture::EventHandler* handler) { | 187 media::VideoCapture::EventHandler* handler) { |
188 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); | 188 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
189 | 189 |
190 // A handler can be in only one client list. | 190 // A handler can be in only one client list. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 if (iter == client_buffers_.end()) | 235 if (iter == client_buffers_.end()) |
236 return; | 236 return; |
237 | 237 |
238 DCHECK(!iter->second || iter->second->HasOneRef()) | 238 DCHECK(!iter->second || iter->second->HasOneRef()) |
239 << "Instructed to delete buffer we are still using."; | 239 << "Instructed to delete buffer we are still using."; |
240 client_buffers_.erase(iter); | 240 client_buffers_.erase(iter); |
241 } | 241 } |
242 | 242 |
243 void VideoCaptureImpl::DoBufferReceivedOnCaptureThread( | 243 void VideoCaptureImpl::DoBufferReceivedOnCaptureThread( |
244 int buffer_id, | 244 int buffer_id, |
245 base::Time timestamp, | 245 base::TimeTicks timestamp, |
246 const media::VideoCaptureFormat& format) { | 246 const media::VideoCaptureFormat& format) { |
247 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); | 247 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
248 | 248 |
249 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 249 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
250 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); | 250 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); |
251 return; | 251 return; |
252 } | 252 } |
253 | 253 |
254 last_frame_format_ = format; | 254 last_frame_format_ = format; |
255 if (last_frame_timestamp_.is_null()) | |
256 last_frame_timestamp_ = timestamp; | |
255 | 257 |
256 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 258 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); |
257 DCHECK(iter != client_buffers_.end()); | 259 DCHECK(iter != client_buffers_.end()); |
258 scoped_refptr<ClientBuffer> buffer = iter->second; | 260 scoped_refptr<ClientBuffer> buffer = iter->second; |
259 scoped_refptr<media::VideoFrame> frame = | 261 scoped_refptr<media::VideoFrame> frame = |
260 media::VideoFrame::WrapExternalPackedMemory( | 262 media::VideoFrame::WrapExternalPackedMemory( |
261 media::VideoFrame::I420, | 263 media::VideoFrame::I420, |
262 last_frame_format_.frame_size, | 264 last_frame_format_.frame_size, |
263 gfx::Rect(last_frame_format_.frame_size), | 265 gfx::Rect(last_frame_format_.frame_size), |
264 last_frame_format_.frame_size, | 266 last_frame_format_.frame_size, |
265 reinterpret_cast<uint8*>(buffer->buffer->memory()), | 267 reinterpret_cast<uint8*>(buffer->buffer->memory()), |
266 buffer->buffer_size, | 268 buffer->buffer_size, |
267 buffer->buffer->handle(), | 269 buffer->buffer->handle(), |
268 // TODO(sheu): convert VideoCaptureMessageFilter::Delegate to use | 270 timestamp - last_frame_timestamp_, |
miu
2014/01/06 22:39:37
Nice and clean! :-) I like how the first frame h
| |
269 // base::TimeTicks instead of base::Time. http://crbug.com/249215 | |
270 timestamp - base::Time::UnixEpoch(), | |
271 media::BindToLoop( | 271 media::BindToLoop( |
272 capture_message_loop_proxy_, | 272 capture_message_loop_proxy_, |
273 base::Bind( | 273 base::Bind( |
274 &VideoCaptureImpl::DoClientBufferFinishedOnCaptureThread, | 274 &VideoCaptureImpl::DoClientBufferFinishedOnCaptureThread, |
275 weak_this_factory_.GetWeakPtr(), | 275 weak_this_factory_.GetWeakPtr(), |
276 buffer_id, | 276 buffer_id, |
277 buffer))); | 277 buffer))); |
278 | 278 |
279 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) | 279 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) |
280 it->first->OnFrameReady(this, frame); | 280 it->first->OnFrameReady(this, frame); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 if (it != clients->end()) { | 422 if (it != clients->end()) { |
423 handler->OnStopped(this); | 423 handler->OnStopped(this); |
424 handler->OnRemoved(this); | 424 handler->OnRemoved(this); |
425 clients->erase(it); | 425 clients->erase(it); |
426 found = true; | 426 found = true; |
427 } | 427 } |
428 return found; | 428 return found; |
429 } | 429 } |
430 | 430 |
431 } // namespace content | 431 } // namespace content |
OLD | NEW |