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/int64_t.h> 00026 #include <libexplain/buffer/pointer.h> 00027 #include <libexplain/buffer/v4l2_control_id.h> 00028 #include <libexplain/buffer/v4l2_ext_control.h> 00029 #include <libexplain/is_efault.h> 00030 #include <libexplain/sizeof.h> 00031 00032 00033 #ifdef HAVE_LINUX_VIDEODEV2_H 00034 00035 void 00036 explain_buffer_v4l2_ext_control(explain_string_buffer_t *sb, 00037 const struct v4l2_ext_control *data, int fildes) 00038 { 00039 struct v4l2_queryctrl qry; 00040 00041 if (explain_is_efault_pointer(data, sizeof(*data))) 00042 { 00043 explain_buffer_pointer(sb, data); 00044 return; 00045 } 00046 00047 explain_string_buffer_puts(sb, "{ id = "); 00048 explain_buffer_v4l2_control_id(sb, data->id); 00049 00050 if (!explain_uint32_array_all_zero(data->reserved2, 00051 SIZEOF(data->reserved2))) 00052 { 00053 explain_string_buffer_puts(sb, ", reserved = "); 00054 explain_buffer_uint32_array(sb, data->reserved2, 00055 SIZEOF(data->reserved2)); 00056 } 00057 00058 memset(&qry, 0, sizeof(qry)); 00059 qry.id = data->id; 00060 if (ioctl(fildes, VIDIOC_QUERYCTRL, &qry) >= 0) 00061 { 00062 switch (qry.type) 00063 { 00064 case V4L2_CTRL_TYPE_INTEGER: 00065 case V4L2_CTRL_TYPE_BUTTON: 00066 #if defined(V4L2_CTRL_TYPE_BITMASK) || defined(HAVE_V4L2_CTRL_TYPE_BITMASK) 00067 case V4L2_CTRL_TYPE_BITMASK: 00068 #endif 00069 explain_buffer_uint32_t(sb, data->value); 00070 break; 00071 00072 case V4L2_CTRL_TYPE_INTEGER64: 00073 explain_buffer_uint64_t(sb, data->value64); 00074 break; 00075 00076 case V4L2_CTRL_TYPE_CTRL_CLASS: 00077 /* Huh?!? */ 00078 break; 00079 00080 #if defined(V4L2_CTRL_TYPE_STRING) || defined(HAVE_V4L2_CTRL_TYPE_STRING) 00081 case V4L2_CTRL_TYPE_STRING: 00082 explain_string_buffer_puts(sb, ", size = "); 00083 explain_buffer_uint32_t(sb, data->size); 00084 if (explain_is_efault_string(data->string)) 00085 explain_buffer_pointer(sb, data->string); 00086 else 00087 explain_string_buffer_puts_quoted(sb, data->string); 00088 break; 00089 #endif 00090 00091 case V4L2_CTRL_TYPE_BOOLEAN: 00092 explain_buffer_boolean(sb, data->value); 00093 break; 00094 00095 case V4L2_CTRL_TYPE_MENU: 00096 { 00097 struct v4l2_querymenu value; 00098 00099 explain_buffer_int32_t(sb, data->value); 00100 00101 memset(&value, 0, sizeof(value)); 00102 value.id = data->id; 00103 value.index = data->value; 00104 if 00105 ( 00106 ioctl(fildes, VIDIOC_QUERYMENU, &value) >= 0 00107 && 00108 value.name[0] 00109 ) 00110 { 00111 explain_string_buffer_putc(sb, ' '); 00112 explain_string_buffer_putsu_quoted_n 00113 ( 00114 sb, 00115 value.name, 00116 sizeof(value.name) 00117 ); 00118 } 00119 } 00120 break; 00121 00122 default: 00123 /* Maybe this code is out of date? */ 00124 break; 00125 } 00126 } 00127 explain_string_buffer_puts(sb, " }"); 00128 } 00129 00130 00131 void 00132 explain_buffer_v4l2_ext_control_array(explain_string_buffer_t *sb, 00133 const struct v4l2_ext_control *data, unsigned data_size, int fildes) 00134 { 00135 size_t j; 00136 00137 if (explain_is_efault_pointer(data, data_size * sizeof(*data))) 00138 { 00139 explain_buffer_pointer(sb, data); 00140 return; 00141 } 00142 00143 explain_string_buffer_puts(sb, "{ "); 00144 for (j = 0; j < data_size; ++j) 00145 { 00146 if (j) 00147 explain_string_buffer_puts(sb, ", "); 00148 explain_buffer_v4l2_ext_control(sb, data + j, fildes); 00149 } 00150 explain_string_buffer_puts(sb, " }"); 00151 } 00152 00153 #endif 00154 00155 /* vim: set ts=8 sw=4 et : */