libexplain  1.4.D001
libexplain/iocontrol/vidioc_s_fmt.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/videodev2.h>
00022 #include <libexplain/ac/sys/ioctl.h>
00023 
00024 #include <libexplain/buffer/einval.h>
00025 #include <libexplain/buffer/enotsup.h>
00026 #include <libexplain/buffer/is_the_null_pointer.h>
00027 #include <libexplain/buffer/v4l2_format.h>
00028 #include <libexplain/iocontrol/generic.h>
00029 #include <libexplain/iocontrol/vidioc_s_fmt.h>
00030 #include <libexplain/is_efault.h>
00031 
00032 #ifdef VIDIOC_S_FMT
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_format(sb, data, 1);
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     /*
00052      * Note: Linux:
00053      * drivers/media/video/sh_vou.c can return EIO when it means EINVAL
00054      * when fmt == V4L2_BUF_TYPE_VIDEO_OUTPUT
00055      */
00056     switch (errnum)
00057     {
00058     case EINVAL:
00059         if (!data)
00060         {
00061             explain_buffer_is_the_null_pointer(sb, "data");
00062             return;
00063         }
00064 
00065         switch (explain_v4l2_format_check_type(fildes, data))
00066         {
00067         case explain_v4l2_format_check_type_no_idea:
00068         default:
00069             goto generic;
00070 
00071         case explain_v4l2_format_check_type_notsup:
00072             explain_buffer_enotsup_device(sb, "data->type");
00073             break;
00074 
00075         case explain_v4l2_format_check_type_nosuch:
00076             explain_buffer_einval_vague(sb, "data->type");
00077             break;;
00078 
00079         case explain_v4l2_format_check_type_ok:
00080             explain_buffer_einval_vague(sb, "data");
00081             break;
00082         }
00083         break;
00084 
00085     default:
00086         generic:
00087         explain_iocontrol_generic_print_explanation
00088         (
00089             p,
00090             sb,
00091             errnum,
00092             fildes,
00093             request,
00094             data
00095         );
00096         break;
00097     }
00098 }
00099 
00100 
00101 static void
00102 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00103     int errnum, int fildes, int request, const void *data)
00104 {
00105     (void)p;
00106     (void)errnum;
00107     (void)fildes;
00108     (void)request;
00109     explain_buffer_v4l2_format(sb, data, 1);
00110 }
00111 
00112 
00113 const explain_iocontrol_t explain_iocontrol_vidioc_s_fmt =
00114 {
00115     "VIDIOC_S_FMT", /* name */
00116     VIDIOC_S_FMT, /* value */
00117     0, /* disambiguate */
00118     0, /* print_name */
00119     print_data,
00120     print_explanation,
00121     print_data_returned,
00122     sizeof(struct v4l2_format), /* data_size */
00123     "struct v4l2_format *", /* data_type */
00124     0, /* flags */
00125     __FILE__,
00126     __LINE__,
00127 };
00128 
00129 #else /* ndef VIDIOC_S_FMT */
00130 
00131 const explain_iocontrol_t explain_iocontrol_vidioc_s_fmt =
00132 {
00133     0, /* name */
00134     0, /* value */
00135     0, /* disambiguate */
00136     0, /* print_name */
00137     0, /* print_data */
00138     0, /* print_explanation */
00139     0, /* print_data_returned */
00140     0, /* data_size */
00141     0, /* data_type */
00142     0, /* flags */
00143     __FILE__,
00144     __LINE__,
00145 };
00146 
00147 #endif /* VIDIOC_S_FMT */
00148 
00149 /* vim: set ts=8 sw=4 et : */