[vlc-devel] [PATCH v2 1/5] dav1d: prepare hardware decoding support

Steve Lhomme robux4 at ycbcr.xyz
Fri Sep 11 11:46:05 CEST 2020


Using a decoder device and a video context.

This will make the next patch more readable.
---
 modules/codec/dav1d.c | 71 ++++++++++++++++++++++++++++---------------
 1 file changed, 47 insertions(+), 24 deletions(-)

diff --git a/modules/codec/dav1d.c b/modules/codec/dav1d.c
index 5d341a367fa..539780b0d83 100644
--- a/modules/codec/dav1d.c
+++ b/modules/codec/dav1d.c
@@ -79,6 +79,10 @@ typedef struct
     Dav1dSettings s;
     Dav1dContext *c;
     cc_data_t cc;
+
+    // hardware decoding
+    vlc_video_context  *vctx_out;
+    vlc_decoder_device *dec_dev;
 } decoder_sys_t;
 
 struct user_data_s
@@ -147,6 +151,7 @@ static void UpdateDecoderOutput(decoder_t *dec, const Dav1dSequenceHeader *seq_h
 static int NewPicture(Dav1dPicture *img, void *cookie)
 {
     decoder_t *dec = cookie;
+    decoder_sys_t *sys = dec->p_sys;
 
     video_format_t *v = &dec->fmt_out.video;
 
@@ -185,25 +190,30 @@ static int NewPicture(Dav1dPicture *img, void *cookie)
     v->projection_mode = dec->fmt_in.video.projection_mode;
     v->multiview_mode = dec->fmt_in.video.multiview_mode;
     v->pose = dec->fmt_in.video.pose;
-    dec->fmt_out.i_codec = FindVlcChroma(img);
-    v->i_width  = (img->p.w + 0x7F) & ~0x7F;
-    v->i_height = (img->p.h + 0x7F) & ~0x7F;
+    dec->fmt_out.i_codec = 0;
+    if (dec->fmt_out.i_codec == 0)
+    {
+        dec->fmt_out.i_codec = FindVlcChroma(img);
+        v->i_width  = (img->p.w + 0x7F) & ~0x7F;
+        v->i_height = (img->p.h + 0x7F) & ~0x7F;
+    }
     v->i_chroma = dec->fmt_out.i_codec;
 
-    if (decoder_UpdateVideoFormat(dec) == 0)
+    if (decoder_UpdateVideoOutput(dec, sys->vctx_out) == 0)
     {
         picture_t *pic;
-        pic = decoder_NewPicture(dec);
-        if (unlikely(pic == NULL))
-            return -1;
-
-        img->data[0] = pic->p[0].p_pixels;
-        img->stride[0] = pic->p[0].i_pitch;
-        img->data[1] = pic->p[1].p_pixels;
-        img->data[2] = pic->p[2].p_pixels;
-        assert(pic->p[1].i_pitch == pic->p[2].i_pitch);
-        img->stride[1] = pic->p[1].i_pitch;
-
+        {
+            pic = decoder_NewPicture(dec);
+            if (unlikely(pic == NULL))
+                return -1;
+
+            img->data[0] = pic->p[0].p_pixels;
+            img->stride[0] = pic->p[0].i_pitch;
+            img->data[1] = pic->p[1].p_pixels;
+            img->data[2] = pic->p[2].p_pixels;
+            assert(pic->p[1].i_pitch == pic->p[2].i_pitch);
+            img->stride[1] = pic->p[1].i_pitch;
+        }
         img->allocator_data = pic;
         return 0;
     }
@@ -400,6 +410,15 @@ static int OpenDecoder(vlc_object_t *p_this)
     p_sys->s.allocator.cookie = dec;
     p_sys->s.allocator.alloc_picture_callback = NewPicture;
     p_sys->s.allocator.release_picture_callback = FreePicture;
+    p_sys->vctx_out = NULL;
+    p_sys->dec_dev = NULL;
+
+    dec->p_sys = p_sys;
+
+    dec->fmt_out.video.primaries   = dec->fmt_in.video.primaries;
+    dec->fmt_out.video.transfer    = dec->fmt_in.video.transfer;
+    dec->fmt_out.video.space       = dec->fmt_in.video.space;
+    dec->fmt_out.video.color_range = dec->fmt_in.video.color_range;
 
     av1_OBU_sequence_header_t *sequence_hdr = NULL;
     if (dec->fmt_in.i_extra > 4)
@@ -435,6 +454,8 @@ static int OpenDecoder(vlc_object_t *p_this)
     if (dav1d_open(&p_sys->c, &p_sys->s) < 0)
     {
         msg_Err(p_this, "Could not open the Dav1d decoder");
+        vlc_video_context_Release(p_sys->vctx_out);
+        p_sys->vctx_out = NULL;
         return VLC_EGENERIC;
     }
 
@@ -442,19 +463,16 @@ static int OpenDecoder(vlc_object_t *p_this)
             dav1d_version(), p_sys->s.n_frame_threads, p_sys->s.n_tile_threads);
 
     dec->i_extra_picture_buffers = (p_sys->s.n_frame_threads - 1);
-    dec->fmt_out.video.i_width  = (dec->fmt_out.video.i_width + 0x7F) & ~0x7F;
-    dec->fmt_out.video.i_height = (dec->fmt_out.video.i_height + 0x7F) & ~0x7F;
-
-    dec->p_sys = p_sys;
+    if (p_sys->dec_dev == NULL)
+    {
+        dec->fmt_out.video.i_width  = (dec->fmt_out.video.i_width + 0x7F) & ~0x7F;
+        dec->fmt_out.video.i_height = (dec->fmt_out.video.i_height + 0x7F) & ~0x7F;
+    }
 
     if (dec->fmt_in.video.i_sar_num > 0 && dec->fmt_in.video.i_sar_den > 0) {
         dec->fmt_out.video.i_sar_num = dec->fmt_in.video.i_sar_num;
         dec->fmt_out.video.i_sar_den = dec->fmt_in.video.i_sar_den;
     }
-    dec->fmt_out.video.primaries   = dec->fmt_in.video.primaries;
-    dec->fmt_out.video.transfer    = dec->fmt_in.video.transfer;
-    dec->fmt_out.video.space       = dec->fmt_in.video.space;
-    dec->fmt_out.video.color_range = dec->fmt_in.video.color_range;
     dec->fmt_out.video.mastering   = dec->fmt_in.video.mastering;
     dec->fmt_out.video.lighting    = dec->fmt_in.video.lighting;
 
@@ -463,7 +481,7 @@ static int OpenDecoder(vlc_object_t *p_this)
         // we have the proper chroma, make sure we can use it
         AV1_release_sequence_header(sequence_hdr);
 
-        if (decoder_UpdateVideoFormat(dec) != 0)
+        if (decoder_UpdateVideoOutput(dec, p_sys->vctx_out) != 0)
         {
             CloseDecoder(VLC_OBJECT(dec));
             return VLC_EGENERIC;
@@ -488,5 +506,10 @@ static void CloseDecoder(vlc_object_t *p_this)
     /* Flush decoder */
     FlushDecoder(dec);
 
+    if (p_sys->vctx_out)
+        vlc_video_context_Release(p_sys->vctx_out);
+    if (p_sys->dec_dev)
+        vlc_decoder_device_Release(p_sys->dec_dev);
+
     dav1d_close(&p_sys->c);
 }
-- 
2.26.2



More information about the vlc-devel mailing list