Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Tong Wu via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Tong Wu <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/d3d12va_encode: use macros to set QP range and max frame size (PR #20666)
Date: Wed, 08 Oct 2025 03:46:59 -0000
Message-ID: <175989522022.65.2448921515826896793@bf249f23a2c8> (raw)

PR #20666 opened by Tong Wu (tong1wu)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20666
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20666.patch

Signed-off-by: Tong Wu <wutong1208@outlook.com>


>From 11d06cb4927455bdd4478014f8b9b64a8724b44a Mon Sep 17 00:00:00 2001
From: Tong Wu <wutong1208@outlook.com>
Date: Wed, 8 Oct 2025 11:41:56 +0800
Subject: [PATCH] avcodec/d3d12va_encode: use macros to set QP range and max
 frame size

Signed-off-by: Tong Wu <wutong1208@outlook.com>
---
 libavcodec/d3d12va_encode.c | 51 +++++++++++++++----------------------
 1 file changed, 21 insertions(+), 30 deletions(-)

diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c
index f34605ec41..4a8672a359 100644
--- a/libavcodec/d3d12va_encode.c
+++ b/libavcodec/d3d12va_encode.c
@@ -853,6 +853,21 @@ static int d3d12va_encode_init_rate_control(AVCodecContext *avctx)
     int fr_num, fr_den;
     const D3D12VAEncodeRCMode *rc_mode;
 
+#define SET_QP_RANGE(ctl) do { \
+        if (avctx->qmin > 0 || avctx->qmax > 0) { \
+            ctl->MinQP = avctx->qmin; \
+            ctl->MaxQP = avctx->qmax; \
+            ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE; \
+        } \
+    } while(0)
+
+#define SET_MAX_FRAME_SIZE(ctl) do { \
+        if (ctx->max_frame_size > 0) { \
+            ctl->MaxFrameBitSize = ctx->max_frame_size * 8; \
+            ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE; \
+        } \
+    } while(0)
+
     // Rate control mode selection:
     // * If the user has set a mode explicitly with the rc_mode option,
     //   use it and fail if it is not available.
@@ -1053,16 +1068,8 @@ rc_mode_found:
             cbr_ctl->InitialVBVFullness = hrd_initial_buffer_fullness;
             ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
 
-            if (avctx->qmin > 0 || avctx->qmax > 0) {
-                cbr_ctl->MinQP = avctx->qmin;
-                cbr_ctl->MaxQP = avctx->qmax;
-                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
-            }
-
-            if (ctx->max_frame_size > 0) {
-                cbr_ctl->MaxFrameBitSize = ctx->max_frame_size * 8;
-                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
-            }
+            SET_QP_RANGE(cbr_ctl);
+            SET_MAX_FRAME_SIZE(cbr_ctl);
 
             ctx->rc.ConfigParams.pConfiguration_CBR = cbr_ctl;
             break;
@@ -1081,16 +1088,8 @@ rc_mode_found:
             vbr_ctl->InitialVBVFullness = hrd_initial_buffer_fullness;
             ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES;
 
-            if (avctx->qmin > 0 || avctx->qmax > 0) {
-                vbr_ctl->MinQP = avctx->qmin;
-                vbr_ctl->MaxQP = avctx->qmax;
-                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
-            }
-
-            if (ctx->max_frame_size > 0) {
-                vbr_ctl->MaxFrameBitSize = ctx->max_frame_size * 8;
-                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
-            }
+            SET_QP_RANGE(vbr_ctl);
+            SET_MAX_FRAME_SIZE(vbr_ctl);
 
             ctx->rc.ConfigParams.pConfiguration_VBR = vbr_ctl;
             break;
@@ -1107,16 +1106,8 @@ rc_mode_found:
             qvbr_ctl->PeakBitRate           = rc_peak_bitrate;
             qvbr_ctl->ConstantQualityTarget = rc_quality;
 
-            if (avctx->qmin > 0 || avctx->qmax > 0) {
-                qvbr_ctl->MinQP = avctx->qmin;
-                qvbr_ctl->MaxQP = avctx->qmax;
-                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
-            }
-
-            if (ctx->max_frame_size > 0) {
-                qvbr_ctl->MaxFrameBitSize = ctx->max_frame_size * 8;
-                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
-            }
+            SET_QP_RANGE(qvbr_ctl);
+            SET_MAX_FRAME_SIZE(qvbr_ctl);
 
             ctx->rc.ConfigParams.pConfiguration_QVBR = qvbr_ctl;
             break;
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-10-08  3:48 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=175989522022.65.2448921515826896793@bf249f23a2c8 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@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 http://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/ http://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