Fix memory issues
This commit is contained in:
@@ -54,10 +54,10 @@ load_entity_ids(libmegapixels_camera *camera)
|
||||
}
|
||||
|
||||
for (int i = 0; i < camera->num_modes; i++) {
|
||||
libmegapixels_mode *mode = &camera->modes[i];
|
||||
libmegapixels_mode *mode = camera->modes[i];
|
||||
|
||||
for (int j = 0; j < mode->num_cmds; j++) {
|
||||
libmegapixels_cmd *cmd = &mode->cmds[j];
|
||||
libmegapixels_cmd *cmd = mode->cmds[j];
|
||||
|
||||
if (cmd->type == LIBMEGAPIXELS_CMD_LINK) {
|
||||
int found_from = 0;
|
||||
@@ -80,6 +80,18 @@ load_entity_ids(libmegapixels_camera *camera)
|
||||
log_error("Could not find entity '%s'\n", cmd->entity_to);
|
||||
return -1;
|
||||
}
|
||||
} else if (cmd->type == LIBMEGAPIXELS_CMD_MODE) {
|
||||
int found = 0;
|
||||
for (int k = 0; k < topology.num_entities; k++) {
|
||||
if (strncmp(entities[k].name, cmd->entity_from, strlen(cmd->entity_from)) == 0) {
|
||||
cmd->entity_from_id = entities[k].id;
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found != 1) {
|
||||
log_error("Could not find entity '%s'\n", cmd->entity_from);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,7 +173,7 @@ unsigned int
|
||||
libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode)
|
||||
{
|
||||
for (int i = 0; i < mode->num_cmds; i++) {
|
||||
libmegapixels_cmd *cmd = &mode->cmds[i];
|
||||
libmegapixels_cmd *cmd = mode->cmds[i];
|
||||
struct v4l2_subdev_format subdev_fmt = {};
|
||||
fprintf(stderr, "Do %d\n", cmd->type);
|
||||
switch (cmd->type) {
|
||||
@@ -179,7 +191,29 @@ libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode
|
||||
subdev_fmt.format.height = cmd->height;
|
||||
subdev_fmt.format.code = mode->media_busfmt;
|
||||
subdev_fmt.format.field = V4L2_FIELD_ANY;
|
||||
if (xioctl(camera->sensor_fd, VIDIOC_SUBDEV_S_FMT, &subdev_fmt) == -1) {
|
||||
|
||||
libmegapixels_subdev *sd;
|
||||
int found = 0;
|
||||
for (int h = 0; h < camera->num_handles; h++) {
|
||||
if (camera->handles[h]->entity_id == cmd->entity_from_id) {
|
||||
sd = camera->handles[h];
|
||||
found++;
|
||||
}
|
||||
}
|
||||
if (found != 1) {
|
||||
log_error("Could not find handle for entity\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (sd->fd == 0) {
|
||||
sd->fd = open(sd->path, O_RDWR);
|
||||
if (sd->fd < 0) {
|
||||
log_error("Could not open %s\n", sd->path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (xioctl(sd->fd, VIDIOC_SUBDEV_S_FMT, &subdev_fmt) == -1) {
|
||||
log_error("Could not set mode on sensor: %s\n", strerror(errno));
|
||||
}
|
||||
break;
|
||||
|
Reference in New Issue
Block a user