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/is_the_null_pointer.h> 00027 #include <libexplain/buffer/v4l2_frmivalenum.h> 00028 #include <libexplain/buffer/v4l2_pixel_format.h> 00029 #include <libexplain/iocontrol/generic.h> 00030 #include <libexplain/iocontrol/vidioc_enum_frameintervals.h> 00031 #include <libexplain/is_efault.h> 00032 00033 #ifdef VIDIOC_ENUM_FRAMEINTERVALS 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_frmivalenum(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_frmivalenum *arg; 00063 int nsizes; 00064 struct v4l2_format qf; 00065 00066 arg = data; 00067 if (explain_is_efault_pointer(arg, sizeof(*arg))) 00068 goto generic; 00069 00070 /* 00071 * the index could be out of range 00072 */ 00073 nsizes = explain_v4l2_frmivalenum_get_n(fildes, arg->pixel_format); 00074 if (nsizes > 0 && arg->index >= (unsigned)nsizes) 00075 { 00076 explain_buffer_einval_out_of_range 00077 ( 00078 sb, 00079 "data->index", 00080 0, 00081 nsizes - 1 00082 ); 00083 return; 00084 } 00085 00086 /* 00087 * the pixel format could be wrong 00088 */ 00089 memset(&qf, 0, sizeof(qf)); 00090 if 00091 ( 00092 ioctl(fildes, VIDIOC_G_FMT, &qf) >= 0 00093 && 00094 qf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE 00095 && 00096 arg->pixel_format != qf.fmt.pix.pixelformat 00097 ) 00098 { 00099 explain_buffer_einval_vague(sb, "data->pixel_format"); 00100 00101 explain_string_buffer_puts(sb->footnotes, "; "); 00102 /* FIXME: i18n */ 00103 explain_string_buffer_puts 00104 ( 00105 sb->footnotes, 00106 "the current pixel format is " 00107 ); 00108 explain_buffer_v4l2_pixel_format(sb, qf.fmt.pix.pixelformat); 00109 return; 00110 } 00111 } 00112 00113 /* No idea */ 00114 explain_buffer_einval_vague(sb, "data"); 00115 return; 00116 00117 default: 00118 generic: 00119 explain_iocontrol_generic_print_explanation 00120 ( 00121 p, 00122 sb, 00123 errnum, 00124 fildes, 00125 request, 00126 data 00127 ); 00128 break; 00129 } 00130 } 00131 00132 00133 static void 00134 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00135 int errnum, int fildes, int request, const void *data) 00136 { 00137 (void)p; 00138 (void)errnum; 00139 (void)fildes; 00140 (void)request; 00141 explain_buffer_v4l2_frmivalenum(sb, data, 1); 00142 } 00143 00144 00145 const explain_iocontrol_t explain_iocontrol_vidioc_enum_frameintervals = 00146 { 00147 "VIDIOC_ENUM_FRAMEINTERVALS", /* name */ 00148 VIDIOC_ENUM_FRAMEINTERVALS, /* value */ 00149 0, /* disambiguate */ 00150 0, /* print_name */ 00151 print_data, 00152 print_explanation, 00153 print_data_returned, 00154 sizeof(struct v4l2_frmivalenum), /* data_size */ 00155 "struct v4l2_frmivalenum *", /* data_type */ 00156 0, /* flags */ 00157 __FILE__, 00158 __LINE__, 00159 }; 00160 00161 #else /* ndef VIDIOC_ENUM_FRAMEINTERVALS */ 00162 00163 const explain_iocontrol_t explain_iocontrol_vidioc_enum_frameintervals = 00164 { 00165 0, /* name */ 00166 0, /* value */ 00167 0, /* disambiguate */ 00168 0, /* print_name */ 00169 0, /* print_data */ 00170 0, /* print_explanation */ 00171 0, /* print_data_returned */ 00172 0, /* data_size */ 00173 0, /* data_type */ 00174 0, /* flags */ 00175 __FILE__, 00176 __LINE__, 00177 }; 00178 00179 #endif /* VIDIOC_ENUM_FRAMEINTERVALS */ 00180 00181 /* vim: set ts=8 sw=4 et : */