1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/*****************************************************************************
* radio.c : V4L2 analog radio receiver
*****************************************************************************
* Copyright (C) 2012 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <fcntl.h>
#include <vlc_common.h>
#include <vlc_demux.h>
#include <vlc_fs.h>
#include "v4l2.h"
struct demux_sys_t
{
int fd;
vlc_v4l2_ctrl_t *controls;
vlc_tick_t start;
};
static int RadioControl (demux_t *demux, int query, va_list args)
{
demux_sys_t *sys = demux->p_sys;
switch (query)
{
case DEMUX_CAN_PAUSE:
case DEMUX_CAN_SEEK:
case DEMUX_CAN_CONTROL_PACE:
*va_arg (args, bool *) = false;
break;
case DEMUX_GET_PTS_DELAY:
*va_arg (args,int64_t *) = INT64_C(1000)
* var_InheritInteger (demux, "live-caching");
break;
case DEMUX_GET_TIME:
*va_arg (args, int64_t *) = mdate () - sys->start;
break;
/* TODO implement others */
default:
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
int RadioOpen (vlc_object_t *obj)
{
demux_t *demux = (demux_t *)obj;
/* Parse MRL */
size_t pathlen = strcspn (demux->psz_location, ":;");
char *path = (pathlen != 0) ? strndup (demux->psz_location, pathlen)
: var_InheritString (obj, CFG_PREFIX"radio-dev");
if (unlikely(path == NULL))
return VLC_ENOMEM;
if (demux->psz_location[pathlen] != '\0')
var_LocationParse (obj, demux->psz_location + pathlen + 1, CFG_PREFIX);
/* Open device */
uint32_t caps;
int fd = OpenDevice (obj, path, &caps);
free (path);
if (fd == -1)
return VLC_EGENERIC;
if (!(caps & V4L2_CAP_TUNER))
{
msg_Err (obj, "not a radio tuner device");
goto error;
}
if (SetupTuner (obj, fd, 0))
goto error;
demux_sys_t *sys = malloc (sizeof (*sys));
if (unlikely(sys == NULL))
goto error;
sys->fd = fd;
sys->controls = ControlsInit (VLC_OBJECT(demux), fd);
sys->start = mdate ();
demux->p_sys = sys;
demux->pf_demux = NULL;
demux->pf_control = RadioControl;
demux->info.i_update = 0;
demux->info.i_title = 0;
demux->info.i_seekpoint = 0;
return VLC_SUCCESS;
error:
v4l2_close (fd);
return VLC_EGENERIC;
}
void RadioClose (vlc_object_t *obj)
{
demux_t *demux = (demux_t *)obj;
demux_sys_t *sys = demux->p_sys;
ControlsDeinit (obj, sys->controls);
v4l2_close (sys->fd);
free (sys);
}
|