static bool fill_subset(const struct v4l2_query_ext_ctrl &qc, ctrl_subset &subset) { unsigned d; if (qc.nr_of_dims == 0) return false; for (d = 0; d < qc.nr_of_dims; d++) { subset.offset[d] = 0; subset.size[d] = qc.dims[d]; } std::string s = name2var(qc.name); if (ctrl_subsets.find(s) != ctrl_subsets.end()) { unsigned ss_dims; subset = ctrl_subsets[s]; for (ss_dims = 0; ss_dims < V4L2_CTRL_MAX_DIMS && subset.size[ss_dims]; ss_dims++) ; if (ss_dims != qc.nr_of_dims) { fprintf(stderr, "expected %d dimensions but --subset specified %d\n", qc.nr_of_dims, ss_dims); return true; } for (d = 0; d < qc.nr_of_dims; d++) { if (subset.offset[d] + subset.size[d] > qc.dims[d]) { fprintf(stderr, "the subset offset+size for dimension %d is out of range\n", d); return true; } } } return false; }
static void print_qctrl(int fd, struct v4l2_queryctrl *queryctrl, struct v4l2_ext_control *ctrl, int show_menus) { struct v4l2_querymenu qmenu = { 0 }; std::string s = name2var(queryctrl->name); int i; qmenu.id = queryctrl->id; switch (queryctrl->type) { case V4L2_CTRL_TYPE_INTEGER: printf("%31s (int) : min=%d max=%d step=%d default=%d value=%d", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->step, queryctrl->default_value, ctrl->value); break; case V4L2_CTRL_TYPE_INTEGER64: printf("%31s (int64): value=%lld", s.c_str(), ctrl->value64); break; case V4L2_CTRL_TYPE_BOOLEAN: printf("%31s (bool) : default=%d value=%d", s.c_str(), queryctrl->default_value, ctrl->value); break; case V4L2_CTRL_TYPE_MENU: printf("%31s (menu) : min=%d max=%d default=%d value=%d", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->default_value, ctrl->value); break; case V4L2_CTRL_TYPE_BUTTON: printf("%31s (button)\n", s.c_str()); break; default: break; } if (queryctrl->flags) { const flag_def def[] = { { V4L2_CTRL_FLAG_GRABBED, "grabbed" }, { V4L2_CTRL_FLAG_READ_ONLY, "read-only" }, { V4L2_CTRL_FLAG_UPDATE, "update" }, { V4L2_CTRL_FLAG_INACTIVE, "inactive" }, { V4L2_CTRL_FLAG_SLIDER, "slider" }, { 0, NULL } }; printf(" flags=%s", flags2s(queryctrl->flags, def).c_str()); } printf("\n"); if (queryctrl->type == V4L2_CTRL_TYPE_MENU && show_menus) { for (i = 0; i <= queryctrl->maximum; i++) { qmenu.index = i; if (ioctl(fd, VIDIOC_QUERYMENU, &qmenu)) continue; printf("\t\t\t\t%d: %s\n", i, qmenu.name); } } }
static void find_controls(int fd) { printf("finding controls\n"); struct v4l2_queryctrl qctrl = { V4L2_CTRL_FLAG_NEXT_CTRL }; int id; while (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) { if (qctrl.type != V4L2_CTRL_TYPE_CTRL_CLASS && !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2id[name2var(qctrl.name)] = qctrl.id; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; } if (qctrl.id != V4L2_CTRL_FLAG_NEXT_CTRL) return; for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) { qctrl.id = id; if (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0 && !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2id[name2var(qctrl.name)] = qctrl.id; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } } for (qctrl.id = V4L2_CID_PRIVATE_BASE; ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) { if (!(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2id[name2var(qctrl.name)] = qctrl.id; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } } }
static void find_controls(int fd) { const unsigned next_fl = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND; struct v4l2_query_ext_ctrl qctrl; int id; memset(&qctrl, 0, sizeof(qctrl)); qctrl.id = next_fl; while (query_ext_ctrl_ioctl(fd, qctrl) == 0) { if (qctrl.type != V4L2_CTRL_TYPE_CTRL_CLASS && !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } qctrl.id |= next_fl; } if (!(qctrl.id & next_fl)) return; for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) { qctrl.id = id; if (query_ext_ctrl_ioctl(fd, qctrl) == 0 && !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } } for (qctrl.id = V4L2_CID_PRIVATE_BASE; query_ext_ctrl_ioctl(fd, qctrl) == 0; qctrl.id++) { if (!(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } } }
static void find_controls(int fd) { struct v4l2_queryctrl qctrl; int id; memset(&qctrl, 0, sizeof(qctrl)); qctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL; while (test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) { if (qctrl.type != V4L2_CTRL_TYPE_CTRL_CLASS && !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; } if (qctrl.id != V4L2_CTRL_FLAG_NEXT_CTRL) return; for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) { qctrl.id = id; if (test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0 && !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } } for (qctrl.id = V4L2_CID_PRIVATE_BASE; test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) { if (!(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) { ctrl_str2q[name2var(qctrl.name)] = qctrl; ctrl_id2str[qctrl.id] = name2var(qctrl.name); } } }
void enter_control_options( struct v4l2_queryctrl *queryctrl, CAMERA_CONTROLS cam_ctl[100], char menu_names[30][100], int *cam_ctl_c, int *menu_c ) { struct v4l2_control control; struct v4l2_querymenu querymenu; std::string s; strcpy( cam_ctl[*cam_ctl_c].name, (char*) queryctrl->name ); s = name2var( (unsigned char*) cam_ctl[*cam_ctl_c].name ); strcpy( cam_ctl[*cam_ctl_c].format_name, s.c_str() ); cam_ctl[*cam_ctl_c].id = queryctrl->id; cam_ctl[*cam_ctl_c].type = queryctrl->type; cam_ctl[*cam_ctl_c].max_value = queryctrl->maximum; cam_ctl[*cam_ctl_c].min_value = queryctrl->minimum; cam_ctl[*cam_ctl_c].step = queryctrl->step; memset( &control, 0, sizeof(control) ); control.id = queryctrl->id; if( 0 == ioctl( fd, VIDIOC_G_CTRL, &control ) ) cam_ctl[*cam_ctl_c].value = control.value; if( queryctrl->type == V4L2_CTRL_TYPE_MENU ) { cam_ctl[*cam_ctl_c].menu_start = *menu_c; memset( &querymenu, 0, sizeof(querymenu) ); querymenu.id = queryctrl->id; for( querymenu.index = queryctrl->minimum; querymenu.index <= queryctrl->maximum; querymenu.index++ ) { if( 0 == ioctl ( fd, VIDIOC_QUERYMENU, &querymenu ) ) { strcpy( menu_names[*menu_c], (char*) querymenu.name ); (*menu_c)++; } } cam_ctl[*cam_ctl_c].menu_end = *menu_c; } (*cam_ctl_c)++; }
static void print_qctrl(int fd, struct v4l2_query_ext_ctrl *queryctrl, struct v4l2_ext_control *ctrl, int show_menus) { struct v4l2_querymenu qmenu; std::string s = name2var(queryctrl->name); unsigned i; memset(&qmenu, 0, sizeof(qmenu)); qmenu.id = queryctrl->id; switch (queryctrl->type) { case V4L2_CTRL_TYPE_INTEGER: printf("%31s (int) : min=%lld max=%lld step=%lld default=%lld", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->step, queryctrl->default_value); break; case V4L2_CTRL_TYPE_INTEGER64: printf("%31s (int64) : min=%lld max=%lld step=%lld default=%lld", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->step, queryctrl->default_value); break; case V4L2_CTRL_TYPE_STRING: printf("%31s (str) : min=%lld max=%lld step=%lld", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->step); break; case V4L2_CTRL_TYPE_BOOLEAN: printf("%31s (bool) : default=%lld", s.c_str(), queryctrl->default_value); break; case V4L2_CTRL_TYPE_MENU: printf("%31s (menu) : min=%lld max=%lld default=%lld", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->default_value); break; case V4L2_CTRL_TYPE_INTEGER_MENU: printf("%31s (intmenu): min=%lld max=%lld default=%lld", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->default_value); break; case V4L2_CTRL_TYPE_BUTTON: printf("%31s (button) :", s.c_str()); break; case V4L2_CTRL_TYPE_BITMASK: printf("%31s (bitmask): max=0x%08llx default=0x%08llx", s.c_str(), queryctrl->maximum, queryctrl->default_value); break; case V4L2_CTRL_TYPE_U8: printf("%31s (u8) : min=%lld max=%lld step=%lld default=%lld", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->step, queryctrl->default_value); break; case V4L2_CTRL_TYPE_U16: printf("%31s (u16) : min=%lld max=%lld step=%lld default=%lld", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->step, queryctrl->default_value); break; case V4L2_CTRL_TYPE_U32: printf("%31s (u32) : min=%lld max=%lld step=%lld default=%lld", s.c_str(), queryctrl->minimum, queryctrl->maximum, queryctrl->step, queryctrl->default_value); break; default: printf("%31s (unknown): type=%x", s.c_str(), queryctrl->type); break; } if (queryctrl->nr_of_dims == 0) { switch (queryctrl->type) { case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_BOOLEAN: case V4L2_CTRL_TYPE_MENU: case V4L2_CTRL_TYPE_INTEGER_MENU: printf(" value=%d", ctrl->value); break; case V4L2_CTRL_TYPE_BITMASK: printf(" value=0x%08x", ctrl->value); break; case V4L2_CTRL_TYPE_INTEGER64: printf(" value=%lld", ctrl->value64); break; case V4L2_CTRL_TYPE_STRING: printf(" value='%s'", safename(ctrl->string).c_str()); break; default: break; } } if (queryctrl->nr_of_dims) { printf(" "); for (i = 0; i < queryctrl->nr_of_dims; i++) printf("[%u]", queryctrl->dims[i]); } if (queryctrl->flags) printf(" flags=%s", ctrlflags2s(queryctrl->flags).c_str()); printf("\n"); if ((queryctrl->type == V4L2_CTRL_TYPE_MENU || queryctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) && show_menus) { for (i = queryctrl->minimum; i <= queryctrl->maximum; i++) { qmenu.index = i; if (test_ioctl(fd, VIDIOC_QUERYMENU, &qmenu)) continue; if (queryctrl->type == V4L2_CTRL_TYPE_MENU) printf("\t\t\t\t%d: %s\n", i, qmenu.name); else printf("\t\t\t\t%d: %lld (0x%llx)\n", i, qmenu.value, qmenu.value); } } }