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] AV1 VDPAU hwaccel Decode support
@ 2022-05-16 13:15 ManojGuptaBonda
  2022-05-17  4:46 ` Philip Langdale
  0 siblings, 1 reply; 5+ messages in thread
From: ManojGuptaBonda @ 2022-05-16 13:15 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: vdpau, aplattner, ManojGuptaBonda, ARitger, philipl

Support for VDPAU accelerated AV1 decoding was added with libvdpau-1.5.
Support for the same in ffmpeg is added with this patch. Profiles
related to VDPAU AV1 can be found in latest vdpau.h present in
libvdpau-1.5.

Add AV1 VDPAU to list of hwaccels and supported formats
Added file vdpau_av1.c and Modified configure to add VDPAU AV1 support.
Mapped AV1 profiles to VDPAU AV1 profiles. Populated the codec specific
params that need to be passed to VDPAU.
---
 Changelog                   |   1 +
 configure                   |   3 +
 libavcodec/Makefile         |   1 +
 libavcodec/av1dec.c         |  13 +-
 libavcodec/hwaccels.h       |   1 +
 libavcodec/vdpau_av1.c      | 370 ++++++++++++++++++++++++++++++++++++
 libavcodec/vdpau_internal.h |   3 +
 libavcodec/version.h        |   2 +-
 8 files changed, 392 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/vdpau_av1.c

diff --git a/Changelog b/Changelog
index 4d42a0f681..a713edf566 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,7 @@ version 5.1:
 - blurdetect filter
 - multiply video filter
 - PGS subtitle frame merge bitstream filter
+- VDPAU AV1 hwaccel
 
 
 version 5.0:
diff --git a/configure b/configure
index 0faf2455b7..702fb4d741 100755
--- a/configure
+++ b/configure
@@ -3025,6 +3025,8 @@ av1_nvdec_hwaccel_deps="nvdec CUVIDAV1PICPARAMS"
 av1_nvdec_hwaccel_select="av1_decoder"
 av1_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferAV1_bit_depth_idx"
 av1_vaapi_hwaccel_select="av1_decoder"
+av1_vdpau_hwaccel_deps="vdpau VdpPictureInfoAV1"
+av1_vdpau_hwaccel_select="av1_decoder"
 h263_vaapi_hwaccel_deps="vaapi"
 h263_vaapi_hwaccel_select="h263_decoder"
 h263_videotoolbox_hwaccel_deps="videotoolbox"
@@ -6391,6 +6393,7 @@ check_func_headers mfapi.h MFCreateAlignedMemoryBuffer -lmfplat
 
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
 check_type "vdpau/vdpau.h" "VdpPictureInfoVP9"
+check_type "vdpau/vdpau.h" "VdpPictureInfoAV1"
 
 if [ -z "$nvccflags" ]; then
     nvccflags=$nvccflags_default
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 38425d2f22..813989cee9 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -954,6 +954,7 @@ OBJS-$(CONFIG_AV1_D3D11VA_HWACCEL)        += dxva2_av1.o
 OBJS-$(CONFIG_AV1_DXVA2_HWACCEL)          += dxva2_av1.o
 OBJS-$(CONFIG_AV1_NVDEC_HWACCEL)          += nvdec_av1.o
 OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)          += vaapi_av1.o
+OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)          += vdpau_av1.o
 OBJS-$(CONFIG_H263_VAAPI_HWACCEL)         += vaapi_mpeg4.o
 OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL)  += videotoolbox.o
 OBJS-$(CONFIG_H264_D3D11VA_HWACCEL)       += dxva2_h264.o
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 1c09b1d6d6..dd83373dd6 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -441,7 +441,8 @@ static int get_pixel_format(AVCodecContext *avctx)
 #define HWACCEL_MAX (CONFIG_AV1_DXVA2_HWACCEL + \
                      CONFIG_AV1_D3D11VA_HWACCEL * 2 + \
                      CONFIG_AV1_NVDEC_HWACCEL + \
-                     CONFIG_AV1_VAAPI_HWACCEL)
+                     CONFIG_AV1_VAAPI_HWACCEL + \
+                     CONFIG_AV1_VDPAU_HWACCEL)
     enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
 
     if (seq->seq_profile == 2 && seq->color_config.high_bitdepth)
@@ -518,6 +519,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 #endif
 #if CONFIG_AV1_VAAPI_HWACCEL
         *fmtp++ = AV_PIX_FMT_VAAPI;
+#endif
+#if CONFIG_AV1_VDPAU_HWACCEL
+        *fmtp++ = AV_PIX_FMT_VDPAU;
 #endif
         break;
     case AV_PIX_FMT_YUV420P10:
@@ -533,6 +537,9 @@ static int get_pixel_format(AVCodecContext *avctx)
 #endif
 #if CONFIG_AV1_VAAPI_HWACCEL
         *fmtp++ = AV_PIX_FMT_VAAPI;
+#endif
+#if CONFIG_AV1_VDPAU_HWACCEL
+        *fmtp++ = AV_PIX_FMT_VDPAU;
 #endif
         break;
     case AV_PIX_FMT_GRAY8:
@@ -1271,6 +1278,10 @@ const FFCodec ff_av1_decoder = {
 #if CONFIG_AV1_VAAPI_HWACCEL
         HWACCEL_VAAPI(av1),
 #endif
+#if CONFIG_AV1_VDPAU_HWACCEL
+        HWACCEL_VDPAU(av1),
+#endif
+
         NULL
     },
 };
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index ff4daca0e2..aca55831f3 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -26,6 +26,7 @@ extern const AVHWAccel ff_av1_d3d11va2_hwaccel;
 extern const AVHWAccel ff_av1_dxva2_hwaccel;
 extern const AVHWAccel ff_av1_nvdec_hwaccel;
 extern const AVHWAccel ff_av1_vaapi_hwaccel;
+extern const AVHWAccel ff_av1_vdpau_hwaccel;
 extern const AVHWAccel ff_h263_vaapi_hwaccel;
 extern const AVHWAccel ff_h263_videotoolbox_hwaccel;
 extern const AVHWAccel ff_h264_d3d11va_hwaccel;
diff --git a/libavcodec/vdpau_av1.c b/libavcodec/vdpau_av1.c
new file mode 100644
index 0000000000..95c1e58cf7
--- /dev/null
+++ b/libavcodec/vdpau_av1.c
@@ -0,0 +1,370 @@
+/*
+ * AV1 HW decode acceleration through VDPAU
+ *
+ * Copyright (c) 2022 Manoj Gupta Bonda
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <vdpau/vdpau.h>
+#include "libavutil/pixdesc.h"
+#include "avcodec.h"
+#include "internal.h"
+#include "av1dec.h"
+#include "hwconfig.h"
+#include "vdpau.h"
+#include "vdpau_internal.h"
+
+static int get_bit_depth_from_seq(const AV1RawSequenceHeader *seq)
+{
+    if (seq->seq_profile == 2 && seq->color_config.high_bitdepth) {
+        return seq->color_config.twelve_bit ? 12 : 10;
+    } else if (seq->seq_profile <= 2 && seq->color_config.high_bitdepth) {
+        return 10;
+    } else {
+        return 8;
+    }
+}
+
+static int vdpau_av1_start_frame(AVCodecContext *avctx,
+                                  const uint8_t *buffer, uint32_t size)
+{
+    AV1DecContext *s = avctx->priv_data;
+    const AV1RawSequenceHeader *seq = s->raw_seq;
+    const AV1RawFrameHeader *frame_header = s->raw_frame_header;
+    const AV1RawFilmGrainParams *film_grain = &s->cur_frame.film_grain;
+
+    struct vdpau_picture_context *pic_ctx = s->cur_frame.hwaccel_picture_private;
+    int i,j;
+
+    unsigned char remap_lr_type[4] = { AV1_RESTORE_NONE, AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ };
+
+
+    VdpPictureInfoAV1 *info = &pic_ctx->info.av1;
+    const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
+    if (!pixdesc) {
+        return AV_PIX_FMT_NONE;
+    }
+
+    info->width = avctx->width;
+    info->height = avctx->height;
+
+
+    info->frame_offset = frame_header->order_hint;
+
+    /* Sequence Header */
+    info->profile                    = seq->seq_profile;
+    info->use_128x128_superblock     = seq->use_128x128_superblock;
+    info->subsampling_x              = seq->color_config.subsampling_x;
+    info->subsampling_y              = seq->color_config.subsampling_y;
+    info->mono_chrome                = seq->color_config.mono_chrome;
+    info->bit_depth_minus8           = get_bit_depth_from_seq(seq) - 8;
+    info->enable_filter_intra        = seq->enable_filter_intra;
+    info->enable_intra_edge_filter   = seq->enable_intra_edge_filter;
+    info->enable_interintra_compound = seq->enable_interintra_compound;
+    info->enable_masked_compound     = seq->enable_masked_compound;
+    info->enable_dual_filter         = seq->enable_dual_filter;
+    info->enable_order_hint          = seq->enable_order_hint;
+    info->order_hint_bits_minus1     = seq->order_hint_bits_minus_1;
+    info->enable_jnt_comp            = seq->enable_jnt_comp;
+    info->enable_superres            = seq->enable_superres;
+    info->enable_cdef                = seq->enable_cdef;
+    info->enable_restoration         = seq->enable_restoration;
+    info->enable_fgs                 = seq->film_grain_params_present;
+
+    /* Frame Header */
+    info->frame_type                   = frame_header->frame_type;
+    info->show_frame                   = frame_header->show_frame;
+    info->disable_cdf_update           = frame_header->disable_cdf_update;
+    info->allow_screen_content_tools   = frame_header->allow_screen_content_tools;
+    info->force_integer_mv             = frame_header->force_integer_mv ||
+                                    frame_header->frame_type == AV1_FRAME_INTRA_ONLY ||
+                                    frame_header->frame_type == AV1_FRAME_KEY;
+    info->coded_denom                  = frame_header->coded_denom;
+    info->allow_intrabc                = frame_header->allow_intrabc;
+    info->allow_high_precision_mv      = frame_header->allow_high_precision_mv;
+    info->interp_filter                = frame_header->interpolation_filter;
+    info->switchable_motion_mode       = frame_header->is_motion_mode_switchable;
+    info->use_ref_frame_mvs            = frame_header->use_ref_frame_mvs;
+    info->disable_frame_end_update_cdf = frame_header->disable_frame_end_update_cdf;
+    info->delta_q_present              = frame_header->delta_q_present;
+    info->delta_q_res                  = frame_header->delta_q_res;
+    info->using_qmatrix                = frame_header->using_qmatrix;
+    info->coded_lossless               = s->cur_frame.coded_lossless;
+    info->use_superres                 = frame_header->use_superres;
+    info->tx_mode                      = frame_header->tx_mode;
+    info->reference_mode               = frame_header->reference_select;
+    info->allow_warped_motion          = frame_header->allow_warped_motion;
+    info->reduced_tx_set               = frame_header->reduced_tx_set;
+    info->skip_mode                    = frame_header->skip_mode_present;
+
+    /* Tiling Info */
+    info->num_tile_cols          = frame_header->tile_cols;
+    info->num_tile_rows          = frame_header->tile_rows;
+    info->context_update_tile_id = frame_header->context_update_tile_id;
+
+    /* CDEF */
+    info->cdef_damping_minus_3 = frame_header->cdef_damping_minus_3;
+    info->cdef_bits            = frame_header->cdef_bits;
+
+    /* SkipModeFrames */
+    info->SkipModeFrame0 = frame_header->skip_mode_present ?
+                      s->cur_frame.skip_mode_frame_idx[0] : 0;
+    info->SkipModeFrame1 = frame_header->skip_mode_present ?
+                      s->cur_frame.skip_mode_frame_idx[1] : 0;
+
+    /* QP Information */
+    info->base_qindex     = frame_header->base_q_idx;
+    info->qp_y_dc_delta_q = frame_header->delta_q_y_dc;
+    info->qp_u_dc_delta_q = frame_header->delta_q_u_dc;
+    info->qp_v_dc_delta_q = frame_header->delta_q_v_dc;
+    info->qp_u_ac_delta_q = frame_header->delta_q_u_ac;
+    info->qp_v_ac_delta_q = frame_header->delta_q_v_ac;
+    info->qm_y            = frame_header->qm_y;
+    info->qm_u            = frame_header->qm_u;
+    info->qm_v            = frame_header->qm_v;
+
+    /* Segmentation */
+    info->segmentation_enabled         = frame_header->segmentation_enabled;
+    info->segmentation_update_map      = frame_header->segmentation_update_map;
+    info->segmentation_update_data     = frame_header->segmentation_update_data;
+    info->segmentation_temporal_update = frame_header->segmentation_temporal_update;
+
+    /* Loopfilter */
+    info->loop_filter_level[0]       = frame_header->loop_filter_level[0];
+    info->loop_filter_level[1]       = frame_header->loop_filter_level[1];
+    info->loop_filter_level_u        = frame_header->loop_filter_level[2];
+    info->loop_filter_level_v        = frame_header->loop_filter_level[3];
+    info->loop_filter_sharpness      = frame_header->loop_filter_sharpness;
+    info->loop_filter_delta_enabled  = frame_header->loop_filter_delta_enabled;
+    info->loop_filter_delta_update   = frame_header->loop_filter_delta_update;
+    info->loop_filter_mode_deltas[0] = frame_header->loop_filter_mode_deltas[0];
+    info->loop_filter_mode_deltas[1] = frame_header->loop_filter_mode_deltas[1];
+    info->delta_lf_present           = frame_header->delta_lf_present;
+    info->delta_lf_res               = frame_header->delta_lf_res;
+    info->delta_lf_multi             = frame_header->delta_lf_multi;
+
+    /* Restoration */
+    info->lr_type[0]      = remap_lr_type[frame_header->lr_type[0]];
+    info->lr_type[1]      = remap_lr_type[frame_header->lr_type[1]];
+    info->lr_type[2]      = remap_lr_type[frame_header->lr_type[2]];
+    info->lr_unit_size[0] = 1 + frame_header->lr_unit_shift;
+    info->lr_unit_size[1] = 1 + frame_header->lr_unit_shift - frame_header->lr_uv_shift;
+    info->lr_unit_size[2] = 1 + frame_header->lr_unit_shift - frame_header->lr_uv_shift;
+
+    /* Reference Frames */
+    info->temporal_layer_id = s->cur_frame.temporal_id;
+    info->spatial_layer_id  = s->cur_frame.spatial_id;
+
+    /* Film Grain Params */
+    info->apply_grain              = film_grain->apply_grain;
+    info->overlap_flag             = film_grain->overlap_flag;
+    info->scaling_shift_minus8     = film_grain->grain_scaling_minus_8;
+    info->chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma;
+    info->ar_coeff_lag             = film_grain->ar_coeff_lag;
+    info->ar_coeff_shift_minus6    = film_grain->ar_coeff_shift_minus_6;
+    info->grain_scale_shift        = film_grain->grain_scale_shift;
+    info->clip_to_restricted_range = film_grain->clip_to_restricted_range;
+    info->num_y_points             = film_grain->num_y_points;
+    info->num_cb_points            = film_grain->num_cb_points;
+    info->num_cr_points            = film_grain->num_cr_points;
+    info->random_seed              = film_grain->grain_seed;
+    info->cb_mult                  = film_grain->cb_mult;
+    info->cb_luma_mult             = film_grain->cb_luma_mult;
+    info->cb_offset                = film_grain->cb_offset;
+    info->cr_mult                  = film_grain->cr_mult;
+    info->cr_luma_mult             = film_grain->cr_luma_mult;
+    info->cr_offset                = film_grain->cr_offset;
+
+    /* Tiling Info */
+    for (i = 0; i < frame_header->tile_cols; ++i) {
+        info->tile_widths[i] = frame_header->width_in_sbs_minus_1[i] + 1;
+    }
+    for (i = 0; i < frame_header->tile_rows; ++i) {
+        info->tile_heights[i] = frame_header->height_in_sbs_minus_1[i] + 1;
+    }
+
+    /* CDEF */
+    for (i = 0; i < (1 << frame_header->cdef_bits); ++i) {
+        info->cdef_y_strength[i] = (frame_header->cdef_y_pri_strength[i] & 0x0F) | (frame_header->cdef_y_sec_strength[i] << 4);
+        info->cdef_uv_strength[i] = (frame_header->cdef_uv_pri_strength[i] & 0x0F) | (frame_header->cdef_uv_sec_strength[i] << 4);
+    }
+
+
+    /* Segmentation */
+    for (i = 0; i < AV1_MAX_SEGMENTS; ++i) {
+        info->segmentation_feature_mask[i] = 0;
+        for (j = 0; j < AV1_SEG_LVL_MAX; ++j) {
+            info->segmentation_feature_mask[i] |= frame_header->feature_enabled[i][j] << j;
+            info->segmentation_feature_data[i][j] = frame_header->feature_value[i][j];
+        }
+    }
+
+    for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) {
+        /* Loopfilter */
+        info->loop_filter_ref_deltas[i] = frame_header->loop_filter_ref_deltas[i];
+
+        /* Reference Frames */
+        info->ref_frame_map[i] = ff_vdpau_get_surface_id(s->ref[i].tf.f) ? ff_vdpau_get_surface_id(s->ref[i].tf.f) : VDP_INVALID_HANDLE;
+    }
+
+    if (frame_header->primary_ref_frame == AV1_PRIMARY_REF_NONE) {
+        info->primary_ref_frame = -1;
+    } else {
+        int8_t pri_ref_idx = frame_header->ref_frame_idx[frame_header->primary_ref_frame];
+        info->primary_ref_frame = info->ref_frame_map[pri_ref_idx];
+    }
+
+    for (i = 0; i < AV1_REFS_PER_FRAME; ++i) {
+        /* Ref Frame List */
+        int8_t ref_idx = frame_header->ref_frame_idx[i];
+        AVFrame *ref_frame = s->ref[ref_idx].tf.f;
+
+        info->ref_frame[i].index = info->ref_frame_map[ref_idx];
+        info->ref_frame[i].width = ref_frame->width;
+        info->ref_frame[i].height = ref_frame->height;
+
+        /* Global Motion */
+        info->global_motion[i].invalid = !frame_header->is_global[AV1_REF_FRAME_LAST + i];
+        info->global_motion[i].wmtype = s->cur_frame.gm_type[AV1_REF_FRAME_LAST + i];
+        for (j = 0; j < 6; ++j) {
+            info->global_motion[i].wmmat[j] = s->cur_frame.gm_params[AV1_REF_FRAME_LAST + i][j];
+        }
+    }
+
+    /* Film Grain Params */
+    if (film_grain->apply_grain) {
+        for (i = 0; i < 14; ++i) {
+            info->scaling_points_y[i][0] = film_grain->point_y_value[i];
+            info->scaling_points_y[i][1] = film_grain->point_y_scaling[i];
+        }
+        for (i = 0; i < 10; ++i) {
+            info->scaling_points_cb[i][0] = film_grain->point_cb_value[i];
+            info->scaling_points_cb[i][1] = film_grain->point_cb_scaling[i];
+            info->scaling_points_cr[i][0] = film_grain->point_cr_value[i];
+            info->scaling_points_cr[i][1] = film_grain->point_cr_scaling[i];
+        }
+        for (i = 0; i < 24; ++i) {
+            info->ar_coeffs_y[i] = (short)film_grain->ar_coeffs_y_plus_128[i] - 128;
+        }
+        for (i = 0; i < 25; ++i) {
+            info->ar_coeffs_cb[i] = (short)film_grain->ar_coeffs_cb_plus_128[i] - 128;
+            info->ar_coeffs_cr[i] = (short)film_grain->ar_coeffs_cr_plus_128[i] - 128;
+        }
+    }
+
+
+    return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
+
+}
+
+static int vdpau_av1_decode_slice(AVCodecContext *avctx,
+                                   const uint8_t *buffer, uint32_t size)
+{
+    const AV1DecContext *s = avctx->priv_data;
+    const AV1RawFrameHeader *frame_header = s->raw_frame_header;
+    struct vdpau_picture_context *pic_ctx = s->cur_frame.hwaccel_picture_private;
+    VdpPictureInfoAV1 *info = &pic_ctx->info.av1;
+    int val;
+    int nb_slices;
+    VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers;
+    int bitstream_len = 0;
+
+    nb_slices = frame_header->tile_cols * frame_header->tile_rows;
+    /* Shortcut if all tiles are in the same buffer*/
+    if (nb_slices == s->tg_end - s->tg_start + 1) {
+        for (int i = 0; i < nb_slices; ++i) {
+            info->tile_info[i*2    ] = s->tile_group_info[i].tile_offset;
+            info->tile_info[i*2 + 1] = info->tile_info[i*2] + s->tile_group_info[i].tile_size;
+        }
+        val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
+        if (val) {
+            return val;
+        }
+
+        return 0;
+    }
+
+    for(int i = 0; i < pic_ctx->bitstream_buffers_used; i++) {
+        bitstream_len += buffers->bitstream_bytes;
+        buffers++;
+    }
+
+    for (uint32_t tile_num = s->tg_start; tile_num <= s->tg_end; ++tile_num) {
+        info->tile_info[tile_num*2    ] = bitstream_len + s->tile_group_info[tile_num].tile_offset;
+        info->tile_info[tile_num*2 + 1] = info->tile_info[tile_num*2] + s->tile_group_info[tile_num].tile_size;
+    }
+
+    val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
+    if (val) {
+        return val;
+    }
+
+    return 0;
+}
+
+static int vdpau_av1_end_frame(AVCodecContext *avctx)
+{
+    const AV1DecContext *s = avctx->priv_data;
+    struct vdpau_picture_context *pic_ctx = s->cur_frame.hwaccel_picture_private;
+
+    int val;
+
+    val = ff_vdpau_common_end_frame(avctx, s->cur_frame.tf.f, pic_ctx);
+    if (val < 0)
+        return val;
+
+    return 0;
+}
+
+static int vdpau_av1_init(AVCodecContext *avctx)
+{
+    VdpDecoderProfile profile;
+    uint32_t level = avctx->level;
+
+    switch (avctx->profile) {
+    case FF_PROFILE_AV1_MAIN:
+        profile = VDP_DECODER_PROFILE_AV1_MAIN;
+        break;
+    case FF_PROFILE_AV1_HIGH:
+        profile = VDP_DECODER_PROFILE_AV1_HIGH;
+        break;
+    case FF_PROFILE_AV1_PROFESSIONAL:
+        profile = VDP_DECODER_PROFILE_AV1_PROFESSIONAL;
+        break;
+    default:
+        return AVERROR(ENOTSUP);
+    }
+
+    return ff_vdpau_common_init(avctx, profile, level);
+}
+
+const AVHWAccel ff_av1_vdpau_hwaccel = {
+    .name           = "av1_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_AV1,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_av1_start_frame,
+    .end_frame      = vdpau_av1_end_frame,
+    .decode_slice   = vdpau_av1_decode_slice,
+    .frame_priv_data_size = sizeof(struct vdpau_picture_context),
+    .init           = vdpau_av1_init,
+    .uninit         = ff_vdpau_common_uninit,
+    .frame_params   = ff_vdpau_common_frame_params,
+    .priv_data_size = sizeof(VDPAUContext),
+    .caps_internal  = HWACCEL_CAP_ASYNC_SAFE,
+};
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index b6ea078cb2..347576e0c3 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -57,6 +57,9 @@ union VDPAUPictureInfo {
 #ifdef VDP_DECODER_PROFILE_VP9_PROFILE_0
     VdpPictureInfoVP9        vp9;
 #endif
+#ifdef VDP_DECODER_PROFILE_AV1_MAIN
+    VdpPictureInfoAV1        av1;
+#endif
 };
 
 typedef struct VDPAUHWContext {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 87b7284a95..5183deb68b 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  28
+#define LIBAVCODEC_VERSION_MINOR  29
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.17.1

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support
  2022-05-16 13:15 [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support ManojGuptaBonda
@ 2022-05-17  4:46 ` Philip Langdale
  2022-05-17 12:07   ` Manoj Bonda
  0 siblings, 1 reply; 5+ messages in thread
From: Philip Langdale @ 2022-05-17  4:46 UTC (permalink / raw)
  To: FFmpeg development discussions and patches
  Cc: vdpau, ManojGuptaBonda, ManojGuptaBonda, ARitger, aplattner

On Mon, 16 May 2022 18:45:58 +0530
ManojGuptaBonda <mbonda-at-nvidia.com@ffmpeg.org> wrote:

> Support for VDPAU accelerated AV1 decoding was added with
> libvdpau-1.5. Support for the same in ffmpeg is added with this
> patch. Profiles related to VDPAU AV1 can be found in latest vdpau.h
> present in libvdpau-1.5.
> 
> Add AV1 VDPAU to list of hwaccels and supported formats
> Added file vdpau_av1.c and Modified configure to add VDPAU AV1
> support. Mapped AV1 profiles to VDPAU AV1 profiles. Populated the
> codec specific params that need to be passed to VDPAU.
> ---
>  Changelog                   |   1 +
>  configure                   |   3 +
>  libavcodec/Makefile         |   1 +
>  libavcodec/av1dec.c         |  13 +-
>  libavcodec/hwaccels.h       |   1 +
>  libavcodec/vdpau_av1.c      | 370
> ++++++++++++++++++++++++++++++++++++ libavcodec/vdpau_internal.h |
> 3 + libavcodec/version.h        |   2 +-
>  8 files changed, 392 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/vdpau_av1.c
> 

<Snip>

> diff --git a/libavcodec/vdpau_av1.c b/libavcodec/vdpau_av1.c
> new file mode 100644
> index 0000000000..95c1e58cf7
> --- /dev/null
> +++ b/libavcodec/vdpau_av1.c
> @@ -0,0 +1,370 @@
> +/*
> + * AV1 HW decode acceleration through VDPAU
> + *
> + * Copyright (c) 2022 Manoj Gupta Bonda
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> Foundation,
> + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include <vdpau/vdpau.h>
> +#include "libavutil/pixdesc.h"
> +#include "avcodec.h"
> +#include "internal.h"
> +#include "av1dec.h"
> +#include "hwconfig.h"
> +#include "vdpau.h"
> +#include "vdpau_internal.h"
> +
> +static int get_bit_depth_from_seq(const AV1RawSequenceHeader *seq)
> +{
> +    if (seq->seq_profile == 2 && seq->color_config.high_bitdepth) {
> +        return seq->color_config.twelve_bit ? 12 : 10;
> +    } else if (seq->seq_profile <= 2 &&
> seq->color_config.high_bitdepth) {
> +        return 10;
> +    } else {
> +        return 8;
> +    }
> +}
> +
> +static int vdpau_av1_start_frame(AVCodecContext *avctx,
> +                                  const uint8_t *buffer, uint32_t
> size) +{
> +    AV1DecContext *s = avctx->priv_data;
> +    const AV1RawSequenceHeader *seq = s->raw_seq;
> +    const AV1RawFrameHeader *frame_header = s->raw_frame_header;
> +    const AV1RawFilmGrainParams *film_grain =
> &s->cur_frame.film_grain; +
> +    struct vdpau_picture_context *pic_ctx =
> s->cur_frame.hwaccel_picture_private;
> +    int i,j;
> +
> +    unsigned char remap_lr_type[4] = { AV1_RESTORE_NONE,
> AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ }; +
> +
> +    VdpPictureInfoAV1 *info = &pic_ctx->info.av1;
> +    const AVPixFmtDescriptor *pixdesc =
> av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> +    if (!pixdesc) {
> +        return AV_PIX_FMT_NONE;
> +    }
> +
> +    info->width = avctx->width;
> +    info->height = avctx->height;
> +
> +
> +    info->frame_offset = frame_header->order_hint;
> +
> +    /* Sequence Header */
> +    info->profile                    = seq->seq_profile;
> +    info->use_128x128_superblock     = seq->use_128x128_superblock;
> +    info->subsampling_x              =
> seq->color_config.subsampling_x;
> +    info->subsampling_y              =
> seq->color_config.subsampling_y;
> +    info->mono_chrome                = seq->color_config.mono_chrome;
> +    info->bit_depth_minus8           = get_bit_depth_from_seq(seq) -
> 8;
> +    info->enable_filter_intra        = seq->enable_filter_intra;
> +    info->enable_intra_edge_filter   = seq->enable_intra_edge_filter;
> +    info->enable_interintra_compound =
> seq->enable_interintra_compound;
> +    info->enable_masked_compound     = seq->enable_masked_compound;
> +    info->enable_dual_filter         = seq->enable_dual_filter;
> +    info->enable_order_hint          = seq->enable_order_hint;
> +    info->order_hint_bits_minus1     = seq->order_hint_bits_minus_1;
> +    info->enable_jnt_comp            = seq->enable_jnt_comp;
> +    info->enable_superres            = seq->enable_superres;
> +    info->enable_cdef                = seq->enable_cdef;
> +    info->enable_restoration         = seq->enable_restoration;
> +    info->enable_fgs                 =
> seq->film_grain_params_present; +
> +    /* Frame Header */
> +    info->frame_type                   = frame_header->frame_type;
> +    info->show_frame                   = frame_header->show_frame;
> +    info->disable_cdf_update           =
> frame_header->disable_cdf_update;
> +    info->allow_screen_content_tools   =
> frame_header->allow_screen_content_tools;
> +    info->force_integer_mv             =
> frame_header->force_integer_mv ||
> +                                    frame_header->frame_type ==
> AV1_FRAME_INTRA_ONLY ||
> +                                    frame_header->frame_type ==
> AV1_FRAME_KEY;
> +    info->coded_denom                  = frame_header->coded_denom;
> +    info->allow_intrabc                = frame_header->allow_intrabc;
> +    info->allow_high_precision_mv      =
> frame_header->allow_high_precision_mv;
> +    info->interp_filter                =
> frame_header->interpolation_filter;
> +    info->switchable_motion_mode       =
> frame_header->is_motion_mode_switchable;
> +    info->use_ref_frame_mvs            =
> frame_header->use_ref_frame_mvs;
> +    info->disable_frame_end_update_cdf =
> frame_header->disable_frame_end_update_cdf;
> +    info->delta_q_present              =
> frame_header->delta_q_present;
> +    info->delta_q_res                  = frame_header->delta_q_res;
> +    info->using_qmatrix                = frame_header->using_qmatrix;
> +    info->coded_lossless               = s->cur_frame.coded_lossless;
> +    info->use_superres                 = frame_header->use_superres;
> +    info->tx_mode                      = frame_header->tx_mode;
> +    info->reference_mode               =
> frame_header->reference_select;
> +    info->allow_warped_motion          =
> frame_header->allow_warped_motion;
> +    info->reduced_tx_set               =
> frame_header->reduced_tx_set;
> +    info->skip_mode                    =
> frame_header->skip_mode_present; +
> +    /* Tiling Info */
> +    info->num_tile_cols          = frame_header->tile_cols;
> +    info->num_tile_rows          = frame_header->tile_rows;
> +    info->context_update_tile_id =
> frame_header->context_update_tile_id; +
> +    /* CDEF */
> +    info->cdef_damping_minus_3 = frame_header->cdef_damping_minus_3;
> +    info->cdef_bits            = frame_header->cdef_bits;
> +
> +    /* SkipModeFrames */
> +    info->SkipModeFrame0 = frame_header->skip_mode_present ?
> +                      s->cur_frame.skip_mode_frame_idx[0] : 0;
> +    info->SkipModeFrame1 = frame_header->skip_mode_present ?
> +                      s->cur_frame.skip_mode_frame_idx[1] : 0;
> +
> +    /* QP Information */
> +    info->base_qindex     = frame_header->base_q_idx;
> +    info->qp_y_dc_delta_q = frame_header->delta_q_y_dc;
> +    info->qp_u_dc_delta_q = frame_header->delta_q_u_dc;
> +    info->qp_v_dc_delta_q = frame_header->delta_q_v_dc;
> +    info->qp_u_ac_delta_q = frame_header->delta_q_u_ac;
> +    info->qp_v_ac_delta_q = frame_header->delta_q_v_ac;
> +    info->qm_y            = frame_header->qm_y;
> +    info->qm_u            = frame_header->qm_u;
> +    info->qm_v            = frame_header->qm_v;
> +
> +    /* Segmentation */
> +    info->segmentation_enabled         =
> frame_header->segmentation_enabled;
> +    info->segmentation_update_map      =
> frame_header->segmentation_update_map;
> +    info->segmentation_update_data     =
> frame_header->segmentation_update_data;
> +    info->segmentation_temporal_update =
> frame_header->segmentation_temporal_update; +
> +    /* Loopfilter */
> +    info->loop_filter_level[0]       =
> frame_header->loop_filter_level[0];
> +    info->loop_filter_level[1]       =
> frame_header->loop_filter_level[1];
> +    info->loop_filter_level_u        =
> frame_header->loop_filter_level[2];
> +    info->loop_filter_level_v        =
> frame_header->loop_filter_level[3];
> +    info->loop_filter_sharpness      =
> frame_header->loop_filter_sharpness;
> +    info->loop_filter_delta_enabled  =
> frame_header->loop_filter_delta_enabled;
> +    info->loop_filter_delta_update   =
> frame_header->loop_filter_delta_update;
> +    info->loop_filter_mode_deltas[0] =
> frame_header->loop_filter_mode_deltas[0];
> +    info->loop_filter_mode_deltas[1] =
> frame_header->loop_filter_mode_deltas[1];
> +    info->delta_lf_present           =
> frame_header->delta_lf_present;
> +    info->delta_lf_res               = frame_header->delta_lf_res;
> +    info->delta_lf_multi             = frame_header->delta_lf_multi;
> +
> +    /* Restoration */
> +    info->lr_type[0]      = remap_lr_type[frame_header->lr_type[0]];
> +    info->lr_type[1]      = remap_lr_type[frame_header->lr_type[1]];
> +    info->lr_type[2]      = remap_lr_type[frame_header->lr_type[2]];
> +    info->lr_unit_size[0] = 1 + frame_header->lr_unit_shift;
> +    info->lr_unit_size[1] = 1 + frame_header->lr_unit_shift -
> frame_header->lr_uv_shift;
> +    info->lr_unit_size[2] = 1 + frame_header->lr_unit_shift -
> frame_header->lr_uv_shift; +
> +    /* Reference Frames */
> +    info->temporal_layer_id = s->cur_frame.temporal_id;
> +    info->spatial_layer_id  = s->cur_frame.spatial_id;
> +
> +    /* Film Grain Params */
> +    info->apply_grain              = film_grain->apply_grain;
> +    info->overlap_flag             = film_grain->overlap_flag;
> +    info->scaling_shift_minus8     =
> film_grain->grain_scaling_minus_8;
> +    info->chroma_scaling_from_luma =
> film_grain->chroma_scaling_from_luma;
> +    info->ar_coeff_lag             = film_grain->ar_coeff_lag;
> +    info->ar_coeff_shift_minus6    =
> film_grain->ar_coeff_shift_minus_6;
> +    info->grain_scale_shift        = film_grain->grain_scale_shift;
> +    info->clip_to_restricted_range =
> film_grain->clip_to_restricted_range;
> +    info->num_y_points             = film_grain->num_y_points;
> +    info->num_cb_points            = film_grain->num_cb_points;
> +    info->num_cr_points            = film_grain->num_cr_points;
> +    info->random_seed              = film_grain->grain_seed;
> +    info->cb_mult                  = film_grain->cb_mult;
> +    info->cb_luma_mult             = film_grain->cb_luma_mult;
> +    info->cb_offset                = film_grain->cb_offset;
> +    info->cr_mult                  = film_grain->cr_mult;
> +    info->cr_luma_mult             = film_grain->cr_luma_mult;
> +    info->cr_offset                = film_grain->cr_offset;
> +
> +    /* Tiling Info */
> +    for (i = 0; i < frame_header->tile_cols; ++i) {
> +        info->tile_widths[i] = frame_header->width_in_sbs_minus_1[i]
> + 1;
> +    }
> +    for (i = 0; i < frame_header->tile_rows; ++i) {
> +        info->tile_heights[i] =
> frame_header->height_in_sbs_minus_1[i] + 1;
> +    }
> +
> +    /* CDEF */
> +    for (i = 0; i < (1 << frame_header->cdef_bits); ++i) {
> +        info->cdef_y_strength[i] =
> (frame_header->cdef_y_pri_strength[i] & 0x0F) |
> (frame_header->cdef_y_sec_strength[i] << 4);
> +        info->cdef_uv_strength[i] =
> (frame_header->cdef_uv_pri_strength[i] & 0x0F) |
> (frame_header->cdef_uv_sec_strength[i] << 4);
> +    }
> +
> +
> +    /* Segmentation */
> +    for (i = 0; i < AV1_MAX_SEGMENTS; ++i) {
> +        info->segmentation_feature_mask[i] = 0;
> +        for (j = 0; j < AV1_SEG_LVL_MAX; ++j) {
> +            info->segmentation_feature_mask[i] |=
> frame_header->feature_enabled[i][j] << j;
> +            info->segmentation_feature_data[i][j] =
> frame_header->feature_value[i][j];
> +        }
> +    }
> +
> +    for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) {
> +        /* Loopfilter */
> +        info->loop_filter_ref_deltas[i] =
> frame_header->loop_filter_ref_deltas[i]; +
> +        /* Reference Frames */
> +        info->ref_frame_map[i] =
> ff_vdpau_get_surface_id(s->ref[i].tf.f) ?
> ff_vdpau_get_surface_id(s->ref[i].tf.f) : VDP_INVALID_HANDLE;

These usages of tf.f do not compile. I replaced them with .f and it
does compile, but then when I tested in mpv (doesn't require any code
changes, just run against the patched ffmpeg), there are visual
glitches and something is clearly wrong. Doesn't matter whether I use
the GL interop or copy-back. This is with 510.68.02 drivers.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support
  2022-05-17  4:46 ` Philip Langdale
@ 2022-05-17 12:07   ` Manoj Bonda
       [not found]     ` <DM4PR12MB51026463462272DF753EDFAAA3D09@DM4PR12MB5102.namprd12.prod.outlook.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Manoj Bonda @ 2022-05-17 12:07 UTC (permalink / raw)
  To: Philip Langdale, FFmpeg development discussions and patches
  Cc: vdpau, ManojGuptaBonda, Andy Ritger, Aaron Plattner

[-- Attachment #1: Type: text/plain, Size: 15055 bytes --]

Hi Philip, 

I am currently relying on using ffmpeg with nvcuvid to cross verify my vdpau patch 
I see the clips with me are matching in output for both VDPAU and NVCUVID/NVDEC.
Attached are the script I used to verify and its output.

Was unable to use AV1 VDPAU with MPV hence not able to repro the issue you are seeing. 
looking into it once resolved will check and resend the patch. Please bear with me.

Thanks,
ManojGupta.

> -----Original Message-----
> From: Philip Langdale <philipl@overt.org>
> Sent: Tuesday, May 17, 2022 10:17 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Cc: ManojGuptaBonda <mbonda-at-nvidia.com@ffmpeg.org>;
> vdpau@lists.freedesktop.org; Aaron Plattner <aplattner@nvidia.com>;
> Manoj Bonda <mbonda@nvidia.com>; Andy Ritger <ARitger@nvidia.com>
> Subject: Re: [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support
> 
> External email: Use caution opening links or attachments
> 
> 
> On Mon, 16 May 2022 18:45:58 +0530
> ManojGuptaBonda <mbonda-at-nvidia.com@ffmpeg.org> wrote:
> 
> > Support for VDPAU accelerated AV1 decoding was added with
> > libvdpau-1.5. Support for the same in ffmpeg is added with this patch.
> > Profiles related to VDPAU AV1 can be found in latest vdpau.h present
> > in libvdpau-1.5.
> >
> > Add AV1 VDPAU to list of hwaccels and supported formats Added file
> > vdpau_av1.c and Modified configure to add VDPAU AV1 support. Mapped
> > AV1 profiles to VDPAU AV1 profiles. Populated the codec specific
> > params that need to be passed to VDPAU.
> > ---
> >  Changelog                   |   1 +
> >  configure                   |   3 +
> >  libavcodec/Makefile         |   1 +
> >  libavcodec/av1dec.c         |  13 +-
> >  libavcodec/hwaccels.h       |   1 +
> >  libavcodec/vdpau_av1.c      | 370
> > ++++++++++++++++++++++++++++++++++++
> libavcodec/vdpau_internal.h |
> > 3 + libavcodec/version.h        |   2 +-
> >  8 files changed, 392 insertions(+), 2 deletions(-)  create mode
> > 100644 libavcodec/vdpau_av1.c
> >
> 
> <Snip>
> 
> > diff --git a/libavcodec/vdpau_av1.c b/libavcodec/vdpau_av1.c new file
> > mode 100644 index 0000000000..95c1e58cf7
> > --- /dev/null
> > +++ b/libavcodec/vdpau_av1.c
> > @@ -0,0 +1,370 @@
> > +/*
> > + * AV1 HW decode acceleration through VDPAU
> > + *
> > + * Copyright (c) 2022 Manoj Gupta Bonda
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> GNU
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU Lesser General Public
> > + * License along with FFmpeg; if not, write to the Free Software
> > Foundation,
> > + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> > + */
> > +
> > +#include <vdpau/vdpau.h>
> > +#include "libavutil/pixdesc.h"
> > +#include "avcodec.h"
> > +#include "internal.h"
> > +#include "av1dec.h"
> > +#include "hwconfig.h"
> > +#include "vdpau.h"
> > +#include "vdpau_internal.h"
> > +
> > +static int get_bit_depth_from_seq(const AV1RawSequenceHeader *seq)
> {
> > +    if (seq->seq_profile == 2 && seq->color_config.high_bitdepth) {
> > +        return seq->color_config.twelve_bit ? 12 : 10;
> > +    } else if (seq->seq_profile <= 2 &&
> > seq->color_config.high_bitdepth) {
> > +        return 10;
> > +    } else {
> > +        return 8;
> > +    }
> > +}
> > +
> > +static int vdpau_av1_start_frame(AVCodecContext *avctx,
> > +                                  const uint8_t *buffer, uint32_t
> > size) +{
> > +    AV1DecContext *s = avctx->priv_data;
> > +    const AV1RawSequenceHeader *seq = s->raw_seq;
> > +    const AV1RawFrameHeader *frame_header = s->raw_frame_header;
> > +    const AV1RawFilmGrainParams *film_grain =
> > &s->cur_frame.film_grain; +
> > +    struct vdpau_picture_context *pic_ctx =
> > s->cur_frame.hwaccel_picture_private;
> > +    int i,j;
> > +
> > +    unsigned char remap_lr_type[4] = { AV1_RESTORE_NONE,
> > AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER,
> AV1_RESTORE_SGRPROJ }; +
> > +
> > +    VdpPictureInfoAV1 *info = &pic_ctx->info.av1;
> > +    const AVPixFmtDescriptor *pixdesc =
> > av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > +    if (!pixdesc) {
> > +        return AV_PIX_FMT_NONE;
> > +    }
> > +
> > +    info->width = avctx->width;
> > +    info->height = avctx->height;
> > +
> > +
> > +    info->frame_offset = frame_header->order_hint;
> > +
> > +    /* Sequence Header */
> > +    info->profile                    = seq->seq_profile;
> > +    info->use_128x128_superblock     = seq->use_128x128_superblock;
> > +    info->subsampling_x              =
> > seq->color_config.subsampling_x;
> > +    info->subsampling_y              =
> > seq->color_config.subsampling_y;
> > +    info->mono_chrome                = seq->color_config.mono_chrome;
> > +    info->bit_depth_minus8           = get_bit_depth_from_seq(seq) -
> > 8;
> > +    info->enable_filter_intra        = seq->enable_filter_intra;
> > +    info->enable_intra_edge_filter   = seq->enable_intra_edge_filter;
> > +    info->enable_interintra_compound =
> > seq->enable_interintra_compound;
> > +    info->enable_masked_compound     = seq-
> >enable_masked_compound;
> > +    info->enable_dual_filter         = seq->enable_dual_filter;
> > +    info->enable_order_hint          = seq->enable_order_hint;
> > +    info->order_hint_bits_minus1     = seq->order_hint_bits_minus_1;
> > +    info->enable_jnt_comp            = seq->enable_jnt_comp;
> > +    info->enable_superres            = seq->enable_superres;
> > +    info->enable_cdef                = seq->enable_cdef;
> > +    info->enable_restoration         = seq->enable_restoration;
> > +    info->enable_fgs                 =
> > seq->film_grain_params_present; +
> > +    /* Frame Header */
> > +    info->frame_type                   = frame_header->frame_type;
> > +    info->show_frame                   = frame_header->show_frame;
> > +    info->disable_cdf_update           =
> > frame_header->disable_cdf_update;
> > +    info->allow_screen_content_tools   =
> > frame_header->allow_screen_content_tools;
> > +    info->force_integer_mv             =
> > frame_header->force_integer_mv ||
> > +                                    frame_header->frame_type ==
> > AV1_FRAME_INTRA_ONLY ||
> > +                                    frame_header->frame_type ==
> > AV1_FRAME_KEY;
> > +    info->coded_denom                  = frame_header->coded_denom;
> > +    info->allow_intrabc                = frame_header->allow_intrabc;
> > +    info->allow_high_precision_mv      =
> > frame_header->allow_high_precision_mv;
> > +    info->interp_filter                =
> > frame_header->interpolation_filter;
> > +    info->switchable_motion_mode       =
> > frame_header->is_motion_mode_switchable;
> > +    info->use_ref_frame_mvs            =
> > frame_header->use_ref_frame_mvs;
> > +    info->disable_frame_end_update_cdf =
> > frame_header->disable_frame_end_update_cdf;
> > +    info->delta_q_present              =
> > frame_header->delta_q_present;
> > +    info->delta_q_res                  = frame_header->delta_q_res;
> > +    info->using_qmatrix                = frame_header->using_qmatrix;
> > +    info->coded_lossless               = s->cur_frame.coded_lossless;
> > +    info->use_superres                 = frame_header->use_superres;
> > +    info->tx_mode                      = frame_header->tx_mode;
> > +    info->reference_mode               =
> > frame_header->reference_select;
> > +    info->allow_warped_motion          =
> > frame_header->allow_warped_motion;
> > +    info->reduced_tx_set               =
> > frame_header->reduced_tx_set;
> > +    info->skip_mode                    =
> > frame_header->skip_mode_present; +
> > +    /* Tiling Info */
> > +    info->num_tile_cols          = frame_header->tile_cols;
> > +    info->num_tile_rows          = frame_header->tile_rows;
> > +    info->context_update_tile_id =
> > frame_header->context_update_tile_id; +
> > +    /* CDEF */
> > +    info->cdef_damping_minus_3 = frame_header-
> >cdef_damping_minus_3;
> > +    info->cdef_bits            = frame_header->cdef_bits;
> > +
> > +    /* SkipModeFrames */
> > +    info->SkipModeFrame0 = frame_header->skip_mode_present ?
> > +                      s->cur_frame.skip_mode_frame_idx[0] : 0;
> > +    info->SkipModeFrame1 = frame_header->skip_mode_present ?
> > +                      s->cur_frame.skip_mode_frame_idx[1] : 0;
> > +
> > +    /* QP Information */
> > +    info->base_qindex     = frame_header->base_q_idx;
> > +    info->qp_y_dc_delta_q = frame_header->delta_q_y_dc;
> > +    info->qp_u_dc_delta_q = frame_header->delta_q_u_dc;
> > +    info->qp_v_dc_delta_q = frame_header->delta_q_v_dc;
> > +    info->qp_u_ac_delta_q = frame_header->delta_q_u_ac;
> > +    info->qp_v_ac_delta_q = frame_header->delta_q_v_ac;
> > +    info->qm_y            = frame_header->qm_y;
> > +    info->qm_u            = frame_header->qm_u;
> > +    info->qm_v            = frame_header->qm_v;
> > +
> > +    /* Segmentation */
> > +    info->segmentation_enabled         =
> > frame_header->segmentation_enabled;
> > +    info->segmentation_update_map      =
> > frame_header->segmentation_update_map;
> > +    info->segmentation_update_data     =
> > frame_header->segmentation_update_data;
> > +    info->segmentation_temporal_update =
> > frame_header->segmentation_temporal_update; +
> > +    /* Loopfilter */
> > +    info->loop_filter_level[0]       =
> > frame_header->loop_filter_level[0];
> > +    info->loop_filter_level[1]       =
> > frame_header->loop_filter_level[1];
> > +    info->loop_filter_level_u        =
> > frame_header->loop_filter_level[2];
> > +    info->loop_filter_level_v        =
> > frame_header->loop_filter_level[3];
> > +    info->loop_filter_sharpness      =
> > frame_header->loop_filter_sharpness;
> > +    info->loop_filter_delta_enabled  =
> > frame_header->loop_filter_delta_enabled;
> > +    info->loop_filter_delta_update   =
> > frame_header->loop_filter_delta_update;
> > +    info->loop_filter_mode_deltas[0] =
> > frame_header->loop_filter_mode_deltas[0];
> > +    info->loop_filter_mode_deltas[1] =
> > frame_header->loop_filter_mode_deltas[1];
> > +    info->delta_lf_present           =
> > frame_header->delta_lf_present;
> > +    info->delta_lf_res               = frame_header->delta_lf_res;
> > +    info->delta_lf_multi             = frame_header->delta_lf_multi;
> > +
> > +    /* Restoration */
> > +    info->lr_type[0]      = remap_lr_type[frame_header->lr_type[0]];
> > +    info->lr_type[1]      = remap_lr_type[frame_header->lr_type[1]];
> > +    info->lr_type[2]      = remap_lr_type[frame_header->lr_type[2]];
> > +    info->lr_unit_size[0] = 1 + frame_header->lr_unit_shift;
> > +    info->lr_unit_size[1] = 1 + frame_header->lr_unit_shift -
> > frame_header->lr_uv_shift;
> > +    info->lr_unit_size[2] = 1 + frame_header->lr_unit_shift -
> > frame_header->lr_uv_shift; +
> > +    /* Reference Frames */
> > +    info->temporal_layer_id = s->cur_frame.temporal_id;
> > +    info->spatial_layer_id  = s->cur_frame.spatial_id;
> > +
> > +    /* Film Grain Params */
> > +    info->apply_grain              = film_grain->apply_grain;
> > +    info->overlap_flag             = film_grain->overlap_flag;
> > +    info->scaling_shift_minus8     =
> > film_grain->grain_scaling_minus_8;
> > +    info->chroma_scaling_from_luma =
> > film_grain->chroma_scaling_from_luma;
> > +    info->ar_coeff_lag             = film_grain->ar_coeff_lag;
> > +    info->ar_coeff_shift_minus6    =
> > film_grain->ar_coeff_shift_minus_6;
> > +    info->grain_scale_shift        = film_grain->grain_scale_shift;
> > +    info->clip_to_restricted_range =
> > film_grain->clip_to_restricted_range;
> > +    info->num_y_points             = film_grain->num_y_points;
> > +    info->num_cb_points            = film_grain->num_cb_points;
> > +    info->num_cr_points            = film_grain->num_cr_points;
> > +    info->random_seed              = film_grain->grain_seed;
> > +    info->cb_mult                  = film_grain->cb_mult;
> > +    info->cb_luma_mult             = film_grain->cb_luma_mult;
> > +    info->cb_offset                = film_grain->cb_offset;
> > +    info->cr_mult                  = film_grain->cr_mult;
> > +    info->cr_luma_mult             = film_grain->cr_luma_mult;
> > +    info->cr_offset                = film_grain->cr_offset;
> > +
> > +    /* Tiling Info */
> > +    for (i = 0; i < frame_header->tile_cols; ++i) {
> > +        info->tile_widths[i] = frame_header->width_in_sbs_minus_1[i]
> > + 1;
> > +    }
> > +    for (i = 0; i < frame_header->tile_rows; ++i) {
> > +        info->tile_heights[i] =
> > frame_header->height_in_sbs_minus_1[i] + 1;
> > +    }
> > +
> > +    /* CDEF */
> > +    for (i = 0; i < (1 << frame_header->cdef_bits); ++i) {
> > +        info->cdef_y_strength[i] =
> > (frame_header->cdef_y_pri_strength[i] & 0x0F) |
> > (frame_header->cdef_y_sec_strength[i] << 4);
> > +        info->cdef_uv_strength[i] =
> > (frame_header->cdef_uv_pri_strength[i] & 0x0F) |
> > (frame_header->cdef_uv_sec_strength[i] << 4);
> > +    }
> > +
> > +
> > +    /* Segmentation */
> > +    for (i = 0; i < AV1_MAX_SEGMENTS; ++i) {
> > +        info->segmentation_feature_mask[i] = 0;
> > +        for (j = 0; j < AV1_SEG_LVL_MAX; ++j) {
> > +            info->segmentation_feature_mask[i] |=
> > frame_header->feature_enabled[i][j] << j;
> > +            info->segmentation_feature_data[i][j] =
> > frame_header->feature_value[i][j];
> > +        }
> > +    }
> > +
> > +    for (i = 0; i < AV1_NUM_REF_FRAMES; ++i) {
> > +        /* Loopfilter */
> > +        info->loop_filter_ref_deltas[i] =
> > frame_header->loop_filter_ref_deltas[i]; +
> > +        /* Reference Frames */
> > +        info->ref_frame_map[i] =
> > ff_vdpau_get_surface_id(s->ref[i].tf.f) ?
> > ff_vdpau_get_surface_id(s->ref[i].tf.f) : VDP_INVALID_HANDLE;
> 
> These usages of tf.f do not compile. I replaced them with .f and it does
> compile, but then when I tested in mpv (doesn't require any code changes,
> just run against the patched ffmpeg), there are visual glitches and something
> is clearly wrong. Doesn't matter whether I use the GL interop or copy-back.
> This is with 510.68.02 drivers.
> 
> --phil

[-- Attachment #2: AV1_Test_Compare.sh --]
[-- Type: application/octet-stream, Size: 14888 bytes --]

[-- Attachment #3: Output_AV1_VDPAU.txt --]
[-- Type: text/plain, Size: 2225 bytes --]

Test av1_stream_00000
Test av1_stream_00001
Test av1_stream_00002
Test av1_stream_00003
Test av1_stream_00004
Test av1_stream_00005
Test av1_stream_00007
Test av1_stream_00008
Test av1_stream_00009
Test av1_stream_00010
Test av1_stream_00011
Test av1_stream_00012
Test av1_stream_00014
Test av1_stream_00015
Test av1_stream_00016
Test av1_stream_00022
Test av1_stream_00028
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
Test av1_stream_00023
Test av1_stream_00030
Test av1_stream_00324
Test av1_stream_00325
Test av1_stream_00326
Test av1_stream_00327
Test av1_stream_00328
Test av1_stream_00329
Test av1_stream_00330
Test av1_stream_00331
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
target surface doesn't match Frame size
Test av1_stream_00410
Test av1_stream_00411
Test av1_stream_00447
Test av1_stream_00448
Test av1_stream_00449
Test av1_stream_00450.ivf
Test av1_stream_00451
Test Chimera-AV1-10bit-1280x720-2380kbps
Test Chimera-AV1-8bit-1280x720-3363kbps.ivf
Test av1_test_mul_tile_groups_tiles.av1
Test av1_test_mul_tiles.av1

[-- Attachment #4: Type: text/plain, Size: 251 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support
       [not found]       ` <20220519095432.7b07e873@fido7>
@ 2022-06-21  2:45         ` Manoj Bonda
  2022-06-22 10:13           ` Philip Langdale
  0 siblings, 1 reply; 5+ messages in thread
From: Manoj Bonda @ 2022-06-21  2:45 UTC (permalink / raw)
  To: Philip Langdale, FFmpeg development discussions and patches
  Cc: Ashish Roy, Hardy Doelfel, Mandar Godse, Andy Ritger, Aaron Plattner

Hi Philip, 

The issue seems to be from MPV side rather than from ffmpeg patch. 
I was able to decode the clip Halo_AV1 properly bitmatching with nvcuvid output 
with ffmpeg + VDPAU. 

Please find the cmds I used to verify the same. 

./ffmpeg  -hwaccel vdpau  -i /home/bondamanoj/VideoClips/AV1Clips/Halo_AV1.mp4 -y decoded_vdpau.yuv
./ffmpeg  -hwaccel nvdec -i  /home/bondamanoj/VideoClips/AV1Clips/Halo_AV1.mp4   decoded_nvcuvid.yuv
cmp decoded_vdpau.yuv ~/Downloads/ffmpeg-git2/FFmpeg/decoded_nvcuvid.yuv

The same clip is dumped using mpv via cmd 
./mpv  --hwdec=vdpau-copy --o=Halo_dump_av1.yuv  --of=rawvideo /home/bondamanoj/VideoClips/AV1Clips/Halo_AV1.mp4

Is differing and is having corruption while playing. 


Thanks,
ManojGupta.

> -----Original Message-----
> From: Philip Langdale <philipl@overt.org>
> Sent: Thursday, May 19, 2022 10:25 PM
> To: Manoj Bonda <mbonda@nvidia.com>
> Cc: Andy Ritger <ARitger@nvidia.com>; Aaron Plattner
> <aplattner@nvidia.com>; Mandar Godse <mgodse@nvidia.com>; Ashish Roy
> <AROY@nvidia.com>; Hardy Doelfel <hdoelfel@nvidia.com>
> Subject: Re: [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support
> 
> External email: Use caution opening links or attachments
> 
> 
> On Thu, 19 May 2022 09:01:26 +0000
> Manoj Bonda <mbonda@nvidia.com> wrote:
> 
> > Hi Philip,
> >
> > As mentioned earlier I am getting output matching with nvcuvid for
> > VDPAU While using ffmpeg.
> > With MPV I am not seeing issue with below cmd ./mpv --vo=vdpau
> > --hwdec=vdpau
> > /home/bondamanoj/VideoClips/AV1Clips/Chimera-AV1-8bit-1280x720-
> 3363kbp
> > s.ivf
> >
> > I am getting mpv failures with --vo=opengl or --vo=gpu and not
> > decoding the clip. Can you please share us the cmds and the clip used
> > by you where you saw corruption. So I can debug and fix the issue.
> 
> Ok, it seems weird.
> 
> I've been using youtube clips, so here's one from their original AV1 playlist
> (The Halo Infinite announce trailer):
> 
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.
> youtube.com%2Fwatch%3Fv%3DFmdb-
> KmlzD8&amp;data=05%7C01%7Cmbonda%40nvidia.com%7Cf69926f451734
> 86cf2f208da39b8430d%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0
> %7C637885760832069373%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj
> AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%
> 7C%7C&amp;sdata=Kw2mXnUdaupPhwBq13MCCiciZo6alDqTpM6sh88TMtg%
> 3D&amp;reserved=0
> 
> You then need yt-dlp installed.
> 
> If you tell mpv to play the URL directly, it will use yt-dlp to stream it, and it
> appears to play just fine.
> 
> However, if you use yt-dlp to download the stream to either mp4 or mkv, and
> then play that back, the playback is glitched.
> 
> With nvdec, it plays fine either way.
> 
> Minimum Command line:
> 
> mpv --no-config --hwdec=vdpau --gpu-context=x11 <file or url>
> 
> And switch vdpau for nvdec to compare the two.
> 
> Hope that helps,
> 
> --phil
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support
  2022-06-21  2:45         ` Manoj Bonda
@ 2022-06-22 10:13           ` Philip Langdale
  0 siblings, 0 replies; 5+ messages in thread
From: Philip Langdale @ 2022-06-22 10:13 UTC (permalink / raw)
  To: Manoj Bonda
  Cc: Ashish Roy, Hardy Doelfel, Aaron Plattner, Mandar Godse,
	FFmpeg development discussions and patches, Andy Ritger

On Tue, 21 Jun 2022 02:45:21 +0000
Manoj Bonda <mbonda@nvidia.com> wrote:

> Hi Philip, 
> 
> The issue seems to be from MPV side rather than from ffmpeg patch. 
> I was able to decode the clip Halo_AV1 properly bitmatching with
> nvcuvid output with ffmpeg + VDPAU. 
> 
> Please find the cmds I used to verify the same. 
> 
> ./ffmpeg  -hwaccel vdpau  -i
> /home/bondamanoj/VideoClips/AV1Clips/Halo_AV1.mp4 -y
> decoded_vdpau.yuv ./ffmpeg  -hwaccel nvdec -i
> /home/bondamanoj/VideoClips/AV1Clips/Halo_AV1.mp4
> decoded_nvcuvid.yuv cmp decoded_vdpau.yuv
> ~/Downloads/ffmpeg-git2/FFmpeg/decoded_nvcuvid.yuv
> 
> The same clip is dumped using mpv via cmd 
> ./mpv  --hwdec=vdpau-copy --o=Halo_dump_av1.yuv  --of=rawvideo
> /home/bondamanoj/VideoClips/AV1Clips/Halo_AV1.mp4
> 
> Is differing and is having corruption while playing. 
> 
> 
> Thanks,
> ManojGupta.

Hi Manoj,

Ok. In that case, I guess it's reasonable to merge. I'm puzzled as to
the behaviour as other codecs work fine and other hwaccels used by the
same av1 decoder also work fine, so I don't see where there is room for
things to go wrong specifically in mpv specifically for this hwaccel.

Anyway, I'll merge it later this week.

Thanks,

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-22 10:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 13:15 [FFmpeg-devel] [PATCH] AV1 VDPAU hwaccel Decode support ManojGuptaBonda
2022-05-17  4:46 ` Philip Langdale
2022-05-17 12:07   ` Manoj Bonda
     [not found]     ` <DM4PR12MB51026463462272DF753EDFAAA3D09@DM4PR12MB5102.namprd12.prod.outlook.com>
     [not found]       ` <20220519095432.7b07e873@fido7>
2022-06-21  2:45         ` Manoj Bonda
2022-06-22 10:13           ` Philip Langdale

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