diff mbox series

[FFmpeg-devel,2/2] avcodec/svq3: Don't copy watermarked frame data twice

Message ID 20210320184717.168755-2-andreas.rheinhardt@gmail.com
State Accepted
Commit bcf707639e2eb308407cf5536153a27bdff91990
Headers show
Series [FFmpeg-devel,1/2] avcodec/svq3: Use av_fast_padded_malloc() instead of av_fast_malloc()
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 20, 2021, 6:47 p.m. UTC
The SVQ3 decoder modifies the input bitstream at two places.
One of them is only reached when the file is watermarked.
Therefore commit 2264c1108135380c49fdf0aef97520bf77a6ed37
made a copy of all the frame data in this case.

But there is a second possibility for modifying the frame and
therefore Libav commit 1098f5c0495c61a98d4ff6b8e24c17974d4bace5
made the decoder always copy the data. This of course makes
the additional copy for watermarked frames redundant, but it hasn't
been removed. This commit does so.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/svq3.c | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index 32accb1484..edc8aeacc6 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -97,8 +97,6 @@  typedef struct SVQ3Context {
     int thirdpel_flag;
     int has_watermark;
     uint32_t watermark_key;
-    uint8_t *buf;
-    int buf_size;
     int adaptive_quant;
     int next_p_frame_damaged;
     int h_edge_pos;
@@ -1383,7 +1381,6 @@  static int svq3_decode_frame(AVCodecContext *avctx, void *data,
     SVQ3Context *s     = avctx->priv_data;
     int buf_size       = avpkt->size;
     int left;
-    uint8_t *buf;
     int ret, m, i;
 
     /* special case for last picture */
@@ -1400,17 +1397,7 @@  static int svq3_decode_frame(AVCodecContext *avctx, void *data,
 
     s->mb_x = s->mb_y = s->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);
+    ret = init_get_bits8(&s->gb, avpkt->data, avpkt->size);
     if (ret < 0)
         return ret;
 
@@ -1611,10 +1598,6 @@  static av_cold int svq3_decode_end(AVCodecContext *avctx)
     av_freep(&s->edge_emu_buffer);
     av_freep(&s->mb2br_xy);
 
-
-    av_freep(&s->buf);
-    s->buf_size = 0;
-
     return 0;
 }