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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 for (const auto& client : controller_clients_) { | 313 for (const auto& client : controller_clients_) { |
314 if (client->session_closed || client->paused) | 314 if (client->session_closed || client->paused) |
315 continue; | 315 continue; |
316 | 316 |
317 CHECK((frame->IsMappable() && | 317 CHECK((frame->IsMappable() && |
318 frame->format() == media::PIXEL_FORMAT_I420) || | 318 frame->format() == media::PIXEL_FORMAT_I420) || |
319 (!frame->IsMappable() && frame->HasTextures() && | 319 (frame->HasTextures() && |
320 frame->format() == media::PIXEL_FORMAT_ARGB)) | 320 (frame->format() == media::PIXEL_FORMAT_ARGB || |
321 frame->format() == media::PIXEL_FORMAT_I420))) | |
321 << "Format and/or storage type combination not supported (received: " | 322 << "Format and/or storage type combination not supported (received: " |
322 << media::VideoPixelFormatToString(frame->format()) << ")"; | 323 << media::VideoPixelFormatToString(frame->format()) << ")"; |
323 | 324 |
324 if (frame->HasTextures()) { | 325 // On the first use of a buffer on a client, share the memory handles. |
325 DCHECK(frame->coded_size() == frame->visible_rect().size()) | 326 const bool is_new_buffer = client->known_buffers.insert(buffer_id).second; |
326 << "Textures are always supposed to be tightly packed."; | 327 if (is_new_buffer) { |
327 DCHECK_EQ(1u, VideoFrame::NumPlanes(frame->format())); | 328 if (frame->HasTextures() && |
328 } else if (frame->format() == media::PIXEL_FORMAT_I420) { | 329 frame->format() == media::PIXEL_FORMAT_I420) { |
329 const bool is_new_buffer = | 330 std::vector<gfx::GpuMemoryBufferHandle> gmb_handles( |
330 client->known_buffers.insert(buffer_id).second; | 331 VideoFrame::NumPlanes(frame->format())); |
331 if (is_new_buffer) { | 332 for (size_t i = 0; i < gmb_handles.size(); ++i) |
332 // On the first use of a buffer on a client, share the memory handle. | 333 buffer_pool_->ShareToProcess( |
333 size_t memory_size = 0; | 334 buffer_id, i, client->render_process_handle, &gmb_handles[i]); |
334 base::SharedMemoryHandle remote_handle = buffer_pool_->ShareToProcess( | 335 |
335 buffer_id, client->render_process_handle, &memory_size); | 336 client->event_handler->OnGpuMemoryBufferCreated( |
337 client->controller_id, gmb_handles, buffer->dimensions(), | |
338 buffer_id); | |
339 } else if (frame->IsMappable()) { | |
mcasas
2015/08/21 03:57:25
Please keep the DCHECKs for the case of opaque tex
emircan
2015/08/22 03:13:26
Done. I restructured this method to make it clear
| |
340 base::SharedMemoryHandle remote_handle; | |
341 buffer_pool_->ShareToProcess( | |
342 buffer_id, 0, client->render_process_handle, &remote_handle); | |
343 | |
336 client->event_handler->OnBufferCreated( | 344 client->event_handler->OnBufferCreated( |
337 client->controller_id, remote_handle, memory_size, buffer_id); | 345 client->controller_id, remote_handle, buffer->mapped_size(), |
346 buffer_id); | |
338 } | 347 } |
339 } | 348 } |
340 | 349 |
341 client->event_handler->OnBufferReady(client->controller_id, | 350 client->event_handler->OnBufferReady(client->controller_id, |
342 buffer_id, | 351 buffer_id, |
343 frame, | 352 frame, |
344 timestamp); | 353 timestamp); |
345 const bool inserted = | 354 const bool inserted = |
346 client->active_buffers.insert(std::make_pair(buffer_id, frame)) | 355 client->active_buffers.insert(std::make_pair(buffer_id, frame)) |
347 .second; | 356 .second; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 440 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
432 int active_client_count = 0; | 441 int active_client_count = 0; |
433 for (ControllerClient* client : controller_clients_) { | 442 for (ControllerClient* client : controller_clients_) { |
434 if (!client->paused) | 443 if (!client->paused) |
435 ++active_client_count; | 444 ++active_client_count; |
436 } | 445 } |
437 return active_client_count; | 446 return active_client_count; |
438 } | 447 } |
439 | 448 |
440 } // namespace content | 449 } // namespace content |
OLD | NEW |