]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/nvdec: Implement vp8 hwaccel
authorPhilip Langdale <philipl@overt.org>
Sun, 19 Nov 2017 16:42:39 +0000 (08:42 -0800)
committerPhilip Langdale <philipl@overt.org>
Sun, 26 Nov 2017 22:55:01 +0000 (14:55 -0800)
Changelog
configure
libavcodec/Makefile
libavcodec/hwaccels.h
libavcodec/nvdec.c
libavcodec/nvdec_vp8.c [new file with mode: 0644]
libavcodec/version.h
libavcodec/vp8.c

index e3092e211f4e2c62bfc7b0f258b00ecc8bfe419f..afead72f14c37f86e70f5793ce1a19beff21c1e0 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -13,7 +13,7 @@ version <next>:
 - PCE support for extended channel layouts in the AAC encoder
 - native aptX encoder and decoder
 - Raw aptX muxer and demuxer
-- NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1 and VP9 hwaccel decoding
+- NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8/9 hwaccel decoding
 - Intel QSV-accelerated overlay filter
 - mcompand audio filter
 - acontrast audio filter
index fbff66669c9ed6ef5824422dd6feedf076e4c94f..6748ef8bc9af2acdb1470fb297c7b6de9d4a11fc 100755 (executable)
--- a/configure
+++ b/configure
@@ -2746,6 +2746,8 @@ vc1_vaapi_hwaccel_deps="vaapi"
 vc1_vaapi_hwaccel_select="vc1_decoder"
 vc1_vdpau_hwaccel_deps="vdpau"
 vc1_vdpau_hwaccel_select="vc1_decoder"
+vp8_nvdec_hwaccel_deps="nvdec"
+vp8_nvdec_hwaccel_select="vp8_decoder"
 vp8_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferVP8"
 vp8_vaapi_hwaccel_select="vp8_decoder"
 vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
index 0ebd2820ebfee2ad266a9b07ae41ff464221acee..a6203d424b7401ffccff0a14784680090ef321b6 100644 (file)
@@ -871,6 +871,7 @@ OBJS-$(CONFIG_VC1_NVDEC_HWACCEL)          += nvdec_vc1.o
 OBJS-$(CONFIG_VC1_QSV_HWACCEL)            += qsvdec_other.o
 OBJS-$(CONFIG_VC1_VAAPI_HWACCEL)          += vaapi_vc1.o
 OBJS-$(CONFIG_VC1_VDPAU_HWACCEL)          += vdpau_vc1.o
+OBJS-$(CONFIG_VP8_NVDEC_HWACCEL)          += nvdec_vp8.o
 OBJS-$(CONFIG_VP8_VAAPI_HWACCEL)          += vaapi_vp8.o
 OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL)        += dxva2_vp9.o
 OBJS-$(CONFIG_VP9_DXVA2_HWACCEL)          += dxva2_vp9.o
index afe728934191b848dbbd7e8381cc4efb29b1ea9a..fcfe4e088ec7b54c9b12201cf3300477a2a27245 100644 (file)
@@ -59,6 +59,7 @@ extern const AVHWAccel ff_vc1_dxva2_hwaccel;
 extern const AVHWAccel ff_vc1_nvdec_hwaccel;
 extern const AVHWAccel ff_vc1_vaapi_hwaccel;
 extern const AVHWAccel ff_vc1_vdpau_hwaccel;
+extern const AVHWAccel ff_vp8_nvdec_hwaccel;
 extern const AVHWAccel ff_vp8_vaapi_hwaccel;
 extern const AVHWAccel ff_vp9_d3d11va_hwaccel;
 extern const AVHWAccel ff_vp9_d3d11va2_hwaccel;
index da4451a739dc43762d639015dd8f6c885b9428af..c7a02ff40f61685cfcdfead0f66578df0db022fa 100644 (file)
@@ -58,6 +58,7 @@ static int map_avcodec_id(enum AVCodecID id)
     case AV_CODEC_ID_MPEG2VIDEO: return cudaVideoCodec_MPEG2;
     case AV_CODEC_ID_MPEG4:      return cudaVideoCodec_MPEG4;
     case AV_CODEC_ID_VC1:        return cudaVideoCodec_VC1;
+    case AV_CODEC_ID_VP8:        return cudaVideoCodec_VP8;
     case AV_CODEC_ID_VP9:        return cudaVideoCodec_VP9;
     case AV_CODEC_ID_WMV3:       return cudaVideoCodec_VC1;
     }
diff --git a/libavcodec/nvdec_vp8.c b/libavcodec/nvdec_vp8.c
new file mode 100644 (file)
index 0000000..ceb3de2
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * VP8 HW decode acceleration through NVDEC
+ *
+ * Copyright (c) 2017 Philip Langdale
+ *
+ * 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 "avcodec.h"
+#include "nvdec.h"
+#include "decode.h"
+#include "internal.h"
+#include "vp8.h"
+
+static unsigned char safe_get_ref_idx(VP8Frame *frame)
+{
+    return frame ? ff_nvdec_get_ref_idx(frame->tf.f) : 255;
+}
+
+static int nvdec_vp8_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
+{
+    VP8Context *h = avctx->priv_data;
+
+    NVDECContext      *ctx = avctx->internal->hwaccel_priv_data;
+    CUVIDPICPARAMS     *pp = &ctx->pic_params;
+    FrameDecodeData *fdd;
+    NVDECFrame *cf;
+    AVFrame *cur_frame = h->framep[VP56_FRAME_CURRENT]->tf.f;
+
+    int ret;
+
+    ret = ff_nvdec_start_frame(avctx, cur_frame);
+    if (ret < 0)
+        return ret;
+
+    fdd = (FrameDecodeData*)cur_frame->private_ref->data;
+    cf  = (NVDECFrame*)fdd->hwaccel_priv;
+
+    *pp = (CUVIDPICPARAMS) {
+        .PicWidthInMbs     = (cur_frame->width  + 15) / 16,
+        .FrameHeightInMbs  = (cur_frame->height + 15) / 16,
+        .CurrPicIdx        = cf->idx,
+
+        .CodecSpecific.vp8 = {
+            .width                       = cur_frame->width,
+            .height                      = cur_frame->height,
+
+            .first_partition_size        = h->header_partition_size,
+
+            .LastRefIdx                  = safe_get_ref_idx(h->framep[VP56_FRAME_PREVIOUS]),
+            .GoldenRefIdx                = safe_get_ref_idx(h->framep[VP56_FRAME_GOLDEN]),
+            .AltRefIdx                   = safe_get_ref_idx(h->framep[VP56_FRAME_GOLDEN2]),
+
+            .frame_type                  = !h->keyframe,
+            .version                     = h->profile,
+            .show_frame                  = !h->invisible,
+            .update_mb_segmentation_data = h->segmentation.enabled ? h->segmentation.update_feature_data : 0,
+       }
+    };
+
+    return 0;
+}
+
+static int nvdec_vp8_frame_params(AVCodecContext *avctx,
+                                  AVBufferRef *hw_frames_ctx)
+{
+    // VP8 uses a fixed size pool of 3 possible reference frames
+    return ff_nvdec_frame_params(avctx, hw_frames_ctx, 3);
+}
+
+AVHWAccel ff_vp8_nvdec_hwaccel = {
+    .name                 = "vp8_nvdec",
+    .type                 = AVMEDIA_TYPE_VIDEO,
+    .id                   = AV_CODEC_ID_VP8,
+    .pix_fmt              = AV_PIX_FMT_CUDA,
+    .start_frame          = nvdec_vp8_start_frame,
+    .end_frame            = ff_nvdec_simple_end_frame,
+    .decode_slice         = ff_nvdec_simple_decode_slice,
+    .frame_params         = nvdec_vp8_frame_params,
+    .init                 = ff_nvdec_decode_init,
+    .uninit               = ff_nvdec_decode_uninit,
+    .priv_data_size       = sizeof(NVDECContext),
+};
index ba46721fb588014a55ace855ec1f146e6fa0467d..55bb5c5e01f6f998ffa46f364c20a886304fc1ac 100644 (file)
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR   6
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
index 2b1cd155e24d0751793831cd3802cbcd7f47a25f..471c0bb89e244dbe80f2926bfae5ce0ceac8a267 100644 (file)
@@ -2601,6 +2601,9 @@ int vp78_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         enum AVPixelFormat pix_fmts[] = {
 #if CONFIG_VP8_VAAPI_HWACCEL
             AV_PIX_FMT_VAAPI,
+#endif
+#if CONFIG_VP8_NVDEC_HWACCEL
+            AV_PIX_FMT_CUDA,
 #endif
             AV_PIX_FMT_YUV420P,
             AV_PIX_FMT_NONE,
@@ -2949,6 +2952,9 @@ AVCodec ff_vp8_decoder = {
     .hw_configs            = (const AVCodecHWConfigInternal*[]) {
 #if CONFIG_VP8_VAAPI_HWACCEL
                                HWACCEL_VAAPI(vp8),
+#endif
+#if CONFIG_VP8_NVDEC_HWACCEL
+                               HWACCEL_NVDEC(vp8),
 #endif
                                NULL
                            },