From a753dba7ed68896912f291f7ca01edb85a66db75 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 11 Aug 2010 09:28:09 +0200 Subject: Add a --get-format option The option takes a pad name as argument and returns the active format (and optional crop settings if available) for that pad. Signed-off-by: Laurent Pinchart --- main.c | 30 +++++++++++++++++++++++++----- media.c | 26 +++++--------------------- options.c | 13 ++++++++++--- options.h | 1 + subdev.c | 22 ++++++++++++++++++++++ subdev.h | 3 +++ 6 files changed, 66 insertions(+), 29 deletions(-) diff --git a/main.c b/main.c index 15ccfb2..e143b8c 100644 --- a/main.c +++ b/main.c @@ -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; } diff --git a/media.c b/media.c index 05fc76c..aaa1005 100644 --- a/media.c +++ b/media.c @@ -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"); diff --git a/options.c b/options.c index 6fd2daf..f4a551b 100644 --- a/options.c +++ b/options.c @@ -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]); diff --git a/options.h b/options.h index 81c9736..2467fbe 100644 --- a/options.h +++ b/options.h @@ -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; diff --git a/subdev.c b/subdev.c index 40b2506..8e434ca 100644 --- a/subdev.c +++ b/subdev.c @@ -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("]"); +} + diff --git a/subdev.h b/subdev.h index 7b65411..467bbcc 100644 --- a/subdev.h +++ b/subdev.h @@ -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 -- cgit v1.2.3