diff options
-rw-r--r-- | main.c | 30 | ||||
-rw-r--r-- | media.c | 26 | ||||
-rw-r--r-- | options.c | 13 | ||||
-rw-r--r-- | options.h | 1 | ||||
-rw-r--r-- | subdev.c | 22 | ||||
-rw-r--r-- | subdev.h | 3 |
6 files changed, 66 insertions, 29 deletions
@@ -81,7 +81,8 @@ static struct media_entity_pad *parse_pad(struct media_device *media, const char return NULL; for (p = end; isspace(*p); ++p); - *endp = (char *)p; + if (endp) + *endp = (char *)p; return &entity->pads[pad]; } @@ -443,6 +444,7 @@ static int setup_formats(struct media_device *media, const char *p) int main(int argc, char **argv) { struct media_device *media; + int ret = -1; if (parse_cmdline(argc, argv)) return EXIT_FAILURE; @@ -457,10 +459,26 @@ int main(int argc, char **argv) entity = media_get_entity_by_name(media, media_opts.entity, strlen(media_opts.entity)); - if (entity != NULL) - printf("%s\n", entity->devname); - else + if (entity == NULL) { printf("Entity '%s' not found\n", media_opts.entity); + goto out; + } + + printf("%s\n", entity->devname); + } + + if (media_opts.pad) { + struct media_entity_pad *pad; + + pad = parse_pad(media, media_opts.pad, NULL); + if (pad == NULL) { + printf("Pad '%s' not found\n", media_opts.pad); + goto out; + } + + v4l2_subdev_print_format(pad->entity, pad->index, + V4L2_SUBDEV_FORMAT_ACTIVE); + printf("\n"); } if (media_opts.print || media_opts.print_dot) { @@ -495,10 +513,12 @@ int main(int argc, char **argv) } } + ret = 0; + out: if (media) media_close(media); - exit(EXIT_SUCCESS); + return ret ? EXIT_FAILURE : EXIT_SUCCESS; } @@ -315,7 +315,6 @@ static void media_print_topology_text(struct media_device *media) { unsigned int i, j, k; unsigned int padding; - int ret; printf("Device topology\n"); @@ -334,26 +333,11 @@ static void media_print_topology_text(struct media_device *media) for (j = 0; j < entity->info.pads; j++) { struct media_entity_pad *pad = &entity->pads[j]; - struct v4l2_mbus_framefmt format; - struct v4l2_rect rect; - - printf("\tpad%u: %s", j, media_pad_type_to_string(pad->type)); - - if (entity->info.type == MEDIA_ENTITY_TYPE_SUBDEV) { - ret = v4l2_subdev_get_format(entity, &format, j, - V4L2_SUBDEV_FORMAT_ACTIVE); - if (ret == 0) { - printf(" [%s %ux%u", pixelcode_to_string(format.code), - format.width, format.height); - - ret = v4l2_subdev_get_crop(entity, &rect, j, - V4L2_SUBDEV_FORMAT_ACTIVE); - if (ret == 0) - printf(" (%u,%u)/%ux%u", rect.left, rect.top, - rect.width, rect.height); - printf("]"); - } - } + + printf("\tpad%u: %s ", j, media_pad_type_to_string(pad->type)); + + if (entity->info.type == MEDIA_ENTITY_TYPE_SUBDEV) + v4l2_subdev_print_format(entity, j, V4L2_SUBDEV_FORMAT_ACTIVE); printf("\n"); @@ -35,7 +35,8 @@ static void usage(const char *argv0, int verbose) printf("%s [options] device\n", argv0); printf("-d, --device dev Media device name (default: %s)\n", MEDIA_DEVNAME_DEFAULT); printf("-e, --entity name Print the device name associated with the given entity\n"); - printf("-f, --formats Comma-separated list of formats to setup\n"); + printf("-f, --set-format Comma-separated list of formats to setup\n"); + printf(" --get-format pad Print the active format on a given pad\n"); printf("-h, --help Show verbose help and exit\n"); printf("-i, --interactive Modify links interactively\n"); printf("-l, --links Comma-separated list of links descriptors to setup\n"); @@ -68,12 +69,14 @@ static void usage(const char *argv0, int verbose) printf("\tdenominator Frame interval denominator\n"); } -#define OPT_PRINT_DOT 256 +#define OPT_PRINT_DOT 256 +#define OPT_GET_FORMAT 257 static struct option opts[] = { {"device", 1, 0, 'd'}, {"entity", 1, 0, 'e'}, - {"formats", 1, 0, 'f'}, + {"set-format", 1, 0, 'f'}, + {"get-format", 1, 0, OPT_GET_FORMAT}, {"help", 0, 0, 'h'}, {"interactive", 0, 0, 'i'}, {"links", 1, 0, 'l'}, @@ -136,6 +139,10 @@ int parse_cmdline(int argc, char **argv) media_opts.print_dot = 1; break; + case OPT_GET_FORMAT: + media_opts.pad = optarg; + break; + default: printf("Invalid option -%c\n", opt); printf("Run %s -h for help.\n", argv[0]); @@ -31,6 +31,7 @@ struct media_options const char *entity; const char *formats; const char *links; + const char *pad; }; extern struct media_options media_opts; @@ -198,3 +198,25 @@ int v4l2_subdev_set_frame_interval(struct media_entity *entity, *interval = ival.interval; return 0; } + +void v4l2_subdev_print_format(struct media_entity *entity, + unsigned int pad, enum v4l2_subdev_format which) +{ + struct v4l2_mbus_framefmt format; + struct v4l2_rect rect; + int ret; + + ret = v4l2_subdev_get_format(entity, &format, pad, which); + if (ret != 0) + return; + + printf("[%s %ux%u", pixelcode_to_string(format.code), + format.width, format.height); + + ret = v4l2_subdev_get_crop(entity, &rect, pad, which); + if (ret == 0) + printf(" (%u,%u)/%ux%u", rect.left, rect.top, + rect.width, rect.height); + printf("]"); +} + @@ -41,5 +41,8 @@ int v4l2_subdev_set_crop(struct media_entity *entity, struct v4l2_rect *rect, int v4l2_subdev_set_frame_interval(struct media_entity *entity, struct v4l2_fract *interval); +void v4l2_subdev_print_format(struct media_entity *entity, + unsigned int pad, enum v4l2_subdev_format which); + #endif |