2003-03-16 20:13:28 +00:00
|
|
|
/*
|
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
dvbstream
|
|
|
|
(C) Dave Chapman <dave@dchapman.com> 2001, 2002.
|
2017-12-15 12:37:30 +00:00
|
|
|
(C) Rozhuk Ivan <rozhuk.im@gmail.com> 2016 - 2017
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
Original authors: Nico, probably Arpi
|
2013-07-12 20:11:08 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
Some code based on dvbstream, 0.4.3-pre3 (CVS checkout),
|
|
|
|
http://sourceforge.net/projects/dvbtools/
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
Modified for use with MPlayer, for details see the changelog at
|
|
|
|
http://svn.mplayerhq.hu/mplayer/trunk/
|
|
|
|
$Id$
|
2005-04-16 12:51:09 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
Copyright notice:
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2015-01-06 19:19:49 +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.
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
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.
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
#include "config.h"
|
2003-03-16 20:13:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/time.h>
|
2008-08-14 15:54:53 +00:00
|
|
|
#include <poll.h>
|
2003-03-16 20:13:28 +00:00
|
|
|
#include <unistd.h>
|
2003-08-11 00:02:46 +00:00
|
|
|
#include <fcntl.h>
|
2003-03-16 20:13:28 +00:00
|
|
|
#include <errno.h>
|
2016-01-08 17:37:30 +00:00
|
|
|
#include <pthread.h>
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-11-30 21:40:51 +00:00
|
|
|
#include <libavutil/avstring.h>
|
|
|
|
|
|
|
|
#include "osdep/io.h"
|
2014-07-01 21:10:38 +00:00
|
|
|
#include "misc/ctype.h"
|
2013-11-30 21:40:51 +00:00
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
#include "stream.h"
|
2016-01-08 02:31:29 +00:00
|
|
|
#include "common/tags.h"
|
2014-06-10 19:44:50 +00:00
|
|
|
#include "options/m_config.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2014-06-10 19:44:50 +00:00
|
|
|
#include "options/options.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/path.h"
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
#include "dvbin.h"
|
2013-12-21 19:36:45 +00:00
|
|
|
#include "dvb_tune.h"
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-10-10 13:51:16 +00:00
|
|
|
#if !HAVE_GPL
|
|
|
|
#error GPL only
|
|
|
|
#endif
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
#define CHANNEL_LINE_LEN 256
|
|
|
|
#define min(a, b) ((a) <= (b) ? (a) : (b))
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
#define OPT_BASE_STRUCT dvb_priv_t
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
static dvb_state_t *global_dvb_state = NULL;
|
2016-01-08 17:37:30 +00:00
|
|
|
static pthread_mutex_t global_dvb_state_lock = PTHREAD_MUTEX_INITIALIZER;
|
2016-01-07 22:55:15 +00:00
|
|
|
|
2014-06-10 19:44:50 +00:00
|
|
|
const struct m_sub_options stream_dvb_conf = {
|
|
|
|
.opts = (const m_option_t[]) {
|
|
|
|
OPT_STRING("prog", cfg_prog, 0),
|
2017-02-13 01:55:35 +00:00
|
|
|
OPT_INTRANGE("card", cfg_devno, 0, 1, 4),
|
2015-01-06 19:19:49 +00:00
|
|
|
OPT_INTRANGE("timeout", cfg_timeout, 0, 1, 30),
|
2015-03-07 19:41:32 +00:00
|
|
|
OPT_STRING("file", cfg_file, M_OPT_FILE),
|
2015-01-05 22:41:54 +00:00
|
|
|
OPT_FLAG("full-transponder", cfg_full_transponder, 0),
|
2014-06-10 19:44:50 +00:00
|
|
|
{0}
|
|
|
|
},
|
2017-02-13 01:55:35 +00:00
|
|
|
.size = sizeof(dvb_priv_t),
|
|
|
|
.defaults = &(const dvb_priv_t){
|
|
|
|
.cfg_prog = NULL,
|
|
|
|
.cfg_devno = 0,
|
2014-06-10 19:44:50 +00:00
|
|
|
.cfg_timeout = 30,
|
|
|
|
},
|
2003-08-11 00:02:46 +00:00
|
|
|
};
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
void dvbin_close(stream_t *stream);
|
|
|
|
|
2017-10-08 16:05:18 +00:00
|
|
|
static fe_modulation_t parse_vdr_modulation(const char** modstring) {
|
|
|
|
if (!strncmp(*modstring, "16", 2)) {
|
|
|
|
(*modstring)+=2;
|
|
|
|
return QAM_16;
|
|
|
|
} else if (!strncmp(*modstring, "32", 2)) {
|
|
|
|
(*modstring)+=2;
|
|
|
|
return QAM_32;
|
|
|
|
} else if (!strncmp(*modstring, "64", 2)) {
|
|
|
|
(*modstring)+=2;
|
|
|
|
return QAM_64;
|
|
|
|
} else if (!strncmp(*modstring, "128", 3)) {
|
|
|
|
(*modstring)+=3;
|
|
|
|
return QAM_128;
|
|
|
|
} else if (!strncmp(*modstring, "256", 3)) {
|
|
|
|
(*modstring)+=3;
|
|
|
|
return QAM_256;
|
|
|
|
} else if (!strncmp(*modstring, "998", 3)) {
|
|
|
|
(*modstring)+=3;
|
|
|
|
return QAM_AUTO;
|
|
|
|
} else if (!strncmp(*modstring, "2", 1)) {
|
|
|
|
(*modstring)++;
|
|
|
|
return QPSK;
|
|
|
|
} else if (!strncmp(*modstring, "5", 1)) {
|
|
|
|
(*modstring)++;
|
|
|
|
return PSK_8;
|
|
|
|
} else if (!strncmp(*modstring, "6", 1)) {
|
|
|
|
(*modstring)++;
|
|
|
|
return APSK_16;
|
|
|
|
} else if (!strncmp(*modstring, "7", 1)) {
|
|
|
|
(*modstring)++;
|
|
|
|
return APSK_32;
|
|
|
|
} else if (!strncmp(*modstring, "10", 2)) {
|
|
|
|
(*modstring)+=2;
|
|
|
|
return VSB_8;
|
|
|
|
} else if (!strncmp(*modstring, "11", 2)) {
|
|
|
|
(*modstring)+=2;
|
|
|
|
return VSB_16;
|
|
|
|
} else if (!strncmp(*modstring, "12", 2)) {
|
|
|
|
(*modstring)+=2;
|
|
|
|
return DQPSK;
|
|
|
|
} else {
|
|
|
|
return QAM_AUTO;
|
|
|
|
}
|
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
static void parse_vdr_par_string(const char *vdr_par_str, dvb_channel_t *ptr)
|
|
|
|
{
|
|
|
|
//FIXME: There is more information in this parameter string, especially related
|
|
|
|
// to non-DVB-S reception.
|
|
|
|
if (vdr_par_str[0]) {
|
|
|
|
const char *vdr_par = &vdr_par_str[0];
|
|
|
|
while (vdr_par && *vdr_par) {
|
|
|
|
switch (mp_toupper(*vdr_par)) {
|
|
|
|
case 'H':
|
|
|
|
ptr->pol = 'H';
|
|
|
|
vdr_par++;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
ptr->pol = 'V';
|
|
|
|
vdr_par++;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
vdr_par++;
|
|
|
|
if (*vdr_par == '1') {
|
2017-02-13 01:55:35 +00:00
|
|
|
ptr->is_dvb_x2 = true;
|
2015-01-06 19:19:49 +00:00
|
|
|
} else {
|
2017-02-13 01:55:35 +00:00
|
|
|
ptr->is_dvb_x2 = false;
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
|
|
|
vdr_par++;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
vdr_par++;
|
|
|
|
char *endptr = NULL;
|
|
|
|
errno = 0;
|
|
|
|
int n = strtol(vdr_par, &endptr, 10);
|
|
|
|
if (!errno && endptr != vdr_par) {
|
|
|
|
ptr->stream_id = n;
|
|
|
|
vdr_par = endptr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
vdr_par++;
|
|
|
|
if (*vdr_par == '1') {
|
|
|
|
ptr->inv = INVERSION_ON;
|
|
|
|
} else {
|
|
|
|
ptr->inv = INVERSION_OFF;
|
|
|
|
}
|
|
|
|
vdr_par++;
|
|
|
|
break;
|
2017-10-08 16:05:18 +00:00
|
|
|
case 'M':
|
|
|
|
vdr_par++;
|
|
|
|
ptr->mod = parse_vdr_modulation(&vdr_par);
|
|
|
|
break;
|
2015-01-06 19:19:49 +00:00
|
|
|
default:
|
|
|
|
vdr_par++;
|
|
|
|
}
|
2014-12-31 01:20:14 +00:00
|
|
|
}
|
2014-12-31 00:57:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
static char *dvb_strtok_r(char *s, const char *sep, char **p)
|
|
|
|
{
|
|
|
|
if (!s && !(s = *p))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Skip leading separators. */
|
|
|
|
s += strspn(s, sep);
|
|
|
|
|
|
|
|
/* s points at first non-separator, or end of string. */
|
|
|
|
if (!*s)
|
|
|
|
return *p = 0;
|
|
|
|
|
|
|
|
/* Move *p to next separator. */
|
|
|
|
*p = s + strcspn(s, sep);
|
|
|
|
if (**p) {
|
|
|
|
*(*p)++ = 0;
|
|
|
|
} else {
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
return s;
|
2014-12-31 02:27:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
static bool parse_pid_string(struct mp_log *log, char *pid_string,
|
|
|
|
dvb_channel_t *ptr)
|
|
|
|
{
|
|
|
|
if (pid_string[0]) {
|
|
|
|
int pcnt = 0;
|
|
|
|
/* These tokens also catch vdr-style PID lists.
|
|
|
|
* They can contain 123=deu@3,124=eng+jap@4;125
|
|
|
|
* 3 and 4 are codes for codec type, =langLeft+langRight is allowed,
|
|
|
|
* and ; may separate a dolby channel.
|
|
|
|
* With the numChars-test and the full token-list, all is handled
|
|
|
|
* gracefully.
|
|
|
|
*/
|
|
|
|
const char *tokens = "+,;";
|
|
|
|
char *pidPart;
|
2015-01-19 16:58:37 +00:00
|
|
|
char *savePtr = NULL;
|
2015-01-06 19:19:49 +00:00
|
|
|
pidPart = dvb_strtok_r(pid_string, tokens, &savePtr);
|
|
|
|
while (pidPart != NULL) {
|
|
|
|
if (ptr->pids_cnt >= DMX_FILTER_SIZE - 1) {
|
|
|
|
mp_verbose(log, "Maximum number of PIDs for one channel "
|
|
|
|
"reached, ignoring further ones!\n");
|
|
|
|
return pcnt > 0;
|
|
|
|
}
|
|
|
|
int numChars = 0;
|
|
|
|
int pid = 0;
|
|
|
|
pcnt += sscanf(pidPart, "%d%n", &pid, &numChars);
|
|
|
|
if (numChars > 0) {
|
|
|
|
ptr->pids[ptr->pids_cnt] = pid;
|
|
|
|
ptr->pids_cnt++;
|
|
|
|
}
|
|
|
|
pidPart = dvb_strtok_r(NULL, tokens, &savePtr);
|
|
|
|
}
|
|
|
|
if (pcnt > 0)
|
|
|
|
return true;
|
2014-12-31 02:20:01 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
return false;
|
2014-12-31 02:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
static dvb_channels_list_t *dvb_get_channels(struct mp_log *log,
|
|
|
|
dvb_channels_list_t *list_add,
|
2015-01-06 19:19:49 +00:00
|
|
|
int cfg_full_transponder,
|
|
|
|
char *filename,
|
2017-12-15 12:37:30 +00:00
|
|
|
unsigned int frontend,
|
2017-02-13 01:55:35 +00:00
|
|
|
int delsys, unsigned int delsys_mask)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_channels_list_t *list = list_add;
|
2015-01-06 19:19:49 +00:00
|
|
|
FILE *f;
|
|
|
|
char line[CHANNEL_LINE_LEN], *colon;
|
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int fields, cnt, k;
|
|
|
|
int has8192, has0;
|
|
|
|
dvb_channel_t *ptr, *tmp, chn;
|
|
|
|
char tmp_lcr[256], tmp_hier[256], inv[256], bw[256], cr[256], mod[256],
|
|
|
|
transm[256], gi[256], vpid_str[256], apid_str[256], tpid_str[256],
|
|
|
|
vdr_par_str[256], vdr_loc_str[256];
|
|
|
|
const char *cbl_conf =
|
|
|
|
"%d:%255[^:]:%d:%255[^:]:%255[^:]:%255[^:]:%255[^:]\n";
|
|
|
|
const char *sat_conf = "%d:%c:%d:%d:%255[^:]:%255[^:]\n";
|
|
|
|
const char *ter_conf =
|
|
|
|
"%d:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]\n";
|
2017-02-13 01:55:35 +00:00
|
|
|
#ifdef DVB_ATSC
|
2015-01-06 19:19:49 +00:00
|
|
|
const char *atsc_conf = "%d:%255[^:]:%255[^:]:%255[^:]\n";
|
2017-02-13 01:55:35 +00:00
|
|
|
#endif
|
2015-01-06 19:19:49 +00:00
|
|
|
const char *vdr_conf =
|
|
|
|
"%d:%255[^:]:%255[^:]:%d:%255[^:]:%255[^:]:%255[^:]:%*255[^:]:%d:%*d:%*d:%*d\n%n";
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
mp_verbose(log, "CONFIG_READ FILE: %s, type: %s\n",
|
|
|
|
filename, get_dvb_delsys(delsys));
|
2015-01-06 19:19:49 +00:00
|
|
|
if ((f = fopen(filename, "r")) == NULL) {
|
|
|
|
mp_fatal(log, "CAN'T READ CONFIG FILE %s\n", filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
if (list == NULL) {
|
2017-02-13 01:55:35 +00:00
|
|
|
list = malloc(sizeof(dvb_channels_list_t));
|
|
|
|
if (list == NULL) {
|
|
|
|
fclose(f);
|
|
|
|
mp_verbose(log, "DVB_GET_CHANNELS: couldn't malloc enough memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memset(list, 0x00, sizeof(dvb_channels_list_t));
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
ptr = &chn;
|
|
|
|
while (!feof(f)) {
|
|
|
|
if (fgets(line, CHANNEL_LINE_LEN, f) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((line[0] == '#') || (strlen(line) == 0))
|
|
|
|
continue;
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
memset(ptr, 0x00, sizeof(dvb_channel_t));
|
|
|
|
vpid_str[0] = apid_str[0] = tpid_str[0] = 0;
|
|
|
|
vdr_loc_str[0] = vdr_par_str[0] = 0;
|
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
colon = strchr(line, ':');
|
|
|
|
if (colon) {
|
|
|
|
k = colon - line;
|
|
|
|
if (!k)
|
|
|
|
continue;
|
|
|
|
// In some modern VDR-style configs, channel name also has bouquet after ;.
|
|
|
|
// Parse that off, we ignore it.
|
|
|
|
char *bouquet_sep = strchr(line, ';');
|
|
|
|
int channel_name_length = k;
|
|
|
|
if (bouquet_sep && bouquet_sep < colon)
|
2017-02-13 01:55:35 +00:00
|
|
|
channel_name_length = (bouquet_sep - line);
|
|
|
|
ptr->name = malloc((channel_name_length + 1));
|
2015-01-06 19:19:49 +00:00
|
|
|
if (!ptr->name)
|
|
|
|
continue;
|
2017-02-13 01:55:35 +00:00
|
|
|
av_strlcpy(ptr->name, line, (channel_name_length + 1));
|
2015-01-06 19:19:49 +00:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
k++;
|
|
|
|
ptr->pids_cnt = 0;
|
|
|
|
ptr->freq = 0;
|
|
|
|
ptr->service_id = -1;
|
2017-02-13 01:55:35 +00:00
|
|
|
ptr->is_dvb_x2 = false;
|
2017-12-15 12:37:30 +00:00
|
|
|
ptr->frontend = frontend;
|
2017-02-13 01:55:35 +00:00
|
|
|
ptr->delsys = delsys;
|
|
|
|
ptr->diseqc = 0;
|
2015-01-06 19:19:49 +00:00
|
|
|
ptr->stream_id = NO_STREAM_ID_FILTER;
|
|
|
|
ptr->inv = INVERSION_AUTO;
|
2017-02-13 01:55:35 +00:00
|
|
|
ptr->bw = BANDWIDTH_AUTO;
|
|
|
|
ptr->cr = FEC_AUTO;
|
|
|
|
ptr->cr_lp = FEC_AUTO;
|
|
|
|
ptr->mod = QAM_AUTO;
|
|
|
|
ptr->hier = HIERARCHY_AUTO;
|
|
|
|
ptr->gi = GUARD_INTERVAL_AUTO;
|
|
|
|
ptr->trans = TRANSMISSION_MODE_AUTO;
|
2015-01-06 19:19:49 +00:00
|
|
|
|
|
|
|
// Check if VDR-type channels.conf-line - then full line is consumed by the scan.
|
|
|
|
int num_chars = 0;
|
|
|
|
fields = sscanf(&line[k], vdr_conf,
|
|
|
|
&ptr->freq, vdr_par_str, vdr_loc_str, &ptr->srate,
|
|
|
|
vpid_str, apid_str, tpid_str, &ptr->service_id,
|
|
|
|
&num_chars);
|
|
|
|
|
|
|
|
if (num_chars == strlen(&line[k])) {
|
2017-10-08 16:05:18 +00:00
|
|
|
// Modulation parsed here, not via old xine-parsing path.
|
|
|
|
mod[0] = '\0';
|
2015-01-06 19:19:49 +00:00
|
|
|
// It's a VDR-style config line.
|
|
|
|
parse_vdr_par_string(vdr_par_str, ptr);
|
2017-10-08 02:37:42 +00:00
|
|
|
// Units in VDR-style config files are divided by 1000.
|
|
|
|
ptr->freq *= 1000UL;
|
|
|
|
ptr->srate *= 1000UL;
|
2017-02-13 01:55:35 +00:00
|
|
|
switch (delsys) {
|
|
|
|
case SYS_DVBT:
|
|
|
|
case SYS_DVBT2:
|
|
|
|
/* Fix delsys value. */
|
|
|
|
if (ptr->is_dvb_x2) {
|
|
|
|
ptr->delsys = delsys = SYS_DVBT2;
|
|
|
|
} else {
|
|
|
|
ptr->delsys = delsys = SYS_DVBT;
|
|
|
|
}
|
|
|
|
if (!DELSYS_IS_SET(delsys_mask, delsys))
|
|
|
|
continue; /* Skip channel. */
|
|
|
|
/* PASSTROUTH */
|
|
|
|
case SYS_DVBC_ANNEX_A:
|
|
|
|
case SYS_DVBC_ANNEX_C:
|
|
|
|
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(log, "VDR, %s, NUM: %d, NUM_FIELDS: %d, NAME: %s, "
|
|
|
|
"FREQ: %d, SRATE: %d",
|
|
|
|
get_dvb_delsys(delsys),
|
|
|
|
list->NUM_CHANNELS, fields,
|
|
|
|
ptr->name, ptr->freq, ptr->srate);
|
|
|
|
break;
|
|
|
|
case SYS_DVBS:
|
|
|
|
case SYS_DVBS2:
|
|
|
|
/* Fix delsys value. */
|
|
|
|
if (ptr->is_dvb_x2) {
|
|
|
|
ptr->delsys = delsys = SYS_DVBS2;
|
|
|
|
} else {
|
|
|
|
ptr->delsys = delsys = SYS_DVBS;
|
|
|
|
}
|
|
|
|
if (!DELSYS_IS_SET(delsys_mask, delsys))
|
|
|
|
continue; /* Skip channel. */
|
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
if (vdr_loc_str[0]) {
|
|
|
|
// In older vdr config format, this field contained the DISEQc information.
|
|
|
|
// If it is numeric, assume that's it.
|
|
|
|
int diseqc_info = 0;
|
|
|
|
int valid_digits = 0;
|
|
|
|
if (sscanf(vdr_loc_str, "%d%n", &diseqc_info,
|
|
|
|
&valid_digits) == 1)
|
|
|
|
{
|
2014-12-31 01:42:29 +00:00
|
|
|
if (valid_digits == strlen(vdr_loc_str)) {
|
2017-02-13 01:55:35 +00:00
|
|
|
ptr->diseqc = (unsigned int)diseqc_info;
|
|
|
|
if (ptr->diseqc > 4)
|
2015-01-06 19:19:49 +00:00
|
|
|
continue;
|
|
|
|
if (ptr->diseqc > 0)
|
|
|
|
ptr->diseqc--;
|
2014-12-31 01:42:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
mp_verbose(log, "%s NUM: %d, NUM_FIELDS: %d, NAME: %s, "
|
2015-01-06 19:19:49 +00:00
|
|
|
"FREQ: %d, SRATE: %d, POL: %c, DISEQC: %d, S2: %s, "
|
2017-02-13 01:55:35 +00:00
|
|
|
"StreamID: %d, SID: %d",
|
|
|
|
get_dvb_delsys(delsys),
|
|
|
|
list->NUM_CHANNELS,
|
2015-01-06 19:19:49 +00:00
|
|
|
fields, ptr->name, ptr->freq, ptr->srate, ptr->pol,
|
2017-02-13 01:55:35 +00:00
|
|
|
ptr->diseqc, (delsys == SYS_DVBS2) ? "yes" : "no",
|
2015-01-06 19:19:49 +00:00
|
|
|
ptr->stream_id, ptr->service_id);
|
2017-02-13 01:55:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
} else {
|
|
|
|
switch (delsys) {
|
|
|
|
case SYS_DVBT:
|
|
|
|
case SYS_DVBT2:
|
|
|
|
fields = sscanf(&line[k], ter_conf,
|
|
|
|
&ptr->freq, inv, bw, cr, tmp_lcr, mod,
|
|
|
|
transm, gi, tmp_hier, vpid_str, apid_str);
|
|
|
|
mp_verbose(log, "%s, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d",
|
|
|
|
get_dvb_delsys(delsys), list->NUM_CHANNELS,
|
|
|
|
fields, ptr->name, ptr->freq);
|
|
|
|
break;
|
|
|
|
case SYS_DVBC_ANNEX_A:
|
|
|
|
case SYS_DVBC_ANNEX_C:
|
|
|
|
fields = sscanf(&line[k], cbl_conf,
|
|
|
|
&ptr->freq, inv, &ptr->srate,
|
|
|
|
cr, mod, vpid_str, apid_str);
|
|
|
|
mp_verbose(log, "%s, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, "
|
|
|
|
"SRATE: %d",
|
|
|
|
get_dvb_delsys(delsys),
|
|
|
|
list->NUM_CHANNELS, fields, ptr->name,
|
|
|
|
ptr->freq, ptr->srate);
|
|
|
|
break;
|
2005-01-06 09:43:10 +00:00
|
|
|
#ifdef DVB_ATSC
|
2017-02-13 01:55:35 +00:00
|
|
|
case SYS_ATSC:
|
2017-10-08 03:01:55 +00:00
|
|
|
case SYS_DVBC_ANNEX_B:
|
2017-02-13 01:55:35 +00:00
|
|
|
fields = sscanf(&line[k], atsc_conf,
|
|
|
|
&ptr->freq, mod, vpid_str, apid_str);
|
|
|
|
mp_verbose(log, "%s, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d\n",
|
|
|
|
get_dvb_delsys(delsys), list->NUM_CHANNELS,
|
|
|
|
fields, ptr->name, ptr->freq);
|
|
|
|
break;
|
2005-01-06 09:43:10 +00:00
|
|
|
#endif
|
2017-02-13 01:55:35 +00:00
|
|
|
case SYS_DVBS:
|
|
|
|
case SYS_DVBS2:
|
|
|
|
fields = sscanf(&line[k], sat_conf,
|
|
|
|
&ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate,
|
|
|
|
vpid_str,
|
|
|
|
apid_str);
|
|
|
|
ptr->pol = mp_toupper(ptr->pol);
|
|
|
|
ptr->freq *= 1000UL;
|
|
|
|
ptr->srate *= 1000UL;
|
|
|
|
if (ptr->diseqc > 4)
|
|
|
|
continue;
|
|
|
|
if (ptr->diseqc > 0)
|
|
|
|
ptr->diseqc--;
|
|
|
|
mp_verbose(log, "%s, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, "
|
|
|
|
"SRATE: %d, POL: %c, DISEQC: %d",
|
|
|
|
get_dvb_delsys(delsys),
|
|
|
|
list->NUM_CHANNELS, fields, ptr->name, ptr->freq,
|
|
|
|
ptr->srate, ptr->pol, ptr->diseqc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2015-01-05 19:27:22 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
if (parse_pid_string(log, vpid_str, ptr))
|
|
|
|
fields++;
|
|
|
|
if (parse_pid_string(log, apid_str, ptr))
|
|
|
|
fields++;
|
|
|
|
/* If we do not know the service_id, PMT can not be extracted.
|
|
|
|
Teletext decoding will fail without PMT. */
|
|
|
|
if (ptr->service_id != -1) {
|
|
|
|
if (parse_pid_string(log, tpid_str, ptr))
|
|
|
|
fields++;
|
|
|
|
}
|
2015-01-05 19:27:22 +00:00
|
|
|
|
2015-01-05 22:46:31 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (fields < 2 || ptr->pids_cnt == 0 || ptr->freq == 0 ||
|
|
|
|
strlen(ptr->name) == 0)
|
2015-01-06 19:19:49 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Add some PIDs which are mandatory in DVB,
|
|
|
|
* and contain human-readable helpful data. */
|
|
|
|
|
|
|
|
/* This is the STD, the service description table.
|
|
|
|
* It contains service names and such, ffmpeg decodes it. */
|
|
|
|
ptr->pids[ptr->pids_cnt] = 0x0011;
|
|
|
|
ptr->pids_cnt++;
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
/* This is the EIT, which contains EPG data.
|
|
|
|
* ffmpeg can not decode it (yet), but e.g. VLC
|
|
|
|
* shows what was recorded. */
|
|
|
|
ptr->pids[ptr->pids_cnt] = 0x0012;
|
|
|
|
ptr->pids_cnt++;
|
|
|
|
|
|
|
|
if (ptr->service_id != -1) {
|
|
|
|
/* We have the PMT-PID in addition.
|
|
|
|
This will be found later, when we tune to the channel.
|
|
|
|
Push back here to create the additional demux. */
|
|
|
|
ptr->pids[ptr->pids_cnt] = -1; // Placeholder.
|
|
|
|
ptr->pids_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
has8192 = has0 = 0;
|
|
|
|
for (cnt = 0; cnt < ptr->pids_cnt; cnt++) {
|
|
|
|
if (ptr->pids[cnt] == 8192)
|
|
|
|
has8192 = 1;
|
|
|
|
if (ptr->pids[cnt] == 0)
|
|
|
|
has0 = 1;
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
/* 8192 is the pseudo-PID for full TP dump,
|
|
|
|
enforce that if requested. */
|
|
|
|
if (!has8192 && cfg_full_transponder)
|
|
|
|
has8192 = 1;
|
|
|
|
if (has8192) {
|
|
|
|
ptr->pids[0] = 8192;
|
|
|
|
ptr->pids_cnt = 1;
|
|
|
|
} else if (!has0) {
|
|
|
|
ptr->pids[ptr->pids_cnt] = 0; //PID 0 is the PAT
|
|
|
|
ptr->pids_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_verbose(log, " PIDS: ");
|
|
|
|
for (cnt = 0; cnt < ptr->pids_cnt; cnt++)
|
|
|
|
mp_verbose(log, " %d ", ptr->pids[cnt]);
|
|
|
|
mp_verbose(log, "\n");
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
switch (delsys) {
|
|
|
|
case SYS_DVBT:
|
|
|
|
case SYS_DVBT2:
|
|
|
|
case SYS_DVBC_ANNEX_A:
|
|
|
|
case SYS_DVBC_ANNEX_C:
|
2015-01-06 19:19:49 +00:00
|
|
|
if (!strcmp(inv, "INVERSION_ON")) {
|
|
|
|
ptr->inv = INVERSION_ON;
|
|
|
|
} else if (!strcmp(inv, "INVERSION_OFF")) {
|
|
|
|
ptr->inv = INVERSION_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(cr, "FEC_1_2")) {
|
|
|
|
ptr->cr = FEC_1_2;
|
|
|
|
} else if (!strcmp(cr, "FEC_2_3")) {
|
|
|
|
ptr->cr = FEC_2_3;
|
|
|
|
} else if (!strcmp(cr, "FEC_3_4")) {
|
|
|
|
ptr->cr = FEC_3_4;
|
|
|
|
} else if (!strcmp(cr, "FEC_4_5")) {
|
|
|
|
ptr->cr = FEC_4_5;
|
|
|
|
} else if (!strcmp(cr, "FEC_6_7")) {
|
|
|
|
ptr->cr = FEC_6_7;
|
|
|
|
} else if (!strcmp(cr, "FEC_8_9")) {
|
|
|
|
ptr->cr = FEC_8_9;
|
|
|
|
} else if (!strcmp(cr, "FEC_5_6")) {
|
|
|
|
ptr->cr = FEC_5_6;
|
|
|
|
} else if (!strcmp(cr, "FEC_7_8")) {
|
|
|
|
ptr->cr = FEC_7_8;
|
|
|
|
} else if (!strcmp(cr, "FEC_NONE")) {
|
|
|
|
ptr->cr = FEC_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
switch (delsys) {
|
|
|
|
case SYS_DVBT:
|
|
|
|
case SYS_DVBT2:
|
|
|
|
case SYS_DVBC_ANNEX_A:
|
|
|
|
case SYS_DVBC_ANNEX_C:
|
|
|
|
case SYS_ATSC:
|
2017-10-08 03:01:55 +00:00
|
|
|
case SYS_DVBC_ANNEX_B:
|
2015-01-06 19:19:49 +00:00
|
|
|
if (!strcmp(mod, "QAM_128")) {
|
|
|
|
ptr->mod = QAM_128;
|
|
|
|
} else if (!strcmp(mod, "QAM_256")) {
|
|
|
|
ptr->mod = QAM_256;
|
|
|
|
} else if (!strcmp(mod, "QAM_64")) {
|
|
|
|
ptr->mod = QAM_64;
|
|
|
|
} else if (!strcmp(mod, "QAM_32")) {
|
|
|
|
ptr->mod = QAM_32;
|
|
|
|
} else if (!strcmp(mod, "QAM_16")) {
|
|
|
|
ptr->mod = QAM_16;
|
2009-05-13 02:58:57 +00:00
|
|
|
#ifdef DVB_ATSC
|
2015-01-06 19:19:49 +00:00
|
|
|
} else if (!strcmp(mod, "VSB_8") || !strcmp(mod, "8VSB")) {
|
|
|
|
ptr->mod = VSB_8;
|
|
|
|
} else if (!strcmp(mod, "VSB_16") || !strcmp(mod, "16VSB")) {
|
|
|
|
ptr->mod = VSB_16;
|
2005-01-06 09:43:10 +00:00
|
|
|
#endif
|
2017-02-13 01:55:35 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2017-10-08 03:01:55 +00:00
|
|
|
#ifdef DVB_ATSC
|
|
|
|
/* Modulation defines real delsys for ATSC:
|
|
|
|
Terrestrial (VSB) is SYS_ATSC, Cable (QAM) is SYS_DVBC_ANNEX_B. */
|
|
|
|
if (delsys == SYS_ATSC || delsys == SYS_DVBC_ANNEX_B) {
|
|
|
|
if (ptr->mod == VSB_8 || ptr->mod == VSB_16) {
|
|
|
|
delsys = SYS_ATSC;
|
|
|
|
} else {
|
|
|
|
delsys = SYS_DVBC_ANNEX_B;
|
|
|
|
}
|
2017-10-08 16:07:17 +00:00
|
|
|
if (!DELSYS_IS_SET(delsys_mask, delsys))
|
|
|
|
continue; /* Skip channel. */
|
|
|
|
mp_verbose(log, "Switched to delivery system for ATSC: %s (guessed from modulation).\n",
|
2017-10-08 03:01:55 +00:00
|
|
|
get_dvb_delsys(delsys));
|
|
|
|
}
|
|
|
|
#endif
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
switch (delsys) {
|
|
|
|
case SYS_DVBT:
|
|
|
|
case SYS_DVBT2:
|
|
|
|
if (!strcmp(bw, "BANDWIDTH_5_MHZ")) {
|
|
|
|
ptr->bw = BANDWIDTH_5_MHZ;
|
|
|
|
} else if (!strcmp(bw, "BANDWIDTH_6_MHZ")) {
|
2015-01-06 19:19:49 +00:00
|
|
|
ptr->bw = BANDWIDTH_6_MHZ;
|
|
|
|
} else if (!strcmp(bw, "BANDWIDTH_7_MHZ")) {
|
|
|
|
ptr->bw = BANDWIDTH_7_MHZ;
|
|
|
|
} else if (!strcmp(bw, "BANDWIDTH_8_MHZ")) {
|
|
|
|
ptr->bw = BANDWIDTH_8_MHZ;
|
2017-02-13 01:55:35 +00:00
|
|
|
} else if (!strcmp(bw, "BANDWIDTH_10_MHZ")) {
|
|
|
|
ptr->bw = BANDWIDTH_10_MHZ;
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
|
|
|
|
if (!strcmp(transm, "TRANSMISSION_MODE_2K")) {
|
|
|
|
ptr->trans = TRANSMISSION_MODE_2K;
|
|
|
|
} else if (!strcmp(transm, "TRANSMISSION_MODE_8K")) {
|
|
|
|
ptr->trans = TRANSMISSION_MODE_8K;
|
|
|
|
} else if (!strcmp(transm, "TRANSMISSION_MODE_AUTO")) {
|
|
|
|
ptr->trans = TRANSMISSION_MODE_AUTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(gi, "GUARD_INTERVAL_1_32")) {
|
|
|
|
ptr->gi = GUARD_INTERVAL_1_32;
|
|
|
|
} else if (!strcmp(gi, "GUARD_INTERVAL_1_16")) {
|
|
|
|
ptr->gi = GUARD_INTERVAL_1_16;
|
|
|
|
} else if (!strcmp(gi, "GUARD_INTERVAL_1_8")) {
|
|
|
|
ptr->gi = GUARD_INTERVAL_1_8;
|
|
|
|
} else if (!strcmp(gi, "GUARD_INTERVAL_1_4")) {
|
|
|
|
ptr->gi = GUARD_INTERVAL_1_4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(tmp_lcr, "FEC_1_2")) {
|
|
|
|
ptr->cr_lp = FEC_1_2;
|
|
|
|
} else if (!strcmp(tmp_lcr, "FEC_2_3")) {
|
|
|
|
ptr->cr_lp = FEC_2_3;
|
|
|
|
} else if (!strcmp(tmp_lcr, "FEC_3_4")) {
|
|
|
|
ptr->cr_lp = FEC_3_4;
|
|
|
|
} else if (!strcmp(tmp_lcr, "FEC_4_5")) {
|
|
|
|
ptr->cr_lp = FEC_4_5;
|
|
|
|
} else if (!strcmp(tmp_lcr, "FEC_6_7")) {
|
|
|
|
ptr->cr_lp = FEC_6_7;
|
|
|
|
} else if (!strcmp(tmp_lcr, "FEC_8_9")) {
|
|
|
|
ptr->cr_lp = FEC_8_9;
|
|
|
|
} else if (!strcmp(tmp_lcr, "FEC_5_6")) {
|
|
|
|
ptr->cr_lp = FEC_5_6;
|
|
|
|
} else if (!strcmp(tmp_lcr, "FEC_7_8")) {
|
|
|
|
ptr->cr_lp = FEC_7_8;
|
|
|
|
} else if (!strcmp(tmp_lcr, "FEC_NONE")) {
|
|
|
|
ptr->cr_lp = FEC_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!strcmp(tmp_hier, "HIERARCHY_1")) {
|
|
|
|
ptr->hier = HIERARCHY_1;
|
|
|
|
} else if (!strcmp(tmp_hier, "HIERARCHY_2")) {
|
|
|
|
ptr->hier = HIERARCHY_2;
|
|
|
|
} else if (!strcmp(tmp_hier, "HIERARCHY_4")) {
|
|
|
|
ptr->hier = HIERARCHY_4;
|
2017-02-13 01:55:35 +00:00
|
|
|
} else if (!strcmp(tmp_hier, "HIERARCHY_NONE")) {
|
2015-01-06 19:19:49 +00:00
|
|
|
ptr->hier = HIERARCHY_NONE;
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
tmp = realloc(list->channels, sizeof(dvb_channel_t) *
|
|
|
|
(list->NUM_CHANNELS + 1));
|
|
|
|
if (tmp == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
list->channels = tmp;
|
|
|
|
memcpy(&(list->channels[list->NUM_CHANNELS]), ptr, sizeof(dvb_channel_t));
|
|
|
|
list->NUM_CHANNELS++;
|
|
|
|
if (sizeof(dvb_channel_t) * list->NUM_CHANNELS >= 1024 * 1024) {
|
|
|
|
mp_verbose(log, "dvbin.c, > 1MB allocated for channels struct, "
|
|
|
|
"dropping the rest of the file\n");
|
|
|
|
break;
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
if (list->NUM_CHANNELS == 0) {
|
|
|
|
free(list->channels);
|
|
|
|
free(list);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return list;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
void dvb_free_state(dvb_state_t *state)
|
2007-12-15 13:30:44 +00:00
|
|
|
{
|
2015-01-06 19:19:49 +00:00
|
|
|
int i, j;
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
for (i = 0; i < state->adapters_count; i++) {
|
|
|
|
if (!state->adapters[i].list)
|
2015-01-06 19:19:49 +00:00
|
|
|
continue;
|
2017-02-13 01:55:35 +00:00
|
|
|
if (state->adapters[i].list->channels) {
|
|
|
|
for (j = 0; j < state->adapters[i].list->NUM_CHANNELS; j++)
|
|
|
|
free(state->adapters[i].list->channels[j].name);
|
|
|
|
free(state->adapters[i].list->channels);
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
free(state->adapters[i].list);
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2016-01-07 22:30:46 +00:00
|
|
|
free(state);
|
2007-12-15 13:30:44 +00:00
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
static int dvb_streaming_read(stream_t *stream, char *buffer, int size)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2015-01-06 19:19:49 +00:00
|
|
|
struct pollfd pfds[1];
|
|
|
|
int pos = 0, tries, rk, fd;
|
|
|
|
dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_state_t *state = priv->state;
|
2015-01-06 19:19:49 +00:00
|
|
|
|
|
|
|
MP_TRACE(stream, "dvb_streaming_read(%d)\n", size);
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
tries = state->retry;
|
2016-01-07 22:30:46 +00:00
|
|
|
fd = state->dvr_fd;
|
2015-01-06 19:19:49 +00:00
|
|
|
while (pos < size) {
|
2017-02-13 01:55:35 +00:00
|
|
|
rk = read(fd, &buffer[pos], (size - pos));
|
|
|
|
if (rk <= 0) {
|
|
|
|
if (pos || tries == 0)
|
|
|
|
break;
|
|
|
|
tries --;
|
|
|
|
pfds[0].fd = fd;
|
|
|
|
pfds[0].events = POLLIN | POLLPRI;
|
|
|
|
if (poll(pfds, 1, 500) <= 0) {
|
|
|
|
MP_ERR(stream, "dvb_streaming_read, failed with "
|
|
|
|
"errno %d when reading %d bytes\n", errno, size - pos);
|
|
|
|
errno = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
pos += rk;
|
|
|
|
MP_TRACE(stream, "ret (%d) bytes\n", pos);
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
if (!pos)
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_ERR(stream, "dvb_streaming_read, return 0 bytes\n");
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return pos;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
int dvb_set_channel(stream_t *stream, unsigned int adapter, unsigned int n)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_channels_list_t *new_list;
|
2015-01-06 19:19:49 +00:00
|
|
|
dvb_channel_t *channel;
|
|
|
|
dvb_priv_t *priv = stream->priv;
|
|
|
|
char buf[4096];
|
2016-01-07 22:30:46 +00:00
|
|
|
dvb_state_t *state = (dvb_state_t *) priv->state;
|
2015-01-06 19:19:49 +00:00
|
|
|
int devno;
|
|
|
|
int i;
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (adapter >= state->adapters_count) {
|
|
|
|
MP_ERR(stream, "dvb_set_channel: INVALID internal ADAPTER NUMBER: %d vs %d, abort\n",
|
|
|
|
adapter, state->adapters_count);
|
2015-01-06 19:19:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
devno = state->adapters[adapter].devno;
|
|
|
|
new_list = state->adapters[adapter].list;
|
|
|
|
if (n > new_list->NUM_CHANNELS) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(stream, "dvb_set_channel: INVALID CHANNEL NUMBER: %d, for "
|
2017-02-13 01:55:35 +00:00
|
|
|
"adapter %d, abort\n", n, devno);
|
2015-01-06 19:19:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
channel = &(new_list->channels[n]);
|
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
if (state->is_on) { //the fds are already open and we have to stop the demuxers
|
2017-02-13 01:55:35 +00:00
|
|
|
/* Remove all demuxes. */
|
|
|
|
dvb_fix_demuxes(priv, 0);
|
2015-01-06 19:19:49 +00:00
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
state->retry = 0;
|
2015-01-06 19:19:49 +00:00
|
|
|
//empty both the stream's and driver's buffer
|
2017-02-13 01:55:35 +00:00
|
|
|
while (dvb_streaming_read(stream, buf, sizeof(buf)) > 0) {}
|
2017-12-15 12:37:30 +00:00
|
|
|
if (state->cur_adapter != adapter ||
|
|
|
|
state->cur_frontend != channel->frontend) {
|
2015-01-06 19:19:49 +00:00
|
|
|
dvbin_close(stream);
|
2017-12-15 12:37:30 +00:00
|
|
|
if (!dvb_open_devices(priv, devno, channel->frontend, channel->pids_cnt)) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(stream, "DVB_SET_CHANNEL, COULDN'T OPEN DEVICES OF "
|
2017-02-13 01:55:35 +00:00
|
|
|
"ADAPTER: %d, EXIT\n", devno);
|
2015-01-06 19:19:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// close all demux_fds with pos > pids required for the new channel
|
|
|
|
// or open other demux_fds if we have too few
|
|
|
|
if (!dvb_fix_demuxes(priv, channel->pids_cnt))
|
2014-04-13 16:00:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
} else {
|
2017-12-15 12:37:30 +00:00
|
|
|
if (!dvb_open_devices(priv, devno, channel->frontend, channel->pids_cnt)) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(stream, "DVB_SET_CHANNEL2, COULDN'T OPEN DEVICES OF "
|
2017-02-13 01:55:35 +00:00
|
|
|
"ADAPTER: %d, EXIT\n", devno);
|
2015-01-06 19:19:49 +00:00
|
|
|
return 0;
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
state->retry = 5;
|
2015-01-06 19:19:49 +00:00
|
|
|
new_list->current = n;
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_VERBOSE(stream, "DVB_SET_CHANNEL: new channel name=%s, adapter: %d, "
|
|
|
|
"channel %d\n", channel->name, devno, n);
|
2015-01-06 19:19:49 +00:00
|
|
|
|
|
|
|
stream_drop_buffers(stream);
|
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
if (channel->freq != state->last_freq) {
|
2017-02-13 01:55:35 +00:00
|
|
|
if (!dvb_tune(priv, channel->delsys, channel->freq,
|
|
|
|
channel->pol, channel->srate, channel->diseqc,
|
|
|
|
channel->stream_id, channel->inv,
|
2015-01-06 19:19:49 +00:00
|
|
|
channel->mod, channel->gi,
|
|
|
|
channel->trans, channel->bw, channel->cr, channel->cr_lp,
|
|
|
|
channel->hier, priv->cfg_timeout))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
state->is_on = 1;
|
2017-12-15 12:37:30 +00:00
|
|
|
state->last_freq = channel->freq;
|
|
|
|
state->cur_adapter = adapter;
|
|
|
|
state->cur_frontend = channel->frontend;
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
if (channel->service_id != -1) {
|
|
|
|
/* We need the PMT-PID in addition.
|
|
|
|
If it has not yet beem resolved, do it now. */
|
|
|
|
for (i = 0; i < channel->pids_cnt; i++) {
|
2015-01-04 22:22:02 +00:00
|
|
|
if (channel->pids[i] == -1) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_VERBOSE(stream, "DVB_SET_CHANNEL: PMT-PID for service %d "
|
|
|
|
"not resolved yet, parsing PAT...\n",
|
|
|
|
channel->service_id);
|
2017-02-13 01:55:35 +00:00
|
|
|
int pmt_pid = dvb_get_pmt_pid(priv, adapter, channel->service_id);
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_VERBOSE(stream, "DVB_SET_CHANNEL: Found PMT-PID: %d\n",
|
|
|
|
pmt_pid);
|
|
|
|
channel->pids[i] = pmt_pid;
|
2015-01-04 22:22:02 +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
|
|
|
// sets demux filters and restart the stream
|
|
|
|
for (i = 0; i < channel->pids_cnt; i++) {
|
|
|
|
if (channel->pids[i] == -1) {
|
2015-01-04 22:22:02 +00:00
|
|
|
// In case PMT was not resolved, skip it here.
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(stream, "DVB_SET_CHANNEL: PMT-PID not found, "
|
|
|
|
"teletext-decoding may fail.\n");
|
|
|
|
} else {
|
2016-01-07 22:30:46 +00:00
|
|
|
if (!dvb_set_ts_filt(priv, state->demux_fds[i], channel->pids[i],
|
2015-01-06 19:19:49 +00:00
|
|
|
DMX_PES_OTHER))
|
|
|
|
return 0;
|
2014-04-13 16:00:51 +00:00
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2015-01-04 22:22:02 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return 1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2007-12-15 13:05:06 +00:00
|
|
|
int dvb_step_channel(stream_t *stream, int dir)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2017-02-13 01:55:35 +00:00
|
|
|
unsigned int new_current;
|
2015-01-06 19:19:49 +00:00
|
|
|
dvb_priv_t *priv = stream->priv;
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_state_t *state = priv->state;
|
|
|
|
dvb_channels_list_t *list = state->adapters[state->cur_adapter].list;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_VERBOSE(stream, "DVB_STEP_CHANNEL dir %d\n", dir);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
if (list == NULL) {
|
|
|
|
MP_ERR(stream, "dvb_step_channel: NULL list_ptr, quit\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
new_current = (list->NUM_CHANNELS + list->current +
|
|
|
|
(dir >= 0 ? 1 : -1)) % list->NUM_CHANNELS;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
return dvb_set_channel(stream, state->cur_adapter, new_current);
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
static int dvbin_stream_control(struct stream *s, int cmd, void *arg)
|
|
|
|
{
|
|
|
|
int r;
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_priv_t *priv = (dvb_priv_t *) s->priv;
|
|
|
|
dvb_state_t *state = priv->state;
|
|
|
|
dvb_channels_list_t *list = NULL;
|
|
|
|
|
|
|
|
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case STREAM_CTRL_DVB_SET_CHANNEL: {
|
2017-02-13 01:55:35 +00:00
|
|
|
unsigned int *iarg = arg;
|
|
|
|
MP_VERBOSE(s, "dvbin_stream_control: cmd STREAM_CTRL_DVB_SET_CHANNEL: %i, %i\n", iarg[1], iarg[0]);
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
r = dvb_set_channel(s, iarg[1], iarg[0]);
|
2016-01-07 22:55:15 +00:00
|
|
|
if (r) {
|
|
|
|
// Stream will be pulled down after channel switch,
|
|
|
|
// persist state.
|
|
|
|
state->switching_channel = true;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
return STREAM_ERROR;
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
case STREAM_CTRL_DVB_STEP_CHANNEL: {
|
|
|
|
MP_VERBOSE(s, "dvbin_stream_control: cmd STREAM_CTRL_DVB_STEP_CHANNEL: %i\n", (*(int *)arg));
|
|
|
|
r = dvb_step_channel(s, (*(int *)arg));
|
2016-01-08 19:19:57 +00:00
|
|
|
if (r) {
|
|
|
|
// Stream will be pulled down after channel switch,
|
|
|
|
// persist state.
|
|
|
|
state->switching_channel = true;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state->cur_adapter >= state->adapters_count)
|
|
|
|
return STREAM_ERROR;
|
|
|
|
list = state->adapters[state->cur_adapter].list;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case STREAM_CTRL_GET_TV_FREQ:
|
|
|
|
(*(unsigned int*)arg) = list->channels[list->current].freq;
|
|
|
|
return STREAM_ERROR;
|
|
|
|
case STREAM_CTRL_DVB_SET_CHANNEL_NAME: {
|
|
|
|
char *progname = *((char**)arg);
|
|
|
|
unsigned int new_channel = (~(unsigned int)0);
|
|
|
|
MP_VERBOSE(s, "dvbin_stream_control: cmd STREAM_CTRL_DVB_SET_CHANNEL_NAME: %s\n", progname);
|
|
|
|
for (unsigned int i=0; i < list->NUM_CHANNELS; ++i) {
|
|
|
|
if (!strcmp(list->channels[i].name, progname)) {
|
|
|
|
new_channel = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (new_channel == -1) {
|
|
|
|
MP_ERR(s, "Program '%s' not found for adapter %d!\n",
|
|
|
|
progname, state->adapters[state->cur_adapter].devno);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
r = dvb_set_channel(s, state->cur_adapter, new_channel);
|
2016-01-07 22:55:15 +00:00
|
|
|
if (r) {
|
|
|
|
// Stream will be pulled down after channel switch,
|
|
|
|
// persist state.
|
|
|
|
state->switching_channel = true;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
return STREAM_ERROR;
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
}
|
2016-01-08 19:19:57 +00:00
|
|
|
case STREAM_CTRL_DVB_GET_CHANNEL_NAME: {
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_VERBOSE(s, "dvbin_stream_control: cmd STREAM_CTRL_DVB_GET_CHANNEL_NAME\n");
|
|
|
|
char *progname = list->channels[list->current].name;
|
|
|
|
*(char **)arg = talloc_strdup(NULL, progname);
|
|
|
|
return STREAM_OK;
|
2016-01-08 19:19:57 +00:00
|
|
|
}
|
2016-01-08 02:31:29 +00:00
|
|
|
case STREAM_CTRL_GET_METADATA: {
|
2017-02-13 01:55:35 +00:00
|
|
|
struct mp_tags *metadata = talloc_zero(NULL, struct mp_tags);
|
|
|
|
char *progname = list->channels[list->current].name;
|
|
|
|
mp_tags_set_str(metadata, "title", progname);
|
|
|
|
*(struct mp_tags **)arg = metadata;
|
|
|
|
return STREAM_OK;
|
2016-01-08 02:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
void dvbin_close(stream_t *stream)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2015-01-06 19:19:49 +00:00
|
|
|
dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_state_t *state = priv->state;
|
2016-01-08 17:37:30 +00:00
|
|
|
|
2016-01-07 22:55:15 +00:00
|
|
|
if (state->switching_channel && state->is_on) {
|
2016-01-22 10:55:47 +00:00
|
|
|
// Prevent state destruction, reset channel-switch.
|
2016-01-07 22:55:15 +00:00
|
|
|
state->switching_channel = false;
|
2016-01-08 17:37:30 +00:00
|
|
|
pthread_mutex_lock(&global_dvb_state_lock);
|
|
|
|
global_dvb_state->stream_used = false;
|
|
|
|
pthread_mutex_unlock(&global_dvb_state_lock);
|
2016-01-07 22:55:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-01-22 10:55:47 +00:00
|
|
|
|
2016-01-07 22:55:15 +00:00
|
|
|
for (int i = state->demux_fds_cnt - 1; i >= 0; i--) {
|
2016-01-07 22:30:46 +00:00
|
|
|
state->demux_fds_cnt--;
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_VERBOSE(stream, "DVBIN_CLOSE, close(%d), fd=%d, COUNT=%d\n", i,
|
2016-01-07 22:30:46 +00:00
|
|
|
state->demux_fds[i], state->demux_fds_cnt);
|
|
|
|
close(state->demux_fds[i]);
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2016-01-07 22:30:46 +00:00
|
|
|
close(state->dvr_fd);
|
|
|
|
close(state->fe_fd);
|
|
|
|
state->fe_fd = state->dvr_fd = -1;
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
state->is_on = 0;
|
2017-12-15 12:37:30 +00:00
|
|
|
state->cur_adapter = -1;
|
|
|
|
state->cur_frontend = -1;
|
2016-01-22 10:55:47 +00:00
|
|
|
|
2016-01-08 17:37:30 +00:00
|
|
|
pthread_mutex_lock(&global_dvb_state_lock);
|
2016-01-07 22:30:46 +00:00
|
|
|
dvb_free_state(state);
|
2016-01-07 22:55:15 +00:00
|
|
|
global_dvb_state = NULL;
|
2016-01-08 17:37:30 +00:00
|
|
|
pthread_mutex_unlock(&global_dvb_state_lock);
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
static int dvb_streaming_start(stream_t *stream, char *progname)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2015-01-06 19:19:49 +00:00
|
|
|
int i;
|
|
|
|
dvb_channel_t *channel = NULL;
|
|
|
|
dvb_priv_t *priv = stream->priv;
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_state_t *state = priv->state;
|
|
|
|
dvb_channels_list_t *list;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (progname == NULL)
|
|
|
|
return 0;
|
|
|
|
MP_VERBOSE(stream, "\r\ndvb_streaming_start(PROG: %s, ADAPTER: %d)\n",
|
|
|
|
progname, priv->cfg_devno);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
state->is_on = 0;
|
2017-02-13 01:55:35 +00:00
|
|
|
list = state->adapters[state->cur_adapter].list;
|
|
|
|
for (i = 0; i < list->NUM_CHANNELS; i ++) {
|
|
|
|
if (!strcmp(list->channels[i].name, progname)) {
|
|
|
|
channel = &(list->channels[i]);
|
|
|
|
break;
|
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (channel == NULL) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(stream, "\n\nDVBIN: no such channel \"%s\"\n\n", progname);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
list->current = i;
|
|
|
|
MP_VERBOSE(stream, "PROGRAM NUMBER %d: name=%s, freq=%u\n", i,
|
|
|
|
channel->name, channel->freq);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (!dvb_set_channel(stream, state->cur_adapter, list->current)) {
|
|
|
|
MP_ERR(stream, "ERROR, COULDN'T SET CHANNEL %i: \"%s\"\n", list->current, progname);
|
2015-01-06 19:19:49 +00:00
|
|
|
dvbin_close(stream);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_VERBOSE(stream, "SUCCESSFUL EXIT from dvb_streaming_start\n");
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return 1;
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-24 12:06:13 +00:00
|
|
|
static int dvb_open(stream_t *stream)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2016-01-07 22:55:15 +00:00
|
|
|
// I don't force the file format because, although it's almost always TS,
|
2015-01-06 19:19:49 +00:00
|
|
|
// there are some providers that stream an IP multicast with M$ Mpeg4 inside
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_priv_t *priv = NULL;
|
2015-01-06 19:19:49 +00:00
|
|
|
char *progname;
|
2017-02-13 01:55:35 +00:00
|
|
|
int i;
|
2015-01-06 19:19:49 +00:00
|
|
|
|
2016-01-08 17:37:30 +00:00
|
|
|
pthread_mutex_lock(&global_dvb_state_lock);
|
|
|
|
if (global_dvb_state && global_dvb_state->stream_used) {
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_ERR(stream, "DVB stream already in use, only one DVB stream can exist at a time!\n");
|
2016-01-08 17:37:30 +00:00
|
|
|
pthread_mutex_unlock(&global_dvb_state_lock);
|
2017-02-13 01:55:35 +00:00
|
|
|
goto err_out;
|
2016-01-08 17:37:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
// Need to re-get config in any case, not part of global state.
|
2017-02-10 00:08:02 +00:00
|
|
|
stream->priv = mp_get_config_group(stream, stream->global, &stream_dvb_conf);
|
2017-02-13 01:55:35 +00:00
|
|
|
dvb_state_t *state = dvb_get_state(stream);
|
2016-09-09 15:35:25 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
priv->state = state;
|
|
|
|
priv->log = stream->log;
|
2016-01-07 22:30:46 +00:00
|
|
|
if (state == NULL) {
|
2015-01-06 19:19:49 +00:00
|
|
|
MP_ERR(stream, "DVB CONFIGURATION IS EMPTY, exit\n");
|
2016-01-24 19:20:08 +00:00
|
|
|
pthread_mutex_unlock(&global_dvb_state_lock);
|
2017-02-13 01:55:35 +00:00
|
|
|
goto err_out;
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
2016-01-24 19:20:08 +00:00
|
|
|
state->stream_used = true;
|
|
|
|
pthread_mutex_unlock(&global_dvb_state_lock);
|
2006-11-26 12:03:23 +00:00
|
|
|
|
2016-01-07 22:55:15 +00:00
|
|
|
if (state->is_on != 1) {
|
2016-01-22 10:55:47 +00:00
|
|
|
// State could be already initialized, for example, we just did a channel switch.
|
|
|
|
// The following setup only has to be done once.
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
state->cur_adapter = -1;
|
2017-12-15 12:37:30 +00:00
|
|
|
state->cur_frontend = -1;
|
2017-02-13 01:55:35 +00:00
|
|
|
for (i = 0; i < state->adapters_count; i++) {
|
|
|
|
if (state->adapters[i].devno == priv->cfg_devno) {
|
|
|
|
state->cur_adapter = i;
|
2016-01-07 22:55:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (state->cur_adapter == -1) {
|
|
|
|
MP_ERR(stream, "NO CONFIGURATION FOUND FOR ADAPTER N. %d, exit\n",
|
|
|
|
priv->cfg_devno);
|
|
|
|
goto err_out;
|
2016-01-07 22:55:15 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
state->timeout = priv->cfg_timeout;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_VERBOSE(stream, "OPEN_DVB: prog=%s, devno=%d\n",
|
|
|
|
priv->cfg_prog, state->adapters[state->cur_adapter].devno);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if ((priv->cfg_prog == NULL || priv->cfg_prog[0] == 0) &&
|
|
|
|
state->adapters[state->cur_adapter].list != NULL) {
|
|
|
|
progname = state->adapters[state->cur_adapter].list->channels[0].name;
|
2016-01-07 22:55:15 +00:00
|
|
|
} else {
|
2017-02-13 01:55:35 +00:00
|
|
|
progname = priv->cfg_prog;
|
2016-01-07 22:55:15 +00:00
|
|
|
}
|
2004-04-26 21:19:21 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (!dvb_streaming_start(stream, progname))
|
|
|
|
goto err_out;
|
2016-01-07 22:55:15 +00:00
|
|
|
}
|
2016-01-22 10:55:47 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
stream->fill_buffer = dvb_streaming_read;
|
|
|
|
stream->close = dvbin_close;
|
|
|
|
stream->control = dvbin_stream_control;
|
|
|
|
stream->streaming = true;
|
2017-02-13 01:55:35 +00:00
|
|
|
stream->allow_caching = true;
|
2015-01-06 19:19:49 +00:00
|
|
|
stream->demuxer = "lavf";
|
|
|
|
stream->lavf_type = "mpegts";
|
2004-04-26 21:19:21 +00:00
|
|
|
|
2015-01-06 19:19:49 +00:00
|
|
|
return STREAM_OK;
|
2017-02-13 01:55:35 +00:00
|
|
|
|
|
|
|
err_out:
|
|
|
|
talloc_free(priv);
|
|
|
|
stream->priv = NULL;
|
|
|
|
return STREAM_ERROR;
|
2004-04-26 21:19:21 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
dvb_state_t *dvb_get_state(stream_t *stream)
|
2004-04-26 21:19:21 +00:00
|
|
|
{
|
2016-01-07 22:55:15 +00:00
|
|
|
if (global_dvb_state != NULL) {
|
|
|
|
return global_dvb_state;
|
|
|
|
}
|
2015-01-06 19:19:49 +00:00
|
|
|
struct mp_log *log = stream->log;
|
|
|
|
struct mpv_global *global = stream->global;
|
|
|
|
dvb_priv_t *priv = stream->priv;
|
2017-12-15 12:37:30 +00:00
|
|
|
unsigned int delsys, delsys_mask[MAX_FRONTENDS], size;
|
2017-02-13 01:55:35 +00:00
|
|
|
char filename[PATH_MAX], *conf_file;
|
|
|
|
const char *conf_file_name;
|
|
|
|
void *talloc_ctx;
|
|
|
|
dvb_channels_list_t *list;
|
|
|
|
dvb_adapter_config_t *adapters = NULL, *tmp;
|
2016-01-07 22:30:46 +00:00
|
|
|
dvb_state_t *state = NULL;
|
2017-02-13 01:55:35 +00:00
|
|
|
bstr prog, devno;
|
2015-01-06 19:19:49 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (!bstr_split_tok(bstr0(stream->path), "@", &devno, &prog)) {
|
|
|
|
prog = devno;
|
|
|
|
devno.len = 0;
|
2016-09-09 15:35:25 +00:00
|
|
|
}
|
|
|
|
if (prog.len) {
|
|
|
|
talloc_free(priv->cfg_prog);
|
|
|
|
priv->cfg_prog = bstrto0(NULL, prog);
|
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
if (devno.len) {
|
2016-09-09 15:35:25 +00:00
|
|
|
bstr r;
|
2017-02-13 01:55:35 +00:00
|
|
|
priv->cfg_devno = bstrtoll(devno, &r, 0);
|
|
|
|
if (r.len || priv->cfg_devno < 0 || priv->cfg_devno > MAX_ADAPTERS) {
|
|
|
|
MP_ERR(stream, "invalid devno: '%.*s'\n", BSTR_P(devno));
|
2016-09-09 15:35:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
MP_VERBOSE(stream, "DVB_CONFIG: prog=%s, devno=%d\n",
|
|
|
|
priv->cfg_prog, priv->cfg_devno);
|
|
|
|
|
2016-01-07 22:30:46 +00:00
|
|
|
state = malloc(sizeof(dvb_state_t));
|
|
|
|
if (state == NULL)
|
2015-01-06 19:19:49 +00:00
|
|
|
return NULL;
|
2017-02-13 01:55:35 +00:00
|
|
|
memset(state, 0x00, sizeof(dvb_state_t));
|
2016-01-07 22:55:15 +00:00
|
|
|
state->switching_channel = false;
|
2016-01-08 17:37:30 +00:00
|
|
|
state->stream_used = true;
|
2016-01-07 22:30:46 +00:00
|
|
|
state->fe_fd = state->dvr_fd = -1;
|
2017-12-15 12:37:30 +00:00
|
|
|
for (unsigned int i = 0; i < MAX_ADAPTERS; i++) {
|
2017-02-13 01:55:35 +00:00
|
|
|
list = NULL;
|
2017-12-15 12:37:30 +00:00
|
|
|
for (unsigned int f = 0; f < MAX_FRONTENDS; f++) {
|
|
|
|
snprintf(filename, sizeof(filename), "/dev/dvb/adapter%u/frontend%u", i, f);
|
|
|
|
int fd = open(filename, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
|
|
|
if (fd < 0)
|
2017-02-13 01:55:35 +00:00
|
|
|
continue;
|
2017-12-15 12:37:30 +00:00
|
|
|
|
|
|
|
mp_verbose(log, "Opened device %s, FD: %d\n", filename, fd);
|
|
|
|
delsys_mask[f] = dvb_get_tuner_delsys_mask(fd, log);
|
|
|
|
delsys_mask[f] &= DELSYS_SUPP_MASK; /* Filter unsupported delivery systems. */
|
|
|
|
close(fd);
|
|
|
|
if (delsys_mask[f] == 0) {
|
|
|
|
mp_verbose(log, "Frontend device %s has no supported delivery systems.\n",
|
|
|
|
filename);
|
|
|
|
continue; /* Skip tuner. */
|
2017-02-14 12:30:59 +00:00
|
|
|
}
|
2017-12-15 12:37:30 +00:00
|
|
|
mp_verbose(log, "Frontend device %s offers some supported delivery systems.\n",
|
|
|
|
filename);
|
|
|
|
/* Create channel list for adapter. */
|
|
|
|
for (delsys = 0; delsys < SYS_DVB__COUNT__; delsys++) {
|
|
|
|
if (!DELSYS_IS_SET(delsys_mask[f], delsys))
|
|
|
|
continue; /* Skip unsupported. */
|
|
|
|
|
|
|
|
switch (delsys) {
|
|
|
|
case SYS_DVBC_ANNEX_A:
|
|
|
|
case SYS_DVBC_ANNEX_C:
|
|
|
|
conf_file_name = "channels.conf.cbl";
|
|
|
|
break;
|
|
|
|
case SYS_ATSC:
|
|
|
|
conf_file_name = "channels.conf.atsc";
|
|
|
|
break;
|
|
|
|
case SYS_DVBT:
|
|
|
|
if (DELSYS_IS_SET(delsys_mask[f], SYS_DVBT2))
|
|
|
|
continue; /* Add all channels later with T2. */
|
|
|
|
/* PASSTOUTH */
|
|
|
|
case SYS_DVBT2:
|
|
|
|
conf_file_name = "channels.conf.ter";
|
|
|
|
break;
|
|
|
|
case SYS_DVBS:
|
|
|
|
if (DELSYS_IS_SET(delsys_mask[f], SYS_DVBS2))
|
|
|
|
continue; /* Add all channels later with S2. */
|
|
|
|
/* PASSTOUTH */
|
|
|
|
case SYS_DVBS2:
|
|
|
|
conf_file_name = "channels.conf.sat";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
|
2017-12-15 12:37:30 +00:00
|
|
|
if (priv->cfg_file && priv->cfg_file[0]) {
|
|
|
|
talloc_ctx = NULL;
|
|
|
|
conf_file = priv->cfg_file;
|
2017-02-13 01:55:35 +00:00
|
|
|
} else {
|
2017-12-15 12:37:30 +00:00
|
|
|
talloc_ctx = talloc_new(NULL);
|
|
|
|
conf_file = mp_find_config_file(talloc_ctx, global, conf_file_name);
|
|
|
|
if (conf_file) {
|
|
|
|
mp_verbose(log, "Ignoring other channels.conf files.\n");
|
|
|
|
} else {
|
|
|
|
conf_file = mp_find_config_file(talloc_ctx, global,
|
|
|
|
"channels.conf");
|
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
}
|
2004-04-03 10:30:46 +00:00
|
|
|
|
2017-12-15 12:37:30 +00:00
|
|
|
list = dvb_get_channels(log, list, priv->cfg_full_transponder,
|
|
|
|
conf_file, f, delsys, delsys_mask[f]);
|
|
|
|
talloc_free(talloc_ctx);
|
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
}
|
|
|
|
/* Add adapter with non zero channel list. */
|
|
|
|
if (list == NULL)
|
2015-01-06 19:19:49 +00:00
|
|
|
continue;
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
size = sizeof(dvb_adapter_config_t) * (state->adapters_count + 1);
|
|
|
|
tmp = realloc(state->adapters, size);
|
2014-04-13 16:00:51 +00:00
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (tmp == NULL) {
|
2016-01-18 23:18:08 +00:00
|
|
|
mp_err(log, "DVB_CONFIG, can't realloc %d bytes, skipping\n",
|
|
|
|
size);
|
2016-02-12 14:49:44 +00:00
|
|
|
free(list);
|
2015-01-06 19:19:49 +00:00
|
|
|
continue;
|
2017-02-14 12:30:59 +00:00
|
|
|
}
|
2017-02-13 01:55:35 +00:00
|
|
|
adapters = tmp;
|
|
|
|
|
|
|
|
state->adapters = adapters;
|
|
|
|
state->adapters[state->adapters_count].devno = i;
|
2017-12-15 12:37:30 +00:00
|
|
|
memcpy(&state->adapters[state->adapters_count].delsys_mask,
|
|
|
|
&delsys_mask, (sizeof(unsigned int) * MAX_FRONTENDS));
|
2017-02-13 01:55:35 +00:00
|
|
|
state->adapters[state->adapters_count].list = list;
|
|
|
|
state->adapters_count++;
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 01:55:35 +00:00
|
|
|
if (state->adapters_count == 0) {
|
2016-01-07 22:30:46 +00:00
|
|
|
free(state);
|
|
|
|
state = NULL;
|
2015-01-06 19:19:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 22:55:15 +00:00
|
|
|
global_dvb_state = state;
|
2016-01-07 22:30:46 +00:00
|
|
|
return state;
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2007-12-02 13:22:53 +00:00
|
|
|
const stream_info_t stream_info_dvb = {
|
stream: fix url_options field, make protocols field not fixed length
The way the url_options field was handled was not entirely sane: it's
actually a flexible array member, so it points to garbage for streams
which do not initialize this member (it just points to the data right
after the struct, which is garbage in theory and practice). This was
not actually a problem, since the field is only used if priv_size is
set (due to how this stuff is used). But it doesn't allow setting
priv_size only, which might be useful in some cases.
Also, make the protocols array not a fixed size array. Most stream
implementations have only 1 protocol prefix, but stream_lavf.c has
over 10 (whitelists ffmpeg protocols). The high size of the fixed
size protocol array wastes space, and it is _still_ annoying to
add new prefixes to stream_lavf (have to bump the maximum length),
so make it arbitrary length.
The two changes (plus some more cosmetic changes) arte conflated into
one, because it was annoying going over all the stream implementations.
2013-08-25 20:49:27 +00:00
|
|
|
.name = "dvbin",
|
|
|
|
.open = dvb_open,
|
2015-01-06 19:19:49 +00:00
|
|
|
.protocols = (const char *const[]){ "dvb", NULL },
|
2003-08-11 00:02:46 +00:00
|
|
|
};
|