| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 207 |
| 208 void VideoCaptureImpl::OnBufferReceived(int buffer_id, | 208 void VideoCaptureImpl::OnBufferReceived(int buffer_id, |
| 209 const media::VideoCaptureFormat& format, | 209 const media::VideoCaptureFormat& format, |
| 210 base::TimeTicks timestamp) { | 210 base::TimeTicks timestamp) { |
| 211 DCHECK(thread_checker_.CalledOnValidThread()); | 211 DCHECK(thread_checker_.CalledOnValidThread()); |
| 212 | 212 |
| 213 // The capture pipeline supports only I420 for now. | 213 // The capture pipeline supports only I420 for now. |
| 214 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420); | 214 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420); |
| 215 | 215 |
| 216 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 216 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
| 217 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); | 217 Send(new VideoCaptureHostMsg_BufferReady( |
| 218 device_id_, buffer_id, std::vector<uint32>())); |
| 218 return; | 219 return; |
| 219 } | 220 } |
| 220 | 221 |
| 221 last_frame_format_ = format; | 222 last_frame_format_ = format; |
| 222 if (first_frame_timestamp_.is_null()) | 223 if (first_frame_timestamp_.is_null()) |
| 223 first_frame_timestamp_ = timestamp; | 224 first_frame_timestamp_ = timestamp; |
| 224 | 225 |
| 225 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 226 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
| 226 TRACE_EVENT_INSTANT2( | 227 TRACE_EVENT_INSTANT2( |
| 227 "cast_perf_test", "OnBufferReceived", | 228 "cast_perf_test", "OnBufferReceived", |
| 228 TRACE_EVENT_SCOPE_THREAD, | 229 TRACE_EVENT_SCOPE_THREAD, |
| 229 "timestamp", timestamp.ToInternalValue(), | 230 "timestamp", timestamp.ToInternalValue(), |
| 230 "time_delta", (timestamp - first_frame_timestamp_).ToInternalValue()); | 231 "time_delta", (timestamp - first_frame_timestamp_).ToInternalValue()); |
| 231 | 232 |
| 232 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 233 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); |
| 233 DCHECK(iter != client_buffers_.end()); | 234 DCHECK(iter != client_buffers_.end()); |
| 234 scoped_refptr<ClientBuffer> buffer = iter->second; | 235 scoped_refptr<ClientBuffer> buffer = iter->second; |
| 235 scoped_refptr<media::VideoFrame> frame = | 236 scoped_refptr<media::VideoFrame> frame = |
| 236 media::VideoFrame::WrapExternalPackedMemory( | 237 media::VideoFrame::WrapExternalPackedMemory( |
| 237 media::VideoFrame::I420, | 238 media::VideoFrame::I420, |
| 238 last_frame_format_.frame_size, | 239 last_frame_format_.frame_size, |
| 239 gfx::Rect(last_frame_format_.frame_size), | 240 gfx::Rect(last_frame_format_.frame_size), |
| 240 last_frame_format_.frame_size, | 241 last_frame_format_.frame_size, |
| 241 reinterpret_cast<uint8*>(buffer->buffer->memory()), | 242 reinterpret_cast<uint8*>(buffer->buffer->memory()), |
| 242 buffer->buffer_size, | 243 buffer->buffer_size, |
| 243 buffer->buffer->handle(), | 244 buffer->buffer->handle(), |
| 244 timestamp - first_frame_timestamp_, | 245 timestamp - first_frame_timestamp_, |
| 245 media::BindToCurrentLoop(base::Bind( | 246 media::BindToCurrentLoop( |
| 246 &VideoCaptureImpl::OnClientBufferFinished, | 247 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
| 247 weak_factory_.GetWeakPtr(), | 248 weak_factory_.GetWeakPtr(), |
| 248 buffer_id, | 249 buffer_id, |
| 249 buffer, | 250 buffer, |
| 250 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass())))); | 251 std::vector<uint32>()))); |
| 251 | 252 |
| 252 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); | 253 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); |
| 253 ++it) { | 254 ++it) { |
| 254 it->second.deliver_frame_cb.Run(frame, format); | 255 it->second.deliver_frame_cb.Run(frame, format); |
| 255 } | 256 } |
| 256 } | 257 } |
| 257 | 258 |
| 258 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } | 259 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } |
| 259 | 260 |
| 260 void VideoCaptureImpl::OnMailboxBufferReceived( | 261 void VideoCaptureImpl::OnMailboxBufferReceived( |
| 261 int buffer_id, | 262 int buffer_id, |
| 262 const gpu::MailboxHolder& mailbox_holder, | 263 const gpu::MailboxHolder& mailbox_holder, |
| 263 const media::VideoCaptureFormat& format, | 264 const media::VideoCaptureFormat& format, |
| 264 base::TimeTicks timestamp) { | 265 base::TimeTicks timestamp) { |
| 265 DCHECK(thread_checker_.CalledOnValidThread()); | 266 DCHECK(thread_checker_.CalledOnValidThread()); |
| 266 | 267 |
| 267 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 268 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
| 268 Send(new VideoCaptureHostMsg_BufferReady( | 269 Send(new VideoCaptureHostMsg_BufferReady( |
| 269 device_id_, buffer_id, mailbox_holder.sync_point)); | 270 device_id_, buffer_id, std::vector<uint32>())); |
| 270 return; | 271 return; |
| 271 } | 272 } |
| 272 | 273 |
| 273 last_frame_format_ = format; | 274 last_frame_format_ = format; |
| 274 if (first_frame_timestamp_.is_null()) | 275 if (first_frame_timestamp_.is_null()) |
| 275 first_frame_timestamp_ = timestamp; | 276 first_frame_timestamp_ = timestamp; |
| 276 | 277 |
| 277 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( | 278 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( |
| 278 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), | 279 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), |
| 279 media::BindToCurrentLoop( | 280 media::BindToCurrentLoop( |
| 280 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 281 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
| 281 weak_factory_.GetWeakPtr(), | 282 weak_factory_.GetWeakPtr(), |
| 282 buffer_id, | 283 buffer_id, |
| 283 scoped_refptr<ClientBuffer>())), | 284 scoped_refptr<ClientBuffer>())), |
| 284 last_frame_format_.frame_size, | 285 last_frame_format_.frame_size, |
| 285 gfx::Rect(last_frame_format_.frame_size), | 286 gfx::Rect(last_frame_format_.frame_size), |
| 286 last_frame_format_.frame_size, | 287 last_frame_format_.frame_size, |
| 287 timestamp - first_frame_timestamp_, | 288 timestamp - first_frame_timestamp_, |
| 288 base::Bind(&NullReadPixelsCB)); | 289 base::Bind(&NullReadPixelsCB)); |
| 289 | 290 |
| 290 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); | 291 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); |
| 291 ++it) { | 292 ++it) { |
| 292 it->second.deliver_frame_cb.Run(frame, format); | 293 it->second.deliver_frame_cb.Run(frame, format); |
| 293 } | 294 } |
| 294 } | 295 } |
| 295 | 296 |
| 296 void VideoCaptureImpl::OnClientBufferFinished( | 297 void VideoCaptureImpl::OnClientBufferFinished( |
| 297 int buffer_id, | 298 int buffer_id, |
| 298 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 299 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
| 299 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 300 const std::vector<uint32>& release_sync_points) { |
| 300 DCHECK(thread_checker_.CalledOnValidThread()); | 301 DCHECK(thread_checker_.CalledOnValidThread()); |
| 301 const uint32 sync_point = (mailbox_holder ? mailbox_holder->sync_point : 0); | 302 Send(new VideoCaptureHostMsg_BufferReady( |
| 302 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, sync_point)); | 303 device_id_, buffer_id, release_sync_points)); |
| 303 } | 304 } |
| 304 | 305 |
| 305 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 306 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
| 306 DCHECK(thread_checker_.CalledOnValidThread()); | 307 DCHECK(thread_checker_.CalledOnValidThread()); |
| 307 | 308 |
| 308 switch (state) { | 309 switch (state) { |
| 309 case VIDEO_CAPTURE_STATE_STARTED: | 310 case VIDEO_CAPTURE_STATE_STARTED: |
| 310 // Camera has started in the browser process. Since we have already | 311 // Camera has started in the browser process. Since we have already |
| 311 // told all clients that we have started there's nothing to do. | 312 // told all clients that we have started there's nothing to do. |
| 312 break; | 313 break; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 ClientInfoMap::iterator it = clients->find(client_id); | 436 ClientInfoMap::iterator it = clients->find(client_id); |
| 436 if (it != clients->end()) { | 437 if (it != clients->end()) { |
| 437 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); | 438 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); |
| 438 clients->erase(it); | 439 clients->erase(it); |
| 439 found = true; | 440 found = true; |
| 440 } | 441 } |
| 441 return found; | 442 return found; |
| 442 } | 443 } |
| 443 | 444 |
| 444 } // namespace content | 445 } // namespace content |
| OLD | NEW |