summaryrefslogtreecommitdiff
path: root/yavta.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2013-06-26 09:51:23 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2014-04-01 23:52:24 +0200
commit740b98251388a51e51880efcae554df787e46c0b (patch)
treea5bc435a49f163c1d20106bfb5e814588eb3d548 /yavta.c
parentf92311606bbd8b4f16cb98789691b4386597c620 (diff)
Use format information structure directly
Replace the v4l2_format_code() function by functions to retrieve format information by fourcc or name, and access the format information structure directly. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'yavta.c')
-rw-r--r--yavta.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/yavta.c b/yavta.c
index 3a27978..1a3d4fd 100644
--- a/yavta.c
+++ b/yavta.c
@@ -102,7 +102,7 @@ static const char *v4l2_buf_type_name(enum v4l2_buf_type type)
return "Unknown";
}
-static struct {
+static struct v4l2_format_info {
const char *name;
unsigned int fourcc;
unsigned char n_planes;
@@ -151,35 +151,47 @@ static struct {
{ "MPEG", V4L2_PIX_FMT_MPEG, 1 },
};
-static const char *v4l2_format_name(unsigned int fourcc)
+static const struct v4l2_format_info *v4l2_format_by_fourcc(unsigned int fourcc)
{
- static char name[5];
unsigned int i;
for (i = 0; i < ARRAY_SIZE(pixel_formats); ++i) {
if (pixel_formats[i].fourcc == fourcc)
- return pixel_formats[i].name;
- }
-
- for (i = 0; i < 4; ++i) {
- name[i] = fourcc & 0xff;
- fourcc >>= 8;
+ return &pixel_formats[i];
}
- name[4] = '\0';
- return name;
+ return NULL;
}
-static unsigned int v4l2_format_code(const char *name)
+static const struct v4l2_format_info *v4l2_format_by_name(const char *name)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(pixel_formats); ++i) {
if (strcasecmp(pixel_formats[i].name, name) == 0)
- return pixel_formats[i].fourcc;
+ return &pixel_formats[i];
}
- return 0;
+ return NULL;
+}
+
+static const char *v4l2_format_name(unsigned int fourcc)
+{
+ const struct v4l2_format_info *info;
+ static char name[5];
+ unsigned int i;
+
+ info = v4l2_format_by_fourcc(fourcc);
+ if (info)
+ return info->name;
+
+ for (i = 0; i < 4; ++i) {
+ name[i] = fourcc & 0xff;
+ fourcc >>= 8;
+ }
+
+ name[4] = '\0';
+ return name;
}
static int video_open(struct device *dev, const char *devname, int no_query)
@@ -1347,6 +1359,7 @@ int main(int argc, char *argv[])
int ret;
/* Options parsings */
+ const struct v4l2_format_info *info;
int do_file = 0, do_capture = 0, do_pause = 0;
int do_set_time_per_frame = 0;
int do_enum_formats = 0, do_set_format = 0;
@@ -1399,11 +1412,12 @@ int main(int argc, char *argv[])
break;
case 'f':
do_set_format = 1;
- pixelformat = v4l2_format_code(optarg);
- if (pixelformat == 0) {
+ info = v4l2_format_by_name(optarg);
+ if (info == NULL) {
printf("Unsupported video format '%s'\n", optarg);
return 1;
}
+ pixelformat = info->fourcc;
break;
case 'F':
do_file = 1;