2003-03-16 20:13:28 +00:00
|
|
|
/* dvbtune - tune.c
|
|
|
|
|
|
|
|
Copyright (C) Dave Chapman 2001,2002
|
2017-12-15 12:37:30 +00:00
|
|
|
Copyright (C) Rozhuk Ivan <rozhuk.im@gmail.com> 2016 - 2017
|
2003-03-16 20:13:28 +00:00
|
|
|
|
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 <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
|
|
|
|
|
|
|
#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
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
/* Keep in sync with enum fe_delivery_system. */
|
|
|
|
static const char *dvb_delsys_str[] = {
|
|
|
|
"UNDEFINED",
|
|
|
|
"DVB-C ANNEX A",
|
|
|
|
"DVB-C ANNEX B",
|
|
|
|
"DVB-T",
|
|
|
|
"DSS",
|
|
|
|
"DVB-S",
|
|
|
|
"DVB-S2",
|
|
|
|
"DVB-H",
|
|
|
|
"ISDBT",
|
|
|
|
"ISDBS",
|
|
|
|
"ISDBC",
|
|
|
|
"ATSC",
|
|
|
|
"ATSCMH",
|
|
|
|
"DTMB",
|
|
|
|
"CMMB",
|
|
|
|
"DAB",
|
|
|
|
"DVB-T2",
|
|
|
|
"TURBO",
|
|
|
|
"DVB-C ANNEX C",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *get_dvb_delsys(unsigned int delsys)
|
|
|
|
{
|
|
|
|
if (SYS_DVB__COUNT__ <= delsys)
|
|
|
|
return dvb_delsys_str[0];
|
|
|
|
return dvb_delsys_str[delsys];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int dvb_get_tuner_delsys_mask(int fe_fd, struct mp_log *log)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
unsigned int ret_mask = 0, delsys;
|
|
|
|
struct dtv_property prop[1];
|
|
|
|
struct dtv_properties cmdseq = {.num = 1, .props = prop};
|
|
|
|
|
2017-12-15 12:37:30 +00:00
|
|
|
mp_verbose(log, "Querying tuner frontend type via DVBv5 API for frontend FD %d\n",
|
2016-01-18 23:18:08 +00:00
|
|
|
fe_fd);
|
2017-02-13 01:55:35 +00:00
|
|
|
prop[0].cmd = DTV_ENUM_DELSYS;
|
|
|
|
if (ioctl(fe_fd, FE_GET_PROPERTY, &cmdseq) < 0) {
|
|
|
|
mp_err(log, "DVBv5: FE_GET_PROPERTY(DTV_ENUM_DELSYS) error: %d, FD: %d\n\n", errno, fe_fd);
|
2023-01-10 15:28:31 +00:00
|
|
|
return ret_mask;
|
2016-01-18 23:18:08 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
unsigned int i, delsys_count = prop[0].u.buffer.len;
|
|
|
|
mp_verbose(log, "DVBv5: Number of supported delivery systems: %d\n", delsys_count);
|
|
|
|
if (delsys_count == 0) {
|
|
|
|
mp_err(log, "DVBv5: Frontend FD %d returned no delivery systems!\n", fe_fd);
|
2023-01-10 15:28:31 +00:00
|
|
|
return ret_mask;
|
2017-02-13 01:55:35 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
for (i = 0; i < delsys_count; i++) {
|
|
|
|
delsys = (unsigned int)prop[0].u.buffer.data[i];
|
|
|
|
DELSYS_SET(ret_mask, delsys);
|
2017-12-15 12:37:30 +00:00
|
|
|
mp_verbose(log, "DVBv5: Tuner frontend type seems to be %s\n", get_dvb_delsys(delsys));
|
2017-02-13 01:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret_mask;
|
2004-01-29 10:36:33 +00:00
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2017-12-15 12:37:30 +00:00
|
|
|
int dvb_open_devices(dvb_priv_t *priv, unsigned int adapter,
|
|
|
|
unsigned int frontend, unsigned int demux_cnt)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
unsigned int i;
|
|
|
|
char frontend_dev[PATH_MAX], dvr_dev[PATH_MAX], demux_dev[PATH_MAX];
|
2016-01-07 22:30:46 +00:00
|
|
|
dvb_state_t* state = priv->state;
|
2016-01-22 10:55:47 +00:00
|
|
|
|
2017-12-15 12:37:30 +00:00
|
|
|
snprintf(frontend_dev, sizeof(frontend_dev), "/dev/dvb/adapter%u/frontend%u", adapter, frontend);
|
|
|
|
snprintf(dvr_dev, sizeof(dvr_dev), "/dev/dvb/adapter%u/dvr0", adapter);
|
|
|
|
snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux0", adapter);
|
|
|
|
MP_VERBOSE(priv, "DVB_OPEN_DEVICES: frontend: %s\n", frontend_dev);
|
2016-01-07 22:30:46 +00:00
|
|
|
state->fe_fd = open(frontend_dev, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
|
|
|
if (state->fe_fd < 0) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(priv, "ERROR OPENING FRONTEND DEVICE %s: ERRNO %d\n",
|
|
|
|
frontend_dev, errno);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-07 22:30:46 +00:00
|
|
|
state->demux_fds_cnt = 0;
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_VERBOSE(priv, "DVB_OPEN_DEVICES(%d)\n", demux_cnt);
|
|
|
|
for (i = 0; i < demux_cnt; i++) {
|
2016-01-07 22:30:46 +00:00
|
|
|
state->demux_fds[i] = open(demux_dev, O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
|
|
|
if (state->demux_fds[i] < 0) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(priv, "ERROR OPENING DEMUX 0: %d\n", errno);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
MP_VERBOSE(priv, "OPEN(%d), file %s: FD=%d, CNT=%d\n", i, demux_dev,
|
2016-01-07 22:30:46 +00:00
|
|
|
state->demux_fds[i], state->demux_fds_cnt);
|
|
|
|
state->demux_fds_cnt++;
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
state->dvr_fd = open(dvr_dev, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
|
|
|
if (state->dvr_fd < 0) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(priv, "ERROR OPENING DVR DEVICE %s: %d\n", dvr_dev, errno);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return 1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
int dvb_fix_demuxes(dvb_priv_t *priv, unsigned int cnt)
|
2004-07-12 20:52:02 +00:00
|
|
|
{
|
2015-01-06 19:19:49 +00:00
|
|
|
int i;
|
2017-02-13 01:55:35 +00:00
|
|
|
char demux_dev[PATH_MAX];
|
2016-01-22 10:55:47 +00:00
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
dvb_state_t* state = priv->state;
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%d/demux0",
|
|
|
|
state->adapters[state->cur_adapter].devno);
|
2016-01-07 22:30:46 +00:00
|
|
|
MP_VERBOSE(priv, "FIX %d -> %d\n", state->demux_fds_cnt, cnt);
|
|
|
|
if (state->demux_fds_cnt >= cnt) {
|
2017-02-13 01:55:35 +00:00
|
|
|
for (i = state->demux_fds_cnt - 1; i >= (int)cnt; i--) {
|
2016-01-07 22:30:46 +00:00
|
|
|
MP_VERBOSE(priv, "FIX, CLOSE fd(%d): %d\n", i, state->demux_fds[i]);
|
|
|
|
close(state->demux_fds[i]);
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2016-01-07 22:30:46 +00:00
|
|
|
state->demux_fds_cnt = cnt;
|
2017-02-13 01:55:35 +00:00
|
|
|
} else {
|
2016-01-07 22:30:46 +00:00
|
|
|
for (i = state->demux_fds_cnt; i < cnt; i++) {
|
|
|
|
state->demux_fds[i] = open(demux_dev,
|
2015-01-06 19:19:49 +00:00
|
|
|
O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
2016-01-07 22:30:46 +00:00
|
|
|
MP_VERBOSE(priv, "FIX, OPEN fd(%d): %d\n", i, state->demux_fds[i]);
|
|
|
|
if (state->demux_fds[i] < 0) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(priv, "ERROR OPENING DEMUX 0: %d\n", errno);
|
|
|
|
return 0;
|
|
|
|
} else
|
2016-01-07 22:30:46 +00:00
|
|
|
state->demux_fds_cnt++;
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return 1;
|
2004-07-12 20:52:02 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2015-01-06 19:19:49 +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
|
|
|
{
|
2015-01-06 19:19:49 +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;
|
|
|
|
|
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
int buffersize = 256 * 1024;
|
2015-01-06 19:19:49 +00:00
|
|
|
if (ioctl(fd, DMX_SET_BUFFER_SIZE, buffersize) < 0)
|
|
|
|
MP_ERR(priv, "ERROR IN DMX_SET_BUFFER_SIZE %i for fd %d: ERRNO: %d\n",
|
|
|
|
pid, fd, errno);
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
errno = 0;
|
|
|
|
if ((i = ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams)) < 0) {
|
|
|
|
MP_ERR(priv, "ERROR IN SETTING DMX_FILTER %i for fd %d: ERRNO: %d\n",
|
|
|
|
pid, fd, errno);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
MP_VERBOSE(priv, "SET PES FILTER ON PID %d to fd %d, RESULT: %d, ERRNO: %d\n",
|
|
|
|
pid, fd, i, errno);
|
|
|
|
return 1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
int dvb_get_pmt_pid(dvb_priv_t *priv, int devno, int service_id)
|
2015-01-06 19:19:49 +00:00
|
|
|
{
|
|
|
|
/* We need special filters on the demux,
|
|
|
|
so open one locally, and close also here. */
|
2017-02-13 01:55:35 +00:00
|
|
|
char demux_dev[PATH_MAX];
|
|
|
|
snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%d/demux0", devno);
|
2015-01-06 19:19:49 +00:00
|
|
|
|
|
|
|
struct dmx_sct_filter_params fparams;
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
memset(&fparams, 0x00, sizeof(fparams));
|
2015-01-06 19:19:49 +00:00
|
|
|
fparams.pid = 0;
|
|
|
|
fparams.filter.filter[0] = 0x00;
|
|
|
|
fparams.filter.mask[0] = 0xff;
|
|
|
|
fparams.timeout = 0;
|
|
|
|
fparams.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC;
|
|
|
|
|
|
|
|
int pat_fd;
|
|
|
|
if ((pat_fd = open(demux_dev, O_RDWR)) < 0) {
|
|
|
|
MP_ERR(priv, "Opening PAT DEMUX failed, error: %d", errno);
|
|
|
|
return -1;
|
2015-01-04 22:22:02 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (ioctl(pat_fd, DMX_SET_FILTER, &fparams) < 0) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(priv, "ioctl DMX_SET_FILTER failed, error: %d", errno);
|
|
|
|
close(pat_fd);
|
|
|
|
return -1;
|
2015-01-04 22:22:02 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
|
|
|
|
int bytes_read;
|
|
|
|
int section_length;
|
|
|
|
unsigned char buft[4096];
|
|
|
|
unsigned char *bufptr = buft;
|
|
|
|
|
|
|
|
int pmt_pid = -1;
|
|
|
|
|
|
|
|
bool pat_read = false;
|
|
|
|
while (!pat_read) {
|
|
|
|
if (((bytes_read =
|
|
|
|
read(pat_fd, bufptr,
|
|
|
|
sizeof(buft))) < 0) && errno == EOVERFLOW)
|
|
|
|
bytes_read = read(pat_fd, bufptr, sizeof(buft));
|
|
|
|
if (bytes_read < 0) {
|
|
|
|
MP_ERR(priv, "PAT: read_sections: read error: %d", errno);
|
|
|
|
close(pat_fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
section_length = ((bufptr[1] & 0x0f) << 8) | bufptr[2];
|
|
|
|
if (bytes_read != section_length + 3)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bufptr += 8;
|
|
|
|
section_length -= 8;
|
|
|
|
|
|
|
|
/* assumes one section contains the whole pat */
|
|
|
|
pat_read = true;
|
|
|
|
while (section_length > 0) {
|
|
|
|
int this_service_id = (bufptr[0] << 8) | bufptr[1];
|
|
|
|
if (this_service_id == service_id) {
|
|
|
|
pmt_pid = ((bufptr[2] & 0x1f) << 8) | bufptr[3];
|
|
|
|
section_length = 0;
|
|
|
|
}
|
|
|
|
bufptr += 4;
|
|
|
|
section_length -= 4;
|
|
|
|
}
|
2015-01-04 22:22:02 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
close(pat_fd);
|
|
|
|
|
|
|
|
return pmt_pid;
|
2015-01-04 22:22:02 +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
|
|
|
{
|
2015-01-06 19:19:49 +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
|
|
|
{
|
2015-01-06 19:19:49 +00:00
|
|
|
int32_t strength;
|
|
|
|
fe_status_t festatus;
|
|
|
|
struct pollfd pfd[1];
|
|
|
|
int ok = 0, locks = 0;
|
|
|
|
time_t tm1, tm2;
|
|
|
|
|
|
|
|
pfd[0].fd = fd_frontend;
|
|
|
|
pfd[0].events = POLLPRI;
|
|
|
|
|
|
|
|
MP_VERBOSE(priv, "Getting frontend status\n");
|
|
|
|
tm1 = tm2 = time((time_t *) NULL);
|
|
|
|
while (!ok) {
|
|
|
|
festatus = 0;
|
|
|
|
if (poll(pfd, 1, tmout * 1000) > 0) {
|
|
|
|
if (pfd[0].revents & POLLPRI) {
|
|
|
|
if (ioctl(fd_frontend, FE_READ_STATUS, &festatus) >= 0) {
|
|
|
|
if (festatus & FE_HAS_LOCK)
|
|
|
|
locks++;
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
usleep(10000);
|
|
|
|
tm2 = time((time_t *) NULL);
|
|
|
|
if ((festatus & FE_TIMEDOUT) || (locks >= 2) || (tm2 - tm1 >= tmout))
|
|
|
|
ok = 1;
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
if (festatus & FE_HAS_LOCK) {
|
|
|
|
strength = 0;
|
|
|
|
if (ioctl(fd_frontend, FE_READ_BER, &strength) >= 0)
|
|
|
|
MP_VERBOSE(priv, "Bit error rate: %d\n", strength);
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
strength = 0;
|
|
|
|
if (ioctl(fd_frontend, FE_READ_SIGNAL_STRENGTH, &strength) >= 0)
|
|
|
|
MP_VERBOSE(priv, "Signal strength: %d\n", strength);
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
strength = 0;
|
|
|
|
if (ioctl(fd_frontend, FE_READ_SNR, &strength) >= 0)
|
|
|
|
MP_VERBOSE(priv, "SNR: %d\n", strength);
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
strength = 0;
|
|
|
|
if (ioctl(fd_frontend, FE_READ_UNCORRECTED_BLOCKS, &strength) >= 0)
|
|
|
|
MP_VERBOSE(priv, "UNC: %d\n", strength);
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
print_status(priv, festatus);
|
|
|
|
} else {
|
|
|
|
MP_ERR(priv, "Not able to lock to the signal on the given frequency, "
|
|
|
|
"timeout: %d\n", tmout);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2010-02-21 20:39:49 +00:00
|
|
|
struct diseqc_cmd {
|
2015-01-06 19:19:49 +00:00
|
|
|
struct dvb_diseqc_master_cmd cmd;
|
|
|
|
uint32_t wait;
|
2010-02-21 20:39:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd,
|
2015-01-06 19:19:49 +00:00
|
|
|
fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
|
2010-02-21 20:39:49 +00:00
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) < 0)
|
2015-01-06 19:19:49 +00:00
|
|
|
return -1;
|
2017-02-13 01:55:35 +00:00
|
|
|
if (ioctl(fd, FE_SET_VOLTAGE, v) < 0)
|
2015-01-06 19:19:49 +00:00
|
|
|
return -1;
|
|
|
|
usleep(15 * 1000);
|
2017-02-13 01:55:35 +00:00
|
|
|
if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd) < 0)
|
2015-01-06 19:19:49 +00:00
|
|
|
return -1;
|
|
|
|
usleep(cmd->wait * 1000);
|
|
|
|
usleep(15 * 1000);
|
2017-02-13 01:55:35 +00:00
|
|
|
if (ioctl(fd, FE_DISEQC_SEND_BURST, b) < 0)
|
2015-01-06 19:19:49 +00:00
|
|
|
return -1;
|
|
|
|
usleep(15 * 1000);
|
2017-02-13 01:55:35 +00:00
|
|
|
if (ioctl(fd, FE_SET_TONE, t) < 0)
|
2015-01-06 19:19:49 +00:00
|
|
|
return -1;
|
2017-02-13 01:55:35 +00:00
|
|
|
usleep(100000);
|
2010-02-21 20:39:49 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-01-06 19:19:49 +00:00
|
|
|
struct diseqc_cmd cmd = { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 };
|
2010-02-21 20:39:49 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
/* 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));
|
2010-02-21 20:39:49 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return diseqc_send_msg(secfd, polv ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18,
|
|
|
|
&cmd, hi_lo ? SEC_TONE_ON : SEC_TONE_OFF,
|
2017-02-13 01:55:35 +00:00
|
|
|
((sat_no / 4) % 2) ? SEC_MINI_B : SEC_MINI_A);
|
2010-02-21 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 22:26:23 +00:00
|
|
|
static int dvbv5_tune(dvb_priv_t *priv, int fd_frontend,
|
|
|
|
unsigned int delsys, struct dtv_properties* cmdseq)
|
|
|
|
{
|
|
|
|
MP_VERBOSE(priv, "Tuning via S2API, channel is %s.\n",
|
|
|
|
get_dvb_delsys(delsys));
|
|
|
|
MP_VERBOSE(priv, "Dumping raw tuning commands and values:\n");
|
|
|
|
for (int i = 0; i < cmdseq->num; ++i) {
|
|
|
|
MP_VERBOSE(priv, "%02d: 0x%x(%d) => 0x%x(%d)\n",
|
|
|
|
i, cmdseq->props[i].cmd, cmdseq->props[i].cmd,
|
|
|
|
cmdseq->props[i].u.data, cmdseq->props[i].u.data);
|
|
|
|
}
|
|
|
|
if (ioctl(fd_frontend, FE_SET_PROPERTY, cmdseq) < 0) {
|
|
|
|
MP_ERR(priv, "ERROR tuning channel\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
static int tune_it(dvb_priv_t *priv, int fd_frontend, unsigned int delsys,
|
|
|
|
unsigned int freq, unsigned int srate, char pol,
|
|
|
|
int stream_id,
|
2015-01-06 19:19:49 +00:00
|
|
|
fe_spectral_inversion_t specInv, unsigned int diseqc,
|
|
|
|
fe_modulation_t modulation,
|
|
|
|
fe_code_rate_t HP_CodeRate,
|
|
|
|
fe_transmit_mode_t TransmissionMode,
|
|
|
|
fe_guard_interval_t guardInterval,
|
|
|
|
fe_bandwidth_t bandwidth,
|
|
|
|
fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier,
|
|
|
|
int timeout)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
int hi_lo = 0, bandwidth_hz = 0;
|
2016-01-19 23:29:47 +00:00
|
|
|
dvb_state_t* state = priv->state;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_VERBOSE(priv, "TUNE_IT, fd_frontend %d, %s freq %lu, srate %lu, "
|
|
|
|
"pol %c, diseqc %u\n", fd_frontend,
|
|
|
|
get_dvb_delsys(delsys),
|
|
|
|
(long unsigned int)freq, (long unsigned int)srate,
|
|
|
|
(pol > ' ' ? pol : '-'), diseqc);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_VERBOSE(priv, "Using %s adapter %d\n",
|
|
|
|
get_dvb_delsys(delsys),
|
|
|
|
state->adapters[state->cur_adapter].devno);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
{
|
|
|
|
/* discard stale QPSK events */
|
|
|
|
struct dvb_frontend_event ev;
|
|
|
|
while (true) {
|
2017-02-13 01:55:35 +00:00
|
|
|
if (ioctl(fd_frontend, FE_GET_EVENT, &ev) < 0)
|
2015-01-06 19:19:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-12-30 19:34:22 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
/* Prepare params, be verbose. */
|
|
|
|
switch (delsys) {
|
|
|
|
case SYS_DVBT2:
|
|
|
|
case SYS_DVBT:
|
2015-01-06 19:19:49 +00:00
|
|
|
if (freq < 1000000)
|
|
|
|
freq *= 1000UL;
|
2017-02-13 01:55:35 +00:00
|
|
|
switch (bandwidth) {
|
|
|
|
case BANDWIDTH_5_MHZ:
|
|
|
|
bandwidth_hz = 5000000;
|
|
|
|
break;
|
|
|
|
case BANDWIDTH_6_MHZ:
|
|
|
|
bandwidth_hz = 6000000;
|
|
|
|
break;
|
|
|
|
case BANDWIDTH_7_MHZ:
|
|
|
|
bandwidth_hz = 7000000;
|
|
|
|
break;
|
|
|
|
case BANDWIDTH_8_MHZ:
|
|
|
|
bandwidth_hz = 8000000;
|
|
|
|
break;
|
|
|
|
case BANDWIDTH_10_MHZ:
|
|
|
|
bandwidth_hz = 10000000;
|
|
|
|
break;
|
|
|
|
case BANDWIDTH_AUTO:
|
|
|
|
if (freq < 474000000) {
|
|
|
|
bandwidth_hz = 7000000;
|
|
|
|
} else {
|
|
|
|
bandwidth_hz = 8000000;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bandwidth_hz = 0;
|
|
|
|
break;
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
|
|
|
|
MP_VERBOSE(priv, "tuning %s to %d Hz, bandwidth: %d\n",
|
|
|
|
get_dvb_delsys(delsys), freq, bandwidth_hz);
|
|
|
|
break;
|
|
|
|
case SYS_DVBS2:
|
|
|
|
case SYS_DVBS:
|
2015-01-06 19:19:49 +00:00
|
|
|
if (freq > 2200000) {
|
|
|
|
// this must be an absolute frequency
|
|
|
|
if (freq < SLOF) {
|
2017-02-13 01:55:35 +00:00
|
|
|
freq -= LOF1;
|
2015-01-06 19:19:49 +00:00
|
|
|
hi_lo = 0;
|
|
|
|
} else {
|
2017-02-13 01:55:35 +00:00
|
|
|
freq -= LOF2;
|
2015-01-06 19:19:49 +00:00
|
|
|
hi_lo = 1;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_VERBOSE(priv, "tuning %s to Freq: %u, Pol: %c Srate: %d, "
|
|
|
|
"22kHz: %s, LNB: %d\n", get_dvb_delsys(delsys), freq,
|
2015-01-06 19:19:49 +00:00
|
|
|
pol, srate, hi_lo ? "on" : "off", diseqc);
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (do_diseqc(fd_frontend, diseqc, (pol == 'V' ? 1 : 0), hi_lo) == 0) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_VERBOSE(priv, "DISEQC setting succeeded\n");
|
|
|
|
} else {
|
|
|
|
MP_ERR(priv, "DISEQC setting failed\n");
|
|
|
|
return -1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
break;
|
|
|
|
case SYS_DVBC_ANNEX_A:
|
|
|
|
case SYS_DVBC_ANNEX_C:
|
|
|
|
MP_VERBOSE(priv, "tuning %s to %d, srate=%d\n",
|
|
|
|
get_dvb_delsys(delsys), freq, srate);
|
|
|
|
break;
|
|
|
|
case SYS_ATSC:
|
2017-10-08 03:01:55 +00:00
|
|
|
case SYS_DVBC_ANNEX_B:
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_VERBOSE(priv, "tuning %s to %d, modulation=%d\n",
|
|
|
|
get_dvb_delsys(delsys), freq, modulation);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MP_VERBOSE(priv, "Unknown FE type. Aborting\n");
|
|
|
|
return 0;
|
2017-02-13 01:55:35 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
|
|
|
|
/* S2API is the DVB API new since 2.6.28.
|
|
|
|
* It is needed to tune to new delivery systems, e.g. DVB-S2.
|
|
|
|
* It takes a struct with a list of pairs of command + parameter.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Reset before tune. */
|
|
|
|
struct dtv_property p_clear[] = {
|
|
|
|
{ .cmd = DTV_CLEAR },
|
|
|
|
};
|
|
|
|
struct dtv_properties cmdseq_clear = {
|
|
|
|
.num = 1,
|
|
|
|
.props = p_clear
|
|
|
|
};
|
|
|
|
if (ioctl(fd_frontend, FE_SET_PROPERTY, &cmdseq_clear) < 0) {
|
|
|
|
MP_ERR(priv, "FE_SET_PROPERTY DTV_CLEAR failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tune. */
|
2017-10-03 19:40:19 +00:00
|
|
|
switch (delsys) {
|
|
|
|
case SYS_DVBS:
|
|
|
|
case SYS_DVBS2:
|
|
|
|
{
|
|
|
|
struct dtv_property p[] = {
|
|
|
|
{ .cmd = DTV_DELIVERY_SYSTEM, .u.data = delsys },
|
|
|
|
{ .cmd = DTV_FREQUENCY, .u.data = freq },
|
|
|
|
{ .cmd = DTV_MODULATION, .u.data = modulation },
|
|
|
|
{ .cmd = DTV_SYMBOL_RATE, .u.data = srate },
|
|
|
|
{ .cmd = DTV_INNER_FEC, .u.data = HP_CodeRate },
|
|
|
|
{ .cmd = DTV_INVERSION, .u.data = specInv },
|
|
|
|
{ .cmd = DTV_ROLLOFF, .u.data = ROLLOFF_AUTO },
|
|
|
|
{ .cmd = DTV_PILOT, .u.data = PILOT_AUTO },
|
|
|
|
{ .cmd = DTV_TUNE },
|
|
|
|
};
|
|
|
|
struct dtv_properties cmdseq = {
|
|
|
|
.num = sizeof(p) / sizeof(p[0]),
|
|
|
|
.props = p
|
|
|
|
};
|
2017-10-05 22:26:23 +00:00
|
|
|
if (dvbv5_tune(priv, fd_frontend, delsys, &cmdseq) != 0) {
|
2023-01-10 15:28:31 +00:00
|
|
|
goto error_tune;
|
2017-10-03 19:40:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYS_DVBT:
|
|
|
|
case SYS_DVBT2:
|
|
|
|
{
|
|
|
|
struct dtv_property p[] = {
|
|
|
|
{ .cmd = DTV_DELIVERY_SYSTEM, .u.data = delsys },
|
|
|
|
{ .cmd = DTV_FREQUENCY, .u.data = freq },
|
|
|
|
{ .cmd = DTV_MODULATION, .u.data = modulation },
|
|
|
|
{ .cmd = DTV_SYMBOL_RATE, .u.data = srate },
|
|
|
|
{ .cmd = DTV_CODE_RATE_HP, .u.data = HP_CodeRate },
|
|
|
|
{ .cmd = DTV_CODE_RATE_LP, .u.data = LP_CodeRate },
|
|
|
|
{ .cmd = DTV_INVERSION, .u.data = specInv },
|
|
|
|
{ .cmd = DTV_BANDWIDTH_HZ, .u.data = bandwidth_hz },
|
|
|
|
{ .cmd = DTV_TRANSMISSION_MODE, .u.data = TransmissionMode },
|
|
|
|
{ .cmd = DTV_GUARD_INTERVAL, .u.data = guardInterval },
|
|
|
|
{ .cmd = DTV_HIERARCHY, .u.data = hier },
|
|
|
|
{ .cmd = DTV_STREAM_ID, .u.data = stream_id },
|
|
|
|
{ .cmd = DTV_TUNE },
|
|
|
|
};
|
|
|
|
struct dtv_properties cmdseq = {
|
|
|
|
.num = sizeof(p) / sizeof(p[0]),
|
|
|
|
.props = p
|
|
|
|
};
|
2017-10-05 22:26:23 +00:00
|
|
|
if (dvbv5_tune(priv, fd_frontend, delsys, &cmdseq) != 0) {
|
2023-01-10 15:28:31 +00:00
|
|
|
goto error_tune;
|
2017-10-03 19:40:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYS_DVBC_ANNEX_A:
|
|
|
|
case SYS_DVBC_ANNEX_C:
|
|
|
|
{
|
|
|
|
struct dtv_property p[] = {
|
|
|
|
{ .cmd = DTV_DELIVERY_SYSTEM, .u.data = delsys },
|
|
|
|
{ .cmd = DTV_FREQUENCY, .u.data = freq },
|
|
|
|
{ .cmd = DTV_MODULATION, .u.data = modulation },
|
|
|
|
{ .cmd = DTV_SYMBOL_RATE, .u.data = srate },
|
|
|
|
{ .cmd = DTV_INNER_FEC, .u.data = HP_CodeRate },
|
|
|
|
{ .cmd = DTV_INVERSION, .u.data = specInv },
|
|
|
|
{ .cmd = DTV_TUNE },
|
|
|
|
};
|
|
|
|
struct dtv_properties cmdseq = {
|
|
|
|
.num = sizeof(p) / sizeof(p[0]),
|
|
|
|
.props = p
|
|
|
|
};
|
2017-10-05 22:26:23 +00:00
|
|
|
if (dvbv5_tune(priv, fd_frontend, delsys, &cmdseq) != 0) {
|
2023-01-10 15:28:31 +00:00
|
|
|
goto error_tune;
|
2017-10-03 19:40:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYS_ATSC:
|
2017-10-08 03:01:55 +00:00
|
|
|
case SYS_DVBC_ANNEX_B:
|
2017-10-03 19:40:19 +00:00
|
|
|
{
|
|
|
|
struct dtv_property p[] = {
|
|
|
|
{ .cmd = DTV_DELIVERY_SYSTEM, .u.data = delsys },
|
|
|
|
{ .cmd = DTV_FREQUENCY, .u.data = freq },
|
|
|
|
{ .cmd = DTV_INVERSION, .u.data = specInv },
|
|
|
|
{ .cmd = DTV_MODULATION, .u.data = modulation },
|
|
|
|
{ .cmd = DTV_TUNE },
|
|
|
|
};
|
|
|
|
struct dtv_properties cmdseq = {
|
|
|
|
.num = sizeof(p) / sizeof(p[0]),
|
|
|
|
.props = p
|
|
|
|
};
|
2017-10-05 22:26:23 +00:00
|
|
|
if (dvbv5_tune(priv, fd_frontend, delsys, &cmdseq) != 0) {
|
2023-01-10 15:28:31 +00:00
|
|
|
goto error_tune;
|
2017-10-03 19:40:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-02-13 01:55:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 19:40:19 +00:00
|
|
|
int tune_status = check_status(priv, fd_frontend, timeout);
|
|
|
|
if (tune_status != 0) {
|
2023-01-10 15:28:31 +00:00
|
|
|
MP_ERR(priv, "ERROR locking to channel\n");
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2023-01-10 15:28:31 +00:00
|
|
|
return tune_status;
|
2007-01-06 11:43:44 +00:00
|
|
|
|
2023-01-10 15:28:31 +00:00
|
|
|
error_tune:
|
|
|
|
MP_ERR(priv, "ERROR tuning channel\n");
|
|
|
|
return -1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
2010-02-21 20:39:49 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
int dvb_tune(dvb_priv_t *priv, unsigned int delsys,
|
|
|
|
int freq, char pol, int srate, int diseqc,
|
|
|
|
int stream_id, fe_spectral_inversion_t specInv,
|
2015-01-06 19:19:49 +00:00
|
|
|
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)
|
2010-02-21 20:39:49 +00:00
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_INFO(priv, "dvb_tune %s Freq: %lu\n",
|
|
|
|
get_dvb_delsys(delsys), (long unsigned int) freq);
|
2010-02-21 20:39:49 +00:00
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
dvb_state_t* state = priv->state;
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
int ris = tune_it(priv, state->fe_fd, delsys, freq, srate, pol,
|
|
|
|
stream_id, specInv, diseqc, modulation,
|
2015-01-06 19:19:49 +00:00
|
|
|
HP_CodeRate, TransmissionMode, guardInterval,
|
|
|
|
bandWidth, LP_CodeRate, hier, timeout);
|
2010-02-21 20:39:49 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
if (ris != 0)
|
|
|
|
MP_INFO(priv, "dvb_tune, TUNING FAILED\n");
|
2010-02-21 20:39:49 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return ris == 0;
|
2010-02-21 20:39:49 +00:00
|
|
|
}
|