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 <wutong1208@outlook.com>
To: Tong Wu <wutong1208@outlook.com>,
	"ffmpeg-devel@ffmpeg.org" <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavc/d3d12va_encode: trim header alignment at output
Date: Sun, 28 Jul 2024 13:06:00 +0000
Message-ID: <SY7P300MB08453DAA53A7F91457C09C4DC7B62@SY7P300MB0845.AUSP300.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <SY7P282MB45027EAFDD9F182948E9B36DC7DA2@SY7P282MB4502.AUSP282.PROD.OUTLOOK.COM>

Tong Wu:
>Subject: [FFmpeg-devel][PATCH 2/2] lavc/d3d12va_encode: trim header
>alignment at output
>
>It is d3d12va's requirement that the FrameStartOffset must be aligned as per
>hardware limitation. However, we could trim this alignment at output to reduce
>coded size. A aligned_header_size is added to D3D12VAEncodePicture.
>
>Signed-off-by: Tong Wu <wutong1208@outlook.com>
>---
> libavcodec/d3d12va_encode.c | 18 ++++++++++++------
>libavcodec/d3d12va_encode.h |  1 +
> 2 files changed, 13 insertions(+), 6 deletions(-)
>
>diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c index
>9f7a42911e..9ee9da41e3 100644
>--- a/libavcodec/d3d12va_encode.c
>+++ b/libavcodec/d3d12va_encode.c
>@@ -308,9 +308,9 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
>         }
>
>         pic->header_size = (int)bit_len / 8;
>-        pic->header_size = pic->header_size % ctx-
>>req.CompressedBitstreamBufferAccessAlignment ?
>-                           FFALIGN(pic->header_size, ctx-
>>req.CompressedBitstreamBufferAccessAlignment) :
>-                           pic->header_size;
>+        pic->aligned_header_size = pic->header_size % ctx-
>>req.CompressedBitstreamBufferAccessAlignment ?
>+                                   FFALIGN(pic->header_size, ctx-
>>req.CompressedBitstreamBufferAccessAlignment) :
>+                                   pic->header_size;
>
>         hr = ID3D12Resource_Map(pic->output_buffer, 0, NULL, (void **)&ptr);
>         if (FAILED(hr)) {
>@@ -318,7 +318,7 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
>             goto fail;
>         }
>
>-        memcpy(ptr, data, pic->header_size);
>+        memcpy(ptr, data, pic->aligned_header_size);
>         ID3D12Resource_Unmap(pic->output_buffer, 0, NULL);
>     }
>
>@@ -344,10 +344,10 @@ static int d3d12va_encode_issue(AVCodecContext
>*avctx,
>
>     input_args.PictureControlDesc.PictureControlCodecData = pic->pic_ctl;
>     input_args.PictureControlDesc.ReferenceFrames         = d3d12_refs;
>-    input_args.CurrentFrameBitstreamMetadataSize          = pic->header_size;
>+    input_args.CurrentFrameBitstreamMetadataSize          = pic-
>>aligned_header_size;
>
>     output_args.Bitstream.pBuffer                                    = pic->output_buffer;
>-    output_args.Bitstream.FrameStartOffset                           = pic->header_size;
>+    output_args.Bitstream.FrameStartOffset                           = pic-
>>aligned_header_size;
>     output_args.ReconstructedPicture.pReconstructedPicture           = pic-
>>recon_surface->texture;
>     output_args.ReconstructedPicture.ReconstructedPictureSubresource = 0;
>     output_args.EncoderOutputMetadata.pBuffer                        = pic-
>>encoded_metadata;
>@@ -663,6 +663,12 @@ static int
>d3d12va_encode_get_coded_data(AVCodecContext *avctx,
>         goto end;
>     ptr = pkt->data;
>
>+    memcpy(ptr, mapped_data, pic->header_size);
>+
>+    ptr += pic->header_size;
>+    mapped_data += pic->aligned_header_size;
>+    total_size -= pic->header_size;
>+
>     memcpy(ptr, mapped_data, total_size);
>
>     ID3D12Resource_Unmap(pic->output_buffer, 0, NULL); diff --git
>a/libavcodec/d3d12va_encode.h b/libavcodec/d3d12va_encode.h index
>1a0abc5bd0..51440428e4 100644
>--- a/libavcodec/d3d12va_encode.h
>+++ b/libavcodec/d3d12va_encode.h
>@@ -43,6 +43,7 @@ typedef struct D3D12VAEncodePicture {
>     FFHWBaseEncodePicture base;
>
>     int             header_size;
>+    int             aligned_header_size;
>
>     AVD3D12VAFrame *input_surface;
>     AVD3D12VAFrame *recon_surface;
>--
>2.45.1.windows.1


The first patch in this patchset has been merged earlier. Will merge this patch if there's no more comment.

-Tong



_______________________________________________
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:[~2024-07-28 13:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240708151323.312-1-wutong1208@outlook.com>
2024-07-08 15:13 ` Tong Wu
2024-07-28 13:06   ` Tong Wu [this message]
2024-07-28 15:55     ` Lynne via ffmpeg-devel
2024-07-29 14:36       ` Tong Wu

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=SY7P300MB08453DAA53A7F91457C09C4DC7B62@SY7P300MB0845.AUSP300.PROD.OUTLOOK.COM \
    --to=wutong1208@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