| 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 "chrome/gpu/arc_gpu_video_decode_accelerator.h" | 5 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/numerics/safe_math.h" | 10 #include "base/numerics/safe_math.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 InputBufferInfo* input_info = &input_buffer_info_[index]; | 193 InputBufferInfo* input_info = &input_buffer_info_[index]; |
| 194 input_info->handle = std::move(ashmem_fd); | 194 input_info->handle = std::move(ashmem_fd); |
| 195 input_info->offset = offset; | 195 input_info->offset = offset; |
| 196 input_info->length = length; | 196 input_info->length = length; |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool ArcGpuVideoDecodeAccelerator::VerifyDmabuf( | 199 bool ArcGpuVideoDecodeAccelerator::VerifyDmabuf( |
| 200 const base::ScopedFD& dmabuf_fd, | 200 const base::ScopedFD& dmabuf_fd, |
| 201 const std::vector<DmabufPlane>& dmabuf_planes) const { | 201 const std::vector<::arc::ArcVideoAcceleratorDmabufPlane>& dmabuf_planes) |
| 202 const { |
| 202 size_t num_planes = media::VideoFrame::NumPlanes(output_pixel_format_); | 203 size_t num_planes = media::VideoFrame::NumPlanes(output_pixel_format_); |
| 203 if (dmabuf_planes.size() != num_planes) { | 204 if (dmabuf_planes.size() != num_planes) { |
| 204 DLOG(ERROR) << "Invalid number of dmabuf planes passed: " | 205 DLOG(ERROR) << "Invalid number of dmabuf planes passed: " |
| 205 << dmabuf_planes.size() << ", expected: " << num_planes; | 206 << dmabuf_planes.size() << ", expected: " << num_planes; |
| 206 return false; | 207 return false; |
| 207 } | 208 } |
| 208 | 209 |
| 209 off_t size = lseek(dmabuf_fd.get(), 0, SEEK_END); | 210 off_t size = lseek(dmabuf_fd.get(), 0, SEEK_END); |
| 210 lseek(dmabuf_fd.get(), 0, SEEK_SET); | 211 lseek(dmabuf_fd.get(), 0, SEEK_SET); |
| 211 if (size < 0) { | 212 if (size < 0) { |
| 212 DPLOG(ERROR) << "fail to find the size of dmabuf"; | 213 DPLOG(ERROR) << "fail to find the size of dmabuf"; |
| 213 return false; | 214 return false; |
| 214 } | 215 } |
| 215 | 216 |
| 216 size_t i = 0; | 217 size_t i = 0; |
| 217 for (const auto& plane : dmabuf_planes) { | 218 for (const auto& plane : dmabuf_planes) { |
| 218 DVLOG(4) << "Plane " << i << ", offset: " << plane.offset | 219 DVLOG(4) << "Plane " << i << ", offset: " << plane.offset |
| 219 << ", stride: " << plane.stride; | 220 << ", stride: " << plane.stride; |
| 220 | 221 |
| 221 size_t rows = | 222 size_t rows = |
| 222 media::VideoFrame::Rows(i, output_pixel_format_, coded_size_.height()); | 223 media::VideoFrame::Rows(i, output_pixel_format_, coded_size_.height()); |
| 223 base::CheckedNumeric<off_t> current_size(plane.offset); | 224 base::CheckedNumeric<off_t> current_size(plane.offset); |
| 224 current_size += plane.stride * rows; | 225 current_size += base::CheckMul(plane.stride, rows); |
| 225 | 226 |
| 226 if (!current_size.IsValid() || current_size.ValueOrDie() > size) { | 227 if (!current_size.IsValid() || current_size.ValueOrDie() > size) { |
| 227 DLOG(ERROR) << "Invalid strides/offsets"; | 228 DLOG(ERROR) << "Invalid strides/offsets"; |
| 228 return false; | 229 return false; |
| 229 } | 230 } |
| 230 | 231 |
| 231 ++i; | 232 ++i; |
| 232 } | 233 } |
| 233 | 234 |
| 234 return true; | 235 return true; |
| 235 } | 236 } |
| 236 | 237 |
| 237 void ArcGpuVideoDecodeAccelerator::BindDmabuf( | 238 void ArcGpuVideoDecodeAccelerator::BindDmabuf( |
| 238 PortType port, | 239 PortType port, |
| 239 uint32_t index, | 240 uint32_t index, |
| 240 base::ScopedFD dmabuf_fd, | 241 base::ScopedFD dmabuf_fd, |
| 241 const std::vector<DmabufPlane>& dmabuf_planes) { | 242 const std::vector<::arc::ArcVideoAcceleratorDmabufPlane>& dmabuf_planes) { |
| 242 DCHECK(thread_checker_.CalledOnValidThread()); | 243 DCHECK(thread_checker_.CalledOnValidThread()); |
| 243 | 244 |
| 244 if (!vda_) { | 245 if (!vda_) { |
| 245 DLOG(ERROR) << "VDA not initialized"; | 246 DLOG(ERROR) << "VDA not initialized"; |
| 246 return; | 247 return; |
| 247 } | 248 } |
| 248 | 249 |
| 249 if (port != PORT_OUTPUT) { | 250 if (port != PORT_OUTPUT) { |
| 250 DLOG(ERROR) << "Dmabuf is only supported for input"; | 251 DLOG(ERROR) << "Dmabuf is only supported for input"; |
| 251 arc_client_->OnError(INVALID_ARGUMENT); | 252 arc_client_->OnError(INVALID_ARGUMENT); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 } | 522 } |
| 522 return true; | 523 return true; |
| 523 default: | 524 default: |
| 524 DLOG(ERROR) << "Invalid port: " << port; | 525 DLOG(ERROR) << "Invalid port: " << port; |
| 525 return false; | 526 return false; |
| 526 } | 527 } |
| 527 } | 528 } |
| 528 | 529 |
| 529 } // namespace arc | 530 } // namespace arc |
| 530 } // namespace chromeos | 531 } // namespace chromeos |
| OLD | NEW |