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

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

Issue 2398463003: 16 bit capture and GPU&CPU memory buffer support.
Patch Set: fixes. Created 4 years, 2 months 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 const media::VideoCaptureParams& params) { 211 const media::VideoCaptureParams& params) {
212 DCHECK_CURRENTLY_ON(BrowserThread::IO); 212 DCHECK_CURRENTLY_ON(BrowserThread::IO);
213 DVLOG(1) << "VideoCaptureController::AddClient() -- id=" << id 213 DVLOG(1) << "VideoCaptureController::AddClient() -- id=" << id
214 << ", session_id=" << session_id 214 << ", session_id=" << session_id
215 << ", params.requested_format=" 215 << ", params.requested_format="
216 << media::VideoCaptureFormat::ToString(params.requested_format); 216 << media::VideoCaptureFormat::ToString(params.requested_format);
217 217
218 // Check that requested VideoCaptureParams are valid and supported. If not, 218 // Check that requested VideoCaptureParams are valid and supported. If not,
219 // report an error immediately and punt. 219 // report an error immediately and punt.
220 if (!params.IsValid() || 220 if (!params.IsValid() ||
221 params.requested_format.pixel_format != media::PIXEL_FORMAT_I420 || 221 !(params.requested_format.pixel_format == media::PIXEL_FORMAT_I420 ||
222 params.requested_format.pixel_format == media::PIXEL_FORMAT_Y16) ||
222 (params.requested_format.pixel_storage != media::PIXEL_STORAGE_CPU && 223 (params.requested_format.pixel_storage != media::PIXEL_STORAGE_CPU &&
223 params.requested_format.pixel_storage != 224 params.requested_format.pixel_storage !=
224 media::PIXEL_STORAGE_GPUMEMORYBUFFER)) { 225 media::PIXEL_STORAGE_GPUMEMORYBUFFER)) {
225 // Crash in debug builds since the renderer should not have asked for 226 // Crash in debug builds since the renderer should not have asked for
226 // invalid or unsupported parameters. 227 // invalid or unsupported parameters.
227 LOG(DFATAL) << "Invalid or unsupported video capture parameters requested: " 228 LOG(DFATAL) << "Invalid or unsupported video capture parameters requested: "
228 << media::VideoCaptureFormat::ToString(params.requested_format); 229 << media::VideoCaptureFormat::ToString(params.requested_format);
229 event_handler->OnError(id); 230 event_handler->OnError(id);
230 return; 231 return;
231 } 232 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 int count = 0; 417 int count = 0;
417 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 418 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
418 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) { 419 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) {
419 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, 420 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE,
420 video_capture_format_.frame_rate); 421 video_capture_format_.frame_rate);
421 } 422 }
422 std::unique_ptr<base::DictionaryValue> metadata( 423 std::unique_ptr<base::DictionaryValue> metadata(
423 new base::DictionaryValue()); 424 new base::DictionaryValue());
424 frame->metadata()->MergeInternalValuesInto(metadata.get()); 425 frame->metadata()->MergeInternalValuesInto(metadata.get());
425 426
426 // Only I420 pixel format is currently supported. 427 // Only I420 and Y16 pixel formats are currently supported.
427 DCHECK_EQ(frame->format(), media::PIXEL_FORMAT_I420) 428 DCHECK(frame->format() == media::PIXEL_FORMAT_I420 ||
429 frame->format() == media::PIXEL_FORMAT_Y16)
428 << "Unsupported pixel format: " 430 << "Unsupported pixel format: "
429 << media::VideoPixelFormatToString(frame->format()); 431 << media::VideoPixelFormatToString(frame->format());
430 432
431 // Sanity-checks to confirm |frame| is actually being backed by |buffer|. 433 // Sanity-checks to confirm |frame| is actually being backed by |buffer|.
432 DCHECK(frame->storage_type() == media::VideoFrame::STORAGE_SHMEM || 434 DCHECK(frame->storage_type() == media::VideoFrame::STORAGE_SHMEM ||
433 (frame->storage_type() == 435 (frame->storage_type() ==
434 media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS)); 436 media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS));
435 DCHECK(frame->data(media::VideoFrame::kYPlane) >= buffer->data(0) && 437 DCHECK(frame->data(media::VideoFrame::kYPlane) >= buffer->data(0) &&
436 (frame->data(media::VideoFrame::kYPlane) < 438 (frame->data(media::VideoFrame::kYPlane) <
437 (reinterpret_cast<const uint8_t*>(buffer->data(0)) + 439 (reinterpret_cast<const uint8_t*>(buffer->data(0)) +
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 case media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS: { 520 case media::VideoFrame::STORAGE_GPU_MEMORY_BUFFERS: {
519 std::vector<gfx::GpuMemoryBufferHandle> handles; 521 std::vector<gfx::GpuMemoryBufferHandle> handles;
520 const size_t num_planes = media::VideoFrame::NumPlanes(frame->format()); 522 const size_t num_planes = media::VideoFrame::NumPlanes(frame->format());
521 for (size_t i = 0; i < num_planes; ++i) { 523 for (size_t i = 0; i < num_planes; ++i) {
522 gfx::GpuMemoryBufferHandle remote_handle; 524 gfx::GpuMemoryBufferHandle remote_handle;
523 buffer_pool_->ShareToProcess2( 525 buffer_pool_->ShareToProcess2(
524 buffer_id, i, client->render_process_handle, &remote_handle); 526 buffer_id, i, client->render_process_handle, &remote_handle);
525 handles.push_back(remote_handle); 527 handles.push_back(remote_handle);
526 } 528 }
527 client->event_handler->OnBufferCreated2(client->controller_id, handles, 529 client->event_handler->OnBufferCreated2(client->controller_id, handles,
528 buffer->dimensions(), buffer_id); 530 buffer->dimensions(),
531 frame->format(), buffer_id);
529 break; 532 break;
530 } 533 }
531 case media::VideoFrame::STORAGE_SHMEM: { 534 case media::VideoFrame::STORAGE_SHMEM: {
532 base::SharedMemoryHandle remote_handle; 535 base::SharedMemoryHandle remote_handle;
533 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle, 536 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle,
534 &remote_handle); 537 &remote_handle);
535 client->event_handler->OnBufferCreated( 538 client->event_handler->OnBufferCreated(
536 client->controller_id, remote_handle, buffer->mapped_size(), 539 client->controller_id, remote_handle, buffer->mapped_size(),
537 buffer_id); 540 buffer_id);
538 break; 541 break;
(...skipping 19 matching lines...) Expand all
558 int session_id, 561 int session_id,
559 const ControllerClients& clients) { 562 const ControllerClients& clients) {
560 for (const auto& client : clients) { 563 for (const auto& client : clients) {
561 if (client->session_id == session_id) 564 if (client->session_id == session_id)
562 return client.get(); 565 return client.get();
563 } 566 }
564 return nullptr; 567 return nullptr;
565 } 568 }
566 569
567 } // namespace content 570 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698