Ejemplo n.º 1
0
static void parse_freq_seek(char *optarg, struct v4l2_hw_freq_seek &seek)
{
	char *value;
	char *subs = optarg;

	while (*subs != '\0') {
		static const char *const subopts[] = {
			"dir",
			"wrap",
			"spacing",
			NULL
		};

		switch (parse_subopt(&subs, subopts, &value)) {
		case 0:
			seek.seek_upward = strtol(value, 0L, 0);
			break;
		case 1:
			seek.wrap_around = strtol(value, 0L, 0);
			break;
		case 2:
			seek.spacing = strtol(value, 0L, 0);
			break;
		default:
			usage_tuner();
			exit(1);
		}
	}
}
Ejemplo n.º 2
0
void vbi_cmd(int ch, char *optarg)
{
	char *value, *subs;
	bool found_off = false;
	v4l2_format *fmt = &vbi_fmt;

	switch (ch) {
	case OptSetSlicedVbiOutFormat:
	case OptTrySlicedVbiOutFormat:
		fmt = &vbi_fmt_out;
		/* fall through */
	case OptSetSlicedVbiFormat:
	case OptTrySlicedVbiFormat:
		fmt->fmt.sliced.service_set = 0;
		subs = optarg;
		while (*subs != '\0') {
			static const char *const subopts[] = {
				"off",
				"teletext",
				"cc",
				"wss",
				"vps",
				NULL
			};

			switch (parse_subopt(&subs, subopts, &value)) {
			case 0:
				found_off = true;
				break;
			case 1:
				fmt->fmt.sliced.service_set |=
					V4L2_SLICED_TELETEXT_B;
				break;
			case 2:
				fmt->fmt.sliced.service_set |=
					V4L2_SLICED_CAPTION_525;
				break;
			case 3:
				fmt->fmt.sliced.service_set |=
					V4L2_SLICED_WSS_625;
				break;
			case 4:
				fmt->fmt.sliced.service_set |=
					V4L2_SLICED_VPS;
				break;
			default:
				vbi_usage();
				break;
			}
		}
		if (found_off && fmt->fmt.sliced.service_set) {
			fprintf(stderr, "Sliced VBI mode 'off' cannot be combined with other modes\n");
			vbi_usage();
			exit(1);
		}
		break;
	}
}
Ejemplo n.º 3
0
void vidcap_cmd(int ch, char *optarg)
{
	__u32 colorspace, xfer_func, ycbcr, quantization;
	char *value, *subs;

	switch (ch) {
	case OptSetVideoFormat:
	case OptTryVideoFormat:
		set_fmts = parse_fmt(optarg, width, height, pixfmt, field, colorspace,
				xfer_func, ycbcr, quantization, flags, bytesperline);
		if (!set_fmts ||
		    (set_fmts & (FmtColorspace | FmtYCbCr | FmtQuantization | FmtXferFunc))) {
			vidcap_usage();
			exit(1);
		}
		break;
	case OptListFrameSizes:
		if (strlen(optarg) == 4)
			frmsize.pixel_format = v4l2_fourcc(optarg[0], optarg[1],
					optarg[2], optarg[3]);
		else
			frmsize.pixel_format = strtol(optarg, 0L, 0);
		break;
	case OptListFrameIntervals:
		subs = optarg;
		while (*subs != '\0') {
			static const char *const subopts[] = {
				"width",
				"height",
				"pixelformat",
				NULL
			};

			switch (parse_subopt(&subs, subopts, &value)) {
			case 0:
				frmival.width = strtol(value, 0L, 0);
				break;
			case 1:
				frmival.height = strtol(value, 0L, 0);
				break;
			case 2:
				if (strlen(value) == 4)
					frmival.pixel_format =
						v4l2_fourcc(value[0], value[1],
								value[2], value[3]);
				else
					frmival.pixel_format = strtol(value, 0L, 0);
				break;
			default:
				vidcap_usage();
				exit(1);
			}
		}
		break;
	}
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
	char *value, *subs;
	int i, forcedstride = 0;

	int fd = -1;

	/* command args */
	int ch;
	const char *device = "/dev/video0";	/* -d device */
	struct v4l2_capability vcap;	/* list_cap */
	struct v4l2_dbg_register set_reg;
	struct v4l2_dbg_register get_reg;
	struct v4l2_dbg_chip_info chip_info;
	const struct board_list *curr_bd = NULL;
	char short_options[26 * 2 * 3 + 1];
	int idx = 0;
	std::string reg_min_arg, reg_max_arg;
	std::string reg_set_arg;
	unsigned long long reg_min = 0, reg_max = 0;
	std::vector<std::string> get_regs;
	struct v4l2_dbg_match match;
	char *p;

	match.type = V4L2_CHIP_MATCH_BRIDGE;
	match.addr = 0;
	memset(&set_reg, 0, sizeof(set_reg));
	memset(&get_reg, 0, sizeof(get_reg));

	if (argc == 1) {
		usage();
		return 0;
	}
	for (i = 0; long_options[i].name; i++) {
		if (!isalpha(long_options[i].val))
			continue;
		short_options[idx++] = long_options[i].val;
		if (long_options[i].has_arg == required_argument) {
			short_options[idx++] = ':';
		} else if (long_options[i].has_arg == optional_argument) {
			short_options[idx++] = ':';
			short_options[idx++] = ':';
		}
	}
	while (1) {
		int option_index = 0;

		short_options[idx] = 0;
		ch = getopt_long(argc, argv, short_options,
				 long_options, &option_index);
		if (ch == -1)
			break;

		options[(int)ch] = 1;
		switch (ch) {
		case OptHelp:
			usage();
			return 0;

		case OptSetDevice:
			device = optarg;
			if (device[0] >= '0' && device[0] <= '9' && strlen(device) <= 3) {
				static char newdev[20];

				sprintf(newdev, "/dev/video%s", device);
				device = newdev;
			}
			break;

		case OptChip:
			if (!memcmp(optarg, "subdev", 6) && isdigit(optarg[6])) {
				match.type = V4L2_CHIP_MATCH_SUBDEV;
				match.addr = strtoul(optarg + 6, NULL, 0);
				break;
			}
			if (!memcmp(optarg, "bridge", 6)) {
				match.type = V4L2_CHIP_MATCH_BRIDGE;
				match.addr = strtoul(optarg + 6, NULL, 0);
				break;
			}
			match.type = V4L2_CHIP_MATCH_BRIDGE;
			match.addr = 0;
			break;

		case OptSetRegister:
			reg_set_arg = optarg;
			break;

		case OptGetRegister:
			get_regs.push_back(optarg);
			break;

		case OptSetStride:
			forcedstride = strtoull(optarg, 0L, 0);
			break;

		case OptListRegisters:
			subs = optarg;
			if (subs == NULL)
				break;

			while (*subs != '\0') {
				static const char * const subopts[] = {
					"min",
					"max",
					NULL
				};

				switch (parse_subopt(&subs, subopts, &value)) {
				case 0:
					reg_min_arg = value;
					//if (reg_max == 0)
					//	reg_max = reg_min + 0xff;
					break;
				case 1:
					reg_max_arg = value;
					break;
				}
			}
			break;

		case OptListSymbols:
			break;

		case ':':
			fprintf(stderr, "Option `%s' requires a value\n",
				argv[optind]);
			usage();
			return 1;

		case '?':
			fprintf(stderr, "Unknown argument `%s'\n",
				argv[optind]);
			usage();
			return 1;
		}
	}

	if ((fd = open(device, O_RDWR)) < 0) {
		fprintf(stderr, "Failed to open %s: %s\n", device,
			strerror(errno));
		exit(1);
	}

	doioctl(fd, VIDIOC_QUERYCAP, &vcap, "VIDIOC_QUERYCAP");
	capabilities = vcap.capabilities;

	/* Information Opts */

	if (options[OptGetDriverInfo]) {
		printf("Driver info:\n");
		printf("\tDriver name   : %s\n", vcap.driver);
		printf("\tCard type     : %s\n", vcap.card);
		printf("\tBus info      : %s\n", vcap.bus_info);
		printf("\tDriver version: %d.%d.%d\n",
				vcap.version >> 16,
				(vcap.version >> 8) & 0xff,
				vcap.version & 0xff);
		printf("\tCapabilities  : 0x%08X\n", vcap.capabilities);
		printf("%s", cap2s(vcap.capabilities).c_str());
	}

	chip_info.name[0] = '\0';
	if (options[OptChip]) {
		/* try to figure out which chip it is */
		chip_info.match = match;
		if (doioctl(fd, VIDIOC_DBG_G_CHIP_INFO, &chip_info, "VIDIOC_DBG_G_CHIP_INFO") != 0)
			chip_info.name[0] = '\0';

		if (!strncasecmp(match.name, "ac97", 4)) {
			curr_bd = &boards[AC97_BOARD];
		} else {
			for (int board = ARRAY_SIZE(boards) - 1; board >= 0; board--) {
				if (!strcasecmp(chip_info.name, boards[board].name)) {
					curr_bd = &boards[board];
					break;
				}
			}
		}
	}

	/* Set options */

	if (options[OptSetRegister]) {
		set_reg.match = match;
		if (optind >= argc)
			usage();
		set_reg.reg = parse_reg(curr_bd, reg_set_arg);
		while (optind < argc) {
			unsigned size = 0;

			if (doioctl(fd, VIDIOC_DBG_G_REGISTER, &set_reg,
				    "VIDIOC_DBG_G_REGISTER") >= 0)
				size = set_reg.size;

			set_reg.val = strtoull(argv[optind++], NULL, 0);
			if (doioctl(fd, VIDIOC_DBG_S_REGISTER, &set_reg,
						"VIDIOC_DBG_S_REGISTER") >= 0) {
				const char *name = reg_name(curr_bd, set_reg.reg);

				printf("Register ");

				if (name)
					printf("%s (0x%08llx)", name, set_reg.reg);
				else
					printf("0x%08llx", set_reg.reg);

				printf(" set to 0x%llx\n", set_reg.val);
			} else {
				printf("Failed to set register 0x%08llx value 0x%llx: %s\n",
					set_reg.reg, set_reg.val, strerror(errno));
			}
			set_reg.reg += size ? : (forcedstride ? : 1);
		}
	}

	if (options[OptScanChips]) {
		chip_info.match.type = V4L2_CHIP_MATCH_BRIDGE;
		chip_info.match.addr = 0;

		while (doioctl(fd, VIDIOC_DBG_G_CHIP_INFO, &chip_info, "VIDIOC_DBG_G_CHIP_INFO") == 0 && chip_info.name[0]) {
			printf("bridge%d: ", chip_info.match.addr);
			print_name(&chip_info);
			chip_info.match.addr++;
		}

		chip_info.match.type = V4L2_CHIP_MATCH_SUBDEV;
		chip_info.match.addr = 0;
		while (doioctl(fd, VIDIOC_DBG_G_CHIP_INFO, &chip_info, "VIDIOC_DBG_G_CHIP_INFO") == 0 && chip_info.name[0]) {
			printf("subdev%d: ", chip_info.match.addr++);
			print_name(&chip_info);
		}
	}

	if (options[OptGetRegister]) {
		get_reg.match = match;
		printf("ioctl: VIDIOC_DBG_G_REGISTER\n");

		for (std::vector<std::string>::iterator iter = get_regs.begin();
				iter != get_regs.end(); ++iter) {
			get_reg.reg = parse_reg(curr_bd, *iter);
			if (ioctl(fd, VIDIOC_DBG_G_REGISTER, &get_reg) < 0)
				fprintf(stderr, "ioctl: VIDIOC_DBG_G_REGISTER "
						"failed for 0x%llx\n", get_reg.reg);
			else {
				const char *name = reg_name(curr_bd, get_reg.reg);

				printf("Register ");

				if (name)
					printf("%s (0x%08llx)", name, get_reg.reg);
				else
					printf("0x%08llx", get_reg.reg);

				printf(" = %llxh (%lldd  %sb)\n",
					get_reg.val, get_reg.val, binary(get_reg.val));
			}
		}
	}

	if (options[OptListRegisters]) {
		std::string name;
		int stride = 1;

		get_reg.match = match;
		if (forcedstride) {
			stride = forcedstride;
		} else if (get_reg.match.type == V4L2_CHIP_MATCH_BRIDGE) {
			stride = 4;
		}
		printf("ioctl: VIDIOC_DBG_G_REGISTER\n");

		if (curr_bd) {
			if (reg_min_arg.empty())
				reg_min = 0;
			else
				reg_min = parse_reg(curr_bd, reg_min_arg);


			if (reg_max_arg.empty())
				reg_max = (1ll << 32) - 1;
			else
				reg_max = parse_reg(curr_bd, reg_max_arg);

			for (int i = 0; i < curr_bd->regs_size; i++) {
				if (reg_min_arg.empty() || ((curr_bd->regs[i].reg >= reg_min) && curr_bd->regs[i].reg <= reg_max)) {
					get_reg.reg = curr_bd->regs[i].reg;

					if (ioctl(fd, VIDIOC_DBG_G_REGISTER, &get_reg) < 0)
						fprintf(stderr, "ioctl: VIDIOC_DBG_G_REGISTER "
								"failed for 0x%llx\n", get_reg.reg);
					else {
						const char *name = reg_name(curr_bd, get_reg.reg);

						printf("Register ");

						if (name)
							printf("%s (0x%08llx)", name, get_reg.reg);
						else
							printf("0x%08llx", get_reg.reg);

						printf(" = %llxh (%lldd  %sb)\n",
							get_reg.val, get_reg.val, binary(get_reg.val));
					}
				}
			}
			goto list_done;
		}

		if (!reg_min_arg.empty()) {
			reg_min = parse_reg(curr_bd, reg_min_arg);
			if (reg_max_arg.empty())
				reg_max = reg_min + 0xff;
			else
				reg_max = parse_reg(curr_bd, reg_max_arg);
			/* Explicit memory range: just do it */
			print_regs(fd, &get_reg, reg_min, reg_max, stride);
			goto list_done;
		}

		p = strchr(chip_info.name, ' ');
		if (p)
			*p = '\0';
		name = chip_info.name;

		if (name == "saa7115") {
			print_regs(fd, &get_reg, 0, 0xff, stride);
		} else if (name == "saa717x") {
			// FIXME: use correct reg regions
			print_regs(fd, &get_reg, 0, 0xff, stride);
		} else if (name == "saa7127") {
			print_regs(fd, &get_reg, 0, 0x7f, stride);
		} else if (name == "ov7670") {
			print_regs(fd, &get_reg, 0, 0x89, stride);
		} else if (name == "cx25840") {
			print_regs(fd, &get_reg, 0, 2, stride);
			print_regs(fd, &get_reg, 0x100, 0x15f, stride);
			print_regs(fd, &get_reg, 0x200, 0x23f, stride);
			print_regs(fd, &get_reg, 0x400, 0x4bf, stride);
			print_regs(fd, &get_reg, 0x800, 0x9af, stride);
		} else if (name == "cs5345") {
			print_regs(fd, &get_reg, 1, 0x10, stride);
		} else if (name == "cx23416") {
			print_regs(fd, &get_reg, 0x02000000, 0x020000ff, stride);
		} else if (name == "cx23418") {
			print_regs(fd, &get_reg, 0x02c40000, 0x02c409c7, stride);
		} else if (name == "cafe") {
			print_regs(fd, &get_reg, 0, 0x43, stride);
			print_regs(fd, &get_reg, 0x88, 0x8f, stride);
			print_regs(fd, &get_reg, 0xb4, 0xbb, stride);
			print_regs(fd, &get_reg, 0x3000, 0x300c, stride);
		} else {
			/* unknown chip, dump 0-0xff by default */
			print_regs(fd, &get_reg, 0, 0xff, stride);
		}
	}
list_done:

	if (options[OptLogStatus]) {
		static char buf[40960];
		int len = -1;

		if (doioctl(fd, VIDIOC_LOG_STATUS, NULL, "VIDIOC_LOG_STATUS") == 0) {
			printf("\nStatus Log:\n\n");
#ifdef HAVE_KLOGCTL
			len = klogctl(3, buf, sizeof(buf) - 1);
#endif
			if (len >= 0) {
				bool found_status = false;
				char *p = buf;
				char *q;

				buf[len] = 0;
				while ((q = strstr(p, "START STATUS"))) {
					found_status = true;
					p = q + 1;
				}
				if (found_status) {
					while (p > buf && *p != '<') p--;
					q = p;
					while ((q = strstr(q, "<6>"))) {
						memcpy(q, "   ", 3);
					}
					printf("%s", p);
				}
			}
		}
	}

	if (options[OptListSymbols]) {
		if (curr_bd == NULL) {
			printf("No symbols found for driver %s\n", vcap.driver);
		}
		else {
			printf("Symbols for driver %s:\n", curr_bd->name);
			for (int i = 0; i < curr_bd->regs_size; i++)
				printf("0x%08x: %s\n", curr_bd->regs[i].reg, curr_bd->regs[i].name);
			for (int i = 0; i < curr_bd->alt_regs_size; i++)
				printf("0x%08x: %s\n", curr_bd->alt_regs[i].reg, curr_bd->alt_regs[i].name);
		}
	}

	close(fd);
	exit(0);
}
Ejemplo n.º 5
0
static void parse_dv_bt_timings(char *optarg, struct v4l2_dv_timings *dv_timings,
		bool &query, int &enumerate)
{
	char *value;
	char *subs = optarg;
	struct v4l2_bt_timings *bt = &dv_timings->bt;

	dv_timings->type = V4L2_DV_BT_656_1120;

	if (!strcmp(subs, "query")) {
		query = true;
		return;
	}

	while (*subs != '\0') {
		static const char *const subopts[] = {
			"width",
			"height",
			"interlaced",
			"polarities",
			"pixelclock",
			"hfp",
			"hs",
			"hbp",
			"vfp",
			"vs",
			"vbp",
			"il_vfp",
			"il_vs",
			"il_vbp",
			"index",
			NULL
		};

		switch (parse_subopt(&subs, subopts, &value)) {
		case 0:
			bt->width = atoi(value);
			break;
		case 1:
			bt->height = strtol(value, 0L, 0);
			break;
		case 2:
			bt->interlaced = strtol(value, 0L, 0);
			break;
		case 3:
			bt->polarities = strtol(value, 0L, 0);
			break;
		case 4:
			bt->pixelclock = strtol(value, 0L, 0);
			break;
		case 5:
			bt->hfrontporch = strtol(value, 0L, 0);
			break;
		case 6:
			bt->hsync = strtol(value, 0L, 0);
			break;
		case 7:
			bt->hbackporch = strtol(value, 0L, 0);
			break;
		case 8:
			bt->vfrontporch = strtol(value, 0L, 0);
			break;
		case 9:
			bt->vsync = strtol(value, 0L, 0);
			break;
		case 10:
			bt->vbackporch = strtol(value, 0L, 0);
			break;
		case 11:
			bt->il_vfrontporch = strtol(value, 0L, 0);
			break;
		case 12:
			bt->il_vsync = strtol(value, 0L, 0);
			break;
		case 13:
			bt->il_vbackporch = strtol(value, 0L, 0);
			break;
		case 14:
			enumerate = strtol(value, 0L, 0);
			break;
		default:
			stds_usage();
			exit(1);
		}
	}
}
Ejemplo n.º 6
0
void overlay_cmd(int ch, char *optarg)
{
	unsigned int *set_overlay_fmt_ptr = NULL;
	struct v4l2_format *overlay_fmt_ptr = NULL;
	char *value, *subs;

	switch (ch) {
	case OptSetOverlayFormat:
	case OptTryOverlayFormat:
	case OptSetOutputOverlayFormat:
	case OptTryOutputOverlayFormat:
		switch (ch) {
		case OptSetOverlayFormat:
		case OptTryOverlayFormat:
			set_overlay_fmt_ptr = &set_overlay_fmt;
			overlay_fmt_ptr = &overlay_fmt;
			break;
		case OptSetOutputOverlayFormat:
		case OptTryOutputOverlayFormat:
			set_overlay_fmt_ptr = &set_overlay_fmt_out;
			overlay_fmt_ptr = &overlay_fmt_out;
			break;
		}
		subs = optarg;
		while (*subs != '\0') {
			static const char *const subopts[] = {
				"chromakey",
				"global_alpha",
				"left",
				"top",
				"width",
				"height",
				"field",
				NULL
			};

			switch (parse_subopt(&subs, subopts, &value)) {
			case 0:
				overlay_fmt_ptr->fmt.win.chromakey = strtol(value, 0L, 0);
				*set_overlay_fmt_ptr |= FmtChromaKey;
				break;
			case 1:
				overlay_fmt_ptr->fmt.win.global_alpha = strtol(value, 0L, 0);
				*set_overlay_fmt_ptr |= FmtGlobalAlpha;
				break;
			case 2:
				overlay_fmt_ptr->fmt.win.w.left = strtol(value, 0L, 0);
				*set_overlay_fmt_ptr |= FmtLeft;
				break;
			case 3:
				overlay_fmt_ptr->fmt.win.w.top = strtol(value, 0L, 0);
				*set_overlay_fmt_ptr |= FmtTop;
				break;
			case 4:
				overlay_fmt_ptr->fmt.win.w.width = strtol(value, 0L, 0);
				*set_overlay_fmt_ptr |= FmtWidth;
				break;
			case 5:
				overlay_fmt_ptr->fmt.win.w.height = strtol(value, 0L, 0);
				*set_overlay_fmt_ptr |= FmtHeight;
				break;
			case 6:
				overlay_fmt_ptr->fmt.win.field = parse_field(value);
				*set_overlay_fmt_ptr |= FmtField;
				break;
			default:
				overlay_usage();
				break;
			}
		}
		break;
	case OptSetFBuf:
		subs = optarg;
		while (*subs != '\0') {
			static const char *const subopts[] = {
				"chromakey",
				"global_alpha",
				"local_alpha",
				"local_inv_alpha",
				NULL
			};

			switch (parse_subopt(&subs, subopts, &value)) {
			case 0:
				fbuf.flags |= strtol(value, 0L, 0) ? V4L2_FBUF_FLAG_CHROMAKEY : 0;
				set_fbuf |= V4L2_FBUF_FLAG_CHROMAKEY;
				break;
			case 1:
				fbuf.flags |= strtol(value, 0L, 0) ? V4L2_FBUF_FLAG_GLOBAL_ALPHA : 0;
				set_fbuf |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
				break;
			case 2:
				fbuf.flags |= strtol(value, 0L, 0) ? V4L2_FBUF_FLAG_LOCAL_ALPHA : 0;
				set_fbuf |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
				break;
			case 3:
				fbuf.flags |= strtol(value, 0L, 0) ? V4L2_FBUF_FLAG_LOCAL_INV_ALPHA : 0;
				set_fbuf |= V4L2_FBUF_FLAG_LOCAL_INV_ALPHA;
				break;
			default:
				overlay_usage();
				break;
			}
		}
		break;
	case OptOverlay:
		overlay = strtol(optarg, 0L, 0);
		break;
	}
}
Ejemplo n.º 7
0
void misc_cmd(int ch, char *optarg)
{
    char *value, *subs;

    switch (ch) {
    case OptSetParm:
        fps = strtod(optarg, NULL);
        break;
    case OptSetOutputParm:
        output_fps = strtod(optarg, NULL);
        break;
    case OptSetJpegComp:
        subs = optarg;
        while (*subs != '\0') {
            static const char *const subopts[] = {
                "app0", "app1", "app2", "app3",
                "app4", "app5", "app6", "app7",
                "app8", "app9", "appa", "appb",
                "appc", "appd", "appe", "appf",
                "quality",
                "markers",
                "comment",
                NULL
            };
            size_t len;
            int opt = parse_subopt(&subs, subopts, &value);

            switch (opt) {
            case 16:
                jpegcomp.quality = strtol(value, 0L, 0);
                break;
            case 17:
                if (strstr(value, "dht"))
                    jpegcomp.jpeg_markers |= V4L2_JPEG_MARKER_DHT;
                if (strstr(value, "dqt"))
                    jpegcomp.jpeg_markers |= V4L2_JPEG_MARKER_DQT;
                if (strstr(value, "dri"))
                    jpegcomp.jpeg_markers |= V4L2_JPEG_MARKER_DRI;
                break;
            case 18:
                len = strlen(value);
                if (len > sizeof(jpegcomp.COM_data) - 1)
                    len = sizeof(jpegcomp.COM_data) - 1;
                jpegcomp.COM_len = len;
                memcpy(jpegcomp.COM_data, value, len);
                jpegcomp.COM_data[len] = '\0';
                break;
            default:
                if (opt < 0 || opt > 15) {
                    misc_usage();
                    exit(1);
                }
                len = strlen(value);
                if (len > sizeof(jpegcomp.APP_data) - 1)
                    len = sizeof(jpegcomp.APP_data) - 1;
                if (jpegcomp.APP_len) {
                    fprintf(stderr, "Only one APP segment can be set\n");
                    break;
                }
                jpegcomp.APP_len = len;
                memcpy(jpegcomp.APP_data, value, len);
                jpegcomp.APP_data[len] = '\0';
                jpegcomp.APPn = opt;
                break;
            }
        }
        break;
    case OptEncoderCmd:
    case OptTryEncoderCmd:
        subs = optarg;
        while (*subs != '\0') {
            static const char *const subopts[] = {
                "cmd",
                "flags",
                NULL
            };

            switch (parse_subopt(&subs, subopts, &value)) {
            case 0:
                enc_cmd.cmd = parse_cmd(value);
                break;
            case 1:
                enc_cmd.flags = parse_encflags(value);
                break;
            default:
                misc_usage();
                exit(1);
            }
        }
        break;
    case OptDecoderCmd:
    case OptTryDecoderCmd:
        subs = optarg;
        while (*subs != '\0') {
            static const char *const subopts[] = {
                "cmd",
                "flags",
                "stop_pts",
                "start_speed",
                "start_format",
                NULL
            };

            switch (parse_subopt(&subs, subopts, &value)) {
            case 0:
                dec_cmd.cmd = parse_cmd(value);
                break;
            case 1:
                dec_cmd.flags = parse_decflags(value);
                break;
            case 2:
                dec_cmd.stop.pts = strtoull(value, 0, 0);
                break;
            case 3:
                dec_cmd.start.speed = strtol(value, 0, 0);
                break;
            case 4:
                if (!strcmp(value, "gop"))
                    dec_cmd.start.format = V4L2_DEC_START_FMT_GOP;
                else if (!strcmp(value, "none"))
                    dec_cmd.start.format = V4L2_DEC_START_FMT_NONE;
                break;
            default:
                misc_usage();
                exit(1);
            }
        }
        break;
    }
}
Ejemplo n.º 8
0
void edid_cmd(int ch, char *optarg)
{
	char *value, *subs;

	switch (ch) {
	case OptSetEdid:
		memset(&sedid, 0, sizeof(sedid));
		file_in = NULL;
		if (!optarg)
			break;
		subs = optarg;
		while (*subs != '\0') {
			static const char *const subopts[] = {
				"pad",
				"edid",
				"file",
				NULL
			};
			switch (parse_subopt(&subs, subopts, &value)) {
			case 0:
				sedid.pad = strtoul(value, 0, 0);
				break;
			case 1:
				if (!strcmp(value, "dvid")) {
					sedid.edid = dvid_edid;
					sedid.blocks = sizeof(dvid_edid) / 128;
				} else if (!strcmp(value, "vga")) {
					sedid.edid = vga_edid;
					sedid.blocks = sizeof(vga_edid) / 128;
				} else if (!strcmp(value, "hdmi")) {
					sedid.edid = hdmi_edid;
					sedid.blocks = sizeof(hdmi_edid) / 128;
				} else {
					edid_usage();
					exit(1);
				}
				if (file_in) {
					fprintf(stderr, "The edid and file options can't be used together.\n");
					exit(1);
				}
				break;
			case 2:
				if (value) {
					file_in = value;
					if (sedid.edid) {
						fprintf(stderr, "The edid and file options can't be used together.\n");
						exit(1);
					}
				}
				break;
			default:
				edid_usage();
				exit(1);
			}
		}
		break;

	case OptClearEdid:
		if (optarg)
			clear_pad = strtoul(optarg, 0, 0);
		break;

	case OptGetEdid:
		memset(&gedid, 0, sizeof(gedid));
		gedid.blocks = 256; /* default all blocks */
		gformat = HEX; /* default hex output */
		file_out = NULL;
		if (!optarg)
			break;
		subs = optarg;
		while (*subs != '\0') {
			static const char *const subopts[] = {
				"pad",
				"startblock",
				"blocks",
				"format",
				"file",
				NULL
			};
			switch (parse_subopt(&subs, subopts, &value)) {
			case 0:
				gedid.pad = strtoul(value, 0, 0);
				break;
			case 1:
				gedid.start_block = strtoul(value, 0, 0);
				if (gedid.start_block > 255) {
					fprintf(stderr, "startblock %d too large, max 255\n", gedid.start_block);
					exit(1);
				}
				break;
			case 2:
				gedid.blocks = strtoul(value, 0, 0);
				break;
			case 3:
				if (!strcmp(value, "hex")) {
					gformat = HEX;
				} else if (!strcmp(value, "raw")) {
					gformat = RAW;
				} else if (!strcmp(value, "carray")) {
					gformat = CARRAY;
				} else {
					edid_usage();
					exit(1);
				}
				break;
			case 4:
				if (value)
					file_out = value;
				break;
			default:
				edid_usage();
				exit(1);
			}
		}
		if (gedid.start_block + gedid.blocks > 256)
			gedid.blocks = 256 - gedid.start_block;
	}
}