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 #include "content/browser/renderer_host/media/video_capture_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 | 303 |
304 int count = 0; | 304 int count = 0; |
305 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 305 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
306 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) { | 306 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) { |
307 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, | 307 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, |
308 video_capture_format_.frame_rate); | 308 video_capture_format_.frame_rate); |
309 } | 309 } |
310 scoped_ptr<base::DictionaryValue> metadata(new base::DictionaryValue()); | 310 scoped_ptr<base::DictionaryValue> metadata(new base::DictionaryValue()); |
311 frame->metadata()->MergeInternalValuesInto(metadata.get()); | 311 frame->metadata()->MergeInternalValuesInto(metadata.get()); |
312 | 312 |
313 DCHECK( | |
mcasas
2015/08/27 18:26:55
Why the change to DCHECK() (and reformatting)?
emircan
2015/08/27 22:01:06
reveman@ pointed it out on PS#6. Do you think we s
| |
314 (frame->IsMappable() && frame->format() == media::PIXEL_FORMAT_I420) || | |
315 (frame->HasTextures() && (frame->format() == media::PIXEL_FORMAT_ARGB || | |
316 frame->format() == media::PIXEL_FORMAT_I420))) | |
317 << "Format and/or storage type combination not supported (received: " | |
318 << media::VideoPixelFormatToString(frame->format()) << ")"; | |
319 | |
313 for (const auto& client : controller_clients_) { | 320 for (const auto& client : controller_clients_) { |
314 if (client->session_closed || client->paused) | 321 if (client->session_closed || client->paused) |
315 continue; | 322 continue; |
316 | 323 |
317 CHECK((frame->IsMappable() && | 324 // On the first use of a buffer on a client, share the memory handles. |
318 frame->format() == media::PIXEL_FORMAT_I420) || | 325 const bool is_new_buffer = client->known_buffers.insert(buffer_id).second; |
319 (!frame->IsMappable() && frame->HasTextures() && | 326 if (is_new_buffer) { |
320 frame->format() == media::PIXEL_FORMAT_ARGB)) | 327 if (frame->HasTextures()) { |
321 << "Format and/or storage type combination not supported (received: " | 328 DCHECK(frame->coded_size() == frame->visible_rect().size()) |
322 << media::VideoPixelFormatToString(frame->format()) << ")"; | 329 << "Textures are always supposed to be tightly packed."; |
323 | 330 |
324 if (frame->HasTextures()) { | 331 if (frame->format() == media::PIXEL_FORMAT_I420) { |
325 DCHECK(frame->coded_size() == frame->visible_rect().size()) | 332 std::vector<gfx::GpuMemoryBufferHandle> handles( |
326 << "Textures are always supposed to be tightly packed."; | 333 VideoFrame::NumPlanes(frame->format())); |
327 DCHECK_EQ(1u, VideoFrame::NumPlanes(frame->format())); | 334 for (size_t i = 0; i < handles.size(); ++i) |
328 } else if (frame->format() == media::PIXEL_FORMAT_I420) { | 335 buffer_pool_->ShareToProcess2( |
mcasas
2015/08/27 18:26:55
Since you're adding ShareToProcess2(), why
not mak
emircan
2015/08/27 22:01:06
Acknowledged. We would need to pass |std::vector<g
| |
329 const bool is_new_buffer = | 336 buffer_id, i, client->render_process_handle, &handles[i]); |
330 client->known_buffers.insert(buffer_id).second; | 337 |
331 if (is_new_buffer) { | 338 client->event_handler->OnBufferCreated2( |
332 // On the first use of a buffer on a client, share the memory handle. | 339 client->controller_id, handles, buffer->dimensions(), |
333 size_t memory_size = 0; | 340 buffer_id); |
334 base::SharedMemoryHandle remote_handle = buffer_pool_->ShareToProcess( | 341 } else { |
335 buffer_id, client->render_process_handle, &memory_size); | 342 DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_ARGB); |
343 } | |
344 } else if (frame->IsMappable()) { | |
345 DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_I420); | |
346 base::SharedMemoryHandle remote_handle; | |
347 buffer_pool_->ShareToProcess( | |
348 buffer_id, client->render_process_handle, &remote_handle); | |
349 | |
336 client->event_handler->OnBufferCreated( | 350 client->event_handler->OnBufferCreated( |
337 client->controller_id, remote_handle, memory_size, buffer_id); | 351 client->controller_id, remote_handle, buffer->mapped_size(), |
352 buffer_id); | |
338 } | 353 } |
339 } | 354 } |
340 | 355 |
341 client->event_handler->OnBufferReady(client->controller_id, | 356 client->event_handler->OnBufferReady(client->controller_id, |
342 buffer_id, | 357 buffer_id, |
343 frame, | 358 frame, |
344 timestamp); | 359 timestamp); |
345 const bool inserted = | 360 const bool inserted = |
346 client->active_buffers.insert(std::make_pair(buffer_id, frame)) | 361 client->active_buffers.insert(std::make_pair(buffer_id, frame)) |
347 .second; | 362 .second; |
(...skipping 12 matching lines...) Expand all Loading... | |
360 frame->visible_rect().height()); | 375 frame->visible_rect().height()); |
361 double frame_rate = 0.0f; | 376 double frame_rate = 0.0f; |
362 if (!frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, | 377 if (!frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, |
363 &frame_rate)) { | 378 &frame_rate)) { |
364 frame_rate = video_capture_format_.frame_rate; | 379 frame_rate = video_capture_format_.frame_rate; |
365 } | 380 } |
366 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.FrameRate", frame_rate); | 381 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.FrameRate", frame_rate); |
367 has_received_frames_ = true; | 382 has_received_frames_ = true; |
368 } | 383 } |
369 | 384 |
370 buffer_pool_->HoldForConsumers(buffer_id, count); | 385 buffer_pool_->HoldForConsumers(buffer_id, count); |
mcasas
2015/08/27 18:26:55
nit: not your fault, but this |count| is just furt
emircan
2015/08/27 22:01:06
Done.
| |
371 } | 386 } |
372 | 387 |
373 void VideoCaptureController::DoErrorOnIOThread() { | 388 void VideoCaptureController::DoErrorOnIOThread() { |
374 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 389 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
375 state_ = VIDEO_CAPTURE_STATE_ERROR; | 390 state_ = VIDEO_CAPTURE_STATE_ERROR; |
376 | 391 |
377 for (const auto* client : controller_clients_) { | 392 for (const auto* client : controller_clients_) { |
378 if (client->session_closed) | 393 if (client->session_closed) |
379 continue; | 394 continue; |
380 client->event_handler->OnError(client->controller_id); | 395 client->event_handler->OnError(client->controller_id); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 446 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
432 int active_client_count = 0; | 447 int active_client_count = 0; |
433 for (ControllerClient* client : controller_clients_) { | 448 for (ControllerClient* client : controller_clients_) { |
434 if (!client->paused) | 449 if (!client->paused) |
435 ++active_client_count; | 450 ++active_client_count; |
436 } | 451 } |
437 return active_client_count; | 452 return active_client_count; |
438 } | 453 } |
439 | 454 |
440 } // namespace content | 455 } // namespace content |
OLD | NEW |