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

Side by Side Diff: chrome/gpu/arc_gpu_video_decode_accelerator.cc

Issue 2513973002: Use mojo typemap to simplify the code using DmabufPlane (Closed)
Patch Set: Addressed comments Created 4 years 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 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/numerics/safe_math.h" 9 #include "base/numerics/safe_math.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return; 179 return;
180 } 180 }
181 InputBufferInfo* input_info = &input_buffer_info_[index]; 181 InputBufferInfo* input_info = &input_buffer_info_[index];
182 input_info->handle = std::move(ashmem_fd); 182 input_info->handle = std::move(ashmem_fd);
183 input_info->offset = offset; 183 input_info->offset = offset;
184 input_info->length = length; 184 input_info->length = length;
185 } 185 }
186 186
187 bool ArcGpuVideoDecodeAccelerator::VerifyDmabuf( 187 bool ArcGpuVideoDecodeAccelerator::VerifyDmabuf(
188 const base::ScopedFD& dmabuf_fd, 188 const base::ScopedFD& dmabuf_fd,
189 const std::vector<DmabufPlane>& dmabuf_planes) const { 189 const std::vector<::arc::ArcVideoAcceleratorDmabufPlane>& dmabuf_planes)
190 const {
190 size_t num_planes = media::VideoFrame::NumPlanes(output_pixel_format_); 191 size_t num_planes = media::VideoFrame::NumPlanes(output_pixel_format_);
191 if (dmabuf_planes.size() != num_planes) { 192 if (dmabuf_planes.size() != num_planes) {
192 DLOG(ERROR) << "Invalid number of dmabuf planes passed: " 193 DLOG(ERROR) << "Invalid number of dmabuf planes passed: "
193 << dmabuf_planes.size() << ", expected: " << num_planes; 194 << dmabuf_planes.size() << ", expected: " << num_planes;
194 return false; 195 return false;
195 } 196 }
196 197
197 off_t size = lseek(dmabuf_fd.get(), 0, SEEK_END); 198 off_t size = lseek(dmabuf_fd.get(), 0, SEEK_END);
198 lseek(dmabuf_fd.get(), 0, SEEK_SET); 199 lseek(dmabuf_fd.get(), 0, SEEK_SET);
199 if (size < 0) { 200 if (size < 0) {
200 DPLOG(ERROR) << "fail to find the size of dmabuf"; 201 DPLOG(ERROR) << "fail to find the size of dmabuf";
201 return false; 202 return false;
202 } 203 }
203 204
204 size_t i = 0; 205 size_t i = 0;
205 for (const auto& plane : dmabuf_planes) { 206 for (const auto& plane : dmabuf_planes) {
206 DVLOG(4) << "Plane " << i << ", offset: " << plane.offset 207 DVLOG(4) << "Plane " << i << ", offset: " << plane.offset
207 << ", stride: " << plane.stride; 208 << ", stride: " << plane.stride;
208 209
209 size_t rows = 210 size_t rows =
210 media::VideoFrame::Rows(i, output_pixel_format_, coded_size_.height()); 211 media::VideoFrame::Rows(i, output_pixel_format_, coded_size_.height());
211 base::CheckedNumeric<off_t> current_size(plane.offset); 212 base::CheckedNumeric<off_t> current_size(plane.offset);
212 current_size += plane.stride * rows; 213 current_size += plane.stride * rows;
dcheng 2016/12/01 01:30:50 Btw, is it possible for this to overflow size_t be
yoshiki 2016/12/02 08:31:43 Powel, could you answer this question?
Pawel Osciak 2016/12/06 07:08:38 Yes, it looks technically possible.
yoshiki 2016/12/06 16:48:33 Done. I made this checked.
213 214
214 if (!current_size.IsValid() || current_size.ValueOrDie() > size) { 215 if (!current_size.IsValid() || current_size.ValueOrDie() > size) {
215 DLOG(ERROR) << "Invalid strides/offsets"; 216 DLOG(ERROR) << "Invalid strides/offsets";
216 return false; 217 return false;
217 } 218 }
218 219
219 ++i; 220 ++i;
220 } 221 }
221 222
222 return true; 223 return true;
223 } 224 }
224 225
225 void ArcGpuVideoDecodeAccelerator::BindDmabuf( 226 void ArcGpuVideoDecodeAccelerator::BindDmabuf(
226 PortType port, 227 PortType port,
227 uint32_t index, 228 uint32_t index,
228 base::ScopedFD dmabuf_fd, 229 base::ScopedFD dmabuf_fd,
229 const std::vector<DmabufPlane>& dmabuf_planes) { 230 const std::vector<::arc::ArcVideoAcceleratorDmabufPlane>& dmabuf_planes) {
230 DCHECK(thread_checker_.CalledOnValidThread()); 231 DCHECK(thread_checker_.CalledOnValidThread());
231 232
232 if (!vda_) { 233 if (!vda_) {
233 DLOG(ERROR) << "VDA not initialized"; 234 DLOG(ERROR) << "VDA not initialized";
234 return; 235 return;
235 } 236 }
236 237
237 if (port != PORT_OUTPUT) { 238 if (port != PORT_OUTPUT) {
238 DLOG(ERROR) << "Dmabuf is only supported for input"; 239 DLOG(ERROR) << "Dmabuf is only supported for input";
239 arc_client_->OnError(INVALID_ARGUMENT); 240 arc_client_->OnError(INVALID_ARGUMENT);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 510 }
510 return true; 511 return true;
511 default: 512 default:
512 DLOG(ERROR) << "Invalid port: " << port; 513 DLOG(ERROR) << "Invalid port: " << port;
513 return false; 514 return false;
514 } 515 }
515 } 516 }
516 517
517 } // namespace arc 518 } // namespace arc
518 } // namespace chromeos 519 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698