[FFmpeg-devel,3/3] qsvdec: add mjpeg decoding support

Submitted by Zhong Li on June 27, 2019, 12:59 p.m.

Details

Message ID 1561640354-12545-3-git-send-email-zhong.li@intel.com
State New
Headers show

Commit Message

Zhong Li June 27, 2019, 12:59 p.m.
Only baseline profile and NV12 output format supported right now.
---
 Changelog                 |  1 +
 configure                 |  2 ++
 libavcodec/Makefile       |  1 +
 libavcodec/allcodecs.c    |  1 +
 libavcodec/qsv.c          |  2 ++
 libavcodec/qsvdec.c       |  2 ++
 libavcodec/qsvdec.h       |  1 +
 libavcodec/qsvdec_other.c | 28 +++++++++++++++++++++++++++-
 8 files changed, 37 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/Changelog b/Changelog
index 57476c3..2bc1087 100644
--- a/Changelog
+++ b/Changelog
@@ -34,6 +34,7 @@  version <next>:
 - VP4 video decoder
 - IFV demuxer
 - derain filter
+- Intel QSV-accelerated MJPEG decoding
 
 
 version 4.1:
diff --git a/configure b/configure
index 7cea9d4..8119a29 100755
--- a/configure
+++ b/configure
@@ -3028,6 +3028,8 @@  hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
 hevc_v4l2m2m_decoder_select="hevc_mp4toannexb_bsf"
 hevc_v4l2m2m_encoder_deps="v4l2_m2m hevc_v4l2_m2m"
 mjpeg_cuvid_decoder_deps="cuvid"
+mjpeg_qsv_decoder_deps="libmfx"
+mjpeg_qsv_decoder_select="qsvdec mjpeg_parser"
 mjpeg_qsv_encoder_deps="libmfx"
 mjpeg_qsv_encoder_select="qsvenc"
 mjpeg_vaapi_encoder_deps="VAEncPictureParameterBufferJPEG"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index edccd73..95b7fc8 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -425,6 +425,7 @@  OBJS-$(CONFIG_METASOUND_DECODER)       += metasound.o metasound_data.o \
 OBJS-$(CONFIG_MICRODVD_DECODER)        += microdvddec.o ass.o
 OBJS-$(CONFIG_MIMIC_DECODER)           += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)           += mjpegdec.o
+OBJS-$(CONFIG_MJPEG_QSV_DECODER)       += qsvdec_other.o
 OBJS-$(CONFIG_MJPEG_ENCODER)           += mjpegenc.o mjpegenc_common.o \
                                           mjpegenc_huffman.o
 OBJS-$(CONFIG_MJPEGB_DECODER)          += mjpegbdec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index d2f9a39..cfc1d47 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -763,6 +763,7 @@  extern AVCodec ff_hevc_videotoolbox_encoder;
 extern AVCodec ff_libkvazaar_encoder;
 extern AVCodec ff_mjpeg_cuvid_decoder;
 extern AVCodec ff_mjpeg_qsv_encoder;
+extern AVCodec ff_mjpeg_qsv_decoder;
 extern AVCodec ff_mjpeg_vaapi_encoder;
 extern AVCodec ff_mpeg1_cuvid_decoder;
 extern AVCodec ff_mpeg2_cuvid_decoder;
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 986d4f6..69961b7 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -96,6 +96,8 @@  static const struct {
     MAP(HEVC,        HEVC_REXT,       HEVC_REXT    ),
 #endif
 
+    MAP(MJPEG,       MJPEG_HUFFMAN_LOSSLESS,     JPEG_BASELINE ),
+
     MAP(VC1,         VC1_SIMPLE,      VC1_SIMPLE   ),
     MAP(VC1,         VC1_MAIN,        VC1_MAIN     ),
     MAP(VC1,         VC1_COMPLEX,     VC1_ADVANCED ),
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 46aa2d6..d1ea056 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -212,6 +212,8 @@  static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
     param.mfx.FrameInfo.Width          = frame_width;
     param.mfx.FrameInfo.Height         = frame_height;
     param.mfx.FrameInfo.ChromaFormat   = MFX_CHROMAFORMAT_YUV420;
+    param.mfx.FrameInfo.CropW          = avctx->width;
+    param.mfx.FrameInfo.CropH          = avctx->height;
 
     switch (avctx->field_order) {
     case AV_FIELD_PROGRESSIVE:
diff --git a/libavcodec/qsvdec.h b/libavcodec/qsvdec.h
index 111536c..3b44af9 100644
--- a/libavcodec/qsvdec.h
+++ b/libavcodec/qsvdec.h
@@ -27,6 +27,7 @@ 
 #include <sys/types.h>
 
 #include <mfx/mfxvideo.h>
+#include <mfx/mfxjpeg.h>
 
 #include "libavutil/fifo.h"
 #include "libavutil/frame.h"
diff --git a/libavcodec/qsvdec_other.c b/libavcodec/qsvdec_other.c
index 03251d2..8c9c1e6 100644
--- a/libavcodec/qsvdec_other.c
+++ b/libavcodec/qsvdec_other.c
@@ -1,5 +1,5 @@ 
 /*
- * Intel MediaSDK QSV based MPEG-2, VC-1 and VP8 decoders
+ * Intel MediaSDK QSV based MPEG-2, VC-1, VP8 and MJPEG decoders
  *
  * copyright (c) 2015 Anton Khirnov
  *
@@ -255,3 +255,29 @@  AVCodec ff_vp8_qsv_decoder = {
     .wrapper_name   = "qsv",
 };
 #endif
+
+#if CONFIG_MJPEG_QSV_DECODER
+static const AVClass mjpeg_qsv_class = {
+    .class_name = "mjpeg_qsv",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_mjpeg_qsv_decoder = {
+    .name           = "mjpeg_qsv",
+    .long_name      = NULL_IF_CONFIG_SMALL("MJPEG video (Intel Quick Sync Video acceleration)"),
+    .priv_data_size = sizeof(QSVOtherContext),
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_MJPEG,
+    .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,
+    .priv_class     = &mjpeg_qsv_class,
+    .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
+                                                    AV_PIX_FMT_QSV,
+                                                    AV_PIX_FMT_NONE },
+};
+#endif