libexplain  1.4.D001
libexplain/iocontrol/vidiocmcapture.c
Go to the documentation of this file.
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/videodev.h>
00022 #include <libexplain/ac/sys/ioctl.h>
00023 
00024 #include <libexplain/buffer/einval.h>
00025 #include <libexplain/buffer/is_the_null_pointer.h>
00026 #include <libexplain/buffer/video_mmap.h>
00027 #include <libexplain/iocontrol/generic.h>
00028 #include <libexplain/iocontrol/vidiocmcapture.h>
00029 #include <libexplain/is_efault.h>
00030 
00031 #ifdef VIDIOCMCAPTURE
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_video_mmap(sb, data);
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 video_mmap *arg;
00061 
00062             arg = data;
00063             if (!explain_is_efault_pointer(arg, sizeof(*arg)))
00064             {
00065                 struct video_capability cap;
00066 
00067                 /*
00068                  * Size could be wrong.
00069                  */
00070                 if (ioctl(fildes, VIDIOCGCAP, &cap) >= 0)
00071                 {
00072                     if (arg->width < cap.minwidth || arg->width > cap.maxwidth)
00073                     {
00074                         explain_buffer_einval_out_of_range
00075                         (
00076                             sb,
00077                             "data->width",
00078                             cap.minwidth,
00079                             cap.maxwidth
00080                         );
00081                         return;
00082                     }
00083                     if
00084                     (
00085                         arg->height < cap.minheight
00086                     ||
00087                         arg->height > cap.maxheight
00088                     )
00089                     {
00090                         explain_buffer_einval_out_of_range
00091                         (
00092                             sb,
00093                             "data->height",
00094                             cap.minheight,
00095                             cap.maxheight
00096                         );
00097                         return;
00098                     }
00099                 }
00100 
00101                 /* FIXME: format could be wrong */
00102 
00103                 /*
00104                  * Frame number could be wrong.
00105                  */
00106                 {
00107                     struct video_mbuf qry;
00108 
00109                     if
00110                     (
00111                         ioctl(fildes, VIDIOCGMBUF, &qry) >= 0
00112                     &&
00113                         qry.frames > 0
00114                     &&
00115                         (unsigned)arg->frame >= (unsigned)qry.frames
00116                     )
00117                     {
00118                         explain_buffer_einval_out_of_range
00119                         (
00120                             sb,
00121                             "data->frame",
00122                             0,
00123                             qry.frames
00124                         );
00125                         return;
00126                     }
00127                 }
00128             }
00129         }
00130 
00131         /* No idea */
00132         explain_buffer_einval_vague(sb, "data");
00133         break;
00134 
00135     default:
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 const explain_iocontrol_t explain_iocontrol_vidiocmcapture =
00151 {
00152     "VIDIOCMCAPTURE", /* name */
00153     VIDIOCMCAPTURE, /* value */
00154     0, /* disambiguate */
00155     0, /* print_name */
00156     print_data,
00157     print_explanation,
00158     0, /* print_data_returned */
00159     sizeof(struct video_mmap), /* data_size */
00160     "struct video_mmap *", /* data_type */
00161     0, /* flags */
00162     __FILE__,
00163     __LINE__,
00164 };
00165 
00166 #else /* ndef VIDIOCMCAPTURE */
00167 
00168 const explain_iocontrol_t explain_iocontrol_vidiocmcapture =
00169 {
00170     0, /* name */
00171     0, /* value */
00172     0, /* disambiguate */
00173     0, /* print_name */
00174     0, /* print_data */
00175     0, /* print_explanation */
00176     0, /* print_data_returned */
00177     0, /* data_size */
00178     0, /* data_type */
00179     0, /* flags */
00180     __FILE__,
00181     __LINE__,
00182 };
00183 
00184 #endif /* VIDIOCMCAPTURE */
00185 
00186 /* vim: set ts=8 sw=4 et : */