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

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller.cc

Issue 1439533004: Remove dead code paths around PIXEL_STORAGE_TEXTURE in capture pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mcasas's second round comments REBASE Created 5 years, 1 month 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
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/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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/sparse_histogram.h" 13 #include "base/metrics/sparse_histogram.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "content/browser/renderer_host/media/media_stream_manager.h" 15 #include "content/browser/renderer_host/media/media_stream_manager.h"
16 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" 16 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h"
17 #include "content/browser/renderer_host/media/video_capture_device_client.h" 17 #include "content/browser/renderer_host/media/video_capture_device_client.h"
18 #include "content/browser/renderer_host/media/video_capture_manager.h" 18 #include "content/browser/renderer_host/media/video_capture_manager.h"
19 #include "content/common/gpu/client/gl_helper.h" 19 #include "content/common/gpu/client/gl_helper.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
22 #include "gpu/command_buffer/common/mailbox_holder.h"
23 #include "media/base/video_frame.h" 22 #include "media/base/video_frame.h"
24 23
25 #if !defined(OS_ANDROID) 24 #if !defined(OS_ANDROID)
26 #include "content/browser/compositor/image_transport_factory.h" 25 #include "content/browser/compositor/image_transport_factory.h"
27 #endif 26 #endif
28 27
29 using media::VideoCaptureFormat; 28 using media::VideoCaptureFormat;
30 using media::VideoFrame; 29 using media::VideoFrame;
31 using media::VideoFrameMetadata; 30 using media::VideoFrameMetadata;
32 31
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 this->GetWeakPtrForIOThread(), buffer_pool_)); 144 this->GetWeakPtrForIOThread(), buffer_pool_));
146 } 145 }
147 146
148 void VideoCaptureController::AddClient( 147 void VideoCaptureController::AddClient(
149 VideoCaptureControllerID id, 148 VideoCaptureControllerID id,
150 VideoCaptureControllerEventHandler* event_handler, 149 VideoCaptureControllerEventHandler* event_handler,
151 base::ProcessHandle render_process, 150 base::ProcessHandle render_process,
152 media::VideoCaptureSessionId session_id, 151 media::VideoCaptureSessionId session_id,
153 const media::VideoCaptureParams& params) { 152 const media::VideoCaptureParams& params) {
154 DCHECK_CURRENTLY_ON(BrowserThread::IO); 153 DCHECK_CURRENTLY_ON(BrowserThread::IO);
155 DVLOG(1) << "VideoCaptureController::AddClient, id " << id 154 DVLOG(1) << "VideoCaptureController::AddClient() -- id=" << id
156 << ", " << params.requested_format.frame_size.ToString() 155 << ", session_id=" << session_id
157 << ", " << params.requested_format.frame_rate 156 << ", params.requested_format="
158 << ", " << session_id 157 << media::VideoCaptureFormat::ToString(params.requested_format);
159 << ")"; 158
159 // Check that requested VideoCaptureParams are valid and supported. If not,
160 // report an error immediately and punt.
161 if (!params.IsValid() ||
162 params.requested_format.pixel_format != media::PIXEL_FORMAT_I420 ||
163 (params.requested_format.pixel_storage != media::PIXEL_STORAGE_CPU &&
164 params.requested_format.pixel_storage !=
165 media::PIXEL_STORAGE_GPUMEMORYBUFFER)) {
166 // Crash in debug builds since the renderer should not have asked for
167 // invalid or unsupported parameters.
168 LOG(DFATAL) << "Invalid or unsupported video capture parameters requested: "
169 << media::VideoCaptureFormat::ToString(params.requested_format);
170 event_handler->OnError(id);
171 return;
172 }
160 173
161 // If this is the first client added to the controller, cache the parameters. 174 // If this is the first client added to the controller, cache the parameters.
162 if (!controller_clients_.size()) 175 if (!controller_clients_.size())
163 video_capture_format_ = params.requested_format; 176 video_capture_format_ = params.requested_format;
164 177
165 // Signal error in case device is already in error state. 178 // Signal error in case device is already in error state.
166 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { 179 if (state_ == VIDEO_CAPTURE_STATE_ERROR) {
167 event_handler->OnError(id); 180 event_handler->OnError(id);
168 return; 181 return;
169 } 182 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 349
337 int count = 0; 350 int count = 0;
338 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 351 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
339 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) { 352 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) {
340 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, 353 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE,
341 video_capture_format_.frame_rate); 354 video_capture_format_.frame_rate);
342 } 355 }
343 scoped_ptr<base::DictionaryValue> metadata(new base::DictionaryValue()); 356 scoped_ptr<base::DictionaryValue> metadata(new base::DictionaryValue());
344 frame->metadata()->MergeInternalValuesInto(metadata.get()); 357 frame->metadata()->MergeInternalValuesInto(metadata.get());
345 358
346 DCHECK( 359 // Only I420 pixel format is currently supported.
347 (frame->IsMappable() && frame->format() == media::PIXEL_FORMAT_I420) || 360 DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_I420)
348 (frame->HasTextures() && frame->format() == media::PIXEL_FORMAT_ARGB)) 361 << "Unsupported pixel format: "
349 << "Format and/or storage type combination not supported (received: " 362 << media::VideoPixelFormatToString(frame->format());
350 << media::VideoPixelFormatToString(frame->format()) << ")"; 363
364 // Sanity-checks to confirm |frame| is actually being backed by |buffer|.
365 DCHECK(frame->storage_type() == media::VideoFrame::STORAGE_SHMEM ||
366 (frame->storage_type() ==
367 media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS));
368 DCHECK(frame->data(media::VideoFrame::kYPlane) >= buffer->data(0) &&
369 (frame->data(media::VideoFrame::kYPlane) <
370 (reinterpret_cast<const uint8*>(buffer->data(0)) +
371 buffer->mapped_size())))
372 << "VideoFrame does not appear to be backed by Buffer";
351 373
352 for (const auto& client : controller_clients_) { 374 for (const auto& client : controller_clients_) {
353 if (client->session_closed || client->paused) 375 if (client->session_closed || client->paused)
354 continue; 376 continue;
355 377
356 // On the first use of a buffer on a client, share the memory handles. 378 // On the first use of a buffer on a client, share the memory handles.
357 const bool is_new_buffer = client->known_buffers.insert(buffer_id).second; 379 const bool is_new_buffer = client->known_buffers.insert(buffer_id).second;
358 if (is_new_buffer) 380 if (is_new_buffer)
359 DoNewBufferOnIOThread(client, buffer.get(), frame); 381 DoNewBufferOnIOThread(client, buffer.get(), frame);
360 382
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 443 }
422 } 444 }
423 445
424 void VideoCaptureController::DoNewBufferOnIOThread( 446 void VideoCaptureController::DoNewBufferOnIOThread(
425 ControllerClient* client, 447 ControllerClient* client,
426 media::VideoCaptureDevice::Client::Buffer* buffer, 448 media::VideoCaptureDevice::Client::Buffer* buffer,
427 const scoped_refptr<media::VideoFrame>& frame) { 449 const scoped_refptr<media::VideoFrame>& frame) {
428 DCHECK_CURRENTLY_ON(BrowserThread::IO); 450 DCHECK_CURRENTLY_ON(BrowserThread::IO);
429 const int buffer_id = buffer->id(); 451 const int buffer_id = buffer->id();
430 452
431 if (frame->HasTextures()) { 453 switch (frame->storage_type()) {
432 DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_ARGB); 454 case media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS: {
433 DCHECK(frame->coded_size() == frame->visible_rect().size()) 455 std::vector<gfx::GpuMemoryBufferHandle> handles;
434 << "Textures shouldn't be crop-marked or letterboxed."; 456 const size_t num_planes = media::VideoFrame::NumPlanes(frame->format());
435 return; 457 for (size_t i = 0; i < num_planes; ++i) {
436 } 458 gfx::GpuMemoryBufferHandle remote_handle;
437 459 buffer_pool_->ShareToProcess2(
438 DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_I420); 460 buffer_id, i, client->render_process_handle, &remote_handle);
439 if (frame->storage_type() == media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS) { 461 handles.push_back(remote_handle);
440 std::vector<gfx::GpuMemoryBufferHandle> handles; 462 }
441 for (size_t i = 0; i < media::VideoFrame::NumPlanes(frame->format()); ++i) { 463 client->event_handler->OnBufferCreated2(client->controller_id, handles,
442 gfx::GpuMemoryBufferHandle remote_handle; 464 buffer->dimensions(), buffer_id);
443 buffer_pool_->ShareToProcess2(buffer_id, i, client->render_process_handle, 465 break;
444 &remote_handle);
445 handles.push_back(remote_handle);
446 } 466 }
447 client->event_handler->OnBufferCreated2(client->controller_id, handles, 467 case media::VideoFrame::STORAGE_SHMEM: {
448 buffer->dimensions(), buffer_id); 468 base::SharedMemoryHandle remote_handle;
449 } else { 469 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle,
450 base::SharedMemoryHandle remote_handle; 470 &remote_handle);
451 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle, 471 client->event_handler->OnBufferCreated(
452 &remote_handle); 472 client->controller_id, remote_handle, buffer->mapped_size(),
453 473 buffer_id);
454 client->event_handler->OnBufferCreated(client->controller_id, remote_handle, 474 break;
455 buffer->mapped_size(), buffer_id); 475 }
476 default:
477 NOTREACHED();
478 break;
456 } 479 }
457 } 480 }
458 481
459 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( 482 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient(
460 VideoCaptureControllerID id, 483 VideoCaptureControllerID id,
461 VideoCaptureControllerEventHandler* handler, 484 VideoCaptureControllerEventHandler* handler,
462 const ControllerClients& clients) { 485 const ControllerClients& clients) {
463 for (auto* client : clients) { 486 for (auto* client : clients) {
464 if (client->controller_id == id && client->event_handler == handler) 487 if (client->controller_id == id && client->event_handler == handler)
465 return client; 488 return client;
466 } 489 }
467 return NULL; 490 return NULL;
468 } 491 }
469 492
470 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( 493 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient(
471 int session_id, 494 int session_id,
472 const ControllerClients& clients) { 495 const ControllerClients& clients) {
473 for (auto client : clients) { 496 for (auto client : clients) {
474 if (client->session_id == session_id) 497 if (client->session_id == session_id)
475 return client; 498 return client;
476 } 499 }
477 return NULL; 500 return NULL;
478 } 501 }
479 502
480 } // namespace content 503 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698