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/sys/ioctl.h> 00023 00024 #include <libexplain/buffer/einval.h> 00025 #include <libexplain/buffer/v4l2_fmtdesc.h> 00026 #include <libexplain/buffer/is_the_null_pointer.h> 00027 #include <libexplain/iocontrol/generic.h> 00028 #include <libexplain/iocontrol/vidioc_enum_fmt.h> 00029 #include <libexplain/is_efault.h> 00030 00031 #ifdef VIDIOC_ENUM_FMT 00032 00033 00034 static void 00035 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00036 int errnum, int fildes, int request, const void *data) 00037 { 00038 (void)p; 00039 (void)errnum; 00040 (void)fildes; 00041 (void)request; 00042 explain_buffer_v4l2_fmtdesc(sb, data, 0); 00043 } 00044 00045 00046 static void 00047 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00048 int errnum, int fildes, int request, const void *data) 00049 { 00050 switch (errnum) 00051 { 00052 case EINVAL: 00053 if (!data) 00054 { 00055 explain_buffer_is_the_null_pointer(sb, "data"); 00056 return; 00057 } 00058 00059 { 00060 const struct v4l2_fmtdesc *arg; 00061 int nformats; 00062 00063 arg = data; 00064 if (explain_is_efault_pointer(arg, sizeof(*arg))) 00065 goto generic; 00066 00067 /* 00068 * Check the type. 00069 * Not all types are available for enumeration. 00070 */ 00071 switch (arg->type) 00072 { 00073 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 00074 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 00075 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 00076 case V4L2_BUF_TYPE_PRIVATE: 00077 #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE 00078 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 00079 #endif 00080 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE 00081 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 00082 #endif 00083 break; 00084 00085 case V4L2_BUF_TYPE_VBI_CAPTURE: 00086 case V4L2_BUF_TYPE_VBI_OUTPUT: 00087 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 00088 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 00089 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 00090 default: 00091 explain_buffer_einval_vague(sb, "data->type"); 00092 return; 00093 } 00094 00095 /* 00096 * Check the index. 00097 */ 00098 nformats = explain_v4l2_fmtdesc_get_nformats(fildes, arg->type); 00099 if (nformats == 0) 00100 { 00101 /* FIXME: i18n */ 00102 explain_string_buffer_puts 00103 ( 00104 sb, 00105 "no pixel formats of the specified type are available" 00106 ); 00107 return; 00108 } 00109 if (nformats > 0 && arg->index >= (unsigned)nformats) 00110 { 00111 explain_buffer_einval_out_of_range 00112 ( 00113 sb, 00114 "data->index", 00115 0, 00116 nformats - 1 00117 ); 00118 return; 00119 } 00120 return; 00121 } 00122 00123 /* no idea */ 00124 goto generic; 00125 00126 default: 00127 generic: 00128 explain_iocontrol_generic_print_explanation 00129 ( 00130 p, 00131 sb, 00132 errnum, 00133 fildes, 00134 request, 00135 data 00136 ); 00137 break; 00138 } 00139 } 00140 00141 00142 static void 00143 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00144 int errnum, int fildes, int request, const void *data) 00145 { 00146 (void)p; 00147 (void)errnum; 00148 (void)fildes; 00149 (void)request; 00150 explain_buffer_v4l2_fmtdesc(sb, data, 1); 00151 } 00152 00153 00154 const explain_iocontrol_t explain_iocontrol_vidioc_enum_fmt = 00155 { 00156 "VIDIOC_ENUM_FMT", /* name */ 00157 VIDIOC_ENUM_FMT, /* value */ 00158 0, /* disambiguate */ 00159 0, /* print_name */ 00160 print_data, 00161 print_explanation, 00162 print_data_returned, 00163 sizeof(struct v4l2_fmtdesc), /* data_size */ 00164 "struct v4l2_fmtdesc *", /* data_type */ 00165 0, /* flags */ 00166 __FILE__, 00167 __LINE__, 00168 }; 00169 00170 #else /* ndef VIDIOC_ENUM_FMT */ 00171 00172 const explain_iocontrol_t explain_iocontrol_vidioc_enum_fmt = 00173 { 00174 0, /* name */ 00175 0, /* value */ 00176 0, /* disambiguate */ 00177 0, /* print_name */ 00178 0, /* print_data */ 00179 0, /* print_explanation */ 00180 0, /* print_data_returned */ 00181 0, /* data_size */ 00182 0, /* data_type */ 00183 0, /* flags */ 00184 __FILE__, 00185 __LINE__, 00186 }; 00187 00188 #endif /* VIDIOC_ENUM_FMT */ 00189 00190 /* vim: set ts=8 sw=4 et : */