[FFmpeg-devel] [PATCH 3/4] lavc: add h.263 mediacodec decoder

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


From: Thomas Volkert <thomas at netzeal.de>

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

diff --git a/Changelog b/Changelog
index b8bbdb9..e35224c 100644
--- a/Changelog
+++ b/Changelog
@@ -8,6 +8,7 @@ version <next>:
 - Alias muxer for Ogg Video (.ogv)
 - VP8 in Ogg muxing
 - MediaCodec MPEG-4 decoding
+- MediaCodec H.263 decoding
 
 
 version 3.1:
diff --git a/configure b/configure
index 9004b06..18cc5f2 100755
--- a/configure
+++ b/configure
@@ -2548,6 +2548,7 @@ videotoolbox_hwaccel_deps="videotoolbox pthreads"
 videotoolbox_hwaccel_extralibs="-framework QuartzCore"
 xvmc_deps="X11_extensions_XvMClib_h"
 
+h263_mediacodec_decoder_deps="mediacodec"
 h263_vaapi_hwaccel_deps="vaapi"
 h263_vaapi_hwaccel_select="h263_decoder"
 h263_videotoolbox_hwaccel_deps="videotoolbox"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 642cf2a..0bc0211 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -309,6 +309,7 @@ OBJS-$(CONFIG_H263_DECODER)            += h263dec.o h263.o ituh263dec.o        \
                                           intelh263dec.o h263data.o
 OBJS-$(CONFIG_H263_ENCODER)            += mpeg4videoenc.o mpeg4video.o  \
                                           h263.o ituh263enc.o flvenc.o h263data.o
+OBJS-$(CONFIG_H263_MEDIACODEC_DECODER) += mediacodecdec_h263.o
 OBJS-$(CONFIG_H264_DECODER)            += h264.o h264_cabac.o h264_cavlc.o \
                                           h264_direct.o h264_loopfilter.o  \
                                           h264_mb.o h264_picture.o h264_ps.o \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2d98694..db2f25d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -193,6 +193,7 @@ void avcodec_register_all(void)
     REGISTER_ENCDEC (H263,              h263);
     REGISTER_DECODER(H263I,             h263i);
     REGISTER_ENCDEC (H263P,             h263p);
+    REGISTER_DECODER(H263_MEDIACODEC,   h263_mediacodec);
     REGISTER_DECODER(H264,              h264);
     REGISTER_DECODER(H264_CRYSTALHD,    h264_crystalhd);
     REGISTER_DECODER(H264_MEDIACODEC,   h264_mediacodec);
diff --git a/libavcodec/mediacodecdec_h263.c b/libavcodec/mediacodecdec_h263.c
new file mode 100644
index 0000000..5f2c412
--- /dev/null
+++ b/libavcodec/mediacodecdec_h263.c
@@ -0,0 +1,90 @@
+/*
+ * Android MediaCodec H.263 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/3gpp"
+
+static av_cold int mediacodec_decoder_init_h263(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_h263_mediacodec_decoder = {
+    .name           = "h263_mediacodec",
+    .long_name      = NULL_IF_CONFIG_SMALL("H.263 Android MediaCodec decoder"),
+    .type           = AVMEDIA_TYPE_VIDEO,
+    .id             = AV_CODEC_ID_H263,
+    .priv_data_size = sizeof(MediaCodecDecContext),
+    .init           = mediacodec_decoder_init_h263,
+    .decode         = ff_mediacodec_decoder_decode,
+    .flush          = ff_mediacodec_decoder_flush,
+    .close          = ff_mediacodec_decoder_close,
+    .capabilities   = CODEC_CAP_DELAY,
+    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
+};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 4ded1ee..a697261 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  51
+#define LIBAVCODEC_VERSION_MINOR  52
 #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