libexplain  1.4.D001
libexplain/iocontrol/vidioc_encoder_cmd.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/string.h>
00023 #include <libexplain/ac/sys/ioctl.h>
00024 
00025 #include <libexplain/buffer/einval.h>
00026 #include <libexplain/buffer/enotsup.h>
00027 #include <libexplain/buffer/is_the_null_pointer.h>
00028 #include <libexplain/buffer/v4l2_encoder_cmd.h>
00029 #include <libexplain/iocontrol/generic.h>
00030 #include <libexplain/iocontrol/vidioc_encoder_cmd.h>
00031 #include <libexplain/is_efault.h>
00032 
00033 #ifdef VIDIOC_ENCODER_CMD
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_encoder_cmd(sb, data);
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_encoder_cmd *arg;
00063 
00064             arg = data;
00065             if (!explain_is_efault_pointer(arg, sizeof(*arg)))
00066             {
00067                 switch (arg->cmd)
00068                 {
00069                 case V4L2_ENC_CMD_START:
00070                 case V4L2_ENC_CMD_STOP:
00071                     /*
00072                      * All drivers that support this ioctl support these
00073                      * two commands.  So if the command isn't supported,
00074                      * probably the whole ioctl isn't supported.
00075                      */
00076                     enotty:
00077                     explain_iocontrol_generic_print_explanation
00078                     (
00079                         p,
00080                         sb,
00081                         ENOTTY,
00082                         fildes,
00083                         request,
00084                         data
00085                     );
00086                     return;
00087 
00088                 case V4L2_ENC_CMD_PAUSE:
00089                 case V4L2_ENC_CMD_RESUME:
00090                     {
00091                         struct v4l2_encoder_cmd qry;
00092 
00093                         memset(&qry, 0, sizeof(qry));
00094                         qry.cmd = V4L2_ENC_CMD_STOP;
00095                         if
00096                         (
00097                             ioctl(fildes, VIDIOC_TRY_ENCODER_CMD, &qry) < 0
00098                         &&
00099                             errno == EINVAL
00100                         )
00101                             goto enotty;
00102                     }
00103 
00104                     explain_buffer_enotsup_device(sb, "data->cmd");
00105                     break;
00106 
00107                 default:
00108                     explain_buffer_einval_vague(sb, "data->cmd");
00109                     return;
00110                 }
00111             }
00112         }
00113 
00114         explain_buffer_einval_vague(sb, "data");
00115         break;
00116 
00117     default:
00118         explain_iocontrol_generic_print_explanation
00119         (
00120             p,
00121             sb,
00122             errnum,
00123             fildes,
00124             request,
00125             data
00126         );
00127         break;
00128     }
00129 }
00130 
00131 
00132 static void
00133 print_data_returned(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00134     int errnum, int fildes, int request, const void *data)
00135 {
00136     (void)p;
00137     (void)errnum;
00138     (void)fildes;
00139     (void)request;
00140     explain_buffer_v4l2_encoder_cmd(sb, data);
00141 }
00142 
00143 
00144 const explain_iocontrol_t explain_iocontrol_vidioc_encoder_cmd =
00145 {
00146     "VIDIOC_ENCODER_CMD", /* name */
00147     VIDIOC_ENCODER_CMD, /* value */
00148     0, /* disambiguate */
00149     0, /* print_name */
00150     print_data,
00151     print_explanation,
00152     print_data_returned,
00153     sizeof(struct v4l2_encoder_cmd), /* data_size */
00154     "struct v4l2_encoder_cmd *", /* data_type */
00155     0, /* flags */
00156     __FILE__,
00157     __LINE__,
00158 };
00159 
00160 const explain_iocontrol_t explain_iocontrol_vidioc_try_encoder_cmd =
00161 {
00162     "VIDIOC_TRY_ENCODER_CMD", /* name */
00163     VIDIOC_TRY_ENCODER_CMD, /* value */
00164     0, /* disambiguate */
00165     0, /* print_name */
00166     print_data,
00167     print_explanation,
00168     print_data_returned,
00169     sizeof(struct v4l2_encoder_cmd), /* data_size */
00170     "struct v4l2_encoder_cmd *", /* data_type */
00171     0, /* flags */
00172     __FILE__,
00173     __LINE__,
00174 };
00175 
00176 #else /* ndef VIDIOC_ENCODER_CMD */
00177 
00178 const explain_iocontrol_t explain_iocontrol_vidioc_encoder_cmd =
00179 {
00180     0, /* name */
00181     0, /* value */
00182     0, /* disambiguate */
00183     0, /* print_name */
00184     0, /* print_data */
00185     0, /* print_explanation */
00186     0, /* print_data_returned */
00187     0, /* data_size */
00188     0, /* data_type */
00189     0, /* flags */
00190     __FILE__,
00191     __LINE__,
00192 };
00193 
00194 const explain_iocontrol_t explain_iocontrol_vidioc_try_encoder_cmd =
00195 {
00196     0, /* name */
00197     0, /* value */
00198     0, /* disambiguate */
00199     0, /* print_name */
00200     0, /* print_data */
00201     0, /* print_explanation */
00202     0, /* print_data_returned */
00203     0, /* data_size */
00204     0, /* data_type */
00205     0, /* flags */
00206     __FILE__,
00207     __LINE__,
00208 };
00209 
00210 #endif /* VIDIOC_ENCODER_CMD */
00211 
00212 /* vim: set ts=8 sw=4 et : */