[vlc-commits] aom: add AV1 decoder
Tristan Matthews
git at videolan.org
Sun Aug 21 19:47:34 CEST 2016
vlc | branch: master | Tristan Matthews <tmatth at videolan.org> | Fri Aug 19 14:00:27 2016 -0700| [461b9cb189fc09649484f52eb83f10eda440c39c] | committer: Tristan Matthews
aom: add AV1 decoder
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=461b9cb189fc09649484f52eb83f10eda440c39c
---
NEWS | 1 +
configure.ac | 5 +
modules/codec/Makefile.am | 8 ++
modules/codec/aom.c | 236 ++++++++++++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 1 +
5 files changed, 251 insertions(+)
diff --git a/NEWS b/NEWS
index e735729..8a6d0be 100644
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,7 @@ Decoder:
* Support 4:4:4 and 4:2:2 chroma samplings with VDPAU hw acceleration
* Support for ARIB STD-B24 subtitles
* Support for Daala video
+ * Support for AV1 video
* Important improvements for the MMAL decoder and output for rPI and rPI2
* Support HEVC hardware decoding using OMX and MediaCodec
* Use MediaCodec via NDK native API after Android Lollipop
diff --git a/configure.ac b/configure.ac
index abcd3b5..62ad078 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2669,6 +2669,11 @@ AS_IF([test "${enable_faad}" != "no"], [
])
dnl
+dnl AOM decoder plugin
+dnl
+PKG_ENABLE_MODULES_VLC([AOM], [], [aom], [experimental AV1 codec], [disabled])
+
+dnl
dnl libvpx decoder plugin
dnl
AC_ARG_ENABLE(vpx,
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index 88e7a28..c42473b 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -516,6 +516,14 @@ libvpx_plugin_la_LIBADD = $(VPX_LIBS)
EXTRA_LTLIBRARIES += libvpx_plugin.la
codec_LTLIBRARIES += $(LTLIBvpx)
+libaom_plugin_la_SOURCES = codec/aom.c
+libaom_plugin_la_CPPFLAGS = $(AM_CPPFLAGS)
+libaom_plugin_la_CFLAGS = $(AM_CFLAGS) $(AOM_CFLAGS) $(CPPFLAGS_aom)
+libaom_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(codecdir)'
+libaom_plugin_la_LIBADD = $(AOM_LIBS) $(LIBPTHREAD)
+EXTRA_LTLIBRARIES += libaom_plugin.la
+codec_LTLIBRARIES += $(LTLIBaom)
+
libtwolame_plugin_la_SOURCES = codec/twolame.c
libtwolame_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DLIBTWOLAME_STATIC
libtwolame_plugin_la_CFLAGS = $(AM_CFLAGS) $(TWOLAME_CFLAGS)
diff --git a/modules/codec/aom.c b/modules/codec/aom.c
new file mode 100644
index 0000000..e20b898
--- /dev/null
+++ b/modules/codec/aom.c
@@ -0,0 +1,236 @@
+/*****************************************************************************
+ * aom.c: libaom decoder (AV1) module
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ *
+ * Authors: Tristan Matthews <tmatth at videolan.org>
+ * Based on vpx.c by: Rafaël Carré <funman at videolan.org>
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_codec.h>
+
+#include <aom/aom_decoder.h>
+#include <aom/aomdx.h>
+
+/****************************************************************************
+ * Local prototypes
+ ****************************************************************************/
+static int OpenDecoder(vlc_object_t *);
+static void CloseDecoder(vlc_object_t *);
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+
+vlc_module_begin ()
+ set_shortname("aom")
+ set_description(N_("AOM video decoder"))
+ set_capability("decoder", 100)
+ set_callbacks(OpenDecoder, CloseDecoder)
+ set_category(CAT_INPUT)
+ set_subcategory(SUBCAT_INPUT_VCODEC)
+vlc_module_end ()
+
+static void aom_err_msg(vlc_object_t *this, aom_codec_ctx_t *ctx,
+ const char *msg)
+{
+ const char *error = aom_codec_error(ctx);
+ const char *detail = aom_codec_error_detail(ctx);
+ if (!detail)
+ detail = "no specific information";
+ msg_Err(this, msg, error, detail);
+}
+
+#define AOM_ERR(this, ctx, msg) aom_err_msg(VLC_OBJECT(this), ctx, msg ": %s (%s)")
+
+/*****************************************************************************
+ * decoder_sys_t: libaom decoder descriptor
+ *****************************************************************************/
+struct decoder_sys_t
+{
+ aom_codec_ctx_t ctx;
+};
+
+/****************************************************************************
+ * Decode: the whole thing
+ ****************************************************************************/
+static picture_t *Decode(decoder_t *dec, block_t **pp_block)
+{
+ aom_codec_ctx_t *ctx = &dec->p_sys->ctx;
+
+ if( !pp_block || !*pp_block )
+ return NULL;
+ block_t *block = *pp_block;
+
+ if (block->i_flags & (BLOCK_FLAG_CORRUPTED)) {
+ block_Release(block);
+ return NULL;
+ }
+
+ /* Associate packet PTS with decoded frame */
+ mtime_t *pkt_pts = malloc(sizeof(*pkt_pts));
+ if (!pkt_pts) {
+ block_Release(block);
+ *pp_block = NULL;
+ return NULL;
+ }
+
+ *pkt_pts = block->i_pts;
+
+ aom_codec_err_t err;
+ err = aom_codec_decode(ctx, block->p_buffer, block->i_buffer, pkt_pts, 0);
+
+ block_Release(block);
+ *pp_block = NULL;
+
+ if (err != AOM_CODEC_OK) {
+ free(pkt_pts);
+ AOM_ERR(dec, ctx, "Failed to decode frame");
+ return NULL;
+ }
+
+ const void *iter = NULL;
+ struct aom_image *img = aom_codec_get_frame(ctx, &iter);
+ if (!img) {
+ free(pkt_pts);
+ return NULL;
+ }
+
+ /* fetches back the PTS */
+ pkt_pts = img->user_priv;
+ mtime_t pts = *pkt_pts;
+ free(pkt_pts);
+
+ if (img->fmt != AOM_IMG_FMT_I420) {
+ msg_Err(dec, "Unsupported output colorspace %d", img->fmt);
+ return NULL;
+ }
+
+ video_format_t *v = &dec->fmt_out.video;
+
+ if (img->d_w != v->i_visible_width || img->d_h != v->i_visible_height) {
+ v->i_visible_width = img->d_w;
+ v->i_visible_height = img->d_h;
+ }
+
+ if( !dec->fmt_out.video.i_sar_num || !dec->fmt_out.video.i_sar_den )
+ {
+ dec->fmt_out.video.i_sar_num = 1;
+ dec->fmt_out.video.i_sar_den = 1;
+ }
+
+ picture_t *pic = decoder_NewPicture(dec);
+ if (!pic)
+ return NULL;
+
+ for (int plane = 0; plane < pic->i_planes; plane++ ) {
+ uint8_t *src = img->planes[plane];
+ uint8_t *dst = pic->p[plane].p_pixels;
+ int src_stride = img->stride[plane];
+ int dst_stride = pic->p[plane].i_pitch;
+
+ int size = __MIN( src_stride, dst_stride );
+ for( int line = 0; line < pic->p[plane].i_visible_lines; line++ ) {
+ memcpy( dst, src, size );
+ src += src_stride;
+ dst += dst_stride;
+ }
+ }
+
+ pic->b_progressive = true; /* codec does not support interlacing */
+ pic->date = pts;
+
+ return pic;
+}
+
+/*****************************************************************************
+ * OpenDecoder: probe the decoder
+ *****************************************************************************/
+static int OpenDecoder(vlc_object_t *p_this)
+{
+ decoder_t *dec = (decoder_t *)p_this;
+ const aom_codec_iface_t *iface;
+ int av_version;
+
+ switch (dec->fmt_in.i_codec)
+ {
+ case VLC_CODEC_AV1:
+ iface = &aom_codec_av1_dx_algo;
+ av_version = 1;
+ break;
+ default:
+ return VLC_EGENERIC;
+ }
+
+ decoder_sys_t *sys = malloc(sizeof(*sys));
+ if (!sys)
+ return VLC_ENOMEM;
+ dec->p_sys = sys;
+
+ struct aom_codec_dec_cfg deccfg = {
+ .threads = __MIN(vlc_GetCPUCount(), 16)
+ };
+
+ msg_Dbg(p_this, "AV%d: using libaom version %s (build options %s)",
+ av_version, aom_codec_version_str(), aom_codec_build_config());
+
+ if (aom_codec_dec_init(&sys->ctx, iface, &deccfg, 0) != AOM_CODEC_OK) {
+ AOM_ERR(p_this, &sys->ctx, "Failed to initialize decoder");
+ free(sys);
+ return VLC_EGENERIC;;
+ }
+
+ dec->pf_decode_video = Decode;
+
+ dec->fmt_out.i_cat = VIDEO_ES;
+ dec->fmt_out.video.i_width = dec->fmt_in.video.i_width;
+ dec->fmt_out.video.i_height = dec->fmt_in.video.i_height;
+ dec->fmt_out.i_codec = VLC_CODEC_I420;
+
+ return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * CloseDecoder: decoder destruction
+ *****************************************************************************/
+static void CloseDecoder(vlc_object_t *p_this)
+{
+ decoder_t *dec = (decoder_t *)p_this;
+ decoder_sys_t *sys = dec->p_sys;
+
+ /* Free our PTS */
+ const void *iter = NULL;
+ for (;;) {
+ struct aom_image *img = aom_codec_get_frame(&sys->ctx, &iter);
+ if (!img)
+ break;
+ free(img->user_priv);
+ }
+
+ aom_codec_destroy(&sys->ctx);
+
+ free(sys);
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f3a2af6..cd4d8e0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -332,6 +332,7 @@ modules/audio_output/waveout.c
modules/audio_output/windows_audio_common.h
modules/codec/adpcm.c
modules/codec/aes3.c
+modules/codec/aom.c
modules/codec/araw.c
modules/codec/arib/aribsub.c
modules/codec/avcodec/audio.c
More information about the vlc-commits
mailing list