[FFmpeg-devel] [PATCH 4/4] lavc: add vp8 mediacodec decoder

Thomas Volkert silvo at gmx.net
Sun Jul 24 16:06:17 EEST 2016


From: Thomas Volkert <thomas at netzeal.de>

---
 Changelog                      |  1 +
 configure                      |  1 +
 libavcodec/Makefile            |  1 +
 libavcodec/allcodecs.c         |  1 +
 libavcodec/mediacodecdec_vp8.c | 89 ++++++++++++++++++++++++++++++++++++++++++
 libavcodec/version.h           |  2 +-
 6 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/mediacodecdec_vp8.c

diff --git a/Changelog b/Changelog
index e35224c..6eaec1b 100644
--- a/Changelog
+++ b/Changelog
@@ -9,6 +9,7 @@ version <next>:
 - VP8 in Ogg muxing
 - MediaCodec MPEG-4 decoding
 - MediaCodec H.263 decoding
+- MediaCodec VP8 decoding
 
 
 version 3.1:
diff --git a/configure b/configure
index 18cc5f2..445d975 100755
--- a/configure
+++ b/configure
@@ -2655,6 +2655,7 @@ vc1_vdpau_hwaccel_deps="vdpau"
 vc1_vdpau_hwaccel_select="vc1_decoder"
 vp8_cuvid_hwaccel_deps="cuda cuvid CUVIDVP9PICPARAMS"
 vp9_cuvid_hwaccel_deps="cuda cuvid CUVIDVP9PICPARAMS"
+vp8_mediacodec_decoder_deps="mediacodec"
 vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
 vp9_d3d11va_hwaccel_select="vp9_decoder"
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 0bc0211..466c5a4 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -593,6 +593,7 @@ OBJS-$(CONFIG_VP6_DECODER)             += vp6.o vp56.o vp56data.o \
 OBJS-$(CONFIG_VP7_DECODER)             += vp8.o vp56rac.o
 OBJS-$(CONFIG_VP8_DECODER)             += vp8.o vp56rac.o
 OBJS-$(CONFIG_VP8_CUVID_DECODER)       += cuvid.o
+OBJS-$(CONFIG_VP8_MEDIACODEC_DECODER)  += mediacodecdec_vp8.o
 OBJS-$(CONFIG_VP9_DECODER)             += vp9.o vp9dsp.o vp56rac.o vp9dsp_8bpp.o \
                                           vp9dsp_10bpp.o vp9dsp_12bpp.o
 OBJS-$(CONFIG_VP9_CUVID_DECODER)       += cuvid.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index db2f25d..b750c0e 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -353,6 +353,7 @@ void avcodec_register_all(void)
     REGISTER_DECODER(VP6F,              vp6f);
     REGISTER_DECODER(VP7,               vp7);
     REGISTER_DECODER(VP8,               vp8);
+    REGISTER_DECODER(VP8_MEDIACODEC,    vp8_mediacodec);
     REGISTER_DECODER(VP9,               vp9);
     REGISTER_DECODER(VQA,               vqa);
     REGISTER_DECODER(WEBP,              webp);
diff --git a/libavcodec/mediacodecdec_vp8.c b/libavcodec/mediacodecdec_vp8.c
new file mode 100644
index 0000000..6beac70
--- /dev/null
+++ b/libavcodec/mediacodecdec_vp8.c
@@ -0,0 +1,89 @@
+/*
+ * Android MediaCodec VP8 decoder
+ *
+ * Copyright (c) 2016 Thomas Volkert <thomas at netzeal.de>
+ *
+ * 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 "libavutil/avassert.h"
+#include "libavutil/common.h"
+#include "libavutil/fifo.h"
+
+#include "avcodec.h"
+#include "internal.h"
+#include "mediacodecdec.h"
+#include "mediacodec_wrapper.h"
+
+#define CODEC_MIME "video/x-vnd.on2.vp8"
+
+static av_cold int mediacodec_decoder_init_vp8(AVCodecContext *avctx)
+{
+    int ret;
+
+    FFAMediaFormat *format = NULL;
+    MediaCodecDecContext *s = avctx->priv_data;
+
+    format = ff_AMediaFormat_new();
+    if (!format) {
+        av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
+        ret = AVERROR_EXTERNAL;
+        goto done;
+    }
+
+    ff_AMediaFormat_setString(format, "mime", CODEC_MIME);
+    ff_AMediaFormat_setInt32(format, "width", avctx->width);
+    ff_AMediaFormat_setInt32(format, "height", avctx->height);
+
+    if ((ret = ff_mediacodec_dec_init(avctx, s, CODEC_MIME, format)) < 0) {
+        goto done;
+    }
+
+    av_log(avctx, AV_LOG_INFO, "MediaCodec started successfully, ret = %d\n", ret);
+
+    s->fifo = av_fifo_alloc(sizeof(AVPacket));
+    if (!s->fifo) {
+        ret = AVERROR(ENOMEM);
+        goto done;
+    }
+
+    av_init_packet(&s->output_pkt);
+
+done:
+    if (format) {
+        ff_AMediaFormat_delete(format);
+    }
+
+    if (ret < 0) {
+    	ff_mediacodec_decoder_close(avctx);
+    }
+
+    return ret;
+}
+
+AVCodec ff_vp8_mediacodec_decoder = {
+    .name           = "vp8_mediacodec",
+    .long_name      = NULL_IF_CONFIG_SMALL("VP8 Android MediaCodec decoder"),
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_VP8,
+    .priv_data_size = sizeof(MediaCodecDecContext),
+    .init           = mediacodec_decoder_init_vp8,
+    .decode         = ff_mediacodec_decoder_decode,
+    .flush          = ff_mediacodec_decoder_flush,
+    .close          = ff_mediacodec_decoder_close,
+    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
+};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a697261..cdfc4f9 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  57
-#define LIBAVCODEC_VERSION_MINOR  52
+#define LIBAVCODEC_VERSION_MINOR  53
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
2.7.4



More information about the ffmpeg-devel mailing list