changeset 20478:c8bc7d300bb3

in ts_parse() centralized stream_read()+stream_skip(); smaller and cleaner
author nicodvb
date Sat, 28 Oct 2006 17:42:25 +0000
parents de4a66d99f41
children 4652156da0d5
files libmpdemux/demux_ts.c
diffstat 1 files changed, 23 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_ts.c	Sat Oct 28 15:07:18 2006 +0000
+++ b/libmpdemux/demux_ts.c	Sat Oct 28 17:42:25 2006 +0000
@@ -2861,6 +2861,27 @@
 		}
 
 
+		if(probe)
+		{
+			p = &packet[base];
+		}
+		else	//feeding
+		{
+			if(*dp_offset + buf_size > *buffer_size)
+			{
+				*buffer_size = *dp_offset + buf_size + TS_FEC_PACKET_SIZE;
+				resize_demux_packet(*dp, *buffer_size);
+			}
+			p = &((*dp)->buffer[*dp_offset]);
+		}
+
+		buf_size = stream_read(stream, p, buf_size);
+		if(buf_size==-1)
+		{
+			mp_msg(MSGT_DEMUX, MSGL_DBG2,  "\r\nts_parse() couldn't read data\r\n");
+			continue;
+		}
+		stream_skip(stream, junk);
 
 		if(is_start)
 		{
@@ -2868,10 +2889,6 @@
 
 			mp_msg(MSGT_DEMUX, MSGL_DBG2, "IS_START\n");
 
-			p = &packet[base];
-			stream_read(stream, p, buf_size);
-			stream_skip(stream, junk);
-
 			len = pes_parse2(p, buf_size, es, pid_type, pmt, pid);
 			if(! len)
 			{
@@ -2912,14 +2929,7 @@
 
 				demuxer->filepos = stream_tell(demuxer->stream) - es->size;
 
-				if(*dp_offset + es->size > *buffer_size)
-				{
-					*buffer_size = *dp_offset + es->size + TS_FEC_PACKET_SIZE;
-					resize_demux_packet(*dp, *buffer_size);
-					//we'll skip at least one RESIZE() in the next iteration of ts_parse()
-					mp_msg(MSGT_DEMUX, MSGL_DBG2, "RESIZE DP TO %d\n", *buffer_size);
-				}
-				memcpy(&((*dp)->buffer[*dp_offset]), es->start, es->size);
+				memmove(p, es->start, es->size);
 				*dp_offset += es->size;
 				(*dp)->flags = 0;
 				(*dp)->pos = stream_tell(demuxer->stream);
@@ -2962,7 +2972,6 @@
 				}
 				else
 				{
-					stream_skip(stream, buf_size+junk);
 					continue;
 				}
 			}
@@ -2970,23 +2979,8 @@
 
 			if(! probe)
 			{
-				if(*dp_offset + sz > *buffer_size)
-				{
-					*buffer_size = *dp_offset + sz + TS_FEC_PACKET_SIZE;
-					resize_demux_packet(*dp, *buffer_size);
-					//we'll skip at least one RESIZE() in the next iteration of ts_parse()
-					mp_msg(MSGT_DEMUX, MSGL_DBG2, "RESIZE DP TO %d\n", *buffer_size);
-				}
-
-				stream_read(stream, &((*dp)->buffer[*dp_offset]), sz);
 				*dp_offset += sz;
 
-				if(buf_size - sz > 0)
-				{
-					stream_skip(stream, buf_size - sz);
-				}
-				stream_skip(stream, junk);
-
 				if(*dp_offset >= MAX_PACK_BYTES)
 				{
 					(*dp)->pts = tss->last_pts;
@@ -2998,9 +2992,7 @@
 			}
 			else
 			{
-				stream_read(stream, es->start, sz);
-				if(buf_size - sz) stream_skip(stream, buf_size-sz);
-				stream_skip(stream, junk);
+				memcpy(es->start, p, sz);
 
 				if(es->size)
 					return es->size;