| 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( |
| 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( |
| 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 83 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 |