diff mbox

[FFmpeg-devel,1/2] Add VP9 VDPAU to list of hwaccels and supported formats

Message ID 20191021102013.30676-2-mbonda@nvidia.com
State Superseded
Headers show

Commit Message

ManojGuptaBonda Oct. 21, 2019, 10:20 a.m. UTC
Added file vdpau_vp9.c for supporting VDPAU VP9 decoding in FFmpeg with
stub functions. Modified configure to add VDPAU VP9 support. Mapped VP9
profiles to VDPAU VP9 profiles.

Support for VDPAU accelerated VP9 decoding was added with libvdpau-1.3
version. Profiles related to VDPAU VP9 can be found in latest vdpau.h
present in libvdpau-1.3
---
 configure                   |  3 ++
 libavcodec/Makefile         |  1 +
 libavcodec/hwaccels.h       |  1 +
 libavcodec/vdpau_internal.h |  3 ++
 libavcodec/vdpau_vp9.c      | 91 +++++++++++++++++++++++++++++++++++++
 libavcodec/vp9.c            |  9 +++-
 6 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vdpau_vp9.c
diff mbox

Patch

diff --git a/configure b/configure
index 8413826f9e..7f63eebc9d 100755
--- a/configure
+++ b/configure
@@ -2979,6 +2979,8 @@  vp9_nvdec_hwaccel_deps="nvdec"
 vp9_nvdec_hwaccel_select="vp9_decoder"
 vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth"
 vp9_vaapi_hwaccel_select="vp9_decoder"
+vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9"
+vp9_vdpau_hwaccel_select="vp9_decoder"
 wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel"
 wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel"
 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
@@ -6093,6 +6095,7 @@  check_type "windows.h d3d11.h" "ID3D11VideoContext"
 check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
 
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
+check_type "vdpau/vdpau.h" "VdpPictureInfoVP9"
 
 if [ -z "$nvccflags" ]; then
     nvccflags=$nvccflags_default
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 37a84a6bb4..34c3a22116 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -913,6 +913,7 @@  OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)        += dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)          += dxva2_vp9.o
 OBJS-$(CONFIG_VP9_NVDEC_HWACCEL)          += nvdec_vp9.o
 OBJS-$(CONFIG_VP9_VAAPI_HWACCEL)          += vaapi_vp9.o
+OBJS-$(CONFIG_VP9_VDPAU_HWACCEL)          += vdpau_vp9.o
 OBJS-$(CONFIG_VP8_QSV_HWACCEL)            += qsvdec_other.o
 
 # libavformat dependencies
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index 7d73da8676..6109c89bd6 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -68,6 +68,7 @@  extern const AVHWAccel ff_vp9_d3d11va2_hwaccel;
 extern const AVHWAccel ff_vp9_dxva2_hwaccel;
 extern const AVHWAccel ff_vp9_nvdec_hwaccel;
 extern const AVHWAccel ff_vp9_vaapi_hwaccel;
+extern const AVHWAccel ff_vp9_vdpau_hwaccel;
 extern const AVHWAccel ff_wmv3_d3d11va_hwaccel;
 extern const AVHWAccel ff_wmv3_d3d11va2_hwaccel;
 extern const AVHWAccel ff_wmv3_dxva2_hwaccel;
diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h
index 1ee38dbc55..b6ea078cb2 100644
--- a/libavcodec/vdpau_internal.h
+++ b/libavcodec/vdpau_internal.h
@@ -54,6 +54,9 @@  union VDPAUPictureInfo {
 #ifdef VDP_YCBCR_FORMAT_Y_U_V_444
     VdpPictureInfoHEVC444     hevc_444;
 #endif
+#ifdef VDP_DECODER_PROFILE_VP9_PROFILE_0
+    VdpPictureInfoVP9        vp9;
+#endif
 };
 
 typedef struct VDPAUHWContext {
diff --git a/libavcodec/vdpau_vp9.c b/libavcodec/vdpau_vp9.c
new file mode 100644
index 0000000000..d8f629d135
--- /dev/null
+++ b/libavcodec/vdpau_vp9.c
@@ -0,0 +1,91 @@ 
+/*
+ * VP9 HW decode acceleration through VDPAU
+ *
+ * Copyright (c) 2019 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 "avcodec.h"
+#include "internal.h"
+#include "vp9data.h"
+#include "vp9dec.h"
+#include "hwaccel.h"
+#include "vdpau.h"
+#include "vdpau_internal.h"
+
+static int vdpau_vp9_start_frame(AVCodecContext *avctx,
+                                  const uint8_t *buffer, uint32_t size)
+{
+    return 0;
+}
+
+static const uint8_t start_code_prefix[3] = { 0x00, 0x00, 0x01 };
+
+static int vdpau_vp9_decode_slice(AVCodecContext *avctx,
+                                   const uint8_t *buffer, uint32_t size)
+{
+    return 0;
+}
+
+static int vdpau_vp9_end_frame(AVCodecContext *avctx)
+{
+    return 0;
+}
+
+static int vdpau_vp9_init(AVCodecContext *avctx)
+{
+    VdpDecoderProfile profile;
+    uint32_t level = avctx->level;
+
+    switch (avctx->profile) {
+    case FF_PROFILE_VP9_0:
+        profile = VDP_DECODER_PROFILE_VP9_PROFILE_0;
+        break;
+    case FF_PROFILE_VP9_1:
+        profile = VDP_DECODER_PROFILE_VP9_PROFILE_1;
+        break;
+    case FF_PROFILE_VP9_2:
+        profile = VDP_DECODER_PROFILE_VP9_PROFILE_2;
+        break;
+    case FF_PROFILE_VP9_3:
+        profile = VDP_DECODER_PROFILE_VP9_PROFILE_3;
+        break;
+    default:
+        return AVERROR(ENOTSUP);
+    }
+
+    return ff_vdpau_common_init(avctx, profile, level);
+}
+
+const AVHWAccel ff_vp9_vdpau_hwaccel = {
+    .name           = "vp9_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_VP9,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_vp9_start_frame,
+    .end_frame      = vdpau_vp9_end_frame,
+    .decode_slice   = vdpau_vp9_decode_slice,
+    .frame_priv_data_size = sizeof(struct vdpau_picture_context),
+    .init           = vdpau_vp9_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/vp9.c b/libavcodec/vp9.c
index f16462b1e9..e6edab524e 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -173,7 +173,8 @@  static int update_size(AVCodecContext *avctx, int w, int h)
 #define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \
                      CONFIG_VP9_D3D11VA_HWACCEL * 2 + \
                      CONFIG_VP9_NVDEC_HWACCEL + \
-                     CONFIG_VP9_VAAPI_HWACCEL)
+                     CONFIG_VP9_VAAPI_HWACCEL + \
+                     CONFIG_VP9_VDPAU_HWACCEL)
     enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
     VP9Context *s = avctx->priv_data;
     uint8_t *p;
@@ -201,6 +202,9 @@  static int update_size(AVCodecContext *avctx, int w, int h)
 #endif
 #if CONFIG_VP9_VAAPI_HWACCEL
             *fmtp++ = AV_PIX_FMT_VAAPI;
+#endif
+#if CONFIG_VP9_VDPAU_HWACCEL
+            *fmtp++ = AV_PIX_FMT_VDPAU;
 #endif
             break;
         case AV_PIX_FMT_YUV420P12:
@@ -1816,6 +1820,9 @@  AVCodec ff_vp9_decoder = {
 #endif
 #if CONFIG_VP9_VAAPI_HWACCEL
                                HWACCEL_VAAPI(vp9),
+#endif
+#if CONFIG_VP9_VDPAU_HWACCEL
+                               HWACCEL_VDPAU(vp9),
 #endif
                                NULL
                            },