Merge commit '4f6fbe47a9f784373c277870d9d4989762873bf1' into release/1.1
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 2 Jun 2013 23:32:19 +0000 (01:32 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 2 Jun 2013 23:32:19 +0000 (01:32 +0200)
* commit '4f6fbe47a9f784373c277870d9d4989762873bf1':
  vmdav: convert to bytestream2

Conflicts:
libavcodec/vmdav.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/vmdav.c

@@@ -110,13 -107,13 +107,13 @@@ static void lz_unpack(const unsigned ch
          speclen = 100;  /* no speclen */
      }
  
-     while (s_end - s > 0 && dataleft > 0) {
-         tag = *s++;
+     while (dataleft > 0 && bytestream2_get_bytes_left(&gb) > 0) {
+         tag = bytestream2_get_byteu(&gb);
          if ((tag == 0xFF) && (dataleft > 8)) {
-             if (d_end - d < 8 || s_end - s < 8)
 -            if (d + 8 > d_end || bytestream2_get_bytes_left(&gb) < 8)
++            if (d_end - d < 8 || bytestream2_get_bytes_left(&gb) < 8)
                  return;
              for (i = 0; i < 8; i++) {
-                 queue[qpos++] = *d++ = *s++;
+                 queue[qpos++] = *d++ = bytestream2_get_byteu(&gb);
                  qpos &= QUEUE_MASK;
              }
              dataleft -= 8;
                  if (dataleft == 0)
                      break;
                  if (tag & 0x01) {
-                     if (d_end - d < 1 || s_end - s < 1)
 -                    if (d + 1 > d_end || bytestream2_get_bytes_left(&gb) < 1)
++                    if (d_end - d < 1 || bytestream2_get_bytes_left(&gb) < 1)
                          return;
-                     queue[qpos++] = *d++ = *s++;
+                     queue[qpos++] = *d++ = bytestream2_get_byte(&gb);
                      qpos &= QUEUE_MASK;
                      dataleft--;
                  } else {
-                     if (s_end - s < 2)
-                         return;
-                     chainofs = *s++;
-                     chainofs |= ((*s & 0xF0) << 4);
-                     chainlen = (*s++ & 0x0F) + 3;
+                     chainofs = bytestream2_get_byte(&gb);
+                     chainofs |= ((bytestream2_peek_byte(&gb) & 0xF0) << 4);
+                     chainlen = (bytestream2_get_byte(&gb) & 0x0F) + 3;
                      if (chainlen == speclen) {
-                         if (s_end - s < 1)
-                             return;
-                         chainlen = *s++ + 0xF + 3;
+                         chainlen = bytestream2_get_byte(&gb) + 0xF + 3;
                      }
 -                    if (d + chainlen > d_end)
 +                    if (d_end - d < chainlen)
                          return;
                      for (j = 0; j < chainlen; j++) {
                          *d = queue[chainofs++ & QUEUE_MASK];
      }
  }
  
- static int rle_unpack(const unsigned char *src, int src_len, int src_count,
-                       unsigned char *dest, int dest_len)
+ static int rle_unpack(const unsigned char *src, unsigned char *dest,
 -    int src_count, int src_size, int dest_len)
++                      int src_count, int src_size, int dest_len)
  {
-     const unsigned char *ps;
-     const unsigned char *ps_end;
      unsigned char *pd;
 -    int i, l;
 +    int i, j, l;
      unsigned char *dest_end = dest + dest_len;
+     GetByteContext gb;
  
-     ps = src;
-     ps_end = src + src_len;
+     bytestream2_init(&gb, src, src_size);
      pd = dest;
      if (src_count & 1) {
-         if (ps_end - ps < 1)
+         if (bytestream2_get_bytes_left(&gb) < 1)
              return 0;
-         *pd++ = *ps++;
+         *pd++ = bytestream2_get_byteu(&gb);
      }
  
      src_count >>= 1;
      i = 0;
      do {
-         if (ps_end - ps < 1)
+         if (bytestream2_get_bytes_left(&gb) < 1)
              break;
-         l = *ps++;
+         l = bytestream2_get_byteu(&gb);
          if (l & 0x80) {
              l = (l & 0x7F) * 2;
-             if (dest_end - pd < l || ps_end - ps < l)
-                 return ps - src;
-             memcpy(pd, ps, l);
-             ps += l;
 -            if (pd + l > dest_end || bytestream2_get_bytes_left(&gb) < l)
++            if (dest_end - pd < l || bytestream2_get_bytes_left(&gb) < l)
+                 return bytestream2_tell(&gb);
+             bytestream2_get_buffer(&gb, pd, l);
              pd += l;
          } else {
-             if (dest_end - pd < 2*l || ps_end - ps < 2)
-                 return ps - src;
 -            if (pd + i > dest_end || bytestream2_get_bytes_left(&gb) < 2)
++            if (dest_end - pd < 2*l || bytestream2_get_bytes_left(&gb) < 2)
+                 return bytestream2_tell(&gb);
 -            for (i = 0; i < l; i++) {
++
 +            for (j = 0; j < l; j++) {
-                 *pd++ = ps[0];
-                 *pd++ = ps[1];
+                 *pd++ = bytestream2_get_byteu(&gb);
+                 *pd++ = bytestream2_get_byteu(&gb);
              }
-             ps += 2;
 -            bytestream2_skip(&gb, 2);
          }
          i += l;
      } while (i < src_count);
@@@ -258,29 -244,31 +244,31 @@@ static void vmd_decode(VmdVideoContext 
      }
  
      /* check if there is a new palette */
+     bytestream2_init(&gb, s->buf + 16, s->size - 16);
      if (s->buf[15] & 0x02) {
-         if (p_end - p < 2 + 3 * PALETTE_COUNT)
-             return;
-         p += 2;
+         bytestream2_skip(&gb, 2);
          palette32 = (unsigned int *)s->palette;
-         for (i = 0; i < PALETTE_COUNT; i++) {
-             r = *p++ * 4;
-             g = *p++ * 4;
-             b = *p++ * 4;
-             palette32[i] = 0xFFU << 24 | r << 16 | g << 8 | b;
-             palette32[i] |= palette32[i] >> 6 & 0x30303;
+         if (bytestream2_get_bytes_left(&gb) >= PALETTE_COUNT * 3) {
+             for (i = 0; i < PALETTE_COUNT; i++) {
+                 r = bytestream2_get_byteu(&gb) * 4;
+                 g = bytestream2_get_byteu(&gb) * 4;
+                 b = bytestream2_get_byteu(&gb) * 4;
 -                palette32[i] = (r << 16) | (g << 8) | (b);
++                palette32[i] = 0xFFU << 24 | (r << 16) | (g << 8) | (b);
++                palette32[i] |= palette32[i] >> 6 & 0x30303;
+             }
          }
 -        s->size -= (256 * 3 + 2);
      }
-     if (p < p_end) {
+     if (s->size > 0) {
          /* originally UnpackFrame in VAG's code */
-         pb = p;
-         pb_end = p_end;
-         meth = *pb++;
+         bytestream2_init(&gb, gb.buffer, s->buf + s->size - gb.buffer);
+         if (bytestream2_get_bytes_left(&gb) < 1)
+             return;
+         meth = bytestream2_get_byteu(&gb);
          if (meth & 0x80) {
-             lz_unpack(pb, p_end - pb, s->unpack_buffer, s->unpack_buffer_size);
+             lz_unpack(gb.buffer, bytestream2_get_bytes_left(&gb),
+                       s->unpack_buffer, s->unpack_buffer_size);
              meth &= 0x7F;
-             pb = s->unpack_buffer;
-             pb_end = s->unpack_buffer + s->unpack_buffer_size;
+             bytestream2_init(&gb, s->unpack_buffer, s->unpack_buffer_size);
          }
  
          dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x];