links: use n_output_lists for link_t

This commit is contained in:
Kamil Trzcinski 2023-02-24 19:59:51 +01:00
parent 17fc87a2d8
commit f7f4eba9ca
5 changed files with 18 additions and 12 deletions

View File

@ -85,7 +85,7 @@ static nlohmann::json links_status_json()
nlohmann::json link_json;
link_json["source"] = link->capture_list->name;
for (int j = 0; link->output_lists[j]; j++) {
for (int j = 0; j < link->n_output_lists; j++) {
link_json["sinks"][j] = link->output_lists[j]->name;
}
for (int j = 0; j < link->n_callbacks; j++) {

View File

@ -82,16 +82,14 @@ link_t *camera_ensure_capture(camera_t *camera, buffer_list_t *capture)
void camera_capture_add_output(camera_t *camera, buffer_list_t *capture, buffer_list_t *output)
{
link_t *link = camera_ensure_capture(camera, capture);
int nsinks;
for (nsinks = 0; link->output_lists[nsinks]; nsinks++);
link->output_lists[nsinks] = output;
ARRAY_APPEND(link->output_lists, link->n_output_lists, output);
}
void camera_capture_add_callbacks(camera_t *camera, buffer_list_t *capture, link_callbacks_t callbacks)
{
link_t *link = camera_ensure_capture(camera, capture);
link->callbacks[link->n_callbacks++] = callbacks;
if (!ARRAY_APPEND(link->callbacks, link->n_callbacks, callbacks))
return;
if (callbacks.buf_lock) {
callbacks.buf_lock->buf_list = capture;

View File

@ -63,7 +63,7 @@ static int links_build_fds(link_t *all_links, link_pool_t *link_pool)
paused = false;
}
for (int j = 0; link->output_lists[j]; j++) {
for (int j = 0; j < link->n_output_lists; j++) {
buffer_list_t *sink = link->output_lists[j];
if (n >= N_FDS) {
@ -150,7 +150,7 @@ static int links_enqueue_from_capture_list(buffer_list_t *capture_list, link_t *
bool dropped = false;
for (int j = 0; link->output_lists[j]; j++) {
for (int j = 0; j < link->n_output_lists; j++) {
if (link->output_lists[j]->dev->paused) {
continue;
}
@ -314,7 +314,7 @@ static int links_stream(link_t *all_links, bool do_stream)
LOG_ERROR(link->capture_list, "Failed to start streaming");
}
for (int j = 0; link->output_lists[j]; j++) {
for (int j = 0; j < link->n_output_lists; j++) {
if (buffer_list_set_stream(link->output_lists[j], streaming) < 0) {
LOG_ERROR(link->output_lists[j], "Failed to start streaming");
}
@ -412,7 +412,7 @@ void links_dump(link_t *all_links)
line[0] = 0;
links_dump_buf_list(line, link->capture_list);
strcat(line, " => [");
for (int j = 0; link->output_lists[j]; j++) {
for (int j = 0; j < link->n_output_lists; j++) {
if (j > 0)
strcat(line, ", ");
links_dump_buf_list(line, link->output_lists[j]);

View File

@ -4,6 +4,8 @@
#include <stdbool.h>
#define LINKS_LOOP_INTERVAL 100
#define MAX_OUTPUT_LISTS 10
#define MAX_CALLBACKS 10
typedef struct buffer_s buffer_t;
typedef struct buffer_list_s buffer_list_t;
@ -22,8 +24,9 @@ typedef struct link_callbacks_s {
typedef struct link_s {
buffer_list_t *capture_list;
buffer_list_t *output_lists[10];
link_callbacks_t callbacks[10];
buffer_list_t *output_lists[MAX_OUTPUT_LISTS];
int n_output_lists;
link_callbacks_t callbacks[MAX_CALLBACKS];
int n_callbacks;
} link_t;

View File

@ -60,3 +60,8 @@ int ioctl_retried(const char *name, int fd, int request, void *arg);
LOG_ERROR(dev, "ioctl(ret=%d, errno=%d): " _msg, ret, errno, ##__VA_ARGS__); \
} \
} while(0)
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define ARRAY_APPEND(arr, n_arr, item) ((n_arr) < ARRAY_SIZE(arr) ? ((arr[n_arr++] = item), true) : false)
#define ARRAY_FOREACH(type, key, arr, n_arr) \
for (type *key = &arr[0]; key < &arr[n_arr]; key++)