summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-08-11 00:02:46 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-08-11 00:02:46 +0000
commitd891bc11ccbe529beb532f44c0fc837d5dbb5f3f (patch)
tree00d6baa4f49709d223730b991b0c179f27850301
parenta3b1944cc63a540c05d9368ab05afc80f36da0d9 (diff)
downloadmpv-d891bc11ccbe529beb532f44c0fc837d5dbb5f3f.tar.bz2
mpv-d891bc11ccbe529beb532f44c0fc837d5dbb5f3f.tar.xz
this patch fixes
1) some bugs introduced in the tuner autodetection and in the channel-parsing functions, 3) retries reading when the mplayer/mencoder don't read fast enough (sooner it exited) but especially 4) makes the stream compliant with the new, modular stream api (the one currently in CVS is not and is totally unreachable). [and maybe more, next time please include cvslog in patch! -- A'rpi] patch by Nico <nsabbi@libero.it> git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10561 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--cfg-common.h4
-rw-r--r--libmpdemux/dvb_tune.c184
-rw-r--r--libmpdemux/dvbin.c899
-rw-r--r--libmpdemux/dvbin.h44
-rw-r--r--libmpdemux/open.c18
-rw-r--r--libmpdemux/stream.c20
-rw-r--r--mplayer.c58
7 files changed, 656 insertions, 571 deletions
diff --git a/cfg-common.h b/cfg-common.h
index 187c1bb4fa..e89bee0122 100644
--- a/cfg-common.h
+++ b/cfg-common.h
@@ -109,7 +109,7 @@
#endif
{"vivo", vivoopts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
#ifdef HAS_DVBIN_SUPPORT
- {"dvbin", dvbin_opts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
+ {"dvbin", dvbin_opts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
#endif
@@ -328,7 +328,7 @@ struct config tvopts_conf[]={
#ifdef HAS_DVBIN_SUPPORT
#include "libmpdemux/dvbin.h"
-extern struct config dvbin_opts_conf[];
+extern m_config_t dvbin_opts_conf[];
#endif
extern int audio_stream_cache;
diff --git a/libmpdemux/dvb_tune.c b/libmpdemux/dvb_tune.c
index 147976c22f..cc6c58697b 100644
--- a/libmpdemux/dvb_tune.c
+++ b/libmpdemux/dvb_tune.c
@@ -27,57 +27,104 @@
#include <unistd.h>
#include <fcntl.h>
#include <error.h>
+#include <errno.h>
#include "config.h"
#ifdef HAVE_DVB_HEAD
#include <linux/dvb/dmx.h>
#include <linux/dvb/frontend.h>
- char* frontenddev[4]={"/dev/dvb/adapter0/frontend0","/dev/dvb/adapter1/frontend0","/dev/dvb/adapter2/frontend0","/dev/dvb/adapter3/frontend0"};
- char* dvrdev[4]={"/dev/dvb/adapter0/dvr0","/dev/dvb/adapter1/dvr0","/dev/dvb/adapter2/dvr0","/dev/dvb/adapter3/dvr0"};
- char* demuxdev[4]={"/dev/dvb/adapter0/demux0","/dev/dvb/adapter1/demux0","/dev/dvb/adapter2/demux0","/dev/dvb/adapter3/demux0"};
- char* secdev[4]={"","","",""}; //UNUSED, ONLY FOR UNIFORMITY
+ static char* dvb_frontenddev[4]={"/dev/dvb/adapter0/frontend0","/dev/dvb/adapter1/frontend0","/dev/dvb/adapter2/frontend0","/dev/dvb/adapter3/frontend0"};
+ char* dvb_dvrdev[4]={"/dev/dvb/adapter0/dvr0","/dev/dvb/adapter1/dvr0","/dev/dvb/adapter2/dvr0","/dev/dvb/adapter3/dvr0"};
+ char* dvb_demuxdev[4]={"/dev/dvb/adapter0/demux0","/dev/dvb/adapter1/demux0","/dev/dvb/adapter2/demux0","/dev/dvb/adapter3/demux0"};
+ static char* dvb_secdev[4]={"","","",""}; //UNUSED, ONLY FOR UNIFORMITY
#else
#include <ost/dmx.h>
#include <ost/sec.h>
#include <ost/frontend.h>
- char* frontenddev[4]={"/dev/ost/frontend0","/dev/ost/frontend1","/dev/ost/frontend2","/dev/ost/frontend3"};
- char* dvrdev[4]={"/dev/ost/dvr0","/dev/ost/dvr1","/dev/ost/dvr2","/dev/ost/dvr3"};
- char* secdev[4]={"/dev/ost/sec0","/dev/ost/sec1","/dev/ost/sec2","/dev/ost/sec3"};
- char* demuxdev[4]={"/dev/ost/demux0","/dev/ost/demux1","/dev/ost/demux2","/dev/ost/demux3"};
+ static char* dvb_frontenddev[4]={"/dev/ost/frontend0","/dev/ost/frontend1","/dev/ost/frontend2","/dev/ost/frontend3"};
+ char* dvb_dvrdev[4]={"/dev/ost/dvr0","/dev/ost/dvr1","/dev/ost/dvr2","/dev/ost/dvr3"};
+ static char* dvb_secdev[4]={"/dev/ost/sec0","/dev/ost/sec1","/dev/ost/sec2","/dev/ost/sec3"};
+ char* dvb_demuxdev[4]={"/dev/ost/demux0","/dev/ost/demux1","/dev/ost/demux2","/dev/ost/demux3"};
#endif
#include "dvbin.h"
-#include "dvb_defaults.h"
#include "../mp_msg.h"
-extern int card;
-int open_fe(int* fd_frontend, int* fd_sec)
+int dvb_get_tuner_type(dvb_priv_t *priv)
{
- if((*fd_frontend = open(frontenddev[card], O_RDWR)) < 0)
+#ifdef HAVE_DVB_HEAD
+ struct dvb_frontend_info fe_info;
+#else
+ FrontendInfo fe_info;
+#endif
+
+ int res, fe_fd = -1;
+
+ fe_fd = open(dvb_frontenddev[priv->card], O_RDWR);
+ if(fe_fd < 0)
+ {
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "get_tuner_type(%d, %s), ERROR IN OPENING FRONTEND DEVICE %s: %d\n", priv->card, dvb_frontenddev[priv->card], errno);
+ return 0;
+ }
+
+ res = ioctl(fe_fd, FE_GET_INFO, &fe_info);
+ if(res < 0)
+ {
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_INFO error: %d, FD: %d\n\n", errno, fe_fd);
+ return 0;
+ }
+ close(fe_fd);
+
+ switch(fe_info.type)
+ {
+ case FE_OFDM:
+ mp_msg(MSGT_DEMUX, MSGL_INFO, "TUNER TYPE SEEMS TO BE DVB-T\n");
+ return TUNER_TER;
+
+ case FE_QPSK:
+ mp_msg(MSGT_DEMUX, MSGL_INFO, "TUNER TYPE SEEMS TO BE DVB-S\n");
+ return TUNER_SAT;
+
+ case FE_QAM:
+ mp_msg(MSGT_DEMUX, MSGL_INFO, "TUNER TYPE SEEMS TO BE DVB-C\n");
+ return TUNER_CBL;
+
+ default:
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "UNKNOWN TUNER TYPE\n");
+ return 0;
+ }
+
+}
+
+
+static int open_fe(dvb_priv_t *priv)
+{
+ priv->fe_fd = open(dvb_frontenddev[priv->card], O_RDWR);
+ if(priv->fe_fd < 0)
{
- perror("ERROR IN OPENING FRONTEND DEVICE: ");
- return -1;
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR IN OPENING FRONTEND DEVICE %s: %d\n", dvb_frontenddev[priv->card], errno);
+ return 0;
}
#ifdef HAVE_DVB_HEAD
- fd_sec=0;
+ priv->sec_fd=0;
#else
- if (fd_sec != 0)
- {
- if((*fd_sec = open(secdev[card], O_RDWR)) < 0)
- {
- perror("ERROR IN OPENING SEC DEVICE: ");
- return -1;
- }
- }
+ priv->sec_fd = open(dvb_secdev[priv->card], O_RDWR);
+ if(priv->sec_fd < 0)
+ {
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR IN OPENING SEC DEVICE %s: %d\n", dvb_secdev[priv->card], errno);
+ close(priv->fe_fd);
+ return 0;
+ }
#endif
- return 1;
+
+ return 1;
}
-int set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype)
+int dvb_set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype)
{
int i;
struct dmx_pes_filter_params pesFilterParams;
@@ -91,21 +138,22 @@ int set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype)
pesFilterParams.pesType = pestype;
#endif
- //pesFilterParams.pesType = pestype;
-
pesFilterParams.flags = DMX_IMMEDIATE_START;
+ //pesFilterParams.flags = DMX_START;
+ //errno = 0;
if ((i = ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams)) < 0)
{
- mp_msg(MSGT_DEMUX, MSGL_DBG2, "ERROR IN SETTING DMX_FILTER %i: ", pid);
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR IN SETTING DMX_FILTER %i for fd %d: ERRNO: %d", pid, fd, errno);
+ return 0;
}
- mp_msg(MSGT_DEMUX, MSGL_V, "SET PES FILTER ON PID %d, RESULT: %d\n", pid, i );
+ mp_msg(MSGT_DEMUX, MSGL_V, "SET PES FILTER ON PID %d to fd %d, RESULT: %d, ERRNO: %d\n", pid, fd, i, errno);
return 1;
}
-int demux_stop(int fd)
+int dvb_demux_stop(int fd)
{
int i;
i = ioctl(fd, DMX_STOP);
@@ -116,8 +164,18 @@ int demux_stop(int fd)
}
+int dvb_demux_start(int fd)
+{
+ int i;
+ i = ioctl(fd, DMX_START);
+
+ mp_msg(MSGT_DEMUX, MSGL_DBG2, "STARTING FD: %d, RESULT: %d\n", fd, i);
+
+ return (i==0);
+}
+
-void make_nonblock(int f)
+static void make_nonblock(int f)
{
int oldflags;
@@ -139,48 +197,31 @@ static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int
fe_transmit_mode_t TransmissionMode, fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth);
-//int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone)
dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone,
fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval,
fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate)
{
- mp_msg(MSGT_DEMUX, MSGL_DBG2, "dvb_tune con Freq: %lu, pol: %c, srate: %lu, diseqc %d, tone %d\n", freq, pol, srate, diseqc, tone);
- /* INPUT: frequency, polarization, srate */
+ mp_msg(MSGT_DEMUX, MSGL_INFO, "dvb_tune Freq: %lu\n", freq);
+ if(! open_fe(priv))
+ {
+ return 0;
+ }
+
if(freq > 100000000)
{
- if(open_fe(&(priv->fe_fd), 0))
- {
- //tune_it(fd_frontend, 0, freq, 0, 0, tone, specInv, diseqc,modulation,HP_CodeRate,TransmissionMode,guardInterval,bandWidth);
- tune_it(priv->fe_fd, 0, freq, 0, 0, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth);
-
- close(priv->fe_fd);
- }
- else
- return 0;
+ tune_it(priv->fe_fd, 0, freq, 0, 0, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth);
}
- else if ((freq != 0) && (pol != 0) && (srate != 0))
+ else if(freq != 0)
{
- if (open_fe(&(priv->fe_fd), &(priv->sec_fd)))
- {
- tune_it(priv->fe_fd, priv->sec_fd, freq, srate, pol, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth);
- close(priv->fe_fd);
- close(priv->sec_fd);
- }
- else
- return 0;
+ tune_it(priv->fe_fd, priv->sec_fd, freq, srate, pol, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth);
}
-
- priv->channel.freq = freq;
- priv->channel.srate = srate;
- priv->channel.pol = pol;
- priv->channel.diseqc = diseqc;
- priv->channel.tone = tone;
- priv->channel.inv = specInv;
- priv->channel.mod = modulation;
- priv->channel.gi = guardInterval;
- priv->channel.trans = TransmissionMode;
- priv->channel.bw = bandWidth;
- priv->channel.cr = HP_CodeRate;
+
+ close(priv->fe_fd);
+
+#ifdef HAVE_DVB_HEAD
+#else
+ close(priv->sec_fd);
+#endif
return 1;
}
@@ -541,7 +582,7 @@ static int check_status(int fd_frontend,FrontendParameters* feparams,int tone)
#ifdef HAVE_DVB_HEAD
-struct diseqc_cmd {
+static struct diseqc_cmd {
struct dvb_diseqc_master_cmd cmd;
uint32_t wait;
};
@@ -585,6 +626,7 @@ static int head_diseqc(int secfd, int sat_no, int pol, int hi_lo)
#endif
+static unsigned int prev_diseqc = 0;
static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone,
fe_spectral_inversion_t specInv, unsigned int diseqc, fe_modulation_t modulation, fe_code_rate_t HP_CodeRate,
@@ -602,8 +644,12 @@ static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int
struct secStatus sec_state;
#endif
+ if(diseqc == prev_diseqc)
+ diseqc = 0;
+ else
+ prev_diseqc = diseqc;
- mp_msg(MSGT_DEMUX, MSGL_V, "TUNE_IT, fd_frontend %d, fd_sec %d, freq %lu, srate %lu, pol %c, tone %i, specInv, diseqc %u, fe_modulation_t modulation,fe_code_rate_t HP_CodeRate, fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth\n",
+ mp_msg(MSGT_DEMUX, MSGL_V, "TUNE_IT, fd_frontend %d, fd_sec %d\nfreq %lu, srate %lu, pol %c, tone %i, specInv, diseqc %u, fe_modulation_t modulation,fe_code_rate_t HP_CodeRate, fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth\n",
fd_frontend, fd_sec, freq, srate, pol, tone, diseqc);
@@ -615,7 +661,7 @@ static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int
#ifdef HAVE_DVB_HEAD
- mp_msg(MSGT_DEMUX, MSGL_V, "Using DVB card \"%s\"\n",fe_info.name);
+ mp_msg(MSGT_DEMUX, MSGL_V, "Using DVB card \"%s\"\n", fe_info.name);
#endif
switch(fe_info.type)
@@ -737,7 +783,7 @@ static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int
}
else
{
- mp_msg(MSGT_DEMUX, MSGL_V, "DISEQC SETTING FAILED\n");
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "DISEQC SETTING FAILED\n");
}
}
#else
@@ -768,7 +814,7 @@ static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int
if (ioctl(fd_sec,SEC_SEND_SEQUENCE,&scmds) < 0)
{
mp_msg(MSGT_DEMUX, MSGL_ERR, "Error sending DisEqC");
- return -1;
+ return 0;
}
}
#endif
diff --git a/libmpdemux/dvbin.c b/libmpdemux/dvbin.c
index d845b64e32..fc5dd6c13c 100644
--- a/libmpdemux/dvbin.c
+++ b/libmpdemux/dvbin.c
@@ -23,7 +23,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-// Linux includes:
+#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -31,93 +31,112 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/poll.h>
-#include <sys/stat.h>
-#include <resolv.h>
-#include <fcntl.h>
#include <unistd.h>
-#include <signal.h>
-#include <values.h>
+#include <fcntl.h>
#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
#include <errno.h>
#include <fcntl.h>
-#include <unistd.h>
-#include "config.h"
-
-// DVB includes:
#include "stream.h"
#include "demuxer.h"
-
-#include "../cfgparser.h"
+#include "help_mp.h"
+#include "../m_option.h"
+#include "../m_struct.h"
#include "dvbin.h"
-#include "dvb_defaults.h"
-
-extern int video_id, audio_id, demuxer_type;
#define MAX_CHANNELS 8
+#define CHANNEL_LINE_LEN 256
+#define min(a, b) ((a) <= (b) ? (a) : (b))
-#define min(a, b) ((a) <= (b) ? (a) : (b))
+//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 =
+{
+ "", 1, "", 0, 0, "channels.conf"
+};
+
+#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},
-int dvbin_param_card, dvbin_param_freq, dvbin_param_srate, dvbin_param_diseqc = 0,
- dvbin_param_tone = -1, dvbin_param_vid, dvbin_param_aid, dvbin_is_active = 0;
-int dvbin_param_mod, dvbin_param_gi, dvbin_param_tm, dvbin_param_bw, dvbin_param_cr;
-char *dvbin_param_pol = "", *dvbin_param_inv="INVERSION_AUTO",
- *dvbin_param_type="SAT ",
- *dvbin_param_prog = " ";
-dvb_history_t dvb_prev_next;
-
-struct config dvbin_opts_conf[] = {
- {"on", &dvbin_param_on, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"type", &dvbin_param_type, CONF_TYPE_STRING, 0, 0, 1, NULL},
- {"card", &dvbin_param_card, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
- {"freq", &dvbin_param_freq, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"pol", &dvbin_param_pol, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"srate", &dvbin_param_srate, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"diseqc", &dvbin_param_diseqc, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
- {"tone", &dvbin_param_tone, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"vid", &dvbin_param_vid, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"aid", &dvbin_param_aid, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"prog", &dvbin_param_prog, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"inv", &dvbin_param_inv, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"mod", &dvbin_param_mod, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"gi", &dvbin_param_gi, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"tm", &dvbin_param_tm, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"bw", &dvbin_param_bw, CONF_TYPE_INT, 0, 0, 1, NULL},
- {"cr", &dvbin_param_cr, CONF_TYPE_INT, 0, 0, 1, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
+ {"hostname", ST_OFF(prog), CONF_TYPE_STRING, 0, 0, 0, NULL },
+ {"filename", ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},
+ {NULL, NULL, 0, 0, 0, 0, NULL}
};
+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},
+ {"type", &stream_defaults.type, CONF_TYPE_STRING, 0, 0 ,0, NULL},
+ {"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}
+};
+
+
+
-int card=0;
+extern int dvb_set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype);
+extern int dvb_demux_stop(int fd);
+extern int dvb_get_tuner_type(dvb_priv_t *priv);
-extern int open_fe(int* fd_frontend, int* fd_sec);
-extern int set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype);
-extern int demux_stop(int fd);
-extern void make_nonblock(int f);
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,
fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate);
-extern char *frontenddev[4], *dvrdev[4], *secdev[4], *demuxdev[4];
+extern char *dvb_dvrdev[4], *dvb_demuxdev[4];
+dvb_channels_list *dvb_list_ptr = NULL;
-dvb_channels_list *dvb_get_channels(char *filename, const char *type)
+
+static dvb_channels_list *dvb_get_channels(char *filename, int type)
{
dvb_channels_list *list;
FILE *f;
- uint8_t line[128];
+ uint8_t line[CHANNEL_LINE_LEN];
+
int fields, row_count;
dvb_channel_t *ptr;
char *tmp_lcr, *tmp_hier, *inv, *bw, *cr, *mod, *transm, *gi;
- //const char *cbl_conf = "%a[^:]:%d:%c:%d:%a[^:]:%a[^:]:%d:%d\n";
+ const char *cbl_conf = "%a[^:]:%d:%c:%d:%a[^:]:%a[^:]:%d:%d\n";
const char *sat_conf = "%a[^:]:%d:%c:%d:%d:%d:%d:%d:%d:%d\n";
const char *ter_conf = "%a[^:]:%d:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%d:%d\n";
+ if(type != TUNER_SAT && type != TUNER_TER && type != TUNER_CBL)
+ {
+ mp_msg(MSGT_DEMUX, MSGL_V, "DVB_GET_CHANNELS: wrong tuner type, exit\n");
+ return 0;
+ }
+
list = malloc(sizeof(dvb_channels_list));
if(list == NULL)
{
@@ -125,7 +144,8 @@ dvb_channels_list *dvb_get_channels(char *filename, const char *type)
return NULL;
}
- mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %s\n", filename, type);
+ bzero(list, sizeof(dvb_channels_list));
+ mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %d\n", filename, type);
if((f=fopen(filename, "r"))==NULL)
{
mp_msg(MSGT_DEMUX, MSGL_FATAL, "CAN'T READ CONFIG FILE %s\n", filename);
@@ -136,19 +156,42 @@ dvb_channels_list *dvb_get_channels(char *filename, const char *type)
row_count = 0;
while(! feof(f) && row_count < 512)
{
- if( fgets(line, 128, f) == NULL ) continue;
+ if( fgets(line, CHANNEL_LINE_LEN, f) == NULL ) continue;
if(line[0] == '#')
- continue; //comment line
+ continue;
- ptr = &(list->channels[ list->NUM_CHANNELS ]);
+ ptr = &(list->channels[list->NUM_CHANNELS]);
- if(! strcmp(type, "TER"))
+ if(type == TUNER_TER)
{
fields = sscanf(line, ter_conf,
- &ptr->name, &ptr->freq, &inv, &bw, &cr, tmp_lcr, &mod,
+ &ptr->name, &ptr->freq, &inv, &bw, &cr, &tmp_lcr, &mod,
&transm, &gi, &tmp_hier, &ptr->vpid, &ptr->apid1);
+ }
+ else if(type == TUNER_CBL)
+ {
+ fields = sscanf(line, cbl_conf,
+ &ptr->name, &ptr->freq, &inv, &ptr->srate,
+ &cr, &mod, &ptr->vpid, &ptr->apid1);
+ }
+ else //SATELLITE
+ {
+ fields = sscanf(line, sat_conf,
+ &ptr->name, &ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate, &ptr->vpid, &ptr->apid1,
+ &ptr->tpid, &ptr->ca, &ptr->progid);
+ ptr->pol = toupper(ptr->pol);
+ ptr->freq *= 1000UL;
+ ptr->srate *= 1000UL;
+ ptr->tone = -1;
+ mp_msg(MSGT_DEMUX, MSGL_V,
+ "NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d, POL: %c, DISEQC: %d, TONE: %d, VPID: %d, APID1: %d, APID2: %d, TPID: %d, PROGID: %d, NUM: %d\n",
+ fields, ptr->name, ptr->freq, ptr->srate, ptr->pol, ptr->diseqc, ptr->tone, ptr->vpid, ptr->apid1, ptr->apid2, ptr->tpid, ptr->progid, list->NUM_CHANNELS);
+ }
+
+ if((type == TUNER_TER) || (type == TUNER_CBL))
+ {
if(! strcmp(inv, "INVERSION_ON"))
ptr->inv = INVERSION_ON;
else if(! strcmp(inv, "INVERSION_OFF"))
@@ -156,13 +199,6 @@ dvb_channels_list *dvb_get_channels(char *filename, const char *type)
else
ptr->inv = INVERSION_AUTO;
- 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;
-
if(! strcmp(cr, "FEC_1_2"))
ptr->cr =FEC_1_2;
@@ -196,7 +232,18 @@ dvb_channels_list *dvb_get_channels(char *filename, const char *type)
ptr->mod = QAM_32;
else if(! strcmp(mod, "QAM_16"))
ptr->mod = QAM_16;
- else ptr->mod = QPSK;
+ //else ptr->mod = QPSK;
+ }
+
+
+ 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;
if(! strcmp(transm, "TRANSMISSION_MODE_2K"))
@@ -204,6 +251,7 @@ dvb_channels_list *dvb_get_channels(char *filename, const char *type)
else if(! strcmp(transm, "TRANSMISSION_MODE_8K"))
ptr->trans = TRANSMISSION_MODE_8K;
+
if(! strcmp(gi, "GUARD_INTERVAL_1_32"))
ptr->gi = GUARD_INTERVAL_1_32;
else if(! strcmp(gi, "GUARD_INTERVAL_1_16"))
@@ -211,31 +259,6 @@ dvb_channels_list *dvb_get_channels(char *filename, const char *type)
else if(! strcmp(gi, "GUARD_INTERVAL_1_8"))
ptr->gi = GUARD_INTERVAL_1_8;
else ptr->gi = GUARD_INTERVAL_1_4;
-
-
- }
- /*
- else if(! strcmp(type, "CBL"))
- {
- fields = sscanf(line, cbl_conf,
- &ptr->name, &ptr->freq, &ptr->inv, &ptr->qam,
- &ptr->fec, &ptr->mod, &ptr->vpid, &ptr->apid1);
-
-
- }
- */
- else //SATELLITE
- {
- fields = sscanf(line, sat_conf,
- &ptr->name, &ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate, &ptr->vpid, &ptr->apid1,
- &ptr->tpid, &ptr->ca, &ptr->progid);
- ptr->pol = toupper(ptr->pol);
- ptr->freq *= 1000UL;
- ptr->srate *= 1000UL;
- ptr->tone = -1;
- mp_msg(MSGT_DEMUX, MSGL_V,
- "NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d, POL: %c, DISEQC: %d, TONE: %d, VPID: %d, APID1: %d, APID2: %d, TPID: %d, PROGID: %d, NUM: %d\n",
- fields, ptr->name, ptr->freq, ptr->srate, ptr->pol, ptr->diseqc, ptr->tone, ptr->vpid, ptr->apid1, ptr->apid2, ptr->tpid, ptr->progid, list->NUM_CHANNELS);
}
list->NUM_CHANNELS++;
@@ -243,442 +266,476 @@ dvb_channels_list *dvb_get_channels(char *filename, const char *type)
}
fclose(f);
+ list->current = 0;
return list;
}
-static long getmsec()
+
+static int dvb_streaming_read(stream_t *stream, char *buffer, int size)
{
- struct timeval tv;
- gettimeofday(&tv, (struct timezone*) NULL);
- return(tv.tv_sec%1000000)*1000 + tv.tv_usec/1000;
+ struct pollfd pfds[1];
+ int pos=0, tries, rk;
+ int fd = stream->fd;
+ dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
+
+ mp_msg(MSGT_DEMUX, MSGL_V, "dvb_streaming_read(%d)\n", size);
+
+ if(priv->retry)
+ tries = 5;
+ else
+ tries = 1;
+ while(pos < size)
+ {
+ pfds[0].fd = fd;
+ pfds[0].events = POLLIN | POLLPRI;
+
+ poll(pfds, 1, 500);
+ rk = size - pos;
+ if((rk = read(fd, &buffer[pos], rk)) > 0)
+ {
+ pos += rk;
+ mp_msg(MSGT_DEMUX, MSGL_V, "ret (%d) bytes\n", pos);
+ }
+ else
+ {
+ 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)
+ {
+ errno = 0;
+ //reset_demuxers(priv);
+ continue;
+ }
+ else
+ {
+ errno = 0;
+ break;
+ }
+ }
+ }
+
+ if(! pos)
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_streaming_read, return %d bytes\n", pos);
+
+ return pos;
}
+static int reset_demuxers(dvb_priv_t *priv)
+{
+ dvb_channel_t *channel;
+ dvb_channels_list *list = priv->list;
+
+ channel = &(list->channels[list->current]);
+
+ if(priv->is_on) //the fds are already open and we have to stop the demuxers
+ {
+ dvb_demux_stop(priv->demux_fd[0]);
+ dvb_demux_stop(priv->demux_fd[1]);
+ }
+
+ if(channel->vpid)
+ if(! dvb_set_ts_filt(priv->demux_fd[0], channel->vpid, DMX_PES_VIDEO))
+ return 0;
+ //dvb_demux_start(priv->demux_fd[0]);
+
+ if(channel->apid1)
+ if(! dvb_set_ts_filt(priv->demux_fd[1], channel->apid1, DMX_PES_AUDIO))
+ return 0;
+
+ printf("RESET DEMUXERS SUCCEDED, errno=%d\n\n\n", errno);
+}
-int dvb_streaming_read(int fd, char *buffer, unsigned int size, dvb_priv_t *priv)
+
+int dvb_set_channel(dvb_priv_t *priv, int n)
{
- struct pollfd pfds[1];
- uint32_t ok = 0, pos = 0, tot = 0, rk, d, r, m;
+ dvb_channels_list *list;
+ dvb_channel_t *channel;
+ int do_tuning;
+ stream_t *stream = (stream_t*) priv->stream;
+ char buf[4096];
- mp_msg(MSGT_DEMUX, MSGL_DBG2, "dvb_streaming_read(%u)\n", fd);
+ if(priv->is_on) //the fds are already open and we have to stop the demuxers
+ {
+ dvb_demux_stop(priv->demux_fd[0]);
+ dvb_demux_stop(priv->demux_fd[1]);
+ priv->retry = 0;
+ while(stream_read(stream, buf, 4096)); //empty both the stream's and driver's buffer
+ }
- while(pos < size)
+ priv->retry = 1;
+ mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: channel %d\n", n);
+ list = priv->list;
+ if(list == NULL)
{
- ok = 0;
- tot = 0;
- //int m = min((size-pos), 188);
- m = size - pos;
- d = (int) (m / 188);
- r = m % 188;
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: LIST NULL PTR, quit\n");
+ return 0;
+ }
- m = d * 188;
- m = (m ? m : r);
+ if((n > list->NUM_CHANNELS) || (n < 0))
+ {
+ mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CHANNEL NUMBER: %d, abort\n", n);
+ return 0;
+ }
- pfds[0].fd = fd;
- pfds[0].events = POLLIN | POLLPRI;
+ list->current = n;
+ channel = &(list->channels[list->current]);
+ mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: new channel name=%s\n", channel->name);
- mp_msg(MSGT_DEMUX, MSGL_DBG2, "DEVICE: %d, DVR: %d, PIPE: %d <-> %d\n", fd, priv->dvr_fd, priv->input, priv->output);
+ 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;
+ }
- poll(pfds, 1, 500);
- if((rk = read(fd, &buffer[pos], m)) > 0)
- pos += rk;
+
+
+ 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
+ {
+ mp_msg(MSGT_DEMUX, MSGL_V, "SAME TUNING, NO TUNING\n");
+ do_tuning = 0;
}
- return pos;
+ stream->eof=1;
+ stream_reset(stream);
+
+
+ if(do_tuning)
+ if (! dvb_tune(priv, channel->freq, channel->pol, channel->srate, channel->diseqc, channel->tone,
+ channel->inv, channel->mod, channel->gi, channel->trans, channel->bw, channel->cr))
+ return 0;
+
+
+ priv->is_on = 1;
+
+ //sets demux filters and restart the stream
+ if(channel->vpid)
+ if(! dvb_set_ts_filt(priv->demux_fd[0], channel->vpid, DMX_PES_VIDEO))
+ return 0;
+ //dvb_demux_start(priv->demux_fd[0]);
+
+ if(channel->apid1)
+ if(! dvb_set_ts_filt(priv->demux_fd[1], channel->apid1, DMX_PES_AUDIO))
+ return 0;
+ //dvb_demux_start(priv->demux_fd[1]);
+
+ return 1;
}
-dvb_history_t *dvb_step_channel(dvb_priv_t *priv, int dir, dvb_history_t *h)
+int dvb_step_channel(dvb_priv_t *priv, int dir)
{
- //int new_freq, new_srate, new_diseqc, new_tone, new_vpid, new_apid;
- //char new_pol;
- int new_current;
- dvb_channel_t *next;
- dvb_channels_list *list;
-
- if(priv == NULL)
- {
- mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: PRIV NULL PTR, quit\n");
- return 0;
- }
-
- list = priv->list;
- if(list == NULL)
- {
- mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: LIST NULL PTR, quit\n");
- return 0;
- }
-
- mp_msg(MSGT_DEMUX, MSGL_V, "DVB_STEP_CHANNEL dir %d\n", dir);
-
- if(dir == DVB_CHANNEL_HIGHER)
- {
- if(list->current == list->NUM_CHANNELS)
- return 0;
-
- new_current = list->current + 1;
- next = &(list->channels[new_current]);
- }
- else
- {
- if(list->current == 0)
- return 0;
-
- new_current = list->current - 1;
- next = &(list->channels[new_current]);
-
- }
-
- demux_stop(priv->demux_fd[0]);
- demux_stop(priv->demux_fd[1]);
-
- h->prev = list->current;
- h->next = new_current;
-
- list->current = new_current;
-
- return h;
+ 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;
+ }
+
+ return dvb_set_channel(priv, new_current);
}
-extern char *get_path(char *);
-dvb_channels_list *list_ptr = NULL;
-int dvb_streaming_start(stream_t *stream)
+extern char *get_path(char *);
+
+static void dvbin_close(stream_t *stream)
{
- int pids[MAX_CHANNELS];
- int pestypes[MAX_CHANNELS];
- int npids, i;
- char *filename, type[80];
- unsigned long freq = 0;
- char pol = 0;
- unsigned long srate = 0;
- int diseqc = 0, old_diseqc = 0;
- int tone = -1;
+ dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
- dvb_priv_t *priv;
- dvb_channel_t *channel = NULL;
- fe_spectral_inversion_t specInv = INVERSION_AUTO;
- fe_modulation_t modulation = CONSTELLATION_DEFAULT;
- fe_transmit_mode_t TransmissionMode = TRANSMISSION_MODE_DEFAULT;
- fe_bandwidth_t bandWidth = BANDWIDTH_DEFAULT;
- fe_guard_interval_t guardInterval = GUARD_INTERVAL_DEFAULT;
- fe_code_rate_t HP_CodeRate = HP_CODERATE_DEFAULT;
+ close(priv->dvr_fd);
+ close(priv->demux_fd[0]);
+ close(priv->demux_fd[1]);
+ priv->is_on = 0;
+ priv->stream = NULL;
+ if(dvb_list_ptr)
+ free(dvb_list_ptr);
+ dvb_list_ptr = NULL;
+}
- stream->priv = (dvb_priv_t*) malloc(sizeof(dvb_priv_t));
- if(stream->priv == NULL)
- return 0;
- priv = (dvb_priv_t*) stream->priv;
- if(!strncmp(dvbin_param_type, "CBL", 3))
- strncpy(type, "CBL", 3);
- else if(!strncmp(dvbin_param_type, "TER", 3))
- strncpy(type, "TER", 3);
- else
- strncpy(type, "SAT", 3);
+static int dvb_streaming_start(dvb_priv_t *priv, struct stream_priv_s *opts, int tuner_type)
+{
+ int pids[MAX_CHANNELS], pestypes[MAX_CHANNELS], npids = 0, i;
+ dvb_channel_t *channel = NULL;
+ stream_t *stream = (stream_t*) priv->stream;
- filename = get_path("channels.conf");
+ 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;
- if(list_ptr == NULL)
+ if(strlen(opts->prog))
{
- if(filename)
+ if(dvb