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
;
71 if (demux
->out
== NULL
)
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
))
80 if (demux
->psz_location
[pathlen
] != '\0')
81 var_LocationParse (obj
, demux
->psz_location
+ pathlen
+ 1, CFG_PREFIX
);
85 int fd
= OpenDevice (obj
, path
, &caps
);
89 if (!(caps
& V4L2_CAP_TUNER
))
91 msg_Err (obj
, "not a radio tuner device");
95 if (SetupTuner (obj
, fd
, 0))
98 demux_sys_t
*sys
= malloc (sizeof (*sys
));
99 if (unlikely(sys
== NULL
))
103 sys
->controls
= ControlsInit (VLC_OBJECT(demux
), fd
);
104 sys
->start
= mdate ();
107 demux
->pf_demux
= NULL
;
108 demux
->pf_control
= RadioControl
;
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
);