2003-03-16 20:13:28 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
dvbstream
|
|
|
|
(C) Dave Chapman <dave@dchapman.com> 2001, 2002.
|
|
|
|
|
|
|
|
The latest version can be found at http://www.linuxstb.org/dvbstream
|
|
|
|
|
2005-04-16 12:51:09 +00:00
|
|
|
Modified for use with MPlayer, for details see the CVS changelog at
|
|
|
|
http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
|
|
|
|
$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
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
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>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <unistd.h>
|
2003-08-11 00:02:46 +00:00
|
|
|
#include <fcntl.h>
|
2003-03-16 20:13:28 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "stream.h"
|
|
|
|
#include "demuxer.h"
|
2003-08-11 00:02:46 +00:00
|
|
|
#include "help_mp.h"
|
|
|
|
#include "../m_option.h"
|
|
|
|
#include "../m_struct.h"
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
#include "dvbin.h"
|
|
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
|
static struct stream_priv_s
|
|
|
|
{
|
|
|
|
char *prog;
|
|
|
|
int card;
|
|
|
|
char *type;
|
|
|
|
int vid, aid;
|
|
|
|
char *file;
|
|
|
|
}
|
|
|
|
stream_defaults =
|
|
|
|
{
|
2004-04-03 10:30:46 +00:00
|
|
|
"", 1, "", 0, 0, NULL
|
2003-08-11 00:02:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_OFF(f) M_ST_OFF(struct stream_priv_s, f)
|
|
|
|
|
|
|
|
/// URL definition
|
|
|
|
static m_option_t stream_params[] = {
|
|
|
|
{"prog", ST_OFF(prog), CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
|
|
{"card", ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},
|
|
|
|
{"type", ST_OFF(type), CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
|
|
{"vid", ST_OFF(vid), CONF_TYPE_INT, 0, 0 ,0, NULL},
|
|
|
|
{"aid", ST_OFF(aid), CONF_TYPE_INT, 0, 0 ,0, NULL},
|
|
|
|
{"file", ST_OFF(file), CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
{"hostname", ST_OFF(prog), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
2004-04-26 21:19:21 +00:00
|
|
|
{"username", ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},
|
2003-08-11 00:02:46 +00:00
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
2003-03-16 20:13:28 +00:00
|
|
|
};
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
static struct m_struct_st stream_opts = {
|
|
|
|
"dvbin",
|
|
|
|
sizeof(struct stream_priv_s),
|
|
|
|
&stream_defaults,
|
|
|
|
stream_params
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_option_t dvbin_opts_conf[] = {
|
|
|
|
{"prog", &stream_defaults.prog, CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
|
|
{"card", &stream_defaults.card, CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},
|
2004-04-03 10:30:46 +00:00
|
|
|
{"type", "DVB card type is autodetected and can't be overridden\n", CONF_TYPE_PRINT, CONF_NOCFG, 0 ,0, NULL},
|
2003-08-11 00:02:46 +00:00
|
|
|
{"vid", &stream_defaults.vid, CONF_TYPE_INT, 0, 0 ,0, NULL},
|
|
|
|
{"aid", &stream_defaults.aid, CONF_TYPE_INT, 0, 0 ,0, NULL},
|
|
|
|
{"file", &stream_defaults.file, CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
|
|
|
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
extern int dvb_set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype);
|
|
|
|
extern int dvb_demux_stop(int fd);
|
2004-04-26 21:19:21 +00:00
|
|
|
extern int dvb_get_tuner_type(int fd);
|
2004-07-12 20:52:02 +00:00
|
|
|
int dvb_open_devices(dvb_priv_t *priv, int n, int demux_cnt, int *pids);
|
|
|
|
int dvb_fix_demuxes(dvb_priv_t *priv, int cnt, int *pids);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
extern int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone,
|
|
|
|
fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval,
|
2004-08-26 19:38:16 +00:00
|
|
|
fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate,
|
|
|
|
fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier);
|
2004-01-29 10:36:33 +00:00
|
|
|
extern char *dvb_dvrdev[4], *dvb_demuxdev[4], *dvb_frontenddev[4];
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
static dvb_config_t *dvb_config = NULL;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
static dvb_channels_list *dvb_get_channels(char *filename, int type)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
|
|
|
dvb_channels_list *list;
|
|
|
|
FILE *f;
|
2003-08-11 00:02:46 +00:00
|
|
|
uint8_t line[CHANNEL_LINE_LEN];
|
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
int fields, cnt, pcnt;
|
2004-04-26 21:19:21 +00:00
|
|
|
dvb_channel_t *ptr, *tmp, chn;
|
2004-07-12 20:52:02 +00:00
|
|
|
char *tmp_lcr, *tmp_hier, *inv, *bw, *cr, *mod, *transm, *gi, *vpid_str, *apid_str;
|
|
|
|
const char *cbl_conf = "%a[^:]:%d:%a[^:]:%d:%a[^:]:%a[^:]:%a[^:]:%a[^:]\n";
|
|
|
|
const char *sat_conf = "%a[^:]:%d:%c:%d:%d:%a[^:]:%a[^:]\n";
|
|
|
|
const char *ter_conf = "%a[^:]:%d:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]\n";
|
2005-01-06 09:43:10 +00:00
|
|
|
const char *atsc_conf = "%a[^:]:%d:%a[^:]:%a[^:]:%a[^:]\n";
|
2004-07-12 20:52:02 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %d\n", filename, type);
|
|
|
|
if((f=fopen(filename, "r"))==NULL)
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_FATAL, "CAN'T READ CONFIG FILE %s\n", filename);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "DVB_GET_CHANNELS: couldn't malloc enough memory\n");
|
|
|
|
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
|
|
|
|
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
apid_str = vpid_str = NULL;
|
|
|
|
ptr->pids_cnt = 0;
|
2003-08-11 00:02:46 +00:00
|
|
|
if(type == TUNER_TER)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
|
|
|
fields = sscanf(line, ter_conf,
|
2003-08-11 00:02:46 +00:00
|
|
|
&ptr->name, &ptr->freq, &inv, &bw, &cr, &tmp_lcr, &mod,
|
2004-07-12 20:52:02 +00:00
|
|
|
&transm, &gi, &tmp_hier, &vpid_str, &apid_str);
|
2003-08-27 17:08:58 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V,
|
2004-07-12 20:52:02 +00:00
|
|
|
"TER, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d",
|
|
|
|
list->NUM_CHANNELS, fields, ptr->name, ptr->freq);
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
|
|
|
else if(type == TUNER_CBL)
|
|
|
|
{
|
|
|
|
fields = sscanf(line, cbl_conf,
|
|
|
|
&ptr->name, &ptr->freq, &inv, &ptr->srate,
|
2004-07-12 20:52:02 +00:00
|
|
|
&cr, &mod, &vpid_str, &apid_str);
|
2003-08-27 17:08:58 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V,
|
2004-07-12 20:52:02 +00:00
|
|
|
"CBL, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d",
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
fields = sscanf(line, atsc_conf,
|
|
|
|
&ptr->name, &ptr->freq, &mod, &vpid_str, &apid_str);
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V,
|
|
|
|
"ATSC, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d\n",
|
|
|
|
list->NUM_CHANNELS, fields, ptr->name, ptr->freq);
|
|
|
|
}
|
|
|
|
#endif
|
2003-08-11 00:02:46 +00:00
|
|
|
else //SATELLITE
|
|
|
|
{
|
|
|
|
fields = sscanf(line, sat_conf,
|
2004-07-12 20:52:02 +00:00
|
|
|
&ptr->name, &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--;
|
2003-08-11 00:02:46 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V,
|
2004-07-12 20:52:02 +00:00
|
|
|
"SAT, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d, POL: %c, DISEQC: %d",
|
|
|
|
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
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
if(vpid_str != NULL)
|
|
|
|
{
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(apid_str != NULL)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
if((fields < 3) || (ptr->pids_cnt <= 0) || (ptr->freq == 0) || (strlen(ptr->name) == 0))
|
2003-08-27 17:08:58 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
ptr->pids[ptr->pids_cnt] = 0; //PID 0 is the PAT
|
|
|
|
ptr->pids_cnt++;
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, " PIDS: ");
|
|
|
|
for(cnt = 0; cnt < ptr->pids_cnt; cnt++)
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, " %d ", ptr->pids[cnt]);
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "\n");
|
|
|
|
|
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;
|
|
|
|
#ifdef HAVE_DVB_HEAD
|
|
|
|
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;
|
|
|
|
#endif
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
2005-01-06 09:43:10 +00:00
|
|
|
#ifdef DVB_ATSC
|
|
|
|
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;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2005-01-06 09:43:10 +00:00
|
|
|
ptr->inv = INVERSION_AUTO;
|
|
|
|
#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;
|
|
|
|
|
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;
|
|
|
|
else ptr->gi = GUARD_INTERVAL_1_4;
|
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;
|
|
|
|
#ifdef HAVE_DVB_HEAD
|
|
|
|
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;
|
|
|
|
#endif
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
#ifdef HAVE_DVB_HEAD
|
|
|
|
else if(! strcmp(tmp_hier, "HIERARCHY_AUTO"))
|
|
|
|
ptr->hier = HIERARCHY_AUTO;
|
|
|
|
#endif
|
|
|
|
else ptr->hier = HIERARCHY_NONE;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
tmp = (dvb_channel_t*)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));
|
2003-03-16 20:13:28 +00:00
|
|
|
list->NUM_CHANNELS++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
2004-04-26 21:19:21 +00:00
|
|
|
if(list->NUM_CHANNELS == 0)
|
|
|
|
{
|
|
|
|
if(list->channels != NULL)
|
|
|
|
free(list->channels);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2004-03-19 20:22:10 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_DBG3, "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;
|
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
fd = stream->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
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
errno = 0;
|
2003-08-11 00:02:46 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_streaming_read, attempt N. %d failed with errno %d when reading %d bytes\n", tries, errno, size-pos);
|
|
|
|
if(--tries > 0)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2005-04-18 19:49:40 +00:00
|
|
|
if((rk = read(fd, &buffer[pos], rk)) > 0)
|
|
|
|
{
|
|
|
|
pos += rk;
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_DBG3, "ret (%d) bytes\n", pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
if(! pos)
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_streaming_read, return %d bytes\n", pos);
|
|
|
|
|
|
|
|
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
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
int dvb_set_channel(dvb_priv_t *priv, 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;
|
|
|
|
int do_tuning;
|
|
|
|
stream_t *stream = (stream_t*) priv->stream;
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CARD NUMBER: %d vs %d, abort\n", card, conf->count);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
devno = conf->cards[card].devno;
|
|
|
|
new_list = conf->cards[card].list;
|
|
|
|
if((n > new_list->NUM_CHANNELS) || (n < 0))
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CHANNEL NUMBER: %d, for card %d, abort\n", n, card);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
channel = &(new_list->channels[n]);
|
|
|
|
|
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]);
|
|
|
|
|
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);
|
2004-07-12 20:52:02 +00:00
|
|
|
if(! dvb_open_devices(priv, devno, channel->pids_cnt, channel->pids))
|
2004-04-26 21:19:21 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB_SET_CHANNEL, COULDN'T OPEN DEVICES OF CARD: %d, EXIT\n", card);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strcpy(priv->prev_tuning, "");
|
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
|
|
|
|
{
|
|
|
|
if(! dvb_fix_demuxes(priv, channel->pids_cnt, channel->pids))
|
|
|
|
return 0;
|
2004-04-26 21:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-12 20:52:02 +00:00
|
|
|
if(! dvb_open_devices(priv, devno, channel->pids_cnt, channel->pids))
|
2004-04-26 21:19:21 +00:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB_SET_CHANNEL2, COULDN'T OPEN DEVICES OF CARD: %d, EXIT\n", card);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strcpy(priv->prev_tuning, "");
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-07-12 20:52:02 +00:00
|
|
|
dvb_config->priv = priv;
|
|
|
|
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->fd = priv->dvr_fd;
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: new channel name=%s, card: %d, channel %d\n", channel->name, card, n);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
switch(priv->tuner_type)
|
|
|
|
{
|
|
|
|
case TUNER_SAT:
|
|
|
|
sprintf(priv->new_tuning, "%d|%09d|%09d|%d|%c", priv->card, channel->freq, channel->srate, channel->diseqc, channel->pol);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TUNER_TER:
|
|
|
|
sprintf(priv->new_tuning, "%d|%09d|%d|%d|%d|%d|%d|%d", priv->card, channel->freq, channel->inv,
|
|
|
|
channel->bw, channel->cr, channel->mod, channel->trans, channel->gi);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TUNER_CBL:
|
|
|
|
sprintf(priv->new_tuning, "%d|%09d|%d|%d|%d|%d", priv->card, channel->freq, channel->inv, channel->srate,
|
|
|
|
channel->cr, channel->mod);
|
|
|
|
break;
|
2005-01-06 09:43:10 +00:00
|
|
|
#ifdef DVB_ATSC
|
|
|
|
case TUNER_ATSC:
|
|
|
|
sprintf(priv->new_tuning, "%d|%09d|%d", priv->card, channel->freq, channel->mod);
|
|
|
|
break;
|
|
|
|
#endif
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
if(strcmp(priv->prev_tuning, priv->new_tuning))
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "DIFFERENT TUNING THAN THE PREVIOUS: %s -> %s\n", priv->prev_tuning, priv->new_tuning);
|
|
|
|
strcpy(priv->prev_tuning, priv->new_tuning);
|
|
|
|
do_tuning = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-01 15:17:01 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "SAME TUNING PARAMETERS, NO TUNING\n");
|
2003-08-11 00:02:46 +00:00
|
|
|
do_tuning = 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
stream->eof=1;
|
|
|
|
stream_reset(stream);
|
|
|
|
|
|
|
|
|
|
|
|
if(do_tuning)
|
|
|
|
if (! dvb_tune(priv, channel->freq, channel->pol, channel->srate, channel->diseqc, channel->tone,
|
2004-08-26 19:38:16 +00:00
|
|
|
channel->inv, channel->mod, channel->gi, channel->trans, channel->bw, channel->cr, channel->cr_lp, channel->hier))
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
if(! dvb_set_ts_filt(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
|
|
|
}
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
return 1;
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
int dvb_step_channel(dvb_priv_t *priv, 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;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "DVB_STEP_CHANNEL dir %d\n", dir);
|
|
|
|
|
|
|
|
if(priv == NULL)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: NULL priv_ptr, quit\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = priv->list;
|
|
|
|
if(list == NULL)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: NULL list_ptr, quit\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(dir == DVB_CHANNEL_HIGHER)
|
|
|
|
{
|
|
|
|
if(list->current == list->NUM_CHANNELS-1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
new_current = list->current + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(list->current == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
new_current = list->current - 1;
|
|
|
|
}
|
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
return dvb_set_channel(priv, priv->card, new_current);
|
2003-03-16 20:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
extern char *get_path(char *);
|
|
|
|
|
|
|
|
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--;
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "DVBIN_CLOSE, close(%d), fd=%d, COUNT=%d\n", i, priv->demux_fds[i], priv->demux_fds_cnt);
|
|
|
|
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);
|
|
|
|
#ifdef HAVE_DVB
|
|
|
|
close(priv->sec_fd);
|
|
|
|
#endif
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
priv->is_on = 0;
|
2004-04-26 21:19:21 +00:00
|
|
|
dvb_config->priv = NULL;
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
static int dvb_streaming_start(dvb_priv_t *priv, struct stream_priv_s *opts, 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;
|
|
|
|
stream_t *stream = (stream_t*) priv->stream;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "code taken from dvbstream for mplayer v0.4pre1 - (C) Dave Chapman 2001\n");
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "Released under the GPL.\n");
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "Latest version available from http://www.linuxstb.org/\n");
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "PROG: %s, CARD: %d, VID: %d, AID: %d, TYPE: %s, FILE: %s\n",
|
|
|
|
opts->prog, opts->card, opts->vid, opts->aid, opts->type, opts->file);
|
|
|
|
|
|
|
|
priv->is_on = 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
i = 0;
|
2004-04-26 21:19:21 +00:00
|
|
|
while((channel == NULL) && i < priv->list->NUM_CHANNELS)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
if(! strcmp(priv->list->channels[i].name, progname))
|
|
|
|
channel = &(priv->list->channels[i]);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(channel != NULL)
|
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
priv->list->current = i-1;
|
2004-07-12 20:52:02 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "PROGRAM NUMBER %d: name=%s, freq=%u\n", i-1, channel->name, channel->freq);
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
else
|
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "\n\nDVBIN: no such channel \"%s\"\n\n", progname);
|
2003-08-11 00:02:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
strcpy(priv->prev_tuning, "");
|
2004-04-26 21:19:21 +00:00
|
|
|
if(!dvb_set_channel(priv, priv->card, priv->list->current))
|
2003-08-11 00:02:46 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "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
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "SUCCESSFUL EXIT from dvb_streaming_start\n");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int dvb_open(stream_t *stream, int mode, void *opts, int *file_format)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
struct stream_priv_s* p = (struct stream_priv_s*)opts;
|
|
|
|
dvb_priv_t *priv;
|
2004-04-26 21:19:21 +00:00
|
|
|
char *progname;
|
2003-11-01 15:17:01 +00:00
|
|
|
int tuner_type = 0;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
if(mode != STREAM_READ)
|
|
|
|
return STREAM_UNSUPORTED;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
stream->priv = (dvb_priv_t*) malloc(sizeof(dvb_priv_t));
|
|
|
|
if(stream->priv == NULL)
|
|
|
|
return STREAM_ERROR;
|
|
|
|
|
|
|
|
priv = (dvb_priv_t *)stream->priv;
|
|
|
|
priv->stream = stream;
|
2004-04-26 21:19:21 +00:00
|
|
|
dvb_config = dvb_get_config();
|
|
|
|
if(dvb_config == NULL)
|
|
|
|
{
|
|
|
|
free(priv);
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB CONFIGURATION IS EMPTY, exit\n");
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
dvb_config->priv = priv;
|
|
|
|
priv->config = dvb_config;
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
if(p->card < 1 || p->card > priv->config->count)
|
2004-01-29 10:36:33 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
free(priv);
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_ERR, "NO CONFIGURATION FOUND FOR CARD N. %d, exit\n", p->card);
|
2004-01-29 10:36:33 +00:00
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2004-04-26 21:19:21 +00:00
|
|
|
priv->card = p->card - 1;
|
2004-01-29 10:36:33 +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)
|
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
free(priv);
|
2003-11-01 15:17:01 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "OPEN_DVB: UNKNOWN OR UNDETECTABLE TUNER TYPE, EXIT\n");
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
priv->tuner_type = tuner_type;
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-04-03 10:30:46 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "OPEN_DVB: prog=%s, card=%d, type=%d, vid=%d, aid=%d\n",
|
|
|
|
p->prog, priv->card+1, priv->tuner_type, p->vid, p->aid);
|
2003-08-11 00:02:46 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
priv->list = priv->config->cards[priv->card].list;
|
|
|
|
|
|
|
|
if((! strcmp(p->prog, "")) && (priv->list != NULL))
|
|
|
|
progname = priv->list->channels[0].name;
|
|
|
|
else
|
|
|
|
progname = p->prog;
|
|
|
|
|
|
|
|
|
|
|
|
if(! dvb_streaming_start(priv, p, tuner_type, progname))
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
free(stream->priv);
|
|
|
|
stream->priv = NULL;
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->type = STREAMTYPE_DVB;
|
|
|
|
stream->fill_buffer = dvb_streaming_read;
|
|
|
|
stream->close = dvbin_close;
|
|
|
|
m_struct_free(&stream_opts, opts);
|
|
|
|
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_CARDS 4
|
|
|
|
dvb_config_t *dvb_get_config()
|
|
|
|
{
|
|
|
|
int i, fd, type, size;
|
|
|
|
char filename[30], *conf_file, *name;
|
|
|
|
dvb_channels_list *list;
|
|
|
|
dvb_card_config_t *cards = NULL;
|
|
|
|
dvb_config_t *conf = NULL;
|
|
|
|
|
|
|
|
if(dvb_config != NULL)
|
|
|
|
return dvb_config;
|
|
|
|
|
|
|
|
conf = (dvb_config_t*) malloc(sizeof(dvb_config_t));
|
|
|
|
if(conf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
conf->priv = NULL;
|
|
|
|
conf->count = 0;
|
|
|
|
conf->cards = NULL;
|
|
|
|
for(i=0; i<MAX_CARDS; i++)
|
|
|
|
{
|
|
|
|
sprintf(filename, "/dev/dvb/adapter%d/frontend0", i);
|
|
|
|
fd = open(filename, O_RDWR | O_NONBLOCK);
|
|
|
|
if(fd < 0)
|
2004-04-03 10:30:46 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "DVB_CONFIG, can't open device %s, skipping\n", filename);
|
|
|
|
continue;
|
2004-04-03 10:30:46 +00:00
|
|
|
}
|
2004-04-26 21:19:21 +00:00
|
|
|
|
|
|
|
type = dvb_get_tuner_type(fd);
|
|
|
|
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
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "DVB_CONFIG, can't detect tuner type of card %d, skipping\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(type)
|
2004-04-03 10:30:46 +00:00
|
|
|
{
|
|
|
|
case TUNER_TER:
|
2004-04-26 21:19:21 +00:00
|
|
|
conf_file = get_path("channels.conf.ter");
|
2004-04-03 10:30:46 +00:00
|
|
|
break;
|
|
|
|
case TUNER_CBL:
|
2004-04-26 21:19:21 +00:00
|
|
|
conf_file = get_path("channels.conf.cbl");
|
2004-04-03 10:30:46 +00:00
|
|
|
break;
|
|
|
|
case TUNER_SAT:
|
2004-04-26 21:19:21 +00:00
|
|
|
conf_file = get_path("channels.conf.sat");
|
2004-04-03 10:30:46 +00:00
|
|
|
break;
|
2005-01-06 09:43:10 +00:00
|
|
|
case TUNER_ATSC:
|
|
|
|
conf_file = get_path("channels.conf.atsc");
|
|
|
|
break;
|
2004-04-03 10:30:46 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
if((access(conf_file, F_OK | R_OK) != 0))
|
|
|
|
conf_file = get_path("channels.conf");
|
2004-04-03 10:30:46 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
list = dvb_get_channels(conf_file, type);
|
|
|
|
if(list == NULL)
|
|
|
|
continue;
|
2004-04-03 10:30:46 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
size = sizeof(dvb_card_config_t) * (conf->count + 1);
|
|
|
|
cards = realloc(conf->cards, size);
|
2003-03-16 20:13:28 +00:00
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
if(cards == NULL)
|
2003-11-01 15:17:01 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
fprintf(stderr, "DVB_CONFIG, can't realloc %d bytes, skipping\n", size);
|
|
|
|
continue;
|
2003-11-01 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2004-04-26 21:19:21 +00:00
|
|
|
name = (char*) malloc(20);
|
|
|
|
if(name==NULL)
|
2003-03-16 20:13:28 +00:00
|
|
|
{
|
2004-04-26 21:19:21 +00:00
|
|
|
fprintf(stderr, "DVB_CONFIG, can't realloc 20 bytes, skipping\n");
|
|
|
|
continue;
|
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;
|
|
|
|
sprintf(name, "DVB-%c card n. %d", type==TUNER_TER ? 'T' : (type==TUNER_CBL ? 'C' : 'S'), conf->count+1);
|
|
|
|
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
|
|
|
dvb_config = conf;
|
|
|
|
return conf;
|
2003-08-11 00:02:46 +00:00
|
|
|
}
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-11 00:02:46 +00:00
|
|
|
stream_info_t stream_info_dvb = {
|
|
|
|
"Dvb Input",
|
|
|
|
"dvbin",
|
|
|
|
"Nico",
|
|
|
|
"based on the code from ??? (probably Arpi)",
|
|
|
|
dvb_open,
|
|
|
|
{ "dvb", NULL },
|
|
|
|
&stream_opts,
|
|
|
|
1 // Urls are an option string
|
|
|
|
};
|
2003-03-16 20:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|