2003-03-16 20:13:28 +00:00
|
|
|
/* dvbtune - tune.c
|
|
|
|
|
|
|
|
Copyright (C) Dave Chapman 2001,2002
|
|
|
|
|
2006-06-22 13:34:00 +00:00
|
|
|
Modified for use with MPlayer, for details see the changelog at
|
|
|
|
http://svn.mplayerhq.hu/mplayer/trunk/
|
2005-04-16 12:51:09 +00:00
|
|
|
$Id$
|
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
Or, point your browser to http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/ioctl.h>
|
2008-08-14 15:54:53 +00:00
|
|
|
#include <poll.h>
|
2003-03-16 20:13:28 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2004-12-31 11:40:01 +00:00
|
|
|
#include <time.h>
|
2003-08-11 00:02:46 +00:00
|
|
|
#include <errno.h>
|
2010-03-02 19:57:17 +00:00
|
|
|
#include <linux/dvb/dmx.h>
|
|
|
|
#include <linux/dvb/frontend.h>
|
2013-11-30 21:40:51 +00:00
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
#include "config.h"
|
2013-11-30 21:40:51 +00:00
|
|
|
#include "osdep/io.h"
|
2003-03-16 20:13:28 +00:00
|
|
|
#include "dvbin.h"
|
2010-02-21 21:00:08 +00:00
|
|
|
#include "dvb_tune.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
int dvb_get_tuner_type(int fe_fd, struct mp_log *log)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2003-08-11 00:02:46 +00:00
|
|
|
struct dvb_frontend_info fe_info;
|
|
|
|
|
2004-04-26 21:22:33 +00:00
|
|
|
int res;
|
2004-01-29 10:36:33 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
res = ioctl(fe_fd, FE_GET_INFO, &fe_info);
|
|
|
|
if(res < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_err(log, "FE_GET_INFO error: %d, FD: %d\n\n", errno, fe_fd);
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(fe_info.type)
|
|
|
|
{
|
|
|
|
case FE_OFDM:
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "TUNER TYPE SEEMS TO BE DVB-T\n");
|
2003-08-11 00:02:46 +00:00
|
|
|
return TUNER_TER;
|
|
|
|
|
|
|
|
case FE_QPSK:
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "TUNER TYPE SEEMS TO BE DVB-S\n");
|
2003-08-11 00:02:46 +00:00
|
|
|
return TUNER_SAT;
|
2004-01-29 10:36:33 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
case FE_QAM:
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "TUNER TYPE SEEMS TO BE DVB-C\n");
|
2003-08-11 00:02:46 +00:00
|
|
|
return TUNER_CBL;
|
2004-01-29 10:36:33 +00:00
|
|
|
|
2005-01-06 09:43:10 +00:00
|
|
|
#ifdef DVB_ATSC
|
|
|
|
case FE_ATSC:
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "TUNER TYPE SEEMS TO BE DVB-ATSC\n");
|
2005-01-06 09:43:10 +00:00
|
|
|
return TUNER_ATSC;
|
|
|
|
#endif
|
2003-08-11 00:02:46 +00:00
|
|
|
default:
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_err(log, "UNKNOWN TUNER TYPE\n");
|
2004-01-29 10:36:33 +00:00
|
|
|
return 0;
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2004-01-29 10:36:33 +00:00
|
|
|
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2007-10-30 22:30:15 +00:00
|
|
|
int dvb_open_devices(dvb_priv_t *priv, int n, int demux_cnt)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2004-07-12 20:52:02 +00:00
|
|
|
int i;
|
2008-10-24 09:13:04 +00:00
|
|
|
char frontend_dev[32], dvr_dev[32], demux_dev[32];
|
2008-04-13 10:23:54 +00:00
|
|
|
|
|
|
|
sprintf(frontend_dev, "/dev/dvb/adapter%d/frontend0", n);
|
|
|
|
sprintf(dvr_dev, "/dev/dvb/adapter%d/dvr0", n);
|
|
|
|
sprintf(demux_dev, "/dev/dvb/adapter%d/demux0", n);
|
2013-11-30 21:40:51 +00:00
|
|
|
priv->fe_fd = open(frontend_dev, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
2003-08-11 00:02:46 +00:00
|
|
|
if(priv->fe_fd < 0)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(priv, "ERROR OPENING FRONTEND DEVICE %s: ERRNO %d\n", frontend_dev, errno);
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
2004-07-12 20:52:02 +00:00
|
|
|
priv->demux_fds_cnt = 0;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "DVB_OPEN_DEVICES(%d)\n", demux_cnt);
|
2004-07-12 20:52:02 +00:00
|
|
|
for(i = 0; i < demux_cnt; i++)
|
2004-04-26 21:22:33 +00:00
|
|
|
{
|
2013-11-30 21:40:51 +00:00
|
|
|
priv->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
2004-07-12 20:52:02 +00:00
|
|
|
if(priv->demux_fds[i] < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(priv, "ERROR OPENING DEMUX 0: %d\n", errno);
|
2004-07-12 20:52:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "OPEN(%d), file %s: FD=%d, CNT=%d\n", i, demux_dev, priv->demux_fds[i], priv->demux_fds_cnt);
|
2004-07-12 20:52:02 +00:00
|
|
|
priv->demux_fds_cnt++;
|
|
|
|
}
|
2004-04-26 21:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-30 21:40:51 +00:00
|
|
|
priv->dvr_fd = open(dvr_dev, O_RDONLY| O_NONBLOCK | O_CLOEXEC);
|
2004-04-26 21:22:33 +00:00
|
|
|
if(priv->dvr_fd < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(priv, "ERROR OPENING DVR DEVICE %s: %d\n", dvr_dev, errno);
|
2004-04-26 21:22:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2006-12-30 22:43:12 +00:00
|
|
|
return 1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-30 22:30:15 +00:00
|
|
|
int dvb_fix_demuxes(dvb_priv_t *priv, int cnt)
|
2004-07-12 20:52:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-04-13 10:23:54 +00:00
|
|
|
char demux_dev[32];
|
|
|
|
|
|
|
|
sprintf(demux_dev, "/dev/dvb/adapter%d/demux0", priv->card);
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "FIX %d -> %d\n", priv->demux_fds_cnt, cnt);
|
2004-07-12 20:52:02 +00:00
|
|
|
if(priv->demux_fds_cnt >= cnt)
|
|
|
|
{
|
|
|
|
for(i = priv->demux_fds_cnt-1; i >= cnt; i--)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "FIX, CLOSE fd(%d): %d\n", i, priv->demux_fds[i]);
|
2004-07-12 20:52:02 +00:00
|
|
|
close(priv->demux_fds[i]);
|
|
|
|
}
|
|
|
|
priv->demux_fds_cnt = cnt;
|
|
|
|
}
|
|
|
|
else if(priv->demux_fds_cnt < cnt)
|
|
|
|
{
|
|
|
|
for(i = priv->demux_fds_cnt; i < cnt; i++)
|
|
|
|
{
|
2013-11-30 21:40:51 +00:00
|
|
|
priv->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "FIX, OPEN fd(%d): %d\n", i, priv->demux_fds[i]);
|
2004-07-12 20:52:02 +00:00
|
|
|
if(priv->demux_fds[i] < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(priv, "ERROR OPENING DEMUX 0: %d\n", errno);
|
2004-07-12 20:52:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
priv->demux_fds_cnt++;
|
2009-05-13 02:58:57 +00:00
|
|
|
}
|
2004-07-12 20:52:02 +00:00
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
int dvb_set_ts_filt(dvb_priv_t *priv, int fd, uint16_t pid, dmx_pes_type_t pestype)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct dmx_pes_filter_params pesFilterParams;
|
|
|
|
|
|
|
|
pesFilterParams.pid = pid;
|
|
|
|
pesFilterParams.input = DMX_IN_FRONTEND;
|
|
|
|
pesFilterParams.output = DMX_OUT_TS_TAP;
|
|
|
|
pesFilterParams.pes_type = pestype;
|
|
|
|
pesFilterParams.flags = DMX_IMMEDIATE_START;
|
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
errno = 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
if ((i = ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams)) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(priv, "ERROR IN SETTING DMX_FILTER %i for fd %d: ERRNO: %d", pid, fd, errno);
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "SET PES FILTER ON PID %d to fd %d, RESULT: %d, ERRNO: %d\n", pid, fd, i, errno);
|
2003-03-16 20:13:28 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
int dvb_demux_stop(int fd)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
i = ioctl(fd, DMX_STOP);
|
|
|
|
|
2009-10-08 11:25:01 +00:00
|
|
|
return i == 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
int dvb_demux_start(int fd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
i = ioctl(fd, DMX_START);
|
|
|
|
|
2009-10-08 11:25:01 +00:00
|
|
|
return i == 0;
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
static void print_status(dvb_priv_t *priv, fe_status_t festatus)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "FE_STATUS:");
|
|
|
|
if (festatus & FE_HAS_SIGNAL) MP_VERBOSE(priv, " FE_HAS_SIGNAL");
|
|
|
|
if (festatus & FE_TIMEDOUT) MP_VERBOSE(priv, " FE_TIMEDOUT");
|
|
|
|
if (festatus & FE_HAS_LOCK) MP_VERBOSE(priv, " FE_HAS_LOCK");
|
|
|
|
if (festatus & FE_HAS_CARRIER) MP_VERBOSE(priv, " FE_HAS_CARRIER");
|
|
|
|
if (festatus & FE_HAS_VITERBI) MP_VERBOSE(priv, " FE_HAS_VITERBI");
|
|
|
|
if (festatus & FE_HAS_SYNC) MP_VERBOSE(priv, " FE_HAS_SYNC");
|
|
|
|
MP_VERBOSE(priv, "\n");
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
static int check_status(dvb_priv_t *priv, int fd_frontend, int tmout)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
|
|
|
int32_t strength;
|
|
|
|
fe_status_t festatus;
|
|
|
|
struct pollfd pfd[1];
|
2004-12-31 11:40:01 +00:00
|
|
|
int ok=0, locks=0;
|
|
|
|
time_t tm1, tm2;
|
2004-03-19 20:29:26 +00:00
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
pfd[0].fd = fd_frontend;
|
2004-03-19 20:29:26 +00:00
|
|
|
pfd[0].events = POLLPRI;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "Getting frontend status\n");
|
2004-12-31 11:40:01 +00:00
|
|
|
tm1 = tm2 = time((time_t*) NULL);
|
|
|
|
while(!ok)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-12-31 11:40:01 +00:00
|
|
|
festatus = 0;
|
2006-06-04 23:04:42 +00:00
|
|
|
if(poll(pfd,1,tmout*1000) > 0)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-03-19 20:29:26 +00:00
|
|
|
if (pfd[0].revents & POLLPRI)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-12-31 11:40:01 +00:00
|
|
|
if(ioctl(fd_frontend, FE_READ_STATUS, &festatus) >= 0)
|
|
|
|
if(festatus & FE_HAS_LOCK)
|
|
|
|
locks++;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-31 11:40:01 +00:00
|
|
|
usleep(10000);
|
|
|
|
tm2 = time((time_t*) NULL);
|
2006-06-04 23:04:42 +00:00
|
|
|
if((festatus & FE_TIMEDOUT) || (locks >= 2) || (tm2 - tm1 >= tmout))
|
2004-12-31 11:40:01 +00:00
|
|
|
ok = 1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2004-12-31 11:40:01 +00:00
|
|
|
if(festatus & FE_HAS_LOCK)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
|
|
|
strength=0;
|
2004-03-19 20:29:26 +00:00
|
|
|
if(ioctl(fd_frontend,FE_READ_BER,&strength) >= 0)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "Bit error rate: %d\n",strength);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
strength=0;
|
2004-03-19 20:29:26 +00:00
|
|
|
if(ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength) >= 0)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "Signal strength: %d\n",strength);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
strength=0;
|
2004-03-19 20:29:26 +00:00
|
|
|
if(ioctl(fd_frontend,FE_READ_SNR,&strength) >= 0)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "SNR: %d\n",strength);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-12-31 11:40:01 +00:00
|
|
|
strength=0;
|
|
|
|
if(ioctl(fd_frontend,FE_READ_UNCORRECTED_BLOCKS,&strength) >= 0)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "UNC: %d\n",strength);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
print_status(priv, festatus);
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(priv, "Not able to lock to the signal on the given frequency, timeout: %d\n", tmout);
|
2003-03-16 20:13:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-21 20:39:49 +00:00
|
|
|
|
|
|
|
struct diseqc_cmd {
|
|
|
|
struct dvb_diseqc_master_cmd cmd;
|
|
|
|
uint32_t wait;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd,
|
|
|
|
fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
|
|
|
|
{
|
|
|
|
if(ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
|
|
|
|
return -1;
|
|
|
|
if(ioctl(fd, FE_SET_VOLTAGE, v) == -1)
|
|
|
|
return -1;
|
|
|
|
usleep(15 * 1000);
|
|
|
|
if(ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd) == -1)
|
|
|
|
return -1;
|
|
|
|
usleep(cmd->wait * 1000);
|
|
|
|
usleep(15 * 1000);
|
|
|
|
if(ioctl(fd, FE_DISEQC_SEND_BURST, b) == -1)
|
|
|
|
return -1;
|
|
|
|
usleep(15 * 1000);
|
|
|
|
if(ioctl(fd, FE_SET_TONE, t) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* digital satellite equipment control,
|
|
|
|
* specification is available from http://www.eutelsat.com/
|
|
|
|
*/
|
|
|
|
static int do_diseqc(int secfd, int sat_no, int polv, int hi_lo)
|
|
|
|
{
|
|
|
|
struct diseqc_cmd cmd = { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
|
|
|
|
|
|
|
|
/* param: high nibble: reset bits, low nibble set bits,
|
|
|
|
* bits are: option, position, polarizaion, band
|
|
|
|
*/
|
|
|
|
cmd.cmd.msg[3] =
|
|
|
|
0xf0 | (((sat_no * 4) & 0x0f) | (hi_lo ? 1 : 0) | (polv ? 0 : 2));
|
|
|
|
|
|
|
|
return diseqc_send_msg(secfd, polv ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18,
|
|
|
|
&cmd, hi_lo ? SEC_TONE_ON : SEC_TONE_OFF,
|
|
|
|
(sat_no / 4) % 2 ? SEC_MINI_B : SEC_MINI_A);
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
static int tune_it(dvb_priv_t *priv, int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone,
|
2003-03-16 20:13:28 +00:00
|
|
|
fe_spectral_inversion_t specInv, unsigned int diseqc, fe_modulation_t modulation, fe_code_rate_t HP_CodeRate,
|
2004-08-26 19:38:16 +00:00
|
|
|
fe_transmit_mode_t TransmissionMode, fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth,
|
2006-06-04 23:04:42 +00:00
|
|
|
fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier, int timeout)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2013-05-06 18:58:54 +00:00
|
|
|
int hi_lo = 0, dfd;
|
2003-03-16 20:13:28 +00:00
|
|
|
struct dvb_frontend_parameters feparams;
|
|
|
|
struct dvb_frontend_info fe_info;
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "TUNE_IT, fd_frontend %d, fd_sec %d\nfreq %lu, srate %lu, pol %c, tone %i, specInv, diseqc %u, fe_modulation_t modulation,fe_code_rate_t HP_CodeRate, fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth\n",
|
2007-01-06 18:54:22 +00:00
|
|
|
fd_frontend, fd_sec, (long unsigned int)freq, (long unsigned int)srate, pol, tone, diseqc);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2007-01-06 18:51:01 +00:00
|
|
|
memset(&feparams, 0, sizeof(feparams));
|
2013-05-06 18:58:54 +00:00
|
|
|
if ( ioctl(fd_frontend,FE_GET_INFO, &fe_info) < 0)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_FATAL(priv, "FE_GET_INFO FAILED\n");
|
2007-01-06 18:54:22 +00:00
|
|
|
return -1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "Using DVB card \"%s\"\n", fe_info.name);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
switch(fe_info.type)
|
|
|
|
{
|
|
|
|
case FE_OFDM:
|
|
|
|
if (freq < 1000000) freq*=1000UL;
|
|
|
|
feparams.frequency=freq;
|
2004-01-29 10:36:33 +00:00
|
|
|
feparams.inversion=specInv;
|
2003-03-16 20:13:28 +00:00
|
|
|
feparams.u.ofdm.bandwidth=bandwidth;
|
|
|
|
feparams.u.ofdm.code_rate_HP=HP_CodeRate;
|
2004-08-26 19:38:16 +00:00
|
|
|
feparams.u.ofdm.code_rate_LP=LP_CodeRate;
|
2003-03-16 20:13:28 +00:00
|
|
|
feparams.u.ofdm.constellation=modulation;
|
|
|
|
feparams.u.ofdm.transmission_mode=TransmissionMode;
|
|
|
|
feparams.u.ofdm.guard_interval=guardInterval;
|
2004-08-26 19:38:16 +00:00
|
|
|
feparams.u.ofdm.hierarchy_information=hier;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "tuning DVB-T to %d Hz, bandwidth: %d\n",freq, bandwidth);
|
2003-03-16 20:13:28 +00:00
|
|
|
break;
|
|
|
|
case FE_QPSK:
|
|
|
|
if (freq > 2200000)
|
|
|
|
{
|
|
|
|
// this must be an absolute frequency
|
|
|
|
if (freq < SLOF)
|
2007-01-06 18:54:22 +00:00
|
|
|
{
|
2004-03-19 20:29:26 +00:00
|
|
|
freq = feparams.frequency=(freq-LOF1);
|
2007-01-06 18:54:22 +00:00
|
|
|
hi_lo = 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
2007-01-06 18:54:22 +00:00
|
|
|
else
|
|
|
|
{
|
2004-03-19 20:29:26 +00:00
|
|
|
freq = feparams.frequency=(freq-LOF2);
|
2007-01-06 18:54:22 +00:00
|
|
|
hi_lo = 1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// this is an L-Band frequency
|
|
|
|
feparams.frequency=freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
feparams.inversion=specInv;
|
|
|
|
feparams.u.qpsk.symbol_rate=srate;
|
2004-03-19 20:29:26 +00:00
|
|
|
feparams.u.qpsk.fec_inner=HP_CodeRate;
|
|
|
|
dfd = fd_frontend;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "tuning DVB-S to Freq: %u, Pol: %c Srate: %d, 22kHz: %s, LNB: %d\n",freq,pol,srate,hi_lo ? "on" : "off", diseqc);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2007-01-06 18:54:22 +00:00
|
|
|
if(do_diseqc(dfd, diseqc, (pol == 'V' ? 1 : 0), hi_lo) == 0)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "DISEQC SETTING SUCCEDED\n");
|
2007-01-06 18:54:22 +00:00
|
|
|
else
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(priv, "DISEQC SETTING FAILED\n");
|
2007-01-06 18:54:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
break;
|
|
|
|
case FE_QAM:
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "tuning DVB-C to %d, srate=%d\n",freq,srate);
|
2003-03-16 20:13:28 +00:00
|
|
|
feparams.frequency=freq;
|
2004-01-29 10:36:33 +00:00
|
|
|
feparams.inversion=specInv;
|
2003-03-16 20:13:28 +00:00
|
|
|
feparams.u.qam.symbol_rate = srate;
|
2004-01-29 10:36:33 +00:00
|
|
|
feparams.u.qam.fec_inner = HP_CodeRate;
|
|
|
|
feparams.u.qam.modulation = modulation;
|
2003-03-16 20:13:28 +00:00
|
|
|
break;
|
2005-01-06 09:43:10 +00:00
|
|
|
#ifdef DVB_ATSC
|
|
|
|
case FE_ATSC:
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "tuning ATSC to %d, modulation=%d\n",freq,modulation);
|
2005-01-06 09:43:10 +00:00
|
|
|
feparams.frequency=freq;
|
|
|
|
feparams.u.vsb.modulation = modulation;
|
|
|
|
break;
|
|
|
|
#endif
|
2003-03-16 20:13:28 +00:00
|
|
|
default:
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(priv, "Unknown FE type. Aborting\n");
|
2003-08-14 01:05:49 +00:00
|
|
|
return 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
usleep(100000);
|
|
|
|
|
2007-01-06 11:43:44 +00:00
|
|
|
if(ioctl(fd_frontend,FE_SET_FRONTEND,&feparams) < 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(priv, "ERROR tuning channel\n");
|
2007-01-06 11:43:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
return check_status(priv, fd_frontend, timeout);
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
2010-02-21 20:39:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone,
|
|
|
|
fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval,
|
|
|
|
fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate,
|
|
|
|
fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier, int timeout)
|
|
|
|
{
|
|
|
|
int ris;
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(priv, "dvb_tune Freq: %lu\n", (long unsigned int) freq);
|
2010-02-21 20:39:49 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
ris = tune_it(priv, priv->fe_fd, priv->sec_fd, freq, srate, pol, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth, LP_CodeRate, hier, timeout);
|
2010-02-21 20:39:49 +00:00
|
|
|
|
|
|
|
if(ris != 0)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_INFO(priv, "dvb_tune, TUNING FAILED\n");
|
2010-02-21 20:39:49 +00:00
|
|
|
|
|
|
|
return ris == 0;
|
|
|
|
}
|