]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '1098f5c0495c61a98d4ff6b8e24c17974d4bace5'
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>
Thu, 14 Apr 2016 12:25:17 +0000 (13:25 +0100)
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>
Thu, 14 Apr 2016 12:25:33 +0000 (13:25 +0100)
* commit '1098f5c0495c61a98d4ff6b8e24c17974d4bace5':
  svq3: Use a separate buffer for decoding the slices

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
1  2 
libavcodec/svq3.c

index 57205c6ad1127c12ae5e8a6e87b3b1b25a7d0e53,90b20af72fb8831e7076887316323ba0a7636bd3..ad3bd5a8fe4e31c72643e0be50022831724787d2
@@@ -76,13 -75,13 +76,15 @@@ typedef struct SVQ3Context 
      H264Picture *cur_pic;
      H264Picture *next_pic;
      H264Picture *last_pic;
+     GetBitContext gb;
+     uint8_t *slice_buf;
+     int slice_size;
      int halfpel_flag;
      int thirdpel_flag;
 -    int unknown_flag;
 +    int has_watermark;
-     int next_slice_index;
      uint32_t watermark_key;
 +    uint8_t *buf;
 +    int buf_size;
      int adaptive_quant;
      int next_p_frame_damaged;
      int h_edge_pos;
@@@ -805,19 -801,24 +808,24 @@@ static int svq3_decode_slice_header(AVC
              return -1;
          }
  
-         h->gb.size_in_bits = s->next_slice_index - 8 * (length - 1);
-         skip_bits(&h->gb, 8);
+         skip_bits(&s->gb, 8);
+         av_fast_malloc(&s->slice_buf, &s->slice_size, slice_bytes + AV_INPUT_BUFFER_PADDING_SIZE);
+         if (!s->slice_buf)
+             return AVERROR(ENOMEM);
+         memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes);
+         init_get_bits(&h->gb, s->slice_buf, slice_bits);
  
          if (s->watermark_key) {
-             uint32_t header = AV_RL32(&h->gb.buffer[(get_bits_count(&h->gb) >> 3) + 1]);
-             AV_WL32(&h->gb.buffer[(get_bits_count(&h->gb) >> 3) + 1],
-                     header ^ s->watermark_key);
+             uint32_t header = AV_RL32(&h->gb.buffer[1]);
+             AV_WL32(&h->gb.buffer[1], header ^ s->watermark_key);
          }
          if (length > 0) {
-             memmove((uint8_t *) &h->gb.buffer[get_bits_count(&h->gb) >> 3],
-                     &h->gb.buffer[h->gb.size_in_bits >> 3], length - 1);
 -            memcpy(s->slice_buf, &s->slice_buf[slice_length], length - 1);
++            memmove(s->slice_buf, &s->slice_buf[slice_length], length - 1);
          }
-         skip_bits_long(&h->gb, 0);
+         skip_bits_long(&s->gb, slice_bytes * 8);
      }
  
      if ((slice_id = svq3_get_ue_golomb(&h->gb)) >= 3) {
@@@ -1182,20 -1161,12 +1190,22 @@@ static int svq3_decode_frame(AVCodecCon
          return 0;
      }
  
-     init_get_bits(&h->gb, buf, 8 * buf_size);
 +    sl->mb_x = sl->mb_y = sl->mb_xy = 0;
 +
 +    if (s->watermark_key) {
 +        av_fast_padded_malloc(&s->buf, &s->buf_size, buf_size);
 +        if (!s->buf)
 +            return AVERROR(ENOMEM);
 +        memcpy(s->buf, avpkt->data, buf_size);
 +        buf = s->buf;
 +    } else {
 +        buf = avpkt->data;
 +    }
 +
+     ret = init_get_bits(&s->gb, buf, 8 * buf_size);
+     if (ret < 0)
+         return ret;
  
 -    sl->mb_x = sl->mb_y = sl->mb_xy = 0;
 -
      if (svq3_decode_slice_header(avctx))
          return -1;