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

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: 5744a8bbb Nits. Created 6 years, 11 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 204 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
205 if (iter == client_buffers_.end()) 205 if (iter == client_buffers_.end())
206 return; 206 return;
207 207
208 DCHECK(!iter->second || iter->second->HasOneRef()) 208 DCHECK(!iter->second || iter->second->HasOneRef())
209 << "Instructed to delete buffer we are still using."; 209 << "Instructed to delete buffer we are still using.";
210 client_buffers_.erase(iter); 210 client_buffers_.erase(iter);
211 } 211 }
212 212
213 void VideoCaptureImpl::OnBufferReceived( 213 void VideoCaptureImpl::OnBufferReceived(int buffer_id,
214 int buffer_id, 214 const media::VideoCaptureFormat& format,
215 base::TimeTicks timestamp, 215 base::TimeTicks timestamp) {
216 const media::VideoCaptureFormat& format) {
217 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 216 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
218 217
218 // The capture pipeline supports only I420 for now.
219 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420);
mcasas 2014/01/21 14:34:02 Yes! (But unfortunately :( )
220
219 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { 221 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
220 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); 222 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, 0));
221 return; 223 return;
222 } 224 }
223 225
224 last_frame_format_ = format; 226 last_frame_format_ = format;
225 if (first_frame_timestamp_.is_null()) 227 if (first_frame_timestamp_.is_null())
226 first_frame_timestamp_ = timestamp; 228 first_frame_timestamp_ = timestamp;
227 229
228 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 230 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
229 DCHECK(iter != client_buffers_.end()); 231 DCHECK(iter != client_buffers_.end());
230 scoped_refptr<ClientBuffer> buffer = iter->second; 232 scoped_refptr<ClientBuffer> buffer = iter->second;
231 scoped_refptr<media::VideoFrame> frame = 233 scoped_refptr<media::VideoFrame> frame =
232 media::VideoFrame::WrapExternalPackedMemory( 234 media::VideoFrame::WrapExternalPackedMemory(
233 media::VideoFrame::I420, 235 media::VideoFrame::I420,
234 last_frame_format_.frame_size, 236 last_frame_format_.frame_size,
235 gfx::Rect(last_frame_format_.frame_size), 237 gfx::Rect(last_frame_format_.frame_size),
236 last_frame_format_.frame_size, 238 last_frame_format_.frame_size,
237 reinterpret_cast<uint8*>(buffer->buffer->memory()), 239 reinterpret_cast<uint8*>(buffer->buffer->memory()),
238 buffer->buffer_size, 240 buffer->buffer_size,
239 buffer->buffer->handle(), 241 buffer->buffer->handle(),
240 timestamp - first_frame_timestamp_, 242 timestamp - first_frame_timestamp_,
241 media::BindToCurrentLoop( 243 media::BindToCurrentLoop(base::Bind(
242 base::Bind( 244 &VideoCaptureImpl::OnClientBufferFinished,
243 &VideoCaptureImpl::OnClientBufferFinished, 245 weak_this_factory_.GetWeakPtr(),
244 weak_this_factory_.GetWeakPtr(), 246 buffer_id,
245 buffer_id, 247 buffer,
246 buffer))); 248 base::Unretained(static_cast<gpu::MailboxHolder*>(NULL)))));
247 249
248 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) 250 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it)
249 it->first->OnFrameReady(this, frame); 251 it->first->OnFrameReady(this, frame);
252 }
253
254 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); }
255
256 void VideoCaptureImpl::OnMailboxBufferReceived(
257 int buffer_id,
258 const gpu::MailboxHolder& mailbox_holder,
259 const media::VideoCaptureFormat& format,
260 base::TimeTicks timestamp) {
261 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
262
263 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
264 Send(new VideoCaptureHostMsg_BufferReady(
265 device_id_, buffer_id, mailbox_holder.sync_point));
266 return;
267 }
268
269 last_frame_format_ = format;
270 if (first_frame_timestamp_.is_null())
271 first_frame_timestamp_ = timestamp;
272
273 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture(
274 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)),
275 media::BindToCurrentLoop(
276 base::Bind(&VideoCaptureImpl::OnClientBufferFinished,
277 weak_this_factory_.GetWeakPtr(),
278 buffer_id,
279 scoped_refptr<ClientBuffer>())),
280 last_frame_format_.frame_size,
281 gfx::Rect(last_frame_format_.frame_size),
282 last_frame_format_.frame_size,
283 timestamp - first_frame_timestamp_,
284 base::Bind(&NullReadPixelsCB));
285
286 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it)
287 it->first->OnFrameReady(this, frame);
250 } 288 }
251 289
252 void VideoCaptureImpl::OnClientBufferFinished( 290 void VideoCaptureImpl::OnClientBufferFinished(
253 int buffer_id, 291 int buffer_id,
254 const scoped_refptr<ClientBuffer>& buffer) { 292 const scoped_refptr<ClientBuffer>& /* ignored_buffer */,
293 const gpu::MailboxHolder* mailbox_holder) {
255 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 294 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
256 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); 295 uint32 sync_point = 0;
mcasas 2014/01/21 14:34:02 uint32 sync_point = mailbox_holder ? mailbox_holde
sheu 2014/01/29 01:19:20 Done.
296 if (mailbox_holder)
297 sync_point = mailbox_holder->sync_point;
298 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id, sync_point));
257 } 299 }
258 300
259 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { 301 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) {
260 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 302 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
261 303
262 switch (state) { 304 switch (state) {
263 case VIDEO_CAPTURE_STATE_STARTED: 305 case VIDEO_CAPTURE_STATE_STARTED:
264 break; 306 break;
265 case VIDEO_CAPTURE_STATE_STOPPED: 307 case VIDEO_CAPTURE_STATE_STOPPED:
266 state_ = VIDEO_CAPTURE_STATE_STOPPED; 308 state_ = VIDEO_CAPTURE_STATE_STOPPED;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 if (it != clients->end()) { 415 if (it != clients->end()) {
374 handler->OnStopped(this); 416 handler->OnStopped(this);
375 handler->OnRemoved(this); 417 handler->OnRemoved(this);
376 clients->erase(it); 418 clients->erase(it);
377 found = true; 419 found = true;
378 } 420 }
379 return found; 421 return found;
380 } 422 }
381 423
382 } // namespace content 424 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698