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 // Notes about usage of this object by VideoCaptureImplManager. | 5 // Notes about usage of this object by VideoCaptureImplManager. |
6 // | 6 // |
7 // VideoCaptureImplManager access this object by using a Unretained() | 7 // VideoCaptureImplManager access this object by using a Unretained() |
8 // binding and tasks on the IO thread. It is then important that | 8 // binding and tasks on the IO thread. It is then important that |
9 // VideoCaptureImpl never post task to itself. All operations must be | 9 // VideoCaptureImpl never post task to itself. All operations must be |
10 // synchronous. | 10 // synchronous. |
11 | 11 |
12 #include "content/renderer/media/video_capture_impl.h" | 12 #include "content/renderer/media/video_capture_impl.h" |
13 | 13 |
| 14 #include <stddef.h> |
| 15 |
14 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/macros.h" |
15 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
16 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
17 #include "content/child/child_process.h" | 20 #include "content/child/child_process.h" |
18 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | 21 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
19 #include "content/common/media/video_capture_messages.h" | 22 #include "content/common/media/video_capture_messages.h" |
20 #include "media/base/bind_to_current_loop.h" | 23 #include "media/base/bind_to_current_loop.h" |
21 #include "media/base/limits.h" | 24 #include "media/base/limits.h" |
22 #include "media/base/video_frame.h" | 25 #include "media/base/video_frame.h" |
23 | 26 |
24 namespace content { | 27 namespace content { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 for (size_t i = 0; i < handles_.size(); ++i) { | 62 for (size_t i = 0; i < handles_.size(); ++i) { |
60 const size_t width = media::VideoFrame::Columns(i, format, size_.width()); | 63 const size_t width = media::VideoFrame::Columns(i, format, size_.width()); |
61 const size_t height = media::VideoFrame::Rows(i, format, size_.height()); | 64 const size_t height = media::VideoFrame::Rows(i, format, size_.height()); |
62 buffers_.push_back(GpuMemoryBufferImpl::CreateFromHandle( | 65 buffers_.push_back(GpuMemoryBufferImpl::CreateFromHandle( |
63 handles_[i], gfx::Size(width, height), gfx::BufferFormat::R_8, | 66 handles_[i], gfx::Size(width, height), gfx::BufferFormat::R_8, |
64 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 67 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
65 base::Bind(&ClientBuffer2::DestroyGpuMemoryBuffer, | 68 base::Bind(&ClientBuffer2::DestroyGpuMemoryBuffer, |
66 base::Unretained(this)))); | 69 base::Unretained(this)))); |
67 bool rv = buffers_[i]->Map(); | 70 bool rv = buffers_[i]->Map(); |
68 DCHECK(rv); | 71 DCHECK(rv); |
69 data_[i] = reinterpret_cast<uint8*>(buffers_[i]->memory(0u)); | 72 data_[i] = reinterpret_cast<uint8_t*>(buffers_[i]->memory(0u)); |
70 strides_[i] = width; | 73 strides_[i] = width; |
71 } | 74 } |
72 } | 75 } |
73 | 76 |
74 uint8* data(int plane) const { return data_[plane]; } | 77 uint8_t* data(int plane) const { return data_[plane]; } |
75 int32 stride(int plane) const { return strides_[plane]; } | 78 int32_t stride(int plane) const { return strides_[plane]; } |
76 std::vector<gfx::GpuMemoryBufferHandle> gpu_memory_buffer_handles() { | 79 std::vector<gfx::GpuMemoryBufferHandle> gpu_memory_buffer_handles() { |
77 return handles_; | 80 return handles_; |
78 } | 81 } |
79 | 82 |
80 private: | 83 private: |
81 friend class base::RefCountedThreadSafe<ClientBuffer2>; | 84 friend class base::RefCountedThreadSafe<ClientBuffer2>; |
82 | 85 |
83 virtual ~ClientBuffer2() { | 86 virtual ~ClientBuffer2() { |
84 for (auto& buffer : buffers_) | 87 for (auto& buffer : buffers_) |
85 buffer->Unmap(); | 88 buffer->Unmap(); |
86 } | 89 } |
87 | 90 |
88 void DestroyGpuMemoryBuffer(const gpu::SyncToken& sync_token) {} | 91 void DestroyGpuMemoryBuffer(const gpu::SyncToken& sync_token) {} |
89 | 92 |
90 const std::vector<gfx::GpuMemoryBufferHandle> handles_; | 93 const std::vector<gfx::GpuMemoryBufferHandle> handles_; |
91 const gfx::Size size_; | 94 const gfx::Size size_; |
92 ScopedVector<gfx::GpuMemoryBuffer> buffers_; | 95 ScopedVector<gfx::GpuMemoryBuffer> buffers_; |
93 uint8* data_[media::VideoFrame::kMaxPlanes]; | 96 uint8_t* data_[media::VideoFrame::kMaxPlanes]; |
94 int32 strides_[media::VideoFrame::kMaxPlanes]; | 97 int32_t strides_[media::VideoFrame::kMaxPlanes]; |
95 | 98 |
96 DISALLOW_COPY_AND_ASSIGN(ClientBuffer2); | 99 DISALLOW_COPY_AND_ASSIGN(ClientBuffer2); |
97 }; | 100 }; |
98 | 101 |
99 VideoCaptureImpl::ClientInfo::ClientInfo() {} | 102 VideoCaptureImpl::ClientInfo::ClientInfo() {} |
100 VideoCaptureImpl::ClientInfo::~ClientInfo() {} | 103 VideoCaptureImpl::ClientInfo::~ClientInfo() {} |
101 | 104 |
102 VideoCaptureImpl::VideoCaptureImpl( | 105 VideoCaptureImpl::VideoCaptureImpl( |
103 const media::VideoCaptureSessionId session_id, | 106 const media::VideoCaptureSessionId session_id, |
104 VideoCaptureMessageFilter* filter) | 107 VideoCaptureMessageFilter* filter) |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 buffer_finished_callback = media::BindToCurrentLoop( | 351 buffer_finished_callback = media::BindToCurrentLoop( |
349 base::Bind(&VideoCaptureImpl::OnClientBufferFinished2, | 352 base::Bind(&VideoCaptureImpl::OnClientBufferFinished2, |
350 weak_factory_.GetWeakPtr(), buffer_id, buffer)); | 353 weak_factory_.GetWeakPtr(), buffer_id, buffer)); |
351 break; | 354 break; |
352 } | 355 } |
353 case media::VideoFrame::STORAGE_SHMEM: { | 356 case media::VideoFrame::STORAGE_SHMEM: { |
354 const auto& iter = client_buffers_.find(buffer_id); | 357 const auto& iter = client_buffers_.find(buffer_id); |
355 DCHECK(iter != client_buffers_.end()); | 358 DCHECK(iter != client_buffers_.end()); |
356 const scoped_refptr<ClientBuffer> buffer = iter->second; | 359 const scoped_refptr<ClientBuffer> buffer = iter->second; |
357 frame = media::VideoFrame::WrapExternalSharedMemory( | 360 frame = media::VideoFrame::WrapExternalSharedMemory( |
358 pixel_format, | 361 pixel_format, coded_size, visible_rect, |
359 coded_size, | 362 gfx::Size(visible_rect.width(), visible_rect.height()), |
360 visible_rect, | 363 reinterpret_cast<uint8_t*>(buffer->buffer()->memory()), |
361 gfx::Size(visible_rect.width(), | 364 buffer->buffer_size(), buffer->buffer()->handle(), |
362 visible_rect.height()), | 365 0 /* shared_memory_offset */, timestamp - first_frame_timestamp_); |
363 reinterpret_cast<uint8*>(buffer->buffer()->memory()), | |
364 buffer->buffer_size(), | |
365 buffer->buffer()->handle(), | |
366 0 /* shared_memory_offset */, | |
367 timestamp - first_frame_timestamp_); | |
368 buffer_finished_callback = media::BindToCurrentLoop( | 366 buffer_finished_callback = media::BindToCurrentLoop( |
369 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 367 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
370 weak_factory_.GetWeakPtr(), buffer_id, buffer)); | 368 weak_factory_.GetWeakPtr(), buffer_id, buffer)); |
371 break; | 369 break; |
372 } | 370 } |
373 default: | 371 default: |
374 NOTREACHED(); | 372 NOTREACHED(); |
375 break; | 373 break; |
376 } | 374 } |
377 DCHECK(frame); | 375 DCHECK(frame); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 456 } |
459 | 457 |
460 void VideoCaptureImpl::OnDeviceFormatsInUseReceived( | 458 void VideoCaptureImpl::OnDeviceFormatsInUseReceived( |
461 const media::VideoCaptureFormats& formats_in_use) { | 459 const media::VideoCaptureFormats& formats_in_use) { |
462 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 460 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
463 for (size_t i = 0; i < device_formats_in_use_cb_queue_.size(); ++i) | 461 for (size_t i = 0; i < device_formats_in_use_cb_queue_.size(); ++i) |
464 device_formats_in_use_cb_queue_[i].Run(formats_in_use); | 462 device_formats_in_use_cb_queue_[i].Run(formats_in_use); |
465 device_formats_in_use_cb_queue_.clear(); | 463 device_formats_in_use_cb_queue_.clear(); |
466 } | 464 } |
467 | 465 |
468 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) { | 466 void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) { |
469 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 467 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
470 DVLOG(1) << "OnDelegateAdded: device_id " << device_id; | 468 DVLOG(1) << "OnDelegateAdded: device_id " << device_id; |
471 | 469 |
472 device_id_ = device_id; | 470 device_id_ = device_id; |
473 ClientInfoMap::iterator it = clients_pending_on_filter_.begin(); | 471 ClientInfoMap::iterator it = clients_pending_on_filter_.begin(); |
474 while (it != clients_pending_on_filter_.end()) { | 472 while (it != clients_pending_on_filter_.end()) { |
475 const int client_id = it->first; | 473 const int client_id = it->first; |
476 const ClientInfo client_info = it->second; | 474 const ClientInfo client_info = it->second; |
477 clients_pending_on_filter_.erase(it++); | 475 clients_pending_on_filter_.erase(it++); |
478 StartCapture(client_id, client_info.params, client_info.state_update_cb, | 476 StartCapture(client_id, client_info.params, client_info.state_update_cb, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 double consumer_resource_utilization = -1.0; | 545 double consumer_resource_utilization = -1.0; |
548 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 546 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
549 &consumer_resource_utilization)) { | 547 &consumer_resource_utilization)) { |
550 consumer_resource_utilization = -1.0; | 548 consumer_resource_utilization = -1.0; |
551 } | 549 } |
552 | 550 |
553 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); | 551 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); |
554 } | 552 } |
555 | 553 |
556 } // namespace content | 554 } // namespace content |
OLD | NEW |