Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/d3d12va_encode: use macros to set QP range and max frame size (PR #20666)
@ 2025-10-08  3:46 Tong Wu via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: Tong Wu via ffmpeg-devel @ 2025-10-08  3:46 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Tong Wu

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-10-08  3:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-08  3:46 [FFmpeg-devel] [PATCH] avcodec/d3d12va_encode: use macros to set QP range and max frame size (PR #20666) Tong Wu via ffmpeg-devel

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