[FFmpeg-devel,5/5] lavc/qsvdec: Add VP9 decoder support

Submitted by Zhong Li on Jan. 21, 2019, 12:41 p.m.

Details

Message ID 1548074517-6578-6-git-send-email-zhong.li@intel.com
State New
Headers show

Commit Message

Zhong Li Jan. 21, 2019, 12:41 p.m.
VP9 decoder is support on Intel kabyLake+ platforms with MSDK Version 1.19+

Signed-off-by: Zhong Li <zhong.li@intel.com>
---
 Changelog                 |  1 +
 configure                 |  1 +
 libavcodec/allcodecs.c    |  1 +
 libavcodec/qsv.c          |  5 +++++
 libavcodec/qsvdec_other.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 51 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/Changelog b/Changelog
index bf76613..053c551 100644
--- a/Changelog
+++ b/Changelog
@@ -15,6 +15,7 @@  version <next>:
 - hymt decoder
 - anlmdn filter
 - Intel QSV-accelerated MJPEG decoding
+- Intel QSV-accelerated VP9 decoding
 
 
 version 4.1:
diff --git a/configure b/configure
index ac71ecf..d81bbb9 100755
--- a/configure
+++ b/configure
@@ -3021,6 +3021,7 @@  vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
 vp9_cuvid_decoder_deps="cuvid"
 vp9_mediacodec_decoder_deps="mediacodec"
+vp9_qsv_decoder_select="qsvdec"
 vp9_rkmpp_decoder_deps="rkmpp"
 vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
 vp9_vaapi_encoder_select="vaapi_encode"
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 32cca0c..3bccfed 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -773,6 +773,7 @@  extern AVCodec ff_vp8_v4l2m2m_encoder;
 extern AVCodec ff_vp8_vaapi_encoder;
 extern AVCodec ff_vp9_cuvid_decoder;
 extern AVCodec ff_vp9_mediacodec_decoder;
+extern AVCodec ff_vp9_qsv_decoder;
 extern AVCodec ff_vp9_vaapi_encoder;
 
 // The iterate API is not usable with ossfuzz due to the excessive size of binaries created
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 224bc00..dface37 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -60,6 +60,11 @@  int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 #endif
     case AV_CODEC_ID_MJPEG:
         return MFX_CODEC_JPEG;
+#if QSV_VERSION_ATLEAST(1, 19)
+    case AV_CODEC_ID_VP9:
+        return MFX_CODEC_VP9;
+#endif
+
     default:
         break;
     }
diff --git a/libavcodec/qsvdec_other.c b/libavcodec/qsvdec_other.c
index ba490d4..3caf295 100644
--- a/libavcodec/qsvdec_other.c
+++ b/libavcodec/qsvdec_other.c
@@ -1,5 +1,5 @@ 
 /*
- * Intel MediaSDK QSV based MPEG-2, VC-1, VP8 and MJPEG decoders
+ * Intel MediaSDK QSV based MPEG-2, VC-1, VP8, MJPEG and VP9 decoders
  *
  * copyright (c) 2015 Anton Khirnov
  *
@@ -60,8 +60,8 @@  static av_cold int qsv_decode_close(AVCodecContext *avctx)
 {
     QSVOtherContext *s = avctx->priv_data;
 
-#if CONFIG_VP8_QSV_DECODER
-    if (avctx->codec_id == AV_CODEC_ID_VP8)
+#if CONFIG_VP8_QSV_DECODER || CONFIG_VP9_QSV_DECODER
+    if (avctx->codec_id == AV_CODEC_ID_VP8 || avctx->codec_id == AV_CODEC_ID_VP9)
         av_freep(&s->qsv.load_plugins);
 #endif
 
@@ -90,6 +90,17 @@  static av_cold int qsv_decode_init(AVCodecContext *avctx)
     }
 #endif
 
+#if CONFIG_VP9_QSV_DECODER
+    if (avctx->codec_id == AV_CODEC_ID_VP9) {
+        static const char *uid_vp9dec_hw = "a922394d8d87452f878c51f2fc9b4131";
+
+        av_freep(&s->qsv.load_plugins);
+        s->qsv.load_plugins = av_strdup(uid_vp9dec_hw);
+        if (!s->qsv.load_plugins)
+            return AVERROR(ENOMEM);
+    }
+#endif
+
     s->packet_fifo = av_fifo_alloc(sizeof(AVPacket));
     if (!s->packet_fifo) {
         ret = AVERROR(ENOMEM);
@@ -281,3 +292,32 @@  AVCodec ff_mjpeg_qsv_decoder = {
                                                     AV_PIX_FMT_NONE },
 };
 #endif
+
+#if CONFIG_VP9_QSV_DECODER
+static const AVClass vp9_qsv_class = {
+    .class_name = "vp9_qsv",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_vp9_qsv_decoder = {
+    .name           = "vp9_qsv",
+    .long_name      = NULL_IF_CONFIG_SMALL("VP9 video (Intel Quick Sync Video acceleration)"),
+    .priv_data_size = sizeof(QSVOtherContext),
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_VP9,
+    .init           = qsv_decode_init,
+    .decode         = qsv_decode_frame,
+    .flush          = qsv_decode_flush,
+    .close          = qsv_decode_close,
+    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
+    .priv_class     = &vp9_qsv_class,
+    .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
+                                                    AV_PIX_FMT_P010,
+                                                    AV_PIX_FMT_QSV,
+                                                    AV_PIX_FMT_NONE },
+    .hw_configs     = ff_qsv_hw_configs,
+    .wrapper_name   = "qsv",
+};
+#endif