[Mplayer-cvslog] CVS: main/libmpdemux demux_ts.c,1.5,1.6

Arpi of Ize arpi at mplayerhq.hu
Sun Jun 8 13:58:33 CEST 2003


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv5422

Modified Files:
	demux_ts.c 
Log Message:
- discard soon non TS files (previously it took too long, as in the case
of mpeg-ps files without a registered extension)
- detect sooner audio-only files (at least 64K of the chosen audio
streams without a video stream)
patch by Nico <nsabbi at libero.it>


Index: demux_ts.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_ts.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- demux_ts.c	7 Jun 2003 11:30:19 -0000	1.5
+++ demux_ts.c	8 Jun 2003 11:58:05 -0000	1.6
@@ -41,8 +41,10 @@
 #define NB_PID_MAX 8192
 
 #define MAX_HEADER_SIZE 6			/* enough for PES header + length */
-#define MAX_PROBE_SIZE	500000
+#define MAX_CHECK_SIZE	65535
+#define MAX_PROBE_SIZE	1000000
 #define NUM_CONSECUTIVE_TS_PACKETS 32
+#define NUM_CONSECUTIVE_AUDIO_PACKETS 348
 
 
 int ts_fastparse = 0;
@@ -99,7 +101,7 @@
 			mp_msg(MSGT_DEMUX, MSGL_DBG2, "GET_PACKET_SIZE, pos %d, char: %2x\n", i, buf[i * TS_PACKET_SIZE]);
 			goto try_fec;
 		}
-    	}
+	}
 	return TS_PACKET_SIZE;
 
 try_fec:
@@ -117,13 +119,14 @@
 {
 	const int buf_size = (TS_FEC_PACKET_SIZE * NUM_CONSECUTIVE_TS_PACKETS);
 	unsigned char buf[buf_size], done = 0, *ptr;
-	uint32_t _read, i, count = 0;
+	uint32_t _read, i, count = 0, is_ts;
 	int cc[NB_PID_MAX], last_cc[NB_PID_MAX], pid, cc_ok, c;
 	uint8_t size = 0;
 	off_t pos = 0;
 
 	mp_msg(MSGT_DEMUX, MSGL_V, "Checking for TS...\n");
 
+	is_ts = 0;
 	while(! done)
 	{
 		i = 1;
@@ -131,37 +134,50 @@
 
 		while(((c=stream_read_char(demuxer->stream)) != 0x47)
 			&& (c >= 0)
-			&& (i < MAX_PROBE_SIZE)
+			&& (i < MAX_CHECK_SIZE)
 			&& ! demuxer->stream->eof
 		) i++;
 
 
-	    if(c != 0x47)
-	    {
+		if(c != 0x47)
+		{
 			mp_msg(MSGT_DEMUX, MSGL_V, "NOT A TS FILE1\n");
+			is_ts = 0;
 			done = 1;
 			continue;
-	    }
+		}
 
-	    pos = stream_tell(demuxer->stream) - 1;
-	    buf[0] = c;
-	    _read = stream_read(demuxer->stream, &buf[1], buf_size-1);
+		pos = stream_tell(demuxer->stream) - 1;
+		buf[0] = c;
+		_read = stream_read(demuxer->stream, &buf[1], buf_size-1);
 
-	    if(_read < buf_size-1)
-	    {
+		if(_read < buf_size-1)
+		{
 			mp_msg(MSGT_DEMUX, MSGL_V, "COULDN'T READ ENOUGH DATA, EXITING TS_CHECK\n");
 			stream_reset(demuxer->stream);
 			return 0;
-	    }
+		}
+
+		size = get_packet_size(buf, buf_size);
+		if(size)
+		{
+			done = 1;
+			is_ts = 1;
+		}
 
-	    size = get_packet_size(buf, buf_size);
-	    if(size)
-		  done = 1;
+		if(pos >= MAX_CHECK_SIZE)
+		{
+			done = 1;
+			is_ts = 0;
+		}
 	}
 
-	mp_msg(MSGT_DEMUX, MSGL_V, "TRIED UP TO POSITION %u, FOUND %x, packet_size= %d\n", i, c, size);
+	mp_msg(MSGT_DEMUX, MSGL_V, "TRIED UP TO POSITION %u, FOUND %x, packet_size= %d\n", pos, c, size);
 	stream_seek(demuxer->stream, pos);
 
+	if(! is_ts)
+	  return 0;
+
 	//LET'S CHECK continuity counters
 	for(count = 0; count < NB_PID_MAX; count++)
 	{
@@ -193,9 +209,10 @@
 
 
 
+
 static void ts_detect_streams(demuxer_t *demuxer, uint32_t *a,  uint32_t *v, int *fapid, int *fvpid)
 {
-	int video_found = 0, audio_found = 0, i;
+	int video_found = 0, audio_found = 0, i, num_packets = 0;
 	off_t pos=0;
 	ES_stream_t es;
 	unsigned char tmp[TS_FEC_PACKET_SIZE];
@@ -209,6 +226,7 @@
 		{
 			mp_msg(MSGT_DEMUXER, MSGL_DBG2, "TYPE: %x, PID: %d\n", es.type, es.pid);
 
+
 			if((*fvpid == -1) || (*fvpid == es.pid))
 			{
 				if(es.type == VIDEO_MPEG2)
@@ -219,8 +237,9 @@
 				}
 			}
 
-			if((*fvpid == -2) && audio_found)
+			if(((*fvpid == -2) || (num_packets >= NUM_CONSECUTIVE_AUDIO_PACKETS)) && audio_found)
 			{
+				//novideo or we have at least 348 audio packets (64 KB) without video (TS with audio only)
 				*v = 0;
 				break;
 			}
@@ -249,6 +268,9 @@
 					audio_found = 1;
 				}
 			}
+
+			if(audio_found && (*fapid == es.pid) && (! video_found))
+			  num_packets++;
 
 			if((*fapid == -2) && video_found)
 			{



More information about the MPlayer-cvslog mailing list