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/enosys.h> 00026 #include <libexplain/buffer/is_the_null_pointer.h> 00027 #include <libexplain/buffer/v4l2_jpegcompression.h> 00028 #include <libexplain/iocontrol/generic.h> 00029 #include <libexplain/iocontrol/vidioc_s_jpegcomp.h> 00030 #include <libexplain/is_efault.h> 00031 00032 #ifdef VIDIOC_S_JPEGCOMP 00033 00034 00035 static void 00036 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00037 int errnum, int fildes, int request, const void *data) 00038 { 00039 (void)p; 00040 (void)errnum; 00041 (void)fildes; 00042 (void)request; 00043 explain_buffer_v4l2_jpegcompression(sb, data); 00044 } 00045 00046 00047 static void 00048 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, 00049 int errnum, int fildes, int request, const void *data) 00050 { 00051 switch (errnum) 00052 { 00053 case EINVAL: 00054 if (!data) 00055 { 00056 explain_buffer_is_the_null_pointer(sb, "data"); 00057 return; 00058 } 00059 00060 { 00061 struct v4l2_jpegcompression qry; 00062 00063 /* 00064 * First, check that JPEG compression support is actually present. 00065 * 00066 * It is possible that VIDIOC_G_JPEGCOMP is supported but 00067 * VIDIOC_S_JPEGCOMP is not, but none of the drivers I looked 00068 * at were asymetric in this way. 00069 */ 00070 if (ioctl(fildes, VIDIOC_G_JPEGCOMP, &qry) < 0 && errno == EINVAL) 00071 { 00072 explain_buffer_enosys_fildes 00073 ( 00074 sb, 00075 fildes, 00076 "fildes", 00077 "ioctl VIDIOC_S_JPEGCOMP" 00078 ); 00079 return; 00080 } 00081 } 00082 00083 { 00084 const struct v4l2_jpegcompression *arg; 00085 00086 arg = data; 00087 if (!explain_is_efault_pointer(arg, sizeof(*arg))) 00088 { 00089 if (arg->quality < 0 || arg->quality > 100) 00090 { 00091 /* Some drivers are fussier than this. */ 00092 explain_buffer_einval_out_of_range 00093 ( 00094 sb, 00095 "data->quality", 00096 0, 00097 100 00098 ); 00099 return; 00100 } 00101 00102 if (arg->APPn < 0 || arg->APPn > 15) 00103 { 00104 explain_buffer_einval_out_of_range(sb, "data->APPn", 0, 15); 00105 return; 00106 } 00107 00108 if 00109 ( 00110 arg->APP_len < 0 00111 || 00112 arg->APP_len > (int)sizeof(arg->APP_data) 00113 ) 00114 { 00115 explain_buffer_einval_out_of_range 00116 ( 00117 sb, 00118 "data->APP_len", 00119 0, 00120 sizeof(arg->APP_data) 00121 ); 00122 return; 00123 } 00124 00125 if 00126 ( 00127 arg->COM_len < 0 00128 || 00129 arg->COM_len > (int)sizeof(arg->COM_data) 00130 ) 00131 { 00132 explain_buffer_einval_out_of_range 00133 ( 00134 sb, 00135 "data->COM_len", 00136 0, 00137 sizeof(arg->COM_data) 00138 ); 00139 return; 00140 } 00141 } 00142 } 00143 00144 /* Nothing obvious */ 00145 explain_buffer_einval_vague(sb, "data"); 00146 break; 00147 00148 default: 00149 explain_iocontrol_generic_print_explanation 00150 ( 00151 p, 00152 sb, 00153 errnum, 00154 fildes, 00155 request, 00156 data 00157 ); 00158 break; 00159 } 00160 } 00161 00162 00163 const explain_iocontrol_t explain_iocontrol_vidioc_s_jpegcomp = 00164 { 00165 "VIDIOC_S_JPEGCOMP", /* name */ 00166 VIDIOC_S_JPEGCOMP, /* value */ 00167 0, /* disambiguate */ 00168 0, /* print_name */ 00169 print_data, 00170 print_explanation, 00171 0, /* print_data_returned */ 00172 sizeof(struct v4l2_jpegcompression), /* data_size */ 00173 "struct v4l2_jpegcompression *", /* data_type */ 00174 0, /* flags */ 00175 __FILE__, 00176 __LINE__, 00177 }; 00178 00179 #else /* ndef VIDIOC_S_JPEGCOMP */ 00180 00181 const explain_iocontrol_t explain_iocontrol_vidioc_s_jpegcomp = 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_JPEGCOMP */ 00198 00199 /* vim: set ts=8 sw=4 et : */