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/v4l2_audioout.h> 00026 #include <libexplain/buffer/pointer.h> 00027 #include <libexplain/is_efault.h> 00028 #include <libexplain/sizeof.h> 00029 00030 00031 #ifdef HAVE_LINUX_VIDEODEV2_H 00032 00033 void 00034 explain_buffer_v4l2_audioout(explain_string_buffer_t *sb, 00035 const struct v4l2_audioout *data, int extra) 00036 { 00037 if (explain_is_efault_pointer(data, sizeof(*data))) 00038 { 00039 explain_buffer_pointer(sb, data); 00040 return; 00041 } 00042 00043 explain_string_buffer_puts(sb, "{ index = "); 00044 explain_buffer_uint32_t(sb, data->index); 00045 if (extra) 00046 { 00047 explain_string_buffer_puts(sb, ", name = "); 00048 explain_string_buffer_putsu_quoted_n(sb, data->name, 00049 sizeof(data->name)); 00050 if (data->capability) 00051 { 00052 explain_string_buffer_puts(sb, ", capability = "); 00053 explain_buffer_uint32_t(sb, data->capability); 00054 } 00055 if (data->mode) 00056 { 00057 explain_string_buffer_puts(sb, ", mode = "); 00058 explain_buffer_uint32_t(sb, data->mode); 00059 } 00060 if (!explain_uint32_array_all_zero(data->reserved, 00061 SIZEOF(data->reserved))) 00062 { 00063 explain_string_buffer_puts(sb, ", reserved = "); 00064 explain_buffer_uint32_array(sb, data->reserved, 00065 SIZEOF(data->reserved)); 00066 } 00067 } 00068 explain_string_buffer_puts(sb, " }"); 00069 } 00070 00071 00072 void 00073 explain_buffer_v4l2_audioout_index(explain_string_buffer_t *sb, int value, 00074 int fildes) 00075 { 00076 struct v4l2_audioout in; 00077 00078 explain_buffer_uint32_t(sb, value); 00079 00080 memset(&in, 0, sizeof(in)); 00081 in.index = value; 00082 if (ioctl(fildes, VIDIOC_ENUMAUDOUT, &in) >= 0) 00083 { 00084 explain_string_buffer_putc(sb, ' '); 00085 explain_string_buffer_putsu_quoted_n(sb, in.name, sizeof(in.name)); 00086 } 00087 } 00088 00089 00090 void 00091 explain_buffer_v4l2_audioout_index_ptr(explain_string_buffer_t *sb, 00092 const int *data, int fildes) 00093 { 00094 if (explain_is_efault_pointer(data, sizeof(*data))) 00095 { 00096 explain_buffer_pointer(sb, data); 00097 return; 00098 } 00099 00100 explain_string_buffer_puts(sb, "{ "); 00101 explain_buffer_v4l2_audioout_index(sb, *data, fildes); 00102 explain_string_buffer_puts(sb, " }"); 00103 } 00104 00105 00106 int 00107 explain_v4l2_audioout_get_naudioouts(int fildes) 00108 { 00109 int lo = 0; 00110 int hi = 200; 00111 for (;;) 00112 { 00113 int mid = (lo + hi) / 2; 00114 struct v4l2_audioout qry; 00115 memset(&qry, 0, sizeof(qry)); 00116 qry.index = mid; 00117 if (ioctl(fildes, VIDIOC_ENUMAUDOUT, &qry) >= 0) 00118 { 00119 if (hi <= 0 && lo <= 0) 00120 return -1; 00121 /* mid < naudioouts */ 00122 lo = mid + 1; 00123 if (lo > hi) 00124 return lo; 00125 } 00126 else if (errno != EINVAL) 00127 { 00128 return -1; 00129 } 00130 else 00131 { 00132 if (hi <= 0 && lo <= 0) 00133 return -1; 00134 /* mid >= naudioouts */ 00135 hi = mid - 1; 00136 if (lo >= hi) 00137 return lo; 00138 } 00139 } 00140 } 00141 00142 #else 00143 00144 void 00145 explain_buffer_v4l2_audioout(explain_string_buffer_t *sb, 00146 const struct v4l2_audioout *data, int extra) 00147 { 00148 (void)extra; 00149 explain_buffer_pointer(sb, data); 00150 } 00151 00152 00153 void 00154 explain_buffer_v4l2_audioout_index(explain_string_buffer_t *sb, int value, 00155 int fildes) 00156 { 00157 (void)fildes; 00158 } 00159 00160 00161 void 00162 explain_buffer_v4l2_audioout_index_ptr(explain_string_buffer_t *sb, 00163 const int *data, int fildes) 00164 { 00165 (void)fildes; 00166 explain_buffer_pointer(sb, data); 00167 } 00168 00169 00170 int 00171 explain_v4l2_audioout_get_naudioouts(int fildes) 00172 { 00173 return -1; 00174 } 00175 00176 #endif 00177 00178 /* vim: set ts=8 sw=4 et : */