libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2011, 2013 Peter Miller 00004 * Written by Peter Miller <pmiller@opensource.org.au> 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 3 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include <libexplain/ac/errno.h> 00021 #include <libexplain/ac/linux/videodev2.h> 00022 #include <libexplain/ac/string.h> 00023 #include <libexplain/ac/sys/ioctl.h> 00024 00025 #include <libexplain/buffer/einval.h> 00026 #include <libexplain/buffer/enotsup.h> 00027 #include <libexplain/buffer/is_the_null_pointer.h> 00028 #include <libexplain/buffer/v4l2_streamparm.h> 00029 #include <libexplain/iocontrol/generic.h> 00030 #include <libexplain/iocontrol/vidioc_g_parm.h> 00031 #include <libexplain/is_efault.h> 00032 00033 #ifdef VIDIOC_G_PARM 00034 00035 00036 static void 00037 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00038 int errnum, int fildes, int request, const void *data) 00039 { 00040 (void)p; 00041 (void)errnum; 00042 (void)fildes; 00043 (void)request; 00044 explain_buffer_v4l2_streamparm(sb, data, 0); 00045 } 00046 00047 00048 static void 00049 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00050 int errnum, int fildes, int request, const void *data) 00051 { 00052 switch (errnum) 00053 { 00054 case EINVAL: 00055 if (!data) 00056 { 00057 explain_buffer_is_the_null_pointer(sb, "data"); 00058 return; 00059 } 00060 00061 { 00062 const struct v4l2_streamparm *arg; 00063 struct v4l2_format fmt; 00064 00065 arg = data; 00066 if (explain_is_efault_pointer(arg, sizeof(*arg))) 00067 goto generic; 00068 00069 memset(&fmt, 0, sizeof(fmt)); 00070 fmt.type = arg->type; 00071 if (ioctl(fildes, VIDIOC_G_FMT, &fmt) >= 0) 00072 { 00073 /* supported buf type, still wrong */ 00074 switch (arg->type) 00075 { 00076 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 00077 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 00078 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 00079 case V4L2_BUF_TYPE_VBI_CAPTURE: 00080 case V4L2_BUF_TYPE_VBI_OUTPUT: 00081 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 00082 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 00083 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 00084 case V4L2_BUF_TYPE_PRIVATE: 00085 #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE 00086 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 00087 #endif 00088 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE 00089 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 00090 #endif 00091 explain_buffer_enotsup_device(sb, "data->type"); 00092 return; 00093 00094 default: 00095 explain_buffer_einval_vague(sb, "data->type"); 00096 return; 00097 } 00098 } 00099 else 00100 { 00101 /* not a supported buf type, still wrong */ 00102 switch (arg->type) 00103 { 00104 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 00105 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 00106 goto generic; 00107 00108 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 00109 case V4L2_BUF_TYPE_VBI_CAPTURE: 00110 case V4L2_BUF_TYPE_VBI_OUTPUT: 00111 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 00112 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 00113 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 00114 case V4L2_BUF_TYPE_PRIVATE: 00115 #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE 00116 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 00117 #endif 00118 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE 00119 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 00120 #endif 00121 explain_buffer_enotsup_device(sb, "data->type"); 00122 return; 00123 00124 default: 00125 explain_buffer_einval_vague(sb, "data->type"); 00126 return; 00127 } 00128 } 00129 } 00130 00131 /* No idea */ 00132 goto generic; 00133 00134 default: 00135 generic: 00136 explain_iocontrol_generic_print_explanation 00137 ( 00138 p, 00139 sb, 00140 errnum, 00141 fildes, 00142 request, 00143 data 00144 ); 00145 break; 00146 } 00147 } 00148 00149 00150 static void 00151 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00152 int errnum, int fildes, int request, const void *data) 00153 { 00154 (void)p; 00155 (void)errnum; 00156 (void)fildes; 00157 (void)request; 00158 explain_buffer_v4l2_streamparm(sb, data, 1); 00159 } 00160 00161 00162 const explain_iocontrol_t explain_iocontrol_vidioc_g_parm = 00163 { 00164 "VIDIOC_G_PARM", /* name */ 00165 VIDIOC_G_PARM, /* value */ 00166 0, /* disambiguate */ 00167 0, /* print_name */ 00168 print_data, 00169 print_explanation, 00170 print_data_returned, 00171 sizeof(struct v4l2_streamparm), /* data_size */ 00172 "struct v4l2_streamparm *", /* data_type */ 00173 0, /* flags */ 00174 __FILE__, 00175 __LINE__, 00176 }; 00177 00178 #else /* ndef VIDIOC_G_PARM */ 00179 00180 const explain_iocontrol_t explain_iocontrol_vidioc_g_parm = 00181 { 00182 0, /* name */ 00183 0, /* value */ 00184 0, /* disambiguate */ 00185 0, /* print_name */ 00186 0, /* print_data */ 00187 0, /* print_explanation */ 00188 0, /* print_data_returned */ 00189 0, /* data_size */ 00190 0, /* data_type */ 00191 0, /* flags */ 00192 __FILE__, 00193 __LINE__, 00194 }; 00195 00196 #endif /* VIDIOC_G_PARM */ 00197 00198 /* vim: set ts=8 sw=4 et : */