| 191 | } |
| 192 | |
| 193 | Status CaptureNextFrame(int camera_handle, CameraBuffer* buffers, |
| 194 | uint8_t** frame_data, int* frame_data_size, |
| 195 | v4l2_buffer* buf) { |
| 196 | int r; |
| 197 | do { |
| 198 | fd_set fds; |
| 199 | FD_ZERO(&fds); |
| 200 | FD_SET(camera_handle, &fds); |
| 201 | struct timeval tv; |
| 202 | tv.tv_sec = 2; |
| 203 | tv.tv_usec = 0; |
| 204 | r = select(camera_handle + 1, &fds, NULL, NULL, &tv); |
| 205 | } while ((r == -1 && (errno = EINTR))); |
| 206 | if (r == -1) { |
| 207 | LOG(ERROR) << "select() failed while waiting for the camera with " << errno; |
| 208 | return tensorflow::errors::Unknown( |
| 209 | "CaptureCameraFrame: select() failed with", errno); |
| 210 | } |
| 211 | |
| 212 | memset(buf, 0, sizeof(*buf)); |
| 213 | buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 214 | buf->memory = V4L2_MEMORY_MMAP; |
| 215 | Status get_buffer_status = |
| 216 | SendCameraCommand(camera_handle, VIDIOC_DQBUF, buf); |
| 217 | if (!get_buffer_status.ok()) { |
| 218 | LOG(ERROR) << "Get buffer failed with " << get_buffer_status; |
| 219 | return get_buffer_status; |
| 220 | } |
| 221 | |
| 222 | *frame_data = static_cast<uint8_t*>(buffers[buf->index].start); |
| 223 | *frame_data_size = buf->bytesused; |
| 224 | |
| 225 | return Status::OK(); |
| 226 | } |
| 227 | |
| 228 | Status ReleaseFrame(int camera_handle, v4l2_buffer* buf) { |
| 229 | Status release_buffer_status = |
no test coverage detected