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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 201 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 media::VideoCaptureFormat& format, | 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 DCHECK(thread_checker_.CalledOnValidThread()); | 215 DCHECK(thread_checker_.CalledOnValidThread()); |
215 | 216 |
216 // The capture pipeline supports only I420 for now. | |
217 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420); | |
218 | |
219 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 217 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
220 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); | 218 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); |
221 return; | 219 return; |
222 } | 220 } |
223 | 221 |
224 last_frame_format_ = format; | |
225 if (first_frame_timestamp_.is_null()) | 222 if (first_frame_timestamp_.is_null()) |
226 first_frame_timestamp_ = timestamp; | 223 first_frame_timestamp_ = timestamp; |
227 | 224 |
228 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 225 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
229 TRACE_EVENT_INSTANT2( | 226 TRACE_EVENT_INSTANT2( |
230 "cast_perf_test", "OnBufferReceived", | 227 "cast_perf_test", "OnBufferReceived", |
231 TRACE_EVENT_SCOPE_THREAD, | 228 TRACE_EVENT_SCOPE_THREAD, |
232 "timestamp", timestamp.ToInternalValue(), | 229 "timestamp", timestamp.ToInternalValue(), |
233 "time_delta", (timestamp - first_frame_timestamp_).ToInternalValue()); | 230 "time_delta", (timestamp - first_frame_timestamp_).ToInternalValue()); |
234 | 231 |
235 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); | 232 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); |
236 DCHECK(iter != client_buffers_.end()); | 233 DCHECK(iter != client_buffers_.end()); |
237 scoped_refptr<ClientBuffer> buffer = iter->second; | 234 scoped_refptr<ClientBuffer> buffer = iter->second; |
238 scoped_refptr<media::VideoFrame> frame = | 235 scoped_refptr<media::VideoFrame> frame = |
239 media::VideoFrame::WrapExternalPackedMemory( | 236 media::VideoFrame::WrapExternalPackedMemory( |
240 media::VideoFrame::I420, | 237 media::VideoFrame::I420, |
241 last_frame_format_.frame_size, | 238 coded_size, |
242 visible_rect, | 239 visible_rect, |
243 gfx::Size(visible_rect.width(), visible_rect.height()), | 240 gfx::Size(visible_rect.width(), visible_rect.height()), |
244 reinterpret_cast<uint8*>(buffer->buffer->memory()), | 241 reinterpret_cast<uint8*>(buffer->buffer->memory()), |
245 buffer->buffer_size, | 242 buffer->buffer_size, |
246 buffer->buffer->handle(), | 243 buffer->buffer->handle(), |
247 0, | 244 0, |
248 timestamp - first_frame_timestamp_, | 245 timestamp - first_frame_timestamp_, |
249 media::BindToCurrentLoop( | 246 media::BindToCurrentLoop( |
250 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 247 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
251 weak_factory_.GetWeakPtr(), | 248 weak_factory_.GetWeakPtr(), |
252 buffer_id, | 249 buffer_id, |
253 buffer, | 250 buffer, |
254 0))); | 251 0))); |
| 252 frame->metadata()->MergeInternalValuesFrom(metadata); |
255 | 253 |
256 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); | 254 for (const auto& entry : clients_) |
257 ++it) { | 255 entry.second.deliver_frame_cb.Run(frame, timestamp); |
258 it->second.deliver_frame_cb.Run(frame, format, timestamp); | |
259 } | |
260 } | 256 } |
261 | 257 |
262 void VideoCaptureImpl::OnMailboxBufferReceived( | 258 void VideoCaptureImpl::OnMailboxBufferReceived( |
263 int buffer_id, | 259 int buffer_id, |
264 const gpu::MailboxHolder& mailbox_holder, | 260 const gpu::MailboxHolder& mailbox_holder, |
265 const media::VideoCaptureFormat& format, | 261 const gfx::Size& packed_frame_size, |
266 base::TimeTicks timestamp) { | 262 base::TimeTicks timestamp, |
| 263 const base::DictionaryValue& metadata) { |
267 DCHECK(thread_checker_.CalledOnValidThread()); | 264 DCHECK(thread_checker_.CalledOnValidThread()); |
268 | 265 |
269 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 266 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
270 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); | 267 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); |
271 return; | 268 return; |
272 } | 269 } |
273 | 270 |
274 last_frame_format_ = format; | |
275 if (first_frame_timestamp_.is_null()) | 271 if (first_frame_timestamp_.is_null()) |
276 first_frame_timestamp_ = timestamp; | 272 first_frame_timestamp_ = timestamp; |
277 | 273 |
278 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( | 274 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( |
279 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), | 275 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), |
280 media::BindToCurrentLoop(base::Bind( | 276 media::BindToCurrentLoop(base::Bind( |
281 &VideoCaptureImpl::OnClientBufferFinished, weak_factory_.GetWeakPtr(), | 277 &VideoCaptureImpl::OnClientBufferFinished, weak_factory_.GetWeakPtr(), |
282 buffer_id, scoped_refptr<ClientBuffer>())), | 278 buffer_id, scoped_refptr<ClientBuffer>())), |
283 last_frame_format_.frame_size, gfx::Rect(last_frame_format_.frame_size), | 279 packed_frame_size, gfx::Rect(packed_frame_size), packed_frame_size, |
284 last_frame_format_.frame_size, timestamp - first_frame_timestamp_, false); | 280 timestamp - first_frame_timestamp_, false); |
| 281 frame->metadata()->MergeInternalValuesFrom(metadata); |
285 | 282 |
286 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); | 283 for (const auto& entry : clients_) |
287 ++it) { | 284 entry.second.deliver_frame_cb.Run(frame, timestamp); |
288 it->second.deliver_frame_cb.Run(frame, format, timestamp); | |
289 } | |
290 } | 285 } |
291 | 286 |
292 void VideoCaptureImpl::OnClientBufferFinished( | 287 void VideoCaptureImpl::OnClientBufferFinished( |
293 int buffer_id, | 288 int buffer_id, |
294 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 289 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
295 uint32 release_sync_point) { | 290 uint32 release_sync_point) { |
296 DCHECK(thread_checker_.CalledOnValidThread()); | 291 DCHECK(thread_checker_.CalledOnValidThread()); |
297 Send(new VideoCaptureHostMsg_BufferReady( | 292 Send(new VideoCaptureHostMsg_BufferReady( |
298 device_id_, buffer_id, release_sync_point)); | 293 device_id_, buffer_id, release_sync_point)); |
299 } | 294 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 ClientInfoMap::iterator it = clients->find(client_id); | 426 ClientInfoMap::iterator it = clients->find(client_id); |
432 if (it != clients->end()) { | 427 if (it != clients->end()) { |
433 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); | 428 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); |
434 clients->erase(it); | 429 clients->erase(it); |
435 found = true; | 430 found = true; |
436 } | 431 } |
437 return found; | 432 return found; |
438 } | 433 } |
439 | 434 |
440 } // namespace content | 435 } // namespace content |
OLD | NEW |