[FFmpeg-devel] [PATCH] libavcodec/libdav1d: add libdav1d_get_format method to call ff_get_format

Lukas Rusak lorusak at gmail.com
Thu Apr 11 01:33:14 EEST 2019


This will allow applications to properly init the decoder in
cases where a hardware decoder is tried first and and software
decoder is tried after by calling the get_format callback.

Even though there is no hardware pixel formats available
we still need to return the software pixel format.

Tested with Kodi by checking if multithreaded software
decoding is properly activated.
---
 libavcodec/libdav1d.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 30c6eccfef..fa71834543 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -48,6 +48,16 @@ static const enum AVPixelFormat pix_fmt[][3] = {
     [DAV1D_PIXEL_LAYOUT_I444] = { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12 },
 };
 
+static enum AVPixelFormat libdav1d_get_format(AVCodecContext *avctx, const Dav1dPicture *p)
+{
+   enum AVPixelFormat pix_fmts[2], *fmt = pix_fmts;
+
+   *fmt++ = pix_fmt[p->p.layout][p->seq_hdr->hbd];
+   *fmt = AV_PIX_FMT_NONE;
+
+   return ff_get_format(avctx, pix_fmts);
+}
+
 static void libdav1d_log_callback(void *opaque, const char *fmt, va_list vl)
 {
     AVCodecContext *c = opaque;
@@ -214,7 +224,7 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
     frame->linesize[2] = p->stride[1];
 
     c->profile = p->seq_hdr->profile;
-    frame->format = c->pix_fmt = pix_fmt[p->p.layout][p->seq_hdr->hbd];
+    frame->format = c->pix_fmt = libdav1d_get_format(c, p);
     frame->width = p->p.w;
     frame->height = p->p.h;
     if (c->width != p->p.w || c->height != p->p.h) {
-- 
2.20.1



More information about the ffmpeg-devel mailing list