Re: [FFmpeg-devel] [PATCH v4] avcodec: libdav1d AV1 decoder wrapper.

2018-11-05 Thread James Almer
On 10/29/2018 7:16 PM, James Almer wrote:
> From: "Ronald S. Bultje" 
> 
> Originally written by Ronald S. Bultje, with fixes, optimizations and
> improvements by James Almer.
> 
> Signed-off-by: James Almer 
> ---
> - s.n_frame_threads is now mapped to avctx->thread_count.
> - colorspace, color_primaries and color_trc are now cast to avutil enums to
>   silence -Wenum-conversion warnings on Clang.
> - Constified the data pointer in libdav1d_data_free() callback due to recent
>   changes upstream.
> 
> Dav1dData was updated upstream as well, so a { 0 } initialization should not
> emit any kind of warning with old GCC/Clang anymore.
> 
>  configure  |   4 +
>  libavcodec/Makefile|   1 +
>  libavcodec/allcodecs.c |   1 +
>  libavcodec/libdav1d.c  | 270 +
>  4 files changed, 276 insertions(+)
>  create mode 100644 libavcodec/libdav1d.c

Pushed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v4] avcodec: libdav1d AV1 decoder wrapper.

2018-10-29 Thread James Almer
> On Fri, Oct 26, 2018 at 4:00 PM James Almer  wrote:
> 
>> On 10/26/2018 7:50 PM, Dale Curtis wrote:
>>> One more piece of feedback, this is not obeying the
>>> AVCodecContext.get_buffer2 API.
>>
>> It's not using it on purpose, wrapping the buffers dav1d allocated
>> itself instead. Hence the lack of AV_CODEC_CAP_DR1 flag.
>>
> 
> Sorry for being unclear, my comment was a request. This is something
> Chromium would require to use this wrapper. If it's not planned, we'd forgo
> the wrapper and use dav1d directly. Otherwise we'd need to change our
> common ffmpeg based decoder enough for this one case that we'd be better
> off writing a pure dav1d based decoder. Thanks for your consideration in
> any case.
> 
> - dale
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 

I don't think the wrapper can use the get_buffer2 API if the idea is to
use it within Dav1dPicAllocator.alloc_picture_callback(). There's no way
to guarantee that the constrains required by said callback will be met
for example by a user provided implementation of get_buffer2.
Also, avctx dimensions need to be set by the time the
alloc_picture_callback() is called (as required by ff_get_buffer), and
said callback can't set them itself since we don't know at what point
during decoding it's going to be called (Things would probably go south
decoding a sample with frame changes in a frame multi-threading scenario).

If the idea is letting dav1d allocate its own buffers and then memcpy
them to get_buffer2() allocated buffers with av_image_copy(), like the
libaom wrapper is doing, then that can be done, but it's not something i
want committed since it will be slower than this zero copy implementation.
You could keep a local patch to implement it that way if you need to. It
should be trivial.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v4] avcodec: libdav1d AV1 decoder wrapper.

2018-10-29 Thread James Almer
From: "Ronald S. Bultje" 

Originally written by Ronald S. Bultje, with fixes, optimizations and
improvements by James Almer.

Signed-off-by: James Almer 
---
- s.n_frame_threads is now mapped to avctx->thread_count.
- colorspace, color_primaries and color_trc are now cast to avutil enums to
  silence -Wenum-conversion warnings on Clang.
- Constified the data pointer in libdav1d_data_free() callback due to recent
  changes upstream.

Dav1dData was updated upstream as well, so a { 0 } initialization should not
emit any kind of warning with old GCC/Clang anymore.

 configure  |   4 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libdav1d.c  | 270 +
 4 files changed, 276 insertions(+)
 create mode 100644 libavcodec/libdav1d.c

diff --git a/configure b/configure
index 01c3a1011d..e56b925065 100755
--- a/configure
+++ b/configure
@@ -226,6 +226,7 @@ External library support:
   --enable-libcelt enable CELT decoding via libcelt [no]
   --enable-libcdio enable audio CD grabbing with libcdio [no]
   --enable-libcodec2   enable codec2 en/decoding using libcodec2 [no]
+  --enable-libdav1denable AV1 decoding via libdav1d [no]
   --enable-libdavs2enable AVS2 decoding via libdavs2 [no]
   --enable-libdc1394   enable IIDC-1394 grabbing using libdc1394
and libraw1394 [no]
@@ -1712,6 +1713,7 @@ EXTERNAL_LIBRARY_LIST="
 libcaca
 libcelt
 libcodec2
+libdav1d
 libdc1394
 libdrm
 libflite
@@ -3088,6 +3090,7 @@ libaom_av1_encoder_select="extract_extradata_bsf"
 libcelt_decoder_deps="libcelt"
 libcodec2_decoder_deps="libcodec2"
 libcodec2_encoder_deps="libcodec2"
+libdav1d_decoder_deps="libdav1d"
 libdavs2_decoder_deps="libdavs2"
 libfdk_aac_decoder_deps="libfdk_aac"
 libfdk_aac_encoder_deps="libfdk_aac"
@@ -6064,6 +6067,7 @@ enabled libcelt   && require libcelt celt/celt.h 
celt_decode -lcelt0 &&
die "ERROR: libcelt must be installed and 
version must be >= 0.11.0."; }
 enabled libcaca   && require_pkg_config libcaca caca caca.h 
caca_create_canvas
 enabled libcodec2 && require libcodec2 codec2/codec2.h codec2_create 
-lcodec2
+enabled libdav1d  && require_pkg_config libdav1d "dav1d >= 0.0.1" 
"dav1d/dav1d.h" dav1d_version
 enabled libdavs2  && require_pkg_config libdavs2 "davs2 >= 1.5.115" 
davs2.h davs2_decoder_open
 enabled libdc1394 && require_pkg_config libdc1394 libdc1394-2 
dc1394/dc1394.h dc1394_new
 enabled libdrm&& require_pkg_config libdrm libdrm xf86drm.h 
drmGetVersion
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3e41497e34..8643da8f2b 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -956,6 +956,7 @@ OBJS-$(CONFIG_LIBAOM_AV1_ENCODER) += libaomenc.o
 OBJS-$(CONFIG_LIBCELT_DECODER)+= libcelt_dec.o
 OBJS-$(CONFIG_LIBCODEC2_DECODER)  += libcodec2.o codec2utils.o
 OBJS-$(CONFIG_LIBCODEC2_ENCODER)  += libcodec2.o codec2utils.o
+OBJS-$(CONFIG_LIBDAV1D_DECODER)   += libdav1d.o
 OBJS-$(CONFIG_LIBDAVS2_DECODER)   += libdavs2.o
 OBJS-$(CONFIG_LIBFDK_AAC_DECODER) += libfdk-aacdec.o
 OBJS-$(CONFIG_LIBFDK_AAC_ENCODER) += libfdk-aacenc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 1b8144a2b7..2c17db5a70 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -676,6 +676,7 @@ extern AVCodec ff_libaom_av1_encoder;
 extern AVCodec ff_libcelt_decoder;
 extern AVCodec ff_libcodec2_encoder;
 extern AVCodec ff_libcodec2_decoder;
+extern AVCodec ff_libdav1d_decoder;
 extern AVCodec ff_libdavs2_decoder;
 extern AVCodec ff_libfdk_aac_encoder;
 extern AVCodec ff_libfdk_aac_decoder;
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
new file mode 100644
index 00..873adfda40
--- /dev/null
+++ b/libavcodec/libdav1d.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2018 Ronald S. Bultje 
+ * Copyright (c) 2018 James Almer 
+ *
+ * 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 
+
+#include "libavutil/avassert.h"
+#include "libavutil/fifo.h"
+#include "libavutil/opt.h"
+
+#include "avcodec.h"
+#include "decode.h"
+#incl