Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "media/gpu/v4l2_video_encode_accelerator.h" | 5 #include "media/gpu/v4l2_video_encode_accelerator.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
| 9 #include <poll.h> | 9 #include <poll.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1074 DCHECK(child_task_runner_->BelongsToCurrentThread()); | 1074 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
| 1075 DCHECK(!input_streamon_); | 1075 DCHECK(!input_streamon_); |
| 1076 DCHECK(!output_streamon_); | 1076 DCHECK(!output_streamon_); |
| 1077 | 1077 |
| 1078 if (!SetOutputFormat(output_profile)) | 1078 if (!SetOutputFormat(output_profile)) |
| 1079 return false; | 1079 return false; |
| 1080 | 1080 |
| 1081 if (!NegotiateInputFormat(input_format)) | 1081 if (!NegotiateInputFormat(input_format)) |
| 1082 return false; | 1082 return false; |
| 1083 | 1083 |
| 1084 struct v4l2_crop crop; | 1084 struct v4l2_rect visible_rect; |
| 1085 memset(&crop, 0, sizeof(crop)); | 1085 visible_rect.left = 0; |
| 1086 crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1086 visible_rect.top = 0; |
| 1087 crop.c.left = 0; | 1087 visible_rect.width = visible_size_.width(); |
| 1088 crop.c.top = 0; | 1088 visible_rect.height = visible_size_.height(); |
| 1089 crop.c.width = visible_size_.width(); | |
| 1090 crop.c.height = visible_size_.height(); | |
| 1091 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_CROP, &crop); | |
| 1092 | 1089 |
| 1093 // The width and height might be adjusted by driver. | 1090 struct v4l2_selection selection_arg; |
| 1094 // Need to read it back and set to visible_size_. | 1091 memset(&selection_arg, 0, sizeof(selection_arg)); |
| 1095 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_G_CROP, &crop); | 1092 selection_arg.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 1096 visible_size_.SetSize(crop.c.width, crop.c.height); | 1093 selection_arg.target = V4L2_SEL_TGT_CROP; |
| 1094 selection_arg.r = visible_rect; | |
| 1095 | |
| 1096 if (device_->Ioctl(VIDIOC_S_SELECTION, &selection_arg) == 0) { | |
| 1097 DVLOG(2) << "VIDIOC_S_SELECTION is supported"; | |
| 1098 // The width and height might be adjusted by driver. | |
| 1099 // Need to read it back and set to visible_size_. | |
| 1100 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_G_SELECTION, &selection_arg); | |
|
wuchengli
2017/07/18 05:46:22
VIDIOC_S_SELECTION will adjust the rect. No need t
| |
| 1101 visible_rect = selection_arg.r; | |
| 1102 } | |
| 1103 else { | |
| 1104 DVLOG(2) << "Fallback to VIDIOC_S/G_CROP"; | |
| 1105 struct v4l2_crop crop; | |
| 1106 memset(&crop, 0, sizeof(crop)); | |
| 1107 crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | |
| 1108 crop.c = visible_rect; | |
| 1109 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_CROP, &crop); | |
| 1110 // The width and height might be adjusted by driver. | |
| 1111 // Need to read it back and set to visible_size_. | |
| 1112 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_G_CROP, &crop); | |
| 1113 visible_rect = crop.c; | |
| 1114 } | |
| 1115 | |
| 1116 visible_size_.SetSize(visible_rect.width, visible_rect.height); | |
| 1097 DVLOG(3) << "After adjusted by driver, visible_size_=" | 1117 DVLOG(3) << "After adjusted by driver, visible_size_=" |
| 1098 << visible_size_.ToString(); | 1118 << visible_size_.ToString(); |
| 1099 | 1119 |
| 1100 return true; | 1120 return true; |
| 1101 } | 1121 } |
| 1102 | 1122 |
| 1103 bool V4L2VideoEncodeAccelerator::IsCtrlExposed(uint32_t ctrl_id) { | 1123 bool V4L2VideoEncodeAccelerator::IsCtrlExposed(uint32_t ctrl_id) { |
| 1104 struct v4l2_queryctrl query_ctrl; | 1124 struct v4l2_queryctrl query_ctrl; |
| 1105 memset(&query_ctrl, 0, sizeof(query_ctrl)); | 1125 memset(&query_ctrl, 0, sizeof(query_ctrl)); |
| 1106 query_ctrl.id = ctrl_id; | 1126 query_ctrl.id = ctrl_id; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 memset(&reqbufs, 0, sizeof(reqbufs)); | 1353 memset(&reqbufs, 0, sizeof(reqbufs)); |
| 1334 reqbufs.count = 0; | 1354 reqbufs.count = 0; |
| 1335 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1355 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1336 reqbufs.memory = V4L2_MEMORY_MMAP; | 1356 reqbufs.memory = V4L2_MEMORY_MMAP; |
| 1337 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); | 1357 IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
| 1338 | 1358 |
| 1339 output_buffer_map_.clear(); | 1359 output_buffer_map_.clear(); |
| 1340 } | 1360 } |
| 1341 | 1361 |
| 1342 } // namespace media | 1362 } // namespace media |
| OLD | NEW |