Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 4/5] avcodec/cfhd, cfhddata: Free VLC as soon as it is not needed
Date: Sat,  3 Sep 2022 22:35:58 +0200
Message-ID: <AS8P250MB0744A4C135C3D57C65D487898F7D9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AS8P250MB07443029028BA4485D8478F18F7D9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>

The VLC is only used to initialize RL VLC.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/cfhd.c     |  3 ---
 libavcodec/cfhd.h     |  4 ----
 libavcodec/cfhddata.c | 17 ++++++++++-------
 3 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c
index 90b3d0a850..c23eb069c6 100644
--- a/libavcodec/cfhd.c
+++ b/libavcodec/cfhd.c
@@ -1404,9 +1404,6 @@ static av_cold int cfhd_close(AVCodecContext *avctx)
 
     free_buffers(s);
 
-    ff_free_vlc(&s->vlc_9);
-    ff_free_vlc(&s->vlc_18);
-
     return 0;
 }
 
diff --git a/libavcodec/cfhd.h b/libavcodec/cfhd.h
index 4c066da5fc..9b09c91262 100644
--- a/libavcodec/cfhd.h
+++ b/libavcodec/cfhd.h
@@ -26,7 +26,6 @@
 #include "avcodec.h"
 #include "bytestream.h"
 #include "get_bits.h"
-#include "vlc.h"
 #include "cfhddsp.h"
 
 enum CFHDParam {
@@ -141,10 +140,7 @@ typedef struct CFHDContext {
     AVCodecContext *avctx;
 
     CFHD_RL_VLC_ELEM table_9_rl_vlc[2088];
-    VLC vlc_9;
-
     CFHD_RL_VLC_ELEM table_18_rl_vlc[4572];
-    VLC vlc_18;
 
     int lut[2][256];
 
diff --git a/libavcodec/cfhddata.c b/libavcodec/cfhddata.c
index 017eb9375c..efe932dc3b 100644
--- a/libavcodec/cfhddata.c
+++ b/libavcodec/cfhddata.c
@@ -23,6 +23,7 @@
 #include "libavutil/attributes.h"
 
 #include "cfhd.h"
+#include "vlc.h"
 
 #define NB_VLC_TABLE_9   (71 + 3)
 #define NB_VLC_TABLE_18 (263 + 1)
@@ -126,11 +127,12 @@ static const CFHD_RL_ELEM table_18_vlc[NB_VLC_TABLE_18] = {
 
 static av_cold int cfhd_init_vlc(CFHD_RL_VLC_ELEM out[], unsigned out_size,
                                  const CFHD_RL_ELEM table_vlc[], unsigned table_size,
-                                 VLC *vlc, void *logctx)
+                                 void *logctx)
 {
     uint8_t  new_cfhd_vlc_len[NB_VLC_TABLE_18 * 2];
     uint16_t new_cfhd_vlc_run[NB_VLC_TABLE_18 * 2];
     int16_t  new_cfhd_vlc_level[NB_VLC_TABLE_18 * 2];
+    VLC vlc;
     unsigned j;
     int ret;
 
@@ -151,15 +153,15 @@ static av_cold int cfhd_init_vlc(CFHD_RL_VLC_ELEM out[], unsigned out_size,
         }
     }
 
-    ret = ff_init_vlc_from_lengths(vlc, VLC_BITS, j, new_cfhd_vlc_len,
+    ret = ff_init_vlc_from_lengths(&vlc, VLC_BITS, j, new_cfhd_vlc_len,
                                    1, NULL, 0, 0, 0, 0, logctx);
     if (ret < 0)
         return ret;
-    av_assert0(vlc->table_size == out_size);
+    av_assert0(vlc.table_size == out_size);
 
     for (unsigned i = 0; i < out_size; i++) {
-        int code = vlc->table[i].sym;
-        int len  = vlc->table[i].len;
+        int code = vlc.table[i].sym;
+        int len  = vlc.table[i].len;
         int level, run;
 
         if (len < 0) { // more bits needed
@@ -173,6 +175,7 @@ static av_cold int cfhd_init_vlc(CFHD_RL_VLC_ELEM out[], unsigned out_size,
         out[i].level = level;
         out[i].run   = run;
     }
+    ff_free_vlc(&vlc);
 
     return 0;
 }
@@ -184,13 +187,13 @@ av_cold int ff_cfhd_init_vlcs(CFHDContext *s)
     /* Table 9 */
     ret = cfhd_init_vlc(s->table_9_rl_vlc, FF_ARRAY_ELEMS(s->table_9_rl_vlc),
                         table_9_vlc,       FF_ARRAY_ELEMS(table_9_vlc),
-                        &s->vlc_9, s->avctx);
+                        s->avctx);
     if (ret < 0)
         return ret;
     /* Table 18 */
     ret = cfhd_init_vlc(s->table_18_rl_vlc, FF_ARRAY_ELEMS(s->table_18_rl_vlc),
                         table_18_vlc,       FF_ARRAY_ELEMS(table_18_vlc),
-                        &s->vlc_18, s->avctx);
+                        s->avctx);
     if (ret < 0)
         return ret;
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-09-03 20:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-03 20:30 [FFmpeg-devel] [PATCH 1/5] avcodec/cfhd, cfhddata: Simplify check for escape Andreas Rheinhardt
2022-09-03 20:35 ` [FFmpeg-devel] [PATCH 2/5] avcodec/cfhddata: Avoid code tables Andreas Rheinhardt
2022-09-03 20:35 ` [FFmpeg-devel] [PATCH 3/5] avcodec/cfhddata: Avoid code duplication when creating codebooks Andreas Rheinhardt
2022-09-03 20:35 ` Andreas Rheinhardt [this message]
2022-09-03 20:35 ` [FFmpeg-devel] [PATCH 5/5] avcodec/cfhddata: Reduce stack usage Andreas Rheinhardt
2022-09-03 21:49   ` Paul B Mahol
2022-09-03 21:56     ` Andreas Rheinhardt
2022-09-05 10:25       ` Paul B Mahol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AS8P250MB0744A4C135C3D57C65D487898F7D9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git