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_s_parm.h> 00031 #include <libexplain/is_efault.h> 00032 00033 #ifdef VIDIOC_S_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, 1); 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 /* probably not the error */ 00079 break; 00080 00081 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 00082 case V4L2_BUF_TYPE_VBI_CAPTURE: 00083 case V4L2_BUF_TYPE_VBI_OUTPUT: 00084 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 00085 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 00086 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 00087 case V4L2_BUF_TYPE_PRIVATE: 00088 #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE 00089 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 00090 #endif 00091 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE 00092 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 00093 #endif 00094 explain_buffer_enotsup_device(sb, "data->type"); 00095 return; 00096 00097 default: 00098 explain_buffer_einval_vague(sb, "data->type"); 00099 return; 00100 } 00101 } 00102 else 00103 { 00104 /* not a supported buf type, still wrong */ 00105 switch (arg->type) 00106 { 00107 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 00108 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 00109 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 00110 case V4L2_BUF_TYPE_VBI_CAPTURE: 00111 case V4L2_BUF_TYPE_VBI_OUTPUT: 00112 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 00113 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 00114 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 00115 case V4L2_BUF_TYPE_PRIVATE: 00116 #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE 00117 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 00118 #endif 00119 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE 00120 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 00121 #endif 00122 explain_buffer_enotsup_device(sb, "data->type"); 00123 return; 00124 00125 default: 00126 explain_buffer_einval_vague(sb, "data->type"); 00127 return; 00128 } 00129 } 00130 } 00131 00132 /* no idea */ 00133 goto generic; 00134 00135 default: 00136 generic: 00137 explain_iocontrol_generic_print_explanation 00138 ( 00139 p, 00140 sb, 00141 errnum, 00142 fildes, 00143 request, 00144 data 00145 ); 00146 break; 00147 } 00148 } 00149 00150 00151 static void 00152 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00153 int errnum, int fildes, int request, const void *data) 00154 { 00155 (void)p; 00156 (void)errnum; 00157 (void)fildes; 00158 (void)request; 00159 explain_buffer_v4l2_streamparm(sb, data, 1); 00160 } 00161 00162 00163 const explain_iocontrol_t explain_iocontrol_vidioc_s_parm = 00164 { 00165 "VIDIOC_S_PARM", /* name */ 00166 VIDIOC_S_PARM, /* value */ 00167 0, /* disambiguate */ 00168 0, /* print_name */ 00169 print_data, 00170 print_explanation, 00171 print_data_returned, 00172 sizeof(struct v4l2_streamparm), /* data_size */ 00173 "struct v4l2_streamparm *", /* data_type */ 00174 0, /* flags */ 00175 __FILE__, 00176 __LINE__, 00177 }; 00178 00179 #else /* ndef VIDIOC_S_PARM */ 00180 00181 const explain_iocontrol_t explain_iocontrol_vidioc_s_parm = 00182 { 00183 0, /* name */ 00184 0, /* value */ 00185 0, /* disambiguate */ 00186 0, /* print_name */ 00187 0, /* print_data */ 00188 0, /* print_explanation */ 00189 0, /* print_data_returned */ 00190 0, /* data_size */ 00191 0, /* data_type */ 00192 0, /* flags */ 00193 __FILE__, 00194 __LINE__, 00195 }; 00196 00197 #endif /* VIDIOC_S_PARM */ 00198 00199 /* vim: set ts=8 sw=4 et : */