changeset 24480:a365d70938b3

Simplify demux_ty_FindESPacket by reusing demux_ty_FindESHeader
author reimar
date Fri, 14 Sep 2007 20:08:42 +0000
parents 6fb4555fba27
children 61222a7b1dbd
files libmpdemux/demux_ty.c
diffstat 1 files changed, 10 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_ty.c	Fri Sep 14 19:55:09 2007 +0000
+++ b/libmpdemux/demux_ty.c	Fri Sep 14 20:08:42 2007 +0000
@@ -377,38 +377,16 @@
 static void demux_ty_FindESPacket( unsigned char *header, 
    unsigned char *buffer, int bufferSize, int *esOffset1, int *esOffset2 )
 {
-   int count;
-
-   *esOffset1 = -1;
-   *esOffset2 = -1;
-
-   for( count = 0 ; count < bufferSize ; count++ )
-   {
-      if ( buffer[ count + 0 ] == header[ 0 ] &&
-           buffer[ count + 1 ] == header[ 1 ] &&
-           buffer[ count + 2 ] == header[ 2 ] &&
-           buffer[ count + 3 ] == header[ 3 ] )
-      {
-         *esOffset1 = count;
-         break;
-      }
-   }
-
-   if ( *esOffset1 != -1 )
-   {
-      for( count = *esOffset1 + 1 ; 
-         count < bufferSize ; count++ )
-      {
-         if ( buffer[ count + 0 ] == header[ 0 ] &&
-              buffer[ count + 1 ] == header[ 1 ] &&
-              buffer[ count + 2 ] == header[ 2 ] &&
-              buffer[ count + 3 ] == header[ 3 ] )
-         {
-            *esOffset2 = count;
-            break;
-         }
-      }
-   }
+  *esOffset1 = demux_ty_FindESHeader(header, buffer, bufferSize);
+  if (*esOffset1 == -1) {
+    *esOffset2 = -1;
+    return;
+  }
+  buffer += *esOffset1 + 1;
+  bufferSize -= *esOffset1 + 1;
+  *esOffset2 = demux_ty_FindESHeader(header, buffer, bufferSize);
+  if (*esOffset2 != -1)
+    *esOffset2 += *esOffset1 + 1;
 }
 
 static unsigned char ty_VideoPacket[] = { 0x00, 0x00, 0x01, 0xe0 };