Make libcamera to work?

This commit is contained in:
Kamil Trzcinski
2022-04-11 10:51:05 +02:00
parent a08904688e
commit aa0f7276bf
3 changed files with 84 additions and 4 deletions

View File

@ -3,7 +3,7 @@
int libcamera_buffer_open(buffer_t *buf)
{
buf->libcamera = new buffer_libcamera_t{};
buf->libcamera->request = buf->buf_list->dev->libcamera->camera->createRequest();
buf->libcamera->request = buf->buf_list->dev->libcamera->camera->createRequest(buf->index);
if (!buf->libcamera->request) {
E_LOG_ERROR(buf, "Can't create request");
}
@ -53,15 +53,72 @@ void libcamera_buffer_close(buffer_t *buf)
int libcamera_buffer_enqueue(buffer_t *buf, const char *who)
{
auto &request = buf->libcamera->request;
auto const &camera = buf->buf_list->dev->libcamera->camera;
request->reuse(libcamera::Request::ReuseBuffers);
// TODO: assign timestamps
// for (auto const &pair : request->buffers()) {
// v4l2_buf.timestamp.tv_sec = buf->captured_time_us / (1000LL * 1000LL);
// v4l2_buf.timestamp.tv_usec = buf->captured_time_us % (1000LL * 1000LL);
// }
if (buf->buf_list->dev->libcamera->camera->queueRequest(buf->libcamera->request.get()) < 0) {
E_LOG_ERROR(buf, "Can't queue buffer.");
}
return 0;
error:
return -1;
}
void buffer_list_libcamera_t::libcamera_buffer_list_dequeued(libcamera::Request *request)
{
E_LOG_INFO(buf_list, "Dequeued: index=%d, status=%d", request->cookie(), request->status());
if (request->status() == libcamera::Request::RequestComplete) {
unsigned index = request->cookie();
if (write(buf_list->libcamera->fds[1], &index, sizeof(index)) == sizeof(index)) {
return;
}
}
// put back into queue, as it failed
buf_list->dev->libcamera->camera->queueRequest(request);
}
int libcamera_buffer_list_dequeue(buffer_list_t *buf_list, buffer_t **bufp)
{
return -1;
unsigned index = 0;
int n = read(buf_list->libcamera->fds[0], &index, sizeof(index));
if (n != sizeof(index)) {
E_LOG_INFO(buf_list, "Received invalid result from `read`: %d", n);
return -1;
}
if (index >= buf_list->nbufs) {
E_LOG_INFO(buf_list, "Received invalid index from `read`: %d >= %d", index, buf_list->nbufs);
return -1;
}
*bufp = buf_list->bufs[index];
// TODO: fix timestamps
// buf->v4l2->flags = v4l2_buf.flags;
// buf->flags.is_keyframe = (v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) != 0;
// buf->captured_time_us = get_time_us(CLOCK_FROM_PARAMS, NULL, &v4l2_buf.timestamp, 0);
return 0;
}
int libcamera_buffer_list_pollfd(buffer_list_t *buf_list, struct pollfd *pollfd, bool can_dequeue)
{
return -1;
int count_enqueued = buffer_list_count_enqueued(buf_list);
pollfd->fd = buf_list->libcamera->fds[0]; // write end
pollfd->events = POLLHUP;
if (can_dequeue && count_enqueued > 0) {
pollfd->events |= POLLIN;
}
pollfd->revents = 0;
return 0;
}