diff options
-rw-r--r-- | main.c | 35 | ||||
-rw-r--r-- | media.c | 39 | ||||
-rw-r--r-- | subdev.c | 39 | ||||
-rw-r--r-- | subdev.h | 4 |
4 files changed, 85 insertions, 32 deletions
@@ -39,7 +39,6 @@ #include "media.h" #include "options.h" #include "subdev.h" -#include "tools.h" /* ----------------------------------------------------------------------------- * Links setup @@ -175,43 +174,17 @@ static int setup_links(struct media_device *media, const char *p) * Formats setup */ -static struct { - const char *name; - enum v4l2_mbus_pixelcode code; -} mbus_formats[] = { - { "YUYV", V4L2_MBUS_FMT_YUYV16_1X16 }, - { "UYVY", V4L2_MBUS_FMT_UYVY16_1X16 }, - { "SGRBG10", V4L2_MBUS_FMT_SGRBG10_1X10 }, - { "SGRBG10_DPCM8", V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 }, -}; - -static const char *pixelcode_to_string(enum v4l2_mbus_pixelcode code) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) { - if (mbus_formats[i].code == code) - return mbus_formats[i].name; - } - - return "unknown"; -} - static int parse_format(struct v4l2_mbus_framefmt *format, const char *p, char **endp) { + enum v4l2_mbus_pixelcode code; unsigned int width, height; - unsigned int i; char *end; for (; isspace(*p); ++p); for (end = (char *)p; !isspace(*end) && *end != '\0'; ++end); - for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) { - if (strncmp(mbus_formats[i].name, p, end - p) == 0) - break; - } - - if (i == ARRAY_SIZE(mbus_formats)) + code = string_to_pixelcode(p, end - p); + if (code == (enum v4l2_mbus_pixelcode)-1) return -EINVAL; for (p = end; isspace(*p); ++p); @@ -226,7 +199,7 @@ static int parse_format(struct v4l2_mbus_framefmt *format, const char *p, char * memset(format, 0, sizeof(*format)); format->width = width; format->height = height; - format->code = mbus_formats[i].code; + format->code = code; return 0; } @@ -32,6 +32,7 @@ #include <linux/media.h> #include "media.h" +#include "subdev.h" #include "tools.h" static const char *media_entity_type_to_string(unsigned type) @@ -85,6 +86,26 @@ static const char *media_entity_subtype_to_string(unsigned type, unsigned subtyp } } +static const char *media_pad_type_to_string(unsigned type) +{ + static const struct { + __u32 type; + const char *name; + } types[] = { + { MEDIA_PAD_TYPE_INPUT, "Input" }, + { MEDIA_PAD_TYPE_OUTPUT, "Output" }, + }; + + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(types); i++) { + if (types[i].type == type) + return types[i].name; + } + + return "Unknown"; +} + /* * media_entity_remote_pad - */ @@ -276,6 +297,7 @@ static void media_print_topology_text(struct media_device *media) { unsigned int i, j, k; unsigned int padding; + int ret; printf("Device topology\n"); @@ -293,6 +315,21 @@ static void media_print_topology_text(struct media_device *media) printf("%*cdevice node name %s\n", padding, ' ', entity->devname); for (j = 0; j < entity->info.pads; j++) { + struct media_entity_pad *pad = &entity->pads[j]; + struct v4l2_mbus_framefmt format; + + 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); + } + + printf("\n"); + for (k = 0; k < entity->info.links; k++) { struct media_entity_link *link = &entity->links[k]; @@ -300,7 +337,7 @@ static void media_print_topology_text(struct media_device *media) link->source->index != j) continue; - printf("\tpad%u -> '%s':pad%u [", link->source->index, + printf("\t\t-> '%s':pad%u [", link->sink->entity->info.name, link->sink->index); if (link->flags & MEDIA_LINK_FLAG_IMMUTABLE) @@ -31,6 +31,45 @@ #include "media.h" #include "subdev.h" +#include "tools.h" + +static struct { + const char *name; + enum v4l2_mbus_pixelcode code; +} mbus_formats[] = { + { "YUYV", V4L2_MBUS_FMT_YUYV16_1X16 }, + { "UYVY", V4L2_MBUS_FMT_UYVY16_1X16 }, + { "SGRBG10", V4L2_MBUS_FMT_SGRBG10_1X10 }, + { "SGRBG10_DPCM8", V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 }, +}; + +const char *pixelcode_to_string(enum v4l2_mbus_pixelcode code) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) { + if (mbus_formats[i].code == code) + return mbus_formats[i].name; + } + + return "unknown"; +} + +enum v4l2_mbus_pixelcode string_to_pixelcode(const char *string, + unsigned int length) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) { + if (strncmp(mbus_formats[i].name, string, length) == 0) + break; + } + + if (i == ARRAY_SIZE(mbus_formats)) + return (enum v4l2_mbus_pixelcode)-1; + + return mbus_formats[i].code; +} static int v4l2_subdev_open(struct media_entity *entity) { @@ -24,6 +24,10 @@ struct media_entity; +const char *pixelcode_to_string(enum v4l2_mbus_pixelcode code); +enum v4l2_mbus_pixelcode string_to_pixelcode(const char *string, + unsigned int length); + int v4l2_subdev_get_format(struct media_entity *entity, struct v4l2_mbus_framefmt *format, unsigned int pad, enum v4l2_subdev_format which); |