live555: remove trailing whitespace
[vlc.git] / modules / access / v4l2 / radio.c
blobbc458f71b991ed47472dff763de3665386090f04
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 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <fcntl.h>
27 #include <vlc_common.h>
28 #include <vlc_demux.h>
29 #include <vlc_fs.h>
31 #include "v4l2.h"
33 typedef struct
35 int fd;
36 vlc_v4l2_ctrl_t *controls;
37 mtime_t start;
38 } demux_sys_t;
40 static int RadioControl (demux_t *demux, int query, va_list args)
42 demux_sys_t *sys = demux->p_sys;
44 switch (query)
46 case DEMUX_CAN_PAUSE:
47 case DEMUX_CAN_SEEK:
48 case DEMUX_CAN_CONTROL_PACE:
49 *va_arg (args, bool *) = false;
50 break;
52 case DEMUX_GET_PTS_DELAY:
53 *va_arg (args,int64_t *) = INT64_C(1000)
54 * var_InheritInteger (demux, "live-caching");
55 break;
57 case DEMUX_GET_TIME:
58 *va_arg (args, int64_t *) = mdate () - sys->start;
59 break;
61 /* TODO implement others */
62 default:
63 return VLC_EGENERIC;
65 return VLC_SUCCESS;
68 int RadioOpen (vlc_object_t *obj)
70 demux_t *demux = (demux_t *)obj;
71 if (demux->out == NULL)
72 return VLC_EGENERIC;
74 /* Parse MRL */
75 size_t pathlen = strcspn (demux->psz_location, ":;");
76 char *path = (pathlen != 0) ? strndup (demux->psz_location, pathlen)
77 : var_InheritString (obj, CFG_PREFIX"radio-dev");
78 if (unlikely(path == NULL))
79 return VLC_ENOMEM;
80 if (demux->psz_location[pathlen] != '\0')
81 var_LocationParse (obj, demux->psz_location + pathlen + 1, CFG_PREFIX);
83 /* Open device */
84 uint32_t caps;
85 int fd = OpenDevice (obj, path, &caps);
86 free (path);
87 if (fd == -1)
88 return VLC_EGENERIC;
89 if (!(caps & V4L2_CAP_TUNER))
91 msg_Err (obj, "not a radio tuner device");
92 goto error;
95 if (SetupTuner (obj, fd, 0))
96 goto error;
98 demux_sys_t *sys = malloc (sizeof (*sys));
99 if (unlikely(sys == NULL))
100 goto error;
102 sys->fd = fd;
103 sys->controls = ControlsInit (VLC_OBJECT(demux), fd);
104 sys->start = mdate ();
106 demux->p_sys = sys;
107 demux->pf_demux = NULL;
108 demux->pf_control = RadioControl;
109 return VLC_SUCCESS;
111 error:
112 v4l2_close (fd);
113 return VLC_EGENERIC;
116 void RadioClose (vlc_object_t *obj)
118 demux_t *demux = (demux_t *)obj;
119 demux_sys_t *sys = demux->p_sys;
121 ControlsDeinit (obj, sys->controls);
122 v4l2_close (sys->fd);
123 free (sys);