libexplain
1.4.D001
|
00001 /* 00002 * libexplain - a library of system-call-specific strerror replacements 00003 * Copyright (C) 2011, 2013 Peter Miller 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as 00007 * published by the Free Software Foundation; either version 3 of the 00008 * License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <libexplain/ac/errno.h> 00020 #include <libexplain/ac/linux/videodev2.h> 00021 #include <libexplain/ac/string.h> 00022 #include <libexplain/ac/sys/ioctl.h> 00023 00024 #include <libexplain/buffer/int.h> 00025 #include <libexplain/buffer/pointer.h> 00026 #include <libexplain/buffer/v4l2_buf_type.h> 00027 #include <libexplain/parse_bits.h> 00028 #include <libexplain/is_efault.h> 00029 00030 00031 #ifdef HAVE_LINUX_VIDEODEV2_H 00032 00033 void 00034 explain_buffer_v4l2_buf_type(explain_string_buffer_t *sb, int value) 00035 { 00036 static const explain_parse_bits_table_t table[] = 00037 { 00038 { "V4L2_BUF_TYPE_VIDEO_CAPTURE", V4L2_BUF_TYPE_VIDEO_CAPTURE }, 00039 { "V4L2_BUF_TYPE_VIDEO_OUTPUT", V4L2_BUF_TYPE_VIDEO_OUTPUT }, 00040 { "V4L2_BUF_TYPE_VIDEO_OVERLAY", V4L2_BUF_TYPE_VIDEO_OVERLAY }, 00041 { "V4L2_BUF_TYPE_VBI_CAPTURE", V4L2_BUF_TYPE_VBI_CAPTURE }, 00042 { "V4L2_BUF_TYPE_VBI_OUTPUT", V4L2_BUF_TYPE_VBI_OUTPUT }, 00043 { "V4L2_BUF_TYPE_SLICED_VBI_CAPTURE", 00044 V4L2_BUF_TYPE_SLICED_VBI_CAPTURE }, 00045 { "V4L2_BUF_TYPE_SLICED_VBI_OUTPUT", V4L2_BUF_TYPE_SLICED_VBI_OUTPUT }, 00046 { "V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY", 00047 V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY }, 00048 #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE 00049 { "V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE", 00050 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE }, 00051 #endif 00052 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE 00053 { "V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE", 00054 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE }, 00055 #endif 00056 { "V4L2_BUF_TYPE_PRIVATE", V4L2_BUF_TYPE_PRIVATE }, 00057 }; 00058 explain_parse_bits_print_single(sb, value, table, SIZEOF(table)); 00059 } 00060 00061 00062 void 00063 explain_buffer_v4l2_buf_type_ptr(explain_string_buffer_t *sb, const int *value) 00064 { 00065 if (explain_is_efault_pointer(value, sizeof(*value))) 00066 { 00067 explain_buffer_pointer(sb, value); 00068 } 00069 else 00070 { 00071 explain_string_buffer_puts(sb, "{ "); 00072 explain_buffer_v4l2_buf_type(sb, *value); 00073 explain_string_buffer_puts(sb, " }"); 00074 } 00075 } 00076 00077 00078 enum explain_v4l2_buf_type_check_t 00079 explain_v4l2_buf_type_check(int fildes, int data) 00080 { 00081 struct v4l2_format dummy; 00082 00083 memset(&dummy, 0, sizeof(dummy)); 00084 dummy.type = data; 00085 if (ioctl(fildes, VIDIOC_G_FMT, &dummy) >= 0) 00086 return explain_v4l2_buf_type_check_ok; 00087 switch (errno) 00088 { 00089 case EINVAL: 00090 switch ((enum v4l2_buf_type)data) 00091 { 00092 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 00093 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 00094 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 00095 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 00096 case V4L2_BUF_TYPE_VBI_CAPTURE: 00097 case V4L2_BUF_TYPE_VBI_OUTPUT: 00098 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 00099 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 00100 case V4L2_BUF_TYPE_PRIVATE: 00101 #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE 00102 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 00103 #endif 00104 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE 00105 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 00106 #endif 00107 return explain_v4l2_buf_type_check_notsup; 00108 00109 default: 00110 return explain_v4l2_buf_type_check_nosuch; 00111 } 00112 00113 default: 00114 switch ((enum v4l2_buf_type)data) 00115 { 00116 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 00117 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 00118 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 00119 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 00120 case V4L2_BUF_TYPE_VBI_CAPTURE: 00121 case V4L2_BUF_TYPE_VBI_OUTPUT: 00122 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 00123 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 00124 case V4L2_BUF_TYPE_PRIVATE: 00125 #ifdef V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE 00126 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 00127 #endif 00128 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE 00129 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 00130 #endif 00131 return explain_v4l2_buf_type_check_no_idea; 00132 00133 default: 00134 return explain_v4l2_buf_type_check_nosuch; 00135 } 00136 break; 00137 } 00138 } 00139 00140 00141 enum explain_v4l2_buf_type_check_t 00142 explain_v4l2_buf_type_ptr_check(int fildes, const int *data) 00143 { 00144 if (explain_is_efault_pointer(data, sizeof(*data))) 00145 return explain_v4l2_buf_type_check_no_idea; 00146 return explain_v4l2_buf_type_check(fildes, *data); 00147 } 00148 00149 #endif 00150 00151 00152 /* vim: set ts=8 sw=4 et : */