Improve links to use sinks
This commit is contained in:
parent
4d999d9426
commit
e52a2326c3
@ -44,16 +44,16 @@ int camera_configure_decoder(camera_t *camera)
|
||||
link_t *links = camera->links;
|
||||
|
||||
if (camera->options.format == V4L2_PIX_FMT_MJPEG || camera->options.format == V4L2_PIX_FMT_JPEG) {
|
||||
*links++ = (link_t){ camera->camera, { camera->decoder }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->decoder, { camera->codec_h264 } };
|
||||
*links++ = (link_t){ camera->camera, { camera->decoder->output_list }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->decoder, { camera->codec_h264->output_list } };
|
||||
*links++ = (link_t){ camera->codec_h264, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
} else if (camera->options.format != V4L2_PIX_FMT_H264) {
|
||||
*links++ = (link_t){ camera->camera, { camera->decoder }, { http_h264_capture, http_h264_needs_buffer }};
|
||||
*links++ = (link_t){ camera->decoder, { camera->codec_jpeg } };
|
||||
*links++ = (link_t){ camera->camera, { camera->decoder->output_list }, { http_h264_capture, http_h264_needs_buffer }};
|
||||
*links++ = (link_t){ camera->decoder, { camera->codec_jpeg->output_list } };
|
||||
*links++ = (link_t){ camera->codec_jpeg, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
} else {
|
||||
*links++ = (link_t){ camera->camera, { camera->decoder } };
|
||||
*links++ = (link_t){ camera->decoder, { camera->codec_jpeg, camera->codec_h264 } };
|
||||
*links++ = (link_t){ camera->camera, { camera->decoder->output_list } };
|
||||
*links++ = (link_t){ camera->decoder, { camera->codec_jpeg->output_list, camera->codec_h264->output_list } };
|
||||
*links++ = (link_t){ camera->codec_jpeg, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ int camera_configure_direct(camera_t *camera)
|
||||
|
||||
link_t *links = camera->links;
|
||||
|
||||
*links++ = (link_t){ camera->camera, { camera->codec_jpeg, camera->codec_h264 } };
|
||||
*links++ = (link_t){ camera->camera, { camera->codec_jpeg->output_list, camera->codec_h264->output_list } };
|
||||
*links++ = (link_t){ camera->codec_jpeg, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
return 0;
|
||||
|
@ -54,13 +54,13 @@ int camera_configure_isp(camera_t *camera, float high_div, float low_div)
|
||||
|
||||
link_t *links = camera->links;
|
||||
|
||||
*links++ = (link_t){ camera->camera, { camera->isp_srgb } };
|
||||
*links++ = (link_t){ camera->camera, { camera->isp_srgb->output_list } };
|
||||
|
||||
if (camera->isp_yuuv_low) {
|
||||
*links++ = (link_t){ camera->isp_yuuv, { } };
|
||||
*links++ = (link_t){ camera->isp_yuuv_low, { camera->codec_jpeg, camera->codec_h264 }, { write_yuvu } };
|
||||
*links++ = (link_t){ camera->isp_yuuv_low, { camera->codec_jpeg->output_list, camera->codec_h264->output_list }, { write_yuvu } };
|
||||
} else {
|
||||
*links++ = (link_t){ camera->isp_yuuv, { camera->codec_jpeg, camera->codec_h264 }, { write_yuvu } };
|
||||
*links++ = (link_t){ camera->isp_yuuv, { camera->codec_jpeg->output_list, camera->codec_h264->output_list }, { write_yuvu } };
|
||||
}
|
||||
|
||||
*links++ = (link_t){ camera->codec_jpeg, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
|
@ -47,8 +47,8 @@ int camera_configure_legacy_isp(camera_t *camera, float div)
|
||||
|
||||
link_t *links = camera->links;
|
||||
|
||||
*links++ = (link_t){ camera->camera, { camera->legacy_isp } };
|
||||
*links++ = (link_t){ camera->legacy_isp, { camera->codec_jpeg, camera->codec_h264 }, { write_yuvu, NULL } };
|
||||
*links++ = (link_t){ camera->camera, { camera->legacy_isp->output_list } };
|
||||
*links++ = (link_t){ camera->legacy_isp, { camera->codec_jpeg->output_list, camera->codec_h264->output_list }, { write_yuvu, NULL } };
|
||||
*links++ = (link_t){ camera->codec_jpeg, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
return 0;
|
||||
|
51
hw/links.c
51
hw/links.c
@ -14,7 +14,6 @@ void _update_paused(link_t *all_links)
|
||||
for (int i = n; i-- > 0; ) {
|
||||
link_t *link = &all_links[i];
|
||||
|
||||
|
||||
if (!link->capture->capture_list->streaming) {
|
||||
continue;
|
||||
}
|
||||
@ -25,18 +24,18 @@ void _update_paused(link_t *all_links)
|
||||
paused = false;
|
||||
}
|
||||
|
||||
for (int j = 0; link->outputs[j]; j++) {
|
||||
device_t *output = link->outputs[j];
|
||||
for (int j = 0; link->sinks[j]; j++) {
|
||||
buffer_list_t *sink = link->sinks[j];
|
||||
|
||||
if (!output->output_list->streaming) {
|
||||
if (!sink->streaming) {
|
||||
continue;
|
||||
}
|
||||
if (output->output_list->device->paused) {
|
||||
if (sink->device->paused) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int count_enqueued = buffer_list_count_enqueued(output->output_list);
|
||||
if (count_enqueued < output->output_list->nbufs) {
|
||||
int count_enqueued = buffer_list_count_enqueued(sink);
|
||||
if (count_enqueued < sink->nbufs) {
|
||||
paused = false;
|
||||
}
|
||||
}
|
||||
@ -66,26 +65,26 @@ int _build_fds(link_t *all_links, struct pollfd *fds, link_t **links, buffer_lis
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; link->outputs[j]; j++) {
|
||||
device_t *output = link->outputs[j];
|
||||
for (int j = 0; link->sinks[j]; j++) {
|
||||
buffer_list_t *sink = link->sinks[j];
|
||||
|
||||
if (!output || !output->output_list || n >= max_n) {
|
||||
if (n >= max_n) {
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!output->output_list->streaming) {
|
||||
if (!sink->streaming) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int count_enqueued = buffer_list_count_enqueued(output->output_list);
|
||||
int count_enqueued = buffer_list_count_enqueued(sink);
|
||||
|
||||
// Can something be dequeued?
|
||||
if (count_enqueued == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
struct pollfd fd = {output->fd, POLLOUT};
|
||||
struct pollfd fd = {sink->device->fd, POLLOUT};
|
||||
fds[n] = fd;
|
||||
buf_lists[n] = output->output_list;
|
||||
buf_lists[n] = sink;
|
||||
links[n] = link;
|
||||
n++;
|
||||
}
|
||||
@ -128,11 +127,11 @@ int links_step(link_t *all_links, int timeout)
|
||||
if (fds[i].revents & POLLIN) {
|
||||
E_LOG_DEBUG(buf_list, "POLLIN");
|
||||
if (buf = buffer_list_dequeue(buf_list)) {
|
||||
for (int j = 0; link->outputs[j]; j++) {
|
||||
if (link->outputs[j]->paused) {
|
||||
for (int j = 0; link->sinks[j]; j++) {
|
||||
if (link->sinks[j]->device->paused) {
|
||||
continue;
|
||||
}
|
||||
buffer_list_enqueue(link->outputs[j]->output_list, buf);
|
||||
buffer_list_enqueue(link->sinks[j], buf);
|
||||
}
|
||||
|
||||
if (link->callbacks.on_buffer) {
|
||||
@ -142,14 +141,18 @@ int links_step(link_t *all_links, int timeout)
|
||||
buffer_consumed(buf);
|
||||
}
|
||||
}
|
||||
|
||||
// Dequeue buffers that were processed
|
||||
if (fds[i].revents & POLLOUT) {
|
||||
E_LOG_DEBUG(buf_list, "POLLOUT");
|
||||
buffer_list_dequeue(buf_list);
|
||||
}
|
||||
|
||||
if (fds[i].revents & POLLERR) {
|
||||
E_LOG_DEBUG(buf_list, "POLLERR");
|
||||
device_consume_event(buf_list->device);
|
||||
E_LOG_INFO(buf_list, "Got an error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fds[i].revents & ~(POLLIN|POLLOUT|POLLERR)) {
|
||||
E_LOG_DEBUG(buf_list, "POLL%08x", fds[i].revents);
|
||||
}
|
||||
@ -171,9 +174,13 @@ int links_stream(link_t *all_links, bool do_stream)
|
||||
E_LOG_ERROR(link->capture, "Failed to start streaming");
|
||||
}
|
||||
|
||||
for (int j = 0; link->outputs[j]; j++) {
|
||||
if (buffer_list_stream(link->outputs[j]->output_list, streaming) < 0) {
|
||||
E_LOG_ERROR(link->outputs[j], "Failed to start streaming");
|
||||
if (device_set_stream(link->capture, streaming) < 0) {
|
||||
E_LOG_ERROR(link->capture, "Failed to start streaming");
|
||||
}
|
||||
|
||||
for (int j = 0; link->sinks[j]; j++) {
|
||||
if (buffer_list_stream(link->sinks[j], streaming) < 0) {
|
||||
E_LOG_ERROR(link->sinks[j], "Failed to start streaming");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,14 @@
|
||||
#include "v4l2.h"
|
||||
|
||||
typedef struct buffer_s buffer_t;
|
||||
typedef struct buffer_list_s buffer_list_t;
|
||||
|
||||
typedef void (*link_on_buffer)(buffer_t *buf);
|
||||
typedef bool (*link_check_streaming)();
|
||||
|
||||
typedef struct link_s {
|
||||
struct device_s *capture; // capture_list
|
||||
struct device_s *outputs[10];
|
||||
struct buffer_list_s *sinks[10];
|
||||
struct {
|
||||
link_on_buffer on_buffer;
|
||||
link_check_streaming check_streaming;
|
||||
|
Loading…
x
Reference in New Issue
Block a user