Store received frames from getframe

This commit is contained in:
Martijn Braam
2023-07-09 13:15:41 +02:00
parent ee140b350e
commit af514b28c3
3 changed files with 31 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ Rear: {
# All the links on this platform are immutable
Pipeline: (
{Type: "Mode", Entity: "s5k3l6xx"},
{Type: "Mode", Entity: "imx8mq-mipi-csi2"},
{Type: "Mode", Entity: "csi"},
);
@@ -38,6 +39,7 @@ Front: {
Mirror: true;
Pipeline: (
{Type: "Mode", Entity: "hi846"},
{Type: "Mode", Entity: "imx8mq-mipi-csi2"},
{Type: "Mode", Entity: "csi"},
);

View File

@@ -11,17 +11,17 @@
#include "util.h"
int
setup_link(libmegapixels_camera *camera, uint32_t source_entity_id, uint32_t sink_entity_id, int enabled)
setup_link(libmegapixels_camera *camera, uint32_t source_entity_id, uint32_t sink_entity_id,
uint16_t source_index, uint16_t sink_index, int enabled)
{
struct media_link_desc link = {};
link.flags = (enabled > 0) ? MEDIA_LNK_FL_ENABLED : 0;
link.source.entity = source_entity_id;
link.source.index = 0;
link.source.index = source_index;
link.sink.entity = sink_entity_id;
link.sink.index = 0;
link.sink.index = sink_index;
if (xioctl(camera->media_fd, MEDIA_IOC_SETUP_LINK, &link) == -1) {
log_error("Could not setup link: %s\n", strerror(errno));
return -1;
}
return 0;
@@ -107,7 +107,7 @@ load_entity_ids(libmegapixels_camera *camera)
}
}
setup_link(camera, source_entity, sink_entity, 0);
setup_link(camera, source_entity, sink_entity, 0, 0, 0);
}
}
return 0;
@@ -187,7 +187,7 @@ libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode
struct v4l2_subdev_format subdev_fmt = {};
switch (cmd->type) {
case LIBMEGAPIXELS_CMD_LINK:
if (setup_link(camera, cmd->entity_from_id, cmd->entity_to_id, 1) != 0) {
if (setup_link(camera, cmd->entity_from_id, cmd->entity_to_id, cmd->pad_from, cmd->pad_to, 1) != 0) {
log_error("Could not link %d -> %d [%s -> %s] \n", cmd->entity_from_id, cmd->entity_to_id,
cmd->entity_from,
cmd->entity_to);

View File

@@ -34,8 +34,9 @@ main(int argc, char *argv[])
int camera_id = 0;
long res;
char *end;
char *outfile = NULL;
while ((c = getopt(argc, argv, "c:")) != -1) {
while ((c = getopt(argc, argv, "c:o:")) != -1) {
switch (c) {
case 'c':
res = strtol(optarg, &end, 10);
@@ -45,6 +46,9 @@ main(int argc, char *argv[])
}
camera_id = (int) res;
break;
case 'o':
outfile = optarg;
break;
case '?':
if (optopt == 'd' || optopt == 'l') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
@@ -175,7 +179,24 @@ main(int argc, char *argv[])
fprintf(stderr, "VIDIOC_DQBUF failed\n");
return 1;
}
fprintf(stderr, "GOT FRAME!\n");
fprintf(stderr, "received frame\n");
if (count == 1 && outfile != NULL) {
FILE *fp = fopen(outfile, "w");
fwrite(buffers[buf.index].start, buf.bytesused, 1, fp);
fclose(fp);
printf("Stored frame to: %s\n", outfile);
printf("Format: %dx%x\n", mode->width, mode->height);
char fourcc[5] = {0};
fourcc[0] = (char) (mode->v4l_pixfmt & 0xff);
fourcc[1] = (char) ((mode->v4l_pixfmt >> 8) & 0xff);
fourcc[2] = (char) ((mode->v4l_pixfmt >> 16) & 0xff);
fourcc[3] = (char) ((mode->v4l_pixfmt >> 24) & 0xff);
printf("Pixfmt: %s\n", fourcc);
}
if (xioctl(camera->video_fd, VIDIOC_QBUF, &buf) == -1) {
fprintf(stderr, "VIDIOC_DQBUF failed\n");
return 1;