diff mbox

[FFmpeg-devel] avcodec/decode: add a parameter to ff_reget_buffer() to request a writable buffer

Message ID 20190830192657.7231-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Aug. 30, 2019, 7:26 p.m. UTC
Some decoders may not need a writable buffer in some specific cases, but only
a reference to the existing buffer with updated frame properties instead, for
the purpose of returning duplicate frames.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/aasc.c          | 2 +-
 libavcodec/anm.c           | 2 +-
 libavcodec/ansi.c          | 2 +-
 libavcodec/avs.c           | 2 +-
 libavcodec/bethsoftvideo.c | 2 +-
 libavcodec/bink.c          | 2 +-
 libavcodec/c93.c           | 2 +-
 libavcodec/cdgraphics.c    | 2 +-
 libavcodec/cinepak.c       | 2 +-
 libavcodec/clearvideo.c    | 4 ++--
 libavcodec/cpia.c          | 2 +-
 libavcodec/cscd.c          | 2 +-
 libavcodec/decode.c        | 8 ++++----
 libavcodec/dsicinvideo.c   | 2 +-
 libavcodec/fic.c           | 4 ++--
 libavcodec/flashsv.c       | 2 +-
 libavcodec/flicvideo.c     | 6 +++---
 libavcodec/gifdec.c        | 2 +-
 libavcodec/indeo2.c        | 2 +-
 libavcodec/internal.h      | 6 +++---
 libavcodec/jvdec.c         | 2 +-
 libavcodec/mmvideo.c       | 2 +-
 libavcodec/motionpixels.c  | 2 +-
 libavcodec/msrle.c         | 2 +-
 libavcodec/mss1.c          | 2 +-
 libavcodec/mss2.c          | 2 +-
 libavcodec/mss3.c          | 2 +-
 libavcodec/mss4.c          | 2 +-
 libavcodec/msvideo1.c      | 2 +-
 libavcodec/nuv.c           | 2 +-
 libavcodec/pafvideo.c      | 2 +-
 libavcodec/qtrle.c         | 2 +-
 libavcodec/roqvideodec.c   | 2 +-
 libavcodec/rpza.c          | 2 +-
 libavcodec/rscc.c          | 2 +-
 libavcodec/scpr.c          | 2 +-
 libavcodec/screenpresso.c  | 2 +-
 libavcodec/smacker.c       | 2 +-
 libavcodec/smc.c           | 2 +-
 libavcodec/tiertexseqv.c   | 2 +-
 libavcodec/truemotion1.c   | 2 +-
 libavcodec/truemotion2.c   | 2 +-
 libavcodec/tscc.c          | 2 +-
 libavcodec/tscc2.c         | 2 +-
 libavcodec/ulti.c          | 2 +-
 libavcodec/vmnc.c          | 2 +-
 libavcodec/xxan.c          | 2 +-
 libavcodec/yop.c           | 2 +-
 48 files changed, 57 insertions(+), 57 deletions(-)

Comments

Michael Niedermayer Aug. 31, 2019, 2:22 p.m. UTC | #1
On Fri, Aug 30, 2019 at 04:26:57PM -0300, James Almer wrote:
> Some decoders may not need a writable buffer in some specific cases, but only
> a reference to the existing buffer with updated frame properties instead, for
> the purpose of returning duplicate frames.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
[...]
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index 5f964148fd..d12040f47e 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -321,10 +321,10 @@ static av_always_inline float ff_exp2fi(int x) {
>  int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags);
>  
>  /**
> - * Identical in function to av_frame_make_writable(), except it uses
> - * ff_get_buffer() to allocate the buffer when needed.
> + * Identical in function to ff_get_buffer(), except it reuses the existing buffer
> + * if available and ensures it's writable when requested.
>   */
> -int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame);
> +int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int writable);

I suggest using named constants instead of 0 and 1
#define BUF_TYPE_WRITEABLE 1
#define BUF_TYPE_READONLY  0

This makes the code easier to understand

patch LGTM either way

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/aasc.c b/libavcodec/aasc.c
index 58cc3c85ba..9974297ce2 100644
--- a/libavcodec/aasc.c
+++ b/libavcodec/aasc.c
@@ -91,7 +91,7 @@  static int aasc_decode_frame(AVCodecContext *avctx,
         return AVERROR_INVALIDDATA;
     }
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     compr     = AV_RL32(buf);
diff --git a/libavcodec/anm.c b/libavcodec/anm.c
index 778f38413e..97534ffd04 100644
--- a/libavcodec/anm.c
+++ b/libavcodec/anm.c
@@ -122,7 +122,7 @@  static int decode_frame(AVCodecContext *avctx,
     if (buf_size < 7)
         return AVERROR_INVALIDDATA;
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
     dst     = s->frame->data[0];
     dst_end = s->frame->data[0] + s->frame->linesize[0]*avctx->height;
diff --git a/libavcodec/ansi.c b/libavcodec/ansi.c
index f1fafab771..cde7e28a11 100644
--- a/libavcodec/ansi.c
+++ b/libavcodec/ansi.c
@@ -362,7 +362,7 @@  static int decode_frame(AVCodecContext *avctx,
     const uint8_t *buf_end   = buf+buf_size;
     int ret, i, count;
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
     if (!avctx->frame_number) {
         for (i=0; i<avctx->height; i++)
diff --git a/libavcodec/avs.c b/libavcodec/avs.c
index 66724d47b7..dac1c16ca5 100644
--- a/libavcodec/avs.c
+++ b/libavcodec/avs.c
@@ -59,7 +59,7 @@  avs_decode_frame(AVCodecContext * avctx,
     AvsBlockType type;
     GetBitContext change_map = {0}; //init to silence warning
 
-    if ((ret = ff_reget_buffer(avctx, p)) < 0)
+    if ((ret = ff_reget_buffer(avctx, p, 1)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_P;
     p->key_frame = 0;
diff --git a/libavcodec/bethsoftvideo.c b/libavcodec/bethsoftvideo.c
index e5a73f55a1..d056e673df 100644
--- a/libavcodec/bethsoftvideo.c
+++ b/libavcodec/bethsoftvideo.c
@@ -79,7 +79,7 @@  static int bethsoftvid_decode_frame(AVCodecContext *avctx,
     int code, ret;
     int yoffset;
 
-    if ((ret = ff_reget_buffer(avctx, vid->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, vid->frame, 1)) < 0)
         return ret;
     wrap_to_next_line = vid->frame->linesize[0] - avctx->width;
 
diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index 5bb3955f93..16dc20a362 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -1261,7 +1261,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
             return ret;
     } else {
-        if ((ret = ff_reget_buffer(avctx, c->last)) < 0)
+        if ((ret = ff_reget_buffer(avctx, c->last, 1)) < 0)
             return ret;
         if ((ret = av_frame_ref(frame, c->last)) < 0)
             return ret;
diff --git a/libavcodec/c93.c b/libavcodec/c93.c
index b708659cca..53ba401e33 100644
--- a/libavcodec/c93.c
+++ b/libavcodec/c93.c
@@ -138,7 +138,7 @@  static int decode_frame(AVCodecContext *avctx, void *data,
 
     c93->currentpic ^= 1;
 
-    if ((ret = ff_reget_buffer(avctx, newpic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, newpic, 1)) < 0)
         return ret;
 
     stride = newpic->linesize[0];
diff --git a/libavcodec/cdgraphics.c b/libavcodec/cdgraphics.c
index cf3f01a417..63d530aacf 100644
--- a/libavcodec/cdgraphics.c
+++ b/libavcodec/cdgraphics.c
@@ -283,7 +283,7 @@  static int cdg_decode_frame(AVCodecContext *avctx,
 
     bytestream2_init(&gb, avpkt->data, avpkt->size);
 
-    if ((ret = ff_reget_buffer(avctx, cc->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, cc->frame, 1)) < 0)
         return ret;
     if (!cc->cleared) {
         memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index aeb15de0ed..34efb1c72c 100644
--- a/libavcodec/cinepak.c
+++ b/libavcodec/cinepak.c
@@ -473,7 +473,7 @@  static int cinepak_decode_frame(AVCodecContext *avctx,
         return ret;
     }
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     if (s->palette_video) {
diff --git a/libavcodec/clearvideo.c b/libavcodec/clearvideo.c
index 26cdfb2731..edf65c8ca6 100644
--- a/libavcodec/clearvideo.c
+++ b/libavcodec/clearvideo.c
@@ -524,7 +524,7 @@  static int clv_decode_frame(AVCodecContext *avctx, void *data,
             return AVERROR_INVALIDDATA;
         }
 
-        if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
+        if ((ret = ff_reget_buffer(avctx, c->pic, 1)) < 0)
             return ret;
 
         c->pic->key_frame = 1;
@@ -558,7 +558,7 @@  static int clv_decode_frame(AVCodecContext *avctx, void *data,
         if (c->pmb_width * c->pmb_height > 8LL*(buf_size - bytestream2_tell(&gb)))
             return AVERROR_INVALIDDATA;
 
-        if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
+        if ((ret = ff_reget_buffer(avctx, c->pic, 1)) < 0)
             return ret;
 
         ret = av_frame_copy(c->pic, c->prev);
diff --git a/libavcodec/cpia.c b/libavcodec/cpia.c
index f6d7332606..61ea275a12 100644
--- a/libavcodec/cpia.c
+++ b/libavcodec/cpia.c
@@ -100,7 +100,7 @@  static int cpia_decode_frame(AVCodecContext *avctx,
     }
 
     // Get buffer filled with previous frame
-    if ((ret = ff_reget_buffer(avctx, frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, frame, 1)) < 0)
         return ret;
 
 
diff --git a/libavcodec/cscd.c b/libavcodec/cscd.c
index 8781df110c..4fdd66921a 100644
--- a/libavcodec/cscd.c
+++ b/libavcodec/cscd.c
@@ -77,7 +77,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         return AVERROR_INVALIDDATA;
     }
 
-    if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, c->pic, 1)) < 0)
         return ret;
 
     // decompress data
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index cf9676e2ac..fe88cd9751 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1970,7 +1970,7 @@  int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
     return ret;
 }
 
-static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
+static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int writable)
 {
     AVFrame *tmp;
     int ret;
@@ -1986,7 +1986,7 @@  static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
     if (!frame->data[0])
         return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
 
-    if (av_frame_is_writable(frame))
+    if (!writable || av_frame_is_writable(frame))
         return ff_decode_frame_props(avctx, frame);
 
     tmp = av_frame_alloc();
@@ -2007,9 +2007,9 @@  static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame)
     return 0;
 }
 
-int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
+int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int writable)
 {
-    int ret = reget_buffer_internal(avctx, frame);
+    int ret = reget_buffer_internal(avctx, frame, writable);
     if (ret < 0)
         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
     return ret;
diff --git a/libavcodec/dsicinvideo.c b/libavcodec/dsicinvideo.c
index d422df068d..a7413bca7c 100644
--- a/libavcodec/dsicinvideo.c
+++ b/libavcodec/dsicinvideo.c
@@ -290,7 +290,7 @@  static int cinvideo_decode_frame(AVCodecContext *avctx,
         break;
     }
 
-    if ((res = ff_reget_buffer(avctx, cin->frame)) < 0)
+    if ((res = ff_reget_buffer(avctx, cin->frame, 1)) < 0)
         return res;
 
     memcpy(cin->frame->data[1], cin->palette, sizeof(cin->palette));
diff --git a/libavcodec/fic.c b/libavcodec/fic.c
index 540078eda1..f88f842435 100644
--- a/libavcodec/fic.c
+++ b/libavcodec/fic.c
@@ -278,7 +278,7 @@  static int fic_decode_frame(AVCodecContext *avctx, void *data,
     int skip_cursor = ctx->skip_cursor;
     uint8_t *sdata;
 
-    if ((ret = ff_reget_buffer(avctx, ctx->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, ctx->frame, 1)) < 0)
         return ret;
 
     /* Header + at least one slice (4) */
@@ -421,7 +421,7 @@  static int fic_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* Make sure we use a user-supplied buffer. */
-    if ((ret = ff_reget_buffer(avctx, ctx->final_frame)) < 0) {
+    if ((ret = ff_reget_buffer(avctx, ctx->final_frame, 1)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "Could not make frame writable.\n");
         return ret;
     }
diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c
index 92d1af9fcf..c42b5fc3b6 100644
--- a/libavcodec/flashsv.c
+++ b/libavcodec/flashsv.c
@@ -368,7 +368,7 @@  static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
             s->image_width, s->image_height, s->block_width, s->block_height,
             h_blocks, v_blocks, h_part, v_part);
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     /* loop over all block columns */
diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c
index bf8ffeba4f..538d18e9e7 100644
--- a/libavcodec/flicvideo.c
+++ b/libavcodec/flicvideo.c
@@ -185,7 +185,7 @@  static int flic_decode_frame_8BPP(AVCodecContext *avctx,
 
     bytestream2_init(&g2, buf, buf_size);
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     pixels = s->frame->data[0];
@@ -519,7 +519,7 @@  static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
 
     bytestream2_init(&g2, buf, buf_size);
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     pixels = s->frame->data[0];
@@ -817,7 +817,7 @@  static int flic_decode_frame_24BPP(AVCodecContext *avctx,
 
     bytestream2_init(&g2, buf, buf_size);
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     pixels = s->frame->data[0];
diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
index 2115da163f..4e23502b7c 100644
--- a/libavcodec/gifdec.c
+++ b/libavcodec/gifdec.c
@@ -513,7 +513,7 @@  FF_ENABLE_DEPRECATION_WARNINGS
             return AVERROR_INVALIDDATA;
         }
 
-        if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+        if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
             return ret;
 
         s->frame->pict_type = AV_PICTURE_TYPE_P;
diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c
index f367682e61..917cbe04d5 100644
--- a/libavcodec/indeo2.c
+++ b/libavcodec/indeo2.c
@@ -161,7 +161,7 @@  static int ir2_decode_frame(AVCodecContext *avctx,
     int start, ret;
     int ltab, ctab;
 
-    if ((ret = ff_reget_buffer(avctx, p)) < 0)
+    if ((ret = ff_reget_buffer(avctx, p, 1)) < 0)
         return ret;
 
     start = 48; /* hardcoded for now */
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 5f964148fd..d12040f47e 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -321,10 +321,10 @@  static av_always_inline float ff_exp2fi(int x) {
 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags);
 
 /**
- * Identical in function to av_frame_make_writable(), except it uses
- * ff_get_buffer() to allocate the buffer when needed.
+ * Identical in function to ff_get_buffer(), except it reuses the existing buffer
+ * if available and ensures it's writable when requested.
  */
-int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame);
+int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int writable);
 
 int ff_thread_can_start_frame(AVCodecContext *avctx);
 
diff --git a/libavcodec/jvdec.c b/libavcodec/jvdec.c
index b06e7cf2bf..d9b2452a36 100644
--- a/libavcodec/jvdec.c
+++ b/libavcodec/jvdec.c
@@ -168,7 +168,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             GetBitContext gb;
             init_get_bits(&gb, buf, 8 * video_size);
 
-            if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+            if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
                 return ret;
 
             if (avctx->height/8 * (avctx->width/8) > 4 * video_size) {
diff --git a/libavcodec/mmvideo.c b/libavcodec/mmvideo.c
index 04de6bb4c8..21076777d8 100644
--- a/libavcodec/mmvideo.c
+++ b/libavcodec/mmvideo.c
@@ -201,7 +201,7 @@  static int mm_decode_frame(AVCodecContext *avctx,
     buf_size -= MM_PREAMBLE_SIZE;
     bytestream2_init(&s->gb, buf, buf_size);
 
-    if ((res = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((res = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return res;
 
     switch(type) {
diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c
index 73977664a5..fa9a0857df 100644
--- a/libavcodec/motionpixels.c
+++ b/libavcodec/motionpixels.c
@@ -292,7 +292,7 @@  static int mp_decode_frame(AVCodecContext *avctx,
     GetBitContext gb;
     int i, count1, count2, sz, ret;
 
-    if ((ret = ff_reget_buffer(avctx, mp->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, mp->frame, 1)) < 0)
         return ret;
 
     /* le32 bitstream msb first */
diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c
index b83b3d2a41..b088169ec9 100644
--- a/libavcodec/msrle.c
+++ b/libavcodec/msrle.c
@@ -93,7 +93,7 @@  static int msrle_decode_frame(AVCodecContext *avctx,
     if (buf_size < 2) //Minimally a end of picture code should be there
         return AVERROR_INVALIDDATA;
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) {
diff --git a/libavcodec/mss1.c b/libavcodec/mss1.c
index 84b7a37007..4f94b0a820 100644
--- a/libavcodec/mss1.c
+++ b/libavcodec/mss1.c
@@ -154,7 +154,7 @@  static int mss1_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 
     arith_init(&acoder, &gb);
 
-    if ((ret = ff_reget_buffer(avctx, ctx->pic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, ctx->pic, 1)) < 0)
         return ret;
 
     c->pal_pic    =  ctx->pic->data[0] + ctx->pic->linesize[0] * (avctx->height - 1);
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 29897cea2e..321396daff 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -618,7 +618,7 @@  static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             return AVERROR_INVALIDDATA;
         }
     } else {
-        if ((ret = ff_reget_buffer(avctx, ctx->last_pic)) < 0)
+        if ((ret = ff_reget_buffer(avctx, ctx->last_pic, 1)) < 0)
             return ret;
         if ((ret = av_frame_ref(frame, ctx->last_pic)) < 0)
             return ret;
diff --git a/libavcodec/mss3.c b/libavcodec/mss3.c
index 02bd360996..df1437ef88 100644
--- a/libavcodec/mss3.c
+++ b/libavcodec/mss3.c
@@ -737,7 +737,7 @@  static int mss3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         return buf_size;
     c->got_error = 0;
 
-    if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, c->pic, 1)) < 0)
         return ret;
     c->pic->key_frame = keyframe;
     c->pic->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
diff --git a/libavcodec/mss4.c b/libavcodec/mss4.c
index 76c746a2d5..154fb96000 100644
--- a/libavcodec/mss4.c
+++ b/libavcodec/mss4.c
@@ -558,7 +558,7 @@  static int mss4_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (frame_type != SKIP_FRAME && 8*buf_size < 8*HEADER_SIZE + mb_width*mb_height)
         return AVERROR_INVALIDDATA;
 
-    if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, c->pic, 1)) < 0)
         return ret;
     c->pic->key_frame = (frame_type == INTRA_FRAME);
     c->pic->pict_type = (frame_type == INTRA_FRAME) ? AV_PICTURE_TYPE_I
diff --git a/libavcodec/msvideo1.c b/libavcodec/msvideo1.c
index de048d8b6f..3574864099 100644
--- a/libavcodec/msvideo1.c
+++ b/libavcodec/msvideo1.c
@@ -310,7 +310,7 @@  static int msvideo1_decode_frame(AVCodecContext *avctx,
         return AVERROR_INVALIDDATA;
     }
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     if (s->mode_8bit) {
diff --git a/libavcodec/nuv.c b/libavcodec/nuv.c
index 75b14bce5b..b78e22e7e9 100644
--- a/libavcodec/nuv.c
+++ b/libavcodec/nuv.c
@@ -268,7 +268,7 @@  retry:
         init_frame = 1;
     }
 
-    if ((result = ff_reget_buffer(avctx, c->pic)) < 0)
+    if ((result = ff_reget_buffer(avctx, c->pic, 1)) < 0)
         return result;
     if (init_frame) {
         memset(c->pic->data[0], 0,    avctx->height * c->pic->linesize[0]);
diff --git a/libavcodec/pafvideo.c b/libavcodec/pafvideo.c
index 323c662c59..d8f12f98ab 100644
--- a/libavcodec/pafvideo.c
+++ b/libavcodec/pafvideo.c
@@ -289,7 +289,7 @@  static int paf_video_decode(AVCodecContext *avctx, void *data,
         c->video_size / 32 - (int64_t)bytestream2_get_bytes_left(&c->gb) > c->video_size / 32 * (int64_t)avctx->discard_damaged_percentage / 100)
         return AVERROR_INVALIDDATA;
 
-    if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, c->pic, 1)) < 0)
         return ret;
 
     if (code & 0x20) {  // frame is keyframe
diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index f565e0e358..41175c3986 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -490,7 +490,7 @@  static int qtrle_decode_frame(AVCodecContext *avctx,
         start_line = 0;
         height     = s->avctx->height;
     }
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     row_ptr = s->frame->linesize[0] * start_line;
diff --git a/libavcodec/roqvideodec.c b/libavcodec/roqvideodec.c
index 0ab7d399d6..746aa7ef6c 100644
--- a/libavcodec/roqvideodec.c
+++ b/libavcodec/roqvideodec.c
@@ -206,7 +206,7 @@  static int roq_decode_frame(AVCodecContext *avctx,
     int copy = !s->current_frame->data[0] && s->last_frame->data[0];
     int ret;
 
-    if ((ret = ff_reget_buffer(avctx, s->current_frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->current_frame, 1)) < 0)
         return ret;
 
     if (copy) {
diff --git a/libavcodec/rpza.c b/libavcodec/rpza.c
index 8e1efa2445..4110b38d6b 100644
--- a/libavcodec/rpza.c
+++ b/libavcodec/rpza.c
@@ -108,7 +108,7 @@  static int rpza_decode_stream(RpzaContext *s)
     if (total_blocks / 32 > bytestream2_get_bytes_left(&s->gb))
         return AVERROR_INVALIDDATA;
 
-    if ((ret = ff_reget_buffer(s->avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(s->avctx, s->frame, 1)) < 0)
         return ret;
     pixels = (uint16_t *)s->frame->data[0];
     stride = s->frame->linesize[0] / 2;
diff --git a/libavcodec/rscc.c b/libavcodec/rscc.c
index f494c30ed8..63d9dd027b 100644
--- a/libavcodec/rscc.c
+++ b/libavcodec/rscc.c
@@ -310,7 +310,7 @@  static int rscc_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* Allocate when needed */
-    ret = ff_reget_buffer(avctx, ctx->reference);
+    ret = ff_reget_buffer(avctx, ctx->reference, 1);
     if (ret < 0)
         goto end;
 
diff --git a/libavcodec/scpr.c b/libavcodec/scpr.c
index dc890a87e5..661e1fbd84 100644
--- a/libavcodec/scpr.c
+++ b/libavcodec/scpr.c
@@ -504,7 +504,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             return ret;
     }
 
-    if ((ret = ff_reget_buffer(avctx, s->current_frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->current_frame, 1)) < 0)
         return ret;
 
     bytestream2_init(gb, avpkt->data, avpkt->size);
diff --git a/libavcodec/screenpresso.c b/libavcodec/screenpresso.c
index fb8bfd4701..181653848d 100644
--- a/libavcodec/screenpresso.c
+++ b/libavcodec/screenpresso.c
@@ -145,7 +145,7 @@  static int screenpresso_decode_frame(AVCodecContext *avctx, void *data,
         return AVERROR_UNKNOWN;
     }
 
-    ret = ff_reget_buffer(avctx, ctx->current);
+    ret = ff_reget_buffer(avctx, ctx->current, 1);
     if (ret < 0)
         return ret;
 
diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 70e0dfd5df..3ff9f9ad13 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -428,7 +428,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (avpkt->size <= 769)
         return AVERROR_INVALIDDATA;
 
-    if ((ret = ff_reget_buffer(avctx, smk->pic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, smk->pic, 1)) < 0)
         return ret;
 
     /* make the palette available on the way out */
diff --git a/libavcodec/smc.c b/libavcodec/smc.c
index 3cb4834737..5965d896d1 100644
--- a/libavcodec/smc.c
+++ b/libavcodec/smc.c
@@ -445,7 +445,7 @@  static int smc_decode_frame(AVCodecContext *avctx,
 
     bytestream2_init(&s->gb, buf, buf_size);
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     if (pal && pal_size == AVPALETTE_SIZE) {
diff --git a/libavcodec/tiertexseqv.c b/libavcodec/tiertexseqv.c
index af39f74d7d..0b9e52b69a 100644
--- a/libavcodec/tiertexseqv.c
+++ b/libavcodec/tiertexseqv.c
@@ -239,7 +239,7 @@  static int seqvideo_decode_frame(AVCodecContext *avctx,
 
     SeqVideoContext *seq = avctx->priv_data;
 
-    if ((ret = ff_reget_buffer(avctx, seq->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, seq->frame, 1)) < 0)
         return ret;
 
     if (seqvideo_decode(seq, buf, buf_size))
diff --git a/libavcodec/truemotion1.c b/libavcodec/truemotion1.c
index e1824384c5..4d71fa252e 100644
--- a/libavcodec/truemotion1.c
+++ b/libavcodec/truemotion1.c
@@ -882,7 +882,7 @@  static int truemotion1_decode_frame(AVCodecContext *avctx,
     if ((ret = truemotion1_decode_header(s)) < 0)
         return ret;
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     if (compression_types[s->compression].algorithm == ALGO_RGB24H) {
diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c
index 5d6dfc24c3..2605604f6b 100644
--- a/libavcodec/truemotion2.c
+++ b/libavcodec/truemotion2.c
@@ -915,7 +915,7 @@  static int decode_frame(AVCodecContext *avctx,
         return AVERROR(ENOMEM);
     }
 
-    if ((ret = ff_reget_buffer(avctx, p)) < 0)
+    if ((ret = ff_reget_buffer(avctx, p, 1)) < 0)
         return ret;
 
     l->bdsp.bswap_buf((uint32_t *) l->buffer, (const uint32_t *) buf,
diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c
index fc1ec4de0d..5c277ab9b7 100644
--- a/libavcodec/tscc.c
+++ b/libavcodec/tscc.c
@@ -103,7 +103,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         return AVERROR_UNKNOWN;
     }
 
-    if ((ret = ff_reget_buffer(avctx, frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, frame, 1)) < 0)
         return ret;
 
     if (ret != Z_DATA_ERROR) {
diff --git a/libavcodec/tscc2.c b/libavcodec/tscc2.c
index a8c7ee7996..88d77aa77e 100644
--- a/libavcodec/tscc2.c
+++ b/libavcodec/tscc2.c
@@ -240,7 +240,7 @@  static int tscc2_decode_frame(AVCodecContext *avctx, void *data,
         return buf_size;
     }
 
-    if ((ret = ff_reget_buffer(avctx, c->pic)) < 0) {
+    if ((ret = ff_reget_buffer(avctx, c->pic, 1)) < 0) {
         return ret;
     }
 
diff --git a/libavcodec/ulti.c b/libavcodec/ulti.c
index 9318af064b..a26b493f67 100644
--- a/libavcodec/ulti.c
+++ b/libavcodec/ulti.c
@@ -230,7 +230,7 @@  static int ulti_decode_frame(AVCodecContext *avctx,
     int skip;
     int tmp;
 
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->frame, 1)) < 0)
         return ret;
 
     bytestream2_init(&s->gb, buf, buf_size);
diff --git a/libavcodec/vmnc.c b/libavcodec/vmnc.c
index e273043311..b6fc7853bb 100644
--- a/libavcodec/vmnc.c
+++ b/libavcodec/vmnc.c
@@ -339,7 +339,7 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     if (12LL * chunks > bytestream2_get_bytes_left(gb))
         return AVERROR_INVALIDDATA;
 
-    if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, c->pic, 1)) < 0)
         return ret;
 
     c->pic->key_frame = 0;
diff --git a/libavcodec/xxan.c b/libavcodec/xxan.c
index 8bb7087af9..c5e8366641 100644
--- a/libavcodec/xxan.c
+++ b/libavcodec/xxan.c
@@ -410,7 +410,7 @@  static int xan_decode_frame(AVCodecContext *avctx,
     int ftype;
     int ret;
 
-    if ((ret = ff_reget_buffer(avctx, s->pic)) < 0)
+    if ((ret = ff_reget_buffer(avctx, s->pic, 1)) < 0)
         return ret;
 
     bytestream2_init(&s->gb, avpkt->data, avpkt->size);
diff --git a/libavcodec/yop.c b/libavcodec/yop.c
index 32cfea200a..0195c07f78 100644
--- a/libavcodec/yop.c
+++ b/libavcodec/yop.c
@@ -204,7 +204,7 @@  static int yop_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         return AVERROR_INVALIDDATA;
     }
 
-    if ((ret = ff_reget_buffer(avctx, frame)) < 0)
+    if ((ret = ff_reget_buffer(avctx, frame, 1)) < 0)
         return ret;
 
     if (!avctx->frame_number)