diff mbox series

[FFmpeg-devel,09/13] avcodec/wnv1: Move temporary variables from context to stack

Message ID 20200829175626.11682-9-andreas.rheinhardt@gmail.com
State Accepted
Commit 099bc252c69a6300e7eb03e245c4228703b334f2
Headers show
Series [FFmpeg-devel,01/13] avcodec/cinepakenc: Cleanup generically after init failure
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 29, 2020, 5:56 p.m. UTC
Here it even leads to the complete removal of the context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/wnv1.c | 40 +++++++++++++++++-----------------------
 1 file changed, 17 insertions(+), 23 deletions(-)

Comments

Paul B Mahol Aug. 29, 2020, 6:26 p.m. UTC | #1
On 8/29/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> Here it even leads to the complete removal of the context.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/wnv1.c | 40 +++++++++++++++++-----------------------
>  1 file changed, 17 insertions(+), 23 deletions(-)

LGTM
diff mbox series

Patch

diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c
index 857807a951..b5cd0f0f0c 100644
--- a/libavcodec/wnv1.c
+++ b/libavcodec/wnv1.c
@@ -30,11 +30,6 @@ 
 #include "internal.h"
 
 
-typedef struct WNV1Context {
-    int shift;
-    GetBitContext gb;
-} WNV1Context;
-
 static const uint16_t code_tab[16][2] = {
     { 0x17F, 9 }, { 0xBF, 8 }, { 0x5F, 7 }, { 0x2F, 6 }, { 0x17, 5 }, { 0x0B, 4 }, { 0x005, 3 },
     { 0x000, 1 },
@@ -45,26 +40,26 @@  static const uint16_t code_tab[16][2] = {
 static VLC code_vlc;
 
 /* returns modified base_value */
-static inline int wnv1_get_code(WNV1Context *w, int base_value)
+static inline int wnv1_get_code(GetBitContext *gb, int shift, int base_value)
 {
-    int v = get_vlc2(&w->gb, code_vlc.table, CODE_VLC_BITS, 1);
+    int v = get_vlc2(gb, code_vlc.table, CODE_VLC_BITS, 1);
 
     if (v == 15)
-        return get_bits(&w->gb, 8 - w->shift) << w->shift;
+        return get_bits(gb, 8 - shift) << shift;
     else
-        return base_value + ((v - 7U) << w->shift);
+        return base_value + ((v - 7U) << shift);
 }
 
 static int decode_frame(AVCodecContext *avctx,
                         void *data, int *got_frame,
                         AVPacket *avpkt)
 {
-    WNV1Context * const l = avctx->priv_data;
     const uint8_t *buf    = avpkt->data;
     int buf_size          = avpkt->size;
     AVFrame * const p     = data;
+    GetBitContext gb;
     unsigned char *Y,*U,*V;
-    int i, j, ret;
+    int i, j, ret, shift;
     int prev_y = 0, prev_u = 0, prev_v = 0;
 
     if (buf_size < 8 + avctx->height * (avctx->width/2)/8) {
@@ -76,24 +71,24 @@  static int decode_frame(AVCodecContext *avctx,
         return ret;
     p->key_frame = 1;
 
-    if ((ret = init_get_bits8(&l->gb, buf + 8, buf_size - 8)) < 0)
+    if ((ret = init_get_bits8(&gb, buf + 8, buf_size - 8)) < 0)
         return ret;
 
     if (buf[2] >> 4 == 6)
-        l->shift = 2;
+        shift = 2;
     else {
-        l->shift = 8 - (buf[2] >> 4);
-        if (l->shift > 4) {
+        shift = 8 - (buf[2] >> 4);
+        if (shift > 4) {
             avpriv_request_sample(avctx,
                                   "Unknown WNV1 frame header value %i",
                                   buf[2] >> 4);
-            l->shift = 4;
+            shift = 4;
         }
-        if (l->shift < 1) {
+        if (shift < 1) {
             avpriv_request_sample(avctx,
                                   "Unknown WNV1 frame header value %i",
                                   buf[2] >> 4);
-            l->shift = 1;
+            shift = 1;
         }
     }
 
@@ -102,10 +97,10 @@  static int decode_frame(AVCodecContext *avctx,
     V = p->data[2];
     for (j = 0; j < avctx->height; j++) {
         for (i = 0; i < avctx->width / 2; i++) {
-            Y[i * 2] = wnv1_get_code(l, prev_y);
-            prev_u = U[i] = wnv1_get_code(l, prev_u);
-            prev_y = Y[(i * 2) + 1] = wnv1_get_code(l, Y[i * 2]);
-            prev_v = V[i] = wnv1_get_code(l, prev_v);
+            Y[i * 2] = wnv1_get_code(&gb, shift, prev_y);
+            prev_u = U[i] = wnv1_get_code(&gb, shift, prev_u);
+            prev_y = Y[(i * 2) + 1] = wnv1_get_code(&gb, shift, Y[i * 2]);
+            prev_v = V[i] = wnv1_get_code(&gb, shift, prev_v);
         }
         Y += p->linesize[0];
         U += p->linesize[1];
@@ -138,7 +133,6 @@  AVCodec ff_wnv1_decoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("Winnov WNV1"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_WNV1,
-    .priv_data_size = sizeof(WNV1Context),
     .init           = decode_init,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,