---
 configure              |   2 +
 libavcodec/Makefile    |   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/qsv_mpeg2.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 128 insertions(+)
 create mode 100644 libavcodec/qsv_mpeg2.c

diff --git a/configure b/configure
index 02f511d..1c7b727 100755
--- a/configure
+++ b/configure
@@ -1735,6 +1735,8 @@ mpeg1_vdpau_hwaccel_deps="vdpau"
 mpeg1_vdpau_hwaccel_select="mpeg1video_decoder"
 mpeg2_dxva2_hwaccel_deps="dxva2"
 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
+mpeg2_qsv_decoder_deps="qsv"
+mpeg2_qsv_decoder_select="mpegvideo_parser"
 mpeg2_vaapi_hwaccel_deps="vaapi"
 mpeg2_vaapi_hwaccel_select="mpeg2video_decoder"
 mpeg2_vdpau_hwaccel_deps="vdpau"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ddd81d1..5dc1da2 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -253,6 +253,7 @@ OBJS-$(CONFIG_MPEG_XVMC_DECODER)       += mpegvideo_xvmc.o
 OBJS-$(CONFIG_MPEG1VIDEO_DECODER)      += mpeg12dec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
 OBJS-$(CONFIG_MPEG2VIDEO_DECODER)      += mpeg12dec.o mpeg12.o mpeg12data.o
+OBJS-$(CONFIG_MPEG2_QSV_DECODER)       += qsv_mpeg2.o
 OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
 OBJS-$(CONFIG_MSMPEG4V1_DECODER)       += msmpeg4dec.o msmpeg4.o msmpeg4data.o
 OBJS-$(CONFIG_MSMPEG4V2_DECODER)       += msmpeg4dec.o msmpeg4.o msmpeg4data.o 
\
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 71f08bd..0118301 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -180,6 +180,7 @@ void avcodec_register_all(void)
     REGISTER_DECODER(MPEG_XVMC,         mpeg_xvmc);
     REGISTER_ENCDEC (MPEG1VIDEO,        mpeg1video);
     REGISTER_ENCDEC (MPEG2VIDEO,        mpeg2video);
+    REGISTER_DECODER(MPEG2_QSV,         mpeg2_qsv);
     REGISTER_ENCDEC (MPEG4,             mpeg4);
     REGISTER_DECODER(MSA1,              msa1);
     REGISTER_DECODER(MSMPEG4V1,         msmpeg4v1);
diff --git a/libavcodec/qsv_mpeg2.c b/libavcodec/qsv_mpeg2.c
new file mode 100644
index 0000000..27b85cf
--- /dev/null
+++ b/libavcodec/qsv_mpeg2.c
@@ -0,0 +1,124 @@
+/*
+ * Intel MediaSDK QSV based MPEG-2 decoder
+ *
+ * copyright (c) 2013 Yukinori Yamazoe
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <mfx/mfxvideo.h>
+
+#include "avcodec.h"
+#include "internal.h"
+#include "mpegvideo.h"
+#include "qsv.h"
+
+typedef struct QSVMpegContext {
+    AVClass *class;
+    QSVContext qsv;
+} QSVMpegContext;
+
+static const uint8_t fake_ipic[] = { 0x00, 0x00, 0x01, 0x00, 0x00, 0x0F, 0xFF, 
0xF8 };
+
+static av_cold int qsv_dec_init(AVCodecContext *avctx)
+{
+    QSVMpegContext *q = avctx->priv_data;
+    mfxBitstream *bs  = &q->qsv.bs;
+    int ret;
+
+    avctx->pix_fmt = AV_PIX_FMT_NV12;
+
+    //FIXME feed it a fake I-picture directly
+    bs->Data = av_malloc(avctx->extradata_size + sizeof(fake_ipic));
+    bs->DataLength = avctx->extradata_size;
+
+    memcpy(bs->Data, avctx->extradata, avctx->extradata_size);
+    memcpy(bs->Data + bs->DataLength, fake_ipic, sizeof(fake_ipic));
+
+    bs->DataLength += sizeof(fake_ipic);
+
+    bs->MaxLength = bs->DataLength;
+
+    ret = ff_qsv_init(avctx, &q->qsv);
+    if (ret < 0)
+        av_freep(&bs->Data);
+
+    return ret;
+}
+
+static int qsv_dec_frame(AVCodecContext *avctx, void *data,
+                         int *got_frame, AVPacket *avpkt)
+{
+    QSVMpegContext *q = avctx->priv_data;
+    AVFrame *frame    = data;
+    int ret;
+
+    // Reinit so finished flushing old video parameter cached frames
+    if (q->qsv.need_reinit && q->qsv.last_ret == MFX_ERR_MORE_DATA)
+        if ((ret = ff_qsv_reinit(avctx, &q->qsv)) < 0)
+            return ret;
+
+    return ff_qsv_decode(avctx, &q->qsv, frame, got_frame, avpkt);
+}
+
+static int qsv_dec_close(AVCodecContext *avctx)
+{
+    QSVMpegContext *q = avctx->priv_data;
+    int ret = ff_qsv_close(&q->qsv);
+
+    av_freep(&q->qsv.bs.Data);
+    return ret;
+}
+
+static void qsv_dec_flush(AVCodecContext *avctx)
+{
+    QSVMpegContext *q = avctx->priv_data;
+
+    ff_qsv_flush(&q->qsv);
+}
+
+#define OFFSET(x) offsetof(QSVMpegContext, x)
+#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+    { "async_depth", "Number of parallel processing", OFFSET(qsv.async_depth), 
AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VD },
+    { "timeout", "Maximum timeout in milliseconds when the device has been 
busy", OFFSET(qsv.timeout), AV_OPT_TYPE_INT, { .i64 = TIMEOUT_DEFAULT }, 0, 
INT_MAX, VD },
+    { NULL },
+};
+
+static const AVClass class = {
+    .class_name = "mpeg2_qsv",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_mpeg2_qsv_decoder = {
+    .name           = "mpeg2_qsv",
+    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 video (Intel Quick Sync 
Video acceleration)"),
+    .priv_data_size = sizeof(QSVMpegContext),
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_MPEG2VIDEO,
+    .init           = qsv_dec_init,
+    .decode         = qsv_dec_frame,
+    .flush          = qsv_dec_flush,
+    .close          = qsv_dec_close,
+    .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_PKT_TS | CODEC_CAP_DR1,
+    .priv_class     = &class,
+};
-- 
1.8.3.msysgit.0

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to