[vlc-commits] [Git][videolan/vlc][master] dav1d: treat RGB formats separately

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Sep 6 07:22:09 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
ece317a2 by Tristan Matthews at 2024-09-06T06:41:37+00:00
dav1d: treat RGB formats separately

This avoids incorrectly matching as GBR and also adds support for 12-bit planar GBR.
Fixes #28763 which was missing checks for the matrix and primaries.

This also replaces the loop with a constant-time lookup.

- - - - -


1 changed file:

- modules/codec/dav1d.c


Changes:

=====================================
modules/codec/dav1d.c
=====================================
@@ -97,45 +97,34 @@ static void FreeUserData_Handler(const uint8_t *p, void *userdata)
     free(userdata);
 }
 
-static const struct
-{
-    vlc_fourcc_t          i_chroma;
-    enum Dav1dPixelLayout i_chroma_id;
-    uint8_t               i_bitdepth;
-    enum Dav1dTransferCharacteristics transfer_characteristics;
-} chroma_table[] =
-{
-    /* Transfer characteristic-dependent mappings must come first */
-    {VLC_CODEC_GBR_PLANAR, DAV1D_PIXEL_LAYOUT_I444, 8, DAV1D_TRC_SRGB},
-    {VLC_CODEC_GBR_PLANAR_10L, DAV1D_PIXEL_LAYOUT_I444, 10, DAV1D_TRC_SRGB},
-
-    {VLC_CODEC_GREY, DAV1D_PIXEL_LAYOUT_I400, 8, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I420, DAV1D_PIXEL_LAYOUT_I420, 8, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I422, DAV1D_PIXEL_LAYOUT_I422, 8, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I444, DAV1D_PIXEL_LAYOUT_I444, 8, DAV1D_TRC_UNKNOWN},
-
-    {VLC_CODEC_GREY_10L, DAV1D_PIXEL_LAYOUT_I400, 10, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I420_10L, DAV1D_PIXEL_LAYOUT_I420, 10, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I422_10L, DAV1D_PIXEL_LAYOUT_I422, 10, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I444_10L, DAV1D_PIXEL_LAYOUT_I444, 10, DAV1D_TRC_UNKNOWN},
-
-    {VLC_CODEC_GREY_12L, DAV1D_PIXEL_LAYOUT_I400, 12, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I420_12L, DAV1D_PIXEL_LAYOUT_I420, 12, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I422_12L, DAV1D_PIXEL_LAYOUT_I422, 12, DAV1D_TRC_UNKNOWN},
-    {VLC_CODEC_I444_12L, DAV1D_PIXEL_LAYOUT_I444, 12, DAV1D_TRC_UNKNOWN},
-};
-
 static vlc_fourcc_t FindVlcChroma(const Dav1dPicture *img)
 {
+    static const vlc_fourcc_t chroma_table_rgb[] = { VLC_CODEC_GBR_PLANAR, VLC_CODEC_GBR_PLANAR_10L, VLC_CODEC_GBR_PLANAR_12L };
+    static const vlc_fourcc_t chroma_table[][3] = {
+        [DAV1D_PIXEL_LAYOUT_I400] = { VLC_CODEC_GREY, VLC_CODEC_GREY_10L, VLC_CODEC_GREY_12L },
+        [DAV1D_PIXEL_LAYOUT_I420] = { VLC_CODEC_I420, VLC_CODEC_I420_10L,  VLC_CODEC_I420_12L },
+        [DAV1D_PIXEL_LAYOUT_I422] = { VLC_CODEC_I422, VLC_CODEC_I422_10L,  VLC_CODEC_I422_12L },
+        [DAV1D_PIXEL_LAYOUT_I444] = { VLC_CODEC_I444, VLC_CODEC_I444_10L,  VLC_CODEC_I444_12L },
+    };
 
-    for (unsigned int i = 0; i < ARRAY_SIZE(chroma_table); i++)
-        if (chroma_table[i].i_chroma_id == img->p.layout &&
-            chroma_table[i].i_bitdepth == img->p.bpc &&
-            (chroma_table[i].transfer_characteristics == DAV1D_TRC_UNKNOWN ||
-             chroma_table[i].transfer_characteristics == img->seq_hdr->trc))
-            return chroma_table[i].i_chroma;
+    // AV1 signals RGB with the combination of the identity matrix, the BT.709 primaries and the sRGB/YCC transfer function.
+    // See: "5.5.2. Color config syntax" from https://aomediacodec.github.io/av1-spec/av1-spec.pdf
+    if( img->p.layout == DAV1D_PIXEL_LAYOUT_I444 &&
+        img->seq_hdr->mtrx == DAV1D_MC_IDENTITY &&
+        img->seq_hdr->pri == DAV1D_COLOR_PRI_BT709 &&
+        img->seq_hdr->trc == DAV1D_TRC_SRGB )
+    {
+        if( img->seq_hdr->hbd < 0 || img->seq_hdr->hbd >= (int)ARRAY_SIZE(chroma_table_rgb) )
+            return 0;
+        return chroma_table_rgb[img->seq_hdr->hbd];
+    }
 
-    return 0;
+    if( img->seq_hdr->layout < 0 || img->seq_hdr->layout >= (int)ARRAY_SIZE(chroma_table) )
+        return 0;
+    if( img->seq_hdr->hbd < 0 || img->seq_hdr->hbd >= (int)ARRAY_SIZE(chroma_table[0]) )
+        return 0;
+
+    return chroma_table[img->seq_hdr->layout][img->seq_hdr->hbd];
 }
 
 static void UpdateDecoderOutput(decoder_t *dec, const Dav1dSequenceHeader *seq_hdr)
@@ -200,6 +189,9 @@ static int NewPicture(Dav1dPicture *img, void *cookie)
     v->multiview_mode = dec->fmt_in->video.multiview_mode;
     v->pose = dec->fmt_in->video.pose;
     dec->fmt_out.i_codec = FindVlcChroma(img);
+    if (unlikely(dec->fmt_out.i_codec == 0))
+        return -1;
+
     v->i_width  = (img->seq_hdr->max_width + 0x7F) & ~0x7F;
     v->i_height = (img->seq_hdr->max_height + 0x7F) & ~0x7F;
     v->i_chroma = dec->fmt_out.i_codec;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ece317a245e8c32a5efc11d5e82dcd8a28a2f10b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ece317a245e8c32a5efc11d5e82dcd8a28a2f10b
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list