summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;