1 /*****************************************************************************
2 * radio.c : V4L2 analog radio receiver
3 *****************************************************************************
4 * Copyright (C) 2012 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_demux.h>
36 vlc_v4l2_ctrl_t *controls;
40 static int RadioControl (demux_t *demux, int query, va_list args)
42 demux_sys_t *sys = demux->p_sys;
48 case DEMUX_CAN_CONTROL_PACE:
49 *va_arg (args, bool *) = false;
52 case DEMUX_GET_PTS_DELAY:
53 *va_arg (args,int64_t *) = INT64_C(1000)
54 * var_InheritInteger (demux, "live-caching");
58 *va_arg (args, int64_t *) = mdate () - sys->start;
61 /* TODO implement others */
68 int RadioOpen (vlc_object_t *obj)
70 demux_t *demux = (demux_t *)obj;
73 size_t pathlen = strcspn (demux->psz_location, ":;");
74 char *path = (pathlen != 0) ? strndup (demux->psz_location, pathlen)
75 : var_InheritString (obj, CFG_PREFIX"radio-dev");
76 if (unlikely(path == NULL))
78 if (demux->psz_location[pathlen] != '\0')
79 var_LocationParse (obj, demux->psz_location + pathlen + 1, CFG_PREFIX);
83 int fd = OpenDevice (obj, path, &caps);
87 if (!(caps & V4L2_CAP_TUNER))
89 msg_Err (obj, "not a radio tuner device");
93 if (SetupTuner (obj, fd, 0))
96 demux_sys_t *sys = malloc (sizeof (*sys));
97 if (unlikely(sys == NULL))
101 sys->controls = ControlsInit (VLC_OBJECT(demux), fd);
102 sys->start = mdate ();
105 demux->pf_demux = NULL;
106 demux->pf_control = RadioControl;
107 demux->info.i_update = 0;
108 demux->info.i_title = 0;
109 demux->info.i_seekpoint = 0;
117 void RadioClose (vlc_object_t *obj)
119 demux_t *demux = (demux_t *)obj;
120 demux_sys_t *sys = demux->p_sys;
122 ControlsDeinit (obj, sys->controls);
123 v4l2_close (sys->fd);