Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linux-dvb] dvb-input PATCH for mplayer



Hi,

this patch for mplayer-cvs adds three things to the existing code (that is
actually broken)

1) OSD menu of channels
2) howto instructions in DOCS/en/dvbin-howto.txt
3) recording to a recompressed format is now reliable (doesn't break at
the first EOVERFLOW), but continues with eventual glitches in the recorded
stream; as usual the more powerful CPU you have the better.

As always non-FTA channels are not supported and mpalyer hangs when you
select one of them, so please remove them from you ~/.mplayer/channels.conf.

As the tuning code is taken from dvbstream, my patch always uses
INVERSION_OFF, so it might suffer from the same problems reported some
days ago by some DVB-T users. I'll update the code as soon as I have some
more information about this issue.

Feedback  and suggestions are welcome.

Thanks,
		Nico


diff -Naur MPlayer-20030612/cfg-common.h MPlayer-20030612-new/cfg-common.h
--- MPlayer-20030612/cfg-common.h	2003-05-17 14:23:32.000000000 +0200
+++ MPlayer-20030612-new/cfg-common.h	2003-06-12 21:53:28.000000000 +0200
@@ -108,7 +108,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
 
 
@@ -322,9 +322,10 @@
 
 #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;
 
 extern int sws_chr_vshift;
diff -Naur MPlayer-20030612/input/input.c MPlayer-20030612-new/input/input.c
--- MPlayer-20030612/input/input.c	2003-06-09 14:15:42.000000000 +0200
+++ MPlayer-20030612-new/input/input.c	2003-06-12 21:48:09.000000000 +0200
@@ -86,6 +86,9 @@
   { MP_CMD_TV_SET_CHANNEL, "tv_set_channel", 1, { { MP_CMD_ARG_STRING, {0}}, {-1,{0}}  }},
   { MP_CMD_TV_LAST_CHANNEL, "tv_last_channel", 0, { {-1,{0}} } },
 #endif
+#ifdef HAS_DVBIN_SUPPORT
+  { MP_CMD_DVB_SET_CHANNEL, "dvb_set_channel", 1, { { MP_CMD_ARG_INT, {0}}, {-1,{0}}  }},
+#endif
   { MP_CMD_VO_FULLSCREEN, "vo_fullscreen", 0, { {-1,{0}} } },
   { MP_CMD_SCREENSHOT, "screenshot", 0, { {-1,{0}} } },
   { MP_CMD_PANSCAN, "panscan",1,  { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
diff -Naur MPlayer-20030612/input/input.h MPlayer-20030612-new/input/input.h
--- MPlayer-20030612/input/input.h	2003-05-17 11:21:21.000000000 +0200
+++ MPlayer-20030612-new/input/input.h	2003-06-12 21:48:42.000000000 +0200
@@ -55,6 +55,11 @@
 #define MP_CMD_GUI_FULLSCREEN   5008
 #define MP_CMD_GUI_SKINBROWSER  5009
 
+#ifdef HAS_DVBIN_SUPPORT
+#define MP_CMD_DVB_SET_CHANNEL 5101
+#endif
+
+
 #define MP_CMD_DVDNAV_EVENT     6000
 
 #define MP_CMD_DVDNAV_UP        1
diff -Naur MPlayer-20030612/libmenu/Makefile MPlayer-20030612-new/libmenu/Makefile
--- MPlayer-20030612/libmenu/Makefile	2002-12-28 19:51:09.000000000 +0100
+++ MPlayer-20030612-new/libmenu/Makefile	2003-06-12 21:49:30.000000000 +0200
@@ -4,6 +4,9 @@
 LIBNAME = libmenu.a
 
 SRCS= menu.c vf_menu.c menu_cmdlist.c menu_pt.c menu_list.c menu_filesel.c menu_txt.c menu_console.c menu_param.c
+ifeq ($(DVBIN),yes)
+SRCS += menu_dvbin.c
+endif
 OBJS=$(SRCS:.c=.o)
 
 CFLAGS  = $(OPTFLAGS) -I. -I.. -I../libmpcodecs $(EXTRA_INC) -Wall
diff -Naur MPlayer-20030612/libmenu/menu.c MPlayer-20030612-new/libmenu/menu.c
--- MPlayer-20030612/libmenu/menu.c	2003-02-09 21:18:20.000000000 +0100
+++ MPlayer-20030612-new/libmenu/menu.c	2003-06-12 22:57:41.000000000 +0200
@@ -25,6 +25,9 @@
 extern menu_info_t menu_info_txt;
 extern menu_info_t menu_info_console;
 extern menu_info_t menu_info_pref;
+#ifdef HAS_DVBIN_SUPPORT
+extern menu_info_t menu_info_dvbsel;
+#endif
 
 menu_info_t* menu_info_list[] = {
   &menu_info_pt,
@@ -32,6 +35,9 @@
   &menu_info_filesel,
   &menu_info_txt,
   &menu_info_console,
+#ifdef HAS_DVBIN_SUPPORT
+  &menu_info_dvbsel,
+#endif  
   &menu_info_pref,
   NULL
 };
diff -Naur MPlayer-20030612/libmenu/menu_dvbin.c MPlayer-20030612-new/libmenu/menu_dvbin.c
--- MPlayer-20030612/libmenu/menu_dvbin.c	1970-01-01 01:00:00.000000000 +0100
+++ MPlayer-20030612-new/libmenu/menu_dvbin.c	2003-05-08 22:46:43.000000000 +0200
@@ -0,0 +1,191 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <limits.h>
+
+
+#include "../config.h"
+
+#include "../m_struct.h"
+#include "../m_option.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+
+#include "menu.h"
+#include "menu_list.h"
+#include "../input/input.h"
+#include "../osdep/keycodes.h"
+
+#include "../libmpdemux/dvbin.h"
+
+
+
+struct list_entry_s {
+  struct list_entry p;
+  int num;		//the position of the chosen channel in the list
+};
+
+struct menu_priv_s {
+  menu_list_priv_t p;
+  char* title;
+  char* file;
+  int card;
+};
+
+
+#define ST_OFF(m) M_ST_OFF(struct menu_priv_s, m)
+#define mpriv (menu->priv)
+
+static m_option_t cfg_fields[] = {
+  MENU_LIST_PRIV_FIELDS,
+  { "title", ST_OFF(title), CONF_TYPE_STRING, 0, 0, 0, NULL },
+  { "file", ST_OFF(file),  CONF_TYPE_STRING, 0, 0, 0, NULL },
+  { "card", ST_OFF(card),  CONF_TYPE_INT, 0, 0, 0, NULL },
+  { NULL, NULL, NULL, 0,0,0,NULL }
+};
+
+
+static struct menu_priv_s cfg_dflt = {
+  MENU_LIST_PRIV_DFLT,
+  "Select a channel: %p",
+  "channels.conf",
+  1,
+  NULL,
+};
+
+
+
+
+static void free_entry(list_entry_t* entry)
+{
+  free(entry->p.txt);
+  free(entry);
+}
+
+
+static int fill_menu(menu_t* menu)
+{
+	int n;
+	list_entry_t* elem;
+	char *name;
+	extern dvb_channels_list  *list_ptr;
+	dvb_channel_t *channel;
+
+	menu_list_init(menu);
+	
+	mpriv->p.title = mpriv->title;
+	
+	if(list_ptr == NULL)
+    {
+    	mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: LIST NULL PTR, quit\n");
+		n = 1;
+		if((elem = malloc(sizeof(list_entry_t))) != NULL)
+		{
+			name = malloc(80);
+			sprintf(name, "Empty channel list from file %s; \nrun mplayer dvb:// to load the list", mpriv->file);
+			elem->p.next 	= NULL;
+			elem->p.txt 	= name;
+
+			menu_list_add_entry(menu, elem);
+		}
+    }
+	else
+	{
+		n = list_ptr->NUM_CHANNELS;
+		for(n = 0; n < list_ptr->NUM_CHANNELS; n++)
+		{
+			channel = &(list_ptr->channels[n]);
+			if((elem = malloc(sizeof(list_entry_t))) != NULL)
+			{
+		  		name = malloc(80);
+				strncpy(name, channel->name, 79);
+				name[79] = 0;
+				elem->p.next 	= NULL;
+				elem->p.txt 	= name;
+				elem->num 	= n;
+				
+				
+				menu_list_add_entry(menu, elem);
+			}
+			else
+			{
+				mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_menu: fill_menu: couldn't malloc %d bytes for menu item: %s, exit\n", 
+						sizeof(list_entry_t), strerror(errno));
+			
+			  if(n)
+				return 1;
+			
+			  return 0;
+			}
+		}  
+	}
+	
+	return 1;
+}
+
+
+static void read_cmd(menu_t* menu, int cmd)
+{
+  list_entry_t *p;
+  mp_cmd_t* c;
+  char *cmd_name;
+  switch(cmd)
+  {
+	case MENU_CMD_OK:
+	{
+		p = mpriv->p.current;
+		mp_msg(MSGT_DEMUX, MSGL_V, "CHOSEN DVB CHANNEL %d\n\n", p->num);
+		
+		cmd_name = malloc(30);
+		sprintf(cmd_name, "dvb_set_channel %d", p->num);
+		c = mp_input_parse_cmd(cmd_name);
+    	if(c)
+		  mp_input_queue_cmd(c);
+  	}
+  	break;
+
+  	default:
+    	menu_list_read_cmd(menu, cmd);
+  }
+}
+
+
+static void close_menu(menu_t* menu)
+{
+	menu_list_uninit(menu, free_entry);
+	//free(mpriv->dir);
+}
+
+
+static int open_dvb_sel(menu_t* menu, char* args)
+{
+	menu->draw 		= menu_list_draw;
+	menu->read_cmd 	= read_cmd;
+	//menu->read_key 	= read_key;
+	menu->close 	= close_menu;
+
+	return fill_menu(menu);
+}
+
+const menu_info_t menu_info_dvbsel =
+{
+  "DVB channels menu",	//descr
+  "dvbsel",						//name
+  "Nico",						//author
+  "dvb_sel",
+  {								//m_struct_t priv_st=
+    "dvb_cfg",					//name
+    sizeof(dvb_channels_list),	//size
+    &cfg_dflt,					//defaults
+    cfg_fields					//settable fields
+  },
+  open_dvb_sel					//open function
+};
diff -Naur MPlayer-20030612/libmpdemux/dvbin.c MPlayer-20030612-new/libmpdemux/dvbin.c
--- MPlayer-20030612/libmpdemux/dvbin.c	2003-03-16 21:13:28.000000000 +0100
+++ MPlayer-20030612-new/libmpdemux/dvbin.c	2003-06-12 21:39:10.000000000 +0200
@@ -23,7 +23,7 @@
 
 */
 
-// Linux includes:
+#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,93 +31,113 @@
 #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},
+  
+  {"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}
+};
 
-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}
+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 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 int get_tuner_type(dvb_priv_t *priv);
 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];
 
+dvb_channels_list  *list_ptr = NULL;
+
 
-dvb_channels_list *dvb_get_channels(char *filename, const char *type)
+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 +145,7 @@
 		return NULL;
 	}
 
-	mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %s\n", filename, type);
+	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,95 +156,27 @@
 	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);
-
-			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(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;
-			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;
-
-			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;
-			else ptr->mod = QPSK;
-
-
-			if(! strcmp(transm, "TRANSMISSION_MODE_2K"))
-				ptr->trans = TRANSMISSION_MODE_2K;
-			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"))
-				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;
-
-
 		}
-		/*
-		else if(! strcmp(type, "CBL"))
+		else if(type == TUNER_CBL)
 		{
 			fields = sscanf(line, cbl_conf,
-                                &ptr->name, &ptr->freq, &ptr->inv, &ptr->qam,
-                                &ptr->fec, &ptr->mod, &ptr->vpid, &ptr->apid1);
-
+                &ptr->name, &ptr->freq, &inv, &ptr->srate,
+                &cr, &mod, &ptr->vpid, &ptr->apid1);
 
 		}
-		*/
-		else	//SATELLITE
+		else //SATELLITE
 		{
 			fields = sscanf(line, sat_conf,
 				&ptr->name, &ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate, &ptr->vpid, &ptr->apid1,
@@ -238,88 +190,278 @@
 				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(! 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(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;
+		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;
+
+		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;
+		//else ptr->mod = QPSK;
+
+
+		if(! strcmp(transm, "TRANSMISSION_MODE_2K"))
+			ptr->trans = TRANSMISSION_MODE_2K;
+		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"))
+			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;
+
+
 		list->NUM_CHANNELS++;
 		row_count++;
 	}
 
 	fclose(f);
+	list->current = 0;
 	return list;
 }
 
 
-static long getmsec()
-{
-	struct timeval tv;
-	gettimeofday(&tv, (struct timezone*) NULL);
-	return(tv.tv_sec%1000000)*1000 + tv.tv_usec/1000;
-}
-
-
 
-int dvb_streaming_read(int fd, char *buffer, unsigned int size, dvb_priv_t *priv)
+static int dvb_streaming_read(stream_t *stream, char *buffer, int size)
 {
 	struct pollfd pfds[1];
-	uint32_t ok = 0, pos = 0, tot = 0, rk, d, r, m;
-
-	mp_msg(MSGT_DEMUX, MSGL_DBG2, "dvb_streaming_read(%u)\n", fd);
+	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)
 	{
-	    ok = 0;
-	    tot = 0;
-	    //int m = min((size-pos), 188);
-	    m = size - pos;
-	    d = (int) (m / 188);
-	    r = m % 188;
-
-	    m = d * 188;
-	    m = (m ? m : r);
-
 	    pfds[0].fd = fd;
 	    pfds[0].events = POLLIN | POLLPRI;
 
-	    mp_msg(MSGT_DEMUX, MSGL_DBG2, "DEVICE: %d, DVR: %d, PIPE: %d <-> %d\n", fd, priv->dvr_fd, priv->input, priv->output);
-
 	    poll(pfds, 1, 500);
-	    if((rk = read(fd, &buffer[pos], m)) > 0)
-	    	pos += rk;
+		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;
 }
 
 
+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
+	{
+	  demux_stop(priv->demux_fd[0]);
+  	  demux_stop(priv->demux_fd[1]);
+	}
+	
+	if(channel->vpid)
+  	  if(! set_ts_filt(priv->demux_fd[0], channel->vpid, DMX_PES_VIDEO))
+		return 0;
+	//demux_start(priv->demux_fd[0]);
+	  
+	if(channel->apid1)
+	  if(! 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_set_channel(dvb_priv_t *priv, int n)
+{
+	dvb_channels_list *list;
+	dvb_channel_t *channel;
+	int do_tuning;
+	stream_t *stream  = (stream_t*) priv->stream;
+	char buf[4096];
+	
+	if(priv->is_on)	//the fds are already open and we have to stop the demuxers
+	{
+	  demux_stop(priv->demux_fd[0]);
+  	  demux_stop(priv->demux_fd[1]);
+	  priv->retry = 0;
+	  while(stream_read(stream, buf, 4096));	//empty both the stream's and driver's buffer
+	}
+	
+	priv->retry = 1;
+	mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: channel %d\n", n);
+	list = priv->list;
+    if(list == NULL)
+    {
+    	mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: LIST NULL PTR, quit\n");
+    	return 0;
+    }
+	
+	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;
+	}
+	
+    list->current = n;
+	channel = &(list->channels[list->current]);
+	mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: new channel name=%s\n", channel->name);
+	
+	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;
+	}
+	
+	
+	
+	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;
+	}
+
+	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(! set_ts_filt(priv->demux_fd[0], channel->vpid, DMX_PES_VIDEO))
+		return 0;
+	//demux_start(priv->demux_fd[0]);
+	  
+	if(channel->apid1)
+	  if(! set_ts_filt(priv->demux_fd[1], channel->apid1, DMX_PES_AUDIO))
+		return 0;
+	//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;
 
+	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: PRIV NULL PTR, quit\n");
+    	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: LIST NULL PTR, quit\n");
+    	mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: NULL list_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)
+    	if(list->current == list->NUM_CHANNELS-1)
     		return 0;
-
+	  
     	new_current = list->current + 1;
-    	next = &(list->channels[new_current]);
     }
     else
     {
@@ -327,358 +469,267 @@
     		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;
+	return dvb_set_channel(priv, new_current);
+}
 
-    list->current = new_current;
 
-    return h;
-}
 
 
 extern char *get_path(char *);
 
-dvb_channels_list  *list_ptr = NULL;
-
-int dvb_streaming_start(stream_t *stream)
+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_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;
-
-
-	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);
+	dvb_priv_t *priv  = (dvb_priv_t *) stream->priv;
+	
+	close(priv->dvr_fd);
+	close(priv->demux_fd[0]);
+	close(priv->demux_fd[1]);
+	priv->is_on = 0;
+	priv->stream = NULL;
+	if(list_ptr)
+	  free(list_ptr);
+	  
+	list_ptr = NULL;
+}
 
 
-	filename = get_path("channels.conf");
+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;
+	
+		
+	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);
 
-	if(list_ptr == NULL)
-	{
-		if(filename)
-		{
-			if((list_ptr = dvb_get_channels(filename, type)) == NULL)
-				mp_msg(MSGT_DEMUX, MSGL_WARN, "EMPTY CHANNELS LIST!\n");
-			else
-			{
-				priv->list = list_ptr;
-				priv->list->current = 0;
-			}
+	priv->is_on = 0;		
+	
+	if(strlen(opts->prog))
+	{
+		if(list_ptr != NULL)
+		{
+	  	  i = 0;
+	  	  while((channel == NULL) && i < list_ptr->NUM_CHANNELS)
+		  {
+			if(! strcmp(list_ptr->channels[i].name, opts->prog))
+		  		channel = &(list_ptr->channels[i]);
+			  
+			i++;
+	  	  }
+		  
+	  	  if(channel != NULL)
+	  	  {
+			list_ptr->current = i-1;
+	    	  mp_msg(MSGT_DEMUX, MSGL_V, "PROGRAM NUMBER %d: name=%s, vid=%d, aid=%d, freq=%lu, srate=%lu, pol=%c, diseqc: %d, tone: %d\n", i-1,
+		  		channel->name, channel->vpid, channel->apid1,
+		  		channel->freq, channel->srate, channel->pol, channel->diseqc, channel->tone);
+	  	  }
+		  else if(opts->prog)
+		  {
+			  mp_msg(MSGT_DEMUX, MSGL_ERR, "\n\nDVBIN: no such channel \"%s\"\n\n", opts->prog);
+			  return 0;
+		  }
 		}
 		else
 		{
-			list_ptr = NULL;
-			mp_msg(MSGT_DEMUX, MSGL_WARN, "NO CHANNELS FILE FOUND!\n");
+			mp_msg(MSGT_DEMUX, MSGL_ERR, "DVBIN: chanel %s requested, but no channel list supplied %s\n", opts->prog);
+			return 0;
 		}
 	}
+	
 
 
-	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, "ON: %d, CARD: %d, FREQ: %d, SRATE: %d, POL: %s, VID: %d, AID: %d\n", dvbin_param_on,
-	    dvbin_param_card, dvbin_param_freq, dvbin_param_srate, dvbin_param_pol, dvbin_param_vid, dvbin_param_aid);
-
-	npids = 0;
-
-	if((dvb_prev_next.next > -1) && (dvb_prev_next.prev > -1) && (list_ptr != NULL))	//We are after a channel stepping
-	{
-	    list_ptr->current = dvb_prev_next.next;
-	    channel = &(list_ptr->channels[dvb_prev_next.next]);
-	    mp_msg(MSGT_DEMUX, MSGL_V, "PROGRAM NUMBER %d: name=%s, vid=%d, aid=%d, freq=%lu, srate=%lu, pol=%c, diseqc: %d, tone: %d\n", dvb_prev_next.next,
-		    channel->name, channel->vpid, channel->apid1,
-		    channel->freq, channel->srate, channel->pol, channel->diseqc, channel->tone);
-
-
-	    if((dvb_prev_next.prev >= 0) && (dvb_prev_next.prev < list_ptr->NUM_CHANNELS))
-	    {
-		dvb_channel_t *tmp = &(list_ptr->channels[dvb_prev_next.prev]);
-		old_diseqc = tmp->diseqc;
-	    }
-	}
-	else if(list_ptr != NULL && strlen(dvbin_param_prog))
-	{
-	    i = 0;
-	    while((channel == NULL) && i < list_ptr->NUM_CHANNELS)
-	    {
-		if(! strcmp(list_ptr->channels[i].name, dvbin_param_prog))
-		    channel = &(list_ptr->channels[i]);
-
-		i++;
-	    }
-	    if(channel != NULL)
-	    {
-		list_ptr->current = i-1;
-	    	mp_msg(MSGT_DEMUX, MSGL_V, "PROGRAM NUMBER %d: name=%s, vid=%d, aid=%d, freq=%lu, srate=%lu, pol=%c, diseqc: %d, tone: %d\n", i-1,
-		    channel->name, channel->vpid, channel->apid1,
-		    channel->freq, channel->srate, channel->pol, channel->diseqc, channel->tone);
-
-	    }
-	}
-
-
-	if(dvbin_param_vid > 0)
+	if(opts->vid > 0)
 	{
-	    pids[npids] = priv->channel.vpid = dvbin_param_vid;
+	    pids[npids] =  opts->vid;
 	}
 	else if(channel != NULL)
 	{
-	    pids[npids] = priv->channel.vpid = channel->vpid;
+	    pids[npids] =  channel->vpid;
 	}
 	pestypes[npids] = DMX_PES_VIDEO;
 	npids++;
 
-	if(dvbin_param_aid > 0)
+	if(opts->aid > 0)
 	{
-	    pids[npids] = priv->channel.apid1 = dvbin_param_aid;
+	    pids[npids] = opts->aid;
 	}
 	else if(channel != NULL)
 	{
-	    pids[npids] = priv->channel.vpid = channel->apid1;
+	    pids[npids] = channel->apid1;
 	}
 	pestypes[npids] = DMX_PES_AUDIO;
 	npids++;
 
+	
+	
+	priv->demux_fd[0] = open(demuxdev[priv->card], O_RDWR);
+	if(priv->demux_fd[0] < 0)
+	{
+		mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX 0: %d\n", errno);
+		return 0;
+	}
+	
+	priv->demux_fd[1] = open(demuxdev[priv->card], O_RDWR);
+	if(priv->demux_fd[1] < 0)
+	{
+		mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX 1: %d\n", errno);
+		return 0;
+	}
+	
 
+	priv->dvr_fd = open(dvrdev[priv->card], O_RDONLY| O_NONBLOCK);
+	if(priv->dvr_fd < 0)
+	{
+	  mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DVR DEVICE %s: %d\n", dvrdev[priv->card], errno);
+	  return 0;
+	}
+		
+	
+	strcpy(priv->prev_tuning, "");
+	if(!dvb_set_channel(priv, list_ptr->current))
+	{
+		mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR, COULDN'T SET CHANNEL  %i: ", list_ptr->current);
+		dvbin_close(stream);
+		return 0;
+	}
+		
+	stream->fd = priv->dvr_fd;
+	
+	mp_msg(MSGT_DEMUX, MSGL_V,  "SUCCESSFUL EXIT from dvb_streaming_start\n");
+  
+	return 1;
+}
 
-	if(dvbin_param_freq)
-	    freq  = dvbin_param_freq  * 1000UL;
-	else  if(channel != NULL)
-	    freq = channel->freq;
 
 
-	if(dvbin_param_srate)
-	    srate = dvbin_param_srate * 1000UL;
-	else  if(channel != NULL)
-	    srate = channel->srate;
 
-	if((1<= dvbin_param_diseqc)  && (dvbin_param_diseqc <= 4))
-	    diseqc = dvbin_param_diseqc;
-	else
-	    if(channel != NULL)
-		if(channel->diseqc != old_diseqc)
-		    diseqc = channel->diseqc;
-		else
-		    diseqc = 0;
-	    else
-		diseqc = 0;
-	mp_msg(MSGT_DEMUX, MSGL_INFO, "DISEQC: %d\n", diseqc);
-
-	if((dvbin_param_tone == 0) || (dvbin_param_tone == 1))
-	    tone = dvbin_param_tone;
-	else
-	    if(channel != NULL)
-		tone = channel->tone;
-	    else
-		tone = -1;
-
-	if(! strcmp(dvbin_param_pol, "V")) pol = 'V';
-	else if(! strcmp(dvbin_param_pol, "H")) pol = 'H';
-	else if(channel != NULL) pol = channel->pol;
-	else pol='V';
-	pol = toupper(pol);
-
-
-	if(!strcmp(dvbin_param_inv, "INVERSION_ON"))
-		specInv = INVERSION_ON;
-	else if(!strcmp(dvbin_param_inv, "INVERSION_OFF"))
-		specInv = INVERSION_OFF;
-	else if(!strcmp(dvbin_param_inv, "INVERSION_AUTO"))
-		specInv = INVERSION_AUTO;
-	else if(channel != NULL)
-		specInv = channel->inv;
-	else
-		specInv = INVERSION_AUTO;
+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;
+	char *name = NULL, *filename;
+	dvb_priv_t *priv;
+	int tuner_type;
+	
+	
+	
+	if(mode != STREAM_READ)
+	    return STREAM_UNSUPORTED;
 
+	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;
 
-	if(dvbin_param_mod)
+	name = malloc(sizeof(char)*128);
+	
+	if(name == NULL)
 	{
-		switch(dvbin_param_mod)
-		{
-			case 16:  modulation=QAM_16; break;
-			case 32:  modulation=QAM_32; break;
-			case 64:  modulation=QAM_64; break;
-			case 128: modulation=QAM_128; break;
-			case 256: modulation=QAM_256; break;
-			default:
-				mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid QAM rate: %s\n", dvbin_param_mod);
-				modulation=CONSTELLATION_DEFAULT;
-		}
+	  mp_msg(MSGT_DEMUX, MSGL_ERR, "COULDN'T MALLOC SOME TMP MEMORY, EXIT!\n");
+	  return STREAM_ERROR;
 	}
-	else  if(channel != NULL)
-	    	modulation = channel->mod;
-	else
-		modulation=CONSTELLATION_DEFAULT;
-
-
-	if(dvbin_param_gi)
+	
+	priv->card = p->card - 1;
+	
+	if(!strncmp(p->type, "CBL", 3))
 	{
-		switch(dvbin_param_gi)
-		{
-			case 32:  guardInterval=GUARD_INTERVAL_1_32; break;
-			case 16:  guardInterval=GUARD_INTERVAL_1_16; break;
-			case 8:   guardInterval=GUARD_INTERVAL_1_8; break;
-			case 4:   guardInterval=GUARD_INTERVAL_1_4; break;
-			default:
-				mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid Guard Interval: %s\n", dvbin_param_gi);
-				guardInterval=GUARD_INTERVAL_DEFAULT;
-		}
+		tuner_type = TUNER_CBL;
 	}
-	else  if(channel != NULL)
-	    	guardInterval = channel->gi;
-	else
-		guardInterval=GUARD_INTERVAL_DEFAULT;
-
-	if(dvbin_param_tm)
+	else if(!strncmp(p->type, "TER", 3))
 	{
-		switch(dvbin_param_tm)
-		{
-			case 8:   TransmissionMode=TRANSMISSION_MODE_8K; break;
-			case 2:   TransmissionMode=TRANSMISSION_MODE_2K; break;
-			default:
-				TransmissionMode=TRANSMISSION_MODE_DEFAULT;
-				mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid Transmission Mode: %s\n", dvbin_param_tm);
-		}
+		tuner_type = TUNER_TER;
 	}
-	else  if(channel != NULL)
-	    	TransmissionMode = channel->trans;
-	else
-		TransmissionMode=TRANSMISSION_MODE_DEFAULT;
-
-
-	if(dvbin_param_bw)
+	else if(!strncmp(p->type, "SAT", 3))
 	{
-		switch(dvbin_param_bw)
-		{
-			case 8:   bandWidth=BANDWIDTH_8_MHZ; break;
-			case 7:   bandWidth=BANDWIDTH_7_MHZ; break;
-			case 6:   bandWidth=BANDWIDTH_6_MHZ; break;
-			default:
-				mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid DVB-T bandwidth: %s\n", dvbin_param_bw);
-			       	bandWidth=BANDWIDTH_DEFAULT;
-		}
+		tuner_type = TUNER_SAT;
 	}
-	else  if(channel != NULL)
-	    	bandWidth = channel->bw;
 	else
-		bandWidth=BANDWIDTH_DEFAULT;
-
-
-	if(dvbin_param_cr)
 	{
-		switch(dvbin_param_cr)
+		int t = get_tuner_type(priv);
+		
+		if((t==TUNER_SAT) || (t==TUNER_TER) || (t==TUNER_CBL))
 		{
-			case -1: HP_CodeRate=FEC_AUTO; break;
-			case 12: HP_CodeRate=FEC_1_2; break;
-			case 23: HP_CodeRate=FEC_2_3; break;
-			case 34: HP_CodeRate=FEC_3_4; break;
-			case 56: HP_CodeRate=FEC_5_6; break;
-			case 78: HP_CodeRate=FEC_7_8; break;
-			default:
-				mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid Code Rate: %s\n", dvbin_param_cr);
-				HP_CodeRate=HP_CODERATE_DEFAULT;
+		  tuner_type = t;
 		}
 	}
-	else  if(channel != NULL)
-	    	HP_CodeRate = channel->cr;
-	else
-		HP_CodeRate=HP_CODERATE_DEFAULT;
-
-
-
-	card = dvbin_param_card - 1;
-	if((card < 0) || (card > 4))
-	    card = 0;
-
-
-	dvbin_param_on = 1;
-
-	mp_msg(MSGT_DEMUX, MSGL_V,  "CARD: %d, FREQ: %d, POL: %c, SRATE: %d, DISEQC: %d, TONE: %d, VPID: %d, APID: %d\n", card, freq, pol, srate, diseqc, tone, pids[0], pids[1]);
-
-	priv->channel.freq = freq;
-	priv->channel.srate = srate;
-	priv->channel.diseqc = diseqc;
-	priv->channel.pol = pol;
-	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;
-
-	if(freq && pol && srate)
-		if (! dvb_tune(priv, freq, pol, srate, diseqc, tone, specInv, modulation, guardInterval, TransmissionMode, bandWidth, HP_CodeRate))
-			return 0;
 
-	for (i=0; i < npids; i++)
+	priv->tuner_type = tuner_type;
+	
+	mp_msg(MSGT_DEMUX, MSGL_V, "OPEN_DVB: prog=%s, card=%d, type=%d, vid=%d, aid=%d, file=%s\n", 
+		p->prog, priv->card+1, priv->tuner_type, p->vid, p->aid, p->file);
+		
+	if(list_ptr == NULL)
 	{
-		if((priv->demux_fd[i] = open(demuxdev[card], O_RDWR)) < 0)
+		filename = get_path(p->file);
+		if(filename)
 		{
-	  		mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX %i: ", i);
-	  		return -1;
+			if((list_ptr = dvb_get_channels(filename, tuner_type)) == NULL)
+				mp_msg(MSGT_DEMUX, MSGL_ERR, "EMPTY CHANNELS LIST FROM FILE %s!\n", filename);
+			else
+			{
+				priv->list = list_ptr;
+			}
+		}
+		else
+		{
+			list_ptr = NULL;
+			mp_msg(MSGT_DEMUX, MSGL_WARN, "NO CHANNELS FILE FOUND!\n");
 		}
 	}
-
-	if((priv->dvr_fd = open(dvrdev[card], O_RDONLY| O_NONBLOCK)) < 0)
-	{
-		mp_msg(MSGT_DEMUX, MSGL_ERR, "DVR DEVICE: ");
-		return -1;
-	}
+	else
+	  priv->list = list_ptr;
 
 
-	/* Now we set the filters */
-	for (i=0; i< npids; i++)
+	if(! strcmp(p->prog, ""))
 	{
-	    set_ts_filt(priv->demux_fd[i], pids[i], pestypes[i]);
-	    //make_nonblock(fd[i]);
-	}
+	  if(list_ptr != NULL)
+	  {
+		dvb_channel_t *channel;
+		
+		channel = &(list_ptr->channels[list_ptr->current]);
+		p->prog = channel->name;
+	  }
+	}
+	
+	
+	if(! dvb_streaming_start(priv, p, tuner_type))
+	{
+	  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;
+}
 
 
-	stream->fd = priv->dvr_fd;
 
-	dvbin_is_active = 1;
+stream_info_t stream_info_dvb = {
+  "Dvb Input",
+  "dvbin",
+  "Albeu",
+  "based on the code from ??? (probably Arpi)",
+  dvb_open, 			//open_dvb_stream,
+  { "dvb", NULL },
+  &stream_opts,
+  1 					// Urls are an option string
+};
 
-	mp_msg(MSGT_DEMUX, MSGL_DBG2,  "ESCO da dvb_streaming_start(s)\n");
 
-	return 1;
-}
 
 
-int dvbin_close(dvb_priv_t *priv)
-{
-	//close(priv->dvr_fd);
-	close(priv->demux_fd[0]);
-	close(priv->demux_fd[1]);
-}
diff -Naur MPlayer-20030612/libmpdemux/dvbin.h MPlayer-20030612-new/libmpdemux/dvbin.h
--- MPlayer-20030612/libmpdemux/dvbin.h	2003-03-16 23:59:16.000000000 +0100
+++ MPlayer-20030612-new/libmpdemux/dvbin.h	2003-05-12 23:54:35.000000000 +0200
@@ -2,6 +2,9 @@
 #ifndef DVBIN_H
 #define DVBIN_H
 
+#include "dvb_defaults.h"
+#include "stream.h"
+
 #ifdef HAVE_DVB_HEAD
 	#include <linux/dvb/dmx.h>
 	#include <linux/dvb/frontend.h>
@@ -38,11 +41,11 @@
 	int 				freq, srate, diseqc, tone;
 	char 				pol;
 	int 				vpid, apid1, apid2, tpid, dpid1, dpid2, progid, ca;
-	fe_spectral_inversion_t 	inv;
+	fe_spectral_inversion_t inv;
 	fe_modulation_t 		mod;
 	fe_transmit_mode_t 		trans;
 	fe_bandwidth_t 			bw;
-	fe_guard_interval_t 		gi;
+	fe_guard_interval_t 	gi;
 	fe_code_rate_t 			cr;
 } dvb_channel_t;
 
@@ -56,45 +59,30 @@
 
 
 typedef struct {
+	int card;
     int fe_fd;
     int sec_fd;
     int demux_fd[3];
     int dvr_fd;
-    int input;
-    int output;
-    int discard;
 
-    dvb_channel_t channel;
     dvb_channels_list *list;
+	int tuner_type;
+	int is_on;
+	stream_t *stream;
+	char new_tuning[256], prev_tuning[256];
+	int retry;
 } dvb_priv_t;
 
 
-extern dvb_history_t *dvb_step_channel(dvb_priv_t*, int, dvb_history_t*);
-
-extern dvb_channels_list *dvb_get_channels(char *, const char *);
-extern dvb_history_t dvb_prev_next;
-
-
+#define TUNER_SAT	1
+#define TUNER_TER	2
+#define TUNER_CBL	3
 
+extern int dvb_step_channel(dvb_priv_t *, int);
+extern int dvb_set_channel(dvb_priv_t *, int);
 
-#ifndef DVB_T_LOCATION
-    #ifndef UK
-    #warning No DVB-T country defined in dvb_defaults.h, defaulting to UK
-    #endif
-
-    /* UNITED KINGDOM settings */
-    #define DVB_T_LOCATION              "in United Kingdom"
-    #define BANDWIDTH_DEFAULT           BANDWIDTH_8_MHZ
-    #define HP_CODERATE_DEFAULT         FEC_2_3
-    #define CONSTELLATION_DEFAULT       QAM_64
-    #define TRANSMISSION_MODE_DEFAULT   TRANSMISSION_MODE_2K
-    #define GUARD_INTERVAL_DEFAULT      GUARD_INTERVAL_1_32
-    #define HIERARCHY_DEFAULT           HIERARCHY_NONE
-#endif
-
-#define HIERARCHY_DEFAULT           HIERARCHY_NONE
-#define LP_CODERATE_DEFAULT (0)
-
+extern dvb_channels_list *dvb_get_channels(char *, int);
+extern dvb_history_t dvb_prev_next;
 
 
 #endif
diff -Naur MPlayer-20030612/libmpdemux/dvb_tune.c MPlayer-20030612-new/libmpdemux/dvb_tune.c
--- MPlayer-20030612/libmpdemux/dvb_tune.c	2003-03-16 21:13:28.000000000 +0100
+++ MPlayer-20030612-new/libmpdemux/dvb_tune.c	2003-05-08 22:46:43.000000000 +0200
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <error.h>
+#include <errno.h>
 #include "config.h"
 
 #ifdef HAVE_DVB_HEAD
@@ -47,32 +48,78 @@
 #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 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(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, 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(res)
+  {
+	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;  
+  }
+  
+}	
+
+
+int open_fe(dvb_priv_t *priv)
+{
+	priv->fe_fd = open(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", 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(secdev[priv->card], O_RDWR);
+    if(priv->sec_fd < 0)
+    {
+		mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR IN OPENING SEC DEVICE %s: %d\n", secdev[priv->card], errno);
+		close(priv->fe_fd);
+      	return 0;
+    }
 #endif
-    	return 1;
+
+    return 1;
 }
 
 
@@ -91,16 +138,17 @@
 	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;
 }
 
@@ -116,6 +164,16 @@
 }
 
 
+int 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)
 {
@@ -139,48 +197,31 @@
 	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;
 }
@@ -585,6 +626,7 @@
 
 #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 @@
   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 @@
 
 
 #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 @@
    }
    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 @@
         if (ioctl(fd_sec,SEC_SEND_SEQUENCE,&scmds) < 0)
 	{
           mp_msg(MSGT_DEMUX, MSGL_ERR, "Error sending DisEqC");
-          return -1;
+          return 0;
         }
       }
 #endif
diff -Naur MPlayer-20030612/libmpdemux/open.c MPlayer-20030612-new/libmpdemux/open.c
--- MPlayer-20030612/libmpdemux/open.c	2003-05-17 14:24:01.000000000 +0200
+++ MPlayer-20030612-new/libmpdemux/open.c	2003-06-12 21:46:08.000000000 +0200
@@ -30,8 +30,6 @@
 static URL_t* url;
 #endif
 
-int dvbin_param_on=0;
-
 /// We keep these 2 for the gui atm, but they will be removed.
 int dvd_title=0;
 int vcd_track=0;
@@ -71,11 +69,6 @@
 
 #include "cue_read.h"
 
-#ifdef HAS_DVBIN_SUPPORT
-#include "dvbin.h"
-#endif
-
-
 
 // Define function about auth the libsmbclient library
 // FIXME: I really do not not is this function is properly working
@@ -453,18 +446,6 @@
 }
 #endif
 
-#ifdef HAS_DVBIN_SUPPORT
-if(strncmp("dvbin://",filename,8) == 0)
-{
-	stream = new_stream(-1, STREAMTYPE_DVB);
-	if (!stream)
-	   return(NULL);
-       	if (!dvb_streaming_start(stream))
-	   return NULL;
-
-       	return stream;
-}
-#endif
 
 #ifdef MPLAYER_NETWORK
 #ifdef STREAMING_LIVE_DOT_COM
diff -Naur MPlayer-20030612/libmpdemux/stream.c MPlayer-20030612-new/libmpdemux/stream.c
--- MPlayer-20030612/libmpdemux/stream.c	2003-06-11 18:48:07.000000000 +0200
+++ MPlayer-20030612-new/libmpdemux/stream.c	2003-06-12 21:47:26.000000000 +0200
@@ -60,6 +60,10 @@
 #endif
 extern stream_info_t stream_info_null;
 extern stream_info_t stream_info_file;
+#ifdef HAS_DVBIN_SUPPORT
+extern stream_info_t stream_info_dvb;
+#endif
+
 
 stream_info_t* auto_open_streams[] = {
 #ifdef HAVE_VCD
@@ -71,6 +75,9 @@
 #ifdef MPLAYER_NETWORK
   &stream_info_netstream,
 #endif
+#ifdef HAS_DVBIN_SUPPORT
+  &stream_info_dvb,
+#endif
   &stream_info_null,
   &stream_info_file,
   NULL
@@ -207,13 +214,6 @@
     len = demux_read_data((demux_stream_t*)s->priv,s->buffer,STREAM_BUFFER_SIZE);
     break;
   
-#ifdef HAS_DVBIN_SUPPORT
-  case STREAMTYPE_DVB:
-   len = dvb_streaming_read(s->fd, s->buffer, STREAM_BUFFER_SIZE, s->priv);
-  break;
-#endif
-
-
     
   default: 
     len= s->fill_buffer ? s->fill_buffer(s,s->buffer,STREAM_BUFFER_SIZE) : 0;
@@ -416,11 +416,6 @@
     smbc_close(s->fd);
     break;    
 #endif
-#ifdef HAS_DVBIN_SUPPORT
-  case STREAMTYPE_DVB:
-    dvbin_close(s->priv);
-  break;
-#endif
 
 #ifdef USE_DVDREAD
   case STREAMTYPE_DVD:
diff -Naur MPlayer-20030612/mplayer.c MPlayer-20030612-new/mplayer.c
--- MPlayer-20030612/mplayer.c	2003-06-09 14:15:40.000000000 +0200
+++ MPlayer-20030612-new/mplayer.c	2003-06-12 21:56:30.000000000 +0200
@@ -102,8 +102,6 @@
 
 #ifdef HAS_DVBIN_SUPPORT
 #include "libmpdemux/dvbin.h"
-extern dvb_history_t dvb_prev_next;
-dvb_history_t *dvb_history;
 #endif
 
 
@@ -746,12 +744,6 @@
 
 int gui_no_filename=0;
 
-#ifdef HAS_DVBIN_SUPPORT
-        dvb_prev_next.prev = dvb_prev_next.next = -1;
-	dvb_history = &dvb_prev_next;
-#endif
-
-
 
   srand((int) time(NULL)); 
 
@@ -1339,7 +1331,7 @@
 }
 
 //============ Open DEMUXERS --- DETECT file type =======================
-
+goto_open_demuxer:
 current_module="demux_open";
 
 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename);
@@ -2794,17 +2786,29 @@
       }
     } 
 #ifdef HAS_DVBIN_SUPPORT
-	if(dvbin_param_on == 1)
+	if((stream->type == STREAMTYPE_DVB) && stream->priv)
 	{
+	  dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
+	  if(priv->is_on)
+	  {
+		int dir;
 		int v = cmd->args[0].v.i;
+		
 		if(v > 0)
-			dvb_history = dvb_step_channel((dvb_priv_t*)(demuxer->stream->priv), DVB_CHANNEL_HIGHER, dvb_history);
+			dir = DVB_CHANNEL_HIGHER;
 		else
-			dvb_history = dvb_step_channel((dvb_priv_t*)(demuxer->stream->priv), DVB_CHANNEL_LOWER, dvb_history);
-		uninit_player(INITED_ALL);
-		goto goto_next_file;
+			dir = DVB_CHANNEL_LOWER;
+			
+			
+		if(dvb_step_channel(priv, dir))
+		{
+	  		uninit_player(INITED_ALL-(INITED_STREAM));
+			printf("UNINIT COMPLETE\n");
+			goto goto_open_demuxer;
+		}
+	  }
 	}
-#endif
+#endif	
 
     break;
     case MP_CMD_TV_SET_CHANNEL :  {
@@ -2818,6 +2822,23 @@
 #endif
       }
     } break;
+#ifdef HAS_DVBIN_SUPPORT	
+  case MP_CMD_DVB_SET_CHANNEL:  
+  {
+	if((stream->type == STREAMTYPE_DVB) && stream->priv)
+	{
+	  dvb_priv_t *priv = (dvb_priv_t*) stream->priv;
+	  if(priv->is_on)
+	  {
+  		if(dvb_set_channel(priv, cmd->args[0].v.i))
+		{
+	  	  uninit_player(INITED_ALL-(INITED_STREAM));
+		  goto goto_open_demuxer;
+		}
+	  }
+	}
+  }
+#endif	
     case MP_CMD_TV_LAST_CHANNEL :  {
       if (file_format == DEMUXER_TYPE_TV) {
 	tv_last_channel((tvi_handle_t*)(demuxer->priv));
@@ -3558,12 +3579,7 @@
   }	
 #endif
 
-if(use_gui || playtree_iter != NULL
-#ifdef HAS_DVBIN_SUPPORT
-		    || dvbin_param_on
-#endif
-	){
-
+if(use_gui || playtree_iter != NULL	){
   eof = 0;
   goto play_next_file;
 }

Home | Main Index | Thread Index