[MPlayer-dev-eng] [PATCH] much faster parse_es.c

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Dec 17 12:23:06 CET 2005


Hi,
the attached patch makes MPEG-ES parsing/demuxing about 25% faster,
tested on an AMD64 with the following command:
./mplayer -cache-min 90 -cache 409600 -vc null -vo null -benchmark -nosound
/debian/home/reimar/mpl-tests/THX_Science_FLT_1920.gxf
Though it will hardly be relevant considering the whole decoding step.
Nevertheless, do you think it is okay to apply? It is a bit ugly since
it operates directly on the demuxer buffer and thus makes it harder to
change that part, so I'm undecided if it is worth it.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/parse_es.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/parse_es.c,v
retrieving revision 1.8
diff -u -r1.8 parse_es.c
--- libmpdemux/parse_es.c	3 Sep 2005 08:58:34 -0000	1.8
+++ libmpdemux/parse_es.c	17 Dec 2005 10:56:27 -0000
@@ -68,19 +68,24 @@
   
   // READ PACKET:
   {
-    register uint32_t head = 0xffffffff;
-    register unsigned char *buf = &videobuffer[VIDEOBUFFER_SIZE];
-    register int pos = videobuf_len - VIDEOBUFFER_SIZE;
+    register uint32_t head = 0xffffff00;
     do {
-      int c=demux_getc(ds);
-      if(c<0) break; // EOF
-      buf[pos]=c;
-      head<<=8;
-      if(head==0x100) break; // synced
-      head|=c;
-    } while (++pos);
-    if (pos) pos++; // increment missed because of break
-    videobuf_len = &buf[pos] - videobuffer;
+      register unsigned char *ds_buf = &ds->buffer[ds->buffer_size];
+      int len = ds->buffer_size - ds->buffer_pos;
+      register long pos = -len;
+      if (pos >= 0) { // buffer is empty
+        ds_fill_buffer(ds);
+        continue;
+      }
+      do {
+        head |= ds_buf[pos];
+        head <<= 8;
+      } while (++pos && head != 0x100);
+      len += pos;
+      if (head == 0x100) len++; // also read NAL number
+      len = demux_read_data(ds, &videobuffer[videobuf_len], len);
+      videobuf_len += len;
+    } while (head != 0x100 && !ds->eof);
   }
   
   if(ds->eof){


More information about the MPlayer-dev-eng mailing list