| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/callback_helpers.h" | 5 #include "base/callback_helpers.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h" | 8 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h" |
| 9 #include "content/public/gpu/gpu_video_decode_accelerator_factory.h" | 9 #include "content/public/gpu/gpu_video_decode_accelerator_factory.h" |
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| 11 | 11 |
| 12 #undef DVLOG | 12 #undef DVLOG |
| 13 #define DVLOG VLOG | 13 #define DVLOG VLOG |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 namespace arc { | 16 namespace arc { |
| 17 | 17 |
| 18 ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( | 18 ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( |
| 19 int32_t bitstream_buffer_id, | 19 int32_t bitstream_buffer_id, |
| 20 uint32_t buffer_index, | 20 uint32_t buffer_index, |
| 21 int64_t timestamp) | 21 int64_t timestamp) |
| 22 : bitstream_buffer_id(bitstream_buffer_id), | 22 : bitstream_buffer_id(bitstream_buffer_id), |
| 23 buffer_index(buffer_index), | 23 buffer_index(buffer_index), |
| 24 timestamp(timestamp) {} | 24 timestamp(timestamp) {} |
| 25 | 25 |
| 26 ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator( | 26 ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator() |
| 27 const gpu::GpuPreferences& gpu_preferences) | |
| 28 : pending_eos_output_buffer_(false), | 27 : pending_eos_output_buffer_(false), |
| 29 arc_client_(nullptr), | 28 arc_client_(nullptr), |
| 30 next_bitstream_buffer_id_(0), | 29 next_bitstream_buffer_id_(0), |
| 31 output_buffer_size_(0), | 30 output_buffer_size_(0) {} |
| 32 gpu_preferences_(gpu_preferences) {} | |
| 33 | 31 |
| 34 ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() {} | 32 ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() {} |
| 35 | 33 |
| 36 namespace { | 34 namespace { |
| 37 | 35 |
| 38 // An arbitrary chosen limit of the number of buffers. The number of | 36 // An arbitrary chosen limit of the number of buffers. The number of |
| 39 // buffers used is requested from the untrusted client side. | 37 // buffers used is requested from the untrusted client side. |
| 40 const size_t kMaxBufferCount = 128; | 38 const size_t kMaxBufferCount = 128; |
| 41 | 39 |
| 42 } // anonymous namespace | 40 } // anonymous namespace |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 media::PictureBuffer(base::checked_cast<int32_t>(id), coded_size_, 0)); | 109 media::PictureBuffer(base::checked_cast<int32_t>(id), coded_size_, 0)); |
| 112 } | 110 } |
| 113 vda_->AssignPictureBuffers(buffers); | 111 vda_->AssignPictureBuffers(buffers); |
| 114 | 112 |
| 115 buffers_pending_import_.clear(); | 113 buffers_pending_import_.clear(); |
| 116 buffers_pending_import_.resize(number); | 114 buffers_pending_import_.resize(number); |
| 117 } | 115 } |
| 118 | 116 |
| 119 void ArcGpuVideoDecodeAccelerator::BindSharedMemory(PortType port, | 117 void ArcGpuVideoDecodeAccelerator::BindSharedMemory(PortType port, |
| 120 uint32_t index, | 118 uint32_t index, |
| 121 int ashmem_fd, | 119 base::ScopedFD ashmem_fd, |
| 122 off_t offset, | 120 off_t offset, |
| 123 size_t length) { | 121 size_t length) { |
| 124 DVLOG(5) << "ArcGVDA::BindSharedMemory, offset: " << offset | 122 DVLOG(5) << "ArcGVDA::BindSharedMemory, offset: " << offset |
| 125 << ", length: " << length; | 123 << ", length: " << length; |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 124 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 if (!vda_) { | 125 if (!vda_) { |
| 128 DLOG(ERROR) << "VDA not initialized"; | 126 DLOG(ERROR) << "VDA not initialized"; |
| 129 return; | 127 return; |
| 130 } | 128 } |
| 131 | 129 |
| 132 // Make sure we will close the file descriptor. | |
| 133 base::ScopedFD handle(ashmem_fd); | |
| 134 if (port != PORT_INPUT) { | 130 if (port != PORT_INPUT) { |
| 135 DLOG(ERROR) << "SharedBuffer is only supported for input"; | 131 DLOG(ERROR) << "SharedBuffer is only supported for input"; |
| 136 arc_client_->OnError(INVALID_ARGUMENT); | 132 arc_client_->OnError(INVALID_ARGUMENT); |
| 137 return; | 133 return; |
| 138 } | 134 } |
| 139 if (!ValidatePortAndIndex(port, index)) { | 135 if (!ValidatePortAndIndex(port, index)) { |
| 140 arc_client_->OnError(INVALID_ARGUMENT); | 136 arc_client_->OnError(INVALID_ARGUMENT); |
| 141 return; | 137 return; |
| 142 } | 138 } |
| 143 InputBufferInfo* input_info = &input_buffer_info_[index]; | 139 InputBufferInfo* input_info = &input_buffer_info_[index]; |
| 144 input_info->handle = std::move(handle); | 140 input_info->handle = std::move(ashmem_fd); |
| 145 input_info->offset = offset; | 141 input_info->offset = offset; |
| 146 input_info->length = length; | 142 input_info->length = length; |
| 147 } | 143 } |
| 148 | 144 |
| 149 void ArcGpuVideoDecodeAccelerator::BindDmabuf(PortType port, | 145 void ArcGpuVideoDecodeAccelerator::BindDmabuf(PortType port, |
| 150 uint32_t index, | 146 uint32_t index, |
| 151 int dmabuf_fd) { | 147 base::ScopedFD dmabuf_fd) { |
| 152 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
| 153 | 149 |
| 154 if (!vda_) { | 150 if (!vda_) { |
| 155 DLOG(ERROR) << "VDA not initialized"; | 151 DLOG(ERROR) << "VDA not initialized"; |
| 156 return; | 152 return; |
| 157 } | 153 } |
| 158 | 154 |
| 159 // Make sure we will close the file descriptor. | |
| 160 base::ScopedFD handle(dmabuf_fd); | |
| 161 if (port != PORT_OUTPUT) { | 155 if (port != PORT_OUTPUT) { |
| 162 DLOG(ERROR) << "Dmabuf is only supported for input"; | 156 DLOG(ERROR) << "Dmabuf is only supported for input"; |
| 163 arc_client_->OnError(INVALID_ARGUMENT); | 157 arc_client_->OnError(INVALID_ARGUMENT); |
| 164 return; | 158 return; |
| 165 } | 159 } |
| 166 if (!ValidatePortAndIndex(port, index)) { | 160 if (!ValidatePortAndIndex(port, index)) { |
| 167 arc_client_->OnError(INVALID_ARGUMENT); | 161 arc_client_->OnError(INVALID_ARGUMENT); |
| 168 return; | 162 return; |
| 169 } | 163 } |
| 170 buffers_pending_import_[index] = std::move(handle); | 164 buffers_pending_import_[index] = std::move(dmabuf_fd); |
| 171 } | 165 } |
| 172 | 166 |
| 173 void ArcGpuVideoDecodeAccelerator::UseBuffer(PortType port, | 167 void ArcGpuVideoDecodeAccelerator::UseBuffer(PortType port, |
| 174 uint32_t index, | 168 uint32_t index, |
| 175 const BufferMetadata& metadata) { | 169 const BufferMetadata& metadata) { |
| 176 DVLOG(5) << "UseBuffer(port=" << port << ", index=" << index | 170 DVLOG(5) << "UseBuffer(port=" << port << ", index=" << index |
| 177 << ", metadata=(bytes_used=" << metadata.bytes_used | 171 << ", metadata=(bytes_used=" << metadata.bytes_used |
| 178 << ", timestamp=" << metadata.timestamp << ")"; | 172 << ", timestamp=" << metadata.timestamp << ")"; |
| 179 DCHECK(thread_checker_.CalledOnValidThread()); | 173 DCHECK(thread_checker_.CalledOnValidThread()); |
| 180 if (!vda_) { | 174 if (!vda_) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 399 } |
| 406 return true; | 400 return true; |
| 407 default: | 401 default: |
| 408 DLOG(ERROR) << "Invalid port: " << port; | 402 DLOG(ERROR) << "Invalid port: " << port; |
| 409 return false; | 403 return false; |
| 410 } | 404 } |
| 411 } | 405 } |
| 412 | 406 |
| 413 } // namespace arc | 407 } // namespace arc |
| 414 } // namespace chromeos | 408 } // namespace chromeos |
| OLD | NEW |