2003-03-16 20:13:28 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
dvbstream
|
|
|
|
(C) Dave Chapman <dave@dchapman.com> 2001, 2002.
|
|
|
|
|
2013-07-12 20:11:08 +00:00
|
|
|
Original authors: Nico, probably Arpi
|
|
|
|
|
2013-10-12 23:18:50 +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
|
|
|
|
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
|
|
|
Copyright notice:
|
|
|
|
|
|
|
|
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
|
2007-01-22 08:02:06 +00:00
|
|
|
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 <ctype.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>
|
|
|
|
|
2013-11-30 21:40:51 +00:00
|
|
|
#include <libavutil/avstring.h>
|
|
|
|
|
|
|
|
#include "osdep/io.h"
|
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
#include "stream.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
#define MAX_CHANNELS 8
|
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
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
//TODO: CAMBIARE list_ptr e da globale a per_priv
|
|
|
|
|
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
static dvb_priv_t stream_defaults = {
|
|
|
|
.cfg_prog = "",
|
|
|
|
.cfg_card = 1,
|
|
|
|
.cfg_timeout = 30,
|
2003-08-11 00:02:46 +00:00
|
|
|
};
|
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
#define OPT_BASE_STRUCT dvb_priv_t
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
/// URL definition
|
2007-12-02 21:37:08 +00:00
|
|
|
static const m_option_t stream_params[] = {
|
2013-08-02 15:02:34 +00:00
|
|
|
OPT_STRING("prog", cfg_prog, 0),
|
|
|
|
OPT_INTRANGE("card", cfg_card, 0, 1, 4),
|
|
|
|
{0}
|
2003-08-11 00:02:46 +00:00
|
|
|
};
|
|
|
|
|
2007-12-02 21:26:23 +00:00
|
|
|
const m_option_t dvbin_opts_conf[] = {
|
2013-08-02 15:02:34 +00:00
|
|
|
{"prog", &stream_defaults.cfg_prog, CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
|
|
{"card", &stream_defaults.cfg_card, CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},
|
|
|
|
{"timeout", &stream_defaults.cfg_timeout, CONF_TYPE_INT, M_OPT_RANGE, 1, 30, NULL},
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
static dvb_channels_list *dvb_get_channels(struct mp_log *log, char *filename, int type)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
|
|
|
dvb_channels_list *list;
|
|
|
|
FILE *f;
|
2005-09-18 19:17:23 +00:00
|
|
|
char line[CHANNEL_LINE_LEN], *colon;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2013-02-08 22:50:21 +00:00
|
|
|
if (!filename)
|
|
|
|
return NULL;
|
|
|
|
|
2005-09-18 19:17:23 +00:00
|
|
|
int fields, cnt, pcnt, k;
|
2007-01-06 11:09:27 +00:00
|
|
|
int has8192, has0;
|
2004-04-26 21:19:21 +00:00
|
|
|
dvb_channel_t *ptr, *tmp, chn;
|
2005-09-18 19:17:23 +00:00
|
|
|
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];
|
|
|
|
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";
|
|
|
|
const char *atsc_conf = "%d:%255[^:]:%255[^:]:%255[^:]\n";
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "CONFIG_READ FILE: %s, type: %d\n", filename, type);
|
2004-04-26 21:19:21 +00:00
|
|
|
if((f=fopen(filename, "r"))==NULL)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_fatal(log, "CAN'T READ CONFIG FILE %s\n", filename);
|
2004-04-26 21:19:21 +00:00
|
|
|
return NULL;
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
list = malloc(sizeof(dvb_channels_list));
|
|
|
|
if(list == NULL)
|
|
|
|
{
|
2006-03-12 11:45:27 +00:00
|
|
|
fclose(f);
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "DVB_GET_CHANNELS: couldn't malloc enough memory\n");
|
2003-03-16 20:13:28 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
ptr = &chn;
|
2003-03-16 20:13:28 +00:00
|
|
|
list->NUM_CHANNELS = 0;
|
2004-04-26 21:19:21 +00:00
|
|
|
list->channels = NULL;
|
|
|
|
while(! feof(f))
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2003-08-27 17:08:58 +00:00
|
|
|
if( fgets(line, CHANNEL_LINE_LEN, f) == NULL )
|
|
|
|
continue;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-08-27 17:08:58 +00:00
|
|
|
if((line[0] == '#') || (strlen(line) == 0))
|
2003-08-11 00:02:46 +00:00
|
|
|
continue;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2006-12-03 21:17:51 +00:00
|
|
|
colon = strchr(line, ':');
|
2005-09-18 19:17:23 +00:00
|
|
|
if(colon)
|
|
|
|
{
|
|
|
|
k = colon - line;
|
|
|
|
if(!k)
|
|
|
|
continue;
|
2007-06-24 13:27:03 +00:00
|
|
|
ptr->name = malloc(k+1);
|
2005-09-18 19:17:23 +00:00
|
|
|
if(! ptr->name)
|
|
|
|
continue;
|
2007-07-05 22:01:07 +00:00
|
|
|
av_strlcpy(ptr->name, line, k+1);
|
2005-09-18 19:17:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
k++;
|
|
|
|
apid_str[0] = vpid_str[0] = 0;
|
2004-07-12 20:52:02 +00:00
|
|
|
ptr->pids_cnt = 0;
|
2005-09-18 19:17:23 +00:00
|
|
|
ptr->freq = 0;
|
2003-08-11 00:02:46 +00:00
|
|
|
if(type == TUNER_TER)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2005-09-18 19:17:23 +00:00
|
|
|
fields = sscanf(&line[k], ter_conf,
|
|
|
|
&ptr->freq, inv, bw, cr, tmp_lcr, mod,
|
|
|
|
transm, gi, tmp_hier, vpid_str, apid_str);
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "TER, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d",
|
2004-07-12 20:52:02 +00:00
|
|
|
list->NUM_CHANNELS, fields, ptr->name, ptr->freq);
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
|
|
|
else if(type == TUNER_CBL)
|
|
|
|
{
|
2005-09-18 19:17:23 +00:00
|
|
|
fields = sscanf(&line[k], cbl_conf,
|
|
|
|
&ptr->freq, inv, &ptr->srate,
|
|
|
|
cr, mod, vpid_str, apid_str);
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "CBL, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d",
|
2004-07-12 20:52:02 +00:00
|
|
|
list->NUM_CHANNELS, fields, ptr->name, ptr->freq, ptr->srate);
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2005-01-06 09:43:10 +00:00
|
|
|
#ifdef DVB_ATSC
|
|
|
|
else if(type == TUNER_ATSC)
|
|
|
|
{
|
2005-09-18 19:17:23 +00:00
|
|
|
fields = sscanf(&line[k], atsc_conf,
|
|
|
|
&ptr->freq, mod, vpid_str, apid_str);
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "ATSC, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d\n",
|
2005-01-06 09:43:10 +00:00
|
|
|
list->NUM_CHANNELS, fields, ptr->name, ptr->freq);
|
|
|
|
}
|
|
|
|
#endif
|
2003-08-11 00:02:46 +00:00
|
|
|
else //SATELLITE
|
|
|
|
{
|
2005-09-18 19:17:23 +00:00
|
|
|
fields = sscanf(&line[k], sat_conf,
|
|
|
|
&ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate, vpid_str, apid_str);
|
2003-08-11 00:02:46 +00:00
|
|
|
ptr->pol = toupper(ptr->pol);
|
|
|
|
ptr->freq *= 1000UL;
|
|
|
|
ptr->srate *= 1000UL;
|
|
|
|
ptr->tone = -1;
|
2004-03-19 20:22:10 +00:00
|
|
|
ptr->inv = INVERSION_AUTO;
|
|
|
|
ptr->cr = FEC_AUTO;
|
2004-04-04 17:11:37 +00:00
|
|
|
if((ptr->diseqc > 4) || (ptr->diseqc < 0))
|
2004-03-19 20:22:10 +00:00
|
|
|
continue;
|
2004-04-04 17:11:37 +00:00
|
|
|
if(ptr->diseqc > 0)
|
|
|
|
ptr->diseqc--;
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "SAT, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d, POL: %c, DISEQC: %d",
|
2004-07-12 20:52:02 +00:00
|
|
|
list->NUM_CHANNELS, fields, ptr->name, ptr->freq, ptr->srate, ptr->pol, ptr->diseqc);
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2005-09-18 19:17:23 +00:00
|
|
|
if(vpid_str[0])
|
2004-07-12 20:52:02 +00:00
|
|
|
{
|
|
|
|
pcnt = sscanf(vpid_str, "%d+%d+%d+%d+%d+%d+%d", &ptr->pids[0], &ptr->pids[1], &ptr->pids[2], &ptr->pids[3],
|
|
|
|
&ptr->pids[4], &ptr->pids[5], &ptr->pids[6]);
|
|
|
|
if(pcnt > 0)
|
|
|
|
{
|
|
|
|
ptr->pids_cnt = pcnt;
|
|
|
|
fields++;
|
|
|
|
}
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2005-09-18 19:17:23 +00:00
|
|
|
if(apid_str[0])
|
2004-07-12 20:52:02 +00:00
|
|
|
{
|
|
|
|
cnt = ptr->pids_cnt;
|
|
|
|
pcnt = sscanf(apid_str, "%d+%d+%d+%d+%d+%d+%d+%d", &ptr->pids[cnt], &ptr->pids[cnt+1], &ptr->pids[cnt+2],
|
|
|
|
&ptr->pids[cnt+3], &ptr->pids[cnt+4], &ptr->pids[cnt+5], &ptr->pids[cnt+6], &ptr->pids[cnt+7]);
|
|
|
|
if(pcnt > 0)
|
|
|
|
{
|
|
|
|
ptr->pids_cnt += pcnt;
|
|
|
|
fields++;
|
|
|
|
}
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2005-09-18 19:17:23 +00:00
|
|
|
if((fields < 2) || (ptr->pids_cnt <= 0) || (ptr->freq == 0) || (strlen(ptr->name) == 0))
|
2003-08-27 17:08:58 +00:00
|
|
|
continue;
|
|
|
|
|
2007-01-06 11:09:27 +00:00
|
|
|
has8192 = has0 = 0;
|
2006-11-19 12:05:11 +00:00
|
|
|
for(cnt = 0; cnt < ptr->pids_cnt; cnt++)
|
|
|
|
{
|
|
|
|
if(ptr->pids[cnt] == 8192)
|
|
|
|
has8192 = 1;
|
2007-01-06 11:09:27 +00:00
|
|
|
if(ptr->pids[cnt] == 0)
|
|
|
|
has0 = 1;
|
2006-11-19 12:05:11 +00:00
|
|
|
}
|
|
|
|
if(has8192)
|
|
|
|
{
|
|
|
|
ptr->pids[0] = 8192;
|
|
|
|
ptr->pids_cnt = 1;
|
|
|
|
}
|
2007-01-06 11:09:27 +00:00
|
|
|
else if(! has0)
|
2006-11-19 12:05:11 +00:00
|
|
|
{
|
2006-11-19 12:06:28 +00:00
|
|
|
ptr->pids[ptr->pids_cnt] = 0; //PID 0 is the PAT
|
|
|
|
ptr->pids_cnt++;
|
2006-11-19 12:05:11 +00:00
|
|
|
}
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, " PIDS: ");
|
2004-07-12 20:52:02 +00:00
|
|
|
for(cnt = 0; cnt < ptr->pids_cnt; cnt++)
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, " %d ", ptr->pids[cnt]);
|
|
|
|
mp_verbose(log, "\n");
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
if((type == TUNER_TER) || (type == TUNER_CBL))
|
|
|
|
{
|
2003-03-16 20:13:28 +00:00
|
|
|
if(! strcmp(inv, "INVERSION_ON"))
|
|
|
|
ptr->inv = INVERSION_ON;
|
|
|
|
else if(! strcmp(inv, "INVERSION_OFF"))
|
|
|
|
ptr->inv = INVERSION_OFF;
|
|
|
|
else
|
|
|
|
ptr->inv = INVERSION_AUTO;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
else ptr->cr =FEC_AUTO;
|
2005-01-06 09:43:10 +00:00
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2005-01-06 09:43:10 +00:00
|
|
|
if((type == TUNER_TER) || (type == TUNER_CBL) || (type == TUNER_ATSC))
|
|
|
|
{
|
2003-03-16 20:13:28 +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
|
2005-01-06 09:43:10 +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;
|
2009-10-30 10:03:54 +00:00
|
|
|
else if(! strcmp(mod, "QAM_AUTO"))
|
|
|
|
ptr->mod = QAM_AUTO;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2005-01-06 09:43:10 +00:00
|
|
|
#endif
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
if(type == TUNER_TER)
|
|
|
|
{
|
|
|
|
if(! strcmp(bw, "BANDWIDTH_6_MHZ"))
|
|
|
|
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;
|
2003-03-16 20:13:28 +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;
|
2009-10-30 10:03:54 +00:00
|
|
|
else if(! strcmp(transm, "TRANSMISSION_MODE_AUTO"))
|
|
|
|
ptr->trans = TRANSMISSION_MODE_AUTO;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
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;
|
2009-10-30 10:03:54 +00:00
|
|
|
else if(! strcmp(gi, "GUARD_INTERVAL_1_4"))
|
|
|
|
ptr->gi = GUARD_INTERVAL_1_4;
|
|
|
|
else ptr->gi = GUARD_INTERVAL_AUTO;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-08-26 19:38:16 +00:00
|
|
|
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;
|
|
|
|
else ptr->cr_lp =FEC_AUTO;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
|
|
|
|
2004-08-26 19:38:16 +00:00
|
|
|
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;
|
|
|
|
else if(! strcmp(tmp_hier, "HIERARCHY_AUTO"))
|
|
|
|
ptr->hier = HIERARCHY_AUTO;
|
|
|
|
else ptr->hier = HIERARCHY_NONE;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 13:27:03 +00:00
|
|
|
tmp = realloc(list->channels, sizeof(dvb_channel_t) * (list->NUM_CHANNELS + 1));
|
2004-04-26 21:19:21 +00:00
|
|
|
if(tmp == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
list->channels = tmp;
|
|
|
|
memcpy(&(list->channels[list->NUM_CHANNELS]), ptr, sizeof(dvb_channel_t));
|
2003-03-16 20:13:28 +00:00
|
|
|
list->NUM_CHANNELS++;
|
2006-05-13 09:01:18 +00:00
|
|
|
if(sizeof(dvb_channel_t) * list->NUM_CHANNELS >= 1024*1024)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "dvbin.c, > 1MB allocated for channels struct, dropping the rest of the file\r\n");
|
2006-05-13 09:01:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
2004-04-26 21:19:21 +00:00
|
|
|
if(list->NUM_CHANNELS == 0)
|
|
|
|
{
|
2010-11-07 12:47:40 +00:00
|
|
|
free(list->channels);
|
2004-04-26 21:19:21 +00:00
|
|
|
free(list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
list->current = 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2007-12-15 13:30:44 +00:00
|
|
|
void dvb_free_config(dvb_config_t *config)
|
|
|
|
{
|
2007-12-15 21:06:58 +00:00
|
|
|
int i, j;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
for(i=0; i<config->count; i++)
|
2007-12-15 13:30:44 +00:00
|
|
|
{
|
2010-11-07 12:47:40 +00:00
|
|
|
free(config->cards[i].name);
|
2007-12-15 13:30:44 +00:00
|
|
|
if(!config->cards[i].list)
|
|
|
|
continue;
|
|
|
|
if(config->cards[i].list->channels)
|
|
|
|
{
|
2007-12-15 21:06:58 +00:00
|
|
|
for(j=0; j<config->cards[i].list->NUM_CHANNELS; j++)
|
2010-11-07 12:47:40 +00:00
|
|
|
free(config->cards[i].list->channels[j].name);
|
2007-12-15 13:30:44 +00:00
|
|
|
free(config->cards[i].list->channels);
|
|
|
|
}
|
|
|
|
free(config->cards[i].list);
|
2009-05-13 02:58:57 +00:00
|
|
|
}
|
2007-12-15 13:30:44 +00:00
|
|
|
free(config);
|
|
|
|
}
|
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
|
|
|
{
|
2003-08-11 00:02:46 +00:00
|
|
|
struct pollfd pfds[1];
|
2004-07-12 20:52:02 +00:00
|
|
|
int pos=0, tries, rk, fd;
|
2003-08-11 00:02:46 +00:00
|
|
|
dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_TRACE(stream, "dvb_streaming_read(%d)\n", size);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2003-11-01 15:17:01 +00:00
|
|
|
tries = priv->retry + 1;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
stream: remove fd member
Stream implementations could set this to a unix file descriptor. The
generic stream code could use it as fallback for a few things. This
was confusing and insane. In most cases, the stream implementations
defined all callbacks, so setting the fd member didn't have any
advantages, other than avoiding defining a private struct to store it.
It appears that even if the stream implementation used close() on the
fd (or something equivalent), stream.c would close() it a second time
(and on windows, even would call closesocket()), which should be proof
for the insanity of this code.
For stream_file.c, additionally make sure we don't close stdin or
stdout if "-" is used as filename.
For stream_vcd.c, remove the control() code. This code most likely
didn't make the slightest sense, because it used a different type
for stream->priv. It also leaked memory. Maybe it worked, but it's
incorrect and insignificant anyway, so kill it. This code was added
with commit 9521c19 (svn commit 31019).
Untested for all protocols other than stream_file.c.
2013-07-12 20:07:07 +00:00
|
|
|
fd = priv->fd;
|
2003-08-11 00:02:46 +00:00
|
|
|
while(pos < size)
|
|
|
|
{
|
|
|
|
pfds[0].fd = fd;
|
|
|
|
pfds[0].events = POLLIN | POLLPRI;
|
|
|
|
|
|
|
|
rk = size - pos;
|
2005-04-18 19:49:40 +00:00
|
|
|
if(poll(pfds, 1, 500) <= 0)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "dvb_streaming_read, attempt N. %d failed with errno %d when reading %d bytes\n", tries, errno, size-pos);
|
2007-06-08 07:45:36 +00:00
|
|
|
errno = 0;
|
2003-08-11 00:02:46 +00:00
|
|
|
if(--tries > 0)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2005-04-18 19:49:40 +00:00
|
|
|
if((rk = read(fd, &buffer[pos], rk)) > 0)
|
|
|
|
{
|
|
|
|
pos += rk;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_TRACE(stream, "ret (%d) bytes\n", pos);
|
2005-04-18 19:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
if(! pos)
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "dvb_streaming_read, return %d bytes\n", pos);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
return pos;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
static void dvbin_close(stream_t *stream);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2007-12-15 13:05:06 +00:00
|
|
|
int dvb_set_channel(stream_t *stream, int card, int n)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-07-12 20:52:02 +00:00
|
|
|
dvb_channels_list *new_list;
|
2003-08-11 00:02:46 +00:00
|
|
|
dvb_channel_t *channel;
|
2007-12-15 13:05:06 +00:00
|
|
|
dvb_priv_t *priv = stream->priv;
|
2003-08-11 00:02:46 +00:00
|
|
|
char buf[4096];
|
2004-04-26 21:19:21 +00:00
|
|
|
dvb_config_t *conf = (dvb_config_t *) priv->config;
|
2004-07-12 20:52:02 +00:00
|
|
|
int devno;
|
|
|
|
int i;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
if((card < 0) || (card > conf->count))
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "dvb_set_channel: INVALID CARD NUMBER: %d vs %d, abort\n", card, conf->count);
|
2004-07-12 20:52:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
devno = conf->cards[card].devno;
|
|
|
|
new_list = conf->cards[card].list;
|
|
|
|
if((n > new_list->NUM_CHANNELS) || (n < 0))
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "dvb_set_channel: INVALID CHANNEL NUMBER: %d, for card %d, abort\n", n, card);
|
2004-07-12 20:52:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
channel = &(new_list->channels[n]);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
if(priv->is_on) //the fds are already open and we have to stop the demuxers
|
|
|
|
{
|
2004-07-12 20:52:02 +00:00
|
|
|
for(i = 0; i < priv->demux_fds_cnt; i++)
|
|
|
|
dvb_demux_stop(priv->demux_fds[i]);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
priv->retry = 0;
|
2003-11-01 15:17:01 +00:00
|
|
|
while(dvb_streaming_read(stream, buf, 4096) > 0); //empty both the stream's and driver's buffer
|
2004-04-26 21:19:21 +00:00
|
|
|
if(priv->card != card)
|
|
|
|
{
|
|
|
|
dvbin_close(stream);
|
2007-10-30 22:30:15 +00:00
|
|
|
if(! dvb_open_devices(priv, devno, channel->pids_cnt))
|
2004-04-26 21:19:21 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "DVB_SET_CHANNEL, COULDN'T OPEN DEVICES OF CARD: %d, EXIT\n", card);
|
2004-04-26 21:19:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-07-12 20:52:02 +00:00
|
|
|
}
|
|
|
|
else //close all demux_fds with pos > pids required for the new channel or open other demux_fds if we have too few
|
2009-05-13 02:58:57 +00:00
|
|
|
{
|
2007-10-30 22:30:15 +00:00
|
|
|
if(! dvb_fix_demuxes(priv, channel->pids_cnt))
|
2004-07-12 20:52:02 +00:00
|
|
|
return 0;
|
2004-04-26 21:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-30 22:30:15 +00:00
|
|
|
if(! dvb_open_devices(priv, devno, channel->pids_cnt))
|
2004-04-26 21:19:21 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "DVB_SET_CHANNEL2, COULDN'T OPEN DEVICES OF CARD: %d, EXIT\n", card);
|
2004-04-26 21:19:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
priv->card = card;
|
|
|
|
priv->list = new_list;
|
2003-11-01 15:17:01 +00:00
|
|
|
priv->retry = 5;
|
2004-07-12 20:52:02 +00:00
|
|
|
new_list->current = n;
|
stream: remove fd member
Stream implementations could set this to a unix file descriptor. The
generic stream code could use it as fallback for a few things. This
was confusing and insane. In most cases, the stream implementations
defined all callbacks, so setting the fd member didn't have any
advantages, other than avoiding defining a private struct to store it.
It appears that even if the stream implementation used close() on the
fd (or something equivalent), stream.c would close() it a second time
(and on windows, even would call closesocket()), which should be proof
for the insanity of this code.
For stream_file.c, additionally make sure we don't close stdin or
stdout if "-" is used as filename.
For stream_vcd.c, remove the control() code. This code most likely
didn't make the slightest sense, because it used a different type
for stream->priv. It also leaked memory. Maybe it worked, but it's
incorrect and insignificant anyway, so kill it. This code was added
with commit 9521c19 (svn commit 31019).
Untested for all protocols other than stream_file.c.
2013-07-12 20:07:07 +00:00
|
|
|
priv->fd = priv->dvr_fd;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(stream, "DVB_SET_CHANNEL: new channel name=%s, card: %d, channel %d\n", channel->name, card, n);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2010-02-20 18:39:26 +00:00
|
|
|
stream->buf_pos = stream->buf_len = 0;
|
|
|
|
stream->pos = 0;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2006-11-04 23:03:52 +00:00
|
|
|
if(channel->freq != priv->last_freq)
|
2003-08-11 00:02:46 +00:00
|
|
|
if (! dvb_tune(priv, channel->freq, channel->pol, channel->srate, channel->diseqc, channel->tone,
|
2013-08-02 15:02:34 +00:00
|
|
|
channel->inv, channel->mod, channel->gi, channel->trans, channel->bw, channel->cr, channel->cr_lp, channel->hier, priv->cfg_timeout))
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
|
|
|
|
2006-11-04 23:03:52 +00:00
|
|
|
priv->last_freq = channel->freq;
|
2003-08-11 00:02:46 +00:00
|
|
|
priv->is_on = 1;
|
|
|
|
|
|
|
|
//sets demux filters and restart the stream
|
2004-07-12 20:52:02 +00:00
|
|
|
for(i = 0; i < channel->pids_cnt; i++)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
if(! dvb_set_ts_filt(priv,priv->demux_fds[i], channel->pids[i], DMX_PES_OTHER))
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
2004-07-12 20:52:02 +00:00
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2003-08-11 00:02:46 +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
|
|
|
{
|
2003-08-11 00:02:46 +00:00
|
|
|
int new_current;
|
|
|
|
dvb_channels_list *list;
|
2007-12-15 13:05:06 +00:00
|
|
|
dvb_priv_t *priv = stream->priv;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(stream, "DVB_STEP_CHANNEL dir %d\n", dir);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
if(priv == NULL)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "dvb_step_channel: NULL priv_ptr, quit\n");
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = priv->list;
|
|
|
|
if(list == NULL)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "dvb_step_channel: NULL list_ptr, quit\n");
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-14 22:37:54 +00:00
|
|
|
new_current = (list->NUM_CHANNELS + list->current + (dir == DVB_CHANNEL_HIGHER ? 1 : -1)) % list->NUM_CHANNELS;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2007-12-15 13:05:06 +00:00
|
|
|
return dvb_set_channel(stream, priv->card, new_current);
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
static void dvbin_close(stream_t *stream)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-07-12 20:52:02 +00:00
|
|
|
int i;
|
2003-08-11 00:02:46 +00:00
|
|
|
dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
for(i = priv->demux_fds_cnt-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
priv->demux_fds_cnt--;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(stream, "DVBIN_CLOSE, close(%d), fd=%d, COUNT=%d\n", i, priv->demux_fds[i], priv->demux_fds_cnt);
|
2004-07-12 20:52:02 +00:00
|
|
|
close(priv->demux_fds[i]);
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
close(priv->dvr_fd);
|
2004-01-29 10:36:33 +00:00
|
|
|
|
|
|
|
close(priv->fe_fd);
|
2008-11-05 23:37:52 +00:00
|
|
|
priv->fe_fd = priv->sec_fd = priv->dvr_fd = -1;
|
2004-01-29 10:36:33 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
priv->is_on = 0;
|
2007-12-15 13:30:44 +00:00
|
|
|
dvb_free_config(priv->config);
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
static int dvb_streaming_start(stream_t *stream, int tuner_type, char *progname)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
int i;
|
2003-08-11 00:02:46 +00:00
|
|
|
dvb_channel_t *channel = NULL;
|
2007-12-15 13:37:41 +00:00
|
|
|
dvb_priv_t *priv = stream->priv;
|
2013-08-02 15:02:34 +00:00
|
|
|
dvb_priv_t *opts = priv;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(stream, "\r\ndvb_streaming_start(PROG: %s, CARD: %d)\r\n",
|
2013-08-02 15:02:34 +00:00
|
|
|
opts->cfg_prog, opts->cfg_card);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
priv->is_on = 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2006-07-14 22:43:50 +00:00
|
|
|
i = 0;
|
|
|
|
while((channel == NULL) && i < priv->list->NUM_CHANNELS)
|
|
|
|
{
|
|
|
|
if(! strcmp(priv->list->channels[i].name, progname))
|
|
|
|
channel = &(priv->list->channels[i]);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2006-07-14 22:43:50 +00:00
|
|
|
i++;
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2006-07-14 22:43:50 +00:00
|
|
|
if(channel != NULL)
|
|
|
|
{
|
|
|
|
priv->list->current = i-1;
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(stream, "PROGRAM NUMBER %d: name=%s, freq=%u\n", i-1, channel->name, channel->freq);
|
2006-07-14 22:43:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "\n\nDVBIN: no such channel \"%s\"\n\n", progname);
|
2006-07-14 22:43:50 +00:00
|
|
|
return 0;
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2007-12-15 13:05:06 +00:00
|
|
|
if(!dvb_set_channel(stream, priv->card, priv->list->current))
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "ERROR, COULDN'T SET CHANNEL %i: ", priv->list->current);
|
2003-08-11 00:02:46 +00:00
|
|
|
dvbin_close(stream);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(stream, "SUCCESSFUL EXIT from dvb_streaming_start\n");
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
static int dvb_open(stream_t *stream, int mode)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
|
|
|
// I don't force the file format bacause, although it's almost always TS,
|
|
|
|
// there are some providers that stream an IP multicast with M$ Mpeg4 inside
|
2013-08-02 15:02:34 +00:00
|
|
|
dvb_priv_t *priv = stream->priv;
|
2013-12-21 19:36:45 +00:00
|
|
|
priv->log = stream->log;
|
2013-08-02 15:02:34 +00:00
|
|
|
dvb_priv_t *p = priv;
|
2004-04-26 21:19:21 +00:00
|
|
|
char *progname;
|
2006-11-26 12:03:23 +00:00
|
|
|
int tuner_type = 0, i;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
if(mode != STREAM_READ)
|
2007-08-28 22:38:45 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2008-11-05 23:37:52 +00:00
|
|
|
priv->fe_fd = priv->sec_fd = priv->dvr_fd = -1;
|
2013-12-21 19:36:45 +00:00
|
|
|
priv->config = dvb_get_config(stream);
|
2007-12-15 13:30:44 +00:00
|
|
|
if(priv->config == NULL)
|
2004-04-26 21:19:21 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "DVB CONFIGURATION IS EMPTY, exit\n");
|
2004-04-26 21:19:21 +00:00
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2006-11-26 12:03:23 +00:00
|
|
|
priv->card = -1;
|
|
|
|
for(i=0; i<priv->config->count; i++)
|
|
|
|
{
|
2013-08-02 15:02:34 +00:00
|
|
|
if(priv->config->cards[i].devno+1 == p->cfg_card)
|
2006-11-26 12:03:23 +00:00
|
|
|
{
|
|
|
|
priv->card = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(priv->card == -1)
|
2004-01-29 10:36:33 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(stream, "NO CONFIGURATION FOUND FOR CARD N. %d, exit\n", p->cfg_card);
|
2004-01-29 10:36:33 +00:00
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2013-08-02 15:02:34 +00:00
|
|
|
priv->timeout = p->cfg_timeout;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
tuner_type = priv->config->cards[priv->card].type;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-11-01 15:17:01 +00:00
|
|
|
if(tuner_type == 0)
|
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(stream, "OPEN_DVB: UNKNOWN OR UNDETECTABLE TUNER TYPE, EXIT\n");
|
2003-11-01 15:17:01 +00:00
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
priv->tuner_type = tuner_type;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(stream, "OPEN_DVB: prog=%s, card=%d, type=%d\n",
|
2013-08-02 15:02:34 +00:00
|
|
|
p->cfg_prog, priv->card+1, priv->tuner_type);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
priv->list = priv->config->cards[priv->card].list;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
if((! strcmp(p->cfg_prog, "")) && (priv->list != NULL))
|
2004-04-26 21:19:21 +00:00
|
|
|
progname = priv->list->channels[0].name;
|
|
|
|
else
|
2013-08-02 15:02:34 +00:00
|
|
|
progname = p->cfg_prog;
|
2004-04-26 21:19:21 +00:00
|
|
|
|
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
if(! dvb_streaming_start(stream, tuner_type, progname))
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->type = STREAMTYPE_DVB;
|
|
|
|
stream->fill_buffer = dvb_streaming_read;
|
|
|
|
stream->close = dvbin_close;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2013-07-12 19:58:11 +00:00
|
|
|
stream->demuxer = "lavf";
|
|
|
|
stream->lavf_type = "mpegts";
|
2004-04-26 21:19:21 +00:00
|
|
|
|
2006-07-14 22:43:50 +00:00
|
|
|
return STREAM_OK;
|
2004-04-26 21:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_CARDS 4
|
2013-12-21 19:36:45 +00:00
|
|
|
dvb_config_t *dvb_get_config(stream_t *stream)
|
2004-04-26 21:19:21 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
struct mp_log *log = stream->log;
|
|
|
|
struct mpv_global *global = stream->global;
|
2004-04-26 21:19:21 +00:00
|
|
|
int i, fd, type, size;
|
|
|
|
char filename[30], *conf_file, *name;
|
|
|
|
dvb_channels_list *list;
|
2006-05-14 22:06:17 +00:00
|
|
|
dvb_card_config_t *cards = NULL, *tmp;
|
|
|
|
dvb_config_t *conf = NULL;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
|
|
|
|
2007-06-24 13:27:03 +00:00
|
|
|
conf = malloc(sizeof(dvb_config_t));
|
2004-04-26 21:19:21 +00:00
|
|
|
if(conf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
conf->priv = NULL;
|
2004-04-26 21:19:21 +00:00
|
|
|
conf->count = 0;
|
|
|
|
conf->cards = NULL;
|
|
|
|
for(i=0; i<MAX_CARDS; i++)
|
|
|
|
{
|
2007-03-03 13:10:31 +00:00
|
|
|
snprintf(filename, sizeof(filename), "/dev/dvb/adapter%d/frontend0", i);
|
2013-11-30 21:40:51 +00:00
|
|
|
fd = open(filename, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
|
2004-04-26 21:19:21 +00:00
|
|
|
if(fd < 0)
|
2004-04-03 10:30:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "DVB_CONFIG, can't open device %s, skipping\n", filename);
|
2004-04-26 21:19:21 +00:00
|
|
|
continue;
|
2004-04-03 10:30:46 +00:00
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
type = dvb_get_tuner_type(fd, log);
|
2004-04-26 21:19:21 +00:00
|
|
|
close(fd);
|
2005-01-06 09:43:10 +00:00
|
|
|
if(type != TUNER_SAT && type != TUNER_TER && type != TUNER_CBL && type != TUNER_ATSC)
|
2004-04-03 10:30:46 +00:00
|
|
|
{
|
2013-12-21 19:36:45 +00:00
|
|
|
mp_verbose(log, "DVB_CONFIG, can't detect tuner type of card %d, skipping\n", i);
|
2004-04-26 21:19:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2012-12-09 14:05:21 +00:00
|
|
|
void *talloc_ctx = talloc_new(NULL);
|
2013-12-21 19:36:45 +00:00
|
|
|
conf_file = mp_find_user_config_file(talloc_ctx, global, "channels.conf");
|
2012-12-09 14:05:21 +00:00
|
|
|
switch(type) {
|
|
|
|
case TUNER_TER:
|
2013-12-21 19:36:45 +00:00
|
|
|
conf_file = mp_find_user_config_file(talloc_ctx, global, "channels.conf.ter");
|
2012-12-09 14:05:21 +00:00
|
|
|
break;
|
|
|
|
case TUNER_CBL:
|
2013-12-21 19:36:45 +00:00
|
|
|
conf_file = mp_find_user_config_file(talloc_ctx, global, "channels.conf.cbl");
|
2012-12-09 14:05:21 +00:00
|
|
|
break;
|
|
|
|
case TUNER_SAT:
|
2013-12-21 19:36:45 +00:00
|
|
|
conf_file = mp_find_user_config_file(talloc_ctx, global, "channels.conf.sat");
|
2012-12-09 14:05:21 +00:00
|
|
|
break;
|
|
|
|
case TUNER_ATSC:
|
2013-12-21 19:36:45 +00:00
|
|
|
conf_file = mp_find_user_config_file(talloc_ctx, global, "channels.conf.atsc");
|
2012-12-09 14:05:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-08 22:50:21 +00:00
|
|
|
if(conf_file && (access(conf_file, F_OK | R_OK) != 0)) {
|
2013-12-21 19:36:45 +00:00
|
|
|
conf_file = mp_find_user_config_file(talloc_ctx, global, "channels.conf");
|
2012-12-09 14:05:21 +00:00
|
|
|
|
2013-02-08 22:50:21 +00:00
|
|
|
if(conf_file && (access(conf_file, F_OK | R_OK) != 0)) {
|
2013-12-21 19:36:45 +00:00
|
|
|
conf_file = mp_find_global_config_file(talloc_ctx, global, "channels.conf");
|
2012-12-09 14:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
list = dvb_get_channels(log, conf_file, type);
|
2012-12-09 14:05:21 +00:00
|
|
|
talloc_free(talloc_ctx);
|
2004-04-03 10:30:46 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
if(list == NULL)
|
|
|
|
continue;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
size = sizeof(dvb_card_config_t) * (conf->count + 1);
|
2006-05-13 09:08:28 +00:00
|
|
|
tmp = realloc(conf->cards, size);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2006-05-13 09:08:28 +00:00
|
|
|
if(tmp == NULL)
|
2006-07-14 22:43:50 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
fprintf(stderr, "DVB_CONFIG, can't realloc %d bytes, skipping\n", size);
|
|
|
|
continue;
|
2006-07-14 22:43:50 +00:00
|
|
|
}
|
2006-05-13 09:08:28 +00:00
|
|
|
cards = tmp;
|
2003-11-01 15:17:01 +00:00
|
|
|
|
2007-06-24 13:27:03 +00:00
|
|
|
name = malloc(20);
|
2004-04-26 21:19:21 +00:00
|
|
|
if(name==NULL)
|
2006-07-14 22:43:50 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
fprintf(stderr, "DVB_CONFIG, can't realloc 20 bytes, skipping\n");
|
|
|
|
continue;
|
2006-07-14 22:43:50 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
conf->cards = cards;
|
|
|
|
conf->cards[conf->count].devno = i;
|
|
|
|
conf->cards[conf->count].list = list;
|
|
|
|
conf->cards[conf->count].type = type;
|
2007-03-03 13:10:31 +00:00
|
|
|
snprintf(name, 20, "DVB-%c card n. %d", type==TUNER_TER ? 'T' : (type==TUNER_CBL ? 'C' : 'S'), conf->count+1);
|
2004-04-26 21:19:21 +00:00
|
|
|
conf->cards[conf->count].name = name;
|
|
|
|
conf->count++;
|
|
|
|
}
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
if(conf->count == 0)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
free(conf);
|
|
|
|
conf = NULL;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
return conf;
|
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,
|
|
|
|
.protocols = (const char*[]){ "dvb", NULL },
|
2013-08-02 15:02:34 +00:00
|
|
|
.priv_size = sizeof(dvb_priv_t),
|
|
|
|
.priv_defaults = &stream_defaults,
|
|
|
|
.options = stream_params,
|
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
|
|
|
.url_options = (const char*[]){
|
|
|
|
"hostname=prog",
|
|
|
|
"username=card",
|
|
|
|
NULL
|
2013-08-02 15:02:34 +00:00
|
|
|
},
|
2003-08-11 00:02:46 +00:00
|
|
|
};
|