---
 libavcodec/Makefile      |    1 +
 libavcodec/allcodecs.c   |    1 +
 libavcodec/mpegvideo.c   |    1 +
 libavcodec/vdpau_mpeg2.c |  102 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+)
 create mode 100644 libavcodec/vdpau_mpeg2.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a4eebb8..0d3004a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -249,6 +249,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_DECODER)      += mpeg12.o 
mpeg12data.o
 OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
 OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)     += dxva2_mpeg2.o
 OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)     += vaapi_mpeg2.o
+OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)     += vdpau_mpeg2.o
 OBJS-$(CONFIG_MPEG2VIDEO_DECODER)      += mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
 OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)     += vaapi_mpeg4.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index ee664e4..29f7385 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -79,6 +79,7 @@ void avcodec_register_all(void)
     REGISTER_HWACCEL(H264_VDA,          h264_vda);
     REGISTER_HWACCEL(MPEG2_DXVA2,       mpeg2_dxva2);
     REGISTER_HWACCEL(MPEG2_VAAPI,       mpeg2_vaapi);
+    REGISTER_HWACCEL(MPEG2_VDPAU,       mpeg2_vdpau);
     REGISTER_HWACCEL(MPEG4_VAAPI,       mpeg4_vaapi);
     REGISTER_HWACCEL(VC1_DXVA2,         vc1_dxva2);
     REGISTER_HWACCEL(VC1_VAAPI,         vc1_vaapi);
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 0b6ddb9..5bb04dd 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -134,6 +134,7 @@ const enum AVPixelFormat ff_hwaccel_pixfmt_list_420[] = {
     AV_PIX_FMT_DXVA2_VLD,
     AV_PIX_FMT_VAAPI_VLD,
     AV_PIX_FMT_VDA_VLD,
+    AV_PIX_FMT_VDPAU,
     AV_PIX_FMT_YUV420P,
     AV_PIX_FMT_NONE
 };
diff --git a/libavcodec/vdpau_mpeg2.c b/libavcodec/vdpau_mpeg2.c
new file mode 100644
index 0000000..896eb4c
--- /dev/null
+++ b/libavcodec/vdpau_mpeg2.c
@@ -0,0 +1,102 @@
+/*
+ * MPEG-1/2 HW decode acceleration through VDPAU
+ *
+ * Copyright (c) 2008 NVIDIA
+ * Copyright (c) 2012-2013 Rémi Denis-Courmont
+ *
+ * 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 "avcodec.h"
+#include "dsputil.h"
+#include "vdpau_internal.h"
+
+#include <assert.h>
+
+static int vdpau_mpeg2_start_frame(AVCodecContext *avctx,
+                                   const uint8_t *buffer, uint32_t size)
+{
+    MpegEncContext * const s = avctx->priv_data;
+    struct vdpau_context *hwctx = avctx->hwaccel_context;
+    VdpVideoSurface ref;
+    int i;
+
+    /* fill VdpPictureInfoMPEG1Or2 struct */
+    hwctx->info.mpeg.picture_structure          = s->picture_structure;
+    hwctx->info.mpeg.picture_coding_type        = s->pict_type;
+    hwctx->info.mpeg.intra_dc_precision         = s->intra_dc_precision;
+    hwctx->info.mpeg.frame_pred_frame_dct       = s->frame_pred_frame_dct;
+    hwctx->info.mpeg.concealment_motion_vectors = 
s->concealment_motion_vectors;
+    hwctx->info.mpeg.intra_vlc_format           = s->intra_vlc_format;
+    hwctx->info.mpeg.alternate_scan             = s->alternate_scan;
+    hwctx->info.mpeg.q_scale_type               = s->q_scale_type;
+    hwctx->info.mpeg.top_field_first            = s->top_field_first;
+    // Both for MPEG-1 only, zero for MPEG-2:
+    hwctx->info.mpeg.full_pel_forward_vector    = s->full_pel[0];
+    hwctx->info.mpeg.full_pel_backward_vector   = s->full_pel[1];
+    // For MPEG-1 fill both horizontal & vertical:
+    hwctx->info.mpeg.f_code[0][0]               = s->mpeg_f_code[0][0];
+    hwctx->info.mpeg.f_code[0][1]               = s->mpeg_f_code[0][1];
+    hwctx->info.mpeg.f_code[1][0]               = s->mpeg_f_code[1][0];
+    hwctx->info.mpeg.f_code[1][1]               = s->mpeg_f_code[1][1];
+    for (i = 0; i < 64; ++i) {
+        hwctx->info.mpeg.intra_quantizer_matrix[i]     = s->intra_matrix[i];
+        hwctx->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
+    }
+
+    hwctx->info.mpeg.forward_reference          = VDP_INVALID_HANDLE;
+    hwctx->info.mpeg.backward_reference         = VDP_INVALID_HANDLE;
+
+    switch(s->pict_type){
+    case  AV_PICTURE_TYPE_B:
+        ref = ff_vdpau_get_surface_id(&s->next_picture);
+        assert(ref != VDP_INVALID_HANDLE);
+        hwctx->info.mpeg.backward_reference     = ref;
+        /* fall through to forward prediction */
+    case  AV_PICTURE_TYPE_P:
+        ref = ff_vdpau_get_surface_id(&s->last_picture);
+        hwctx->info.mpeg.forward_reference      = ref;
+    }
+
+    hwctx->info.mpeg.slice_count                = 0;
+
+    return ff_vdpau_common_start_frame(avctx, buffer, size);
+}
+
+static int vdpau_mpeg2_decode_slice(AVCodecContext *avctx,
+                                    const uint8_t *buffer, uint32_t size)
+{
+    struct vdpau_context *hwctx = avctx->hwaccel_context;
+    int val;
+
+    val = ff_vdpau_add_buffer(avctx, buffer, size);
+    if (val < 0)
+        return val;
+
+    hwctx->info.mpeg.slice_count++;
+    return 0;
+}
+
+AVHWAccel ff_mpeg2_vdpau_hwaccel = {
+    .name           = "mpeg2_vdpau",
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_MPEG2VIDEO,
+    .pix_fmt        = AV_PIX_FMT_VDPAU,
+    .start_frame    = vdpau_mpeg2_start_frame,
+    .end_frame      = ff_vdpau_common_end_frame,
+    .decode_slice   = vdpau_mpeg2_decode_slice,
+};
-- 
1.7.10.4

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

Reply via email to