[MPlayer-dev-eng] [rnissl at gmx.de: [xine-devel] PATCH: libmpeg2: considerable speedup in looking for startcodes]

Diego Biurrun diego at biurrun.de
Thu Feb 2 15:33:31 CET 2006


I haven't checked this in detail (it does not apply anyway), but I
thought this might be interesting for us as well...

Diego


----- Forwarded message from Reinhard Nissl <rnissl at gmx.de> -----

From: Reinhard Nissl <rnissl at gmx.de>
Date: Sun, 29 Jan 2006 22:44:34 +0100
To: xine-devel at lists.sourceforge.net
Subject: [xine-devel] PATCH: libmpeg2: considerable speedup in looking for
 startcodes
User-Agent: Thunderbird 1.5 (X11/20051201)

Hi,

the attached patch is very noticeable on less powerful CPUs like VIA's 
C3 processor.

Bye.
-- 
Dipl.-Inform. (FH) Reinhard Nissl
mailto:rnissl at gmx.de

Index: xine-lib/src/libmpeg2/decode.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/libmpeg2/decode.c,v
retrieving revision 1.128
diff -u -r1.128 decode.c
--- xine-lib/src/libmpeg2/decode.c	17 Jun 2005 22:33:02 -0000	1.128
+++ xine-lib/src/libmpeg2/decode.c	29 Jan 2006 21:25:27 -0000
@@ -585,45 +585,124 @@
     return is_frame_done;
 }
 
+static inline int find_start_code (mpeg2dec_t * mpeg2dec,
+                                   uint8_t ** current, uint8_t * limit)
+{
+    uint8_t * p;
+
+    if (*current >= limit)
+	return 0;
+    if (mpeg2dec->shift == 0x00000100)
+	return 1;
+
+    mpeg2dec->shift = (mpeg2dec->shift | *(*current)++) << 8;
+
+    if (*current >= limit)
+	return 0;
+    if (mpeg2dec->shift == 0x00000100)
+	return 1;
+
+    mpeg2dec->shift = (mpeg2dec->shift | *(*current)++) << 8;
+
+    if (*current >= limit)
+	return 0;
+    if (mpeg2dec->shift == 0x00000100)
+	return 1;
+
+    limit--;
+
+    if (*current >= limit) {
+	mpeg2dec->shift = (mpeg2dec->shift | *(*current)++) << 8;
+	return 0;
+    }
+
+    p = *current;
+
+    while (p < limit) {
+	if (*p > 0x01)
+	    p += 3;
+	else if (!*p)
+	    p++;
+	else if (p[-2] || p[-1])
+	    p += 3;
+	else {
+	    *current = ++p;
+	    return 1;
+	}
+    }
+
+    *current = ++limit;
+    p = limit - 3;
+    mpeg2dec->shift = (mpeg2dec->shift | *p++) << 8;
+    mpeg2dec->shift = (mpeg2dec->shift | *p++) << 8;
+    mpeg2dec->shift = (mpeg2dec->shift | *p++) << 8;
+
+    return 0;
+}
+
 static inline uint8_t * copy_chunk (mpeg2dec_t * mpeg2dec,
 				    uint8_t * current, uint8_t * end)
 {
-    uint32_t shift;
-    uint8_t * chunk_ptr;
     uint8_t * limit;
-    uint8_t byte;
 
-    shift = mpeg2dec->shift;
-    chunk_ptr = mpeg2dec->chunk_ptr;
-    limit = current + (mpeg2dec->chunk_buffer + BUFFER_SIZE - chunk_ptr);
+    limit = current + (mpeg2dec->chunk_buffer + BUFFER_SIZE - mpeg2dec->chunk_ptr);
     if (limit > end)
 	limit = end;
+#if 0
+    {
+	uint32_t shift = mpeg2dec->shift;
+	uint8_t * chunk_ptr = mpeg2dec->chunk_ptr;
 
-    while (1) {
+	while (1) {
 
-	byte = *current++;
-	if (shift != 0x00000100) {
-	    shift = (shift | byte) << 8;
-	    *chunk_ptr++ = byte;
-	    if (current < limit)
-		continue;
-	    if (current == end) {
-		mpeg2dec->chunk_ptr = chunk_ptr;
-		mpeg2dec->shift = shift;
-		return NULL;
-	    } else {
-		/* we filled the chunk buffer without finding a start code */
-		mpeg2dec->code = 0xb4;	/* sequence_error_code */
-		mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
-		return current;
+	    uint8_t byte = *current++;
+	    if (shift != 0x00000100) {
+		shift = (shift | byte) << 8;
+		*chunk_ptr++ = byte;
+		if (current < limit)
+		    continue;
+		if (current == end) {
+		    mpeg2dec->chunk_ptr = chunk_ptr;
+		    mpeg2dec->shift = shift;
+		    return NULL;
+		} else {
+		    /* we filled the chunk buffer without finding a start code */
+		    mpeg2dec->code = 0xb4;	/* sequence_error_code */
+		    mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
+		    return current;
+		}
 	    }
+	    mpeg2dec->code = byte;
+	    mpeg2dec->chunk_size = chunk_ptr - mpeg2dec->chunk_buffer - 3;
+	    mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
+	    mpeg2dec->shift = 0xffffff00;
+	    return current;
 	}
-	mpeg2dec->code = byte;
-	mpeg2dec->chunk_size = chunk_ptr - mpeg2dec->chunk_buffer - 3;
+    }
+#else
+    {
+	uint8_t * data = current;
+	int found = find_start_code(mpeg2dec, &current, limit);
+	memcpy(mpeg2dec->chunk_ptr, data, current - data);
+	mpeg2dec->chunk_ptr += current - data;
+
+	if (found) {
+	    mpeg2dec->code = *current++;
+	    mpeg2dec->chunk_size = mpeg2dec->chunk_ptr - mpeg2dec->chunk_buffer - 3;
+	    mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
+	    mpeg2dec->shift = 0xffffff00;
+	    return current;
+	}
+    
+	if (current == end)
+	    return NULL;
+
+	/* we filled the chunk buffer without finding a start code */
+	mpeg2dec->code = 0xb4;	/* sequence_error_code */
 	mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
-	mpeg2dec->shift = 0xffffff00;
 	return current;
     }
+#endif
 }
 
 int mpeg2_decode_data (mpeg2dec_t * mpeg2dec, uint8_t * current, uint8_t * end,


----- End forwarded message -----




More information about the MPlayer-dev-eng mailing list