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/int32_t.h> 00025 #include <libexplain/buffer/pointer.h> 00026 #include <libexplain/buffer/v4l2_output.h> 00027 #include <libexplain/buffer/v4l2_output_capabilities.h> 00028 #include <libexplain/buffer/v4l2_output_type.h> 00029 #include <libexplain/buffer/v4l2_std_id.h> 00030 #include <libexplain/is_efault.h> 00031 #include <libexplain/sizeof.h> 00032 00033 00034 #ifdef HAVE_LINUX_VIDEODEV2_H 00035 00036 void 00037 explain_buffer_v4l2_output(explain_string_buffer_t *sb, 00038 const struct v4l2_output *data, int extra) 00039 { 00040 if (explain_is_efault_pointer(data, sizeof(*data))) 00041 { 00042 explain_buffer_pointer(sb, data); 00043 return; 00044 } 00045 00046 explain_string_buffer_puts(sb, "{ index = "); 00047 explain_buffer_uint32_t(sb, data->index); 00048 if (extra) 00049 { 00050 explain_string_buffer_puts(sb, ", name = "); 00051 explain_string_buffer_putsu_quoted_n(sb, data->name, 00052 sizeof(data->name)); 00053 explain_string_buffer_puts(sb, ", type = "); 00054 explain_buffer_v4l2_output_type(sb, data->type); 00055 explain_string_buffer_puts(sb, ", audioset = "); 00056 explain_buffer_uint32_t(sb, data->audioset); /* FIXME: bitset */ 00057 explain_string_buffer_puts(sb, ", modulator = "); 00058 explain_buffer_uint32_t(sb, data->modulator); 00059 explain_string_buffer_puts(sb, ", std = "); 00060 explain_buffer_v4l2_std_id(sb, data->std); 00061 #ifdef V4L2_OUT_CAP_PRESETS 00062 if (data->capabilities) 00063 { 00064 explain_string_buffer_puts(sb, ", capabilities = "); 00065 explain_buffer_v4l2_output_capabilities(sb, data->capabilities); 00066 } 00067 #endif 00068 if (!explain_uint32_array_all_zero(data->reserved, 00069 SIZEOF(data->reserved))) 00070 { 00071 explain_string_buffer_puts(sb, ", reserved = "); 00072 explain_buffer_uint32_array(sb, data->reserved, 00073 SIZEOF(data->reserved)); 00074 } 00075 } 00076 explain_string_buffer_puts(sb, " }"); 00077 } 00078 00079 00080 void 00081 explain_buffer_v4l2_output_index(explain_string_buffer_t *sb, int value, 00082 int fildes) 00083 { 00084 struct v4l2_output in; 00085 00086 explain_buffer_uint32_t(sb, value); 00087 00088 memset(&in, 0, sizeof(in)); 00089 in.index = value; 00090 if (ioctl(fildes, VIDIOC_ENUMOUTPUT, &in) >= 0) 00091 { 00092 explain_string_buffer_putc(sb, ' '); 00093 explain_string_buffer_putsu_quoted_n(sb, in.name, sizeof(in.name)); 00094 } 00095 } 00096 00097 00098 void 00099 explain_buffer_v4l2_output_index_ptr(explain_string_buffer_t *sb, 00100 const int *data, int fildes) 00101 { 00102 if (explain_is_efault_pointer(data, sizeof(*data))) 00103 { 00104 explain_buffer_pointer(sb, data); 00105 return; 00106 } 00107 00108 explain_string_buffer_puts(sb, "{ "); 00109 explain_buffer_v4l2_output_index(sb, *data, fildes); 00110 explain_string_buffer_puts(sb, " }"); 00111 } 00112 00113 00114 int 00115 explain_v4l2_output_get_noutputs(int fildes) 00116 { 00117 int lo = 0; 00118 int hi = 200; 00119 for (;;) 00120 { 00121 int mid = (lo + hi) / 2; 00122 struct v4l2_output qry; 00123 memset(&qry, 0, sizeof(qry)); 00124 qry.index = mid; 00125 if (ioctl(fildes, VIDIOC_ENUMOUTPUT, &qry) >= 0) 00126 { 00127 if (hi <= 0 && lo <= 0) 00128 return -1; 00129 /* mid < noutputs */ 00130 lo = mid + 1; 00131 if (lo > hi) 00132 return lo; 00133 } 00134 else if (errno != EINVAL) 00135 { 00136 return -1; 00137 } 00138 else 00139 { 00140 if (hi <= 0 && lo <= 0) 00141 return -1; 00142 /* mid >= noutputs */ 00143 hi = mid - 1; 00144 if (lo >= hi) 00145 return lo; 00146 } 00147 } 00148 } 00149 00150 #endif 00151 00152 /* vim: set ts=8 sw=4 et : */