Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: content/renderer/media/video_capture_impl.cc

Issue 175223003: HW Video: Make media::VideoFrame handle the sync point of the compositor as well as webgl (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: previous patchset has unrelated code by mistake. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 247
248 void VideoCaptureImpl::OnBufferReceived(int buffer_id, 248 void VideoCaptureImpl::OnBufferReceived(int buffer_id,
249 const media::VideoCaptureFormat& format, 249 const media::VideoCaptureFormat& format,
250 base::TimeTicks timestamp) { 250 base::TimeTicks timestamp) {
251 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 251 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
252 252
253 // The capture pipeline supports only I420 for now. 253 // The capture pipeline supports only I420 for now.
254 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420); 254 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420);
255 255
256 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { 256 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
257 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0)); 257 Send(new VideoCaptureHostMsg_BufferReady(
258 device_id_, buffer_id, std::vector<uint32>()));
258 return; 259 return;
259 } 260 }
260 261
261 last_frame_format_ = format; 262 last_frame_format_ = format;
262 if (first_frame_timestamp_.is_null()) 263 if (first_frame_timestamp_.is_null())
263 first_frame_timestamp_ = timestamp; 264 first_frame_timestamp_ = timestamp;
264 265
265 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 266 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
266 DCHECK(iter != client_buffers_.end()); 267 DCHECK(iter != client_buffers_.end());
267 scoped_refptr<ClientBuffer> buffer = iter->second; 268 scoped_refptr<ClientBuffer> buffer = iter->second;
268 scoped_refptr<media::VideoFrame> frame = 269 scoped_refptr<media::VideoFrame> frame =
269 media::VideoFrame::WrapExternalPackedMemory( 270 media::VideoFrame::WrapExternalPackedMemory(
270 media::VideoFrame::I420, 271 media::VideoFrame::I420,
271 last_frame_format_.frame_size, 272 last_frame_format_.frame_size,
272 gfx::Rect(last_frame_format_.frame_size), 273 gfx::Rect(last_frame_format_.frame_size),
273 last_frame_format_.frame_size, 274 last_frame_format_.frame_size,
274 reinterpret_cast<uint8*>(buffer->buffer->memory()), 275 reinterpret_cast<uint8*>(buffer->buffer->memory()),
275 buffer->buffer_size, 276 buffer->buffer_size,
276 buffer->buffer->handle(), 277 buffer->buffer->handle(),
277 timestamp - first_frame_timestamp_, 278 timestamp - first_frame_timestamp_,
278 media::BindToCurrentLoop(base::Bind( 279 media::BindToCurrentLoop(
279 &VideoCaptureImpl::OnClientBufferFinished, 280 base::Bind(&VideoCaptureImpl::OnClientBufferFinished,
280 weak_this_factory_.GetWeakPtr(), 281 weak_this_factory_.GetWeakPtr(),
281 buffer_id, 282 buffer_id,
282 buffer, 283 buffer,
283 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass())))); 284 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass()),
285 std::vector<uint32>())));
284 286
285 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) 287 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it)
286 it->first->OnFrameReady(this, frame); 288 it->first->OnFrameReady(this, frame);
287 } 289 }
288 290
289 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); }
290
291 void VideoCaptureImpl::OnMailboxBufferReceived( 291 void VideoCaptureImpl::OnMailboxBufferReceived(
292 int buffer_id, 292 int buffer_id,
293 const gpu::MailboxHolder& mailbox_holder, 293 const gpu::MailboxHolder& mailbox_holder,
294 const media::VideoCaptureFormat& format, 294 const media::VideoCaptureFormat& format,
295 base::TimeTicks timestamp) { 295 base::TimeTicks timestamp) {
296 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 296 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
297 297
298 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { 298 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
299 Send(new VideoCaptureHostMsg_BufferReady( 299 Send(new VideoCaptureHostMsg_BufferReady(
300 device_id_, buffer_id, mailbox_holder.sync_point)); 300 device_id_, buffer_id, std::vector<uint32>()));
301 return; 301 return;
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_this_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 media::VideoFrame::ReadPixelsCB());
danakj 2014/03/06 19:31:31 Unrelated change, do this separately?
dshwang 2014/03/06 19:51:37 ok, i'll do this change in separate CL.
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);
323 } 323 }
324 324
325 void VideoCaptureImpl::OnClientBufferFinished( 325 void VideoCaptureImpl::OnClientBufferFinished(
326 int buffer_id, 326 int buffer_id,
327 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, 327 const scoped_refptr<ClientBuffer>& /* ignored_buffer */,
328 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { 328 scoped_ptr<gpu::MailboxHolder> mailbox_holder,
329 const std::vector<uint32>& release_sync_points) {
329 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 330 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
330 const uint32 sync_point = (mailbox_holder ? mailbox_holder->sync_point : 0); 331 Send(new VideoCaptureHostMsg_BufferReady(
331 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, sync_point)); 332 device_id_, buffer_id, release_sync_points));
332 } 333 }
333 334
334 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { 335 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) {
335 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 336 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
336 337
337 switch (state) { 338 switch (state) {
338 case VIDEO_CAPTURE_STATE_STARTED: 339 case VIDEO_CAPTURE_STATE_STARTED:
339 break; 340 break;
340 case VIDEO_CAPTURE_STATE_STOPPED: 341 case VIDEO_CAPTURE_STATE_STOPPED:
341 state_ = VIDEO_CAPTURE_STATE_STOPPED; 342 state_ = VIDEO_CAPTURE_STATE_STOPPED;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 if (it != clients->end()) { 465 if (it != clients->end()) {
465 handler->OnStopped(this); 466 handler->OnStopped(this);
466 handler->OnRemoved(this); 467 handler->OnRemoved(this);
467 clients->erase(it); 468 clients->erase(it);
468 found = true; 469 found = true;
469 } 470 }
470 return found; 471 return found;
471 } 472 }
472 473
473 } // namespace content 474 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698