| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 std::unique_ptr<base::DictionaryValue> metadata( | 420 std::unique_ptr<base::DictionaryValue> metadata( |
| 421 new base::DictionaryValue()); | 421 new base::DictionaryValue()); |
| 422 frame->metadata()->MergeInternalValuesInto(metadata.get()); | 422 frame->metadata()->MergeInternalValuesInto(metadata.get()); |
| 423 | 423 |
| 424 // Only I420 pixel format is currently supported. | 424 // Only I420 pixel format is currently supported. |
| 425 DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_I420) | 425 DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_I420) |
| 426 << "Unsupported pixel format: " | 426 << "Unsupported pixel format: " |
| 427 << media::VideoPixelFormatToString(frame->format()); | 427 << media::VideoPixelFormatToString(frame->format()); |
| 428 | 428 |
| 429 // Sanity-checks to confirm |frame| is actually being backed by |buffer|. | 429 // Sanity-checks to confirm |frame| is actually being backed by |buffer|. |
| 430 DCHECK(frame->storage_type() == media::VideoFrame::STORAGE_SHMEM || | 430 DCHECK(frame->storage_type() == media::VideoFrame::STORAGE_SHMEM); |
| 431 (frame->storage_type() == | |
| 432 media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS)); | |
| 433 DCHECK(frame->data(media::VideoFrame::kYPlane) >= buffer->data(0) && | 431 DCHECK(frame->data(media::VideoFrame::kYPlane) >= buffer->data(0) && |
| 434 (frame->data(media::VideoFrame::kYPlane) < | 432 (frame->data(media::VideoFrame::kYPlane) < |
| 435 (reinterpret_cast<const uint8_t*>(buffer->data(0)) + | 433 (reinterpret_cast<const uint8_t*>(buffer->data(0)) + |
| 436 buffer->mapped_size()))) | 434 buffer->mapped_size()))) |
| 437 << "VideoFrame does not appear to be backed by Buffer"; | 435 << "VideoFrame does not appear to be backed by Buffer"; |
| 438 | 436 |
| 439 for (const auto& client : controller_clients_) { | 437 for (const auto& client : controller_clients_) { |
| 440 if (client->session_closed || client->paused) | 438 if (client->session_closed || client->paused) |
| 441 continue; | 439 continue; |
| 442 | 440 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 503 } |
| 506 } | 504 } |
| 507 | 505 |
| 508 void VideoCaptureController::DoNewBufferOnIOThread( | 506 void VideoCaptureController::DoNewBufferOnIOThread( |
| 509 ControllerClient* client, | 507 ControllerClient* client, |
| 510 media::VideoCaptureDevice::Client::Buffer* buffer, | 508 media::VideoCaptureDevice::Client::Buffer* buffer, |
| 511 const scoped_refptr<media::VideoFrame>& frame) { | 509 const scoped_refptr<media::VideoFrame>& frame) { |
| 512 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 510 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 513 const int buffer_id = buffer->id(); | 511 const int buffer_id = buffer->id(); |
| 514 | 512 |
| 515 switch (frame->storage_type()) { | 513 DCHECK_EQ(media::VideoFrame::STORAGE_SHMEM, frame->storage_type()); |
| 516 case media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS: { | 514 |
| 517 std::vector<gfx::GpuMemoryBufferHandle> handles; | 515 base::SharedMemoryHandle remote_handle; |
| 518 const size_t num_planes = media::VideoFrame::NumPlanes(frame->format()); | 516 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle, |
| 519 for (size_t i = 0; i < num_planes; ++i) { | 517 &remote_handle); |
| 520 gfx::GpuMemoryBufferHandle remote_handle; | 518 client->event_handler->OnBufferCreated(client->controller_id, remote_handle, |
| 521 handles.push_back(remote_handle); | 519 buffer->mapped_size(), buffer_id); |
| 522 } | |
| 523 client->event_handler->OnBufferCreated2(client->controller_id, handles, | |
| 524 buffer->dimensions(), buffer_id); | |
| 525 break; | |
| 526 } | |
| 527 case media::VideoFrame::STORAGE_SHMEM: { | |
| 528 base::SharedMemoryHandle remote_handle; | |
| 529 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle, | |
| 530 &remote_handle); | |
| 531 client->event_handler->OnBufferCreated( | |
| 532 client->controller_id, remote_handle, buffer->mapped_size(), | |
| 533 buffer_id); | |
| 534 break; | |
| 535 } | |
| 536 default: | |
| 537 NOTREACHED(); | |
| 538 break; | |
| 539 } | |
| 540 } | 520 } |
| 541 | 521 |
| 542 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 522 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 543 VideoCaptureControllerID id, | 523 VideoCaptureControllerID id, |
| 544 VideoCaptureControllerEventHandler* handler, | 524 VideoCaptureControllerEventHandler* handler, |
| 545 const ControllerClients& clients) { | 525 const ControllerClients& clients) { |
| 546 for (const auto& client : clients) { | 526 for (const auto& client : clients) { |
| 547 if (client->controller_id == id && client->event_handler == handler) | 527 if (client->controller_id == id && client->event_handler == handler) |
| 548 return client.get(); | 528 return client.get(); |
| 549 } | 529 } |
| 550 return nullptr; | 530 return nullptr; |
| 551 } | 531 } |
| 552 | 532 |
| 553 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 533 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 554 int session_id, | 534 int session_id, |
| 555 const ControllerClients& clients) { | 535 const ControllerClients& clients) { |
| 556 for (const auto& client : clients) { | 536 for (const auto& client : clients) { |
| 557 if (client->session_id == session_id) | 537 if (client->session_id == session_id) |
| 558 return client.get(); | 538 return client.get(); |
| 559 } | 539 } |
| 560 return nullptr; | 540 return nullptr; |
| 561 } | 541 } |
| 562 | 542 |
| 563 } // namespace content | 543 } // namespace content |
| OLD | NEW |