aboutsummaryrefslogtreecommitdiffstats
path: root/utils/v4l2-ctl/v4l2-ctl-meta.cpp
blob: 37c91940a8a07f9953c1d679dbcf8926dc830c6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <dirent.h>
#include <math.h>

#include "v4l2-ctl.h"

static struct v4l2_format vfmt;	/* set_format/get_format */

void meta_usage(void)
{
	printf("\nMetadata Formats options:\n"
	       "  --list-formats-meta display supported metadata formats [VIDIOC_ENUM_FMT]\n"
	       "  --get-fmt-meta      query the metadata format [VIDIOC_G_FMT]\n"
	       "  --set-fmt-meta <f>  set the metadata format [VIDIOC_S_FMT]\n"
	       "                     parameter is either the format index as reported by\n"
	       "                     --list-formats-meta, or the fourcc value as a string\n"
	       "  --try-fmt-meta <f>  try the metadata format [VIDIOC_TRY_FMT]\n"
	       "                     parameter is either the format index as reported by\n"
	       "                     --list-formats-meta, or the fourcc value as a string\n"
	       );
}

void meta_cmd(int ch, char *optarg)
{
	switch (ch) {
	case OptSetMetaFormat:
	case OptTryMetaFormat:
		if (strlen(optarg) == 0) {
			meta_usage();
			exit(1);
		} else if (strlen(optarg) == 4) {
			vfmt.fmt.meta.dataformat = v4l2_fourcc(optarg[0],
					optarg[1], optarg[2], optarg[3]);
		} else {
			vfmt.fmt.meta.dataformat = strtol(optarg, 0L, 0);
		}
		break;
	}
}

void meta_set(cv4l_fd &_fd)
{
	int fd = _fd.g_fd();
	int ret;

	if ((options[OptSetMetaFormat] || options[OptTryMetaFormat]) &&
	    v4l_type_is_meta(_fd.g_type())) {
		struct v4l2_format in_vfmt;

		in_vfmt.type = _fd.g_type();
		in_vfmt.fmt.meta.dataformat = vfmt.fmt.meta.dataformat;

		if (in_vfmt.fmt.meta.dataformat < 256) {
			struct v4l2_fmtdesc fmt;

			fmt.index = in_vfmt.fmt.meta.dataformat;
			fmt.type = in_vfmt.type;

			if (doioctl(fd, VIDIOC_ENUM_FMT, &fmt))
				fmt.pixelformat = 0;

			in_vfmt.fmt.meta.dataformat = fmt.pixelformat;
		}

		if (options[OptSetMetaFormat])
			ret = doioctl(fd, VIDIOC_S_FMT, &in_vfmt);
		else
			ret = doioctl(fd, VIDIOC_TRY_FMT, &in_vfmt);
		if (ret == 0 && (verbose || options[OptTryMetaFormat]))
			printfmt(fd, in_vfmt);
	}
}

void meta_get(cv4l_fd &fd)
{
	if (options[OptGetMetaFormat] && v4l_type_is_meta(fd.g_type())) {
		vfmt.type = fd.g_type();
		if (doioctl(fd.g_fd(), VIDIOC_G_FMT, &vfmt) == 0)
			printfmt(fd.g_fd(), vfmt);
	}
}

void meta_list(cv4l_fd &fd)
{
	if (options[OptListMetaFormats] && v4l_type_is_meta(fd.g_type())) {
		printf("ioctl: VIDIOC_ENUM_FMT\n");
		print_video_formats(fd, fd.g_type());
	}
}

Privacy Policy