[vlc-devel] [PATCH 2/2] dav1d: parse the extra data to get the output chroma
Steve Lhomme
robux4 at ycbcr.xyz
Wed Sep 9 16:11:12 CEST 2020
If there are some extra data the chroma should be constant and we can estimate
it so that we create the decoder with the proper chroma.
---
modules/codec/Makefile.am | 3 ++-
modules/codec/dav1d.c | 51 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index 0aede611336..acb5071f569 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -552,7 +552,8 @@ libtwolame_plugin_la_LIBADD = $(TWOLAME_LIBS) $(LIBM)
EXTRA_LTLIBRARIES += libtwolame_plugin.la
codec_LTLIBRARIES += $(LTLIBtwolame)
-libdav1d_plugin_la_SOURCES = codec/dav1d.c
+libdav1d_plugin_la_SOURCES = codec/dav1d.c \
+ packetizer/av1_obu.c packetizer/av1_obu.h
libdav1d_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(DAV1D_CFLAGS)
libdav1d_plugin_la_CFLAGS = $(AM_CFLAGS)
libdav1d_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(codecdir)'
diff --git a/modules/codec/dav1d.c b/modules/codec/dav1d.c
index 92f6f441464..9ee03f70c86 100644
--- a/modules/codec/dav1d.c
+++ b/modules/codec/dav1d.c
@@ -38,6 +38,7 @@
#include <dav1d/dav1d.h>
#include "../packetizer/iso_color_tables.h"
+#include "../packetizer/av1_obu.h"
#include "cc.h"
/****************************************************************************
@@ -391,6 +392,13 @@ static int OpenDecoder(vlc_object_t *p_this)
p_sys->s.allocator.alloc_picture_callback = NewPicture;
p_sys->s.allocator.release_picture_callback = FreePicture;
+ av1_OBU_sequence_header_t *sequence_hdr = NULL;
+ if (dec->fmt_in.i_extra > 4)
+ {
+ sequence_hdr = AV1_OBU_parse_sequence_header(((uint8_t*)dec->fmt_in.p_extra) + 4,
+ dec->fmt_in.i_extra - 4);
+ }
+
if (dav1d_open(&p_sys->c, &p_sys->s) < 0)
{
msg_Err(p_this, "Could not open the Dav1d decoder");
@@ -406,7 +414,48 @@ static int OpenDecoder(vlc_object_t *p_this)
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;
+ if (!sequence_hdr)
+ dec->fmt_out.i_codec = VLC_CODEC_I420;
+ else
+ {
+ // use the sequence header to get a better chroma to start with
+ switch (AV1_get_chroma(sequence_hdr))
+ {
+ case VLC_CODEC_GREY:
+ switch (AV1_get_bitdepth(sequence_hdr))
+ {
+ case 0: dec->fmt_out.i_codec = VLC_CODEC_GREY; break;
+ case 1: dec->fmt_out.i_codec = VLC_CODEC_GREY_10L; break;
+ case 2: dec->fmt_out.i_codec = VLC_CODEC_GREY_12L; break;
+ }
+ break;
+ case VLC_CODEC_I420:
+ switch (AV1_get_bitdepth(sequence_hdr))
+ {
+ case 0: dec->fmt_out.i_codec = VLC_CODEC_I420; break;
+ case 1: dec->fmt_out.i_codec = VLC_CODEC_I420_10L; break;
+ case 2: dec->fmt_out.i_codec = VLC_CODEC_I420_12L; break;
+ }
+ break;
+ case VLC_CODEC_I422:
+ switch (AV1_get_bitdepth(sequence_hdr))
+ {
+ case 0: dec->fmt_out.i_codec = VLC_CODEC_I422; break;
+ case 1: dec->fmt_out.i_codec = VLC_CODEC_I422_10L; break;
+ case 2: dec->fmt_out.i_codec = VLC_CODEC_I422_12L; break;
+ }
+ break;
+ case VLC_CODEC_I444:
+ switch (AV1_get_bitdepth(sequence_hdr))
+ {
+ case 0: dec->fmt_out.i_codec = VLC_CODEC_I444; break;
+ case 1: dec->fmt_out.i_codec = VLC_CODEC_I444_10L; break;
+ case 2: dec->fmt_out.i_codec = VLC_CODEC_I444_12L; break;
+ }
+ break;
+ }
+ AV1_release_sequence_header(sequence_hdr);
+ }
dec->p_sys = p_sys;
if (dec->fmt_in.video.i_sar_num > 0 && dec->fmt_in.video.i_sar_den > 0) {
--
2.26.2
More information about the vlc-devel
mailing list