changeset 21953:62bf4204eed4

in h264_parse_sps() reuse mp_unescape03()
author nicodvb
date Sat, 20 Jan 2007 13:46:17 +0000
parents 58d083ace2f2
children ad465ec1294a
files libmpdemux/mpeg_hdr.c
diffstat 1 files changed, 4 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/mpeg_hdr.c	Sat Jan 20 13:14:09 2007 +0000
+++ b/libmpdemux/mpeg_hdr.c	Sat Jan 20 13:46:17 2007 +0000
@@ -340,36 +340,14 @@
   return n;
 }
 
+static int mp_unescape03(unsigned char *buf, int len);
+
 int h264_parse_sps(mp_mpeg_header_t * picture, unsigned char * buf, int len)
 {
-  unsigned int n = 0, v, i, j, mbh;
-  unsigned char *dest;
+  unsigned int n = 0, v, i, mbh;
   int frame_mbs_only;
 
-  dest = (unsigned char*) malloc(len);
-  if(! dest)
-    return 0;
-  j = i = 0;
-  while(i <= len-3)
-  {
-    if(buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 3)
-    {
-      dest[j] = dest[j+1] = 0;
-      j += 2;
-      i += 3;
-    }
-    else
-    {
-      dest[j] = buf[i];
-      j++;
-      i++;
-    }
-  }
-  dest[j] = buf[len-2];
-  dest[j+1] = buf[len-1];
-  j += 2;
-  len = j+1;
-  buf = dest;
+  len = mp_unescape03(buf, len);
   
   picture->fps = picture->timeinc_unit = picture->timeinc_resolution = 0;
   n = 24;
@@ -416,7 +394,6 @@
   if(getbits(buf, n++, 1))
     n = h264_parse_vui(picture, buf, n);
 
-  free(dest);
   return n;
 }