libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2011-2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/ac/linux/videodev2.h> 00020 #include <libexplain/ac/string.h> 00021 #include <libexplain/ac/sys/ioctl.h> 00022 00023 #include <libexplain/buffer/boolean.h> 00024 #include <libexplain/buffer/int32_t.h> 00025 #include <libexplain/buffer/v4l2_control_id.h> 00026 #include <libexplain/buffer/v4l2_ctrl_type.h> 00027 #include <libexplain/buffer/v4l2_queryctrl.h> 00028 #include <libexplain/buffer/v4l2_queryctrl_flags.h> 00029 #include <libexplain/buffer/pointer.h> 00030 #include <libexplain/is_efault.h> 00031 00032 00033 #ifdef HAVE_LINUX_VIDEODEV2_H 00034 00035 void 00036 explain_buffer_v4l2_queryctrl(explain_string_buffer_t *sb, 00037 const struct v4l2_queryctrl *data, int extra, int fildes) 00038 { 00039 if (explain_is_efault_pointer(data, sizeof(*data))) 00040 { 00041 explain_buffer_pointer(sb, data); 00042 return; 00043 } 00044 00045 explain_string_buffer_puts(sb, "{ id = "); 00046 explain_buffer_v4l2_control_id(sb, data->id); 00047 if (extra) 00048 { 00049 explain_string_buffer_puts(sb, ", type = "); 00050 explain_buffer_v4l2_ctrl_type(sb, data->type); 00051 explain_string_buffer_puts(sb, ", name = "); 00052 explain_string_buffer_putsu_quoted_n 00053 ( 00054 sb, 00055 data->name, 00056 sizeof(data->name) 00057 ); 00058 explain_string_buffer_puts(sb, ", minimum = "); 00059 explain_buffer_int32_t(sb, data->minimum); 00060 explain_string_buffer_puts(sb, ", maximum = "); 00061 explain_buffer_int32_t(sb, data->maximum); 00062 explain_string_buffer_puts(sb, ", step = "); 00063 explain_buffer_int32_t(sb, data->step); 00064 explain_string_buffer_puts(sb, ", default_value = "); 00065 switch (data->type) 00066 { 00067 case V4L2_CTRL_TYPE_INTEGER64: 00068 case V4L2_CTRL_TYPE_CTRL_CLASS: 00069 #if defined(V4L2_CTRL_TYPE_STRING) || defined(HAVE_V4L2_CTRL_TYPE_STRING) 00070 case V4L2_CTRL_TYPE_STRING: 00071 #endif 00072 #if defined(V4L2_CTRL_TYPE_BITMASK) || defined(HAVE_V4L2_CTRL_TYPE_BITMASK) 00073 case V4L2_CTRL_TYPE_BITMASK: 00074 #endif 00075 /* 00076 * In theory, these types only occur for v4l2_ext_control 00077 * values. In practice, they better be right. 00078 */ 00079 00080 case V4L2_CTRL_TYPE_INTEGER: 00081 case V4L2_CTRL_TYPE_BUTTON: 00082 default: 00083 explain_buffer_int32_t(sb, data->default_value); 00084 break; 00085 00086 case V4L2_CTRL_TYPE_BOOLEAN: 00087 explain_buffer_boolean(sb, data->default_value); 00088 break; 00089 00090 case V4L2_CTRL_TYPE_MENU: 00091 { 00092 struct v4l2_querymenu value; 00093 00094 explain_buffer_int32_t(sb, data->default_value); 00095 00096 memset(&value, 0, sizeof(value)); 00097 value.id = data->id; 00098 value.index = data->default_value; 00099 if 00100 ( 00101 ioctl(fildes, VIDIOC_QUERYMENU, &value) >= 0 00102 && 00103 value.name[0] 00104 ) 00105 { 00106 explain_string_buffer_putc(sb, ' '); 00107 explain_string_buffer_putsu_quoted_n 00108 ( 00109 sb, 00110 value.name, 00111 sizeof(value.name) 00112 ); 00113 } 00114 } 00115 break; 00116 } 00117 explain_string_buffer_puts(sb, ", flags = "); 00118 explain_buffer_v4l2_queryctrl_flags(sb, data->flags); 00119 } 00120 explain_string_buffer_puts(sb, " }"); 00121 } 00122 00123 00124 enum explain_v4l2_queryctrl_check_id_t 00125 explain_v4l2_queryctrl_check_id(int fildes, const struct v4l2_queryctrl *data) 00126 { 00127 if (explain_is_efault_pointer(data, sizeof(*data))) 00128 return explain_v4l2_queryctrl_check_id_no_idea; 00129 switch (explain_v4l2_control_id_check(fildes, data->id)) 00130 { 00131 case explain_v4l2_control_id_check_no_idea: 00132 default: 00133 return explain_v4l2_queryctrl_check_id_no_idea; 00134 00135 case explain_v4l2_control_id_check_nosuch: 00136 return explain_v4l2_queryctrl_check_id_nosuch; 00137 00138 case explain_v4l2_control_id_check_notsup: 00139 return explain_v4l2_queryctrl_check_id_notsup; 00140 00141 case explain_v4l2_control_id_check_ok: 00142 return explain_v4l2_queryctrl_check_id_ok; 00143 } 00144 } 00145 00146 /* vim: set ts=8 sw=4 et : */ 00147 #endif