Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: averne <averne381@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] nvdec/vc1: add marker insertion logic
Date: Wed, 12 Mar 2025 18:41:53 +0100
Message-ID: <6862c83d-8389-4da6-862c-ba9da56d721e@gmail.com> (raw)
In-Reply-To: <20250304-nvdec-vc1-marker2-v1-1-b72208fe97c5@gmail.com>

Bump

Le 04/03/2025 à 18:17, averne a écrit :
> 
> 
> ---
> Insert the relevant marker into the bitstream on
> slice submission.
> This is analogous to the logic found in DXVA and
> D3D hwaccels.
> 
> Fixes decoding of various VC-1 streams, eg.:
> https://drive.google.com/file/d/1WJyiRhcdU4FHTW3sVMitS7UdrZM1NBy-/view?usp=sharing
> 
> This was investigated using my nvdec tracing tool:
> https://github.com/averne/NvdecTrace
> 
> Signed-off-by: averne <averne381@gmail.com>
> ---
>  libavcodec/nvdec_vc1.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 48 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/nvdec_vc1.c b/libavcodec/nvdec_vc1.c
> index fbfba1ecb43421573ef8fea1e37a2425c272edc9..2726574a26583b0cfc28bdec5595c15bdc465ff8 100644
> --- a/libavcodec/nvdec_vc1.c
> +++ b/libavcodec/nvdec_vc1.c
> @@ -22,6 +22,7 @@
>  
>  #include "config_components.h"
>  
> +#include "libavutil/mem.h"
>  #include "avcodec.h"
>  #include "hwaccel_internal.h"
>  #include "internal.h"
> @@ -107,6 +108,51 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u
>      return 0;
>  }
>  
> +static int nvdec_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
> +                                  uint32_t size)
> +{
> +    NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
> +    const VC1Context *v = avctx->priv_data;
> +    uint32_t marker;
> +    int marker_size;
> +    void *tmp;
> +
> +    if (avctx->codec_id != AV_CODEC_ID_VC1) {
> +        marker_size = 0;
> +    } else {
> +        if (ctx->bitstream_len)
> +            marker = VC1_CODE_SLICE;
> +        else if (v->profile == PROFILE_ADVANCED && v->fcm == ILACE_FIELD && v->second_field)
> +            marker = VC1_CODE_FIELD;
> +        else
> +            marker = VC1_CODE_FRAME;
> +
> +        marker_size = (size >= sizeof(marker) && AV_RB32(buffer) != marker) ? sizeof(marker) : 0;
> +    }
> +
> +    tmp = av_fast_realloc(ctx->bitstream_internal, &ctx->bitstream_allocated,
> +                          ctx->bitstream_len + size + marker_size);
> +    if (!tmp)
> +        return AVERROR(ENOMEM);
> +    ctx->bitstream = ctx->bitstream_internal = tmp;
> +
> +    tmp = av_fast_realloc(ctx->slice_offsets, &ctx->slice_offsets_allocated,
> +                          (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
> +    if (!tmp)
> +        return AVERROR(ENOMEM);
> +    ctx->slice_offsets = tmp;
> +
> +    if (marker_size)
> +        AV_WB32(ctx->bitstream_internal + ctx->bitstream_len, marker);
> +
> +    memcpy(ctx->bitstream_internal + ctx->bitstream_len + marker_size, buffer, size);
> +    ctx->slice_offsets[ctx->nb_slices] = ctx->bitstream_len;
> +    ctx->bitstream_len += size + marker_size;
> +    ctx->nb_slices++;
> +
> +    return 0;
> +}
> +
>  static int nvdec_vc1_frame_params(AVCodecContext *avctx,
>                                    AVBufferRef *hw_frames_ctx)
>  {
> @@ -121,7 +167,7 @@ const FFHWAccel ff_vc1_nvdec_hwaccel = {
>      .p.pix_fmt            = AV_PIX_FMT_CUDA,
>      .start_frame          = nvdec_vc1_start_frame,
>      .end_frame            = ff_nvdec_simple_end_frame,
> -    .decode_slice         = ff_nvdec_simple_decode_slice,
> +    .decode_slice         = nvdec_vc1_decode_slice,
>      .frame_params         = nvdec_vc1_frame_params,
>      .init                 = ff_nvdec_decode_init,
>      .uninit               = ff_nvdec_decode_uninit,
> @@ -136,7 +182,7 @@ const FFHWAccel ff_wmv3_nvdec_hwaccel = {
>      .p.pix_fmt            = AV_PIX_FMT_CUDA,
>      .start_frame          = nvdec_vc1_start_frame,
>      .end_frame            = ff_nvdec_simple_end_frame,
> -    .decode_slice         = ff_nvdec_simple_decode_slice,
> +    .decode_slice         = nvdec_vc1_decode_slice,
>      .frame_params         = nvdec_vc1_frame_params,
>      .init                 = ff_nvdec_decode_init,
>      .uninit               = ff_nvdec_decode_uninit,
> 
> ---
> base-commit: f76195ff656d6bea68feee783160652e2b3e3d60
> change-id: 20250304-nvdec-vc1-marker2-53d6bd30ee99
> 
> Best regards,

_______________________________________________
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-03-12 17:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 17:17 averne
2025-03-12 17:41 ` averne [this message]

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=6862c83d-8389-4da6-862c-ba9da56d721e@gmail.com \
    --to=averne381@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