Re: Re: HDTV: demux_ts vs lavf

Nico Sabbi <[email protected]> Sat, 21 Oct 2006 12:34:29 +0200
Newsgroups gmane.comp.video.mplayer.user.dvb
Message-ID <[email protected]>
Carl Eugen Hoyos wrote:

>Nico Sabbi <nicola_sabbi <at> fastwebnet.it> writes:
>
>  
>
>>This weekend I'll provide you a patch to see if using a blocking mode 
>>can fix this issue.
>>    
>>
>
>Thank you Nico!
>
>I will be happy to test it, Carl Eugen
>
>  
>

attached.
In order to test the blocking mode add -dvbin blocking
(-dvbin nonblocking is still the default mode)

_______________________________________________
MPlayer-dvb mailing list
[email protected]
http://lists.mplayerhq.hu/mailman/listinfo/mplayer-dvb
dvblocking.diff (text/x-patch, 4.2 KB)
Index: stream/dvbin.h
===================================================================
--- stream/dvbin.h	(revisione 19914)
+++ stream/dvbin.h	(copia locale)
@@ -103,6 +103,7 @@
 	char new_tuning[256], prev_tuning[256];
 	int retry;
 	int timeout;
+	int blocking;
 } dvb_priv_t;
 
 
Index: stream/dvb_tune.c
===================================================================
--- stream/dvb_tune.c	(revisione 19914)
+++ stream/dvb_tune.c	(copia locale)
@@ -105,8 +105,9 @@
 int dvb_open_devices(dvb_priv_t *priv, int n, int demux_cnt, int *pids)
 {
 	int i;
+	int blockingflag = (priv->blocking ? 0 : O_NONBLOCK);
 	
-	priv->fe_fd = open(dvb_frontenddev[n], O_RDWR | O_NONBLOCK);
+	priv->fe_fd = open(dvb_frontenddev[n], O_RDWR | blockingflag);
 	if(priv->fe_fd < 0)
 	{
 		mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING FRONTEND DEVICE %s: ERRNO %d\n", dvb_frontenddev[n], errno);
@@ -127,7 +128,7 @@
 	mp_msg(MSGT_DEMUX, MSGL_V, "DVB_OPEN_DEVICES(%d)\n", demux_cnt);
 	for(i = 0; i < demux_cnt; i++)
 	{
-		priv->demux_fds[i] = open(dvb_demuxdev[n], O_RDWR | O_NONBLOCK);
+		priv->demux_fds[i] = open(dvb_demuxdev[n], O_RDWR | blockingflag);
 		if(priv->demux_fds[i] < 0)
 		{
 			mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX 0: %d\n", errno);
@@ -141,7 +142,7 @@
 	}
 
 
-	priv->dvr_fd = open(dvb_dvrdev[n], O_RDONLY| O_NONBLOCK);
+	priv->dvr_fd = open(dvb_dvrdev[n], O_RDONLY | blockingflag);
 	if(priv->dvr_fd < 0)
 	{
 		mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DVR DEVICE %s: %d\n", dvb_dvrdev[n], errno);
@@ -155,6 +156,7 @@
 int dvb_fix_demuxes(dvb_priv_t *priv, int cnt, int *pids)
 {
 	int i;
+	int blockingflag = (priv->blocking ? 0 : O_NONBLOCK);
 	
 	mp_msg(MSGT_DEMUX, MSGL_V, "FIX %d -> %d\n", priv->demux_fds_cnt, cnt);
 	if(priv->demux_fds_cnt >= cnt)
@@ -170,7 +172,7 @@
 	{
 		for(i = priv->demux_fds_cnt; i < cnt; i++)
 		{
-			priv->demux_fds[i] = open(dvb_demuxdev[priv->card], O_RDWR | O_NONBLOCK);
+			priv->demux_fds[i] = open(dvb_demuxdev[priv->card], O_RDWR | blockingflag);
 			mp_msg(MSGT_DEMUX, MSGL_V, "FIX, OPEN fd(%d): %d\n", i, priv->demux_fds[i]);
 			if(priv->demux_fds[i] < 0)
 			{
Index: stream/stream_dvb.c
===================================================================
--- stream/stream_dvb.c	(revisione 19914)
+++ stream/stream_dvb.c	(copia locale)
@@ -66,10 +66,11 @@
 	int vid, aid;
 	int timeout;
 	char *file;
+	int blocking;
 }
 stream_defaults =
 {
-	"", 1, "", 0, 0, 30, NULL
+	"", 1, "", 0, 0, 30, NULL, 0
 };
 
 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s, f)
@@ -83,6 +84,8 @@
 	{"aid",  ST_OFF(aid),  CONF_TYPE_INT, 0, 0 ,0, NULL},
 	{"timeout",ST_OFF(timeout),  CONF_TYPE_INT, M_OPT_RANGE, 1, 30, NULL},
 	{"file", ST_OFF(file), CONF_TYPE_STRING, 0, 0 ,0, NULL},
+	{"blocking", ST_OFF(blocking), CONF_TYPE_FLAG, 0 , 0, 1, NULL},
+	{"nonblocking", ST_OFF(blocking), CONF_TYPE_FLAG, 0 , 0, 0, NULL},
 
 	{"hostname", 	ST_OFF(prog), CONF_TYPE_STRING, 0, 0, 0, NULL },
 	{"username", 	ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},
@@ -105,6 +108,8 @@
 	{"vid",  &stream_defaults.vid,  CONF_TYPE_INT, 0, 0 ,0, NULL},
 	{"aid",  &stream_defaults.aid,  CONF_TYPE_INT, 0, 0 ,0, NULL},
 	{"timeout",  &stream_defaults.timeout,  CONF_TYPE_INT, M_OPT_RANGE, 1, 30, NULL},
+	{"blocking", &stream_defaults.blocking, CONF_TYPE_FLAG, 0 , 0, 1, NULL},
+	{"nonblocking", &stream_defaults.blocking, CONF_TYPE_FLAG, 0 , 0, 0, NULL},
 	{"file", &stream_defaults.file, CONF_TYPE_STRING, 0, 0 ,0, NULL},
 
 	{NULL, NULL, 0, 0, 0, 0, NULL}
@@ -425,10 +430,12 @@
 	fd = stream->fd;
 	while(pos < size)
 	{
+		rk = size - pos;
+		if(!priv->blocking)
+		{
 		pfds[0].fd = fd;
 		pfds[0].events = POLLIN | POLLPRI;
 
-		rk = size - pos;
 		if(poll(pfds, 1, 500) <= 0)
 		{
 			errno = 0;
@@ -438,6 +445,7 @@
 			else
 				break;
 		}
+		}
 		if((rk = read(fd, &buffer[pos], rk)) > 0)
 		{
 			pos += rk;
@@ -486,6 +494,7 @@
 			dvb_demux_stop(priv->demux_fds[i]);
 			
 		priv->retry = 0;
+		if(!priv->blocking)
 		while(dvb_streaming_read(stream, buf, 4096) > 0);	//empty both the stream's and driver's buffer
 		if(priv->card != card)
 		{
@@ -719,6 +728,7 @@
  	}
 	priv->card = p->card - 1;
 	priv->timeout = p->timeout;
+	priv->blocking = p->blocking;
 	
 	tuner_type = priv->config->cards[priv->card].type;