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

Side by Side Diff: media/gpu/v4l2_image_processor.cc

Issue 2980793002: V4L2ImageProcessor: Use VIDIOC_S_SELECTION for buffer region control (Closed)
Patch Set: V4L2ImageProcessor: Use VIDIOC_S_SELECTION for buffer region control Created 3 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <linux/videodev2.h> 7 #include <linux/videodev2.h>
8 #include <poll.h> 8 #include <poll.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/eventfd.h> 10 #include <sys/eventfd.h>
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 format.fmt.pix_mp.height = input_allocated_size_.height(); 358 format.fmt.pix_mp.height = input_allocated_size_.height();
359 format.fmt.pix_mp.pixelformat = input_format_fourcc_; 359 format.fmt.pix_mp.pixelformat = input_format_fourcc_;
360 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_FMT, &format); 360 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_FMT, &format);
361 361
362 input_planes_count_ = format.fmt.pix_mp.num_planes; 362 input_planes_count_ = format.fmt.pix_mp.num_planes;
363 DCHECK_LE(input_planes_count_, static_cast<size_t>(VIDEO_MAX_PLANES)); 363 DCHECK_LE(input_planes_count_, static_cast<size_t>(VIDEO_MAX_PLANES));
364 input_allocated_size_ = V4L2Device::CodedSizeFromV4L2Format(format); 364 input_allocated_size_ = V4L2Device::CodedSizeFromV4L2Format(format);
365 DCHECK(gfx::Rect(input_allocated_size_) 365 DCHECK(gfx::Rect(input_allocated_size_)
366 .Contains(gfx::Rect(input_visible_size_))); 366 .Contains(gfx::Rect(input_visible_size_)));
367 367
368 struct v4l2_crop crop; 368 struct v4l2_rect visible_rect;
369 memset(&crop, 0, sizeof(crop)); 369 visible_rect.left = 0;
370 crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 370 visible_rect.top = 0;
371 crop.c.left = 0; 371 visible_rect.width = base::checked_cast<__u32>(input_visible_size_.width());
372 crop.c.top = 0; 372 visible_rect.height = base::checked_cast<__u32>(input_visible_size_.height());
373 crop.c.width = base::checked_cast<__u32>(input_visible_size_.width()); 373
374 crop.c.height = base::checked_cast<__u32>(input_visible_size_.height()); 374 struct v4l2_selection selection_arg;
375 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_CROP, &crop); 375 memset(&selection_arg, 0, sizeof(selection_arg));
376 selection_arg.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
377 selection_arg.target = V4L2_SEL_TGT_CROP;
378 selection_arg.r = visible_rect;
379 if (device_->Ioctl(VIDIOC_S_SELECTION, &selection_arg) != 0) {
380 DVLOG(2) << "Fallback to VIDIOC_S_CROP for input buffers.";
381 struct v4l2_crop crop;
382 memset(&crop, 0, sizeof(crop));
383 crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
384 crop.c = visible_rect;
385 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_CROP, &crop);
386 }
376 387
377 struct v4l2_requestbuffers reqbufs; 388 struct v4l2_requestbuffers reqbufs;
378 memset(&reqbufs, 0, sizeof(reqbufs)); 389 memset(&reqbufs, 0, sizeof(reqbufs));
379 reqbufs.count = num_buffers_; 390 reqbufs.count = num_buffers_;
380 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 391 reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
381 reqbufs.memory = input_memory_type_; 392 reqbufs.memory = input_memory_type_;
382 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_REQBUFS, &reqbufs); 393 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_REQBUFS, &reqbufs);
383 if (static_cast<int>(reqbufs.count) != num_buffers_) { 394 if (static_cast<int>(reqbufs.count) != num_buffers_) {
384 LOG(ERROR) << "Failed to allocate input buffers. reqbufs.count=" 395 LOG(ERROR) << "Failed to allocate input buffers. reqbufs.count="
385 << reqbufs.count << ", num_buffers=" << num_buffers_; 396 << reqbufs.count << ", num_buffers=" << num_buffers_;
(...skipping 23 matching lines...) Expand all
409 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_FMT, &format); 420 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_FMT, &format);
410 421
411 output_planes_count_ = format.fmt.pix_mp.num_planes; 422 output_planes_count_ = format.fmt.pix_mp.num_planes;
412 DCHECK_LE(output_planes_count_, static_cast<size_t>(VIDEO_MAX_PLANES)); 423 DCHECK_LE(output_planes_count_, static_cast<size_t>(VIDEO_MAX_PLANES));
413 gfx::Size adjusted_allocated_size = 424 gfx::Size adjusted_allocated_size =
414 V4L2Device::CodedSizeFromV4L2Format(format); 425 V4L2Device::CodedSizeFromV4L2Format(format);
415 DCHECK(gfx::Rect(adjusted_allocated_size) 426 DCHECK(gfx::Rect(adjusted_allocated_size)
416 .Contains(gfx::Rect(output_allocated_size_))); 427 .Contains(gfx::Rect(output_allocated_size_)));
417 output_allocated_size_ = adjusted_allocated_size; 428 output_allocated_size_ = adjusted_allocated_size;
418 429
419 struct v4l2_crop crop; 430 struct v4l2_rect visible_rect;
420 memset(&crop, 0, sizeof(crop)); 431 visible_rect.left = 0;
421 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 432 visible_rect.top = 0;
422 crop.c.left = 0; 433 visible_rect.width = base::checked_cast<__u32>(output_visible_size_.width());
423 crop.c.top = 0; 434 visible_rect.height =
424 crop.c.width = base::checked_cast<__u32>(output_visible_size_.width()); 435 base::checked_cast<__u32>(output_visible_size_.height());
425 crop.c.height = base::checked_cast<__u32>(output_visible_size_.height()); 436
426 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_CROP, &crop); 437 struct v4l2_selection selection_arg;
438 memset(&selection_arg, 0, sizeof(selection_arg));
439 selection_arg.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
440 selection_arg.target = V4L2_SEL_TGT_COMPOSE;
441 selection_arg.r = visible_rect;
442 if (device_->Ioctl(VIDIOC_S_SELECTION, &selection_arg) != 0) {
443 DVLOG(2) << "Fallback to VIDIOC_S_CROP for output buffers.";
444 struct v4l2_crop crop;
445 memset(&crop, 0, sizeof(crop));
446 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
447 crop.c = visible_rect;
448 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_CROP, &crop);
449 }
427 450
428 struct v4l2_requestbuffers reqbufs; 451 struct v4l2_requestbuffers reqbufs;
429 memset(&reqbufs, 0, sizeof(reqbufs)); 452 memset(&reqbufs, 0, sizeof(reqbufs));
430 reqbufs.count = num_buffers_; 453 reqbufs.count = num_buffers_;
431 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 454 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
432 reqbufs.memory = output_memory_type_; 455 reqbufs.memory = output_memory_type_;
433 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_REQBUFS, &reqbufs); 456 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_REQBUFS, &reqbufs);
434 if (static_cast<int>(reqbufs.count) != num_buffers_) { 457 if (static_cast<int>(reqbufs.count) != num_buffers_) {
435 LOG(ERROR) << "Failed to allocate output buffers. reqbufs.count=" 458 LOG(ERROR) << "Failed to allocate output buffers. reqbufs.count="
436 << reqbufs.count << ", num_buffers=" << num_buffers_; 459 << reqbufs.count << ", num_buffers=" << num_buffers_;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 output_buffer_queued_count_ = 0; 800 output_buffer_queued_count_ = 0;
778 } 801 }
779 802
780 void V4L2ImageProcessor::FrameReady(const FrameReadyCB& cb, 803 void V4L2ImageProcessor::FrameReady(const FrameReadyCB& cb,
781 int output_buffer_index) { 804 int output_buffer_index) {
782 DCHECK(child_task_runner_->BelongsToCurrentThread()); 805 DCHECK(child_task_runner_->BelongsToCurrentThread());
783 cb.Run(output_buffer_index); 806 cb.Run(output_buffer_index);
784 } 807 }
785 808
786 } // namespace media 809 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698