libexplain  1.4.D001
libexplain/buffer/video_tuner.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  *
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/long.h>
00027 #include <libexplain/buffer/pointer.h>
00028 #include <libexplain/buffer/video_tuner.h>
00029 #include <libexplain/buffer/video_tuner_flags.h>
00030 #include <libexplain/buffer/video_tuner_mode.h>
00031 #include <libexplain/is_efault.h>
00032 
00033 
00034 #ifdef VIDIOCGTUNER
00035 
00036 void
00037 explain_buffer_video_tuner(explain_string_buffer_t *sb,
00038     const struct video_tuner *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, "{ tuner = ");
00047     explain_buffer_int(sb, data->tuner);
00048     if (extra)
00049     {
00050         explain_string_buffer_puts(sb, ", name = ");
00051         explain_string_buffer_puts_quoted_n(sb, data->name, sizeof(data->name));
00052         explain_string_buffer_puts(sb, ", rangelow = ");
00053         explain_buffer_ulong(sb, data-> rangelow);
00054         explain_string_buffer_puts(sb, ", rangehigh = ");
00055         explain_buffer_ulong(sb, data-> rangehigh);
00056         explain_string_buffer_puts(sb, ", flags = ");
00057         explain_buffer_video_tuner_flags(sb, data->flags);
00058         explain_string_buffer_puts(sb, ", mode = ");
00059         explain_buffer_video_tuner_mode(sb, data->mode);
00060         explain_string_buffer_puts(sb, ", signal = ");
00061         explain_buffer_uint16_t(sb, data->signal);
00062     }
00063     explain_string_buffer_puts(sb, " }");
00064 }
00065 
00066 
00067 int
00068 explain_video_tuner_get_n(int fildes)
00069 {
00070     int lo = 0;
00071     int hi = 200;
00072     for (;;)
00073     {
00074         int mid = (lo + hi) / 2;
00075         struct video_tuner qry;
00076         memset(&qry, 0, sizeof(qry));
00077         qry.tuner = mid;
00078         if (ioctl(fildes, VIDIOCGTUNER, &qry) >= 0)
00079         {
00080             if (hi <= 0 && lo <= 0)
00081                 return -1;
00082             /* mid < naudios */
00083             lo = mid + 1;
00084             if (lo > hi)
00085                 return lo;
00086         }
00087         else if (errno != EINVAL)
00088         {
00089             return -1;
00090         }
00091         else
00092         {
00093             if (hi <= 0 && lo <= 0)
00094                 return -1;
00095             /* mid >= naudios */
00096             hi = mid - 1;
00097             if (lo >= hi)
00098                 return lo;
00099         }
00100     }
00101 }
00102 
00103 #endif
00104 
00105 /* vim: set ts=8 sw=4 et : */