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

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

Issue 83793004: Implement IPCs and VideoCapture::Client interfaces for texture capture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: e296ac98 Win32 bits. 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 | Annotate | Revision Log
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 239 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
240 if (iter == client_buffers_.end()) 240 if (iter == client_buffers_.end())
241 return; 241 return;
242 242
243 DCHECK(!iter->second || iter->second->HasOneRef()) 243 DCHECK(!iter->second || iter->second->HasOneRef())
244 << "Instructed to delete buffer we are still using."; 244 << "Instructed to delete buffer we are still using.";
245 client_buffers_.erase(iter); 245 client_buffers_.erase(iter);
246 } 246 }
247 247
248 void VideoCaptureImpl::OnBufferReceived( 248 void VideoCaptureImpl::OnBufferReceived(int buffer_id,
249 int buffer_id, 249 const media::VideoCaptureFormat& format,
250 base::TimeTicks timestamp, 250 base::TimeTicks timestamp) {
251 const media::VideoCaptureFormat& format) {
252 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 251 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
253 252
253 // The capture pipeline supports only I420 for now.
254 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420);
255
254 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { 256 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
255 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); 257 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0));
256 return; 258 return;
257 } 259 }
258 260
259 last_frame_format_ = format; 261 last_frame_format_ = format;
260 if (first_frame_timestamp_.is_null()) 262 if (first_frame_timestamp_.is_null())
261 first_frame_timestamp_ = timestamp; 263 first_frame_timestamp_ = timestamp;
262 264
263 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 265 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
264 DCHECK(iter != client_buffers_.end()); 266 DCHECK(iter != client_buffers_.end());
265 scoped_refptr<ClientBuffer> buffer = iter->second; 267 scoped_refptr<ClientBuffer> buffer = iter->second;
266 scoped_refptr<media::VideoFrame> frame = 268 scoped_refptr<media::VideoFrame> frame =
267 media::VideoFrame::WrapExternalPackedMemory( 269 media::VideoFrame::WrapExternalPackedMemory(
268 media::VideoFrame::I420, 270 media::VideoFrame::I420,
269 last_frame_format_.frame_size, 271 last_frame_format_.frame_size,
270 gfx::Rect(last_frame_format_.frame_size), 272 gfx::Rect(last_frame_format_.frame_size),
271 last_frame_format_.frame_size, 273 last_frame_format_.frame_size,
272 reinterpret_cast<uint8*>(buffer->buffer->memory()), 274 reinterpret_cast<uint8*>(buffer->buffer->memory()),
273 buffer->buffer_size, 275 buffer->buffer_size,
274 buffer->buffer->handle(), 276 buffer->buffer->handle(),
275 timestamp - first_frame_timestamp_, 277 timestamp - first_frame_timestamp_,
276 media::BindToCurrentLoop( 278 media::BindToCurrentLoop(base::Bind(
277 base::Bind( 279 &VideoCaptureImpl::OnClientBufferFinished,
278 &VideoCaptureImpl::OnClientBufferFinished, 280 weak_this_factory_.GetWeakPtr(),
279 weak_this_factory_.GetWeakPtr(), 281 buffer_id,
280 buffer_id, 282 buffer,
281 buffer))); 283 base::Passed(scoped_ptr<gpu::MailboxHolder>().Pass()))));
282 284
283 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) 285 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it)
284 it->first->OnFrameReady(this, frame); 286 it->first->OnFrameReady(this, frame);
287 }
288
289 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); }
290
291 void VideoCaptureImpl::OnMailboxBufferReceived(
292 int buffer_id,
293 const gpu::MailboxHolder& mailbox_holder,
294 const media::VideoCaptureFormat& format,
295 base::TimeTicks timestamp) {
296 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
297
298 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
299 Send(new VideoCaptureHostMsg_BufferReady(
300 device_id_, buffer_id, mailbox_holder.sync_point));
301 return;
302 }
303
304 last_frame_format_ = format;
305 if (first_frame_timestamp_.is_null())
306 first_frame_timestamp_ = timestamp;
307
308 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture(
309 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)),
310 media::BindToCurrentLoop(
311 base::Bind(&VideoCaptureImpl::OnClientBufferFinished,
312 weak_this_factory_.GetWeakPtr(),
313 buffer_id,
314 scoped_refptr<ClientBuffer>())),
315 last_frame_format_.frame_size,
316 gfx::Rect(last_frame_format_.frame_size),
317 last_frame_format_.frame_size,
318 timestamp - first_frame_timestamp_,
319 base::Bind(&NullReadPixelsCB));
320
321 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it)
322 it->first->OnFrameReady(this, frame);
285 } 323 }
286 324
287 void VideoCaptureImpl::OnClientBufferFinished( 325 void VideoCaptureImpl::OnClientBufferFinished(
288 int buffer_id, 326 int buffer_id,
289 const scoped_refptr<ClientBuffer>& buffer) { 327 const scoped_refptr<ClientBuffer>& /* ignored_buffer */,
328 scoped_ptr<gpu::MailboxHolder> mailbox_holder) {
290 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 329 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
291 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); 330 const uint32 sync_point = (mailbox_holder ? mailbox_holder->sync_point : 0);
331 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, sync_point));
292 } 332 }
293 333
294 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { 334 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) {
295 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 335 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
296 336
297 switch (state) { 337 switch (state) {
298 case VIDEO_CAPTURE_STATE_STARTED: 338 case VIDEO_CAPTURE_STATE_STARTED:
299 break; 339 break;
300 case VIDEO_CAPTURE_STATE_STOPPED: 340 case VIDEO_CAPTURE_STATE_STOPPED:
301 state_ = VIDEO_CAPTURE_STATE_STOPPED; 341 state_ = VIDEO_CAPTURE_STATE_STOPPED;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 if (it != clients->end()) { 464 if (it != clients->end()) {
425 handler->OnStopped(this); 465 handler->OnStopped(this);
426 handler->OnRemoved(this); 466 handler->OnRemoved(this);
427 clients->erase(it); 467 clients->erase(it);
428 found = true; 468 found = true;
429 } 469 }
430 return found; 470 return found;
431 } 471 }
432 472
433 } // namespace content 473 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698