Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] avcodec/apv_decode: build the lut table only once
Date: Sat,  3 May 2025 22:46:06 -0300
Message-ID: <20250504014606.3768-1-jamrial@gmail.com> (raw)

No reason to build the exact same table once per decoding thread.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/apv_decode.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavcodec/apv_decode.c b/libavcodec/apv_decode.c
index b1e1db7d64..b1c59fc873 100644
--- a/libavcodec/apv_decode.c
+++ b/libavcodec/apv_decode.c
@@ -19,6 +19,7 @@
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/thread.h"
 
 #include "apv.h"
 #include "apv_decode.h"
@@ -39,8 +40,6 @@ typedef struct APVDecodeContext {
     CodedBitstreamFragment au;
     APVDerivedTileInfo tile_info;
 
-    APVVLCLUT decode_lut;
-
     AVFrame *output_frame;
 
     uint8_t warned_additional_frames;
@@ -55,6 +54,8 @@ static const enum AVPixelFormat apv_format_table[5][5] = {
     { AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUVA444P16 },
 };
 
+static APVVLCLUT decode_lut;
+
 static int apv_decode_check_format(AVCodecContext *avctx,
                                    const APVRawFrameHeader *header)
 {
@@ -101,11 +102,20 @@ static const CodedBitstreamUnitType apv_decompose_unit_types[] = {
     APV_PBU_METADATA,
 };
 
+static AVOnce apv_entropy_once = AV_ONCE_INIT;
+
+static av_cold void apv_entropy_build_decode_lut(void)
+{
+    ff_apv_entropy_build_decode_lut(&decode_lut);
+}
+
 static av_cold int apv_decode_init(AVCodecContext *avctx)
 {
     APVDecodeContext *apv = avctx->priv_data;
     int err;
 
+    ff_thread_once(&apv_entropy_once, apv_entropy_build_decode_lut);
+
     err = ff_cbs_init(&apv->cbc, AV_CODEC_ID_APV, avctx);
     if (err < 0)
         return err;
@@ -117,8 +127,6 @@ static av_cold int apv_decode_init(AVCodecContext *avctx)
 
     // Extradata could be set here, but is ignored by the decoder.
 
-    ff_apv_entropy_build_decode_lut(&apv->decode_lut);
-
     ff_apv_dsp_init(&apv->dsp);
 
     return 0;
@@ -201,7 +209,7 @@ static int apv_decode_tile_component(AVCodecContext *avctx, void *data,
 
     APVEntropyState entropy_state = {
         .log_ctx           = avctx,
-        .decode_lut        = &apv->decode_lut,
+        .decode_lut        = &decode_lut,
         .prev_dc           = 0,
         .prev_dc_diff      = 20,
         .prev_1st_ac_level = 0,
-- 
2.49.0

_______________________________________________
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".

                 reply	other threads:[~2025-05-04  1:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250504014606.3768-1-jamrial@gmail.com \
    --to=jamrial@gmail.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