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/videodev.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/int16_t.h> 00026 #include <libexplain/buffer/video_audio.h> 00027 #include <libexplain/buffer/video_audio_flags.h> 00028 #include <libexplain/buffer/video_audio_mode.h> 00029 #include <libexplain/buffer/pointer.h> 00030 #include <libexplain/is_efault.h> 00031 00032 00033 #ifdef VIDIOCGAUDIO 00034 00035 void 00036 explain_buffer_video_audio(explain_string_buffer_t *sb, 00037 const struct video_audio *data, int extra) 00038 { 00039 if (explain_is_efault_pointer(data, sizeof(*data))) 00040 { 00041 explain_buffer_pointer(sb, data); 00042 return; 00043 } 00044 00045 explain_string_buffer_puts(sb, "{ audio = "); 00046 explain_buffer_int(sb, data->audio); 00047 if (extra) 00048 { 00049 if (data->flags & VIDEO_AUDIO_VOLUME) 00050 { 00051 explain_string_buffer_puts(sb, ", volume = "); 00052 explain_buffer_uint16_t(sb, data->volume); 00053 } 00054 if (data->flags & VIDEO_AUDIO_BASS) 00055 { 00056 explain_string_buffer_puts(sb, ", bass = "); 00057 explain_buffer_uint16_t(sb, data->bass); 00058 } 00059 if (data->flags & VIDEO_AUDIO_TREBLE) 00060 { 00061 explain_string_buffer_puts(sb, ", trebble = "); 00062 explain_buffer_uint16_t(sb, data->treble); 00063 } 00064 explain_string_buffer_puts(sb, ", flags = "); 00065 explain_buffer_video_audio_flags(sb, data->flags); 00066 explain_string_buffer_puts(sb, ", name = "); 00067 explain_string_buffer_puts_quoted_n(sb, data->name, sizeof(data->name)); 00068 explain_string_buffer_puts(sb, ", mode = "); 00069 explain_buffer_video_audio_mode(sb, data->mode); 00070 if (data->flags & VIDEO_AUDIO_BALANCE) 00071 { 00072 explain_string_buffer_puts(sb, ", balance = "); 00073 explain_buffer_uint16_t(sb, data->balance); 00074 } 00075 if (data->flags & VIDEO_AUDIO_VOLUME) 00076 { 00077 explain_string_buffer_puts(sb, ", step = "); 00078 explain_buffer_uint16_t(sb, data->step); 00079 } 00080 } 00081 explain_string_buffer_puts(sb, " }"); 00082 } 00083 00084 00085 int 00086 explain_video_audio_get_n(int fildes) 00087 { 00088 int lo = 0; 00089 int hi = 200; 00090 for (;;) 00091 { 00092 int mid = (lo + hi) / 2; 00093 struct video_audio qry; 00094 memset(&qry, 0, sizeof(qry)); 00095 qry.audio = mid; 00096 if (ioctl(fildes, VIDIOCGAUDIO, &qry) >= 0) 00097 { 00098 if (hi <= 0 && lo <= 0) 00099 return -1; 00100 /* mid < naudios */ 00101 lo = mid + 1; 00102 if (lo > hi) 00103 return lo; 00104 } 00105 else if (errno != EINVAL) 00106 { 00107 return -1; 00108 } 00109 else 00110 { 00111 if (hi <= 0 && lo <= 0) 00112 return -1; 00113 /* mid >= naudios */ 00114 hi = mid - 1; 00115 if (lo >= hi) 00116 return lo; 00117 } 00118 } 00119 } 00120 00121 #endif 00122 00123 /* vim: set ts=8 sw=4 et : */